public void LogIn() { var loginForm = new LogInView(_appConfig); DialogResult result = loginForm.ShowDialog(); if (result == DialogResult.OK) { _appConfig = loginForm.AppConfig; _presenter = new ExcelPresenter(_application, new DatabaseConnectionFactory().CreateDbConnection(_appConfig.DatabaseType, _appConfig.ConnectionString), new SqlGeneratorFactory().CreateSqlGenerator(_appConfig.DatabaseType), _workbookPropertiesConfig); } }
//public void verifyReportStructure() //{ // // dict of missing structure and related message to display to user // Dictionary<string, string> errors = new Dictionary<string, string>(); // // check for Data worsheet // try // { // Excel.Worksheet sheet = app.ActiveWorkbook.Sheets["Data"]; // } // catch (Exception) // { // errors["Data Worksheet"] = "A worksheet named 'Data' does not exist"; // } // // check for startCell // try // { // Excel.Range range = app.ActiveWorkbook.Sheets["Data"].Range["startCell"]; // } // catch (Exception) // { // errors["Start Cell"] = "Named range, 'startCell', does not exist in Data worksheet"; // } // // check that each pivot table's data source exists (truncate pivot table's name and search) // foreach (Excel.PivotTable pt in app.ActiveWorkbook.PivotTables) // { // string sourceSheetName = pt.Name.Substring(0, pt.Name.IndexOf("__")); // try // { // Excel.Worksheet sourceSheet = app.ActiveWorkbook.Sheets[sourceSheetName]; // } // catch (Exception) // { // errors[sourceSheetName] = string.Format("{0} is not a sheet in this workbook. If left uncorrected, this pivot table will not update " + // "when expected", sourceSheetName); // } // } // // check that Properties worksheet exists // try // { // Excel.Worksheet sheet = app.ActiveWorkbook.Sheets["Properties"]; // } // catch (Exception) // { // errors["Properties Worksheet"] = "A worksheet named 'Properties' does not exist"; // } // // check that each workbook property exists in Properties worksheet // foreach (string property in wBookPropertiesConfig.properties.Keys) // { // try // { // Excel.Range range = app.ActiveWorkbook.Sheets["Properties"].Range[property]; // } // catch (Exception) // { // errors[property] = string.Format("Named range, '{0}', does not exist in the Properties worksheet", property); // } // } // // show message box with 1) missing structure and 2) related message // if (errors.Count > 0) // { // string message = "The following errors should be fixed before the workbook is saved:\r\n"; // foreach (KeyValuePair<string, string> error in errors) // { // message += string.Format("***{0}: {1}\r\n", error.Key, error.Value); // } // MessageBox.Show(message, "Report Structure Errors", MessageBoxButtons.OK); // } // else // { // MessageBox.Show("Report structure is correct!", "Report Structure Check", MessageBoxButtons.OK); // } //} //public void addCellMapping() //{ // //not implemented yet //} //public void deleteCellMapping() //{ // //not implemented yet //} public Hashtable EditConfiguration(IList <string> dbConnStrings) { var editConfig = new ConfigurationEditorView(dbConnStrings); DialogResult result = editConfig.ShowDialog(); if (result == DialogResult.OK) { // wipe appConfig object, which reloads the ConnectionString and SQL_getAvailableTables settings set above var defaultDatabaseType = editConfig.DefaultConnectionDatabaseType; var availableTablesSQL = AvailableTablesSql.availableTablesSql[defaultDatabaseType]; var defaultConnectionString = editConfig.DefaultConnectionString; // Update class fields with new default connection string, availableTablesSQL, and database type (don't update _application field, though) // Updating the _presenter field here allows the new connection string and database type to be tested for validity. If either is not valid // then the an exception will be throw, a message will be displayed to the user, and no settings (null) will be returned to the calling method, // so that no application settings are updated in the calling application. Essentially it guards against malformed connection strings or mismatched // database types leaving the NovenaLibrary application and going to the calling appliation. try { _appConfig = new AppConfig(defaultConnectionString, availableTablesSQL, defaultDatabaseType); _workbookPropertiesConfig = new WorkbookPropertiesConfig(_application.ActiveWorkbook); _presenter = new ExcelPresenter(_application, new DatabaseConnectionFactory().CreateDbConnection(defaultDatabaseType, defaultConnectionString), new SqlGeneratorFactory().CreateSqlGenerator(defaultDatabaseType), _workbookPropertiesConfig); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK); return(null); } // Pass connection strings to calling application method to update application's settings. Hashtable results = new Hashtable(); results.Add("dbConnStrings", editConfig.DatabaseConnections); results.Add("activeConnectionString", defaultConnectionString); results.Add("activeDatabaseType", (int)defaultDatabaseType); results.Add("availableTablesSQL", availableTablesSQL); return(results); } return(null); }
public NovenaReportingAPI(Excel.Application application, string connectionString, string availableTablesSQL, DatabaseType databaseType, string workbookPropertiesConfigXML) { _appConfig = new AppConfig(connectionString, availableTablesSQL, databaseType); _application = application; try { _workbookPropertiesConfig = new WorkbookPropertiesConfig(application.ActiveWorkbook).DeserializeXML(workbookPropertiesConfigXML); // If no credentials are required, create ExcelPresenter with DatabaseConnection and SqlGenerator dependencies. // If credentials are required, then they are set in the Login() method below. if (_appConfig.GetCredentialsRequired == AppConfig.CredentialsRequired.None) { _presenter = new ExcelPresenter(application, new DatabaseConnectionFactory().CreateDbConnection(_appConfig.DatabaseType, _appConfig.ConnectionString), new SqlGeneratorFactory().CreateSqlGenerator(databaseType), _workbookPropertiesConfig); } } catch (Exception) { throw; } }