Ejemplo n.º 1
0
        private void LoadTablesFromDatabase(RecentDataSourceInfo info)
        {
            string connectionString = Configuration.Decrypt(info.ConnStr);
            string name             = info.Name;
            string provider         = info.Provider;

            mruSelectedDatabaseName = name;
            selectedDataProvider    = provider;

            IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(provider);

            if (dbFactory.ArePrerequisitesMet())
            {
                DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);
                db.ConnectionString = connectionString;

                try
                {
                    db.TestConnection();

                    cmbDatabaseType.Text = info.ProviderDesc;

                    LoadTablesFromDatabase(db);
                }
                catch (Exception ex)
                {
                    Epi.Windows.MsgBox.ShowException(ex);
                    return;
                }

                this.selectedDataSource = db;
            }
        }
Ejemplo n.º 2
0
        private void btnConnectionBrowse_Click(object sender, RoutedEventArgs e)
        {
            if (cmbDatabaseType.SelectedIndex >= 0)
            {
                ComboBoxItem item = cmbDatabaseType.SelectedItem as ComboBoxItem;
                switch (item.Text)
                {
                case "Epi Info 7 Project":
                    System.Windows.Forms.OpenFileDialog projectDialog = new System.Windows.Forms.OpenFileDialog();
                    projectDialog.InitialDirectory = config.Directories.Project;
                    projectDialog.Filter           = "Epi Info 7 Project File|*.prj";

                    System.Windows.Forms.DialogResult projectDialogResult = projectDialog.ShowDialog();

                    if (projectDialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        try
                        {
                            Project project = new Project(projectDialog.FileName);
                            LoadFormsFromProject(project);
                        }
                        catch (System.Security.Cryptography.CryptographicException ex)
                        {
                            Epi.Windows.MsgBox.ShowError(string.Format(SharedStrings.ERROR_CRYPTO_KEYS, ex));
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                    break;

                default:
                    IDbDriverFactory dbFactory = null;

                    selectedDataProvider = item.Key;

                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(item.Key);
                    if (dbFactory.ArePrerequisitesMet())
                    {
                        DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                        IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);

                        IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb();

                        if (!string.IsNullOrEmpty(savedConnectionStringDescription))
                        {
                            int splitIndex = savedConnectionStringDescription.IndexOf("::");
                            if (splitIndex > -1)
                            {
                                string serverName   = savedConnectionStringDescription.Substring(0, splitIndex);
                                string databaseName = savedConnectionStringDescription.Substring(splitIndex + 2, savedConnectionStringDescription.Length - splitIndex - 2);
                                dialog.SetDatabaseName(databaseName);
                                dialog.SetServerName(serverName);
                            }
                        }

                        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();

                            try
                            {
                                success = db.TestConnection();
                            }
                            catch
                            {
                                success = false;
                                MessageBox.Show("Could not connect to selected data source.");
                            }

                            if (success)
                            {
                                this.selectedDataSource = db;
                                LoadTablesFromDatabase(db);
                                //formNeedsRefresh = true;
                            }
                            else
                            {
                                this.selectedDataSource = null;
                            }
                        }
                        else
                        {
                            this.selectedDataSource = null;
                        }
                    }
                    else
                    {
                        MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found");
                    }
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private void OpenSelectDataSourceDialog()
        {
            ComboBoxItem selectedPlugIn = cmbDataFormats.SelectedItem as ComboBoxItem;

            if (selectedPlugIn == null)
            {
                throw new GeneralException("No data source plug-in is selected in combo box.");
            }

            if (selectedPlugIn.Key == null) // default project
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Title  = SharedStrings.SELECT_DATA_SOURCE;
                openFileDialog.Filter = "Epi Info " + SharedStrings.PROJECT_FILE + " (*.prj)|*.prj";

                openFileDialog.FilterIndex = 1;
                openFileDialog.Multiselect = false;

                DialogResult result = openFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string filePath = openFileDialog.FileName.Trim();
                    if (System.IO.File.Exists(filePath))
                    {
                        try
                        {
                            selectedDataSource = new Project(filePath);
                            txtDataSource.Text = filePath;
                            LoadTables();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Could not load project: \n\n" + ex.Message);
                            return;
                        }
                    }
                }
            }
            else
            {
                IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(selectedPlugIn.Key);
                if (dbFactory.ArePrerequisitesMet())
                {
                    DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                    IDbDriver            db     = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);
                    IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb();
                    DialogResult         result = ((Form)dialog).ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        bool success = false;

                        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;
                        }
                    }
                    else
                    {
                        this.selectedDataSource = null;
                    }
                }
                LoadTables();
            }
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
        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
            {
                messagePanel.Visibility = System.Windows.Visibility.Hidden;
            }
        }
