Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text != "" && txtAlias.Text != "" && txtPrice.Text != "")
            {
                Product pProduct = new Product();
                pProduct.Name        = txtName.Text.Trim();
                pProduct.Alias       = txtAlias.Text.Trim();
                pProduct.Description = txtDescription.Text.Trim();
                pProduct.Price       = Convert.ToDecimal(txtPrice.Text);

                int resultado = ProductsDAL.Add(pProduct);
                if (resultado > 0)
                {
                    MessageBox.Show("Producto Guardado Con Exito!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.button3_Click(sender, e);
                }
                else
                {
                    MessageBox.Show("No se pudo guardar el Producto", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Se requieren datos obligatorios", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
 private void tbtBuscar_Click(object sender, EventArgs e)
 {
     if (txtAlias.Text != "")
     {
         dgvProducts.DataSource = ProductsDAL.Search(txtAlias.Text);
     }
 }
 private void dgvProducts_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgvProducts.RowCount > 0 && dgvProducts.CurrentRow != null)
     {
         int     id             = Convert.ToInt32(dgvProducts.CurrentRow.Cells[0].Value);
         Product SelectedClient = ProductsDAL.GetProduct(id);
         this.ProductSelected = SelectedClient.Id;
     }
     else
     {
         MessageBox.Show("debe de seleccionar una fila");
         this.ProductSelected = 0;
     }
 }
        private void button3_Click(object sender, EventArgs e)
        {
            if (this.ProductSelected != 0)
            {
                Product pProduct = new Product();

                pProduct.Name = txtName.Text.Trim();
                pProduct.Alias = txtAlias.Text.Trim();
                pProduct.Description = txtDescription.Text.Trim();
                pProduct.Price = Convert.ToDecimal(txtPrice.Text);
                pProduct.Id = ProductSelected;
                if (ProductsDAL.Delete(pProduct) > 0)
                {
                    MessageBox.Show("Los datos del Producto se eliminaron", "Datos Actualizados", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.button2_Click(sender, e);
                }
                else
                {
                    MessageBox.Show("No se pudo eliminar", "Error al Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                }
            }
        }
 private void button4_Click(object sender, EventArgs e)
 {
     if(txtAlias.Text!="")
         dgvProducts.DataSource = ProductsDAL.Search(txtAlias.Text);
 }