// Button 'Save' // Validate input and insert into database private void buttonEditFolioConfirm_Click(object sender, EventArgs e) { // Validate that guest is selcted and folio has items if (listBoxGuest.SelectedIndex > -1 && listBoxFolioItem.Items.Count > 0) { // Reference variables Boolean guestchanged = false; Boolean guestconfirm = true; int guestid = Convert.ToInt32(listBoxGuest.SelectedValue); string adminid = UserInfo.AdminID; // Check if guestid has changed MySqlDataReader getFolioGuest = DBGetData.GetFolioGuest(folioid, guestid); if (getFolioGuest.Read()) { guestchanged = true; } getFolioGuest.Dispose(); // Give warning if guest has changed and ask for confirmation if (!guestchanged) { DialogResult guestDifferent = MessageBox.Show("You have changed the guest for this folio" + "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo); if (guestDifferent == DialogResult.No) { // Cancel edit and reload data guestconfirm = false; LoadDataFolio(); } } if (guestconfirm) { // Add new folio items to folio foreach (DataRowView drv in listBoxFolioItem.Items) { int billingitemid = int.Parse(drv.Row[listBoxFolioItem.ValueMember].ToString()); DBSetData.FolioItemAdd(folioid, billingitemid, adminid); } // Refresh datagridview, close form and display new StatusMessage folioForm.LoadDataFolio(); folioForm.Refresh(); this.Close(); new StatusMessage("Folio populated with " + listBoxFolioItem.Items.Count + " additional items."); } } }