Beispiel #1
0
        public void LoadData()
        {
            BUS_Parameter busParameter = new BUS_Parameter();

            limitRow = busParameter.GetValue("RowInList");

            List <GroupAccountInfo> groupAccountInfos = new List <GroupAccountInfo>();

            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            int empTypeCount            = busEmpType.CountEmployeeTypes();

            if (empTypeCount % limitRow == 0)
            {
                lblMaxPage.Content = empTypeCount / limitRow;
            }
            else
            {
                lblMaxPage.Content = empTypeCount / limitRow + 1;
            }
            if (currentPage == (int)lblMaxPage.Content)
            {
                btnPageNext.IsEnabled = false;
            }
            else
            {
                btnPageNext.IsEnabled = true;
            }

            ReloadDGGroupAccount();
        }
        public void LoadData(DTO_Employees editEmp)
        {
            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            DataTable        AccPer     = busEmpType.GetEmployeeTypes();

            empTypes = new List <EmployeeType>();
            foreach (DataRow row in AccPer.Rows)
            {
                string id   = row["EmployeeTypeID"].ToString();
                string name = row["EmployeeTypeName"].ToString();
                empTypes.Add(new EmployeeType(id, name));
            }
            this.cbEmpType.ItemsSource = empTypes;
            this.cbEmpType.Items.Refresh();

            tboxAccount.Text      = editEmp.EmployeeID;
            tboxEmpName.Text      = editEmp.EmployeeName;
            tboxPassword.Password = editEmp.Password;
            cbEmpType.Text        = editEmp.EmployeeTypeID;

            if (editEmp.EmployeeID == "E001")
            {
                tboxAccount.IsEnabled = false;
                cbEmpType.IsEnabled   = false;
            }
            else
            {
                tboxAccount.IsEnabled = true;
                cbEmpType.IsEnabled   = true;
            }
        }
        public void LoadData()
        {
            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            DataTable        AccPer     = busEmpType.GetEmployeeTypes();

            empTypes = new List <EmployeeType>();
            foreach (DataRow row in AccPer.Rows)
            {
                string id   = row["EmployeeTypeID"].ToString();
                string name = row["EmployeeTypeName"].ToString();
                empTypes.Add(new EmployeeType(id, name));
            }

            this.comboboxEmpType.ItemsSource = empTypes;
            this.comboboxEmpType.Items.Refresh();
        }
Beispiel #4
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 nhóm tài khoản",
                Content               = new PopupAddGroupAccount(),
                Width                 = 460,
                Height                = 540,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();

            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            int empTypeCount            = busEmpType.CountEmployeeTypes();

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

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

            ReloadDGGroupAccount();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Beispiel #5
0
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            string name = ((Button)sender).Tag.ToString();

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

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

            GroupAccountInfo editGrAcc = new GroupAccountInfo();

            for (int i = 0; i < dataGridGroupAccount.Items.Count; i++)
            {
                if (name == ((GroupAccountInfo)dataGridGroupAccount.Items[i]).name)
                {
                    editGrAcc = (GroupAccountInfo)dataGridGroupAccount.Items[i];
                }
            }

            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 nhóm tài khoản",
                Content               = new PopupEditGroupAccount(editGrAcc),
                Width                 = 460,
                Height                = 540,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();
            LoadData();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Beispiel #6
0
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            tbGroupAccountValidation.Text = "";
            if (tbName.Text == "")
            {
                // Name of Employee Type is empty
                tbGroupAccountValidation.Text = "Tên nhóm tài khoản không dược để trống.";
                return;
            }
            DTO_EmployeeType newEmpType = new DTO_EmployeeType("id", tbName.Text);
            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            string           newID      = busEmpType.CreateEmployeeTypes(newEmpType);

            if (newID == "")
            {
                tbGroupAccountValidation.Text = "Tên nhóm tài khoản này đã được tạo trước đây.";
            }
            else
            {
                BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup();
                foreach (AccessPermissionName item in dgSelectedList)
                {
                    foreach (DataRow row in AccPersData.Rows)
                    {
                        if (item.name == row[1].ToString())
                        {
                            busAccPerGr.CreateAccessPermissionGroup(new DTO_AccessPermissionGroup(row[0].ToString(), newID));
                            break;
                        }
                    }
                }

                MessageBox.Show($"Nhóm tài khoản {newEmpType.EmployeeTypeName} đã được tạo.");
                Window.GetWindow(this).Close();
            }
        }
