public SQLResponse executeQuery(String query) { SQLResponse respuesta = new SQLResponse(); SqlCommand comando = new SqlCommand(query, this.sqlConnection); SqlDataAdapter adapter = new SqlDataAdapter(comando); DataTable resultado = new DataTable(); respuesta.rowsAffected = adapter.Fill(resultado); respuesta.result = resultado; return respuesta; }
public SQLResponse executeQuery(String query) { SQLResponse respuesta = new SQLResponse(); SqlCommand comando = new SqlCommand(query, this.sqlConnection); SqlDataAdapter adapter = new SqlDataAdapter(comando); DataTable resultado = new DataTable(); respuesta.rowsAffected = adapter.Fill(resultado); respuesta.result = resultado; return(respuesta); }
private void Facturar_Click(object sender, EventArgs e) { if (FechaDesde.Text == "" || FechaHasta.Text == "" || this.proveedores.Text == "" ) { MessageBox.Show("Faltan datos"); return; } if(this.dataGridCupones.RowCount == 0){ MessageBox.Show("No hay cupones para facturar para el intervalo de fechas seleccionado"); return; } ParamSet ps = new ParamSet("GESTION_DE_PATOS.FacturarProveedor"); float monto = float.Parse(montoFactura().ToString()); r = dbManager.executeQuery("SELECT username FROM GESTION_DE_PATOS.Proveedores where cuit = '"+proveedores.SelectedItem.ToString() + "'"); ps.AddParameter("@proveedor", r.result.Rows[0][0].ToString() ); ps.AddParameter("@fecha_desde", FechaDesde.Text); ps.AddParameter("@fecha_hasta", FechaHasta.Text); ps.AddParameter("@monto", monto*0.5); SqlParameter retval = ps.execSP(); String ret = retval.Value.ToString(); switch (ret) { case "1": MessageBox.Show("Ya hay cupones facturados para el intervalo ingresado."); return; default: String elMonto = (monto*0.5).ToString(); if (elMonto.Contains(",")) { int decimales = elMonto.Substring(elMonto.IndexOf(","), elMonto.Length - elMonto.IndexOf(",")).Length; if (decimales < 3) { elMonto = elMonto.Substring(0, elMonto.IndexOf(",") + decimales); } else { elMonto = elMonto.Substring(0, elMonto.IndexOf(",") + 3); } } MessageBox.Show("Facturación finalizada con éxito. \n Nro de factura: " + ret + ".\n Monto: $" + elMonto); r = dbManager.executeQuery("SELECT c.id_cupon, c.cliente, c.id_promocion, c.fecha_compra, ca.fecha_canje FROM GESTION_DE_PATOS.Cupones c, GESTION_DE_PATOS.Promociones g, GESTION_DE_PATOS.Proveedores p , GESTION_DE_PATOS.Canjes ca WHERE ca.id_cupon = c.id_cupon AND c.id_promocion = g.id_promocion AND g.proveedor = p.username AND p.cuit = \'" + this.proveedores.SelectedItem.ToString() + "\' AND ca.fecha_canje between " + "\'" + this.FechaDesde.Text + "\'" + " and " + "\'" + this.FechaHasta.Text + "\' and not exists (select * from GESTION_DE_PATOS.Cupones_por_factura cpf where cpf.id_cupon = c.id_cupon)"); this.SetDataGridView(r.result); return; } }
public SQLResponse executeQuery(SqlCommand comando) { comando.Connection = this.sqlConnection; comando.CommandType = CommandType.Text; SQLResponse respuesta = new SQLResponse(); SqlDataAdapter adapter = new SqlDataAdapter(comando); DataTable resultado = new DataTable(); respuesta.rowsAffected = adapter.Fill(resultado); respuesta.result = resultado; return(respuesta); }
public SQLResponse executeQuery(SqlCommand comando) { comando.Connection = this.sqlConnection; comando.CommandType = CommandType.Text; SQLResponse respuesta = new SQLResponse(); SqlDataAdapter adapter = new SqlDataAdapter(comando); DataTable resultado = new DataTable(); respuesta.rowsAffected = adapter.Fill(resultado); respuesta.result = resultado; return respuesta; }
private void PublicarCupon_Load(object sender, EventArgs e) { this.fecha.Text += " " + ((String)AppContext.getObject(typeof(String))); this.Proveedores.Items.Clear(); this.Proveedores.Items.Add(""); r = dbManager.executeQuery("SELECT p.cuit FROM GESTION_DE_PATOS.Proveedores p JOIN GESTION_DE_PATOS.Usuarios u on p.username = u.username and u.rol = 'Proveedor'"); foreach (DataRow row in r.result.Rows) { this.Proveedores.Items.Add(row[0]); } this.Proveedores.SelectedIndex = 0; this.cupones.ReadOnly = true; this.cupones.AllowUserToAddRows = false; }
private void CompraCupon_Load(object sender, EventArgs e) { String query = "select distinct gc.id_promocion Promoción, gc.descripcion Descripción, gc.precio_real Precio, gc.fecha_vencimiento_oferta 'Vencimiento Oferta', gc.fecha_vencimiento_canje 'Vencimiento Canje', pr.CUIT Proveedor from GESTION_DE_PATOS.Promociones gc join GESTION_DE_PATOS.Localidad_por_promocion lpg on lpg.id_promocion = gc.id_promocion join GESTION_DE_PATOS.Localidad_por_usuario lpu on lpu.id_localidad = lpg.id_localidad join GESTION_DE_PATOS.Proveedores pr on pr.username = gc.proveedor where GESTION_DE_PATOS.NombreEstadoPromocion(gc.estado) = 'Publicado' and lpu.username = '******' and gc.fecha_vencimiento_oferta >= '" + (String)AppContext.getObject(typeof(String)) + "'"; r = dbManager.executeQuery(query); this.cuponesDisponibles.DataSource = r.result; this.cuponesDisponibles.ReadOnly = true; this.cuponesDisponibles.Columns["Vencimiento Oferta"].Width = 120; this.cuponesDisponibles.Columns["Vencimiento Canje"].Width = 120; DataGridViewButtonColumn comprar = new DataGridViewButtonColumn(); comprar.Name = "comprar"; comprar.HeaderText = "Comprar"; this.cuponesDisponibles.Columns.Add(comprar); this.cuponesDisponibles.Columns["comprar"].ReadOnly = false; this.cuponesDisponibles.AllowUserToAddRows = false; }
private object montoFactura() { object monto = null; r = dbManager.executeQuery("SELECT SUM(g.precio_real) FROM GESTION_DE_PATOS.Cupones c, GESTION_DE_PATOS.Promociones g, GESTION_DE_PATOS.Proveedores p,GESTION_DE_PATOS.Canjes ca WHERE c.id_cupon = ca.id_cupon AND c.id_promocion = g.id_promocion AND g.proveedor = p.username AND p.cuit = \'" + this.proveedores.SelectedItem.ToString() + "\' AND ca.fecha_canje between " + "\'" + this.FechaDesde.Text + "\'" + " and " + "\'" + this.FechaHasta.Text + "\' and c.id_cupon not in (select id_cupon from GESTION_DE_PATOS.Cupones_por_factura)"); monto = r.result.Rows[0][0]; return monto; }
private void Listar_Click(object sender, EventArgs e) { if (FechaDesde.Text == "" || FechaHasta.Text == "") { MessageBox.Show("Faltan datos"); return; } if (esMenor(FechaDesde.Text, FechaHasta.Text) > 0) { MessageBox.Show("La fecha desde no puede ser posterior a la fecha hasta"); return; } if(esMenor(FechaHasta.Text, (String)AppContext.getObject(typeof(String)))>0){ MessageBox.Show("La fecha hasta de la facturación no puede superar la fecha actual"); return; } SQLResponse r; r = dbManager.executeQuery("SELECT c.id_cupon, c.cliente, c.id_promocion, c.fecha_compra, ca.fecha_canje FROM GESTION_DE_PATOS.Cupones c, GESTION_DE_PATOS.Promociones g, GESTION_DE_PATOS.Proveedores p , GESTION_DE_PATOS.Canjes ca WHERE ca.id_cupon = c.id_cupon AND c.id_promocion = g.id_promocion AND g.proveedor = p.username AND p.cuit = \'" + this.proveedores.SelectedItem.ToString() + "\' AND ca.fecha_canje between " + "\'" + this.FechaDesde.Text + "\'" + " and " + "\'" + this.FechaHasta.Text + "\' and not exists (select * from GESTION_DE_PATOS.Cupones_por_factura cpf where cpf.id_cupon = c.id_cupon)"); this.SetDataGridView(r.result); }
private void cuponesDisponibles_CellContentClick(object sender, DataGridViewCellEventArgs e) { String columna_seleccionada = this.cuponesDisponibles.Columns[e.ColumnIndex].Name; if (columna_seleccionada == "comprar") { if (this.Cantidad.Text == "") { MessageBox.Show("Ingrese una cantidad"); return; } Int64 cantidad = 1; try{ cantidad = Int64.Parse(this.Cantidad.Text); } catch(FormatException){ MessageBox.Show("Ingrese una cantidad correcta"); return; } if(cantidad < 1 ){ MessageBox.Show("Ingrese una cantidad positiva"); return; } ParamSet ps = new ParamSet("GESTION_DE_PATOS.ValidarCompraCupon"); ps.AddParameter("@id_promocion", this.cuponesDisponibles.Rows[e.RowIndex].Cells[0].Value.ToString()); ps.AddParameter("@fecha", (String)AppContext.getObject(typeof(String))); ps.AddParameter("@username", s.username); ps.AddParameter("@cantidad", cantidad); SqlParameter retval; retval = ps.execSP(); String ret = retval.Value.ToString(); switch (ret) { case "1": MessageBox.Show("La compra solicitada supera el límite por usuario permitido."); return; case "2": MessageBox.Show("No hay stock para la compra deseada."); return; case "3": MessageBox.Show("El usuario no tiene saldo suficiente."); return; case "0": String mensaje; if (cantidad == 1) { mensaje = "Compra realizada con éxito. \nCupón nro: "; } else { mensaje = "Compra realizada con éxito. \nCupones: "; } SqlParameter r; ps.NombreSP("GESTION_DE_PATOS.ComprarCupon"); mensaje += "\n"; int cambioDeLinea = 0; for (int i = 0; i < cantidad; i++) { if (cambioDeLinea == 10) { mensaje += "\n"; cambioDeLinea = 0; } ps.AddParameter("@id_promocion", this.cuponesDisponibles.Rows[e.RowIndex].Cells[0].Value.ToString()); ps.AddParameter("@fecha", (String)AppContext.getObject(typeof(String))); ps.AddParameter("@username", s.username); r = ps.execSP(); if (i == cantidad-1) { mensaje += r.Value.ToString() + "."; } else { mensaje += r.Value.ToString() + ", "; } Main.actualizar(); cambioDeLinea++; } MessageBox.Show(mensaje); return; } } }
private void setDataGridView() { String proveedor = Proveedores.SelectedItem.ToString(); String fechaActual = (String)AppContext.getObject(typeof(String)); if (proveedor == "") { this.cupones.Columns.Clear(); //todos los proveedores r = dbManager.executeQuery("select id_promocion, p.cuit, descripcion from GESTION_DE_PATOS.Promociones pm JOIN GESTION_DE_PATOS.Proveedores p ON pm.proveedor = p.username where GESTION_DE_PATOS.NombreEstadoPromocion(estado) = 'A publicar' and fecha_vencimiento_oferta >= '" + fechaActual +"' and fecha_publicacion = '" + fechaActual + "'"); cupones.DataSource = r.result; cupones.Columns[2].Width = 300; } else { //un proveedor en particular this.cupones.Columns.Clear(); r = dbManager.executeQuery("select id_promocion, p.cuit, descripcion from GESTION_DE_PATOS.Promociones pm JOIN GESTION_DE_PATOS.Proveedores p ON pm.proveedor = p.username where GESTION_DE_PATOS.NombreEstadoPromocion(estado) = 'A publicar' and p.cuit = '" + proveedor + "'" + "and fecha_vencimiento_oferta >= '" + fechaActual + "' and fecha_publicacion <= '" + fechaActual + "'"); cupones.DataSource = r.result; cupones.Columns[2].Width = 300; } DataGridViewButtonColumn boton = new DataGridViewButtonColumn(); boton.HeaderText = "Publicar"; boton.Name = "Publicar"; cupones.Columns.Add(boton); this.cupones.Columns["Publicar"].ReadOnly = false; }