private void updateBtn_Click(object sender, EventArgs e) { int selectedRowIndex = 0; if (table.SelectedCells.Count > 0) { Software.Model.Customer customer = new Software.Model.Customer(); selectedRowIndex = table.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = table.Rows[selectedRowIndex]; customer.Id = Convert.ToInt32(Convert.ToString(selectedRow.Cells["Id"].Value)); customer.Name = nameBox.Text; customer.Contact_No = contactBox.Text; customer.Email = emailBox.Text; customer.Address = addressBox.Text; customer.Type_Id = ((Software.Model.Customer_Type)typeComboBox.SelectedItem).Id; customer.Picture = pictureBox.ImageLocation; Software.Database.SQL.CustomerDB.UpdateCustomer(customer); MetroFramework.MetroMessageBox.Show(this, "Your data has been updated successfully.", "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.CurrentCell = table.Rows[selectedRowIndex].Cells[0]; table.Rows[selectedRowIndex].Selected = true; }
private void createBtn_Click(object sender, EventArgs e) { Software.Model.Customer customer = new Software.Model.Customer(); customer.Name = nameBox.Text; customer.Contact_No = contactBox.Text; customer.Email = emailBox.Text; customer.Address = addressBox.Text; customer.Type_Id = ((Software.Model.Customer_Type)typeComboBox.SelectedItem).Id; customer.Picture = pictureBox.ImageLocation; Software.Database.SQL.CustomerDB.InsertCustomer(customer); MetroFramework.MetroMessageBox.Show(this, "Data has been inserted!", "Successfully Completed", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); }