コード例 #1
0
 private void btnSignIn_Click(object sender, EventArgs e)
 {
     //Kiểm tra đã nhập đủ các dữ liệu
     if (txtUsername.TextLength > 0 && txtPassword.TextLength > 0 && txtIP.TextLength > 0)
     {
         this.userName = this.txtUsername.Text;
         this.ip       = this.txtIP.Text;
         this.passWord = this.txtPassword.Text;
         string conn = "Data Source=" + this.ip + ";" + "User ID="
                       + this.userName + ";" + "Password="******";";
         DynamicConnection.connectstr = conn;
         DB = new DBMSQuanTraSuaDataContext(DynamicConnection.connectstr);
         DB.Connection.ConnectionString = conn;
         try
         {
             DB.Connection.Open();
         }
         catch
         {
             MessageBox.Show("KHÔNG THỂ KẾT NỐI ĐẾN SERVER NÀY!");
             return;
         }
         if (DB.Connection.State == ConnectionState.Open)
         {
             this.pnlFirstTextBox.Visible  = false;
             this.pnlSecondTextBox.Visible = true;
             this.AcceptButton             = this.btnConnect;
             DataTable databases = DB.Connection.GetSchema("databases");
             if (databases != null)
             {
                 foreach (DataRow database in databases.Rows)
                 {
                     string databaseName = database.Field <string>("Database_Name");
                     if (databaseName != "master" && databaseName != "model" &&
                         databaseName != "tempdb" && databaseName != "msdb" &&
                         databaseName != "ReportServer$SQLEXPRESS" &&
                         databaseName != "ReportServer$SQLEXPRESSTempDB")
                     {
                         this.cbxDatabase.Items.Add(databaseName);
                     }
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Vui lòng nhập đầy đủ thông tin!");
         return;
     }
 }
コード例 #2
0
 private void FormMain_Load(object sender, EventArgs e)
 {
     dangNhap.ShowDialog();
     DB = new DBMSQuanTraSuaDataContext(DynamicConnection.connectstr);
     this.pnlMain.Controls.Clear();
 }