Ejemplo n.º 6
0
        private void OpenSelectDataSourceDialog()
        {
            ComboBoxItem selectedPlugIn = cmbDataSourcePlugIns.SelectedItem as ComboBoxItem;

            if (selectedPlugIn == null)
            {
                throw new GeneralException("No data source plug-in is selected in combo box.");
            }

            if (selectedPlugIn.Key == null) // default project
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Title  = SharedStrings.SELECT_DATA_SOURCE;
                openFileDialog.Filter = "Epi Info " + SharedStrings.PROJECT_FILE + " (*.prj)|*.prj";

                openFileDialog.FilterIndex = 1;
                openFileDialog.Multiselect = false;

                DialogResult result = openFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string filePath = openFileDialog.FileName.Trim();
                    if (System.IO.File.Exists(filePath))
                    {
                        try
                        {
                            IProjectManager manager = Module.GetService(typeof(IProjectManager)) as IProjectManager;
                            if (manager == null)
                            {
                                throw new GeneralException("Project manager is not registered.");
                            }
                            selectedDataSource = manager.OpenProject(filePath);
                            this.SelectedTable = null;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Could not load project: \n\n" + ex.Message);
                            return;
                        }
                    }
                }
            }
            else
            {
                IDbDriverFactory dbFactory = null;
                switch (selectedPlugIn.Key)
                {
                case Configuration.SqlDriver:    //"Epi.Data.SqlServer.SqlDBFactory, Epi.Data.SqlServer":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.SqlDriver);
                    break;

                case Configuration.MySQLDriver:     //"Epi.Data.MySQL.MySQLDBFactory, Epi.Data.MySQL":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.MySQLDriver);
                    break;

                case Configuration.PostgreSQLDriver:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.PostgreSQLDriver);
                    break;

                case Configuration.ExcelDriver:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.ExcelDriver);
                    break;

                case Configuration.Excel2007Driver:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Excel2007Driver);
                    break;

                case Configuration.AccessDriver:     //"Epi.Data.Office.AccessDBFactory, Epi.Data.Office":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver);
                    break;

                case Configuration.Access2007Driver:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Access2007Driver);
                    break;

                case Configuration.CsvDriver:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.CsvDriver);
                    break;

                case Configuration.WebDriver:     //"Epi.Data.WebDriver":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.WebDriver);
                    break;

                default:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver);
                    break;
                }


                DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);
                //IDbDriver db = DatabaseFactoryCreator.CreateDatabaseInstance(selectedPlugIn.Key);
                //IConnectionStringGui dialog = db.GetConnectionStringGuiForExistingDb();
                ////IConnectionStringGui dialog = this.selectedProject.Metadata.DBFactory.GetConnectionStringGuiForExistingDb();
                IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb();
                DialogResult         result = ((Form)dialog).ShowDialog();
                if (result == DialogResult.OK)
                {
                    bool success = false;

                    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;
                        this.SelectedTable      = null;
                    }
                    else
                    {
                        this.selectedDataSource = null;
                        this.SelectedTable      = null;
                    }
                }
                else
                {
                    this.selectedDataSource = null;
                    this.SelectedTable      = null;
                }
            }

            RefreshForm();
        }
