private void cb_db_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            ConnectString = AES.GetDecryptConnectString(CommonConfigurationManager.GetAppConfig("ConnectString"));
            string[] sqlStrArray = null;
            if (ConnectString != null && ConnectString.Contains(";"))
            {
                sqlStrArray = ConnectString.Split(';');
            }
            if (cb_db_Type.Text == cb_db_Type.Items[0].ToString())
            {
                tlp_SQL_File.Visible   = false;
                tlp_SQL_Server.Visible = true;
                DatabaseType           = EnumDatabaseType.SqlServer;
                if (sqlStrArray != null && sqlStrArray.All(str => !str.Contains("AttachDbFilename")))
                {
                    string serverName = sqlStrArray.Where(cs => cs.Contains("Data Source")).FirstOrDefault();
                    if (serverName != null)
                    {
                        serverName    = serverName.Substring(serverName.IndexOf('=') + 1);
                        tx_db_IP.Text = serverName.Trim();
                    }
                }
            }
            else
            {
                tlp_SQL_File.Visible   = true;
                tlp_SQL_Server.Visible = false;
                DatabaseType           = EnumDatabaseType.SqlFile;
                if (sqlStrArray != null)
                {
                    string filePath = sqlStrArray.Where(cs => cs.Contains("AttachDbFilename")).FirstOrDefault();
                    if (filePath != null)
                    {
                        filePath            = filePath.Substring(filePath.IndexOf('=') + 1);
                        tx_db_FilePath.Text = filePath.Trim();
                    }
                }
            }
            if (sqlStrArray != null)
            {
                string userId = sqlStrArray.Where(cs => cs.Contains("User ID")).FirstOrDefault();
                if (userId != null)
                {
                    userId = userId.Substring(userId.IndexOf('=') + 1);
                    tx_db_UserName.Text = userId.Trim();
                }

                string password = sqlStrArray.Where(cs => cs.Contains("Password")).FirstOrDefault();
                if (password != null)
                {
                    password            = password.Substring(password.IndexOf('=') + 1);
                    tx_db_Password.Text = password.Trim();
                }
            }
        }
        public static bool CheckSystemCode()
        {
            string systemCode = CommonConfigurationManager.GetAppConfig("SystemCode");

            if (systemCode.Trim() == "")
            {
                return(false);
            }
            try
            {
                return(AES.AESDecrypt(systemCode).Equals(SystemInformationCode.GetCpuID() + "zhangdahang"));
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
Example #3
0
        private void UserLogin_Load(object sender, EventArgs e)
        {
            SystemSettingForm.DatabaseType = EnumDatabaseType.SqlServer;
            //string connectString = Properties.Settings.Default["DocMngDBConnectionString"].ToString();

            string connectString = AES.GetDecryptConnectString(CommonConfigurationManager.GetAppConfig("ConnectString"));

            if (connectString == null ||
                !DatabaseHelper.DBHelper.GetDBHelper(SystemSettingForm.DatabaseType).TestDBConnect(connectString))
            {
                SystemSettingForm ssf = new SystemSettingForm();
                if (ssf.ShowDialog() == DialogResult.OK)
                {
                    connectString = AES.GetEncryptConnectString(ssf.ConnectString);
                    var str = AES.GetDecryptConnectString(connectString);
                    CommonConfigurationManager.UpdateAppConfig("ConnectString", connectString);
                    Application.Restart();
                }
                else
                {
                    Application.Exit();
                }
            }
            else
            {
                DatabaseHelper.DBHelper.GetDBHelper(SystemSettingForm.DatabaseType).SetDBConnectString(connectString);
            }

            if (!File.Exists("userData.bin"))
            {
                return;
            }
            cmb_UserName.SelectedIndexChanged += (obj, ee) =>
            {
                if (UserDatas.ContainsKey(cmb_UserName.Text))
                {
                    tb_Password.Text = UserDatas[cmb_UserName.Text];
                }
            };
            try
            {
                //读取文件流对象
                FileStream fs = new FileStream("userData.bin", FileMode.OpenOrCreate);
                if (fs.Length > 0)
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    //读出存在Data.bin 里的用户信息
                    UserDatas = bf.Deserialize(fs) as Dictionary <string, string>;
                    if (UserDatas != null)
                    {
                        cmb_UserName.DataSource = UserDatas.Keys.ToList();
                        if (cmb_UserName.Items.Count > 0)
                        {
                            cmb_UserName.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        File.Delete("userData.bin");
                        cb_Remember.Checked = false;
                    }
                }
                else
                {
                    UserDatas = new Dictionary <string, string>();
                }
                fs.Close();
                fs.Dispose();
                fs = null;
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }
        }
 private void SystemSettingForm_Load(object sender, EventArgs e)
 {
     ConnectString            = AES.GetDecryptConnectString(CommonConfigurationManager.GetAppConfig("ConnectString"));
     cb_db_Type.SelectedIndex = 0;
 }