コード例 #1
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (ctrl.KiemTra(txtHoTen, txtuser, txtpas, txtrepas, cmbQuyen))
            {
                group.Enabled = false;

                listDSNguoiDung.Enabled = true;

                btnThem.Enabled    = true;
                btnXoa.Enabled     = true;
                btnSua.Enabled     = true;
                btnCapNhat.Enabled = false;
                btnBoQua.Visible   = false;
                if (adding == true)
                {
                    NguoiDungInfo NguoiDung = ctrl.ControlToInfo(txtMa, txtHoTen, txtuser, txtpas, cmbQuyen);
                    if (ctrl.Them(NguoiDung))//Thêm thành công thì thêm một dòng trên LISTVIEW
                    {
                        listDSNguoiDung.Items.Add(ctrl.InfoToItem(NguoiDung));
                    }
                }
                else if (updating == true)
                {
                    NguoiDungInfo NguoiDung = ctrl.ControlToInfo(txtMa, txtHoTen, txtuser, txtpas, cmbQuyen);
                    if (ctrl.Sua(NguoiDung))//Sửa thành công thì sửa một dòng trên LISTVIEW
                    {
                        ctrl.SuaListView(listDSNguoiDung, NguoiDung);
                    }
                }
                ctrl.HienThi(listDSNguoiDung);
            }
        }
コード例 #2
0
ファイル: Login.aspx.cs プロジェクト: myvien0698/du-an-2
        protected void btn_login_Click(object sender, EventArgs e)
        {
            NguoiDungController kt = new NguoiDungController();
            string        ad       = txt_user.Text;
            NguoiDungInfo info     = kt.Check_Login(txt_user.Text, txt_pass.Text);

            if (info != null)
            {
                if (info.Quyen)
                {
                    Session["TenDangNhap"] = info.TenDangNhap;
                    Response.Redirect("~/Admin/ADIndex.aspx");
                }
                else
                {
                    Session["TenDangNhap"] = info.TenDangNhap;
                }
                Session["Email"]  = info.Email;
                Session["HoTen"]  = info.HoTen;
                Session["SDT"]    = info.SDT;
                Session["DiaChi"] = info.DiaChi;
                Session["quyen"]  = info.Quyen;
                Response.Redirect("~/Home.aspx");
            }
            else
            {
                tb.Text = "Sai Tên Hoặc Mật Khẩu!";
            }
        }
コード例 #3
0
        public DataTable DangNhap(NguoiDungInfo nguoidung)
        {
            SqlCommand com = new SqlCommand("select * from nguoidung where [USER]=@user");

            com.Parameters.Add("@user", SqlDbType.Char, 32).Value = nguoidung.Username;
            ser.Load(com);
            return(ser);
        }
コード例 #4
0
        public bool Update(NguoiDungInfo info, string newPassword)
        {
            if (this.m_Data == null)
            {
                this.m_Data = new NguoiDungData();
            }

            return(this.m_Data.Update(info.MaNguoiDung, newPassword));
        }
コード例 #5
0
        public ListViewItem InfoToItem(NguoiDungInfo NguoiDung)
        {
            ListViewItem item = new ListViewItem();

            item.Text = NguoiDung.Ma.ToString();
            item.SubItems.Add(NguoiDung.HoTen);
            item.SubItems.Add(NguoiDung.Username);
            item.SubItems.Add(NguoiDung.Password);
            item.SubItems.Add(NguoiDung.Quyen.ToString());
            return(item);
        }
コード例 #6
0
        public NguoiDungInfo ControlToInfo(TextBox ma, TextBox ten, TextBox user, TextBox pass, ComboBox quyen)
        {
            NguoiDungInfo NguoiDung = new NguoiDungInfo();

            NguoiDung.Ma       = Convert.ToInt32(ma.Text);
            NguoiDung.HoTen    = ten.Text;
            NguoiDung.Username = user.Text;
            NguoiDung.Password = Md5(pass.Text);
            NguoiDung.Quyen    = quyen.Text.ToCharArray()[0];

            return(NguoiDung);
        }
コード例 #7
0
        public void RowToControl(ListView list, TextBox ma, TextBox ten, TextBoxX user, TextBoxX pass, ComboBoxEx quyen)
        {
            if (list.SelectedItems.Count > 0)
            {
                NguoiDungInfo NguoiDung = (NguoiDungInfo)list.SelectedItems[0].Tag;
                ma.Text   = NguoiDung.Ma.ToString();;
                ten.Text  = NguoiDung.HoTen;
                user.Text = NguoiDung.Username;
                pass.Text = NguoiDung.Password;

                quyen.Text = NguoiDung.Quyen.ToString();
            }
        }
