private void btnDeleteEntry_Click(object sender, EventArgs e) { var isUsed = false; var dbDocsTableOutput = new StringBuilder(); var outputFolder = Application.ExecutablePath; // Strip the Executable name from the path outputFolder = outputFolder.Substring(0, outputFolder.LastIndexOf(@"\", StringComparison.Ordinal)); if (lstsubtables.SelectedIndex > 0) { // Need to check whether the subtable is used or not if (ProgSettings.IsSubtableInTable(lstsubtables.Text)) { isUsed = true; } if (ProgSettings.IsSubtableLocalisedInTable(lstsubtables.Text)) { isUsed = true; } if (ProgSettings.IsSubtableInField(lstsubtables.Text)) { isUsed = true; } if (ProgSettings.IsSubtableLocalisedInField(lstsubtables.Text)) { isUsed = true; } if (isUsed) { return; } if (MessageBox.Show(@"Are you sure you wish to delete this subtable ?", @"Delete Subtable", MessageBoxButtons.YesNo) == DialogResult.Yes) { MessageBox.Show(@"deleted subtable ?", @"Deleted Subtable", MessageBoxButtons.OK); if (lstLangs.SelectedIndex == 0) { // If English, connect to main table dbDocsTableOutput.Append("DELETE FROM dbdocssubtables where subTableId=" + lstsubtables.SelectedIndex + ";"); // Open the file for append and write the entries to it using ( var outfile = new StreamWriter(outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables.SQL", true)) { outfile.Write(dbDocsTableOutput.ToString()); } ProgSettings.SubTableDelete(lstsubtables.Text, lstLangs.SelectedIndex); lstsubtables.Items.Remove(lstsubtables.SelectedIndex); } else { dbDocsTableOutput.Append("DELETE FROM dbdocssubtables_localised where languageid=" + lstLangs.SelectedIndex + "and subTableId=" + lstsubtables.SelectedIndex + ";"); // Open the file for append and write the entries to it using ( var outfile = new StreamWriter( outputFolder + @"\" + ProgSettings.DbName + "_dbdocssubtables_localised.SQL", true)) { outfile.Write(dbDocsTableOutput.ToString()); } ProgSettings.SubTableDelete(lstsubtables.Text, lstLangs.SelectedIndex); lstsubtables.Items.Remove(lstsubtables.SelectedIndex); } } } else { MessageBox.Show(@"No subtable to delete?", @"Deleted Subtable", MessageBoxButtons.OK); } }