public static List <InformeCompra> ListaInforme(int?IdProveedor, int?idInsumo, DateTime?fd, DateTime?fh) { List <InformeCompra> lista = new List <InformeCompra>(); SqlConnection cn = new SqlConnection(); // cn.ConnectionString = "Data Source=NICO-PC;Initial Catalog=PAV02_COD;Integrated Security=True"; cn.ConnectionString = ConnectionString.Cadena(); cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = @"select I.descripcion as 'descripcion', D.cantidad as 'cantidad', P.nombreResponsable as 'nombreEmpresa', C.fechaHora as 'fecha' from compraInsumos C JOIN detalleCompraInsumos D ON C.idProveedor = D.idProveedor JOIN Insumos I ON D.codInsumo = I.idInsumo JOIN proveedores P ON C.idProveedor = P.idProveedor where 1=1 "; if (IdProveedor.HasValue) { cmd.CommandText += " and C.idProveedor = @idProv "; cmd.Parameters.AddWithValue("@idProv", IdProveedor); } if (idInsumo.HasValue) { cmd.CommandText += " and D.codInsumo=@codIns "; cmd.Parameters.AddWithValue("@codIns", idInsumo.Value); } if (fd.HasValue) { cmd.CommandText += " and C.fechaHora >= @FD "; cmd.Parameters.AddWithValue("@FD", fd.Value); } if (fh.HasValue) { cmd.CommandText += " and C.fechaHora <= @FH "; cmd.Parameters.AddWithValue("@FH", fh.Value); } SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { InformeCompra i = new InformeCompra() { descripcion = (dr["descripcion"].ToString()), cantidad = int.Parse(dr["cantidad"].ToString()), nombreEmpresa = dr["nombreEmpresa"].ToString(), fecha = DateTime.Parse(dr["fecha"].ToString()), }; lista.Add(i); } dr.Close(); cn.Close(); return(lista); }
public async Task <PartialViewResult> OnGetTabla(int?IdProveedor, int?Pagina, int?Maximo) { string sql = InformeCompra.query(); if (Pagina != null) { this.Pagina = Pagina.Value; } if (Maximo != null) { this.Maximo = Maximo.Value; } Informes = await _context.InformeCompra.FromSql(sql).ToListAsync(); /**/ var total = _context.InformeCompra .FromSql(sql) .Count(); this.Total = total; //IdProveedor = 65;//??????? List <string> whereIn = new List <string>(); List <MySqlParameter> wParams = new List <MySqlParameter>(); int i = 0; if (IdProveedor != null) { //@Id le puedes poner como quieras //pero es mejor que sea algo representativo ya que es idproveedor no idcompra whereIn.Add("c.IdProveedor = @IdProveedor"); wParams.Add(new MySqlParameter("@IdProveedor", IdProveedor)); } string str = String.Join(" and ", whereIn.ToArray()); //string limit = " limit "+Pagina.Value*Maximo.Value+"," +Maximo.Value; /* * MySqlParameter mysqlp; * mysqlp = new MySqlParameter("@NombreOCodigo", "%Cuaderno%"); * string lquery = "Select * from Producto where Nombre LIKE @NombreOCodigo or Codigo LIKE @NombreOCodigo"; * var list = _context.Productos.FromSql(lquery, mysqlp).ToList(); */ string sqlprueba = InformeCompra.query(str); //Console.WriteLine(sqlprueba); /* * this.Informes = _context.InformeCompra.FromSql(sqlprueba, wParams.ToArray()) * .ToList(); */ this.Informes = _context.InformeCompra.FromSql(sqlprueba, wParams.ToArray()) .Skip((this.Pagina.Value) * this.Maximo.Value).Take(this.Maximo.Value).ToList(); Total = _context.InformeCompra.FromSql(sqlprueba, wParams.ToArray()).Count(); return(Partial("/Pages/Shared/OthersPartials/_TablaComprasPartial.cshtml", this)); }