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; } }
//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; } }