예제 #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.txtUserName.Text != String.Empty && this.txtPassword.Text != String.Empty)
            {
                try
                {
                    khoitao(cmbServer.SelectedValue.ToString(), this.cmbDatabase.Text.Trim(), txtUserName.Text.Trim(), txtPassword.Text.Trim());
                    con = new SqlConnection("Data Source='" + cmbServer.SelectedValue.ToString() + "';Initial Catalog='" + this.cmbDatabase.Text + "';User ID='" + txtUserName.Text + "';Password='******'");
                    con.Open();

                    c.writefile(cmbServer.SelectedValue.ToString(), this.cmbDatabase.Text.Trim(), this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim());



                    frmDangNhap obj = new frmDangNhap();
                    obj.ShowDialog();
                    this.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    RadMessageBox.Show("\nĐường dẫn kết nối không đúng !\n", "Thông báo", MessageBoxButtons.OKCancel, RadMessageIcon.Exclamation);
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                try
                {
                    khoitao(cmbServer.SelectedValue.ToString(), this.cmbDatabase.Text.Trim(), "", "");
                    con = new SqlConnection("Data Source='" + cmbServer.SelectedValue.ToString() + "';Initial Catalog='" + this.cmbDatabase.Text + "';Integrated Security=True");
                    con.Open();

                    c.writefile(cmbServer.SelectedValue.ToString(), this.cmbDatabase.Text.Trim(), this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim());



                    frmDangNhap obj = new frmDangNhap();
                    obj.ShowDialog();
                    this.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    RadMessageBox.Show("\nĐường dẫn kết nối không đúng !\n", "Thông báo", MessageBoxButtons.OKCancel, RadMessageIcon.Exclamation);
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #2
0
        private void frmConfig_Load(object sender, EventArgs e)
        {
            this.cmbDatabase.Items.Clear();
            //if (this.txtUserName.Text != String.Empty && this.txtPassword.Text != String.Empty)
            //{

            c.readfile();
            string strDatabase = "";

            if (c.strLine1.Contains("Server:") == true)
            {
                cmbServer.SelectedValue = c.strLine1.Substring(7);
            }
            if (c.strLine2.Contains("Database:") == true)
            {
                strDatabase = c.strLine2.Substring(9);
            }
            if (c.strLine3.Contains("Username:"******"Password:"******"Data Source='" + cmbServer.SelectedValue.ToString() + "';Initial Catalog='" + strDatabase + "';User ID='" + txtUserName.Text + "';Password='******'");

                    con.Open();

                    SqlCommand scmd = new SqlCommand("select * from tbl_NhanVien", con);
                    scmd.ExecuteNonQuery();
                    khoitao(cmbServer.SelectedValue.ToString(), strDatabase, txtUserName.Text, txtPassword.Text);

                    frmDangNhap obj = new frmDangNhap();
                    obj.ShowDialog();
                    this.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    //RadMessageBox.Show("\nĐường dẫn kết nối không đúng ! \nVui lòng xem lại !\n", "Thông báo", MessageBoxButtons.OKCancel, RadMessageIcon.Exclamation);
                }
            }
            else if (txtUserName.Text.Trim() == String.Empty && txtPassword.Text.Trim() == String.Empty)
            {
                try
                {
                    con = new SqlConnection("Data Source='" + cmbServer.SelectedValue.ToString() + "';Initial Catalog='" + strDatabase + "';Integrated Security=True");

                    con.Open();

                    SqlCommand scmd = new SqlCommand("select * from tbl_NhanVien", con);
                    scmd.ExecuteNonQuery();
                    khoitao(cmbServer.SelectedValue.ToString(), strDatabase, "", "");
                    frmDangNhap obj = new frmDangNhap();
                    obj.ShowDialog();
                    this.Close();
                    con.Close();
                }
                catch (Exception ex)
                {
                    //RadMessageBox.Show("\nĐường dẫn kết nối không đúng ! \nVui lòng xem lại !\n", "Thông báo", MessageBoxButtons.OKCancel, RadMessageIcon.Exclamation);
                }
            }
            else
            {
                //RadMessageBox.Show("\nĐường dẫn kết nối không đúng ! \nVui lòng xem lại !\n", "Thông báo", MessageBoxButtons.OKCancel, RadMessageIcon.Exclamation);
            }
        }