He tenido que hacer una app en c# para trabajar con Adminpaq, pero me quede atorado en querer agregar el folio al documento, lo que intento es que al resultado de la consulta sql pasarlo a un objeto y este objeto editar un item dentro de este.
Este es mi objeto, todos los campos los lleno de una consulta sql a excepcion del ciddocum01, ese seria el id del documento de adminpaq (adminpaq no maneja autoincrementables, al menos no en vfp)
public class Documento
{
public int ciddocum01 { get; set; }
public int ciddocum02 { get; set; }
public string cseriedo01 { get; set; }
public string cfolio { get; set; }
public int cidclien01 { get; set; }
public string crazonso01 { get; set; }
public string cfechave01 { get; set; }
public string cfechapr01 { get; set; }
public int cidmoneda { get; set; }
public string ctipocam01 { get; set; }
public string cobserva01 { get; set; }
public string cnatural01 { get; set; }
public int cusaclie01 { get; set; }
public int cestadoc01 { get; set; }
public int cneto { get; set; }
public int cimpuesto1 { get; set; }
public int cretenci02 { get; set; }
public int ctotal { get; set; }
public int cpendiente { get; set; }
public int cporcent01 { get; set; }
public string clugarexpe { get; set; }
}
y con esta funcion creo los documentos pendientes
public List<object> DocumentosPendientes(string recibo)
{
string json = string.Empty;
List<object> toadmin = new List<object>();
Documento documento = new Documento();
string cnn = ConfigurationManager.ConnectionStrings["siete"].ConnectionString;
using (SqlConnection conexion = new SqlConnection(cnn))
{
conexion.Open();
string query = "SELECT ciddocum02,cseriedo01, cfolio,idAdmin, crazonso01, cfechave01,cfechapr01,cidmoneda, ctipocam01, cobserva01, cnatural01, cusaclie01 " +
", cestadoc01, cneto, cimpuesto1, ISNULL(cretenci02, 0) As cretenci02, ctotal, cpendiente, cporcent01, clugarexpe FROM DocumentosPendientes WHERE IdContraRecibo = @p";
using (SqlCommand cmd = new SqlCommand(query, conexion))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@p", recibo);
using (SqlDataReader rd = cmd.ExecuteReader())
{
toadmin.Clear();
int count = 0;
while (rd.Read())
{
count += 1;
documento.ciddocum01 = count;
documento.ciddocum02 = Convert.ToInt32(rd[0]);
documento.cseriedo01 = rd[1].ToString();
documento.cfolio = rd[2].ToString();
documento.cidclien01 = Convert.ToInt32(rd[3]);
documento.crazonso01 = rd[4].ToString();
documento.cfechave01 = DateTime.Parse(rd[5].ToString());
documento.cfechapr01 = DateTime.Parse(rd[6].ToString());
documento.cidmoneda = Convert.ToInt32(rd[7]);
documento.ctipocam01 = rd[8].ToString();
documento.cobserva01 = rd[9].ToString();
documento.cnatural01 = rd[10].ToString();
documento.cusaclie01 = Convert.ToInt32(rd[11]);
documento.cestadoc01 = Convert.ToInt32(rd[12]);
documento.cneto = Convert.ToInt32(rd[13]);
documento.cimpuesto1 = Convert.ToInt32(rd[14]);
documento.cretenci02 = Convert.ToInt32(rd[15]);
documento.ctotal = Convert.ToInt32(rd[16]);
documento.cpendiente = Convert.ToInt32(rd[17]);
documento.cporcent01 = Convert.ToInt32(rd[18]);
documento.clugarexpe = rd[19].ToString();
toadmin.Add(documento);
}
//System.Diagnostics.Debug.WriteLine(rd.FieldCount);
return toadmin;
}
}
}
}
Pero al agregar en el while
count += 1;
este simplemente me guarda un 4 dentro del item ciddocum01 cuando deberia ser 1 2 3 4
he intentando hacerlo con
do
{
//codigo
} while (rd.Read())
pero no toma los datos de la consulta e igualmente me toma el valor 4 (que son las tablas que cumplen con la condicion), si alguien ha trabajado con esto, agradeceria mucho un poco de ayuda, esta es la respuesta que da el api
[
{
"ciddocum01": 4,
"ciddocum02": 3013,
"cseriedo01": "A ",
"cfolio": "65445 ",
"cidclien01": 53,
"crazonso01": "xxxxxxxxxxxxxxxxxxxxxxxx",
"cfechave01": "2021-02-04T17:00:00Z",
"cfechapr01": "2021-02-04T17:00:00Z",
"cidmoneda": 1,
"ctipocam01": "1",
"cobserva01": "memo",
"cnatural01": "1 ",
"cusaclie01": 1,
"cestadoc01": 1,
"cneto": 200,
"cimpuesto1": 16,
"cretenci02": 0,
"ctotal": 216,
"cpendiente": 216,
"cporcent01": 8,
"clugarexpe": "xxxxx, Chihu. Mexico"
},
{
"ciddocum01": 4,
"ciddocum02": 3013,
"cseriedo01": "A ",
"cfolio": "65445 ",
"cidclien01": 53,
"crazonso01": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"cfechave01": "2021-02-04T17:00:00Z",
"cfechapr01": "2021-02-04T17:00:00Z",
"cidmoneda": 1,
"ctipocam01": "1",
"cobserva01": "memo",
"cnatural01": "1 ",
"cusaclie01": 1,
"cestadoc01": 1,
"cneto": 200,
"cimpuesto1": 16,
"cretenci02": 0,
"ctotal": 216,
"cpendiente": 216,
"cporcent01": 8,
"clugarexpe": "xxxxxx, Chihu. Mexico"
},
{
"ciddocum01": 4,
"ciddocum02": 3013,
"cseriedo01": "A ",
"cfolio": "65445 ",
"cidclien01": 53,
"crazonso01": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"cfechave01": "2021-02-04T17:00:00Z",
"cfechapr01": "2021-02-04T17:00:00Z",
"cidmoneda": 1,
"ctipocam01": "1",
"cobserva01": "memo",
"cnatural01": "1 ",
"cusaclie01": 1,
"cestadoc01": 1,
"cneto": 200,
"cimpuesto1": 16,
"cretenci02": 0,
"ctotal": 216,
"cpendiente": 216,
"cporcent01": 8,
"clugarexpe": "xxxxx, Chihu. Mexico"
},
{
"ciddocum01": 4,
"ciddocum02": 3013,
"cseriedo01": "A ",
"cfolio": "65445 ",
"cidclien01": 53,
"crazonso01": "xxxxxxxxxxxxxxxxxxxxx",
"cfechave01": "2021-02-04T17:00:00Z",
"cfechapr01": "2021-02-04T17:00:00Z",
"cidmoneda": 1,
"ctipocam01": "1",
"cobserva01": "memo",
"cnatural01": "1 ",
"cusaclie01": 1,
"cestadoc01": 1,
"cneto": 200,
"cimpuesto1": 16,
"cretenci02": 0,
"ctotal": 216,
"cpendiente": 216,
"cporcent01": 8,
"clugarexpe": "xxxxxx, Chihu. Mexico"
}
]