示例#1
0
        private void btn_sql_Click(object sender, EventArgs e)
        {
            if (!m_Active)
            {
                MessageBox.Show("软件尚未激活! 请联系软件发布人给予激活!");
                return;
            }
            CSGHelper.SetSQLNames(txt_sqlAccountName.Text, txt_sqlSanvtName.Text, txt_sqlLogName.Text);
            if (btn_sql.Text == "连接数据库")
            {
                //连接数据库
                string conn_str = "Data Source = " + sql_srvAddr + "," + sql_srvPort + "; Initial Catalog = " + txt_sqlAccountName.Text + "; User Id = " + sql_srvUser + "; Password = "******";";
                //string conn_str = "server = " + sql_srvAddr + "," + sql_srvPort + "; database = " + txt_sqlAccountName.Text + "; uid = " + sql_srvUser + "; pwd = " + sql_srvPwd + ";";
                if (!CSGHelper.SqlConn(conn_str))
                {
                    MessageBox.Show("数据库连接失败!");
                    return;
                }
                else
                {
                    MessageBox.Show("数据库连接成功!");

                    btn_sql.Text                = "断开连接";
                    lbl_sqlStatus.Text          = "数据库已连接";
                    txt_sqlsvr.ReadOnly         = true;
                    txt_sqlPort.ReadOnly        = true;
                    txt_sqlAcc.ReadOnly         = true;
                    txt_sqlPwd.ReadOnly         = true;
                    txt_sqlAccountName.ReadOnly = true;
                    txt_sqlSanvtName.ReadOnly   = true;
                    txt_sqlLogName.ReadOnly     = true;
                }
            }
            else
            {
                if (!CSGHelper.SqlClose())
                {
                    MessageBox.Show("断开数据库连接失败!");
                    return;
                }
                else
                {
                    btn_sql.Text                = "连接数据库";
                    lbl_sqlStatus.Text          = "数据库未连接";
                    txt_sqlsvr.ReadOnly         = false;
                    txt_sqlPort.ReadOnly        = false;
                    txt_sqlAcc.ReadOnly         = false;
                    txt_sqlPwd.ReadOnly         = false;
                    txt_sqlAccountName.ReadOnly = false;
                    txt_sqlSanvtName.ReadOnly   = false;
                    txt_sqlLogName.ReadOnly     = false;
                }
            }
        }
示例#2
0
        private void btn_sql_Click(object sender, EventArgs e)
        {
            if (btn_sql.Text == "连接数据库")
            {
                //连接数据库
                //*
                string conn_str = "Data Source = " + sql_srvAddr + "," + sql_srvPort + "; Initial Catalog = " + sqlAccountName + "; User Id = " + sql_srvUser + "; Password = "******";";
                if (!CSGHelper.SqlConn(conn_str))
                {
                    MessageBox.Show("数据库连接失败!");
                    return;
                }
                else
                {
                    MessageBox.Show("数据库连接成功!");

                    btn_sql.Text                = "断开连接";
                    lbl_sqlStatus.Text          = "数据库已连接";
                    txt_sqlsvr.ReadOnly         = true;
                    txt_sqlPort.ReadOnly        = true;
                    txt_sqlAcc.ReadOnly         = true;
                    txt_sqlPwd.ReadOnly         = true;
                    txt_sqlAccountName.ReadOnly = true;
                }
            }
            else
            {
                //*
                if (!CSGHelper.SqlClose())
                {
                    MessageBox.Show("断开数据库连接失败!");
                    return;
                }
                else
                {
                    btn_sql.Text                = "连接数据库";
                    lbl_sqlStatus.Text          = "数据库未连接";
                    txt_sqlsvr.ReadOnly         = false;
                    txt_sqlPort.ReadOnly        = false;
                    txt_sqlAcc.ReadOnly         = false;
                    txt_sqlPwd.ReadOnly         = false;
                    txt_sqlAccountName.ReadOnly = false;
                }
            }
        }