private void dgvProducts_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var row = dgvProducts.CurrentRow; //Obtiene la fila seleccionada

            if (row == null || row.Index == -1 || e.RowIndex == -1)
            {
                return;
            }

            //Obtiene los datos de la fila seleccioanda y la convierte a objeto de PRODUCTO
            var idProduct    = int.Parse(row.Cells[0].Value.ToString());
            var nameProduct  = row.Cells[1].Value.ToString();
            var initialPrice = decimal.Parse(row.Cells[2].Value.ToString());
            var pointsValue  = int.Parse(row.Cells[3].Value.ToString());
            var image        = DataControl.Base64StringToImage(row.Cells[4].Value.ToString());

            var product = new Product
            {
                IdProduct    = idProduct,
                Name         = nameProduct,
                Price        = initialPrice,
                Points       = pointsValue,
                ImageProduct = image
            };

            var form = new FrmProduct(product, this); //Instancia un nuevo formulario para agregar productos

            form.Show();                              //Abre el formulario
        }
Esempio n. 2
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            var childProducts = new ChildMainProducts();

            if (pnlDashboard.Controls.Count > 0)                                     //Si el panel principal contiene un Formulario hijo
            {
                if (pnlDashboard.Controls[0].GetType() != typeof(ChildMainProducts)) //Si el tipo de formulario es diferente a ChildMenuProducts
                {
                    OpenChildForm(childProducts);                                    //Agrega un nuevo formulario de childMenuProducts
                }
                else
                {
                    childProducts = (ChildMainProducts)pnlDashboard.Controls[0];
                }
            }
            else
            {
                OpenChildForm(childProducts);
            }
            var form = new FrmProduct(childProducts);

            form.Show();
        }