public static List<Serviciorepor> GenerarReporServicios(string tienda, string cliente, DateTime fechaIni, DateTime fechaFin, ref Double montoTotal ) { List<Serviciorepor> lstServ = new List<Serviciorepor>(); SqlConnection conn = new SqlConnection(Properties.Settings.Default.inf245g4ConnectionString); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; String where = ""; montoTotal = 0; if (!String.IsNullOrEmpty(tienda)) { where += " AND "; where = where + " t.nombre = @tiendaNom "; cmd.Parameters.Add(new SqlParameter("tiendaNom", tienda)); } if (!String.IsNullOrWhiteSpace(cliente)) { where += " AND "; where = where + " ( (c.nombre + ' ' + c.apePaterno + ' ' + c.apeMaterno) like @nombreCli OR (c.apePaterno + ' ' + c.apeMaterno + ', ' + c.nombre) like @nombreCli OR c.razonSocial like @nombreCli ) "; cmd.Parameters.Add(new SqlParameter("nombreCli", '%' + cliente + '%')); } cmd.CommandText = "Select v.fechaReg as fecha, (c.nombre + ' ' + c.apePaterno + ' ' +c.apeMaterno) as cliente, c.razonSocial as razonSocial, t.nombre as tienda, s.nombre as servicio, v.monto as precio from Venta v, Cliente c, Tienda t, Usuario u, Servicio s, DetalleVentaServicio d where c.idCLiente=v.idCLiente and u.idTienda=t.idTienda and v.idUsuario=u.idUsuario and d.idServicio=s.idServicio and v.idVenta=d.idVenta " + where; cmd.CommandType = CommandType.Text; cmd.Connection = conn; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { Serviciorepor p = new Serviciorepor(); p.Tienda = reader["tienda"].ToString(); p.Nombre = reader["servicio"].ToString(); p.Precio = Double.Parse(reader["precio"].ToString()); if (!String.IsNullOrEmpty(reader["razonSocial"].ToString())) { p.Cliente = reader["razonSocial"].ToString(); } else { p.Cliente = reader["cliente"].ToString(); } p.Fecha = Convert.ToDateTime(reader["fecha"].ToString()); montoTotal += p.Precio; lstServ.Add(p); } conn.Close(); } catch (Exception e) { MessageBox.Show(e.StackTrace.ToString()); } return lstServ; }
public void SelectedItemChanged(object sender) { serviciorepSeleccionado = ((sender as DataGrid).SelectedItem as Serviciorepor); }