//********************************************************************************************// // DELETE MODELS - CLICK DELETE BUTTON EVENT //********************************************************************************************// private void deleteButton_Click(object sender, EventArgs e) { //1. Category if (modeStripStatusLabel.Text == "CATEGORY MODE") { DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this category?" + "\nCategory Name: {0}\nMain Category: {1}", row.Cells["Name"].Value.ToString(), row.Cells["MainCategory"].Value.ToString()), "Delete Category", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { bool result = SqliteDACategory.DeleteCategoryById(Convert.ToInt32(row.Cells["Id"].Value)); if (result == true) { DialogResult dialog = MessageBox.Show("Category was successfully deleted.", "Delete Category", MessageBoxButtons.OK, MessageBoxIcon.Information); mainDataGridView.DataSource = SqliteDACategory.GetAllCategories(); mainDataGridView.AutoResizeColumns(); toggleClickFirstButtons(false); } else { DialogResult dialog = MessageBox.Show("Something went wrong. Category could not be deleted.", "Delete Category Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dialogResult == DialogResult.No) { toggleClickFirstButtons(false); } } //2. Store else if (modeStripStatusLabel.Text == "STORE MODE") { DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this store?" + "\nStore Name: {0}\nLocation: {1}", row.Cells["Name"].Value.ToString(), row.Cells["Location"].Value.ToString()), "Delete Store", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { bool result = SqliteDAStore.DeleteStoreById(Convert.ToInt32(row.Cells["Id"].Value)); if (result == true) { DialogResult dialog = MessageBox.Show("Store was successfully deleted.", "Delete Store", MessageBoxButtons.OK, MessageBoxIcon.Information); mainDataGridView.DataSource = SqliteDAStore.GetAllStores(); mainDataGridView.AutoResizeColumns(); toggleClickFirstButtons(false); } else { DialogResult dialog = MessageBox.Show("Something went wrong. Store could not be deleted.", "Delete Store Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dialogResult == DialogResult.No) { toggleClickFirstButtons(false); } } //3. Product Link else if (modeStripStatusLabel.Text == "PRODUCT LINK MODE") { DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this product link?" + "\nProduct Link Name: {0}\nCategory Name: {1}", row.Cells["Name"].Value.ToString(), row.Cells["CategoryName"].Value.ToString()), "Delete Product Link", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { bool result = SqliteDAProductLink.DeleteProductLinkById(Convert.ToInt32(row.Cells["Id"].Value)); if (result == true) { DialogResult dialog = MessageBox.Show("Product Link was successfully deleted.", "Delete Product Link", MessageBoxButtons.OK, MessageBoxIcon.Information); mainDataGridView.DataSource = SqliteDAProductLink.GetAllProductLinks(); mainDataGridView.AutoResizeColumns(); toggleClickFirstButtons(false); } else { DialogResult dialog = MessageBox.Show("Something went wrong. Product Link could not be deleted.", "Delete Product Link Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dialogResult == DialogResult.No) { toggleClickFirstButtons(false); } } //4. Product else if (modeStripStatusLabel.Text == "PRODUCT MODE") { DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this product?" + "\nBrand Name: {0}\nProduct Description: {1}", row.Cells["BrandName"].Value.ToString(), row.Cells["Description"].Value.ToString()), "Delete Product", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { bool result = SqliteDAProduct.DeleteProductById(Convert.ToInt32(row.Cells["Id"].Value)); if (result == true) { DialogResult dialog = MessageBox.Show("Product was successfully deleted.", "Delete Product", MessageBoxButtons.OK, MessageBoxIcon.Information); mainDataGridView.DataSource = SqliteDAProduct.GetAllProducts(); mainDataGridView.AutoResizeColumns(); toggleClickFirstButtons(false); } else { DialogResult dialog = MessageBox.Show("Something went wrong. Product could not be deleted.", "Delete Product Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dialogResult == DialogResult.No) { toggleClickFirstButtons(false); } } //5. Invoice else if (modeStripStatusLabel.Text == "INVOICE MODE") { DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this invoice?" + "\nInvoice Date: {0}\nInvoice Number: {1}", row.Cells["Date"].Value.ToString(), row.Cells["InvoiceNumber"].Value.ToString()), "Delete Invoice", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { bool result = false; if (row.Cells["Saved"].Value.ToString() == "Open") { //Invoices marked as open will be permanently deleted from the database result = SqliteDAInvoice.DeleteOpenInvoiceById(Convert.ToInt32(row.Cells["Id"].Value)); } else if (row.Cells["Saved"].Value.ToString() == "Saved") { //Invoices marked as saved will be archived (marked as deleted, but still kept in the database). result = SqliteDAInvoice.DeleteSavedInvoiceById(Convert.ToInt32(row.Cells["Id"].Value)); } if (result == true) { DialogResult dialog = MessageBox.Show("Invoice was successfully deleted.", "Delete Invoice", MessageBoxButtons.OK, MessageBoxIcon.Information); mainDataGridView.DataSource = SqliteDAInvoice.GetAllInvoices(); mainDataGridView.AutoResizeColumns(); toggleClickFirstButtons(false); } else { DialogResult dialog = MessageBox.Show("Something went wrong. Invoice could not be deleted.", "Delete Invoice Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dialogResult == DialogResult.No) { toggleClickFirstButtons(false); } } //6. Invoice Product else if (modeStripStatusLabel.Text == "INVOICE PRODUCT MODE") { DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this product from the invoice?" + "\nProduct Name: {0}", row.Cells["ProductName"].Value.ToString()), "Delete Invoice Product", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { bool result = SqliteDAInvoiceProduct.DeleteInvoiceProductById(Convert.ToInt32(row.Cells["Id"].Value)); if (result == true) { DialogResult dialog = MessageBox.Show("Product was successfully deleted from invoice.", "Delete Invoice Product", MessageBoxButtons.OK, MessageBoxIcon.Information); mainDataGridView.DataSource = SqliteDAInvoiceProduct.GetAllInvoiceProductsByInvoiceId(Convert.ToInt32(invoiceNumberStripStatusLabel.Text)); mainDataGridView.AutoResizeColumns(); mainDataGridView.Columns["ProductId"].Visible = false; mainDataGridView.Columns["InvoiceId"].Visible = false; toggleClickFirstButtons(false); } else { DialogResult dialog = MessageBox.Show("Something went wrong. Product could not be deleted from invoice.", "Delete Invoice Product Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (dialogResult == DialogResult.No) { toggleClickFirstButtons(false); } } }