Exemple #1
0
        private void txtBarCodeArticulo_TextChanged(object sender, EventArgs e)
        {
            String barcode = txtBarCodeArticulo.Text;
            //ClienteNEG bl = new ClienteNEG();
            Articulo a = ArticuloNEG.Instancia().ObtenerArticulo(barcode);

            txtNombreArticulo.Text     = a.Nombre;
            codigoArticuloSeleccionado = a.idArticulo;


            //DetalleIngresoAlmacen d = new DetalleIngresoAlmacen();
            //int stockFinal = IngresoAlmacenNEG.ObtenerStockActual(Convert.ToInt32(row.Cells["idArticulo"].Value));

            //DetalleStockTienda dStockFinal = StockTiendaNEG.Instancia().ObtenerStockActual(codigoArticuloSeleccionado);
            //txtStockActual.Text = dStockFinal.StockFinal.ToString();

            DetalleIngresoAlmacen dStockFinal = IngresoAlmacenNEG.Instancia().ObtenerStockActual(codigoArticuloSeleccionado);

            txtStockActual.Text = dStockFinal.CantidadFinal.ToString();

            DetalleIngresoAlmacen dPrecioActual = DetalleIngresoNEG.Instancia().obtenerPrecioVenta(codigoArticuloSeleccionado);

            txtPrecio.Text = dPrecioActual.PrecioVenta.ToString();

            //Cerrando el formulario
        }
        public DetalleIngresoAlmacen obtenerPrecioVenta(int id)
        {
            string sql = @"SELECT TOP 1 PrecioVenta, idDetalleIngresoAlmacen FROM DetalleIngresoAlmacen WHERE idArticulo like @id ORDER BY idDetalleIngresoAlmacen DESC;";


            SqlConnection con = Conexion.Instancia().conectar();
            //SqlConnection con = new SqlConnection(Properties.Settings.Default.con);
            SqlCommand command = new SqlCommand(sql, con);

            //string hash = Helper.EncodePassword(string.Concat(usuario, password));
            //command.Parameters.AddWithValue("@password", hash);
            command.Parameters.AddWithValue("id", id);
            con.Open();

            DetalleIngresoAlmacen obj = new DetalleIngresoAlmacen();

            SqlDataReader dr = command.ExecuteReader();

            while (dr.Read())
            {
                if (dr["PrecioVenta"].ToString() == "")
                {
                    obj.PrecioVenta = 0;
                }
                else
                {
                    obj.PrecioVenta = (Decimal)dr["PrecioVenta"];
                }
                obj.idDetalleIngresoAlmacen = (Int32)dr["idDetalleIngresoAlmacen"];
            }
            con.Close();
            return(obj);
        }
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            if (txtCodigo.Text == "")
            {
                StockTienda c = new StockTienda();
                c.FechaIngresoTienda = dtpFechaIngreso.Value;
                //c.idCliente = codigoClienteSeleccionado;
                c.idUsuario = idUsuario;


                if (radActivo.Enabled == true)
                {
                    c.Estado = true;
                }
                else if (radInactivo.Enabled == true)
                {
                    c.Estado = false;
                }


                foreach (DataGridViewRow row in dgvDetalleStock.Rows)
                {
                    DetalleStockTienda de          = new DetalleStockTienda();
                    DetalleStockTienda dStockFinal = StockTiendaNEG.Instancia().ObtenerStockActual(Convert.ToInt32(row.Cells["idArticulo"].Value));


                    de.idArticulo = Convert.ToInt32(row.Cells["idArticulo"].Value);
                    DetalleIngresoAlmacen dPrecioActual = DetalleIngresoNEG.Instancia().obtenerPrecioVenta(de.idArticulo);
                    int cantidad = Convert.ToInt32(row.Cells["cantidad"].Value);
                    de.idDetalleIngresoAlmacen = dPrecioActual.idDetalleIngresoAlmacen;

                    de.StockInicial = Convert.ToInt32(row.Cells["cantidad"].Value);
                    de.StockFinal   = Convert.ToInt32(row.Cells["cantidad"].Value) + dStockFinal.StockFinal;
                    VentaNEG.Instancia().reducirStock(de.idArticulo, cantidad);
                    c.Lineas.Add(de);
                }



                StockTiendaNEG.RegistrarIngresoTienda(c);

                MessageBox.Show("El ingreso de Stock a Tienda fue exitoso.");
                this.Dispose();
            }

            else
            {
                if (radInactivo.Checked == true)
                {
                }

                this.Dispose();
            }
        }
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            if (this.codigoProveedorSeleccionado == -1)
            {
                this.mError("No ha seleccionado aún ningun Proveedor");
            }
            else
            {
                IngresoAlmacen c = new IngresoAlmacen();
                c.idTipoComprobante = cboTipoComprobante.SelectedIndex + 1;
                c.FechaIngreso      = dtpIngresoAlmacen.Value;
                c.idProveedor       = codigoProveedorSeleccionado;
                c.Serie             = txtSerie.Text;
                c.NroDocumento      = txtCorrelativo.Text;
                c.TotalPagado       = totalInvertido;
                c.igv       = igv;
                c.idUsuario = idUsuario;
                //c.numero = Convert.ToInt32(txtNumero.Text);
                c.subTotal = sub;

                if (radActivo.Enabled == true)
                {
                    c.Estado = true;
                }
                else if (radInactivo.Enabled == true)
                {
                    c.Estado = false;
                }


                foreach (DataGridViewRow row in dgvDetalle.Rows)
                {
                    DetalleIngresoAlmacen d = new DetalleIngresoAlmacen();
                    //int stockFinal = IngresoAlmacenNEG.ObtenerStockActual(Convert.ToInt32(row.Cells["idArticulo"].Value));
                    DetalleIngresoAlmacen dStockFinal = IngresoAlmacenNEG.Instancia().ObtenerStockActual(Convert.ToInt32(row.Cells["idArticulo"].Value));
                    d.idArticulo    = Convert.ToInt32(row.Cells["idArticulo"].Value);
                    d.PrecioCompra  = Convert.ToDecimal(row.Cells["PUCompra"].Value);
                    d.PrecioVenta   = Convert.ToDecimal(row.Cells["PUVenta"].Value);
                    d.Cantidad      = Convert.ToInt32(row.Cells["Cantidad"].Value);
                    d.CantidadFinal = Convert.ToInt32(row.Cells["Cantidad"].Value) + dStockFinal.CantidadFinal;
                    c.Lineas.Add(d);
                }

                IngresoAlmacenNEG.RegistrarIngreso(c);
                MessageBox.Show("El Ingreso se registro correctamente.");

                DialogResult result = MessageBox.Show("Desea realizar un nuevo ingreso?", "Ingreso", MessageBoxButtons.YesNo, MessageBoxIcon.Question);


                if (result == DialogResult.Yes)
                {
                    txtCodigoArticulo.Clear();
                    txtCodigo.Clear();
                    txtCorrelativo.Clear();
                    txtNombreArticulo.Clear();
                    txtNombreProveedor.Clear();
                    txtPrecioCompra.Clear();
                    txtPrecioVenta.Clear();

                    txtSerie.Clear();

                    nudCantidad.Value = 1;


                    foreach (DataGridViewRow row in dgvDetalle.Rows)
                    {
                        //Indice dila actualmente seleccionado y que vamos a eliminar
                        int indiceFila = this.dgvDetalle.CurrentCell.RowIndex;
                        //Fila que vamos a eliminar
                        DataRow row2 = this.dtDetalle.Rows[indiceFila];
                        //Disminuimos el total a pagar
                        this.totalInvertido         = this.totalInvertido - Convert.ToDecimal(row2["subTotal"].ToString());
                        this.lblTotalInvertido.Text = "Total Pagar: S/." + totalInvertido.ToString("#0.00#");
                        //Removemos la fila
                        this.dtDetalle.Rows.Remove(row2);
                    }

                    this.lblTotalInvertido.Text = "Total Invertido: S/. 0.00";
                }
                else
                {
                    this.Dispose();
                }
            }
        }