/// <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); } }
/// <summary> /// 数据查询,绑定 /// </summary> private void BindData() { string strWhere = getConduction(); DataSet ds = bCommon.GetMasterList(_tableName, txtCode.Text.Trim(), txtName.Text.Trim(), strWhere); _currentDt = ds.Tables[0]; ReSetCurrentDt(); for (int i = _currentDt.Rows.Count; i < _pageSize; i++) { _currentDt.Rows.Add(ds.Tables[0].NewRow()); } this.dgvData.DataSource = _currentDt; }