Пример #1
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            try
            {
                ModifyProduct mp = new ModifyProduct(this.idioma);

                String id          = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[0].Value.ToString();
                String gender      = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[1].Value.ToString();
                String editorial   = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[2].Value.ToString();
                String precio      = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[3].Value.ToString();
                String name        = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[4].Value.ToString();
                String description = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[5].Value.ToString();
                String stock       = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[6].Value.ToString();

                if (!GestorProducts.existProductOrders(id))
                {
                    mp.id = id;
                    mp.comboGender.SelectedItem    = gender;
                    mp.comboEditorial.SelectedItem = editorial;
                    mp.txtPrice.Text       = precio;
                    mp.txtName.Text        = name;
                    mp.txtDescription.Text = description;
                    mp.txtStock.Text       = stock;
                    mp.ShowDialog();
                }
                else
                {
                    if (this.idioma == "ESPAÑOL")
                    {
                        MessageBox.Show("Este producto está en pedidos en DB");
                    }
                    else
                    {
                        MessageBox.Show("This Product is in Orders in DB");
                    }
                }
                if (mp.IsDisposed)
                {
                    initTable("Where Deleted = 0");
                    comboEditorial.Items.Clear();
                    comboGender.Items.Clear();
                    initComboEditorial("Where Deleted = 0");
                    initComboGender("Where Deleted = 0");
                }
            }catch (Exception ex)
            {
                if (this.idioma == "ESPAÑOL")
                {
                    MessageBox.Show("No hay ninguna fila seleccionada");
                }
                else
                {
                    MessageBox.Show("Unselected any row");
                }
            }
        }
Пример #2
0
 public ActionResult Modificar(int id, Product producto, GestorProducts gp)
 {
     try
     {
         gp.EditarProducto(id, producto);
         return(RedirectToAction(nameof(HomeController.ManageProduct)));
     }
     catch
     {
         return(View(producto));
     }
 }
Пример #3
0
 private String errorDialog()
 {
     if (this.idioma == "ESPAÑOL")
     {
         String error = "Se han encontrado algunos errores: \n";
         if (string.IsNullOrEmpty(txtName.Text))
         {
             error += "\t - El campo \"Nombre\" no puede estar vacio \n";
         }
         if (string.IsNullOrEmpty(txtStock.Text))
         {
             error += "\t - El campo \"Stock\" no puede estar vacio \n";
         }
         if (string.IsNullOrEmpty(txtPrice.Text))
         {
             error += "\t - El campo \"Precio\" no puede estar vacio \n";
         }
         if (!Utils.check.checkPrice(txtPrice.Text))
         {
             error += "\t - El precio no tiene el formato correcto \n";
         }
         if (GestorProducts.existProduct(txtName.Text))
         {
             error += "\t - Ya existe un producto con nombre: " + txtName.Text;
         }
         return(error);
     }
     else
     {
         String error = "Some Errors has been found: \n";
         if (string.IsNullOrEmpty(txtName.Text))
         {
             error += "\t - The field \"Name\" can`t be empty \n";
         }
         if (string.IsNullOrEmpty(txtStock.Text))
         {
             error += "\t - The field \"Stock\" can`t be empty \n";
         }
         if (string.IsNullOrEmpty(txtPrice.Text))
         {
             error += "\t - The field \"Price\" can`t be empty \n";
         }
         if (!Utils.check.checkPrice(txtPrice.Text))
         {
             error += "\t - The Price doesn't the correct format \n";
         }
         if (GestorProducts.existProduct(txtName.Text))
         {
             error += "\t - Already exist a Product with name: " + txtName.Text;
         }
         return(error);
     }
 }
Пример #4
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         String valor = dgvProduct.Rows[dgvProduct.CurrentRow.Index].Cells[0].Value.ToString();
         if (!GestorProducts.existProductOrders(valor))
         {
             if (this.idioma == "ESPAÑOL")
             {
                 if (MessageBox.Show("¿Quieres eliminar este producto?", "Eliminar Producto", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
                     String sql = "update products set Deleted=1 where idproduct =" + valor;
                     GestorProducts.deleteProduct(sql);
                     initTable(" Where Deleted=0");
                 }
             }
             else
             {
                 if (MessageBox.Show("Do yo Want Delete this Product ?", "Delete Product", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
                     String sql = "update products set Deleted=1 where idproduct =" + valor;
                     GestorProducts.deleteProduct(sql);
                     initTable(" Where Deleted=0");
                 }
             }
         }
         else
         {
             if (this.idioma == "ESPAÑOL")
             {
                 MessageBox.Show("Este producto está en pedidos en DB");
             }
             else
             {
                 MessageBox.Show("This Product is in Orders in DB");
             }
         }
     }
     catch (Exception ex)
     {
         if (this.idioma == "ESPAÑOL")
         {
             MessageBox.Show("No hay ninguna fila seleccionada");
         }
         else
         {
             MessageBox.Show("Unselected any row");
         }
     }
 }
Пример #5
0
        public IActionResult Eliminar(int id)
        {
            GestorProducts gp = new GestorProducts();

            try
            {
                gp.EliminarProducto(id);
                return(RedirectToAction(nameof(HomeController.ManageProduct)));
            }
            catch
            {
                return(View());
            }
        }
Пример #6
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            bool price = true;

            if (!Utils.check.checkPrice(txtPrice.Text))
            {
                price = false;
            }
            if (checkAdd() && price)
            {
                Console.WriteLine(inserSql() + " Where IDPRODUCT =" + this.id);
                GestorProducts.updateProduct(inserSql(), this.id);
                Console.WriteLine("TRAZA3");
                Dispose();
            }
            else
            {
                if (this.idioma == "ESPAÑOL")
                {
                    if (!price)
                    {
                        MessageBox.Show(errorDialog() + "\t - El campo \"Precio\"no tiene el formato correcto \n");
                    }
                    else
                    {
                        MessageBox.Show(errorDialog());
                    }
                }
                else
                {
                    if (!price)
                    {
                        MessageBox.Show(errorDialog() + "\t - The field \"Price\"doesn't the correct format \n");
                    }
                    else
                    {
                        MessageBox.Show(errorDialog());
                    }
                }
            }
        }
Пример #7
0
        private void btnAddandNew_Click(object sender, EventArgs e)
        {
            bool price = true;

            if (!Utils.check.checkPrice(txtPrice.Text))
            {
                price = false;
            }
            if (checkAdd() && price)
            {
                GestorProducts.writeProduct(inserSql());
                clean();
            }
            else
            {
                if (this.idioma == "ESPAÑOL")
                {
                    if (!price)
                    {
                        MessageBox.Show(errorDialog() + "\t - El campo \"Precio\"no tiene el formato correcto \n");
                    }
                    else
                    {
                        MessageBox.Show(errorDialog());
                    }
                }
                else
                {
                    if (!price)
                    {
                        MessageBox.Show(errorDialog() + "\t - The field \"Price\"doesn't the correct format \n");
                    }
                    else
                    {
                        MessageBox.Show(errorDialog());
                    }
                }
            }
        }
 public IActionResult ManageProduct(GestorProducts gp, Product p)
 {
     gp.AgregarProducto(p);
     return(View(gp));
 }
Пример #9
0
 public Product()
 {
     g = new GestorProducts();
 }
Пример #10
0
        public ActionResult Modificar(int id, GestorProducts gp)
        {
            Product producto = gp.ObtenerProducto(id);

            return(View(producto));
        }