コード例 #1
0
 /// <summary>
 /// lkSetDB_LinkClicked
 /// </summary>
 private void lkSetDB_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (this.panelDBConfig.Visible)
     {
         return;
     }
     panelDBConfig.Visible = true;
     try
     {
         string strconn = string.Empty;
         strconn = AppXmlTool.ReadXmlFiles("ConnectionString");
         string ConStringEncrypt = AppXmlTool.ReadXmlFiles("ConStringEncrypt");
         if (ConStringEncrypt == "true")
         {
             strconn = DESEncrypt.Decrypt(strconn);
         }
         string[] ary = strconn.Split(';');
         if (ary.Length > 3)
         {
             this.cmbSqlServers.Text   = ary[0].Substring(ary[0].IndexOf("=") + 1).Trim();
             this.txtUserName.Text     = ary[1].Substring(ary[1].IndexOf("=") + 1).Trim();
             this.txtPassword.Text     = ary[2].Substring(ary[2].IndexOf("=") + 1).Trim();
             this.cmbAllDataBases.Text = ary[3].Substring(ary[3].IndexOf("=") + 1).Trim();
         }
     }
     catch (Exception ex)
     {
         Logger.Error("数据库配置文件文读取异常!", ex);
     }
 }
コード例 #2
0
        /// <summary>
        /// 连接保存
        /// </summary>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.cmbSqlServers.Text == "" || this.cmbAllDataBases.Text == "" || this.txtUserName.Text == "" || this.txtPassword.Text == "")
            {
                MessageBox.Show("数据库名称及用户密码不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                string strconn = "Data Source={0};User ID={1};Password={2};Initial Catalog={3};Pooling=true";
                strconn = string.Format(strconn, this.cmbSqlServers.Text.Trim(), this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim(), this.cmbAllDataBases.Text.Trim());

                string ConStringEncrypt = AppXmlTool.ReadXmlFiles("ConStringEncrypt");
                if (ConStringEncrypt == "true")
                {
                    strconn = DESEncrypt.Encrypt(strconn);
                }
                AppXmlTool.XmlNodeWrite("Config.xml", "ConfigSetting//AppConfig//ConnectionString", strconn);
                DialogResult dr = MessageBox.Show("配置信息保存成功,请重新启动应用程序", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Yes)
                {
                    Application.ExitThread();
                    Restart();
                }
                else
                {
                    this.panelDBConfig.Visible = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, 0, false);
                Logger.Error("数据库连接保存、重启!", ex);
            }
        }
コード例 #3
0
        /// <summary>
        ///  init 页面初始化
        /// </summary>
        private void FrmLogin_Load(object sender, EventArgs e)
        {
            this.TransparencyKey    = Color.WhiteSmoke;
            panelDBConfig.BackColor = Color.FromArgb(65, 204, 212, 230);

            try
            {
                string strconn = string.Empty;
                strconn = AppXmlTool.ReadXmlFiles("ConnectionString");
                string ConStringEncrypt = AppXmlTool.ReadXmlFiles("ConStringEncrypt");
                if (ConStringEncrypt == "true")
                {
                    strconn = DESEncrypt.Decrypt(strconn);
                }
                string[] ary = strconn.Split(';');
                if (ary.Length > 3)
                {
                    this.cmbSqlServers.Text   = ary[0].Substring(ary[0].IndexOf("=") + 1).Trim();
                    this.txtUserName.Text     = ary[1].Substring(ary[1].IndexOf("=") + 1).Trim();
                    this.txtPassword.Text     = ary[2].Substring(ary[2].IndexOf("=") + 1).Trim();
                    this.cmbAllDataBases.Text = ary[3].Substring(ary[3].IndexOf("=") + 1).Trim();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("数据库配置文件文读取异常!", ex);
            }

            try
            {
                string strconn = "Data Source={0};User ID={1};Password={2};Initial Catalog={3};Pooling=true";
                strconn = string.Format(strconn, this.cmbSqlServers.Text.Trim(), this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim(), this.cmbAllDataBases.Text.Trim());
                string strsql = string.Empty;
                strsql = "select 1";
                BCommon bcomm = new BCommon();
                if (bcomm.IsDBConn(strconn, strsql))
                {
                    DataTable dt = bcomm.GetMasterList("COMPANY", "", "", "").Tables[0];
                    cboCompany.DisplayMember = "NAME_SHORT";
                    cboCompany.ValueMember   = "CODE";
                    cboCompany.DataSource    = dt;
                    txtLoginUserCode.Focus();
                }
                else
                {
                    MessageBox.Show("数据库连接失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    panelDBConfig.Visible = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Logger.Error("数据库连接失败!", ex);
            }
        }
コード例 #4
0
        /// <summary>
        /// 得到web.config里配置项的数据库连接字符串。
        /// </summary>
        /// <param name="configName"></param>
        /// <returns></returns>
        public static string GetConnectionString(string configName)
        {
            string connectionString = AppXmlTool.ReadXmlFiles(configName);
            string ConStringEncrypt = AppXmlTool.ReadXmlFiles("ConStringEncrypt");

            if (ConStringEncrypt == "true")
            {
                connectionString = CZZD.ERP.Common.DESEncrypt.Decrypt(connectionString);
            }
            return(connectionString);
        }