protected void btnXacNhan_ServerClick(object sender, EventArgs e)
        {
            if (Text3.Value == Session["key"].ToString())
            {
                user = tbl_user.CheckKey(Text1.Value.Trim());
                MailMessage mail = new MailMessage();

                mail.To.Add(user.Email);
                mail.From    = new MailAddress("*****@*****.**");
                mail.Subject = "Mật Khẩu cũa bạn là: " + user.MK;

                SmtpClient smtp = new SmtpClient();
                smtp.UseDefaultCredentials = false;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.Credentials = new NetworkCredential("*****@*****.**", "01692762910hung");
                smtp.EnableSsl   = true;

                smtp.Send(mail);

                Text3.Value = "";
                MultiView1.ActiveViewIndex = 0;
                WebMsgBox.Show("Hãy kiểm tra hòm thư của bạn");
            }
            else
            {
                Label2.ForeColor = System.Drawing.Color.Red;
                Label2.Text      = "Mã xác nhận không hợp lệ";
            }
        }
Beispiel #2
0
        //Hiển Thị Form Input
        private void ShowFormInput()
        {
            if (Page.RouteData.Values["ID"] != null)
            {
                btnThem.Visible     = false;
                btnCapNhat.Visible  = true;
                btnCapNhat.Visible  = true;
                btnXoa.Visible      = true;
                txtTaiKhoan.Enabled = false;
                txtNam.Enabled      = false;

                string id   = Page.RouteData.Values["ID"].ToString().Trim();
                UserDN user = tbl_user.GetByID(id);

                txtTenSV.Text    = user.TenSV;
                txtMaSV.Text     = user.MSSV;
                txtEmail.Text    = user.Email;
                txtLop.Text      = user.Lop;
                txtNam.Text      = user.nam.ToString();
                txtTaiKhoan.Text = user.UserTK;
                txtMatKhau.Text  = user.MK;
            }
            else
            {
                btnThem.Visible     = true;
                btnCapNhat.Visible  = false;
                btnXoa.Visible      = false;
                txtTaiKhoan.Enabled = true;
                txtNam.Enabled      = true;
            }
        }
Beispiel #3
0
        protected void btnXoa_Click(object sender, EventArgs e)
        {
            string id   = Page.RouteData.Values["ID"].ToString().Trim();
            UserDN user = tbl_user.GetByID(id);

            XoaDuLieu(user, true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Cookies["User"] != null)
                {
                    HttpCookie ck   = Request.Cookies["User"];
                    UserDN     user = tbl_user.GetByID(HttpUtility.UrlDecode(ck.Value.Trim()));

                    if (user == null)
                    {
                        XoaCookie();
                    }
                    else
                    {
                        txtMaThe.Text   = user.MaThe;
                        txtTen.Text     = user.TenSV;
                        txtLop.Text     = user.Lop;
                        txtEmail.Text   = user.Email;
                        txtTK.Text      = user.UserTK;
                        txtThoiHan.Text = user.ThoiHan;
                    }
                }
            }
        }
        protected void txtUpdate_Click(object sender, EventArgs e)
        {
            HttpCookie ck   = Request.Cookies["User"];
            UserDN     user = tbl_user.GetByID(HttpUtility.UrlDecode(ck.Value.Trim()));

            user.TenSV = new System.Globalization.CultureInfo("en-US", false).TextInfo.ToTitleCase(txtTen.Text.ToLower().Trim());
            user.Lop   = txtLop.Text.Trim();
            user.Email = txtEmail.Text.Trim();

            tbl_user.Update(user);
        }
Beispiel #6
0
        //Mã Thẻ
        protected void txtMaThe_TextChanged(object sender, EventArgs e)
        {
            UserDN user = tbl_user.GetByID(txtMaThe.Text.Trim());

            if (user != null)
            {
                txtTen.Text = user.TenSV;
            }
            else
            {
                WebMsgBox.Show("Mã thẻ không tồn tại");
            }
        }
