コード例 #1
0
        protected void btnAgregarproducto_Click(object sender, EventArgs e)
        {
            string sRes = ValidarDatos();

            if (sRes == "")
            {
                SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings.Get("connectionString"));
                cn.Open();
                SqlTransaction trx = cn.BeginTransaction();
                try
                {
                    DetalleVenta detalle  = new DetalleVenta();
                    Producto     producto = new Producto();
                    producto.Id = Convert.ToInt32(hdnProductoId.Value);
                    DataSet dsProducto = EditProducto.GetProducto(producto);

                    detalle.Producto         = producto;
                    detalle.VentaId          = Convert.ToInt32(txtVentaId.Text);
                    detalle.PrecioCosto      = Convert.ToDouble(dsProducto.Tables[0].Rows[0]["PrecioCosto"]);
                    detalle.PrecioVendido    = Convert.ToDouble(dsProducto.Tables[0].Rows[0]["PrecioVenta"]);
                    detalle.CantidadUnidades = Convert.ToInt32(txtCantidad.Text);

                    int detalleVentaId = EditDetalleVenta.InsertarDetalle(detalle, trx, cn);
                    if (detalleVentaId > 0)
                    {
                        trx.Commit();
                        CargarDetalleVenta(Convert.ToInt32(txtVentaId.Text));
                        txtStock.Text       = "";
                        txtCantidad.Text    = "";
                        txtProducto.Text    = "";
                        hdnProductoId.Value = "";
                    }
                    else
                    {
                        trx.Rollback();
                        messageBox.ShowMessage("No se pudo insertar el detalle, intente nuevamente");
                    }
                }
                catch (Exception ex)
                {
                    trx.Rollback();
                    messageBox.ShowMessage(ex.Message + ex.StackTrace);
                }
                finally
                {
                    if (null != cn)
                    {
                        cn.Close();
                    }
                }
            }
            else
            {
                messageBox.ShowMessage(sRes);
            }
        }
コード例 #2
0
        private void CargarDatos(int ProductoId)
        {
            Producto producto = new Producto();

            producto.Id = ProductoId;
            DataSet ds = EditProducto.GetProducto(producto);
            DataRow dr = ds.Tables[0].Rows[0];

            txtId.Text = ProductoId.ToString();
            //
            txtCodigo.Text        = dr["Codigo"].ToString();
            txtDescripcion.Text   = dr["Descripcion"].ToString();
            ddlTipo.SelectedValue = dr["TipoId"].ToString();
            //txtColor.Text = dr["ColorDescripcion"].ToString();
            //ddlTalle.SelectedValue = dr["TalleId"].ToString();
            txtPrecioCosto.Text   = dr["PrecioCosto"].ToString();
            txtPorcGanancia.Text  = dr["PorcGanancia"].ToString();
            txtPrecioVenta.Text   = dr["PrecioVenta"].ToString();
            txtStockActual.Text   = dr["StockActual"].ToString();
            txtPorcDescuento.Text = dr["PorcDescuento"].ToString();
            txtCompra.Text        = dr["CompraDescripcion"].ToString();
            hdnCompraId.Value     = dr["CompraId"].ToString();
        }
コード例 #3
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                Producto producto = new Producto();

                producto.Id = Utils.utils.ToInt(txtId.Text);

                producto.Codigo = Utils.utils.ToInt(txtCodigo.Text);


                producto.Descripcion = txtDescripcion.Text;
                producto.Tipo.Id     = Utils.utils.ToInt(ddlTipo.SelectedValue);
                //producto.Talle.Id = Utils.utils.ToInt(ddlTalle.SelectedValue);
                //producto.Color.Descripcion = txtColor.Text;
                producto.PrecioCosto   = Utils.utils.ToDouble(txtPrecioCosto.Text);
                producto.PorcGanancia  = Utils.utils.ToDouble(txtPorcGanancia.Text);
                producto.PrecioVenta   = Utils.utils.ToDouble(txtPrecioVenta.Text);
                producto.StockActual   = Utils.utils.ToDouble(txtStockActual.Text);
                producto.PorcDescuento = Utils.utils.ToDouble(txtPorcDescuento.Text);
                producto.Compra.Id     = Utils.utils.ToInt(hdnCompraId.Value);

                string sResultado = "";
                if (producto.PrecioCosto == 0)
                {
                    sResultado = sResultado + "Precio Costo<br>";
                }
                if (producto.PrecioVenta == 0)
                {
                    sResultado = sResultado + "Precio Venta<br>";
                }
                if (producto.PorcGanancia == 0)
                {
                    sResultado = sResultado + "Porcentaje de Ganancia<br>";
                }
                if (producto.StockActual == 0)
                {
                    sResultado = sResultado + "Stock Actual<br>";
                }

                if (sResultado != "")
                {
                    messageBox.ShowMessage("Falta ingresar los siguientes campos:<br> " + sResultado);
                }
                else
                {
                    if (EditProducto.Actualizar(producto) == 0)
                    {
                        messageBox.ShowMessage("Hubo un error al guardar los datos intente nuevamente");
                    }
                    else
                    {
                        messageBox.ShowMessage("Los datos fueron guardados exitosamente!");
                    }
                }
            }
            catch (Exception ex)
            {
                messageBox.ShowMessage(ex.Message);
            }
        }