Beispiel #1
0
        private void btnok_Click(object sender, EventArgs e)
        {
            if (txtnhaplaimk.Text == "")
            {
                MessageBox.Show("Bạn phải xác nhận mật khẩu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtmkmoi.Text     = "";
                txtnhaplaimk.Text = "";
                lblmatkhau.Text   = "";
                txtmkmoi.Focus();
                txtnhaplaimk.Enabled = false;
                btnok.Enabled        = false;
                return;
            }
            else
            {
                try
                {
                    string mk = DANGKY.EncryptDataByTripleDES(txtmkmoi.Text, "123");

                    BUS_ND.CapnhatMK(DANGNHAP.IdNV, mk);

                    MessageBox.Show("Đổi mật khẩu thành công!", "Congratulation!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    BUS_ND.CapnhatLanDMKcuoi(DANGNHAP.mand, DateTime.Now.ToShortDateString());
                }
                catch (Exception)
                {
                    MessageBox.Show("Đổi mật khẩu thất bại!", "Congratulation!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                finally
                {
                    Close();
                }
            }
        }
Beispiel #2
0
 private void txtmkmoi_TextChanged(object sender, EventArgs e)
 {
     if (txtmkmoi.Text != "")
     {
         if (BUS_ND.CheckMK(txtmkmoi) == 1)
         {
             erp.SetError(txtmkmoi, "Mật khẩu phải chứa ít nhất 6 ký tự!");
             txtnhaplaimk.Text    = "";
             txtnhaplaimk.Enabled = false;
             lblmatkhau.Text      = "";
             btnok.Enabled        = false;
         }
         else
         {
             if (txtmkcu.Text != txtmkmoi.Text)
             {
                 if (BUS_ND.CheckMK(txtmkmoi) == 2)
                 {
                     erp.Clear();
                     lblmatkhau.Text      = "Yếu!";
                     lblmatkhau.ForeColor = Color.Gray;
                     txtnhaplaimk.Enabled = true;
                 }
                 else if (BUS_ND.CheckMK(txtmkmoi) == 3)
                 {
                     erp.Clear();
                     lblmatkhau.Text      = "Trung bình!";
                     lblmatkhau.ForeColor = Color.YellowGreen;
                     txtnhaplaimk.Enabled = true;
                 }
                 else if (BUS_ND.CheckMK(txtmkmoi) == 4)
                 {
                     erp.Clear();
                     lblmatkhau.Text      = "Mạnh!";
                     lblmatkhau.ForeColor = Color.Green;
                     txtnhaplaimk.Enabled = true;
                 }
             }
             else
             {
                 erp.SetError(txtmkmoi, "Mật khẩu mới không được trùng với mật khẩu cũ!");
                 txtnhaplaimk.Text    = "";
                 txtnhaplaimk.Enabled = false;
                 lblmatkhau.Text      = "";
                 btnok.Enabled        = false;
             }
         }
     }
     else
     {
         erp.SetError(txtmkmoi, "Mật khẩu mới không được để trống!");
         lblmatkhau.Text      = "";
         txtnhaplaimk.Enabled = false;
         txtnhaplaimk.Text    = "";
         btnok.Enabled        = false;
     }
 }
Beispiel #3
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string gt;

            if (nv.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNhanVien.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenNhanVien.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenNhanVien.Focus();
                return;
            }
            if (txtDiaChi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChi.Focus();
                return;
            }
            if (mskDienthoai.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập số điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                mskDienthoai.Focus();
                return;
            }
            if (chkGioitinh.Checked == true)
            {
                gt = "Nam";
            }
            else
            {
                gt = "Nữ";
            }
            //mã nhân viên đã thay đổi so với ban đầu do đổi nhóm nhân viên của nv hiện tại
            if (txtMaNhanVien.Text.Substring(0, 3) != DGVNhanVien.CurrentRow.Cells["IdNV"].Value.ToString().Substring(0, 3))
            {
                //xóa nhân viên hiện tại
                List <string> idnd = new List <string>();

                DataTable dt;
                DataRow   dr;
                //Lấy mã người dùng của nhân viên hiện tại trên bảng người dùng.
                dt = BUS_ND.hienthiND();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < BUS_ND.hienthiND().Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        idnd.Add(dr["IdND"].ToString());
                    }
                }

                //Xóa trên bảng hóa đơn bán chi tiết và bảng hóa đơn bán
                dt = BUS_NV.layMaHDBTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDB.RunDelSQLOnHDBCT(dr[0].ToString());
                        BUS_HDB.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hóa đơn nhập chi tiết và bảng hóa đơn nhập
                dt = BUS_NV.LayMaHDNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDN.RunDelSQLOnHDNCT(dr[0].ToString());
                        BUS_HDN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng công nợ chi tiết và bảng công nợ
                dt = BUS_NV.LayMaCNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_CN.RunDelSQLOnCNCT(dr[0].ToString());
                        BUS_CN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hàng tồn chi tiết và bảng hàng tồn
                dt = BUS_NV.LayMaHTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HT.RunDelSQLOnHTCT(dr[0].ToString());
                        BUS_HT.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên thống kê doanh thu
                dt = BUS_NV.LayMaDTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_DT.RunDelSQL(dr[0].ToString());
                    }
                }

                foreach (string items in idnd)
                {
                    BUS_ND.RunDelSQLOnTC(items); //xoá trên bảng truy cập
                    BUS_ND.RunDelSQL(items);
                }

                BUS_NV.RunDelSQL(DGVNhanVien.CurrentRow.Cells["IdNV"].Value.ToString());

                //thêm mới nhân viên
                DTO_NV nv = new DTO_NV(txtMaNhanVien.Text, txtTenNhanVien.Text.Trim(), dtpNgaySinh.Text, gt, mskDienthoai.Text.Trim(), txtDiaChi.Text.Trim(), tencv, BUS_HDB.ConvertToFloatType(txtluongcb.Text.Trim()), txthsl.Text.Trim(), BUS_HDB.ConvertToFloatType(txtthuclinh.Text), txttaikhoan.Text);
                BUS_NV.themnv(nv);

                LoadDataGridView();
                ResetValues();
                DANGNHAP.thaotac += "Sửa, ";
            }
            else
            {
                DTO_NV nv = new DTO_NV(txtMaNhanVien.Text, txtTenNhanVien.Text.Trim(), dtpNgaySinh.Text, gt, mskDienthoai.Text.Trim(), txtDiaChi.Text.Trim(), tencv, BUS_HDB.ConvertToFloatType(txtluongcb.Text.Trim()), txthsl.Text.Trim(), BUS_HDB.ConvertToFloatType(txtthuclinh.Text), txttaikhoan.Text);

                BUS_NV.suaNV(nv);
                LoadDataGridView();
                ResetValues();
                DANGNHAP.thaotac += "Sửa, ";
            }
        }
