Esempio n. 1
0
        private void btnDoiMatKhau_Click(object sender, EventArgs e)
        {
            if (KiemTraDuLieu())
            {
                var tb = MessageBox.Show("Bạn có chắc chắn muốn đổi mật khẩu ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (tb == DialogResult.Yes)
                {
                    BUS_NguoiDung nd   = new BUS_NguoiDung();
                    var           flag = nd.DoiMatKhau(BUS_NguoiDung.CurUser.MaNguoiDung, txtMatKhauCu.Text, txtMatKhauMoi.Text);

                    if (flag == true)
                    {
                        MessageBox.Show("Đổi mật khẩu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Sai mật khẩu cũ.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 2
0
        private void btnDuyet_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            int    mand  = int.Parse(gridViewNVMoi.GetFocusedRowCellValue("MaNguoiDung").ToString());
            string tennd = gridViewNVMoi.GetFocusedRowCellValue("TenDangNhap").ToString();
            var    tb    = MessageBox.Show(string.Format("Bạn có chắc chắn muốn duyệt nhân viên <{0}> ?", tennd), "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (tb == DialogResult.Yes)
            {
                BUS_NguoiDung nd   = new BUS_NguoiDung();
                var           flag = nd.DuyetNguoiDung(mand);
                if (flag == true)
                {
                    MessageBox.Show(string.Format("Bạn đã duyệt nhân viên <{0}> thành công.", tennd), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.FormLoad();
                }
                else
                {
                    MessageBox.Show("Lỗi.\nBạn cần kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                return;
            }
        }
Esempio n. 3
0
        public bool KiemTraDuLieu()
        {
            BUS_NguoiDung nd = new BUS_NguoiDung();

            ErrorChecker.Clear();  // giả sử ban đầu mọi dữ liệu là đúng
            if (string.IsNullOrWhiteSpace(txtTenDangNhap.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtTenDangNhap, "Không được để trống.");
                return(false);
            }
            if (nd.KTTaiKhoanTonTai(txtTenDangNhap.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtTenDangNhap, "Tài khoản không tồn tại trong hệ thống.");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtMatKhau.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtMatKhau, "Không được để trống.");
                return(false);
            }
            else
            {
                ErrorChecker.Clear();
            }

            return(true);
        }
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            if (!IsEmptyInfor() && !IsCoincident())
            {
                try
                {
                    BUS_NguoiDung bUS_NguoiDung = new BUS_NguoiDung();
                    Const.CurrentUser.MatKhau = HashPassword(txtMatKhauNew.Text);
                    bUS_NguoiDung.Update(Const.CurrentUser);
                    MessageBox.Show("Đổi mật khâu thành công!");

                    //------------Ghi log
                    NhatKyHoatDong nhatKy = new NhatKyHoatDong();
                    nhatKy.NguoiDungId = Const.CurrentUser.NguoiDungId;
                    nhatKy.NoiDung     = "Đổi mật khẩu tài khoản " + Const.CurrentUser.TenDangNhap;
                    nhatKy.ThaoTac     = "";
                    nhatKy.ThoiGian    = DateTime.Now;
                    nhatKy.ChucNang    = "Đổi mật khẩu";
                    Const.NhatKyHoatDong.Insert(nhatKy);
                    //-------------------
                }
                catch
                {
                    MessageBox.Show("Có lỗi xảy ra!!!");
                    throw;
                }
            }
        }
Esempio n. 5
0
        private void frmTTTaiKhoan_Load(object sender, EventArgs e)
        {
            BUS_NguoiDung u    = new BUS_NguoiDung();
            var           user = u.GetUser(BUS_NguoiDung.CurUser.MaNguoiDung);

            txtTenDangNhap.Text = user.TenDangNhap.ToString();
            txtEmail.Text       = user.Email.ToString();
            txtSDT.Text         = user.SoDienThoai.ToString();
            txtDiaChi.Text      = user.DiaChi.ToString();
        }
Esempio n. 6
0
        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            BUS_NguoiDung nd   = new BUS_NguoiDung();
            var           user = nd.LayNguoiDung();

            if (user != null)
            {
                txtTenDangNhap.Text = user.TenDangNhap;
                txtMatKhau.Text     = user.MatKhau;
                ckbGhiNho.Checked   = true;
            }
        }
Esempio n. 7
0
        private bool KiemTraDuLieu()
        {
            ErrorChecker.Clear();  //  giả sử ban đầu mọi dữ liệu là đúng

            BUS_NguoiDung nd = new BUS_NguoiDung();

            if (string.IsNullOrWhiteSpace(txtEmail.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtEmail, "Không được để trống.");
                return(false);
            }


            //  Kiểm tra Email hợp lệ
            //  https://stackoverflow.com/a/19475049/7385686
            //  https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format
            //  https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions

            string pattern = @"\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}\z";

            if (txtEmail.Text.Length == 0)
            {
                ErrorChecker.Clear();
                return(true);
            }
            if (Regex.IsMatch(txtEmail.Text, pattern))
            {
                if (nd.KTEmailTonTai(txtEmail.Text) == true)
                {
                    ErrorChecker.BlinkRate = 500;
                    ErrorChecker.SetError(txtEmail, "Email không tồn tại trong hệ thống.");
                    return(false);
                }
            }
            if (Regex.IsMatch(txtEmail.Text, pattern) == false)
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtEmail, "Email không hợp lệ.");
                return(false);
            }
            else
            {
                ErrorChecker.Clear();
            }

            return(true);
        }
Esempio n. 8
0
        private void btnDangKy_Click(object sender, EventArgs e)
        {
            if (KiemTraDuLieu())
            {
                BUS_NguoiDung nd = new BUS_NguoiDung();
                nd.DangKy(txtTenDangNhap.Text, txtMatKhau.Text, txtEmail.Text, txtSDT.Text, txtDiaChi.Text);

                var tb = MessageBox.Show("Bạn đã đăng ký tài khoản thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (tb == DialogResult.OK)
                {
                    frmDangNhap dangnhap = new frmDangNhap();
                    this.Hide();
                    dangnhap.Show();
                }
            }
        }
Esempio n. 9
0
        private void txtTenDangNhap_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {
            BUS_NguoiDung nd   = new BUS_NguoiDung();
            var           user = nd.LayNguoiDungGN(txtTenDangNhap.Text);

            if (user != null)
            {
                txtMatKhau.Text   = user.MatKhau;
                ckbGhiNho.Checked = true;
            }
            else
            {
                txtMatKhau.Text   = "";
                ckbGhiNho.Checked = false;
            }
        }
Esempio n. 10
0
        public FrmSuaPhieuCapPhat()
        {
            InitializeComponent();

            cbPhong.DataSource    = BUS_Phong.GetData();
            cbPhong.DisplayMember = "tenPhong";
            cbPhong.ValueMember   = "PhongId";

            cbNhanVien.DataSource    = BUS_NhanVien.GetData();
            cbNhanVien.DisplayMember = "tenNhanVien";
            cbNhanVien.ValueMember   = "NhanVienID";

            cbNguoiDung.DataSource    = BUS_NguoiDung.GetData();
            cbNguoiDung.DisplayMember = "tenDangNhap";
            cbNguoiDung.ValueMember   = "NguoiDungId";
        }
Esempio n. 11
0
        private void btnDangXuat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var thongbao = MessageBox.Show("Bạn có chắc chắn muốn đăng xuất ?", "Đăng xuất ?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (thongbao == DialogResult.Yes)
            {
                BUS_NguoiDung nd   = new BUS_NguoiDung();
                var           flag = nd.DangXuat();

                if (flag == true)
                {
                    this.Hide();
                    frmDangNhap dangnhap = new frmDangNhap();
                    dangnhap.Show();
                }
            }
            else
            {
                return;
            }
        }
Esempio n. 12
0
        private void btnLuuTT_Click(object sender, EventArgs e)
        {
            if (KiemTraDuLieu())
            {
                var tb = MessageBox.Show("Bạn có chắc chắn muốn lưu thông tin ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (tb == DialogResult.Yes)
                {
                    BUS_NguoiDung nd   = new BUS_NguoiDung();
                    var           flag = nd.DoiThongTin(BUS_NguoiDung.CurUser.MaNguoiDung, txtEmail.Text, txtSDT.Text, txtDiaChi.Text);

                    if (flag == true)
                    {
                        MessageBox.Show("Lưu thông tin thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 13
0
        private void navbarXoa_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            int    mand  = int.Parse(gridViewNhanVien.GetFocusedRowCellValue("MaNguoiDung").ToString());
            string tennd = gridViewNhanVien.GetFocusedRowCellValue("TenDangNhap").ToString();

            var tb = MessageBox.Show(string.Format("Bạn có chắc chắn muốn xóa nhân viên <{0}> ?", tennd), "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (tb == DialogResult.Yes)
            {
                BUS_NguoiDung nd   = new BUS_NguoiDung();
                var           flag = nd.XoaNguoiDung(mand);
                if (flag == true)
                {
                    MessageBox.Show(string.Format("Bạn đã xóa nhân viên <{0}> thành công.", tennd), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.FormLoad();
                }
            }
            else
            {
                return;
            }
        }
Esempio n. 14
0
        private bool KiemTraDuLieu()
        {
            ErrorChecker.Clear();  //  giả sử ban đầu mọi dữ liệu là đúng

            BUS_NguoiDung nd = new BUS_NguoiDung();

            if (string.IsNullOrWhiteSpace(txtTenDangNhap.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtTenDangNhap, "Không được để trống.");
                return(false);
            }
            if (nd.KTTaiKhoanTonTai(txtTenDangNhap.Text) == false)
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtTenDangNhap, "Tên đăng nhập đã tồn tại trong hệ thống.");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtMatKhau.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtMatKhau, "Không được để trống.");
                return(false);
            }
            if (txtMatKhau.Text.Length < 6)
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtMatKhau, "Mật khẩu phải lớn hơn hoặc bằng 6 ký tự.");
                return(false);
            }
            if (txtMatKhau.Text != txtXacNhanMK.Text)
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtXacNhanMK, "Mật khẩu phải trùng nhau.");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtEmail.Text))
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtEmail, "Không được để trống.");
                return(false);
            }
            if (txtSDT.Text.Length > 0 && txtSDT.Text.Length < 10)
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtSDT, "Số điện thoại không hợp lệ.");
                return(false);
            }


            //  Kiểm tra Email hợp lệ
            //  https://stackoverflow.com/a/19475049/7385686
            //  https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format
            //  https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions

            string pattern = @"\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}\z";

            if (txtEmail.Text.Length == 0)
            {
                ErrorChecker.Clear();
                return(true);
            }
            if (Regex.IsMatch(txtEmail.Text, pattern))
            {
                if (nd.KTEmailTonTai(txtEmail.Text) == false)
                {
                    ErrorChecker.BlinkRate = 500;
                    ErrorChecker.SetError(txtEmail, "Email đã tồn tại trong hệ thống.");
                    return(false);
                }
            }
            if (Regex.IsMatch(txtEmail.Text, pattern) == false)
            {
                ErrorChecker.BlinkRate = 500;
                ErrorChecker.SetError(txtEmail, "Email không hợp lệ.");
                return(false);
            }
            else
            {
                ErrorChecker.Clear();
            }

            return(true);
        }
