private void SaveConnectionDefinition()
        {
            string tempConnectionString = string.Empty;

            if (this.ConnectionName.Trim().Length == 0)
            {
                AppMessages.DisplayErrorMessage("You must specify a connection name.");
                return;
            }

            if (this.ConnectionString.Trim().Length == 0)
            {
                this.ConnectionString = BuildConnectionString();
                if (this.ConnectionString.Trim().Length == 0)
                {
                    AppMessages.DisplayErrorMessage("You must specify connection properties and build a connection string.");
                    return;
                }
            }
            else
            {
                tempConnectionString = BuildConnectionString();
                if (this.ConnectionString != tempConnectionString)
                {
                    _msg.Length = 0;
                    _msg.Append("One or more connection properties have changes since connection string was last built.\r\n");
                    _msg.Append("Do you want to rebuild the connection string before saving it?");
                    DialogResult res = AppMessages.DisplayMessage(_msg.ToString(), "Connection string save ...", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                    if (res == DialogResult.Yes)
                    {
                        this.ConnectionString = tempConnectionString;
                    }
                    else
                    {
                        if (res == DialogResult.Cancel)
                        {
                            return;
                        }
                        else
                        {
                            //continue with save operation even though connection string has not been updated with latest connection properties
                            ;
                        }
                    }
                }
            }


            PFConnectionDefinition conndef = _csp.BuildConnectionDefinition(this.ConnectionName, this.ConnectionString, this.ConnectionAccessStatus);
            string filename = _csp.SaveConnectionDefinition(conndef);

            if (filename != string.Empty)
            {
                _msg.Length = 0;
                _msg.Append("Connection definition saved to ");
                _msg.Append(filename);
                _msg.Append(".");
                AppMessages.DisplayInfoMessage(_msg.ToString());
            }
        }
Beispiel #2
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                NewConnectionDefinition();
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                _db.ConnectionString  = conndef.ConnectionString;

                this.txtDataSource.Text = _db.GetPropertyValue("DataSource").ToString();
                this.txtUserId.Text     = _db.GetPropertyValue("Username").ToString();
                this.txtPassword.Text   = _db.GetPropertyValue("Password").ToString();
                this.chkUseIntegratedSecurity.Checked = (bool)_db.GetPropertyValue("UseIntegratedSecurity");

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                NewConnectionDefinition();
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                _db.ConnectionString  = conndef.ConnectionString;

                //TODO (DONE)
                this.txtServerName.Text   = _db.GetPropertyValue("ServerName").ToString();
                this.txtDatabaseName.Text = _db.GetPropertyValue("DatabaseName").ToString();
                this.txtUsername.Text     = _db.GetPropertyValue("Username").ToString();
                this.txtPassword.Text     = _db.GetPropertyValue("Password").ToString();
                this.txtPortNumber.Text   = _db.GetPropertyValue("PortNumber").ToString();
                //END TODO

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
Beispiel #4
0
        //methods

        /// <summary>
        /// Displays the form dialog for inputting values for connection string keys.
        /// </summary>
        /// <returns>OK if input is to be accepted by the caller. Cancel if input should be ignored by the caller.</returns>
        public DialogResult ShowConnectionPrompt()
        {
            DialogResult res = DialogResult.None;

            _frm = GetFormToDisplay();
            if (_frm != null)
            {
                _frm.DbPlatform       = _dbPlatform;
                _frm.ConnectionName   = _connectionName;
                _frm.ConnectionString = _connectionString;
                _frm.CSP = this;
                res      = _frm.ShowDialog();
                if (res == DialogResult.OK)
                {
                    _connectionName         = _frm.ConnectionName;
                    _connectionString       = _frm.ConnectionString;
                    _connectionAccessStatus = _frm.ConnectionAccessStatus;
                    _connectionDefinition   = BuildConnectionDefinition();
                }
                else
                {
                    ;
                }
            }
            else
            {
                res         = DialogResult.Cancel;
                _msg.Length = 0;
                _msg.Append("Unable to find connection string form for ");
                _msg.Append(this.DbPlatform.ToString());
                _msg.Append(".");
                throw new System.Exception(_msg.ToString());
            }
            return(res);
        }
Beispiel #5
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                PFKeyValueList <string, string> dbPlatformProperties = conndef.DbPlatformConnectionStringProperties;
                //stKeyValuePair<string, string> keyval = default(stKeyValuePair<string, string>);

                this.txtDsnName.Text    = dbPlatformProperties.Find("Dsn").Value;
                this.txtDriverName.Text = dbPlatformProperties.Find("Driver").Value;

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
Beispiel #6
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                PFKeyValueList <string, string> dbPlatformProperties = conndef.DbPlatformConnectionStringProperties;

                this.txtServerName.Text               = dbPlatformProperties.Find("ServerName").Value;
                this.txtDatabaseName.Text             = dbPlatformProperties.Find("DatabaseName").Value;
                this.txtUsername.Text                 = dbPlatformProperties.Find("Username").Value;
                this.txtPassword.Text                 = dbPlatformProperties.Find("Password").Value;
                this.txtApplicationName.Text          = dbPlatformProperties.Find("ApplicationName").Value;
                this.txtWorkstationId.Text            = dbPlatformProperties.Find("WorkstationId").Value;
                this.chkUseIntegratedSecurity.Checked = PFTextProcessor.ConvertStringToBoolean(dbPlatformProperties.Find("UseIntegratedSecurity").Value, "false");
                this.chkUseAsyncProcessing.Checked    = PFTextProcessor.ConvertStringToBoolean(dbPlatformProperties.Find("AsynchronousProcessing").Value, "false");

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
Beispiel #7
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                NewConnectionDefinition();
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                _db.ConnectionString  = conndef.ConnectionString;

                this.txtDataSource.Text             = _db.DataSource;
                this.txtUdlFileName.Text            = _db.UDLFileName;
                this.chkPersistSecurityInfo.Checked = _db.PersistSecurityInfo;
                this.txtProviderName.Text           = _db.Provider;

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            int numValue = 0;

            try
            {
                NewConnectionDefinition();
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                _db.ConnectionString  = conndef.ConnectionString;

                //TODO (DONE)
                this.txtDataSource.Text      = _db.GetPropertyValue("DatabasePath").ToString();
                this.txtPassword.Text        = _db.GetPropertyValue("DatabasePassword").ToString();
                this.chkEncryptionOn.Checked = (bool)_db.GetPropertyValue("EncryptionOn");
                this.cboEncryptionMode.Text  = _db.GetPropertyValue("EncryptionMode").ToString();
                numValue = (int)_db.GetPropertyValue("MaxDatabaseSize");
                if (numValue != (int)enSQLCE35Defaults.MaxDatabaseSize)
                {
                    this.txtMaxDatabaseSize.Text = numValue.ToString();
                }
                else
                {
                    this.txtMaxDatabaseSize.Text = string.Empty;
                }
                numValue = (int)_db.GetPropertyValue("MaxBufferSize");
                if (numValue != (int)enSQLCE35Defaults.MaxBufferSize)
                {
                    this.txtMaxBufferSize.Text = numValue.ToString();
                }
                else
                {
                    this.txtMaxBufferSize.Text = string.Empty;
                }
                numValue = (int)_db.GetPropertyValue("MaxTempFileSize");
                if (numValue != (int)enSQLCE35Defaults.MaxTempFileSize)
                {
                    this.txtMaxTempFileSize.Text = numValue.ToString();
                }
                else
                {
                    this.txtMaxTempFileSize.Text = string.Empty;
                }
                //END TODO

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
Beispiel #9
0
        private void SaveConnectionDefinition()
        {
            string tempConnectionString = string.Empty;

            if (this.ConnectionName.Trim().Length == 0)
            {
                AppMessages.DisplayErrorMessage("You must specify a connection name.");
                return;
            }

            if (this.ConnectionString.Trim().Length == 0)
            {
                this.ConnectionString = BuildConnectionString();
                if (this.ConnectionString.Trim().Length == 0)
                {
                    AppMessages.DisplayErrorMessage("You must specify connection properties and build a connection string.");
                    return;
                }
            }
            //DO NOT PROMPT TO REBUILD FOR OLEDB, even if either dsn or driver parameter has changed. User must specifically use Build button. In most cases connection string must be manually input for OLEDB: parameters on from are not enough.
            //else
            //{
            //    tempConnectionString = BuildConnectionString();
            //    if (this.ConnectionString != tempConnectionString)
            //    {
            //        _msg.Length = 0;
            //        _msg.Append("One or more connection properties have changes since connection string was last built.\r\n");
            //        _msg.Append("Do you want to rebuild the connection string before saving it?");
            //        DialogResult res = AppMessages.DisplayMessage(_msg.ToString(), "Connection string save ...", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
            //        if (res == DialogResult.Yes)
            //        {
            //            this.ConnectionString = tempConnectionString;
            //        }
            //        else
            //        {
            //            if (res == DialogResult.Cancel)
            //                return;
            //            else
            //            {
            //                //continue with save operation even though connection string has not been updated with latest connection properties
            //                ;
            //            }
            //        }
            //    }
            //}


            PFConnectionDefinition conndef = _csp.BuildConnectionDefinition(this.ConnectionName, this.ConnectionString, this.ConnectionAccessStatus);
            string filename = _csp.SaveConnectionDefinition(conndef);

            if (filename != string.Empty)
            {
                _msg.Length = 0;
                _msg.Append("Connection definition saved to ");
                _msg.Append(filename);
                _msg.Append(".");
                AppMessages.DisplayInfoMessage(_msg.ToString());
            }
        }
Beispiel #10
0
        }//end method

        /// <summary>
        /// Retrieves all connection definitions defined and saved by current user.
        /// </summary>
        /// <returns>PFConnectionDefinition object.</returns>
        public PFConnectionDefinition GetConnectionDefinition()
        {
            PFConnectionDefinition conndef = default(PFConnectionDefinition);

            string[] conndefFiles = Directory.GetFiles(_connectionManager.ConnectionDefintionsLocation, "*.xml", SearchOption.AllDirectories);

            return(conndef);
        }
        private void OpenConnectionDefinition()
        {
            PFConnectionDefinition conndef = _csp.GetConnectionDefinition(_dbPlatform);

            if (conndef != default(PFConnectionDefinition))
            {
                LoadConnectionDefinitionToForm(conndef);
            }
            this.Focus();
        }
Beispiel #12
0
 private PFConnectionDefinition BuildConnectionDefinition()
 {
     _connectionDefinition                        = new PFConnectionDefinition();
     _connectionDefinition.DbPlatform             = _dbPlatform;
     _connectionDefinition.ConnectionName         = _connectionName;
     _connectionDefinition.ConnectionString       = _connectionString;
     _connectionDefinition.ProviderDefinition     = _connectionManager.FindProvider(_dbPlatform.ToString());
     _connectionDefinition.ConnectionAccessStatus = _connectionAccessStatus;
     GetPlatformPropertiesAndKeys();
     return(_connectionDefinition);
 }
Beispiel #13
0
        /// <summary>
        /// Saves connection definition to external storage.
        /// </summary>
        /// <param name="connDef">Connection definition object to be saved.</param>
        /// <returns>Path to saved XML file containing connection definition.</returns>
        public string SaveConnectionDefinition(PFConnectionDefinition connDef)
        {
            string retval        = string.Empty;
            string pathToDefFile = Path.Combine(_connectionManager.ConnectionDefintionsLocation, connDef.DbPlatform.ToString(), connDef.ConnectionName + ".xml");

            if (File.Exists(pathToDefFile))
            {
                _msg.Length = 0;
                _msg.Append("Connection definition already exists at ");
                _msg.Append(pathToDefFile);
                _msg.Append(".\r\nDo you wish to overwrite the file?");
                DialogResult res = AppMessages.DisplayMessage(_msg.ToString(), "Save Connection ...", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (res != DialogResult.Yes)
                {
                    return(retval);
                }
            }
            retval = _connectionManager.SaveConnection(connDef);
            return(retval);
        }
Beispiel #14
0
        /// <summary>
        /// Retrieves connection definitions defined and saved by current user for the specified database platform.
        /// </summary>
        /// <param name="dbPlat">DatabasePlatform used in the connection strings to be retrieved.</param>
        /// <returns>PFConnectionDefinition object.</returns>
        public PFConnectionDefinition GetConnectionDefinition(DatabasePlatform dbPlat)
        {
            PFConnectionDefinition conndef  = default(PFConnectionDefinition);
            string           pathToDefFiles = Path.Combine(_connectionManager.ConnectionDefintionsLocation, dbPlat.ToString());
            PFNameListPrompt nlp            = new PFNameListPrompt();

            string[] conndefFiles = Directory.GetFiles(pathToDefFiles, "*.xml", SearchOption.AllDirectories);

            if (conndefFiles.Length == 0)
            {
                _msg.Length = 0;
                _msg.Append("Unabled to find any saved connection definitions in ");
                _msg.Append(pathToDefFiles);
                _msg.Append(".");
                AppMessages.DisplayAlertMessage(_msg.ToString());
                return(conndef);
            }

            nlp.Text           = "Connection Definition Chooser ...";
            nlp.lblSelect.Text = "Select connection definition to open from list below:";
            foreach (string condefFile in conndefFiles)
            {
                string conndefName = Path.GetFileNameWithoutExtension(condefFile);
                nlp.lstNames.Items.Add(conndefName);
            }

            DialogResult res = nlp.ShowDialog();

            if (res == DialogResult.OK)
            {
                string selectedConnDefName = nlp.lstNames.SelectedItem.ToString();
                conndef = PFConnectionDefinition.LoadFromXmlFile(Path.Combine(pathToDefFiles, selectedConnDefName + ".xml"));
            }

            return(conndef);
        }