Beispiel #4
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (nv.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNhanVien.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Xoá nhân viên sẽ xoá tất cả dữ liệu của nhân viên trên bảng người dùng, bảng truy cập, bảng hoá đơn bán chi tiết, bảng hoá đơn nhập chi tiết, bảng hoá đơn nhập, bảng hoá đơn bán. Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                //xóa nhân viên hiện tại
                List <string> idnd = new List <string>();

                DataTable dt;
                DataRow   dr;
                //Lấy mã người dùng của nhân viên hiện tại trên bảng người dùng.
                dt = BUS_ND.hienthiND();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < BUS_ND.hienthiND().Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[2].ToString() == txtMaNhanVien.Text)
                        {
                            idnd.Add(dr["IdND"].ToString());
                        }
                    }
                }

                //Xóa trên bảng hóa đơn bán chi tiết và bảng hóa đơn bán
                dt = BUS_NV.layMaHDBTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDB.RunDelSQLOnHDBCT(dr[0].ToString());
                        BUS_HDB.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hóa đơn nhập chi tiết và bảng hóa đơn nhập
                dt = BUS_NV.LayMaHDNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDN.RunDelSQLOnHDNCT(dr[0].ToString());
                        BUS_HDN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng công nợ chi tiết và bảng công nợ
                dt = BUS_NV.LayMaCNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_CN.RunDelSQLOnCNCT(dr[0].ToString());
                        BUS_CN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hàng tồn chi tiết và bảng hàng tồn
                dt = BUS_NV.LayMaHTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HT.RunDelSQLOnHTCT(dr[0].ToString());
                        BUS_HT.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên thống kê doanh thu
                dt = BUS_NV.LayMaDTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_DT.RunDelSQL(dr[0].ToString());
                    }
                }

                foreach (string items in idnd)
                {
                    BUS_ND.RunDelSQLOnTC(items); //xoá trên bảng truy cập
                    BUS_ND.RunDelSQL(items);
                }

                BUS_NV.RunDelSQL(DGVNhanVien.CurrentRow.Cells["IdNV"].Value.ToString());

                LoadDataGridView();
                ResetValues();
                DANGNHAP.thaotac += "Xoá, ";
            }
        }