Esempio n. 15
0
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (KiemTraDuLieu())
            {
                BUS_NguoiDung nd = new BUS_NguoiDung();
                if (nd.NhanVienChuaDuyet(txtTenDangNhap.Text) == false)  //  Admin + nhân viên đã được duyệt
                {
                    var user = nd.NguoiDung12(txtTenDangNhap.Text, txtMatKhau.Text);
                    if (user == 0)  // người dùng đã bị xóa (ẩn)
                    {
                        MessageBox.Show("Bạn không có quyền truy cập hệ thống.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (user == 1)
                    {
                        // Lưu ghi nhớ xuống dữ liệu
                        if (ckbGhiNho.Checked == true)
                        {
                            nd.DangNhapCu();
                            nd.NhoMatKhau(txtTenDangNhap.Text, 2);
                        }
                        else
                        {
                            nd.NhoMatKhau(txtTenDangNhap.Text, 0);
                        }
                        frmMain main = new frmMain();
                        this.Hide();
                        main.Show();
                    }
                    if (user == -1)  // trước đó người dùng KHÔNG chọn Ghi nhớ
                    {
                        var flag = nd.DangNhap(txtTenDangNhap.Text, txtMatKhau.Text);

                        if (flag == -1)
                        {
                            MessageBox.Show("Sai mật khẩu.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        if (flag == 0)  // người dùng đã bị xóa (ẩn)
                        {
                            MessageBox.Show("Bạn không có quyền truy cập hệ thống.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        if (flag == 1)
                        {
                            // Lưu ghi nhớ xuống dữ liệu
                            if (ckbGhiNho.Checked == true)
                            {
                                nd.DangNhapCu();
                                nd.NhoMatKhau(txtTenDangNhap.Text, 2);
                            }
                            else
                            {
                                nd.NhoMatKhau(txtTenDangNhap.Text, 0);
                            }
                            frmMain main = new frmMain();
                            this.Hide();
                            main.Show();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Tài khoản <{0}> chưa được duyệt.\nBạn hãy liên hệ Admin.", txtTenDangNhap.Text), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 16
0
        protected void SendEmail(string _subject, MailAddress _from, MailAddress _to, List <MailAddress> _cc = null, List <MailAddress> _bcc = null)
        {
            //  https://stackoverflow.com/questions/10940732/sending-emails-from-a-windows-forms-application
            //  https://www.c-sharpcorner.com/UploadFile/deepak.sharma00/send-email-from-C-Sharp-windows-application-using-gmail-smtp/

            var user = db.NguoiDungs
                       .Where(u => u.Email == txtEmail.Text)
                       .FirstOrDefault();

            string MatKhauMoi = RandomPassword();

            string Text = string.Format("<html>Xin chào {0},<br/><br/>Mật khẩu mới của bạn là: {1}<br/><br/>Vui lòng không trả lời email này. Cảm ơn.<br/><br/><br/>Phần mềm Quản lý đại lý.</html>", user.TenDangNhap, MatKhauMoi);

            // Create a new Smtp client to send our email.
            SmtpClient smtp = new SmtpClient("smtp.gmail.com");    // smtp.gmail.com // For Gmail

            // smtp.live.com // Windows live / Hotmail
            // smtp.mail.yahoo.com // Yahoo
            // smtp.aim.com // AIM
            // my.inbox.com // Inbox

            smtp.Port = 25;                          // SmtpClient.Port is used to get or set the port number used for this SMTP. It is set to "25", which is the Gmail SMTP port.

            MailMessage msgMail = new MailMessage(); // To send an email we must first create a new mailMessage(an email) to send.

            msgMail.From = _from;                    // Sender e-mail address.
            msgMail.To.Add(_to);                     // Recipient e-mail address.
            if (_cc != null)
            {
                foreach (MailAddress addr in _cc)
                {
                    msgMail.CC.Add(addr);
                }
            }
            if (_bcc != null)
            {
                foreach (MailAddress addr in _bcc)
                {
                    msgMail.Bcc.Add(addr);
                }
            }

            msgMail.Subject    = _subject; // Assign the subject of our message.
            msgMail.IsBodyHtml = true;
            msgMail.Body       = Text;     // Create the content(body) of our message.
            //msgMail.Body = msgMail.Body.Replace(Environment.NewLine, "<br/>");
            smtp.UseDefaultCredentials = false;

            //  http://vn.ultramailer.org/page/104-xu-ly-loi-5-5-1-authentication-required-moi-nhat-khi-gui-email-hang-loat-qua-hom-gmail.html
            var admin = db.NguoiDungs
                        .Where(u => u.TenDangNhap == "admin")
                        .FirstOrDefault();

            BUS_NguoiDung nd      = new BUS_NguoiDung();
            string        matkhau = nd.Decrypt(admin.MatKhau);

            System.Net.NetworkCredential smtpCreds = new System.Net.NetworkCredential(admin.Email, matkhau);
            smtp.Credentials = smtpCreds;

            smtp.EnableSsl = true; // Enabling SSL(Secure Sockets Layer, encyription) is reqiured by most email providers to send mail
            smtp.Send(msgMail);    // Send our email.
            msgMail.Dispose();

            // Cập nhật mật khẩu mới
            nd.ResetMatKhau(user.MaNguoiDung, MatKhauMoi);
        }