Beispiel #7
0
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            string id   = Page.RouteData.Values["ID"].ToString().Trim();
            UserDN user = tbl_user.GetByID(id);

            user.TenSV = new System.Globalization.CultureInfo("en-US", false).TextInfo.ToTitleCase(txtTenSV.Text.ToLower().Trim());
            user.MSSV  = txtMaSV.Text.Trim();
            user.Lop   = txtLop.Text.Trim();
            user.Email = txtEmail.Text.Trim();
            user.MK    = txtMatKhau.Text.Trim();

            tbl_user.Update(user);
            Response.Redirect("/QuanLyNguoiDoc/TKND");
        }
        //Đăng ký mượn sách
        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            if (sach.SoLuong > 0)
            {
                HttpCookie ck   = Request.Cookies["User"];
                DangKyMuon muon = new DangKyMuon();
                UserDN     user = tbl_user.GetByID(HttpUtility.UrlDecode(ck.Value.Trim()));

                //Tính thời hạn cảu tài khoản
                TimeSpan total = DateTime.Parse(user.ThoiHan).Date - DateTime.Now.Date;
                int      days  = total.Days;

                if (days > 0)
                {
                    //KT xem sinh viên đó có đang mượn cuốn sách nào không
                    //Nếu có thì không cho mượn sách
                    if (tbl_muon.KTdulieuSV(user.MaThe) != null)
                    {
                        WebMsgBox.Show("Hiện tại bạn đang mượn 1 cuốn sách của thư viện nên bạn chưa được phép mượn sách khác");
                    }
                    else
                    {
                        muon.MaMuon    = QL_MuonTra.CreateKey();
                        muon.MaThe     = user.MaThe;
                        muon.TenSV     = user.TenSV;
                        muon.MaSach    = sach.MaSach;
                        muon.TenSach   = sach.TenSach;
                        muon.GhiChuSV  = txtGhiChuSV.Text;
                        muon.GhiChuNV  = "Thông tin mượn sách của bạn sẽ được duyệt sau 1 ngày";
                        muon.SoLuong   = 1;
                        muon.NgayMuon  = DateTime.Now.ToString("dd/MM/yyyy");
                        muon.NgayTra   = DateTime.Now.AddDays(Int32.Parse(txtSoLuong.Text.Trim())).ToString("dd/MM/yyyy");
                        muon.TinhTrang = "Đang Chờ";


                        tbl_muon.Insert(muon);
                        Response.Redirect("/LichSuMuonSach/gs");
                    }
                }
                else
                {
                    WebMsgBox.Show("Tài khoản của bạn đã hết hạn, hãy đến thư viện đăng ký 1 tài khoản mới");
                }
            }
            else
            {
                WebMsgBox.Show("Số lượng sách đã hết, bạn hãy mượn vào lần sau");
            }
        }
        protected void btnDangNhap_ServerClick(object sender, EventArgs e)
        {
            user = tbl_user.CheckUser(txtUserDN.Value, txtMatKhauDN.Value);

            if (user == null)
            {
                WebMsgBox.Show("Sai Thông tin tài khoản");
            }
            else
            {
                HttpCookie myCookie = new HttpCookie("User");
                myCookie.Value   = HttpUtility.UrlEncode(user.MaThe.Trim());
                myCookie.Expires = DateTime.Now.AddDays(10);
                Response.Cookies.Add(myCookie);

                Response.Redirect("/TrangChinh");
            }
        }
        protected void btnDoiMK_Click(object sender, EventArgs e)
        {
            HttpCookie ck   = Request.Cookies["User"];
            UserDN     user = tbl_user.GetByID(HttpUtility.UrlDecode(ck.Value.Trim()));

            if (txtMKCu.Text == user.MK)
            {
                user.MK = txtMatKhau.Text;

                tbl_user.Update(user);

                WebMsgBox.Show("Cập nhật thành công");
            }
            else
            {
                WebMsgBox.Show("Mật khẩu cũ của bạn không trùng khớp");
            }
        }
