Beispiel #1
0
    protected void btnAgregaPrecio_Click(object sender, EventArgs e)
    {
        lblErrorNuevo.Text = "";
        try
        {
            PreciosVenta precio = new PreciosVenta();
            precio.Producto = lblClaveProductoP.Text;
            decimal precioVenta = 0;
            try {
                precioVenta   = Convert.ToDecimal(txtVenta.Text);
                precio.Precio = precioVenta;
                if (!chkTodos.Checked)
                {
                    try { usuarioLog = Convert.ToString(Request.QueryString["u"]); }
                    catch (Exception) { usuarioLog = ""; }
                    if (usuarioLog != "")
                    {
                        precio.Usuario = usuarioLog;
                        precio.Almacen = Convert.ToInt32(ddlIsla.SelectedValue);
                        precio.agregaPrecioVenta();
                        if (precio.Agregado)
                        {
                            CatalogProductos productoCat = new CatalogProductos();
                            productoCat.Producto = lblClaveProductoP.Text.ToUpper();
                            productoCat.actualizaUltimoCosto(Convert.ToInt32(ddlIsla.SelectedValue));


                            txtVenta.Text           = "";
                            chkTodos.Checked        = false;
                            ddlIsla.Enabled         = true;
                            GridView2.SelectedIndex = -1;
                            GridView2.DataBind();
                            GridView3.DataBind();
                        }
                        else
                        {
                            lblErrorNuevo.Text = "El precio ingresado ya existe o se produjo un error al intentar agregar el precio";
                        }
                    }
                    else
                    {
                        lblErrorNuevo.Text = "Su sesión a caducado por favor vuelva a ingresar";
                    }
                }
                else
                {
                    try { usuarioLog = Convert.ToString(Request.QueryString["u"]); }
                    catch (Exception) { usuarioLog = ""; }
                    if (usuarioLog != "")
                    {
                        DataSet islasProd = new DataSet();
                        Islas   islas     = new Islas();
                        islas.obtieneIslas();
                        islasProd = islas.IslasAgregar;

                        int agregados, noAgregados;
                        agregados = noAgregados = 0;
                        foreach (DataRow fila in islasProd.Tables[0].Rows)
                        {
                            int islaReg = Convert.ToInt32(fila[0].ToString());
                            precio.Usuario = usuarioLog;
                            precio.Almacen = islaReg;

                            precio.agregaPrecioVenta();
                            if (!precio.Agregado)
                            {
                                noAgregados++;
                            }
                            else
                            {
                                agregados++;
                            }
                            CatalogProductos productoCat = new CatalogProductos();
                            productoCat.Producto = lblClaveProductoP.Text.ToUpper();
                            productoCat.actualizaUltimoCosto(islaReg);
                        }
                        lblErrorNuevo.Text      = "Se agregó el precio de venta a " + agregados.ToString() + " Tiendas de " + (agregados + noAgregados).ToString() + ".";
                        txtVenta.Text           = "";
                        chkTodos.Checked        = false;
                        ddlIsla.Enabled         = true;
                        GridView2.SelectedIndex = -1;
                        GridView2.DataBind();
                        GridView3.DataBind();
                    }
                    else
                    {
                        lblErrorNuevo.Text = "Su sesión a caducado por favor vuelva a ingresar";
                    }
                }
            }
            catch (Exception) { lblErrorNuevo.Text = "El precio de venta no es un monto válido"; }
        }
        catch (Exception ex) {
            lblErrorNuevo.Text = "Error al agregar precio de venta: " + ex.Message;
        }
    }
