public static List<InformeVentasEntidad> obtenerInforme(InformeVentasEntidad informe) { List<InformeVentasEntidad> lista = new List<InformeVentasEntidad>(); SqlCommand command = new SqlCommand(); SqlConnection connection = new SqlConnection(); try { connection.ConnectionString = cadenaConeccion; connection.Open(); string sql = "select c.cuit as 'cuit', c.nombre as 'nombreCliente', l.nombre as 'nombreLocalidad', f.total as 'total', f.numeroFactura as 'numeroFactura', t.nombre as 'nombre', m.aplique as 'aplique' from Cliente c"; sql += " JOIN Localidad l ON (l.id=c.idLocalidad) JOIN Factura f ON (f.idCliente=c.id) JOIN TipoFactura t ON (t.id=f.idTipoFactura) JOIN DetalleFactura d ON (d.idFactura=f.id) JOIN Matriz m ON (m.id=d.idMatriz) where c.id = @idCliente AND m.aplique = @aplique"; if (informe.total > 0) { sql += " AND f.total = @total"; } command.CommandText = sql; command.Connection = connection; if (informe.total > 0) { command.Parameters.AddWithValue("@total", informe.total); } command.Parameters.AddWithValue("@aplique",informe.aplique); command.Parameters.AddWithValue("@idCliente",informe.idCliente); SqlDataReader dr = command.ExecuteReader(); while(dr.Read()) { InformeVentasEntidad i = new InformeVentasEntidad(); i.cuit = int.Parse(dr["cuit"].ToString()); i.nombreCliente = dr["nombreCliente"].ToString(); i.nombreLocalidad = dr["nombreLocalidad"].ToString(); i.total = decimal.Parse(dr["total"].ToString()); i.numeroFactura = int.Parse(dr["numeroFactura"].ToString()); i.tipoFactura = dr["nombre"].ToString(); i.apliqueBooleano = bool.Parse(dr["aplique"].ToString()); lista.Add(i); } } catch(SqlException ex) { } finally { if(connection.State == ConnectionState.Open) { connection.Close(); } } return lista; }
protected void btnBuscar_Click(object sender, EventArgs e) { InformeVentasEntidad i = new InformeVentasEntidad(); i.idCliente = int.Parse(ddlCliente.SelectedValue); i.aplique = 0; if(cbxAplique.Checked == true) { i.aplique = 1; } if(txtMonto.Text != "") { i.total = decimal.Parse(txtMonto.Text); } grvInforme.DataSource = InformesVentasGestor.obtenerInforme(i); grvInforme.DataBind(); }