Пример #1
0
        public void LoadData()
        {
            BUS_Parameter busParameter = new BUS_Parameter();

            limitRow = busParameter.GetValue("RowInList");
            BUS_Employees bus_employees = new BUS_Employees();
            int           empCount      = bus_employees.CountEmployees();

            if (empCount % limitRow == 0)
            {
                lblMaxPage.Content = empCount / limitRow;
            }
            else
            {
                lblMaxPage.Content = empCount / limitRow + 1;
            }
            if (currentPage == (int)lblMaxPage.Content)
            {
                btnPageNext.IsEnabled = false;
            }
            else
            {
                btnPageNext.IsEnabled = true;
            }
            ReloadDGAccount();
        }
Пример #2
0
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            string        id      = ((Button)sender).Tag.ToString();
            BUS_Employees busEmp  = new BUS_Employees();
            DTO_Employees editEmp = busEmp.GetEmpByID(id);

            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window = new Window
            {
                ResizeMode            = ResizeMode.NoResize,
                WindowStyle           = WindowStyle.None,
                Title                 = "Sửa tài khoản",
                Content               = new PopupEditAccount(editEmp),
                Width                 = 460,
                Height                = 460,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();
            LoadData();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Пример #3
0
        public bool CheckPassword()
        {
            tbIDValidation.Text = tbPassValidation.Text = "";
            string id   = txtBoxAccount.Text;
            string pass = txtBoxPassword.Password;

            if (id == "")
            {
                tbIDValidation.Text = "Tên tài khoản không được để trống.";
                return(false);
            }
            if (pass == "")
            {
                tbPassValidation.Text = "Mật khẩu không được để trống.";
                return(false);
            }

            BUS_Employees busEmp   = new BUS_Employees();
            string        truePass = busEmp.GetPasswordByID(id);

            if (truePass == "")
            {
                //show validate can't find account
                tbIDValidation.Text = "Tài khoản không tồn tại hoặc đã bị vô hiệu hóa.";
                return(false);
            }

            if (truePass != pass)
            {
                //show validate false account or password
                tbPassValidation.Text = "Mật khẩu không đúng.";
                return(false);
            }
            return(true);
        }
Пример #4
0
        private void LoginScreen_BtnSale_Click(object sender, RoutedEventArgs e)
        {
            bool checkResult = loginScreen.CheckPassword();

            if (checkResult)
            {
                tblockUsername.Text = loginScreen.txtBoxAccount.Text;
                BUS_Employees busEmp = new BUS_Employees();
                currentEmpID   = tblockUsername.Text;
                currentEmpType = busEmp.GetEmpTypeByID(tblockUsername.Text);

                BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup();
                bool isHavePermission = busAccPerGr.IsHavePermission(currentEmpType, "AP001");
                if (isHavePermission)
                {
                    gridLogin.Children.Clear();
                    var screen = new Cashier(this, currentEmpID);
                    gridLogin.Children.Add(screen);
                }
                else
                {
                    MessageBox.Show("Bạn không có quyền sử dụng chức năng này!");
                }
            }
        }
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            tbOldPassValidation.Text = tbNewPassValidation.Text = tbConfirmPassValidation.Text = "";
            if (tboxOldPass.Password == "")
            {
                //Old password is empty
                tbOldPassValidation.Text = "Mật khẩu cũ không được để trống.";
                return;
            }

            if (tboxNewPass.Password == "")
            {
                //New password is empty
                tbNewPassValidation.Text = "Mật khẩu mới không được để trống.";
                return;
            }

            if (tboxNewPass.Password.Length < 4 || tboxNewPass.Password.Length > 20)
            {
                // New password < 4 characters or > 20 characters
                tbNewPassValidation.Text = "Mật khẩu mới phải từ 4-20 ký tự.";
                return;
            }

            if (tboxConfirmPass.Password == "")
            {
                //Confirm password is empty
                tbConfirmPassValidation.Text = "Xác nhận mật khẩu không được để trống.";
                return;
            }

            if (tboxNewPass.Password.Length != tboxConfirmPass.Password.Length)
            {
                // New password not equal to Confirm password
                tbConfirmPassValidation.Text = "Mật khẩu không khớp.";
                return;
            }

            BUS_Employees busAcc = new BUS_Employees();

            if (busAcc.GetPasswordByID(empId) != tboxOldPass.Password)
            {
                // Old password is wrong
                tbOldPassValidation.Text = "Mật khẩu không đúng.";
                return;
            }

            if (busAcc.EditPassword(empId, tboxConfirmPass.Password))
            {
                MessageBox.Show($"Đã đổi mật khẩu của nhân viên {empId}.");
                Window.GetWindow(this).Close();
            }
            else
            {
                MessageBox.Show($"Đã xảy ra lỗi trong quá trình đổi mật khẩu.");
            }
        }
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            tbPassValidation.Text = tbNameValidation.Text = tbGroupAccountValidation.Text = "";

            if (tboxPassword.Password == "")
            {
                //Password is empty
                tbPassValidation.Text = "Mật khẩu không được để trống.";
                return;
            }

            if (tboxPassword.Password.Length < 4 || tboxPassword.Password.Length > 20)
            {
                //Password < 4 characters or > 20 characters
                tbPassValidation.Text = "Mật khẩu phải từ 4-20 ký tự.";
                return;
            }

            if (tboxEmpName.Text == "")
            {
                //Employee Name is empty
                tbNameValidation.Text = "Tên nhân viên không được để trống.";
                return;
            }

            string newEmpTypeID = "";

            foreach (EmployeeType empType in empTypes)
            {
                if (empType.name == cbEmpType.Text)
                {
                    newEmpTypeID = empType.id;
                    break;
                }
            }

            DTO_Employees newEmp = new DTO_Employees(tboxAccount.Text, tboxEmpName.Text, newEmpTypeID, tboxPassword.Password);

            BUS_Employees busAcc = new BUS_Employees();

            if (busAcc.EditEmployee(newEmp))
            {
                MessageBox.Show($"Đã sửa tài khoản {tboxAccount.Text} của nhân viên {tboxEmpName.Text}.");
                Window.GetWindow(this).Close();
            }
            else
            {
                MessageBox.Show($"Đã xảy ra lỗi trong quá trình sửa tài khoản.");
            }
        }
