private string getID(string username, string pass)
        {
            string id = "";

            try
            {
                conn.OpenConnection();
                string        strSQL = "SELECT * FROM TAIKHOAN WHERE TENTK ='" + username + "' and MK='" + pass + "'";
                SqlDataReader dr     = conn.getReader(strSQL);
                while (dr.Read())
                {
                    id = dr["ID"].ToString();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Lỗi xảy ra khi truy vấn dữ liệu hoặc kết nối với server thất bại !");
            }
            finally
            {
                conn.ClosedConnection();
            }
            return(id);
        }
        private void btnKetNoi_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboTenMay.Text == "")
                {
                    MessageBox.Show("Hãy chọn Tên máy!", "Chú ý!");
                    return;
                }
                if (txtUser.Text == "")
                {
                    MessageBox.Show("Hãy nhập User!", "Chú ý!");
                    return;
                }
                if (txtPass.Text == "")
                {
                    MessageBox.Show("Hãy nhập mật khẩu!", "Chú ý!");
                    return;
                }
                Luu.user   = txtUser.Text.Trim();
                Luu.pass   = txtPass.Text.Trim();
                Luu.server = cboTenMay.Text.Trim();
                KETNOI conn = new KETNOI();

                conn.OpenConnection();
                conn.ClosedConnection();
                MessageBox.Show("Kết nối thành công");
                Thread t = new Thread(new ThreadStart(chayCT));
                t.Start();
                this.Close();
            }
            catch
            {
                MessageBox.Show("Kết nối thất bại");
                return;
            }
        }
Пример #3
0
        private string getMK(string mkh)
        {
            string mk = "";

            try
            {
                conn.OpenConnection();
                string        strSQL = "SELECT * FROM TAIKHOAN WHERE TENTK ='" + frmDangNhap.ID_USER + "'";
                SqlDataReader dr     = conn.getReader(strSQL);
                while (dr.Read())
                {
                    mk = dr["MK"].ToString();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Lỗi xảy ra khi truy vấn dữ liệu hoặc kết nối với server thất bại !");
            }
            finally
            {
                conn.ClosedConnection();
            }
            return(mk);
        }