Beispiel #2
0
    protected void btnAgregar_Click(object sender, EventArgs e)
    {
        lblErrores.Text = "";

        CatalogProductos productoCat = new CatalogProductos();

        productoCat.Producto = txtClave.Text.ToUpper();
        productoCat.verificaExiste();
        bool existeUsuario = productoCat.Existe;

        if (!existeUsuario)
        {
            decimal precio = -1;
            if (txtPrecioVenta.Text == "")
            {
                precio = 0;
            }
            else
            {
                try { precio = Convert.ToDecimal(txtPrecioVenta.Text); }
                catch (Exception)
                {
                    precio = -1;
                }
                if (precio != -1)
                {
                    try
                    {
                        string sql     = "insert into catproductos(idProducto, descripcion, idMedida, idFamilia, idLinea, detalles, observaciones, estatus, porCosto, id_categoria, granel,IVA) values(@clave, @descripcion, @idMedida, @idFamilia, @idLinea, @detalles, @observaciones, 'A', 0, @id_categoria, @granel,@IVA) ";
                        Islas  tiendas = new Islas();
                        tiendas.obtieneIslas();
                        DataSet infoTiendas = tiendas.IslasAgregar;
                        foreach (DataRow fila in infoTiendas.Tables[0].Rows)
                        {
                            sql = sql + " insert into articulosalmacen select " + fila[0].ToString() + ",idproducto,0,0,1,1,'...',1,null,null,null,null from catproductos where idproducto not in((select idarticulo from articulosalmacen where idalmacen =  " + fila[0].ToString() + ")) ";
                        }

                        SqlDataSource1.InsertCommand = sql;
                        SqlDataSource1.InsertParameters.Add("clave", txtClave.Text.ToUpper());
                        SqlDataSource1.InsertParameters.Add("descripcion", txtDescripcion.Text);
                        SqlDataSource1.InsertParameters.Add("idMedida", ddlUnidad.SelectedValue);
                        SqlDataSource1.InsertParameters.Add("id_categoria", ddlCategoria.SelectedValue);
                        SqlDataSource1.InsertParameters.Add("idFamilia", ddlFamilia.SelectedValue);
                        SqlDataSource1.InsertParameters.Add("idLinea", ddlLinea.SelectedValue);
                        SqlDataSource1.InsertParameters.Add("detalles", txtDetalles.Text);
                        SqlDataSource1.InsertParameters.Add("observaciones", txtObservaciones.Text);
                        string granel = "0";
                        if (chkGranel.Checked)
                        {
                            granel = "1";
                        }
                        SqlDataSource1.InsertParameters.Add("granel", granel);
                        string IVA = "0";
                        if (chkGranel.Checked)
                        {
                            IVA = "1";
                        }
                        SqlDataSource1.InsertParameters.Add("IVA", IVA);

                        SqlDataSource1.Insert();
                        Islas islas = new Islas();
                        islas.obtieneIslas();
                        DataSet islasPrecios = new DataSet();
                        islasPrecios = islas.IslasAgregar;

                        try { usuarioLog = Convert.ToString(Request.QueryString["u"]); }
                        catch (Exception) { usuarioLog = ""; }
                        if (usuarioLog != "")
                        {
                            int agregados, noAgregados;
                            agregados = noAgregados = 0;
                            foreach (DataRow fila in islasPrecios.Tables[0].Rows)
                            {
                                int          islaReg     = Convert.ToInt32(fila[0].ToString());
                                PreciosVenta precioVenta = new PreciosVenta();
                                precioVenta.Producto = txtClave.Text.ToUpper();
                                precioVenta.Precio   = precio;
                                precioVenta.Usuario  = usuarioLog;
                                precioVenta.Almacen  = islaReg;

                                precioVenta.agregaPrecioVenta();
                                if (!precioVenta.Agregado)
                                {
                                    noAgregados++;
                                }
                                else
                                {
                                    agregados++;
                                }
                            }
                            lblErrores.Text = "Se agregó el precio de venta a " + agregados.ToString() + " islas de " + (agregados + noAgregados).ToString() + ".";

                            islas.obtieneIslas();
                            DataSet islasAlta = islas.IslasAgregar;
                            foreach (DataRow r in islasAlta.Tables[0].Rows)
                            {
                                islas.agregaAlamacen(r[0].ToString());
                            }

                            llenaGrid();
                            txtClave.Text = txtDescripcion.Text = txtDetalles.Text = txtObservaciones.Text = txtPrecioVenta.Text = "";
                            ddlUnidad.Items.Clear();
                            ddlCategoria.Items.Clear();
                            ddlFamilia.Items.Clear();
                            ddlLinea.Items.Clear();
                            ddlUnidad.DataBind();
                            ddlCategoria.DataBind();
                            ddlFamilia.DataBind();
                            ddlLinea.DataBind();
                            ddlUnidad.SelectedValue    = "";
                            ddlCategoria.SelectedIndex = 0;
                            ddlFamilia.SelectedValue   = "";
                            ddlLinea.SelectedValue     = "";
                        }
                        else
                        {
                            lblErrores.Text = "Su sesión a caducado, por favor vuelva a ingresar.";
                        }
                    }
                    catch (Exception ex)
                    {
                        lblErrores.Text = "Error al agregar el Producto " + txtClave.Text + " - " + txtDescripcion.Text + ": " + ex.Message;
                    }
                }
                else
                {
                    lblErrores.Text = "El precio de venta no es correcto, verifique";
                }
            }
        }
        else
        {
            lblErrores.Text = "El producto a ingresar ya se encuentra registrado";
        }
    }