private void removeFileTypeButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure you want to delete this File Type?", "Remove File Type", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { int fileTypeID; DataGridViewRow fileTypeRow; if (fileTypeGridView.Rows.Count > 0) { fileTypeRow = fileTypeGridView.CurrentRow; fileTypeID = Convert.ToInt32(fileTypeRow.Cells["fileTypeID"].Value); try { FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase); fileTypeDAO.Delete(fileTypeID); SettingsDAO settingsDAO = new SettingsDAO(ConfigurationDatabase); settingsDAO.Delete(fileTypeID); ColumnDAO columnDAO = new ColumnDAO(ConfigurationDatabase); columnDAO.DeleteAll(fileTypeID); HeaderDAO headerDAO = new HeaderDAO(ConfigurationDatabase); headerDAO.DeleteAll(fileTypeID); FooterDAO footerDAO = new FooterDAO(ConfigurationDatabase); footerDAO.DeleteAll(fileTypeID); FileTypes = fileTypeDAO.GetAllFileTypes(); if (FileTypes != null) { fileTypeGridView.Rows.Remove(fileTypeRow); fileTypeGridView.Refresh(); } } catch (Exception exception) { MessageBox.Show("Failed to remove File Source. " + exception.Message, "File Source Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void saveFileTypeButton_Click(object sender, EventArgs e) { try { SettingsDAO settingsDAO = new SettingsDAO(ConfigurationDatabase); settingsDAO.Delete(FileTypeID); settingsDAO.Insert(new Settings(FileTypeID, useFileNameCheckBox.Checked, useFileExtensionCheckBox.Checked, textToIgnoreFileNameTextBox.Text, dateTimeFormatFileNameTextBox.Text, textToIgnoreFileExtensionTextBox.Text, dateTimeFormatFileExtensionTextBox.Text, linkDateTimeCheckBox.Checked, dateTimeColumnTextBox.Text, dateTimeFormatLinkDateTextBox.Text, truncateTableCheckBox.Checked)); ColumnDAO columnDAO = new ColumnDAO(ConfigurationDatabase); columnDAO.DeleteAll(FileTypeID); foreach (DataGridViewRow row in columnDataGridView.Rows) { columnDAO.Insert(new Column(FileTypeID, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString(), Convert.ToBoolean(row.Cells[3].Value), Convert.ToBoolean(row.Cells[4].Value))); } HeaderDAO headerDAO = new HeaderDAO(ConfigurationDatabase); headerDAO.DeleteAll(FileTypeID); foreach (DataGridViewRow row in headerDataGridView.Rows) { headerDAO.Insert(new Header(FileTypeID, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString())); } FooterDAO footerDAO = new FooterDAO(ConfigurationDatabase); footerDAO.DeleteAll(FileTypeID); foreach (DataGridViewRow row in footerDataGridView.Rows) { footerDAO.Insert(new Footer(FileTypeID, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString())); } MessageBox.Show("Successfully saved File Type Configuration!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } catch (Exception exception) { MessageBox.Show("Failed to save Column data. " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }