Exemple #1
0
        private void btnKetNoi_Click(object sender, EventArgs e)
        {
            // ghi vào file data
            String Data     = txtServer.Text;
            String Database = txtDatabase.Text;
            String User     = txtUser.Text;
            String pass     = txtPassword.Text;
            //String filePath = "D:\\DH\\đồ án lập trình window\\QuanlyLinhKien\\QuanLyLinhKien\\QuanLyLinhKien\\data.txt";
            String       filePath = "data.txt";
            FileStream   fs       = new FileStream(filePath, FileMode.Create);
            StreamWriter sWriter  = new StreamWriter(fs, Encoding.UTF8);

            sWriter.WriteLine(Data);
            sWriter.WriteLine(Database);
            sWriter.WriteLine(User);
            sWriter.WriteLine(pass);
            sWriter.Flush();
            fs.Close();

            if (chb_integrate.Checked == true)
            {
                try
                {
                    String s = @"Data source = " + txtServer.Text + ";Initial catalog=" + txtDatabase.Text + ";integrated security= true";

                    conn = new SqlConnection(s);
                    conn.Open();
                    if (conn.State.ToString() == "Open")
                    {
                        MessageBox.Show("Kết nối thành công");
                        DangNhap dn = new DangNhap();
                        this.Hide();
                        dn.Show();
                    }
                    else
                    {
                        MessageBox.Show("Kết nối thất bại");
                    }
                }
                catch
                {
                    MessageBox.Show("Kết nối thất bại");
                }
            }
            else
            {
                try
                {
                    String s = @"Data source = " + txtServer.Text + ";Initial catalog=" + txtDatabase.Text + "; User id=" + txtUser.Text + "; password="******"Open")
                    {
                        MessageBox.Show("Kết nối thành công");
                        DangNhap dn = new DangNhap();
                        dn.conn = conn;
                        this.Close();
                        dn.Show();
                    }
                    else
                    {
                        MessageBox.Show("Kết nối thất bại", "Kết Nối", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                }
                catch
                {
                    MessageBox.Show("Kết nối thất bại");
                }
            }
        }
Exemple #2
0
 private void btnThoat_Click(object sender, EventArgs e)
 {
     this.Hide();
     DangNhap dn = new DangNhap();
     dn.Show();
 }