Beispiel #5
0
        private void btndangnhap_Click(object sender, EventArgs e)
        {
            try
            {
                BUS_TC.Connect();
            }
            catch
            {
                MessageBox.Show("Kết nối cơ sỡ dữ liệu thất bại. Hãy thử lại lần nữa!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (BUS_TC.GetCon().State == ConnectionState.Open)
            {
                Danhmuc = "";
                Quyen   = "";
                IdNV    = "";
                DataTable dt = BUS_ND.hienthiND();
                if (dt.Rows.Count > 0)
                {
                    DataRow dr;
                    bool    kt = false;
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        string tentk = "", mk = "";
                        dr    = dt.Rows[i];
                        tentk = dr["TenTK"].ToString();
                        mk    = DecryptDataByTripleDES(dr["PassWord"].ToString(), "123");
                        if (tentk == txtUsers.Text.Trim() && mk == txtPass.Text)
                        {
                            kt      = true;
                            Danhmuc = dr["DanhmucTC"].ToString();
                            Quyen   = dr["QuyenDM"].ToString();
                            IdNV    = dr["IdNV"].ToString();

                            //lấy mã người dùng, lần đăng nhập cuối
                            mand = dr["IdND"].ToString();

                            break;
                        }
                        else
                        {
                            kt = false;
                        }
                    }
                    if (kt == true)
                    {
                        if (ckbgn.CheckState == CheckState.Checked)
                        {
                            ghinhomk = true;
                        }
                        else
                        {
                            ghinhomk = false;
                        }
                        user = txtUsers.Text;
                        pass = txtPass.Text;

                        // tạo dữ liệu trên bảng truy cập
                        //tạo mã ngẫu nhiên
                        int    gt;
                        bool   k    = false;
                        Random rand = new Random();
                        gt = rand.Next(100000000, 999999999);
                        string    ma    = "TC" + gt;
                        DataTable table = BUS_TC.hienthiTC();
                        DataRow   drt;
                        if (table.Rows.Count > 0)
                        {
                            while (k == false)
                            {
                                for (int j = 0; j < table.Rows.Count; ++j)
                                {
                                    drt = table.Rows[j];
                                    if (ma == drt["IdTC"].ToString())
                                    {
                                        k  = false;
                                        gt = rand.Next(100000000, 999999999);
                                        ma = "TC" + gt;
                                        break;
                                    }
                                    else
                                    {
                                        k = true;
                                    }
                                }
                            }
                            matc = ma;
                        }
                        else
                        {
                            matc = ma;
                        }

                        //chèn dữ liệu vào bảng truy cập
                        DTO_TC tc = new DTO_TC(matc, mand, user, "", DateTime.Now.ToShortDateString(), "", "");
                        BUS_TC.themTC(tc);

                        this.Hide();
                        MAIN m = new MAIN();
                        m.mnuTaiKhoan.Text = txtUsers.Text;
                        m.Show();
                    }
                    else
                    {
                        MessageBox.Show("Tài khoản hoặc mặt khẩu không đúng hoặc không tồn tại! Bạn chưa đăng ký tài khoản?", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtPass.Text = "";
                        txtPass.Focus();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Tài khoản hoặc mặt khẩu không đúng hoặc không tồn tại! Bạn chưa đăng ký tài khoản?", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPass.Text = "";
                    txtPass.Focus();
                    return;
                }
            }
        }