private void removeFileSourceButton_Click(object sender, EventArgs e) { string fileSourceName; DataGridViewRow fileSourceRow; if (fileSourceGridView.Rows.Count > 0) { fileSourceRow = fileSourceGridView.CurrentRow; fileSourceName = fileSourceRow.Cells["columnName"].Value.ToString(); try { FileSourceDAO fileSourceDAO = new FileSourceDAO(ConfigurationDatabase); fileSourceDAO.Delete(fileSourceName); FileSources = fileSourceDAO.GetAllFileSources(); if (FileSources != null) { fileSourceGridView.Rows.Remove(fileSourceRow); fileSourceGridView.Refresh(); } } catch (Exception exception) { MessageBox.Show("Failed to remove File Source. " + exception.Message, "File Source Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private List <FileSource> GetFileSources() { if (ConfigurationDatabase != null) { FileSourceDAO fileSourceDAO = new FileSourceDAO(ConfigurationDatabase); return(fileSourceDAO.GetAllFileSources()); } return(null); }
private void addButton_Click(object sender, EventArgs e) { try { FileSource source = new FileSource(); if (nameTextBox.Text != "") { source.Name = nameTextBox.Text; } else { MessageBox.Show("Name cannot be an empty string.", "Enter Name", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (directoryTextBox.Text != "") { source.Directory = directoryTextBox.Text; } else { MessageBox.Show("Directory cannot be an empty string.", "Select Directory", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (fileTypeTextBox.Text != "") { source.FileTypeID = Convert.ToInt32(fileTypeTextBox.Text); } else { MessageBox.Show("File Type cannot be an empty string.", "Select Directory", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FileSourceDAO fileSourceDAO = new FileSourceDAO(ConfigurationDatabase); int result = fileSourceDAO.Insert(source); if (result == 0) { source.FileTypeID = 0; } Table.Invoke(new Action(() => Table.Rows.Add(source.FileTypeID, source.Name, source.Directory))); Close(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Failed To Add Source", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void loadConfigurationWorker_DoWork(object sender, DoWorkEventArgs e) { if (!EventLog.SourceExists("File Reader Tool")) { EventLog.CreateEventSource("File Reader Tool", "File Reader Service"); } eventLog = new EventLog(); eventLog.Log = "File Reader Service"; eventLog.Source = "File Reader Tool"; try { ConfigurationDatabase = LocalConfigurationDatabase.GetConfigurationDatabase(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Configuration Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (ConfigurationDatabase != null) { try { CollectionDatabaseConfiguration collectionDatabaseConfiguration = new CollectionDatabaseConfiguration(ConfigurationDatabase); CollectionDatabase = collectionDatabaseConfiguration.GetCollectionDatabase(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Collection Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (CollectionDatabase != null) { try { CollectionDatabase.CreateOpenConnection(); connectedLabel.Invoke(new Action(() => connectedLabel.Text = "Connected")); } catch (Exception exception) { MessageBox.Show(exception.Message, "Collection Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (CollectionDatabase != null) { databaseTypeTextBox.Invoke(new Action(() => databaseTypeTextBox.Text = CollectionDatabase.DatabaseType.ToString())); dataSourceTextBox.Invoke(new Action(() => dataSourceTextBox.Text = CollectionDatabase.DataSource)); hostTextBox.Invoke(new Action(() => hostTextBox.Text = CollectionDatabase.Host)); portTextBox.Invoke(new Action(() => portTextBox.Text = CollectionDatabase.Port.ToString())); usernameTextBox.Invoke(new Action(() => usernameTextBox.Text = CollectionDatabase.Username)); passwordTextBox.Invoke(new Action(() => passwordTextBox.Text = CollectionDatabase.Password)); } try { FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase); FileTypes = fileTypeDAO.GetAllFileTypes(); } catch (Exception exception) { MessageBox.Show("Failed to get File Type Configuration. " + exception.Message, "File Type Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (FileTypes != null) { try { foreach (FileType fileType in FileTypes) { fileTypeGridView.Invoke(new Action(() => fileTypeGridView.Rows.Add(fileType.FileTypeID.ToString(), fileType.Name, fileType.Delimiter, fileType.DatabaseStoredProcedureName))); } } catch (Exception exception) { } } try { FileSourceDAO fileSourceDAO = new FileSourceDAO(ConfigurationDatabase); FileSources = fileSourceDAO.GetAllFileSources(); } catch (Exception exception) { MessageBox.Show("Failed to get File Source Configuration. " + exception.Message, "File Source Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (FileSources != null) { try { foreach (FileSource fileSource in FileSources) { fileSourceGridView.Invoke(new Action(() => fileSourceGridView.Rows.Add(fileSource.FileTypeID.ToString(), fileSource.Name.ToString(), fileSource.Directory.ToString()))); } } catch (Exception exception) { } } } }