private void updateBtn_Click(object sender, EventArgs e) { int selectedrowindex = 0; if (table.SelectedCells.Count > 0) { Software.Model.Supplier supplier = new Software.Model.Supplier(); selectedrowindex = table.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = table.Rows[selectedrowindex]; supplier.Id = Convert.ToInt32(Convert.ToString(selectedRow.Cells["Id"].Value)); supplier.Name = nameBox.Text; supplier.Contact_No = contactBox.Text; supplier.Email = emailBox.Text; supplier.Address = addressBox.Text; supplier.Date_Added = dateTime.Value; supplier.Description = descriptionBox.Text; Software.Database.SQL.SupplierDB.UpdateSupplier(supplier); MetroFramework.MetroMessageBox.Show(this, "Your data has been updated.", "Successfully Completed", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MetroFramework.MetroMessageBox.Show(this, "You must select a row to update its value!", "Invalid Selection", MessageBoxButtons.OK, MessageBoxIcon.Information); } DoRefresh(); table.Rows[selectedrowindex].Selected = true; }
private void createBtn_Click(object sender, EventArgs e) { Software.Model.Supplier supplier = new Software.Model.Supplier(); supplier.Name = nameBox.Text; supplier.Contact_No = contactBox.Text; supplier.Email = emailBox.Text; supplier.Address = addressBox.Text; supplier.Date_Added = dateTime.Value; supplier.Description = descriptionBox.Text; Software.Database.SQL.SupplierDB.InsertSupplier(supplier); MetroFramework.MetroMessageBox.Show(this, "Your data has been created.", "Successfully Completed", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); }