private void canjearButton_Click(object sender, EventArgs e) { if (this.productosCombo.SelectedIndex == -1) { MessageBox.Show("Seleccione un producto.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (this.cantidadNumeric.Value == 0) { MessageBox.Show("Seleccione una cantidad.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (this.cliente_activo == null) { MessageBox.Show("Debe seleccionar un cliente para realizar un canje.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } int productoId = this.indexer[productosCombo.SelectedIndex]; DAO.connect(); Catalogo producto = DAO.selectOne <Catalogo>(new[] { "id = " + productoId }); if (cantidadNumeric.Value > producto.Stock) { MessageBox.Show("El stock del producto " + producto.Descripcion + " no es suficiente. Solo se dispone de " + producto.Stock + " unidades.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DAO.closeConnection(); return; } if (cantidadNumeric.Value * producto.Costo > cliente_activo.Puntos) { MessageBox.Show("El cliente no dispone de la cantidad de puntos necesaria para canjear la cantidad de productos solicitada.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DAO.closeConnection(); return; } Canje canje = new Canje(); canje.Catalogo_Id = productoId; canje.Cliente_Id = this.cliente_activo.Id; canje.Cantidad = cantidadNumeric.Value; canje.Fecha = Config.SystemConfig.systemDate; producto.Stock -= cantidadNumeric.Value; DAO.insert <Canje>(canje); DAO.update <Catalogo>(producto); DAO.closeConnection(); MessageBox.Show("Canje realizado con exito.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buscarClienteButton.PerformClick(); }
public static void Insertar(Canje canje) { Database db = DatabaseFactory.CreateDatabase("Default"); SqlCommand comando = new SqlCommand("Insertar_Canje"); comando.CommandType = CommandType.StoredProcedure; //Parámetros comando.Parameters.AddWithValue("@IDCLIENTE", canje.cliente.identificacion); comando.Parameters.AddWithValue("@IDCUPON", canje.cupon.id); comando.Parameters.AddWithValue("@IDPRODUCTO", canje.producto.id); db.ExecuteNonQuery(comando); }
public static List <Canje> ObtenerTodos() { List <Canje> lista = new List <Canje>(); DataSet ds = CanjeDatos.SeleccionarTodos(); foreach (DataRow fila in ds.Tables[0].Rows) { Canje registro = new Canje(); registro.id = Convert.ToInt16(fila["ID"]); registro.cliente = ClienteLN.ObtenerPorIdentificacion(Convert.ToString(fila["IDCLIENTE"])); registro.cupon = CuponLN.Obtener(Convert.ToInt16(fila["IDCUPON"])); lista.Add(registro); } return(lista); }
public List <Canje> getHistorialCanje(Cliente cliente) { DatabaseEntity dbEntity = new DatabaseEntity(); List <List <Object> > listaDeListas = dbEntity.spExecuteDataReader("ESECUELE.CanjeHistorial", new List <SqlParameter> { new SqlParameter("@cliente", cliente.Id) }); List <Canje> canjes = new List <Canje>(); listaDeListas.ForEach(row => { Canje canje = new Canje(); canje.Id = (int)row[0]; canje.Fecha = (DateTime)row[1]; canje.Producto = (string)row[2]; canjes.Add(canje); }); return(canjes); }
public static void Insertar(Canje canje) { CanjeDatos.Insertar(canje); }
protected void btnConfirmar_Click(object sender, EventArgs e) { //verificar si hay cliente Cliente cliente = (Cliente)Session["cliente"]; if (cliente != null) { // si hay cliente hace lo siguiente Cupon cupon = new Cupon();; //si el ddlCupon es diferente de null obtiene la información del cupón if (listaClienteCupones != null) { cupon = CuponLN.Obtener(Convert.ToInt16(ddlCupon.SelectedValue)); } //se busca el nivel del cliente ClienteNivel clienteNivel = ClienteNivelLN.ObtenerClienteNivel(cliente.identificacion); //se inserta el cambio en el canje, se pregunta primero si agarró algún cupon if (cupon.id != 0) { //se va a ser el canje sólo si escogió un producto if (producto != null) { Canje canje = new Canje { cliente = cliente, cupon = cupon, producto = producto //el que cliente escogío }; CanjeLN.Insertar(canje); } //actualiza el estado después de realizar el canje ClienteCuponLN.ActualizarEstado(cliente.identificacion, 2); } else { //mensaje lblMensajeCupon.Text = "No se aplicará descuento"; lblMensajeCupon.Visible = true; } //ACERCA DE LOS NIVELES if (clienteNivel.nivel.nombre == "Bronce") { // esta suma es acerca del monto que se compró + el monto meta LO QUE SE BUSCA ES ACTUALIZAR EL MONTO ACTUAL DEL CLIENTE NIVEL int suma = clienteNivel.montoActual + Subtotal(); ClienteNivelLN.Actualizar(cliente.identificacion, suma); ClienteNivel clienteNivel2 = ClienteNivelLN.Obtener(cliente.identificacion); //subir de nivel y asignar cupon if (clienteNivel.nivel.montoMeta < clienteNivel2.montoActual) { Nivel nivel = NivelLN.Obtener(2); ClienteNivelLN.ActualizarNivel(cliente.identificacion, nivel.id); } } else { if (clienteNivel.nivel.nombre == "Plata") { // esta suma es acerca del monto que se compró + el monto meta LO QUE SE BUSCA ES ACTUALIZAR EL MONTO ACTUAL DEL CLIENTE NIVEL int suma = clienteNivel.montoActual + Subtotal(); ClienteNivel clienteNivel2 = ClienteNivelLN.Obtener(cliente.identificacion); //subir de nivel y asignar cupon if (clienteNivel.nivel.montoMeta < clienteNivel2.montoActual) { Nivel nivel = NivelLN.Obtener(3); ClienteNivelLN.ActualizarNivel(cliente.identificacion, nivel.id); } } else { if (clienteNivel.nivel.nombre == "Oro") { // esta suma es acerca del monto que se compró + el monto meta LO QUE SE BUSCA ES ACTUALIZAR EL MONTO ACTUAL DEL CLIENTE NIVEL int suma = clienteNivel.montoActual + Subtotal(); ClienteNivel clienteNivel2 = ClienteNivelLN.Obtener(cliente.identificacion); //subir de nivel y asignar cupon if (clienteNivel.nivel.montoMeta < clienteNivel2.montoActual) { Nivel nivel = NivelLN.Obtener(4); ClienteNivelLN.ActualizarNivel(cliente.identificacion, nivel.id); } } } } int total = 0; //sacar total if (cupon != null) { int descuento = 0; descuento = cupon.descuento / 100; total = Subtotal2() + (producto.precio - descuento); } else { total = Subtotal(); } //lista de compras List <DetPedido> lista = (List <DetPedido>)Session["lista"]; //se insertan los det foreach (DetPedido det in lista) { DetPedidoLN.Insertar(det); } //ahora los det de que ya existen en el enca foreach (DetPedido det in lista) { DetPedido detP = DetPedidoLN.Obtener(det.id); EncaPedido encaPedido = new EncaPedido { cliente = cliente, detPedido = detP, total = total }; EncaPedidoLN.Insertar(encaPedido); } lblMensajeC.Text = "¡Compra exitosa, gracias por preferirnos!"; lblMensajeC.Visible = true; //limpiar la lista limpiarLista(); } else { lblMensaje.Text = "Debe ingresar para continuar con la finalización de la compra"; } }