コード例 #8
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có muốn xóa " + (listDSNguoiDung.SelectedItems.Count > 1 ? listDSNguoiDung.SelectedItems.Count.ToString() + " " : "") + "dòng này không?", "Phòng", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         IEnumerator list = listDSNguoiDung.SelectedItems.GetEnumerator();
         while (list.MoveNext())
         {
             ListViewItem  item      = (ListViewItem)list.Current;
             NguoiDungInfo NguoiDung = (NguoiDungInfo)item.Tag;
             ctrl.Xoa(NguoiDung);
         }
     }
     ctrl.HienThi(listDSNguoiDung);
 }
コード例 #9
0
        public NguoiDungInfo RowToInfo(DataRow row)
        {
            NguoiDungInfo NguoiDung = new NguoiDungInfo();

            NguoiDung.Ma = Convert.ToInt32(row["MA"].ToString());

            NguoiDung.HoTen = row["HOTEN"].ToString();

            NguoiDung.Username = row["USER"].ToString();

            NguoiDung.Password = row["PASS"].ToString();
            NguoiDung.Quyen    = row["QUYEN"].ToString().ToCharArray()[0];

            return(NguoiDung);
        }
コード例 #10
0
        /// <summary>
        /// Sửa một dòng trên LISTVIEW có cùng Mã với phòng vừa sửa
        /// </summary>
        /// <param name="list">Listview cần sửa</param>
        /// <param name="NguoiDung">Phòng có khóa cần sửa</param>
        public void SuaListView(ListView list, NguoiDungInfo NguoiDung)
        {
            ListViewItem itemNguoiDung = InfoToItem(NguoiDung);

            for (int i = 0; i < list.Items.Count; i++)
            {
                if (list.Items[i].Text == itemNguoiDung.Text)
                {
                    //Thay đổi nội dung từng ô một trên dòng cần sửa
                    for (int j = 1; j < list.Items[i].SubItems.Count; j++)
                    {
                        list.Items[i].SubItems[j] = itemNguoiDung.SubItems[j];
                    }
                }
            }
        }
コード例 #11
0
        protected void btn_DangKy_Click(object sender, EventArgs e)
        {
            NguoiDungInfo       nd       = layDuLieuForm();
            NguoiDungController taikhoan = new NguoiDungController();
            bool kt = taikhoan.NguoiDung_Insert(nd);

            if (kt)
            {
                lbTB.Text = "Đăng ký thành công";
                Response.Redirect("~/HienThi.aspx");
            }
            else
            {
                lbTB.Text = "Đăng ký thất bại";
            }
        }
コード例 #12
0
        public NguoiDungInfo layDuLieuForm()
        {
            string        TenDN   = txt_Ten.Text;
            string        MatKhau = txtMatKhau.Text;
            string        HoTen   = txtHoTen.Text;
            string        Email   = txtEmail.Text;
            NguoiDungInfo info    = new NguoiDungInfo
            {
                TenDN   = TenDN.ToString(),
                MatKhau = MatKhau.ToString(),
                HoTen   = HoTen.ToString(),
                Email   = Email.ToString()
            };

            return(info);
        }
