/// <summary> /// Constructor for the class for Epi 2000 projects /// </summary> /// <param name="proj">Project the metadata belongs to</param> public MetadataDbProvider(Project proj) { IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver); OleDbConnectionStringBuilder cnnStrBuilder = new OleDbConnectionStringBuilder(); cnnStrBuilder.DataSource = proj.FilePath; this.db = dbFactory.CreateDatabaseObject(cnnStrBuilder); }
private DbConfiguration(string providerName, string connectionString, DbProviderFactory dbProviderFactory) { this.providerName = providerName; this.connectionString = connectionString; this.dbProviderFactory = dbProviderFactory; this.dbDriver = currentDbDrivers[providerName]; }
public ICreateSessionFactory ForConnection(string connectionName, ISqlDialect sqlDialect, IDbDriver dbDriver) { if (connectionName == null) { throw new ArgumentNullException("connectionName"); } if (sqlDialect == null) { throw new ArgumentNullException("sqlDialect"); } if (dbDriver == null) { throw new ArgumentNullException("dbDriver"); } var configSection = ConfigurationManager.ConnectionStrings[connectionName]; if (configSection == null) { throw new ConfigurationException(ExceptionMessages.FluentConfiguration_ConnectionNotFound.FormatWith(connectionName)); } this.chosenConnectionName = configSection.Name; this.chosenSqlDialect = sqlDialect; this.chosenDbDriver = dbDriver; this.chosenDbDriver.ConnectionString = configSection.ConnectionString; this.chosenDbDriver.DbProviderFactory = DbProviderFactories.GetFactory(configSection.ProviderName); return this; }
internal SessionFactory(string connectionName, IDbDriver dbDriver, ISqlDialect sqlDialect) { this.connectionName = connectionName; this.dbDriver = dbDriver; this.sqlDialect = sqlDialect; this.sessionListeners = new SessionListeners(Listener.DeleteListeners, Listener.InsertListener, Listener.UpdateListeners); }
public ReadRelatedDialog(IDbDriver database, Dictionary<string, string> parentTableColumnNames) { InitializeComponent(); Construct(); selectedDataSource = database; this.parentTableColumnNames = parentTableColumnNames; SelectedItemType = Dialogs.SelectedItemType.Table; }
/// <summary> /// Default constructor /// </summary> /// <param name="pProject">The project that will contain the converted metadata</param> /// <param name="pFormName">The name of the form that will be created in the Epi Info 7 project</param> /// <param name="pSourceDriver">The data driver for the external data source</param> /// <param name="pTableName">The name of the table within the external data source</param> /// <param name="pColumnMapping">The column mappings that determine how the fields in the form will be created</param> public TableToFormMetadataConverter(Project pProject, string pFormName, IDbDriver pSourceDriver, string pTableName, List<ColumnConversionInfo> pColumnMapping) { project = pProject; formName = pFormName; sourceDriver = pSourceDriver; tableName = pTableName; columnMapping = pColumnMapping; destinationDriver = project.CollectedData.GetDatabase(); }
public MergeConnection(View view, IDbDriver db, string parentKey, string childKey) { this.view = view; this.db = db; this.TableName = ""; this.ConnectionName = ""; this.ChildKeyField = childKey; this.ParentKeyField = parentKey; }
public MergeConnection(string tableName, IDbDriver db, string parentKey, string childKey) { this.view = null; this.db = db; this.TableName = tableName; this.ConnectionName = ""; this.ChildKeyField = childKey; this.ParentKeyField = parentKey; }
/// <summary> /// Constructor for CollectedDataProvider /// </summary> /// <param name="proj"></param> public CollectedDataProvider(Project proj) { IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver); OleDbConnectionStringBuilder cnnStrBuilder = new OleDbConnectionStringBuilder(); cnnStrBuilder.DataSource = proj.FilePath; this.db = dbFactory.CreateDatabaseObject(cnnStrBuilder); //this.db = dbFactory.CreateDatabaseObjectByConfiguredName(proj.FilePath); //db = DatabaseFactoryCreator.CreateDatabaseInstanceByFileExtension(proj.FilePath); }
public RelatedConnection(View view, IDbDriver db, string parentKey, string childKey, bool useUnmatched, bool sameDataSource) { this.view = view; this.db = db; this.TableName = ""; this.ConnectionName = ""; this.ChildKeyField = childKey; this.ParentKeyField = parentKey; this.UseUnmatched = useUnmatched; this.SameDataSource = sameDataSource; }
public void UnSubscribe() { this.Controls.Clear(); this.host = null; this.dashboard = null; this.host = null; this.enterMainForm = null; this.currentView = null; this.db = null; this.loadedRuntimeView = null; }
public SimpleDataGrid(View view, IDbDriver db) { InitializeComponent(); this.view = view; this.db = db; this.dashboardHelper = new DashboardHelper(view, db); this.dashboardHelper.PopulateDataSet(); //dgResults.MouseDoubleClick += new MouseButtonEventHandler(dgResults_MouseDoubleClick); //dgResults.AutoGeneratingColumn += new EventHandler<DataGridAutoGeneratingColumnEventArgs>(dgResults_AutoGeneratingColumn); this.Loaded += new RoutedEventHandler(SimpleDataGrid_Loaded); this.SizeChanged += new SizeChangedEventHandler(SimpleDataGrid_SizeChanged); }
/// <summary> /// Get Command /// </summary> /// <param name="pFileName">File name</param> /// <param name="pKeyString">Key String</param> /// <param name="pDataTable">Data Table</param> /// <returns>DbCommand</returns> public static System.Data.Common.DbCommand GetCommand(string pFileName, string pKeyString, DataTable pDataTable) { System.Data.Common.DbCommand result = null; string connString = DBReadExecute.ParseConnectionString(pFileName); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; result = driver.GetCommand(pKeyString, pDataTable); } return(result); }
/// <summary> /// Execute SQL /// </summary> /// <param name="pConnectionString">Connection string</param> /// <param name="pSQL">SQL statement</param> /// <param name="pTimeOut">Time out integer</param> /// <returns>bool</returns> public static bool ExecuteSQL(string pConnectionString, string pSQL, int pTimeOut) { bool result = false; string connString = ParseConnectionString(pConnectionString); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; driver.ExecuteNonQuery(driver.CreateQuery(pSQL)); result = true; } return(result); }
/// <summary> /// GetDataDriver /// </summary> /// <param name="fileString">File string</param> /// <returns>IDbDriver</returns> public static IDbDriver GetDataDriver(string fileString, string databaseType, bool pIsConnectionString = false) { string connString = null; connString = ParseConnectionString(fileString, databaseType); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; return(driver); } return(null); }
public Query GenerateInsertQuery(IDbDriver database, int toViewId, int fromViewId, bool isForContactDuplicatedInCaseList = false) { Query insertQuery = database.CreateQuery("INSERT INTO [metaLinks] (FromRecordGuid, ToRecordGuid, FromViewId, ToViewId, [" + ContactTracing.Core.Constants.LAST_CONTACT_DATE_COLUMN_NAME + "], ContactType, RelationshipType, Tentative, IsEstimatedContactDate) VALUES (" + "@CurrentCaseGuid, @ContactGuid, @FromViewId, @ToViewId, @LastContactDate, @ContactType, @Relationship, @Tentative, @IsEstimatedContactDate)"); if (isForContactDuplicatedInCaseList) { insertQuery.Parameters.Add(new QueryParameter("@CurrentCaseGuid", DbType.String, ExposedCaseVM.RecordId)); insertQuery.Parameters.Add(new QueryParameter("@ContactGuid", DbType.String, SourceCaseVM.RecordId)); } else { insertQuery.Parameters.Add(new QueryParameter("@CurrentCaseGuid", DbType.String, SourceCaseVM.RecordId)); insertQuery.Parameters.Add(new QueryParameter("@ContactGuid", DbType.String, ExposedCaseVM.RecordId)); } insertQuery.Parameters.Add(new QueryParameter("@FromViewId", DbType.Int32, fromViewId)); insertQuery.Parameters.Add(new QueryParameter("@ToViewId", DbType.Int32, toViewId)); insertQuery.Parameters.Add(new QueryParameter("@LastContactDate", DbType.DateTime, DateLastContact)); if (ContactType.HasValue) { insertQuery.Parameters.Add(new QueryParameter("@ContactType", DbType.Byte, ContactType)); } else { insertQuery.Parameters.Add(new QueryParameter("@ContactType", DbType.Byte, DBNull.Value)); } if (string.IsNullOrEmpty(Relationship)) { insertQuery.Parameters.Add(new QueryParameter("@Relationship", DbType.String, DBNull.Value)); } else { insertQuery.Parameters.Add(new QueryParameter("@Relationship", DbType.String, Relationship)); } if (IsTentative) { insertQuery.Parameters.Add(new QueryParameter("@Tentative", DbType.Byte, 1)); } else { insertQuery.Parameters.Add(new QueryParameter("@Tentative", DbType.Byte, 0)); } insertQuery.Parameters.Add(new QueryParameter("@IsEstimatedContactDate", DbType.Boolean, IsContactDateEstimated)); return(insertQuery); }
private void RefreshForm() { lvDataSourceObjects.Groups.Clear(); lvDataSourceObjects.Items.Clear(); //txtCurrentProj.Text = (selectedProject == null) ? "(none)" : selectedProject.FullName; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ListViewItem newItem = new ListViewItem(new string[] { tableName, tableName }); this.lvDataSourceObjects.Items.Add(newItem); } gbxExplorer.Enabled = true; } else if (selectedDataSource is Project) { Project project = selectedDataSource as Project; txtDataSource.Text = (selectedDataSource == selectedProject) ? SharedStrings.CURRENT_PROJECT : project.FullName; ListViewGroup tablesGroup = new ListViewGroup("Tables"); this.lvDataSourceObjects.Groups.Add(tablesGroup); foreach (string s in project.GetNonViewTableNames()) { ListViewItem newItem = new ListViewItem(new string[] { s, "Table" }, tablesGroup); this.lvDataSourceObjects.Items.Add(newItem); } gbxExplorer.Enabled = true; } else { // Clear ... this.txtDataSource.Text = "(none)"; this.lvDataSourceObjects.Items.Clear();// DataSource = null; gbxExplorer.Enabled = false; } this.CheckForInputSufficiency(); }
private void OpenSelectedDataDriver() { ComboBoxItem selectedPlugIn = cmbDataSourcePlugIns.SelectedItem as ComboBoxItem; if (selectedPlugIn == null) { throw new GeneralException("No data source plug-in is selected in combo box."); } //IDbDriverFactory dbFactory = DatabaseFactoryCreator.GetDbDriverFactory(selectedPlugIn.Key); IConnectionStringGui dialog = ResourceTool.dbFactory.GetConnectionStringGuiForExistingDb(); DialogResult result = ((Form)dialog).ShowDialog(); IDbDriver db; if (result == DialogResult.OK) { //ToDo: refine code here after remove db.connectstring, connectstringinfo .. bool success = false; db = ResourceTool.dbFactory.CreateDatabaseObject(dialog.DbConnectionStringBuilder); db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); txtDataSource.Text = db.ConnectionDescription; try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } if (success) { this.selectedDataSource = db; } else { this.selectedDataSource = null; } this.RefreshForm(); } else { this.selectedDataSource = null; } }
/// <summary> /// GetDataTable /// </summary> /// <param name="pFileString">File String</param> /// <param name="pSQL">SQL Statement</param> /// <returns>DataTable of results</returns> public static DataTable GetDataTable(string pFileString, string pSQL) { System.Data.DataTable result = new System.Data.DataTable(); string connString = ParseConnectionString(pFileString); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; Query query = driver.CreateQuery(pSQL); driver.Select(query, result); } return(result); }
/// <summary> /// Default constructor /// </summary> /// <param name="pProject">The project that will contain the converted metadata</param> /// <param name="pDestinationView">The form within the project that will accept the converted data</param> /// <param name="pSourceDriver">The data driver for the external data source</param> /// <param name="pTableName">The name of the table within the external data source</param> /// <param name="pColumnMapping">The column mappings that determine how the fields in the form will be created</param> public TableToFormDataConverter(Project pProject, View pDestinationView, IDbDriver pSourceDriver, string pTableName, List <ColumnConversionInfo> pColumnMapping) { project = pProject; destinationView = pDestinationView; sourceDriver = pSourceDriver; tableName = pTableName; columnMapping = pColumnMapping; columnNames = new List <string>(); foreach (ColumnConversionInfo cci in columnMapping) { columnNames.Add(cci.SourceColumnName); } destinationDriver = project.CollectedData.GetDatabase(); }
/// <summary> /// /// </summary> /// <param name="pFileString"></param> /// <param name="pTableName"></param> /// <param name="pIsConnectionString"></param> /// <returns></returns> public override bool CheckDatabaseExistance(string pFileString, string pTableName, bool pIsConnectionString = false) { System.Data.Common.DbConnection Conn = null; //System.Data.Common.DbDataAdapter Adapter = null; System.Data.DataTable DataTable = new System.Data.DataTable(); bool result = false; string connString = pFileString; string[] restrictions = new string[] { null, null, pTableName }; if (DataSource != null) { IDbDriver driver = this; driver.ConnectionString = connString; Conn = (System.Data.Common.DbConnection)driver.GetConnection(); try { Conn.Open(); Conn.ChangeDatabase("master"); System.Data.Common.DbCommand cmd = Conn.CreateCommand(); cmd.CommandText = "SELECT database_id FROM sys.databases WHERE Name = @name"; System.Data.Common.DbParameter parameter = cmd.CreateParameter(); parameter.ParameterName = "@name"; parameter.Value = driver.DbName; cmd.Parameters.Add(parameter); object ret = cmd.ExecuteScalar(); if (ret != null) { int databaseID = (int)ret; result = databaseID > 0; } } catch (Exception ex) { // do nothing } finally { Conn.Close(); } } return(result); }
protected SessionBase(ConnectionScope connectionScope, IDbDriver dbDriver) { this.ConnectionScope = connectionScope; this.DbDriver = dbDriver; this.Connection = dbDriver.CreateConnection(); if (this.ConnectionScope == ConnectionScope.PerSession) { if (Log.IsDebug) { Log.Debug(LogMessages.Session_OpeningConnection); } this.Connection.Open(); } }
protected SessionBase(ConnectionScope connectionScope, IDbDriver dbDriver) { ConnectionScope = connectionScope; DbDriver = dbDriver; Connection = dbDriver.CreateConnection(); if (ConnectionScope == ConnectionScope.PerSession) { if (Log.IsDebug) { Log.Debug(LogMessages.Session_OpeningConnection); } Connection.Open(); } }
private void LoadTables() { //lbxShowViews.DataSource = null; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); //lbxShowViews.DataSource = tableNames; lbxShowAll.DataSource = tableNames; /* * rbAll.Checked = true; * rbView.Checked = false; * rbView.Enabled = false; * lbxShowViews.SelectedIndex = -1;*/ } else if (selectedDataSource is Project) { //rbView.Enabled = true; Project project = selectedDataSource as Project; txtDataSource.Text = project.FullName; List <string> tableNames = project.GetViewNames(); this.lbxShowViews.DataSource = tableNames; tableNames = project.GetNonViewTableNames(); this.lbxShowAll.DataSource = tableNames; this.lbxShowViews.SelectedIndex = -1; this.lbxShowAll.SelectedIndex = -1; } else { // Clear ... this.txtDataSource.Text = string.Empty; this.lbxShowViews.DataSource = null; this.lbxShowAll.DataSource = null; } tabctrlShow.TabPages[1].Show(); }
private void LoadTablesFromDatabase(IDbDriver db) { lbxTables.ItemsSource = null; lbxTables.Items.Clear(); lbxTables.ItemTemplate = null; txtConnectionInformation.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { if (!string.IsNullOrEmpty(tableName.Trim())) { lbxTables.Items.Add(tableName); } } }
/// <summary> /// Update Data /// </summary> /// <param name="pFileString">File String</param> /// <param name="pSelectSQL">Select Statement</param> /// <param name="pDataReader">DataReader</param> /// <returns>bool</returns> public static bool UpdateData(string pFileString, string pSelectSQL, System.Data.Common.DbDataReader pDataReader) { bool result = false; System.Data.Common.DbConnection Conn = null; System.Data.Common.DbDataAdapter Adapter = null; System.Data.Common.DbCommandBuilder builder = null; System.Data.Common.DbCommand cmd = null; DataSet dataSet = new DataSet(); DataTable Temp = new DataTable(); string connString = ParseConnectionString(pFileString); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; Conn = (System.Data.Common.DbConnection)driver.GetConnection(); Adapter = driver.GetDbAdapter(pSelectSQL); Adapter.FillSchema(dataSet, SchemaType.Source); Adapter.Fill(Temp); builder = driver.GetDbCommandBuilder(Adapter); } try { Conn.Open(); cmd = builder.GetInsertCommand(true); cmd.CommandTimeout = 1500; while (pDataReader.Read()) { foreach (System.Data.Common.DbParameter param in cmd.Parameters) { param.Value = pDataReader[param.SourceColumn]; } cmd.ExecuteNonQuery(); } } finally { Conn.Close(); } result = true; return(result); }
/// <summary> /// GetSchema /// </summary> /// <param name="pFileString">File String</param> /// <param name="pTableName">Table Name</param> /// <param name="pDataSet">DataSet</param> public static void GetSchema(string pFileString, string pTableName, ref DataSet pDataSet) { System.Data.Common.DbDataAdapter Adapter = null; string connString = ParseConnectionString(pFileString); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; Adapter = driver.GetDbAdapter("Select * From [" + pTableName + "]"); } if (Adapter != null) { Adapter.FillSchema(pDataSet, SchemaType.Source, pTableName); } }
/// <summary> /// /// </summary> /// <param name="pFileString"></param> /// <param name="pTableName"></param> /// <param name="pIsConnectionString"></param> /// <returns></returns> public override bool CheckDatabaseTableExistance(string pFileString, string pTableName, bool pIsConnectionString = false) { System.Data.Common.DbConnection Conn = null; //System.Data.Common.DbDataAdapter Adapter = null; System.Data.DataTable DataTable = new System.Data.DataTable(); bool result = false; string connString = pFileString; string[] restrictions = new string[] { null, null, pTableName }; if (DataSource != null) { IDbDriver driver = this; driver.ConnectionString = connString; Conn = (System.Data.Common.DbConnection)driver.GetConnection(); try { Conn.Open(); DataTable = Conn.GetSchema("Tables", restrictions); if (DataTable.Rows.Count == 0) { //Table does not exist result = false; } else { //Table exists result = true; } } catch (Exception ex) { // do nothing } finally { Conn.Close(); } } return(result); }
/// <summary> /// Before executing the command, preprocesses information gathered from the dialog. /// If the current project has changed, updates Global.CurrentProject /// </summary> protected void PreProcess() { //base.PreProcess(); // dcs0 8/13/2008 the below doesn't seem necessary, the command processor should do all of this //IProjectHost host = Module.GetService(typeof(IProjectHost)) as IProjectHost; //if (host == null) //{ // throw new GeneralException("No project is hosted by service provider."); //} //if ((host.CurrentProject == null) || (!host.CurrentProject.Equals(this.selectedProject))) //{ // Configuration config = Configuration.GetNewInstance(); // host.CurrentProject = this.selectedProject; // config.CurrentProjectFilePath = selectedProject.FullName; // Configuration.Save(config); //} // add to the config Configuration config = Configuration.GetNewInstance(); string name = string.Empty; string connectionString = string.Empty; string dataProvider = string.Empty; if (SelectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; name = db.DbName; connectionString = db.ConnectionString; dataProvider = SelectedDataProvider; } else if (SelectedDataSource is Project) { Project project = selectedDataSource as Project; name = project.FileName; connectionString = project.FilePath; dataProvider = project.CollectedDataDriver; } if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(connectionString)) { Configuration.OnDataSourceAccessed(name, Configuration.Encrypt(connectionString), dataProvider); } }
public LineListingViewer(View view, IDbDriver db, string title) { try { InitializeComponent(); host = new ElementHost(); host.Dock = DockStyle.Fill; control = new EpiDashboard.SimpleDataGrid(view, db); control.RecordSelected += new EpiDashboard.Mapping.RecordSelectedHandler(control_RecordSelected); host.Child = control; this.Controls.Add(host); this.Text += " - " + title; this.Shown += new EventHandler(LineListingViewer_Shown); } catch (Exception ex) { //catching all for debugging purposes } }
/// <summary> /// Check Database Table Existance /// </summary> /// <param name="pFileString">File String</param> /// <param name="pTableName">Table name</param> /// <returns>bool</returns> public static bool CheckDatabaseTableExistance(string pFileString, string pTableName, bool pIsConnectionString = false) { DataSets.Config.DataDriverDataTable dataDrivers = Configuration.GetNewInstance().DataDrivers; IDbDriverFactory dbFactory = null; foreach (DataSets.Config.DataDriverRow dataDriver in dataDrivers) { dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(dataDriver.Type); if (dbFactory.CanClaimConnectionString(pFileString)) { break; } } IDbDriver dbDriver = DBReadExecute.GetDataDriver(pFileString, pIsConnectionString); return(dbDriver.CheckDatabaseTableExistance(pFileString, pTableName, pIsConnectionString)); }
public Query GenerateDeleteQuery(IDbDriver database, int toViewId, int fromViewId) { string queryString = "DELETE * FROM [metaLinks] WHERE " + "[FromRecordGuid] = @FromRecordGuid AND [ToRecordGuid] = @ToRecordGuid AND [FromViewId] = @FromViewId AND [ToViewId] = @ToViewId"; if (database.ToString().ToLower().Contains("sql")) { queryString = "DELETE FROM [metaLinks] WHERE " + "[FromRecordGuid] = @FromRecordGuid AND [ToRecordGuid] = @ToRecordGuid AND [FromViewId] = @FromViewId AND [ToViewId] = @ToViewId"; } Query deleteQuery = database.CreateQuery(queryString); deleteQuery.Parameters.Add(new QueryParameter("@FromRecordGuid", DbType.String, SourceCaseVM.RecordId)); deleteQuery.Parameters.Add(new QueryParameter("@ToRecordGuid", DbType.String, ExposedCaseVM.RecordId)); deleteQuery.Parameters.Add(new QueryParameter("@FromViewId", DbType.Int32, fromViewId)); deleteQuery.Parameters.Add(new QueryParameter("@ToViewId", DbType.Int32, toViewId)); return(deleteQuery); }
/// <summary> /// Initializes the context by applying the builder config, registering the entities and opening the database connection /// </summary> /// <param name="options">The DataContextBuilder which will be used to configure the context</param> private void OnInit(DataContextBuilder options) { // Run the builder through OnConfigure incase it is implemented OnConfigure(options); // Apply all the options from the builder dbDriver = options.DbDriver; deserializer = options.Deserializer; logger = options.Logger; isLogging = options.Logging; IsConfigured = true; OnEntityRegister(); dbDriver.OpenConnection(logger); if (isLogging) { logger.Log($"{this.GetType().Name} has been initialized with driver: {dbDriver.DriverName} ({dbDriver.GetType().FullName})"); } }
/// <summary> /// Gets a list of code tables. /// </summary> /// <param name="db"></param> /// <returns></returns> public override Epi.DataSets.TableSchema.TablesDataTable GetCodeTableList(IDbDriver db) { Epi.DataSets.TableSchema.TablesDataTable table = db.GetTableSchema(); DataRow[] rowsFiltered = table.Select("TABLE_NAME not like 'code%'"); //remove tables that don't start with "code" foreach (DataRow rowFiltered in rowsFiltered) { table.Rows.Remove(rowFiltered); } //remove the code tables that are not for the current database DataRow[] rowsFilteredSchema = table.Select("TABLE_SCHEMA<>'" + db.DbName + "'"); foreach (DataRow rowFilteredSchema in rowsFilteredSchema) { table.Rows.Remove(rowFilteredSchema); } return(table); }
public TableToFormProgressDialog(Project pProject, string pDestinationViewName, IDbDriver pSourceDriver, string pTableName, List <Epi.ImportExport.ColumnConversionInfo> pColumnMapping) { InitializeComponent(); project = pProject; destinationViewName = pDestinationViewName; sourceDriver = pSourceDriver; tableName = pTableName; columnMapping = pColumnMapping; columnNames = new List <string>(); foreach (Epi.ImportExport.ColumnConversionInfo cci in this.columnMapping) { columnNames.Add(cci.SourceColumnName); } destinationDriver = project.CollectedData.GetDatabase(); }
/// <summary> /// Create Database ObjectBy Configured Name /// </summary> /// <param name="configDatabaseKey">Configuration Database Key.</param> /// <returns>Database driver.</returns> public IDbDriver CreateDatabaseObjectByConfiguredName(string configDatabaseKey) { IDbDriver instance = null; Configuration config = Configuration.GetNewInstance(); DataRow[] result = config.DatabaseConnections.Select("Name='" + configDatabaseKey + "'"); if (result.Length == 1) { Epi.DataSets.Config.DatabaseRow dbConnection = (Epi.DataSets.Config.DatabaseRow)result[0]; OleDbConnectionStringBuilder cnnBuilder = new OleDbConnectionStringBuilder("Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=1;RetrieveIds=Yes;"); instance = CreateDatabaseObject(cnnBuilder); } else { throw new GeneralException("Database name is not configured."); } return(instance); }
public TableToFormProgressDialog(Project pProject, string pDestinationViewName, IDbDriver pSourceDriver, string pTableName, List<Epi.ImportExport.ColumnConversionInfo> pColumnMapping) { InitializeComponent(); project = pProject; destinationViewName = pDestinationViewName; sourceDriver = pSourceDriver; tableName = pTableName; columnMapping = pColumnMapping; columnNames = new List<string>(); foreach (Epi.ImportExport.ColumnConversionInfo cci in this.columnMapping) { columnNames.Add(cci.SourceColumnName); } destinationDriver = project.CollectedData.GetDatabase(); }
private void LoadTables() { lbxDataSourceObjects.DataSource = null; if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; List <string> tableNames = db.GetTableNames(); lbxDataSourceObjects.DataSource = tableNames; rbAll.Checked = true; rbView.Checked = false; rbView.Enabled = false; lbxDataSourceObjects.SelectedIndex = -1; } else if (selectedDataSource is Project) { rbView.Enabled = true; Project project = selectedDataSource as Project; txtDataSource.Text = project.FullName; if (rbView.Checked) { List <string> tableNames = project.GetViewNames(); lbxDataSourceObjects.DataSource = tableNames; } else if (rbAll.Checked) { List <string> tableNames = project.GetNonViewTableNames(); lbxDataSourceObjects.DataSource = tableNames; } lbxDataSourceObjects.SelectedIndex = -1; } else { // Clear ... this.txtDataSource.Text = string.Empty; lbxDataSourceObjects.DataSource = null; rbView.Enabled = true; } }
protected override void UpdateRecord(IDbConnection conn, IDbDriver db, View form, XElement record, string globalRecordId) { if (form.Pages.Count == 1) { Page page = form.Pages[0]; UpdatePageData(conn, form, page, db, record, globalRecordId); } else { Parallel.ForEach(form.Pages, page => { using (SqlConnection connection = db.GetConnection() as SqlConnection) { connection.Open(); UpdatePageData(connection, form, page, db, record, globalRecordId); } }); } }
public static void ExecuteSQL(BaseConfigInfo bci, string file) { if (file != "" && File.Exists(file)) { XmlDocument doc = new XmlDocument(); doc.Load(file); foreach (XmlNode node in doc.SelectNodes("/Update/Database")) { IDbDriver driver = CreateDbDriver(bci.DBType); if (driver == null) { continue; } int success = 0; int errors = 0; using (IConnection conn = driver.CreateConnection(bci.DBConnectionString)) { foreach (XmlNode sub in node.SelectNodes("Sql")) { SqlStatement sql = new SqlStatement(); sql.CommandType = CommandType.Text; sql.SqlClause = sub.InnerText; driver.FormatSQL(sql); try { conn.Update(sql); success++; } catch (Exception ex) { We7.Framework.LogHelper.WriteFileLog(We7.Framework.LogHelper.sql_update, "执行SQL:" + sql.SqlClause + "\n\t 出现错误:", ex.Message); errors++; continue; } } } We7.Framework.LogHelper.WriteFileLog(We7.Framework.LogHelper.sql_update, "执行完毕:", string.Format("{3}执行完毕!共执行语句{0}条,成功{1}条,失败{2}条", success + errors, success, errors, file)); } } }
/// <summary> /// Check Database Table Existance /// </summary> /// <param name="pFileString">File String</param> /// <param name="pTableName">Table name</param> /// <returns>bool</returns> public static bool CheckDatabaseExistance(string pFileString, string pTableName, bool pIsConnectionString = false) { bool result = false; string connString = ParseConnectionString(pFileString); try { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); if (driver != null) { driver.ConnectionString = connString; } } catch (Exception ex) { // do nothing for now } return(result); }
public IDbDriver CreateDatabaseObjectByConfiguredName(string configDatabaseKey) { //may not use since PHIN is .MDB IDbDriver instance = null; Configuration config = Configuration.GetNewInstance(); DataRow[] result = config.DatabaseConnections.Select("Name='" + configDatabaseKey + "'"); if (result.Length == 1) { Epi.DataSets.Config.DatabaseRow dbConnection = (Epi.DataSets.Config.DatabaseRow)result[0]; EpiWebConnectionStringBuilder MongoDBConnectionBuilder = new EpiWebConnectionStringBuilder(dbConnection.ConnectionString); instance = CreateDatabaseObject(MongoDBConnectionBuilder); } else { throw new GeneralException("Database name is not configured."); } return(instance); }
/// <summary> /// Insert one row /// </summary> /// <param name="pFileString">File String</param> /// <param name="pSelectSQL">Select Statement</param> /// <param name="pDataReader">DataReader</param> /// <returns>bool</returns> public static bool Insert_1_Row(string pFileString, string pSelectSQL, System.Data.Common.DbDataReader pDataReader) { /* * NOTE FROM EPI1: The original contents of this method have been moved to SqlDatabase.Insert_1_Row * and OleDbDatabase.Insert_1_Row. * */ bool result = false; string connString = ParseConnectionString(pFileString); if (DataSource != null) { IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder()); driver.ConnectionString = connString; result = driver.Insert_1_Row(pSelectSQL, pDataReader); } return(result); }
void RefreshForm() { string itemText; lvDataSourceObjects.Groups.Clear(); lvDataSourceObjects.Items.Clear(); if (selectedDataSource is IDbDriver) { IDbDriver db = selectedDataSource as IDbDriver; this.txtDataSource.Text = db.ConnectionString; DataTable schemaTable = db.GetTableSchema(); foreach (DataRow row in schemaTable.Rows) { itemText = row[ColumnNames.SCHEMA_TABLE_NAME].ToString(); ListViewItem newItem = new ListViewItem(new string[] { itemText, itemText }); this.lvDataSourceObjects.Items.Add(newItem); } gbxShow.Enabled = true; if (lvDataSourceObjects.Items.Count > 0) { lvDataSourceObjects.Items[0].Selected = true; lvDataSourceObjects.Select(); Application.DoEvents(); } } else { // Clear ... this.txtDataSource.Text = "(none)"; this.lvDataSourceObjects.Items.Clear();// DataSource = null; gbxShow.Enabled = false; } this.CheckForInputSufficiency(); }
private void LoadTablesFromDatabase(IDbDriver db) { lbxTables.ItemsSource = null; lbxTables.Items.Clear(); lbxTables.ItemTemplate = null; txtConnectionInformation.Text = db.ConnectionString; List<string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { if (!string.IsNullOrEmpty(tableName.Trim())) { lbxTables.Items.Add(tableName); } } }
/// <summary> /// Returns code table list /// </summary> /// <param name="db">IDbDriver</param> /// <returns>Epi.DataSets.TableSchema.TablesDataTable</returns> public override Epi.DataSets.TableSchema.TablesDataTable GetCodeTableList(IDbDriver db) { DataSets.TableSchema.TablesDataTable tables = db.GetTableSchema(); //remove tables without prefix "code" DataRow[] rowsFiltered = tables.Select("TABLE_NAME not like 'code%'"); foreach (DataRow rowFiltered in rowsFiltered) { tables.Rows.Remove(rowFiltered); } foreach (DataRow row in tables) { if (String.IsNullOrEmpty(row.ItemArray[2].ToString())) { //remove a row with an empty string tables.Rows.Remove(row); } } DataRow[] rowsCode = tables.Select("TABLE_NAME like 'code%'"); return tables; }
private IDbDriver SetupSourceProject() { sourceProjectDataDriver = DBReadExecute.GetDataDriver(sourceProject.FilePath); return sourceProjectDataDriver; }
void WriteResourcesToDatabase(GlobalizationDataSet ds, IDbDriver db) { AppendToLog("Please wait..."); List<TableColumn> columns = new List<TableColumn>(); columns.Add(new TableColumn("AssemblyName", GenericDbColumnType.String, 255, false)); columns.Add(new TableColumn("ManifestResourceName", GenericDbColumnType.String, 255, false)); columns.Add(new TableColumn("ResourceName", GenericDbColumnType.String, 255, false)); columns.Add(new TableColumn("ResourceValue", GenericDbColumnType.StringLong, false)); columns.Add(new TableColumn("ResourceType", GenericDbColumnType.String, 255, false)); columns.Add(new TableColumn("ResourceVersion", GenericDbColumnType.String, 255, false)); columns.Add(new TableColumn("SourceCultureName", GenericDbColumnType.String, 255, false)); columns.Add(new TableColumn("SourceValue", GenericDbColumnType.StringLong, 255, false)); //columns.Add(new TableColumn("CreationDate", GenericDbColumnType.String, 255, false)); DbDriverInfo dbInfo = new DbDriverInfo(); dbInfo.DBName = "CulturalResources"; dbInfo.DBCnnStringBuilder = new System.Data.OleDb.OleDbConnectionStringBuilder(); dbInfo.DBCnnStringBuilder.ConnectionString = db.ConnectionString; dbFactory.CreatePhysicalDatabase(dbInfo); // db.CreateDatabase("CulturalResources"); string tableName = ds.CulturalResources.TableName; db.CreateTable(tableName, columns); StringBuilder sb = new StringBuilder(); sb.Append("insert into "); sb.Append(tableName); sb.Append(" ("); for (int x = 0; x < columns.Count; x++) { sb.Append(columns[x].Name); if (x < columns.Count - 1) { sb.Append(", "); } } sb.Append(") values "); sb.Append(" ("); for (int x = 0; x < columns.Count; x++) { sb.Append("@"); sb.Append(columns[x].Name); if (x < columns.Count - 1) { sb.Append(", "); } } sb.Append(")"); Query insertQuery = db.CreateQuery(sb.ToString()); for (int x = 0; x < columns.Count; x++) { insertQuery.Parameters.Add(new QueryParameter("@" + columns[x].Name, DbType.String, columns[x].Name, columns[x].Name)); } sb.Remove(0, sb.Length); sb.Append("update [").Append(tableName); sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET).Append(StringLiterals.SPACE); sb.Append("set").Append(StringLiterals.SPACE); for (int x = 0; x < columns.Count; x++) { sb.Append(StringLiterals.LEFT_SQUARE_BRACKET); sb.Append(columns[x].Name); sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET); sb.Append(StringLiterals.EQUAL); sb.Append("@NewValue").Append(StringLiterals.SPACE); sb.Append(", "); } sb.Append("where "); for (int x = 0; x < columns.Count; x++) { sb.Append(columns[x].Name).Append(StringLiterals.SPACE); sb.Append(StringLiterals.EQUAL); sb.Append("@OldValue"); if (columns.Count > 1) { sb.Append(" and"); } } Query updateQuery = db.CreateQuery(sb.ToString()); for (int x = 0; x < columns.Count; x++) { updateQuery.Parameters.Add(new QueryParameter("@NewValue", DbType.String, columns[x].Name, columns[x].Name)); updateQuery.Parameters.Add(new QueryParameter("@OldValue", DbType.String, columns[x].Name, columns[x].Name)); updateQuery.Parameters[1].SourceVersion = DataRowVersion.Original; } db.Update(ds.Tables[0], tableName, insertQuery, null); }
GlobalizationDataSet ReadResourcesFromDatabase(IDbDriver dataSource, string tableName) { AppendToLog("Reading database"); GlobalizationDataSet ds = new GlobalizationDataSet(); if (string.IsNullOrEmpty(tableName)) { // default table name tableName = ds.CulturalResources.TableName; } DataTable dt = dataSource.GetTableData(tableName); try { DataTableReader reader = new DataTableReader(dt); ds.CulturalResources.BeginLoadData(); ds.CulturalResources.Load(reader); ds.CulturalResources.EndLoadData(); } catch (Exception ex) { throw new GeneralException("Import database format is invalid.", ex); } return ds; }
/// <summary> /// Gets a list of code tables. /// </summary> /// <param name="db">Database driver.</param> /// <returns>List of code tables.</returns> public TableSchema.TablesDataTable GetCodeTableList(IDbDriver db) { //return db.GetCodeTableList(db); try { TableSchema.TablesDataTable tables = db.GetCodeTableList(db); return tables; } catch (Exception ex) { throw new System.ApplicationException("Could not retrieve code tables from database", ex); } }
private void SetupOutputDataSource() { try { ComboBoxItem selectedPlugIn = cmbDataFormats.SelectedItem as ComboBoxItem; IDbDriverFactory dbFactory = null; string plugin = string.Empty; foreach (Epi.DataSets.Config.DataDriverRow row in dashboardHelper.Config.DataDrivers) { string content = selectedPlugIn.Content.ToString(); if (content.Equals(row.DisplayName)) { plugin = row.Type; } } selectedDataProvider = plugin; bool isFlatFile = false; dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(plugin); if (dbFactory.ArePrerequisitesMet()) { DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder(); db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder); IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb(); dialog.ShouldIgnoreNonExistance = true; System.Windows.Forms.DialogResult result = ((System.Windows.Forms.Form)dialog).ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { //this.savedConnectionStringDescription = dialog.ConnectionStringDescription; bool success = false; db.ConnectionString = dialog.DbConnectionStringBuilder.ToString(); DbDriverInfo dbInfo = new DbDriverInfo(); dbInfo.DBCnnStringBuilder = dbFactory.RequestNewConnection(db.DataSource); if (db.ConnectionDescription.ToLower().Contains("csv file:")) { isFlatFile = true; } if (!isFlatFile) { if (!db.CheckDatabaseExistance(db.ConnectionString, "", true)) { dbFactory.CreatePhysicalDatabase(dbInfo); } try { success = db.TestConnection(); } catch { success = false; MessageBox.Show("Could not connect to selected data source."); } } else { success = true; } if (success) { this.SelectedDataSource = db; controlNeedsRefresh = true; txtConnectionInformation.Text = db.ConnectionString; } else { this.SelectedDataSource = null; } } else { this.SelectedDataSource = null; } } else { MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found"); } if (selectedDataSource is IDbDriver) { db = selectedDataSource as IDbDriver; //this.txtDataSource.Text = db.ConnectionString; if (!isFlatFile) { System.Collections.Generic.List<string> tableNames = db.GetTableNames(); foreach (string tableName in tableNames) { ComboBoxItem newItem = new ComboBoxItem();//tableName, tableName, tableName); newItem.Content = tableName; cmbDestinationTable.Items.Add(tableName); //this.cmbDataTable.Items.Add(newItem); } } } } catch (Exception ex) { SetErrorMessage(ex.Message); } finally { pnlProgress.Visibility = System.Windows.Visibility.Collapsed; } }
/// <summary> /// Is version Epi Info 7 Metadata flag. /// </summary> /// <param name="db">Database driver</param> /// <returns>True/False on test of EI7 Metadata.</returns> public static bool IsEpi7Metadata(IDbDriver db) { #region Input Validation if (db == null) { throw new ArgumentNullException("DB"); } #endregion try { // Open the database and look for dbInfo table, find Epi Version ... bool isEpi7Metadata = false; Query query = db.CreateQuery("select [EpiVersion], [Purpose] from metaDBInfo"); DataTable results = db.Select(query); if (results.Rows.Count > 0) { foreach (DataRow row in results.Rows) { isEpi7Metadata = (row["EpiVersion"].ToString().Substring(0, 1) == "7") && ((row["Purpose"].ToString() == "0") || (row["Purpose"].ToString() == "1")); } } return isEpi7Metadata; } finally { } }
/// <summary> /// Attaches a db driver object to this provider. /// </summary> /// <param name="dbDriver"></param> public void AttachDbDriver(IDbDriver dbDriver) { this.db = dbDriver; base.db = dbDriver; }
/// <summary> /// Get the code table list /// </summary> /// <param name="db">IDbDriver</param> /// <returns>Epi.DataSets.TableSchema.TablesDataTable</returns> public abstract Epi.DataSets.TableSchema.TablesDataTable GetCodeTableList(IDbDriver db);
private void mainForm_OpenViewEvent(object sender, Epi.Windows.Enter.PresentationLogic.OpenViewEventArgs e) { if (e.View != null) { if (!e.View.IsRelatedView) { this.currentView = e.View; this.fields = null; db = DBReadExecute.GetDataDriver(e.View.Project.FilePath); CreateFromGrid(); CreateToGrid(); ToggleEnable(true); } else { lvLinkedFrom.Clear(); lvLinkedTo.Clear(); ToggleEnable(false); } } }
/// <summary> /// ImportLanguage() /// </summary> /// <param name="applicationPath"></param> /// <param name="targetCulture"></param> /// <param name="dataSource"></param> /// <param name="tableName"></param> /// <param name="callback"></param> public static void ImportLanguage(string applicationPath, string targetCulture, IDbDriver dataSource, string tableName, AppendLogCallback callback) { ResourceTool instance = new ResourceTool(applicationPath, callback); GlobalizationDataSet ds = instance.ReadResourcesFromDatabase(dataSource, tableName); instance.CompileSatelliteAssemblies(targetCulture, ds); }
/// <summary> /// Constructor initialization. /// </summary> /// <param name="MetaDbInfo">Database driver information.</param> /// <param name="driver">Database driver name.</param> /// <param name="createDatabase">Create database flag.</param> public void Initialize(DbDriverInfo MetaDbInfo, string driver, bool createDatabase) { dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(driver); if (createDatabase) { this.CreateDatabase(MetaDbInfo); //\\ + Path.DirectorySeparatorChar + DbDriverInfo.PreferredDatabaseName); db = dbFactory.CreateDatabaseObject(MetaDbInfo.DBCnnStringBuilder); CreateMetadataTables(); } else { db = dbFactory.CreateDatabaseObject(MetaDbInfo.DBCnnStringBuilder); } db.TestConnection(); }
public TestSessionBase(ConnectionScope connectionScope, IDbDriver dbDriver) : base(connectionScope, dbDriver) { }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <returns></returns> public override Epi.DataSets.TableSchema.TablesDataTable GetCodeTableList(IDbDriver db) { Epi.DataSets.TableSchema.TablesDataTable table = db.GetTableSchema(); //remove all databases that do not start with "code" DataRow[] rowsFiltered = table.Select("TABLE_NAME not like 'code%'"); foreach (DataRow rowFiltered in rowsFiltered) { table.Rows.Remove(rowFiltered); } return table; }