Example #1
0
        private void gv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            /*gv.Rows[i].Cells["Stock"].Value = t.Rows[i]["Stock"].ToString();
             *  gv.Rows[i].Cells["Precio"].Value = t.Rows[i]["Precio"].ToString();*/

            if (inicial != 0)
            {
                int    row    = e.RowIndex;
                int    cel    = e.ColumnIndex;
                string codigo = Marca.Codigo_Marca(gv.Rows[row].Cells["Marca"].Value.ToString());

                try
                {
                    Producto p = new Producto(codigo, gv.Rows[row].Cells["Codigo Producto"].Value.ToString());
                    if (gv.Columns[cel].HeaderText == "Stock")
                    {
                        try
                        {
                            int sto = int.Parse(gv.Rows[row].Cells[cel].Value.ToString());
                            p.set_Stock(sto);
                            if (p.update_producto() == 1)
                            {
                            }
                            else
                            {
                                MessageBox.Show("ERROR LIST_PRO 1");
                                Application.Exit();
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Recuerde que el stock tiene que ser un numero entero.");
                            inicial = 0;
                            cargaInicial(vcons);
                        }
                    }
                    else if (gv.Columns[cel].HeaderText == "Precio")
                    {
                        try
                        {
                            gv.Rows[row].Cells[cel].Value = gv.Rows[row].Cells[cel].Value.ToString().Replace(",", ".");
                            //  MessageBox.Show(gv.Rows[row].Cells[cel].Value.ToString());
                            float.Parse(gv.Rows[row].Cells[cel].Value.ToString()).ToString();

                            string pre = gv.Rows[row].Cells[cel].Value.ToString();
                            //     MessageBox.Show(pre);
                            p.set_precio(pre);
                            if (p.update_producto() == 1)
                            {
                            }
                            else
                            {
                                MessageBox.Show("ERROR LIST_PRO 2");
                                Application.Exit();
                            }
                        }
                        catch (Exception) {
                            MessageBox.Show("Recuerde que el Precio tiene que ser un numero, puede contener coma o punto .");
                            inicial = 0;
                            cargaInicial(vcons);
                        }
                    }
                } catch (Exception) { }
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            p.set_CodigoP(textBox1.Text);
            bool   guardar = true;
            string error   = "No se pudo guardar el producto por los siguientes errores:";

            if (comboBox1.SelectedIndex == -1)
            {
                guardar = false;
                error  += "\n * Debe seleccionar una marca existente.";
            }
            else
            {
                p.set_codigoM(Marca.Codigo_Marca(comboBox1.Items[comboBox1.SelectedIndex].ToString()));
                // MessageBox.Show(Marca.Codigo_Marca(comboBox1.Items[comboBox1.SelectedIndex].ToString()));
            }
            if (tipo.SelectedIndex == -1)
            {
                guardar = false;
                error  += "\n * Debe seleccionar un tipo existente.";
            }
            else
            {
                if (tipo.Items[tipo.SelectedIndex].ToString() == "Perfumes")
                {
                    p.set_CodigoT("Perfumes");
                }
                else
                {
                    p.set_CodigoT("Colores");
                }
            }

            if (p.set_NombreP(textBox3.Text) == 0 || textBox3.Text == string.Empty)
            {
                guardar = false;
                error  += "\n * El nombre solo puede tener 300 caracteres y no puede estar vacio.";
            }
            if (p.set_DetalleP(textBox4.Text) == 0 || textBox4.Text == string.Empty)
            {
                guardar = false;
                error  += "\n * El Detalle solo puede tener 300 caracteres y no puede estar vacio.";
            }
            try
            {
                if (p.set_Stock(int.Parse(stock.Text)) == 0)
                {
                    guardar = false;
                    error  += "\n * El stock debe ser mayor o igual a 1.";
                }
            }
            catch (Exception)
            {
                error += "\n * El stock debe ser mayor o igual a 1.";
            }

            if (p.set_precio(precio.Text) == 0)
            {
                guardar = false;
                error  += "\n * El Precio debe ser mayor o igual a 1.";
            }

            if (guardar == true)
            {
                if (p.alta_registro() == 1)
                {
                    MessageBox.Show("Producto Guardado exitosamente.");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Error ALTA_P1");
                    Application.Exit();
                }
            }
            else
            {
                MessageBox.Show(error);
            }
        }