Beispiel #7
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;
        }
Beispiel #8
0
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            tbGroupAccountValidation.Text = "";
            if (tbName.Text == "")
            {
                // Name of Employee Type is empty
                tbGroupAccountValidation.Text = "Tên nhóm tài khoản không dược để trống.";
                return;
            }

            BUS_EmployeeType busEmpType = new BUS_EmployeeType();
            string           editID     = busEmpType.GetIDByName(editGrAccInfo.name);
            bool             result     = busEmpType.EditEmployeeType(new DTO_EmployeeType(editID, tbName.Text));

            if (!result)
            {
                tbGroupAccountValidation.Text = "Tên nhóm tài khoản bị trùng với một nhóm tài khoản khác.";
                return;
            }
            BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup();

            #region Get List Permission
            List <AccessPermissionName> oldPerList = new List <AccessPermissionName>();

            if (editGrAccInfo.cashier)
            {
                oldPerList.Add(new AccessPermissionName(Constants.CASHIER));
            }

            if (editGrAccInfo.account)
            {
                oldPerList.Add(new AccessPermissionName(Constants.ACCOUNT));
            }

            if (editGrAccInfo.accountType)
            {
                oldPerList.Add(new AccessPermissionName(Constants.ACCOUNTTYPE));
            }

            if (editGrAccInfo.inventory)
            {
                oldPerList.Add(new AccessPermissionName(Constants.INVENTORY));
            }

            if (editGrAccInfo.cost)
            {
                oldPerList.Add(new AccessPermissionName(Constants.COST));
            }

            if (editGrAccInfo.menu)
            {
                oldPerList.Add(new AccessPermissionName(Constants.MENU));
            }

            if (editGrAccInfo.discount)
            {
                oldPerList.Add(new AccessPermissionName(Constants.DISCOUNT));
            }

            if (editGrAccInfo.report)
            {
                oldPerList.Add(new AccessPermissionName(Constants.REPORT));
            }

            if (editGrAccInfo.rule)
            {
                oldPerList.Add(new AccessPermissionName(Constants.REPORT));
            }

            #endregion
            // per deleted
            foreach (AccessPermissionName name in oldPerList)
            {
                if (!dgSelectedList.Contains(name))
                {
                    foreach (DataRow row in AccPersData.Rows)
                    {
                        if (name.name == row[1].ToString())
                        {
                            result = busAccPerGr.DeleteAccessPermissionGroup(new DTO_AccessPermissionGroup(row[0].ToString(), editID));
                            if (!result)
                            {
                                MessageBox.Show($"Đã xảy ra lỗi do quyền bị xóa đi trong quá trình sửa nhóm tài khoản {editGrAccInfo.name}.");
                            }
                            break;
                        }
                    }
                }
            }

            // per added
            foreach (AccessPermissionName item in dgSelectedList)
            {
                if (!oldPerList.Contains(item))
                {
                    foreach (DataRow row in AccPersData.Rows)
                    {
                        if (item.name == row[1].ToString())
                        {
                            result = busAccPerGr.CreateAccessPermissionGroup(new DTO_AccessPermissionGroup(row[0].ToString(), editID));
                            if (!result)
                            {
                                MessageBox.Show($"Đã xảy ra lỗi do quyền được thêm vào trong quá trình sửa nhóm tài khoản {editGrAccInfo.name}.");
                            }
                            break;
                        }
                    }
                }
            }

            MessageBox.Show($"Đã sửa thành công nhóm tài khoản {editGrAccInfo.name}.");
            Window.GetWindow(this).Close();
        }
Beispiel #9
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;
            }
        }