private void BtnUpdate_Click(object sender, EventArgs e) { try { if (txtDescription.Text != string.Empty && txtName.Text != string.Empty) { string strQuery = $"update Categorias set Nombre='{txtName.Text}',Descripcion = '{txtDescription.Text}' where id_categoria ={dgvCategorys.Rows[dgvCategorys.CurrentRow.Index].Cells[0].Value.ToString()} "; frmInformation frmUpdateResult = new frmInformation("¿Actualizar categoria?"); DialogResult result = new DialogResult(); result = frmUpdateResult.ShowDialog(); if (result == DialogResult.OK) { DB.ExecuteQuery(strQuery); frmRealizado frmCheced = new frmRealizado("Registro actualizado con exito"); result = frmCheced.ShowDialog(); if (result == DialogResult.OK) { frmCheced.Close(); dgvCategorys.DataSource = getInfoCategory(); dgvCategorys.Columns["id_categoria"].Visible = false; txtDescription.Text = ""; txtName.Text = ""; } } } else { MessageBox.Show("Rellene los Campos", "Campos Vacios", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { throw; } }
private void bunifuFlatButton1_Click(object sender, EventArgs e) { try { if (txtDescription.Text != string.Empty && txtName.Text != string.Empty) { string strQuery = $"insert into Categorias Values ('{txtName.Text}','{txtDescription.Text}')"; DB.ExecuteQuery(strQuery); frmRealizado frmChecked = new frmRealizado("Categoria Agregada"); DialogResult Result = new DialogResult(); Result = frmChecked.ShowDialog(); if (Result == DialogResult.OK) { frmChecked.Close(); dgvCategorys.DataSource = getInfoCategory(); dgvCategorys.Columns["id_categoria"].Visible = false; txtDescription.Text = ""; txtName.Text = ""; } } else { MessageBox.Show("Rellene los campos Vacios", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { throw; } }
private void UpdateProduct() { if (txtName.Text != string.Empty && textBox1.Text != string.Empty && txtPriceSale.Text != string.Empty && txtDescription.Text != string.Empty) { string strQuery = $@"update Producto set Nombre='{txtName.Text}',Descripcion='{txtDescription.Text}',Precio_Unitario={textBox1.Text.Replace(",",".")},Precio_Compra={txtPriceSale.Text.Replace(",", ".")}, Categoria={CmCategory.SelectedValue.ToString()} where id_producto={dgvProducts.Rows[dgvProducts.CurrentRow.Index].Cells[0].Value.ToString()}"; frmInformation frmUpdate = new frmInformation("Actualzar Producto"); DialogResult result = new DialogResult(); result = frmUpdate.ShowDialog(); if (result == DialogResult.OK) { DB.ExecuteQuery(strQuery); frmRealizado frmCheked = new frmRealizado("Producto Actualizado"); result = frmCheked.ShowDialog(); if (result == DialogResult.OK) { txtDescription.Text = ""; txtName.Text = ""; txtPriceSale.Text = ""; textBox1.Text = ""; UpdateTable(); } } } else { MessageBox.Show("Rellene los Campos", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void DeleteProduct() { try { if (txtName.Text != string.Empty && textBox1.Text != string.Empty && txtPriceSale.Text != string.Empty && txtDescription.Text != string.Empty) { string strQuery = $"Delete from Producto where id_producto={dgvProducts.Rows[dgvProducts.CurrentRow.Index].Cells[0].Value.ToString()}"; frmInformation frmDelete = new frmInformation("¿Eliminar Producto?"); DialogResult result = new DialogResult(); result = frmDelete.ShowDialog(); if (result == DialogResult.OK) { DB.ExecuteQuery(strQuery); UpdateTable(); frmRealizado frmchecked = new frmRealizado("Producto Eliminado"); result = frmchecked.ShowDialog(); if (result == DialogResult.OK) { txtDescription.Text = ""; txtName.Text = ""; txtPriceSale.Text = ""; textBox1.Text = ""; } } } else { MessageBox.Show("Rellene los Campos", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { throw; } }
//Metodos del CRUD private void AddProduct() { if (txtName.Text != string.Empty && textBox1.Text != string.Empty && txtPriceSale.Text != string.Empty && txtDescription.Text != string.Empty) { string strSQL = $"insert into Producto Values ('{txtName.Text}','{txtDescription.Text}',{textBox1.Text},{CmCategory.SelectedValue.ToString()},{txtPriceSale.Text})"; DB.ExecuteQuery(strSQL); frmRealizado MensajeExitoso = new frmRealizado("Producto Agregado"); DialogResult Result = new DialogResult(); Result = MensajeExitoso.ShowDialog(); if (Result == DialogResult.OK) { MensajeExitoso.Close(); txtDescription.Text = ""; txtName.Text = ""; txtPriceSale.Text = ""; textBox1.Text = ""; } } else { MessageBox.Show("Rellene los Campos", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void BtnDelete_Click(object sender, EventArgs e) { try { if (txtDescription.Text != string.Empty && txtName.Text != string.Empty) { string strQuery = $"Delete from Categorias where Nombre ='{txtName.Text}' and Descripcion = '{txtDescription.Text}'"; DialogResult result = new DialogResult(); frmInformation frmDelete = new frmInformation("¿Eliminar Categoria?"); result = frmDelete.ShowDialog(); if (result == DialogResult.OK) { frmDelete.Close(); DB.ExecuteQuery(strQuery); frmRealizado frmChecked = new frmRealizado("Categoria Eliminada"); result = frmChecked.ShowDialog(); if (result == DialogResult.OK) { frmChecked.Close(); dgvCategorys.DataSource = getInfoCategory(); dgvCategorys.Columns.Remove("id_categoria"); txtDescription.Text = ""; txtName.Text = ""; } } } else { MessageBox.Show("Rellene los campos", "Campos Vacios", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { throw; } }