Esempio n. 1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (raBtnWindows.Checked == true)
            {
                connect = txtServerName.Text + ";Initial Catalog=" + txtDataBaseName.Text + ";Integrated Security=True";
            }
            else
            {
                connect = txtServerName.Text + ";Initial Catalog="
                          + txtDataBaseName.Text + ";Persist Security Info=True;User ID=" + txtUser.Text + ";Password="******"Data Source= " + connect);

            try
            {
                conn.Open();
                System.IO.StreamWriter ghi = new System.IO.StreamWriter("DataBase\\Setting.txt");
                ghi.Write("SS" + MaHoaString.StringToBase64(connect));
                ghi.Close();
                ghi.Dispose();
                MessageBox.Show("Kết nối thành công!\nChương trình sẽ khởi động lại trong vài giây!");
                this.Close();
                Application.Restart();
            }
            catch (Exception u)
            {
                MessageBox.Show("Vui lòng kiểm tra lại kết nối\nError: " + u.Message, "Lỗi kết nối đến CSDL!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 2
0
        public bool Dal_btnDangKy(DTO_ThongTinDangKy TV)
        {
            SqlConnection cnn = StringSQLConnect.StringSQL();

            try
            {
                cnn.Open();
                string stradd = "insert into DangKy (ID, pass, HoTen, SDT, Email, ChucVu) values (N'" + TV.txtID + "', N'"
                                + MaHoaString.GetMD5(MaHoaString.GetMD5(TV.txtpass)) + "', N'" + TV.txtName + "', N'" + TV.txtDT + "', N'" + TV.txtEmail + "', N'" + TV.txtChucvu + "')";
                SqlCommand add = new SqlCommand(stradd, cnn);

                //add.ExecuteNonQuery();
                if (add.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                cnn.Close();
            }
        }
Esempio n. 3
0
        public static SqlConnection StringSQL()
        {
            string CreateFolder = @"DataBase";             // tạo thư mục DataBase

            if (!System.IO.Directory.Exists(CreateFolder)) // kiểm tra xem có tồn tại hay không
            {
                System.IO.Directory.CreateDirectory(CreateFolder);
            }
            string CreateFileTxt = @"DataBase\\Setting.txt";

            if (!System.IO.File.Exists(CreateFileTxt))
            {
                System.IO.FileStream cr = new System.IO.FileStream(CreateFileTxt, System.IO.FileMode.Create);
                cr.Close();
                cr.Dispose();
            }

            System.IO.StreamReader docFile = new System.IO.StreamReader("DataBase\\Setting.txt");
            string ketnoi = "";

            try
            {
                string con = docFile.ReadLine();
                ketnoi = MaHoaString.Base64ToString(con.Substring(2).ToString());
            }
            catch
            {
            }
            docFile.Close();
            docFile.Dispose();
            SqlConnection cnn = new SqlConnection("Data Source=" + ketnoi);

            //try
            //{
            //    if (cnn.State == System.Data.ConnectionState.Closed)
            //    {
            //        cnn.Open();
            //        return cnn;
            //    }
            //}
            //catch
            //{

            //}
            //finally
            //{
            //    cnn.Close();
            //}
            return(cnn);
        }
Esempio n. 4
0
 void btnLogin()
 {
     if (txtPass.Text != "" || txtUser.Text != "")
     {
         try
         {
             SqlDataReader dr = BUS.BUS_DangNhap(txtUser.Text);
             if (dr.Read())
             {
                 if (txtUser.Text == dr[0].ToString() && MaHoaString.GetMD5(MaHoaString.GetMD5(txtPass.Text)) == dr[1].ToString())
                 {
                     MessageBox.Show("Đăng nhập thành công", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     panel2.Show();
                     pnLogin.Hide();
                     button1.Show();
                     lbWelcome.Text = txtUser.Text;
                     lbWelcome.Show();
                     use = txtUser.Text;
                     CheckDangKy();
                 }
                 else
                 {
                     MessageBox.Show("Username hoặc Password không đúng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("Username hoặc Password không đúng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             dr.Close();
             BUS.BUS_DangNhap(txtUser.Text).Close();
             BUS.BUS_Close_Connect_MainForm();
         }
         catch
         {
             MessageBox.Show("Lỗi kết nối CSDL!");
             kn.ShowDialog();
         }
     }
     else
     {
         MessageBox.Show("Không được để trống!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 5
0
 private void btnLuu_TT_Click(object sender, EventArgs e)
 {
     if (MaHoaString.GetMD5(MaHoaString.GetMD5(txtMK.Text)) == pass)
     {
         if (BUS.BUS_UpdateUser(MainForm.use, txtHoTen.Text, txtSDT.Text))
         {
             MessageBox.Show("Cập nhật thành công!", "Thông báo");
         }
         else
         {
             MessageBox.Show("Có lỗi khi cập nhật dữ liệu!", "Error");
             kn.ShowDialog();
         }
     }
     else
     {
         MessageBox.Show("Mật khẩu bạn nhập không đúng!", "Error");
     }
 }
Esempio n. 6
0
 private void btnLuu_MK_Click(object sender, EventArgs e)
 {
     if (txtPass_NL.Text != txtPassMoi.Text)
     {
         MessageBox.Show("Mật khẩu nhập lại không khớp!", "Error");
     }
     else
     {
         try
         {
             SqlDataReader dr = BUS.BUS_GetPass(MainForm.use);
             if (dr.Read())
             {
                 if (dr[0].ToString() == MaHoaString.GetMD5(MaHoaString.GetMD5(txtMatKhau_DoiMK.Text)))
                 {
                     if (BUS.BUS_ChangePass(MainForm.use, MaHoaString.GetMD5(MaHoaString.GetMD5(txtPass_NL.Text))) == true)
                     {
                         MessageBox.Show("Đã đổi Mật khẩu thành công!", "Thông báo");
                         this.Close();
                     }
                     else
                     {
                         MessageBox.Show("Đã xảy ra lỗi!", "Error");
                     }
                 }
                 else
                 {
                     MessageBox.Show("Mật khẩu không đúng!", "Error");
                 }
             }
             dr.Close();
             BUS.BUS_CloseConnect_SuaThongTin();
         }
         catch
         {
             MessageBox.Show("Lỗi kết nối CSDL!");
             kn.ShowDialog();
         }
     }
 }