Пример #7
0
        private void LoginScreen_BtnManager_Click(object sender, RoutedEventArgs e)
        {
            bool checkResult = loginScreen.CheckPassword();

            if (checkResult)
            {
                tblockUsername.Text = loginScreen.txtBoxAccount.Text;
                BUS_Employees busEmp = new BUS_Employees();
                currentEmpID = tblockUsername.Text;
                ((ItemMenu)((MenuItem)Menu.Children[0]).DataContext)._Cashier.SetCurrrentUser(currentEmpID);
                currentEmpType = busEmp.GetEmpTypeByID(tblockUsername.Text);
                gridLogin.Children.Clear();
                StackPanelMain.Children.Clear();
                StackPanelMain.Children.Add(banner);
            }
        }
Пример #8
0
        private void ReceiptButton_Click(object sender, RoutedEventArgs e)
        {
            BUS_Employees             busEmp      = new BUS_Employees();
            string                    typeEmp     = busEmp.GetEmpTypeByID(user);
            BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup();
            bool isHavePermission = busAccPerGr.IsHavePermission(typeEmp, "AP001");

            if (isHavePermission)
            {
                _context.SwitchToReceipt();
                PrintScreen.Children.Clear();
            }
            else
            {
                MessageBox.Show("Bạn không có quyền sử dụng chức năng này!");
            }
        }