Ejemplo n.º 7
0
        private void cmbRecentSources_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //this.RefreshForm();
                if (cmbRecentSources.SelectedItem != null && !string.IsNullOrEmpty(cmbRecentSources.SelectedItem.ToString()))
                {
                    string connectionString = Configuration.Decrypt(((ComboBoxItem)cmbRecentSources.SelectedItem).Value.ToString());
                    string name             = ((ComboBoxItem)cmbRecentSources.SelectedItem).Text.ToString();
                    string provider         = ((ComboBoxItem)cmbRecentSources.SelectedItem).Key.ToString();

                    mruSelectedDatabaseName = name;
                    selectedDataProvider    = provider;

                    if (name.ToLowerInvariant().EndsWith(".prj"))
                    {
                        Project project = new Project(connectionString);

                        try
                        {
                            project.CollectedData.TestConnection();
                        }
                        catch (Exception ex)
                        {
                            Epi.Windows.MsgBox.ShowException(ex);
                            return;
                        }

                        this.selectedDataSource = project;
                        this.selectedProject    = project;
                    }
                    else
                    {
                        IDbDriverFactory dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(provider);
                        if (dbFactory.ArePrerequisitesMet())
                        {
                            DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                            IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);
                            db.ConnectionString = connectionString;

                            try
                            {
                                db.TestConnection();
                            }
                            catch (Exception ex)
                            {
                                Epi.Windows.MsgBox.ShowException(ex);
                                return;
                            }

                            this.selectedDataSource = db;
                        }
                    }
                }
                else if (cmbRecentSources.SelectedItem != null && string.IsNullOrEmpty(cmbRecentSources.SelectedItem.ToString()))
                {
                    mruSelectedDatabaseName = string.Empty;
                }

                RefreshForm();
            }
            catch (System.IO.DirectoryNotFoundException ex)
            {
                MsgBox.ShowException(ex);
                mruSelectedDatabaseName        = string.Empty;
                cmbRecentSources.SelectedIndex = -1;
            }
            catch (System.IO.FileNotFoundException ex)
            {
                MsgBox.ShowException(ex);
                mruSelectedDatabaseName        = string.Empty;
                cmbRecentSources.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex);
                mruSelectedDatabaseName        = string.Empty;
                cmbRecentSources.SelectedIndex = -1;
            }
        }