コード例 #13
0
        public bool Xoa(NguoiDungInfo NguoiDung)
        {
            SqlCommand command = new SqlCommand("Delete NguoiDung where MA = @ma");

            command.Parameters.Add("@ma", SqlDbType.Int).Value = NguoiDung.Ma;

            try
            {
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
コード例 #14
0
        protected void btn_DangNhap_Click(object sender, EventArgs e)
        {
            NguoiDungController kt = new NguoiDungController();
            string        ten      = txtTen.Text;
            NguoiDungInfo info     = kt.Check_Login(txtTen.Text, txtMatKhau.Text);

            if (info != null)
            {
                Session["TenDN"]    = info.TenDN;
                Session["HoTen"]    = info.HoTen;
                Session["NgaySinh"] = info.NgaySinh;
                Session["GioiTinh"] = info.GioiTinh;
                Session["DiaChi"]   = info.DiaChi;
                Session["Email"]    = info.Email;
                Response.Redirect("~/Home.aspx");
            }
            else
            {
                lbTB.Text = "Sai Tên Hoặc Mật Khẩu!";
            }
        }
コード例 #15
0
        public bool Them(NguoiDungInfo NguoiDung)
        {
            SqlCommand command = new SqlCommand("insert into NGUOIDUNG(MA,HOTEN,[USER],PASS,QUYEN)"
                                                + " values(@ma,@hoten,@user,@pass,@quyen)");

            command.Parameters.Add("@ma", SqlDbType.Int).Value             = NguoiDung.Ma;
            command.Parameters.Add("@hoten", SqlDbType.NVarChar, 30).Value = NguoiDung.HoTen;
            command.Parameters.Add("@user", SqlDbType.VarChar, 32).Value   = NguoiDung.Username;
            command.Parameters.Add("@pass", SqlDbType.VarChar, 32).Value   = NguoiDung.Password;
            command.Parameters.Add("@quyen", SqlDbType.Char, 1).Value      = NguoiDung.Quyen;

            try
            {
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
コード例 #16
0
        /// <summary>
        /// Kiem tra thong tin dang nhap va neu dang nhap thanh cong thi hien thi theo phan quyen
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public int CheckLogin(string tendangnhap, string matkhau)
        {
            //QLDiemSoHocSinhTHPT.Controlller.UserControl ctrlUser = new QLHocSinh.Control.UserControl();
            NguoiDungController ctrlNguoiDung = new NguoiDungController();
            NguoiDungInfo       infoNguoiDung = ctrlNguoiDung.LayNguoiDung(tendangnhap);

            //Neu tim thay username
            if (infoNguoiDung != null)
            {
                //Neu password dung
                if (infoNguoiDung.MatKhau == matkhau)
                {
                    //Gan thong tin user vua dang nahp vao bien toan cuc de tien su dung
                    Utilities.TTNguoiDungDangNhap = infoNguoiDung;

                    //Disable Dang nhap va Enable Dang xuat
                    this.miDangNhap.Enabled = false;
                    this.miDangXuat.Enabled = true;
                    this.tiDangNhap.Enabled = false;
                    this.tiDangXuat.Enabled = true;
                    this.btDangNhap.Enabled = false;
                    this.btDangXuat.Enabled = true;

                    //Hien thi theo phan quyen
                    this.AuthorityShow();
                    return(0);
                }
                else    //Password sai
                {
                    Utilities.TTNguoiDungDangNhap = null;
                    return(1);
                }
            }
            else    //Khong ton tai username
            {
                Utilities.TTNguoiDungDangNhap = null;
                return(2);
            }
        }
コード例 #17
0
        public bool Sua(NguoiDungInfo NguoiDung)
        {
            SqlCommand command = new SqlCommand("Update NguoiDung set HOTEN=@hoten,"
                                                + "[USER]=@user,PASS=@pass,QUYEN=@quyen" +
                                                " where MA=@ma");

            command.Parameters.Add("@ma", SqlDbType.Int).Value             = NguoiDung.Ma;
            command.Parameters.Add("@hoten", SqlDbType.NVarChar, 30).Value = NguoiDung.HoTen;
            command.Parameters.Add("@user", SqlDbType.VarChar, 32).Value   = NguoiDung.Username;
            command.Parameters.Add("@pass", SqlDbType.VarChar, 32).Value   = NguoiDung.Password;
            command.Parameters.Add("@quyen", SqlDbType.Char, 1).Value      = NguoiDung.Quyen;
            try
            {
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
コード例 #18
0
        public void HienThi(ListView list)
        {
            NguoiDungData NguoiDung = new NguoiDungData();

            list.Items.Clear();
            DataTable table = NguoiDung.LayDSNguoiDung();

            foreach (DataRow row in table.Rows)
            {
                NguoiDungInfo info = RowToInfo(row);
                ListViewItem  item = new ListViewItem();
                item.Text = info.Ma.ToString();
                item.SubItems.Add(info.HoTen);
                item.SubItems.Add(info.Username);
                item.SubItems.Add(info.Password);
                item.SubItems.Add(info.Quyen.ToString());

                item.Tag = info;
                list.Items.Add(item);
            }

            //----------------
        }
コード例 #19
0
        public int DangNhap(String username, String password)
        {
            DataTable pw = m_NguoiDungData.LayPassWord(password);
            DataTable nd = m_NguoiDungData.LayNguoiDung(username);

            if (nd.Rows.Count == 0)
            {
                return(0);
            }

            String matkhau_hethong = nd.Rows[0][3].ToString();

            if (matkhau_hethong != password)
            {
                return(1);
            }
            else
            {
                NguoiDungInfo ndinfo = new NguoiDungInfo(nd.Rows[0][0].ToString(), nd.Rows[0][1].ToString(), nd.Rows[0][2].ToString(), nd.Rows[0][3].ToString(), Convert.ToInt32(nd.Rows[0][4]));

                staticClass.nguoidungStatic = ndinfo;
                return(2);
            }
        }
コード例 #20
0
        public bool Them(NguoiDungInfo NguoiDung)
        {
            NguoiDungData data = new NguoiDungData();

            return(data.Them(NguoiDung));
        }
コード例 #21
0
        public bool Sua(NguoiDungInfo NguoiDung)
        {
            NguoiDungData data = new NguoiDungData();

            return(data.Sua(NguoiDung));
        }