Esempio n. 1
0
        private void checkDBButton_Click(object sender, EventArgs e)
        {
            string userId     = userIdBox.Text;
            string pwd        = pwdBox.Text;
            string server     = serverBox.Text;
            string serverType = fwqTypeBox.Text;

            if (userId.Length != 0 && pwd.Length != 0 && server.Length != 0 && serverType.Length != 0)
            {
                dbConnection = new DBconnectionSQLServer(userId, pwd, server);
                if (DBconnectionSQLServer.OpenConnect())
                {
                    DBShowBox.ForeColor = System.Drawing.Color.Black;
                    DataTable dt = DBconnectionSQLServer.ShowDatabaseList();
                    foreach (DataRow row in dt.Rows)
                    {
                        if (row["name"].ToString() != "tempdb")
                        {
                            DBShowBox.Items.Add(row["name"].ToString());
                        }
                    }
                    DBShowBox.SelectedItem = DBShowBox.Items[0];
                    DBconnectionSQLServer.CloseConnect();
                }
                else
                {
                    MessageBox.Show("连接失败,信息有误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                DBShowBox.ForeColor = System.Drawing.Color.Red;
                DBShowBox.Text      = "请先填写完整信息!";
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string userId     = userIdBox.Text;
            string pwd        = pwdBox.Text;
            string server     = serverBox.Text;
            string serverType = fwqTypeBox.Text;
            string dbName     = DBShowBox.Text;

            if (userId.Length == 0 || server.Length == 0 || pwd.Length == 0 || fwqTypeBox.Text.Length == 0)
            {
                MessageBox.Show("请填写完整信息!", "消息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                FileStream      fs   = new FileStream(path + "\\data1.bin", FileMode.Create);
                BinaryFormatter bf   = new BinaryFormatter();
                ConfigerManger  conf = new ConfigerManger();
                conf.UserId     = userId;
                conf.Server     = server;
                conf.ServerType = serverType;
                if (serverType != "SQLServer")
                {
                    conf.DbName = "";
                }
                else
                {
                    conf.DbName = dbName;
                }

                if (remberpwdCB.Checked) //  如果单击了记住密码的功能
                {                        //  在文件中保存密码
                    conf.Pwd = pwd;
                }
                else
                {   //  不在文件中保存密码
                    conf.Pwd = "";
                }

                //  选在集合中是否存在用户名
                if (configs.ContainsKey(conf.Server))
                {
                    configs.Remove(conf.Server);
                }
                configs.Add(conf.Server, conf);
                //要先将User类先设为可以序列化(即在类的前面加[Serializable])
                bf.Serialize(fs, configs);
                //user.Password = this.PassWord.Text;
                fs.Close();

                switch (serverType)
                {
                case "SQLServer":
                {
                    // dbConnection = new DBconnectionSQLServer(userId: userId, password: pwd, server: server);
                    dbConnection = new DBconnectionSQLServer(userId, pwd, server);
                    if (DBconnectionSQLServer.OpenConnect())
                    {
                        this.Hide();
                        //this.TopLevel = false;
                        FormMainTableShow formMain = new FormMainTableShow();
                        formMain.DbName = dbName;
                        formMain.DbType = serverType;

                        formMain.Tag = this;
                        formMain.Show();
                    }
                    else
                    {
                        MessageBox.Show("连接失败,信息有误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;
                }

                case "Oracle":
                {
                    oracleConnection = new DBconnectionOracle(userId, pwd, server);
                    if (DBconnectionOracle.OpenConnect())
                    {
                        this.Hide();
                        //this.TopLevel = false;
                        FormMainTableShow formMain = new FormMainTableShow();
                        formMain.DbName = dbName;
                        formMain.DbType = serverType;
                        formMain.Tag    = this;
                        formMain.Show();
                        //formMain.Parent = this;
                    }
                    else
                    {
                        MessageBox.Show("连接失败,信息有误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;
                }
                }
            }
        }