Ejemplo n.º 8
0
        private void OpenSelectDataSourceDialog()
        {
            bool formNeedsRefresh = false;

            ComboBoxItem selectedPlugIn = cmbDataSourcePlugIns.SelectedItem as ComboBoxItem;

            if (selectedPlugIn == null)
            {
                throw new GeneralException("No data source plug-in is selected in combo box.");
            }

            if (selectedPlugIn.Key == null)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Title            = SharedStrings.SELECT_DATA_SOURCE;
                openFileDialog.Filter           = "Epi Info " + SharedStrings.PROJECT_FILE + " (*.prj)|*.prj";
                openFileDialog.InitialDirectory = config.Directories.Project;
                openFileDialog.FilterIndex      = 1;
                openFileDialog.Multiselect      = false;

                DialogResult result = openFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string filePath = openFileDialog.FileName.Trim();
                    if (System.IO.File.Exists(filePath))
                    {
                        try
                        {
                            selectedDataSource = new Project(filePath);
                            formNeedsRefresh   = true;
                        }
                        catch (System.Security.Cryptography.CryptographicException ex)
                        {
                            MsgBox.ShowError(string.Format(SharedStrings.ERROR_CRYPTO_KEYS, ex.Message));
                            return;
                        }
                        catch (Exception ex)
                        {
                            MsgBox.ShowError(SharedStrings.CANNOT_OPEN_PROJECT_FILE + "\n\nError details: " + ex.Message);
                            return;
                        }
                    }
                }
            }
            else
            {
                IDbDriverFactory dbFactory = null;

                selectedDataProvider = selectedPlugIn.Key;

                dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(selectedPlugIn.Key);
                if (dbFactory.ArePrerequisitesMet())
                {
                    DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                    IDbDriver db = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);

                    IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb();

                    if (!string.IsNullOrEmpty(savedConnectionStringDescription))
                    {
                        int splitIndex = savedConnectionStringDescription.IndexOf("::");
                        if (splitIndex > -1)
                        {
                            string serverName   = savedConnectionStringDescription.Substring(0, splitIndex);
                            string databaseName = savedConnectionStringDescription.Substring(splitIndex + 2, savedConnectionStringDescription.Length - splitIndex - 2);
                            dialog.SetDatabaseName(databaseName);
                            dialog.SetServerName(serverName);
                        }
                    }

                    DialogResult result = ((Form)dialog).ShowDialog();
                    //  dialog.UseManagerService
                    if (result == DialogResult.OK && dialog.DbConnectionStringBuilder != null)
                    {
                        this.savedConnectionStringDescription = dialog.ConnectionStringDescription;
                        bool success = false;
                        db.ConnectionString = dialog.DbConnectionStringBuilder.ToString();

                        try
                        {
                            success = db.TestConnection();
                        }
                        catch
                        {
                            success = false;
                            MessageBox.Show("Could not connect to selected data source.");
                        }

                        if (success)
                        {
                            this.selectedDataSource = db;
                            formNeedsRefresh        = true;
                        }
                        else
                        {
                            this.selectedDataSource = null;
                        }
                    }
                    else
                    {
                        if (selectedPlugIn.Text == "Epi Info Web & Cloud Services")
                        {
                        }

                        else
                        {
                            this.selectedDataSource = null;
                        }
                    }
                }
                else
                {
                    MessageBox.Show(dbFactory.PrerequisiteMessage, "Prerequisites not found");
                }
            }
            if (formNeedsRefresh)
            {
                RefreshForm();
            }
        }