Beispiel #11
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            UserDN user = new UserDN();

            if (txtMaSV.Text.Trim() != "")
            {
                user.MaThe = utf8Convert1(txtMaSV.Text.Trim());
            }
            else
            {
                user.MaThe = CreateKey();
            }

            user.TenSV   = new System.Globalization.CultureInfo("en-US", false).TextInfo.ToTitleCase(txtTenSV.Text.ToLower().Trim());
            user.MSSV    = txtMaSV.Text.Trim();
            user.Lop     = txtLop.Text.Trim();
            user.Email   = txtEmail.Text.Trim();
            user.MK      = txtMatKhau.Text.Trim();
            user.nam     = Int32.Parse(txtNam.Text.Trim());
            user.ThoiHan = DateTime.Now.AddYears(Int32.Parse(txtNam.Text.Trim())).ToString("dd/MM/yyyy");

            if (tbl_user.CheckKey(txtTaiKhoan.Text.Trim()) == null)
            {
                user.UserTK = txtTaiKhoan.Text.Trim();

                tbl_user.Insert(user);

                //Reset
                txtTenSV.Text    = "";
                txtMaSV.Text     = "";
                txtLop.Text      = "";
                txtEmail.Text    = "";
                txtTaiKhoan.Text = "";
                txtMatKhau.Text  = "";
                txtNam.Text      = "";

                ShowData();
                WebMsgBox.Show("Thêm Vào Thành Công");
            }
            else
            {
                WebMsgBox.Show("Tên tài khoản đã tồn tại");
            }
        }
        protected void btnTimTK_ServerClick(object sender, EventArgs e)
        {
            try
            {
                user = tbl_user.CheckKey(Text1.Value.Trim());

                if (user == null)
                {
                    Label1.Text = "Không tìm thấy tài khoản";
                }
                else
                {
                    key = new Random().Next(111111, 999999);

                    if (key != 0)
                    {
                        Session["key"] = key;
                    }

                    MailMessage mail = new MailMessage();

                    mail.To.Add(user.Email.Trim());
                    mail.From    = new MailAddress("*****@*****.**");
                    mail.Subject = "Mã xác nhận của bạn là: " + key.ToString();

                    SmtpClient smtp = new SmtpClient();
                    smtp.UseDefaultCredentials = false;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.Credentials = new NetworkCredential("*****@*****.**", "01692762910hung");
                    smtp.EnableSsl   = true;

                    smtp.Send(mail);
                    Text1.Value = "";
                    MultiView1.ActiveViewIndex = 2;
                }
            }
            catch (Exception ex)
            {
                WebMsgBox.Show("Email của bạn không hợp lệ hãy đến thư viện kiểm tra lại email");
            }
        }
Beispiel #13
0
        private void XoaDuLieu(UserDN user, bool point)
        {
            List <DangKyMuon> li_muon = tbl_muon.GetListByIDUser(user.MaThe);
            bool flag = true;

            //Xóa danh sách mượn của sinh viên
            if (li_muon.Count > 0)
            {
                foreach (DangKyMuon item in li_muon)
                {
                    if (item.TinhTrang == "Đang Mượn" || item.TinhTrang == "Chưa Trả")
                    {
                        flag = false;
                        break;
                    }
                    else
                    {
                        tbl_muon.Delete(item);
                    }
                }
            }

            if (flag == true)
            {
                tbl_user.Delete(user);

                if (point)
                {
                    Response.Redirect("/QuanLyNguoiDoc/TKND");
                }
            }
            else
            {
                WebMsgBox.Show("Tài khoản của mã thẻ " + user.MaThe + " còn đang mượn sách nên chưa xóa được");
            }
        }
 //xoa du lieu
 public void Delete(UserDN obj)
 {
     db.UserDNs.Attach(obj);
     db.UserDNs.Remove(obj);
     db.SaveChanges();
 }
 //Cap nhap du lieu
 public void Update(UserDN obj)
 {
     db.UserDNs.Attach(obj);
     db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
 //Them du lieu
 public UserDN Insert(UserDN obj)
 {
     db.UserDNs.Add(obj);
     db.SaveChanges();
     return(obj);
 }