Exemplo n.º 1
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             Connection            cn   = value as Connection;
             DlgSelectDatabaseType dlg1 = new DlgSelectDatabaseType();
             if (cn != null)
             {
                 dlg1.SetSelection(cn.DatabaseType);
             }
             else
             {
                 cn = new Connection();
             }
             if (edSvc.ShowDialog(dlg1) == System.Windows.Forms.DialogResult.OK)
             {
                 cn.DatabaseType = dlg1.SelectedType;
                 ConnectionStringSelector css = new ConnectionStringSelector();
                 ConnectStringContext     csc = new ConnectStringContext(cn);
                 string s = cn.ConnectionString;
                 object v = css.EditValue(csc, provider, s);
                 if (v != null)
                 {
                     string s2 = v.ToString();
                     cn.ConnectionString = s2;
                 }
                 value = cn.Clone();
             }
         }
     }
     return(value);
 }
Exemplo n.º 2
0
        public static string SetCredentialToFirebirdConnectionString(string connectionString, string user, string userPassword)
        {
            string s    = connectionString;
            string file = GetDatabaseName(s);

            if (!string.IsNullOrEmpty(file))
            {
                file = file.Replace(Filepath.FOLD_CPMMPMAPPDATA, Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                if (!System.IO.File.Exists(file))
                {
                    string fn = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), System.IO.Path.GetFileName(file));
                    if (System.IO.File.Exists(fn))
                    {
                        file = fn;
                        ConnectionStringSelector.InsertValue(ref s, SQL_Database, file);
                    }
                }
            }
            if (!string.IsNullOrEmpty(user))
            {
                ConnectionStringSelector.InsertValue(ref s, DB_USER, user);
            }
            if (!string.IsNullOrEmpty(userPassword))
            {
                ConnectionStringSelector.InsertValue(ref s, ACCESS_USERPASS, userPassword);
            }
            return(s);
        }
Exemplo n.º 3
0
        public bool LoadAccess(string sPath, string sDBPass, string sUser, string sUserPass)        //,out string errStr)
        {
            try
            {
                sOriginalPath = sPath;
                this.Text     = this.Text + " - " + System.IO.Path.GetFileName(sPath);
                sBackupPath   = sPath + ".BACKUP";
                System.IO.File.Copy(sOriginalPath, sBackupPath, true);
                sConnectionString = ConnectionStringSelector.MakeAccessConnectionString(sOriginalPath, false, true, sDBPass, sUser, sUserPass);
                ConnectionStringSelector.InsertValue(ref sConnectionString, "Password", sUserPass);
                ConnectionStringSelector.InsertValue(ref sConnectionString, "Jet OLEDB:Database Password", sDBPass);
                qry = new EasyQuery();
                Connection objCn = new Connection();
                objCn.DatabaseType     = typeof(OleDbConnection);
                objCn.ConnectionString = sConnectionString;

                qry.DatabaseConnection = new ConnectionItem(objCn);
                qry.Description        = "Table editor";
                //
                objCn.SetCredential(sUser, sUserPass, sDBPass);
                schema.dbCon = objCn;
                schema.LoadSchema();
                loadTables();
                return(true);
            }
            catch (Exception er)
            {
                FormLog.NotifyException(true, er);
            }
            finally
            {
            }
            return(false);
        }
Exemplo n.º 4
0
        public void LoadData(string connectionString)
        {
            string sServer = ConnectionStringSelector.GetServerName(connectionString);

            if (string.IsNullOrEmpty(sServer))
            {
                sServer = ConnectionStringSelector.GetDataSource(connectionString);
            }
            string sDB = ConnectionStringSelector.GetDatabaseName(connectionString);

            if (string.IsNullOrEmpty(sDB))
            {
                sDB = ConnectionStringSelector.GetCatalogName(connectionString);
            }
            string sUser = ConnectionStringSelector.GetSQLUser(connectionString);

            if (string.IsNullOrEmpty(sUser))
            {
                sUser = ConnectionStringSelector.GetUser(connectionString);
            }
            string sPass    = ConnectionStringSelector.GetSQLUserPassword(connectionString);
            bool   bTrusted = ConnectionStringSelector.IsTrustedSQLServerConnection(connectionString);

            LoadData(sServer, sDB, sUser, sPass, bTrusted);
        }
Exemplo n.º 5
0
        public static string SetCredentialToMsSqlServerConnectionString(string connectionString, string user, string userPassword)
        {
            string s = connectionString;

            ConnectionStringSelector.InsertValue(ref s, SQL_USERID, user);
            ConnectionStringSelector.InsertValue(ref s, SQL_USERPASS, userPassword);
            return(s);
        }
Exemplo n.º 6
0
        public void LoadData(string connectionString)
        {
            bool   readOnly = false;
            string mode     = ConnectionStringSelector.GetConnectionMode(connectionString);

            if (string.CompareOrdinal(mode, "Read") == 0)
            {
                readOnly = true;
            }
            LoadData(
                ConnectionStringSelector.GetDataSource(connectionString),
                ConnectionStringSelector.GetAccessDatabasePassword(connectionString),
                ConnectionStringSelector.GetUser(connectionString),
                ConnectionStringSelector.GetAccessUserPassword(connectionString), readOnly);
        }
Exemplo n.º 7
0
 public static string RemovePasswords(string connectionString)
 {
     ConnectionStringSelector.InsertValue(ref connectionString, ACCESS_USERPASS, null);
     ConnectionStringSelector.InsertValue(ref connectionString, ACCESS_DBPASS, null);
     return(connectionString);
 }
Exemplo n.º 8
0
 public static void SetDataSource(ref string connectionString, string dataSource)
 {
     ConnectionStringSelector.InsertValue(ref connectionString, DB_DATASOURCE, dataSource);
 }
Exemplo n.º 9
0
        bool makeConnectionString()
        {
            bool bRet = false;

            sRet = txtFile.Text.Trim();
            if (sRet.Length > 0)
            {
                sUser   = txtUser.Text.Trim();
                sPass   = txtPass1.Text;
                sDBPass = txtDBPass1.Text;
                if (!System.IO.File.Exists(sRet))
                {
                    string ext = System.IO.Path.GetExtension(sRet);
                    if (string.IsNullOrEmpty(ext) || string.Compare(ext, ".mdb", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        string sNew;
                        if (sRet.EndsWith(".", StringComparison.Ordinal))
                        {
                            sNew = sRet + "mdb";
                        }
                        else
                        {
                            sNew = sRet + ".mdb";
                        }
                        sRet = sNew;
                    }
                    if (!System.IO.File.Exists(sRet))
                    {
                        if (_forDatabaseEditing)
                        {
                            //create a new Access database
                            string sFile0 = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                            sFile0 = System.IO.Path.Combine(sFile0, "epEmpty.mdb");
                            if (System.IO.File.Exists(sFile0))
                            {
                                try
                                {
                                    System.IO.File.Copy(sFile0, sRet, false);
                                }
                                catch (Exception er)
                                {
                                    MessageBox.Show(this, er.Message, "Create Microsoft Access Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                MessageBox.Show(this, "File not found: " + sFile0, "Create Microsoft Access Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
                if (System.IO.File.Exists(sRet))
                {
                    bReadOnly         = chkReadOnly.Checked;
                    sConnectionString = ConnectionStringSelector.MakeAccessConnectionString(sRet, bReadOnly, false, sDBPass, sUser, sPass);
                    bRet = true;
                }
                else
                {
                    MessageBox.Show(this, "Database File does not exist", "Choose database file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(this, "Database File not specified", "Choose database file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(bRet);
        }