Ejemplo n.º 9
0
        private void btnGetFile_Click(object sender, System.EventArgs e)
        {
            ComboBoxItem selectedPlugIn = cmbOutputFormat.SelectedItem as ComboBoxItem;

            if (selectedPlugIn == null)
            {
                throw new GeneralException("No data source plug-in is selected in combo box.");
            }

            if (selectedPlugIn.Key == null) // default project
            {
                OpenFileDialog dlg = new OpenFileDialog();
                if (cmbOutputFormat.Text == "Text" || cmbOutputFormat.Text.ToUpperInvariant() == "FLAT ASCII FILE")
                {
                    dlg.Filter = "Text Files (*.txt) |*.txt";
                }
                else
                {
                    dlg.Filter = "Database Files (*.mdb) |*.mdb";
                }
                dlg.CheckFileExists = false;
                dlg.CheckPathExists = false;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    if (cmbOutputFormat.Text.ToUpperInvariant() == "TEXT" || cmbOutputFormat.Text.ToUpperInvariant() == "FLAT ASCII FILE")
                    {
                        if (!dlg.FileName.EndsWith(".txt") && dlg.FileName.EndsWith(".csv"))
                        {
                            txtFileName.Text = dlg.FileName + ".csv";
                        }
                        else
                        {
                            txtFileName.Text = dlg.FileName;
                        }
                    }
                    else
                    {
                        txtFileName.Text = dlg.FileName;
                    }
                }
            }
            else
            {
                IDbDriverFactory dbFactory = null;
                switch (selectedPlugIn.Key)
                {
                case "Epi.Data.SqlServer.SqlDBFactory, Epi.Data.SqlServer":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.SqlDriver);
                    break;

                case "Epi.Data.MySQL.MySQLDBFactory, Epi.Data.MySQL":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.MySQLDriver);

                    break;

                case "Epi.Data.Office.AccessDBFactory, Epi.Data.Office":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver);
                    break;

                case "Epi.Data.Office.ExcelWBFactory, Epi.Data.Office":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.ExcelDriver);
                    break;

                case "Epi.Data.Office.Access2007DBFactory, Epi.Data.Office":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Access2007Driver);
                    break;

                case "Epi.Data.Office.Excel2007WBFactory, Epi.Data.Office":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.Excel2007Driver);
                    break;

                case "Epi.Data.Office.CsvFileFactory, Epi.Data.Office":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.CsvDriver);
                    break;

                case "Epi.Data.PostgreSQL.PostgreSQLDBFactory, Epi.Data.PostgreSQL":
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.PostgreSQLDriver);
                    break;

                default:
                    dbFactory = DbDriverFactoryCreator.GetDbDriverFactory(Configuration.AccessDriver);
                    break;
                }

                DbConnectionStringBuilder dbCnnStringBuilder = new DbConnectionStringBuilder();
                IDbDriver            db     = dbFactory.CreateDatabaseObject(dbCnnStringBuilder);
                IConnectionStringGui dialog = dbFactory.GetConnectionStringGuiForExistingDb();
                dialog.ShouldIgnoreNonExistance = true;
                DialogResult result = ((Form)dialog).ShowDialog();
                if (result == DialogResult.OK)
                {
                    bool success = false;

                    db.ConnectionString = dialog.DbConnectionStringBuilder.ToString();
                    txtFileName.Text    = db.ConnectionString;

                    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;
                    }
                }
                else
                {
                    this.selectedDataSource = null;
                }
            }

            if (selectedDataSource is IDbDriver)
            {
                IDbDriver db = selectedDataSource as IDbDriver;
                //this.txtDataSource.Text = db.ConnectionString;

                System.Collections.Generic.List <string> tableNames = db.GetTableNames();

                foreach (string tableName in tableNames)
                {
                    ComboBoxItem newItem = null;
                    if (tableName.EndsWith("$") & (selectedPlugIn.Key == "Epi.Data.Office.ExcelWBFactory, Epi.Data.Office") ||
                        (selectedPlugIn.Key == "Epi.Data.Office.Excel2007WBFactory, Epi.Data.Office"))
                    {
                        newItem = new ComboBoxItem(tableName.Remove(tableName.Length - 1), tableName.Remove(tableName.Length - 1), tableName);
                    }
                    else
                    {
                        newItem = new ComboBoxItem(tableName, tableName, tableName);
                    }
                    this.cmbDataTable.Items.Add(newItem);
                }
            }
            else if (selectedDataSource is Project)
            {
                Project project = selectedDataSource as Project;
                //txtDataSource.Text = (selectedDataSource == selectedProject) ? SharedStrings.CURRENT_PROJECT : project.FullName;

                foreach (string s in project.GetViewNames())
                {
                    ComboBoxItem newItem = new ComboBoxItem(s, s, s);
                    this.cmbDataTable.Items.Add(newItem);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor with file path
        /// </summary>
        /// <param name="filePath">The file path to the location of the PRJ file</param>
        public VhfProject(string filePath)
            : base(filePath)
        {
            XDocument doc  = XDocument.Load(filePath);
            XElement  root = doc.Root;

            XElement isVhf        = root.Element("IsVHF");
            XElement isLab        = root.Element("IsLabProject");
            XElement outbreakDate = root.Element("OutbreakDate");
            XElement outbreakName = root.Element("OutbreakName");
            XElement culture      = root.Element("Culture");

            XElement smsModule = root.Element("SmsModule");

            MacAddress   = Core.Common.GetMacAddress();
            IsVHF        = bool.Parse(isVhf.Value);
            IsLabProject = bool.Parse(isLab.Value);
            OutbreakDate = new DateTime(long.Parse(outbreakDate.Value));
            OutbreakName = outbreakName.Value;
            if (culture == null)
            {
                Culture = String.Empty;
                //throw new InvalidOperationException("Project's culture settings cannot be null.");
                // probably don't need an exception here since we're moving to database-based culture checking
            }
            else
            {
                Culture = culture.Value;
            }

            SmsModule = new SmsModule();

            // setup SMS module
            if (smsModule != null)
            {
                XElement readReceipts = smsModule.Element("SendsReadReceipts");
                if (readReceipts != null)
                {
                    SmsModule.SendsReadReceipts = bool.Parse(readReceipts.Value);
                }

                XElement startupCommands = smsModule.Element("StartupCommands");
                if (startupCommands != null)
                {
                    SmsModule.StartupCommands = startupCommands.Value;
                }

                XElement authCode = smsModule.Element("SelfRegistrationCode");
                if (authCode != null)
                {
                    SmsModule.SelfRegistrationCode = authCode.Value;
                }

                XElement allowSelfReg = smsModule.Element("AllowsSelfRegistration");
                if (allowSelfReg != null)
                {
                    SmsModule.AllowsSelfRegistration = bool.Parse(allowSelfReg.Value);
                }

                XElement pollRate = smsModule.Element("PollRate");
                if (pollRate != null)
                {
                    SmsModule.PollRate = int.Parse(pollRate.Value);
                }

                XElement authorizedSenders = smsModule.Element("AuthorizedSmsSenders");
                if (authorizedSenders != null)
                {
                    SmsModule.AuthorizedSmsSenders.Clear();

                    var query = (from xml in authorizedSenders.Descendants()
                                 select xml);

                    foreach (XElement element in query)
                    {
                        if (element.Name.ToString().Equals("AuthorizedSmsSender", StringComparison.OrdinalIgnoreCase))
                        {
                            string phoneNumber = element.Element("PhoneNumber").Value;

                            SmsSenderInfo sender = new SmsSenderInfo(phoneNumber);

                            sender.Name = element.Element("Name").Value;
                            sender.CanAddUpdateCases      = bool.Parse(element.Element("CanAddUpdateCases").Value);
                            sender.CanAddUpdateContacts   = bool.Parse(element.Element("CanAddUpdateContacts").Value);
                            sender.CanAddUpdateLabResults = bool.Parse(element.Element("CanAddUpdateLabResults").Value);

                            SmsModule.AuthorizedSmsSenders.Add(sender);
                        }
                    }
                }
            }

            IDbDriver db = this.CollectedData.GetDatabase();

            bool connected = db.TestConnection();

            if (connected)
            {
                Query     selectQuery = db.CreateQuery("SELECT * FROM [metaViews]");
                DataTable dt          = db.Select(selectQuery);

                foreach (DataRow row in dt.Rows)
                {
                    if (row["Name"].ToString().Equals(Core.Constants.CASE_FORM_NAME))
                    {
                        CaseFormId = int.Parse(row["ViewId"].ToString());
                    }
                    else if (row["Name"].ToString().Equals(Core.Constants.CONTACT_FORM_NAME))
                    {
                        ContactFormId = int.Parse(row["ViewId"].ToString());
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("No connection to database detected.");
            }
        }
Ejemplo n.º 11
0
        private void SetupOutputDataSource()
        {
            ComboBoxItem     selectedPlugIn = cmbSourceDataFormat.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;

            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();

                    try
                    {
                        success = db.TestConnection();
                    }
                    catch
                    {
                        success = false;
                        MessageBox.Show("Could not connect to selected data source.");
                    }

                    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;

                System.Collections.Generic.List <string> tableNames = db.GetTableNames();

                foreach (string tableName in tableNames)
                {
                    ComboBoxItem newItem = new ComboBoxItem();//tableName, tableName, tableName);
                    newItem.Content = tableName;
                    cmbSourceTable.Items.Add(tableName);
                    //this.cmbDataTable.Items.Add(newItem);
                }
            }

            pnlProgress.Visibility = System.Windows.Visibility.Collapsed;
        }