void AddProd(Clases.Productos p) { try { DB = new Clases.IM_DB_Entities(); Clases.Nombres_Productos nombre = DB.Nombres_Productos .Where(np => np.ID_Nombre_Productos == p.NombreProducto).First(); Clases.Clases_Productos cp = DB.Clases_Productos .Where(c => c.ID_CLase == p.Clase).First(); ListProductos_A_Ingresar.Items.Add(p.ID_Producto, 0); ListProductos_A_Ingresar.Items[ListProductos_A_Ingresar.Items.Count - 1].SubItems.Add(nombre.Descripcion); ListProductos_A_Ingresar.Items[ListProductos_A_Ingresar.Items.Count - 1].SubItems.Add(cp.Descripcion); ListProductos_A_Ingresar.Items[ListProductos_A_Ingresar.Items.Count - 1].SubItems.Add(TxtCosto.Text); ListProductos_A_Ingresar.Items[ListProductos_A_Ingresar.Items.Count - 1].SubItems.Add(dtFechaIngreso.Value.Date.ToString()); ListProductos_A_Ingresar.Items[ListProductos_A_Ingresar.Items.Count - 1].Tag = p; } catch (Exception es) { Program.MensajeError(es.Message); return; } }
private void CmdAgregar_Click(object sender, EventArgs e) { if (TxtID_Producto.Text == "") { // MessageBox.Show("Favor Ingrese el ID!", "Info!", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtID_Producto.Focus(); return; } else if (TxtCosto.Text.Trim() == "" || TxtCosto.Text.Trim() == "0") { Program.MensajeError("Verificar el precio de costo!"); return; } if (TxtCosto.Text == "") { MessageBox.Show("Favor Ingrese el precio de costo!", "Info!", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtCosto.Focus(); return; } try { var prd = new Clases.Productos() { ID_Producto = TxtID_Producto.Text.Trim() == "" ? null : TxtID_Producto.Text, Clase = (int)CmbClase.SelectedValue, NombreProducto = (int)CmbNombre.SelectedValue, Fecha_Ingreso = dtFechaIngreso.Value, Precio_Costo = decimal.Parse(TxtCosto.Text), }; if (!Productos_A_Ingresar.Exists(p => p.ID_Producto == prd.ID_Producto)) { Productos_A_Ingresar.Add(prd); } else { Program.MensageInfo("Producto ya registrado"); return; } TxtID_Producto.Text = ""; TxtID_Producto.Focus(); AddProd(prd); //LlenarListaProdsToAdd(); } catch (Exception es) { MessageBox.Show(es.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void ListProductos_A_Ingresar_MouseClick(object sender, MouseEventArgs e) { try { SelectedProd = (Clases.Productos)ListProductos_A_Ingresar.SelectedItems[0].Tag; } catch (Exception es) { MessageBox.Show(es.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void CmdAgregarProd_Click(object sender, EventArgs e) { ListView _LstProds_A_Vender_virtual = new ListView(); try { if (TxtID_Prod.Text.Trim() == "") { //MensajeInfo("No hay producto que agregar!"); TxtID_Prod.Focus(); return; } EsteProducto = DB.Productos.Where(prod => prod.ID_Producto == TxtID_Prod.Text).First(); if (Lista_Prod_A_Vender.Any(p => p.ID_Producto == TxtID_Prod.Text)) { TxtID_Prod.Text = ""; TxtID_Prod.Focus(); return; } if (EsteProducto != null) { Lista_Prod_A_Vender.Add(EsteProducto); //EsteProducto = new Clases.Productos(); } if (LstProds_A_Vender.Items.Count > 0) { _LstProds_A_Vender_virtual = LstProds_A_Vender; } if (_LstProds_A_Vender_virtual.Items.Count == 0) { ActualizarListaProdVenta(); } else { ActualizarListaProdVenta(_LstProds_A_Vender_virtual, EsteProducto); } EsteProducto = new Clases.Productos(); TxtID_Prod.Text = ""; TxtID_Prod.Focus(); } catch (Exception es) { MensajeError(es.Message); } }
private void LstProds_A_Vender_MouseClick(object sender, MouseEventArgs e) { try { EsteProducto = (Clases.Productos)LstProds_A_Vender.SelectedItems[0].Tag; Clases.Nombres_Productos nombre = DB.Nombres_Productos .Where(np => np.ID_Nombre_Productos == EsteProducto.NombreProducto).First(); LblProdSeleccionado.Text = nombre.Descripcion; } catch (Exception es) { MensajeError(es.Message); } }
void ActualizarListaProdVenta(ListView _lstContingencia, Clases.Productos Prod) { try { Clases.Nombres_Productos nombre = DB.Nombres_Productos .Where(np => np.ID_Nombre_Productos == Prod.NombreProducto).First(); Clases.Clases_Productos cp = DB.Clases_Productos .Where(c => c.ID_CLase == Prod.Clase).First(); LstProds_A_Vender = _lstContingencia; LstProds_A_Vender.Items.Add(Prod.ID_Producto, 0); LstProds_A_Vender.Items[LstProds_A_Vender.Items.Count - 1].SubItems.Add(nombre.Descripcion); LstProds_A_Vender.Items[LstProds_A_Vender.Items.Count - 1].SubItems.Add(cp.Descripcion); LstProds_A_Vender.Items[LstProds_A_Vender.Items.Count - 1].SubItems.Add(0.ToString("c")); LstProds_A_Vender.Items[LstProds_A_Vender.Items.Count - 1].Tag = Prod; } catch (Exception es) { MensajeError(es.Message); } }
private void CmdFacturar_Click(object sender, EventArgs e) { if (decimal.Parse(LblTotal.Text) <= 0) { MensajeInfo("El total de la factura esta en 0"); return; } Clases.IM_DB_Entities DB = new Clases.IM_DB_Entities(); Clases.Facturas fact; List <Clases.Ventas> ListaVentas = new List <Clases.Ventas>(); try { if (Lista_Prod_A_Vender.Count > 0) { fact = new Clases.Facturas() { Cant_Articulos = Lista_Prod_A_Vender.Count, Cliente = (string)CmbClientes.SelectedValue, Fecha = DateTime.Now, Monto_Factura = decimal.Parse(LblTotal.Text), vendedor = Program.LoggedUser.Usr_ID.ToString() }; DB.Facturas.Add(fact); foreach (ListViewItem prod in LstProds_A_Vender.Items) { ListaVentas.Add( new Clases.Ventas() { Factura = fact.ID_Factura, Precio_Venta = decimal.Parse(prod.SubItems[3].Text), Producto = prod.SubItems[0].Text, }); } foreach (var item in ListaVentas) { DB.Ventas.Add(item); Clases.Productos Prod = DB.Productos.Where(p => p.ID_Producto == item.Producto).First(); DB.Productos_V.Add(new Clases.Productos_V() { Clase = Prod.Clase, Fecha_Ingreso = fact.Fecha, ID_Producto = Prod.ID_Producto, NombreProducto = Prod.NombreProducto, Precio_Costo = Prod.Precio_Costo }); //DB.Productos.Remove(Prod); } } //DB.SaveChanges(); GuardarArchivo("Factura_" + CmbClientes.Text + "_" + DateTime.Now.ToString("MMddyyyy_hhmm") , Construir__Factura(ListaVentas, CmbClientes.Text)); foreach (var item in ListaVentas) { Clases.Productos _Prod = DB.Productos.Where(p => p.ID_Producto == item.Producto).First(); DB.Productos.Remove(_Prod); } DB.SaveChanges(); MensajeInfo("Facturado!"); Limpiar(); } catch (Exception es) { MensajeError(es.Message); //Limpiar(); } }