Пример #9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window = new Window
            {
                ResizeMode            = ResizeMode.NoResize,
                WindowStyle           = WindowStyle.None,
                Title                 = "Thêm tài khoản",
                Content               = new PopupAddAccount(),
                Width                 = 460,
                Height                = 460,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();

            BUS_Employees busEmp   = new BUS_Employees();
            int           empCount = busEmp.CountEmployees();

            if (empCount % limitRow == 0)
            {
                lblMaxPage.Content = empCount / limitRow;
            }
            else
            {
                lblMaxPage.Content = empCount / limitRow + 1;
            }

            if (currentPage < (int)lblMaxPage.Content)
            {
                btnPageNext.IsEnabled = true;
            }
            else
            {
                btnPageNext.IsEnabled = false;
            }

            ReloadDGAccount();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Пример #10
0
        void ReloadDGAccount()
        {
            BUS_Employees      busEmp    = new BUS_Employees();
            List <AccountInfo> employees = new List <AccountInfo>();
            DataTable          temp      = busEmp.GetEmployees(limitRow, limitRow * (currentPage - 1));

            foreach (DataRow row in temp.Rows)
            {
                string id    = row["EmployeeID"].ToString();
                string name  = row["EmployeeName"].ToString();
                string type  = row["EmployeeTypeName"].ToString();
                string pass  = row["Password"].ToString();
                bool   state = true;
                if (row["State"].ToString() == "0")
                {
                    state = false;
                }
                employees.Add(item: new AccountInfo(id, name, type, pass, state));
            }
            this.dataGridAccount.ItemsSource = employees;
            this.dataGridAccount.Items.Refresh();
        }
Пример #11
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string name = ((Button)sender).Tag.ToString();

            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            string           id         = busEmpType.GetIDByName(name);

            if (id == "ET001")
            {
                MessageBox.Show("Đây là nhóm tài khoản gốc, không thể xóa!");
                return;
            }
            BUS_Employees busEmp = new BUS_Employees();

            if (busEmp.CountEmployeesByTypeID(id) > 0)
            {
                MessageBox.Show($"Không thể xóa do vẫn còn tài khoản có nhóm tài khoản này.");
                return;
            }

            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window = new Window
            {
                ResizeMode            = ResizeMode.NoResize,
                WindowStyle           = WindowStyle.None,
                Title                 = "Xóa tài khoản",
                Content               = new PopupDeleteConfirm($"Bạn có chắc chắn muốn xóa \nnhóm tài khoản {name} không?", name, 2),
                Width                 = 420,
                Height                = 210,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();

            int empTypeCount = busEmpType.CountEmployeeTypes();

            if (empTypeCount % limitRow == 0)
            {
                lblMaxPage.Content = empTypeCount / limitRow;
            }
            else
            {
                lblMaxPage.Content = empTypeCount / limitRow + 1;
            }
            if (currentPage > (int)lblMaxPage.Content)
            {
                tbNumPage.Text = (--currentPage).ToString();
            }

            if (currentPage == (int)lblMaxPage.Content)
            {
                btnPageNext.IsEnabled = false;
            }
            else
            {
                btnPageNext.IsEnabled = true;
            }

            if (currentPage == 1)
            {
                btnPagePre.IsEnabled = false;
            }
            else
            {
                btnPagePre.IsEnabled = true;
            }

            ReloadDGGroupAccount();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            tbIDValidation.Text = tbPassValidation.Text = tbNameValidation.Text = tbGroupAccountValidation.Text = "";
            //Check if any field is empty
            if (tboxAccName.Text == "")
            {
                //Employee ID is empty
                tbIDValidation.Text = "Tài khoản không được để trống.";
                return;
            }

            if (tboxPassword.Password == "")
            {
                //Password is empty
                tbPassValidation.Text = "Mật khẩu không được để trống.";
                return;
            }

            if (tboxPassword.Password.Length < 4 || tboxPassword.Password.Length > 20)
            {
                //Password < 4 characters or > 20 characters
                tbPassValidation.Text = "Mật khẩu phải từ 4-20 ký tự.";
                return;
            }

            if (tboxEmpName.Text == "")
            {
                //Employee Name is empty
                tbNameValidation.Text = "Tên nhân viên không được để trống.";
                return;
            }

            string newEmpTypeID = "";

            foreach (EmployeeType empType in empTypes)
            {
                if (empType.name == comboboxEmpType.Text)
                {
                    newEmpTypeID = empType.id;
                    break;
                }
            }

            if (newEmpTypeID == "")
            {
                //Employee Type not found
                tbGroupAccountValidation.Text = "Nhóm tài khoản không được để trống.";
                return;
            }

            DTO_Employees newEmp = new DTO_Employees(tboxAccName.Text, tboxEmpName.Text, newEmpTypeID, tboxPassword.Password);

            BUS_Employees busAcc = new BUS_Employees();

            if (busAcc.CreateEmployee(newEmp))
            {
                MessageBox.Show($"Đã thêm tài khoản {tboxAccName.Text} cho nhân viên {tboxEmpName.Text}");
                Window.GetWindow(this).Close();
            }
            else
            {
                MessageBox.Show($"Tên tài khoản bị trùng với một trong những tài khoản đã được tạo");
            }
        }
Пример #13
0
        private void cbCheck_Click(object sender, RoutedEventArgs e)
        {
            string id    = ((CheckBox)sender).Tag.ToString();
            bool?  state = ((CheckBox)sender).IsChecked;

            if (state == false)
            {
                if (_context.GetCurrentEmpID() == id)
                {
                    MessageBox.Show("Không được vô hiệu hóa tài khoản của bản thân!");
                    ((CheckBox)sender).IsChecked = true;
                    return;
                }

                if ("E001" == id)
                {
                    MessageBox.Show("Đây là tài khoản gốc, không được vô hiệu hóa!");
                    ((CheckBox)sender).IsChecked = true;
                    return;
                }
            }
            BUS_Employees busEmp = new BUS_Employees();
            string        name   = busEmp.GetEmpNameByID(id);

            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window;

            if (state == true)
            {
                window = new Window
                {
                    ResizeMode            = ResizeMode.NoResize,
                    WindowStyle           = WindowStyle.None,
                    Title                 = "Kích hoạt tài khoản",
                    Content               = new PopupDeleteConfirm($"Bạn có chắc chắn muốn kích hoạt tài khoản {id} \n của nhân viên {name} không?", id, 3),
                    Width                 = 380,
                    Height                = 210,
                    WindowStartupLocation = WindowStartupLocation.CenterScreen
                }
            }
            ;
            else
            {
                window = new Window
                {
                    ResizeMode            = ResizeMode.NoResize,
                    WindowStyle           = WindowStyle.None,
                    Title                 = "Vô hiệu hóa tài khoản",
                    Content               = new PopupDeleteConfirm($"Bạn có chắc chắn muốn vô hiệu hóa tài khoản \n{id} của nhân viên {name} không?", id, 4),
                    Width                 = 380,
                    Height                = 210,
                    WindowStartupLocation = WindowStartupLocation.CenterScreen
                }
            };
            window.ShowDialog();
            LoadData();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Пример #14
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string id = ((Button)sender).Tag.ToString();

            if (_context.GetCurrentEmpID() == id)
            {
                MessageBox.Show("Không được xóa tài khoản của bản thân!");
                return;
            }

            if (id == "E001")
            {
                MessageBox.Show("Đây là tài khoản gốc, không thể xóa!");
                return;
            }

            BUS_Employees busEmp = new BUS_Employees();
            string        name   = busEmp.GetEmpNameByID(id);

            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window = new Window
            {
                ResizeMode            = ResizeMode.NoResize,
                WindowStyle           = WindowStyle.None,
                Title                 = "Xóa tài khoản",
                Content               = new PopupDeleteConfirm($"Bạn có chắc chắn muốn xóa tài khoản {id}\ncủa nhân viên {name} không?", id, 1),
                Width                 = 420,
                Height                = 210,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();

            int empCount = busEmp.CountEmployees();

            if (empCount % limitRow == 0)
            {
                lblMaxPage.Content = empCount / limitRow;
            }
            else
            {
                lblMaxPage.Content = empCount / limitRow + 1;
            }
            if (currentPage > (int)lblMaxPage.Content)
            {
                tbNumPage.Text = (--currentPage).ToString();
            }

            if (currentPage == (int)lblMaxPage.Content)
            {
                btnPageNext.IsEnabled = false;
            }
            else
            {
                btnPageNext.IsEnabled = true;
            }

            if (currentPage == 1)
            {
                btnPagePre.IsEnabled = false;
            }
            else
            {
                btnPagePre.IsEnabled = true;
            }

            ReloadDGAccount();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Пример #15
0
        public string GetCurrentEmpName()
        {
            BUS_Employees bus = new BUS_Employees();

            return(bus.GetEmpNameByID(this.currentEmpID));
        }
Пример #16
0
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            BUS_Employees busEmp = new BUS_Employees();

            switch (this.type)
            {
            case 1:     /// Delete Account
                if (busEmp.IsDoingAnything(deleteid))
                {
                    MessageBox.Show($"Không thể xóa tài khoản {deleteid} do tài khoản này đã lập hóa đơn/lập phiếu chi/nhập hàng/xuất hàng.");
                    return;
                }

                bool result1 = busEmp.DeleteEmployee(deleteid);

                if (result1)
                {
                    MessageBox.Show($"Đã xóa tài khoản {deleteid}.");
                    Window.GetWindow(this).Close();
                }
                else
                {
                    MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa tài khoản.");
                }
                break;

            case 2:     /// Delete Account type
                BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup();
                BUS_EmployeeType          busEmpType  = new BUS_EmployeeType();

                if (!busAccPerGr.DeleteByEmpTypeID(busEmpType.GetIDByName(deleteid)))
                {
                    MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa nhóm tài khoản.");
                }

                int result2 = busEmpType.DeleteEmployeeType(busEmpType.GetIDByName(deleteid));
                if (result2 == 0)
                {
                    MessageBox.Show($"Không thể xóa do vẫn còn tài khoản có nhóm tài khoản này.");
                }
                else
                {
                    MessageBox.Show($"Đã xóa nhóm tài khoản {deleteid}.");
                    Window.GetWindow(this).Close();
                }
                break;

            case 3:     /// Active Account
                bool result3 = busEmp.SetState(deleteid, true);

                if (result3)
                {
                    MessageBox.Show($"Đã kích hoạt tài khoản {deleteid}.");
                    Window.GetWindow(this).Close();
                }
                else
                {
                    MessageBox.Show($"Đã xảy ra lỗi trong quá trình kích hoạt tài khoản.");
                }
                break;

            case 4:     /// Disable Account
                bool result4 = busEmp.SetState(deleteid, false);

                if (result4)
                {
                    MessageBox.Show($"Đã vô hiệu hóa tài khoản {deleteid}.");
                    Window.GetWindow(this).Close();
                }
                else
                {
                    MessageBox.Show($"Đã xảy ra lỗi trong quá trình vô hiệu hóa tài khoản.");
                }
                break;
            }
        }