/// <summary> /// Add new Employ Information /// </summary> /// <param name="obj">In this Case Parameter is not need.</param> private void newEmployeeClick(object obj) { this.EmployeeNew.IsEnabled = false; Mouse.OverrideCursor = Cursors.Wait; try { ViewEmployPermissions defaultPermission = new ViewEmployPermissions(); ModelEmployee newEmployee = new ModelEmployee(); newEmployee.Permissions = new ObservableCollection<ModelEmployPermissions>(defaultPermission.Where(x=>x.SupperTip!=null).OrderBy(x=>x.Priority)); (this.EmployeeGridView.ItemsSource as ObservableCollection<ModelEmployee>).Add(newEmployee); this.EmployeeGridView.Rebind(); this.EmployeeGridView.SelectedItem = this.EmployeeGridView.Items[this.EmployeeGridView.Items.IndexOf(newEmployee)]; } catch (Exception errorException) { LogFileWriter.ErrorToLog("New Employee Click",errorException); DXMessageBox.Show(errorException.Message, CvVariables.ERROR_MESSAGES[0, 0], MessageBoxButton.OK, MessageBoxImage.Error); } finally { Mouse.OverrideCursor = null; this.EmployeeNew.IsEnabled = true; } }
/// <summary> /// Employee Login Operation is here. /// </summary> /// <param name="obj">Type of ModelEmployee</param> private void employeeLogin_Click(object obj) { this.EmployeeLogin.IsEnabled = false; Mouse.OverrideCursor = Cursors.Wait; try { if (obj!=null) { ModelEmployee employeeLoginInfo = obj as ModelEmployee; if (!String.IsNullOrEmpty(employeeLoginInfo.Name) && !String.IsNullOrEmpty(employeeLoginInfo.Password)) { this.LoginBusyIndicator.IsBusy = true; Task LoginTask = new Task(new Action(() => { using (Cafeteria_Vernier_dbEntities CVDatabase= new Cafeteria_Vernier_dbEntities()) { ViewEmployPermissions defultParmissions = new ViewEmployPermissions(); LoginEmployee = null; // Query in the database and get employee information and his all permissions. LoginEmployee = (from employeeInfo in CVDatabase.Employees.ToList() where employeeInfo.EmployeeID.Trim().Equals(employeeLoginInfo.Name, StringComparison.InvariantCultureIgnoreCase) && employeeInfo.Password.Trim().Equals(employeeLoginInfo.Password) select new ModelEmployee { UserImage=employeeInfo.UserImage, Address = employeeInfo.Address, Name = employeeInfo.EmployeeID, Password = employeeInfo.Password, PhoneNmber = employeeInfo.Phone, Permissions = (new ObservableCollection<ModelEmployPermissions>(new ObservableCollection<ModelEmployPermissions> (from employeeParmisionbd in employeeInfo.EmployeePermissions join employeeParmissions in defultParmissions on employeeParmisionbd.Privilege.Trim() equals employeeParmissions.Item orderby employeeParmissions.Priority select new ModelEmployPermissions { Item = employeeParmissions.Item, Permission = employeeParmissions.Permission, Setting = employeeParmissions.Setting, ImagePath = employeeParmissions.ImagePath, KeboardShortcut = employeeParmissions.KeboardShortcut, Priority = employeeParmissions.Priority, ScreenTip = employeeParmissions.ScreenTip, SupperTip = employeeParmissions.SupperTip }) .Distinct(new ParmissionIequality()))) }).FirstOrDefault(); if (LoginEmployee != null) { this.Dispatcher.Invoke(new Action(() => { //Build the main menu this.MainMenu.ItemsSource = LoginEmployee.Permissions.Where(x => x.Priority != 0 && x.Setting == null).OrderBy(x => x.Priority); var yy = LoginEmployee.Permissions.Where(x => x.Item.Equals("Setting") && x.Setting != null).OrderBy(x => x.Priority); this.SettingMenu.ItemsSource = yy; this.mainMenuClick("Home"); this.MainMenu.Visibility = Visibility.Visible; this.LoginBusyIndicator.IsBusy = false; this.LoginBusyIndicator.Visibility = Visibility.Hidden; this.PanelLogerInfo.Visibility = Visibility.Visible; })); } else { this.Dispatcher.Invoke(new Action(() => { Mouse.OverrideCursor = null; DXMessageBox.Show("Username or Password is not correct.", CvVariables.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation); this.LoginBusyIndicator.IsBusy = false; }), DispatcherPriority.Normal); } } })); LoginTask.Start(); } else { Mouse.OverrideCursor = null; DXMessageBox.Show("Username and Password are empty", CvVariables.SOFTWARE_NAME, MessageBoxButton.OK, MessageBoxImage.Error); } } else { Mouse.OverrideCursor = null; DXMessageBox.Show("Username and Password are empty",CvVariables.SOFTWARE_NAME,MessageBoxButton.OK,MessageBoxImage.Error); } } catch (Exception ErrorException) { LogFileWriter.ErrorToLog("Login Button Click", ErrorException); Mouse.OverrideCursor = null; DXMessageBox.Show(ErrorException.Message,CvVariables.SOFTWARE_NAME,MessageBoxButton.OK,MessageBoxImage.Error); } finally { Mouse.OverrideCursor = null; this.EmployeeLogin.IsEnabled = true; } }
private void mainMenuClick(object obj) { Mouse.OverrideCursor = Cursors.Wait; try { if (this.LoginEmployee==null || this.LoginEmployee.Permissions.AsParallel().FirstOrDefault(x => x.Item.Equals(obj.ToString())) == null) { return; } this.hidePanels(); switch (obj.ToString()) { case "NewEmployee": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities CVDatabase = new Cafeteria_Vernier_dbEntities()) { ViewEmployPermissions defultParmissions = new ViewEmployPermissions(); ObservableCollection<ModelEmployee> employeeinfoList = new ObservableCollection<ModelEmployee>(from employeeInfo in CVDatabase.Employees.ToList().Where(x => x.EmployeeID.Trim() != "Admin") select new ModelEmployee { UserImage = employeeInfo.UserImage, Address = employeeInfo.Address, Name = employeeInfo.EmployeeID, Password = employeeInfo.Password, FirstPassword = employeeInfo.Password, PhoneNmber = employeeInfo.Phone, Permissions = new ObservableCollection<ModelEmployPermissions> ( (from permissionDb in defultParmissions select new ModelEmployPermissions { SupperTip = permissionDb.SupperTip, Priority = permissionDb.Priority, Setting = permissionDb.Setting, Permission = employeeInfo.EmployeePermissions.FirstOrDefault(x => x.Privilege.Trim().Equals(permissionDb.Item, StringComparison.InvariantCultureIgnoreCase) && permissionDb.Setting == x.SettingPrivilage) != null ? true : false }).OrderBy(x => x.Priority) ) }); this.Dispatcher.BeginInvoke( new Action(() => { this.EmployeeGridView.ItemsSource = employeeinfoList; this.selectGridViewFirstItem(this.EmployeeGridView); }),DispatcherPriority.DataBind); } })).Start(); this.PanelNewEmploy.Visibility = Visibility.Visible; break; case "CountersInformation": this.PanelCounterView.Visibility = Visibility.Visible; break; case "NewCustomer": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities CVDatabase = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCustomer> customerCollection = new ObservableCollection<ModelCustomer>(from customerInfo in CVDatabase.CustomerInformations select new ModelCustomer { UserName = customerInfo.UserID, Address = customerInfo.Address, Email = customerInfo.Email, Image = customerInfo.Logo, JoinDate = customerInfo.JoinDate, NationalID = customerInfo.NationalID, Name = customerInfo.Name, Phone = customerInfo.Phone, Minutes = customerInfo.CustomerAccount.Minutes, CheckPassword = customerInfo.CustomerAccount.Password, Password = customerInfo.CustomerAccount.Password }); this.Dispatcher.BeginInvoke( new Action(() => { ICollectionView ProductInfoView = CollectionViewSource.GetDefaultView(customerCollection); this.CustomerList.ItemsSource = customerCollection; this.selectListBoxFirstItem(this.CustomerList); new CustomerInfoSearch(ProductInfoView, this.CustomerTxtSearch); }),DispatcherPriority.DataBind); } })).Start(); this.PanelNewCustomer.Visibility = Visibility.Visible; break; case "NewTeam": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabase= new Cafeteria_Vernier_dbEntities()) { var teamsQuery = new ObservableCollection<ModelTeamInfo>(from teamInfo in cvDatabase.Teams.ToList() select new ModelTeamInfo { AdminName = teamInfo.AdminName, Image = teamInfo.Logo, JoinDate = teamInfo.JoinDate, Minutes = teamInfo.TeamAccount.Minutes, Name = teamInfo.Name, TeamMemberList = new ObservableCollection<ModelCommonUse>(from member in teamInfo.TeamMembers where member.Name!=null select new ModelCommonUse { UserName=member.UserID, Image=member.CustomerInformation.Logo }) }); this.Dispatcher.BeginInvoke(new Action(() => { this.TeamGridView.ItemsSource = teamsQuery; this.selectGridViewFirstItem(this.TeamGridView); }), DispatcherPriority.DataBind); } })).Start(); new Task( new Action(() => { ObservableCollection<ModelCommonUse> customerShotInfo = this.customerInfo(); this.Dispatcher.BeginInvoke( new Action(() => { ICollectionView userInfoView = CollectionViewSource.GetDefaultView(customerShotInfo); new CommonInfoSearch(userInfoView, this.TeamUserSearch); this.TeamExistUserList.ItemsSource = customerShotInfo; this.TeamAdminName.ItemsSource = customerShotInfo; }),DispatcherPriority.DataBind); })).Start(); this.PanelNewTeam.Visibility = Visibility.Visible; break; case "AccountRecharge": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabase = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCustomer> userQuery = new ObservableCollection<ModelCustomer>(from userInfo in cvDatabase.CustomerInformations select new ModelCustomer { Image = userInfo.Logo, Name = userInfo.UserID, Minutes=userInfo.CustomerAccount.Minutes }); this.Dispatcher.BeginInvoke( new Action(() => { ICollectionView userInfoView = CollectionViewSource.GetDefaultView(userQuery); new AccountRechargeSearchs(userInfoView, this.AccountRecUserSearch); this.AccountRecUser.ItemsSource = userQuery; this.selectListBoxFirstItem(this.AccountRecUser); })); } })).Start(); new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabase = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelTeamInfo> teamQuery = new ObservableCollection<ModelTeamInfo>(from teamInfo in cvDatabase.Teams select new ModelTeamInfo { Image = teamInfo.Logo, Name = teamInfo.Name, Minutes=teamInfo.TeamAccount.Minutes }); this.Dispatcher.BeginInvoke( new Action(() => { ICollectionView teamInfoView = CollectionViewSource.GetDefaultView(teamQuery); new AccountRechargeSearchs(teamInfoView, this.AccountRecTeamSearch); this.AccountRecTeam.ItemsSource = teamQuery; this.selectListBoxFirstItem(this.AccountRecTeam); })); } })).Start(); this.PanelAccountRecharge.Visibility = Visibility.Visible; break; case "Cash": this.PanelCahView.Visibility = Visibility.Visible; break; case "CashHistory": this.PanelCashHistory.Visibility = Visibility.Visible; break; case "Summary": this.PanelSummary.Visibility = Visibility.Visible; break; case "RechargeHistory": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCommonUse> cutomerShortInfo = this.customerInfo(); this.Dispatcher.BeginInvoke( new Action(() => { this.ResHisCustomerComboBox.ItemsSource = cutomerShortInfo; })); } })).Start(); new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCommonUse> teamShortInfo = new ObservableCollection<ModelCommonUse>(cvDatabse.Teams.Select(x => new ModelCommonUse { UserName = x.Name, Image = x.Logo })); this.Dispatcher.BeginInvoke( new Action(() => { this.ResHisTeamComboBox.ItemsSource = teamShortInfo; })); } })).Start(); this.PanelRechargeHistoryView.Visibility = Visibility.Visible; break; case "CustomerLoginHistory": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCommonUse> customerShortInfo = this.customerInfo(); this.Dispatcher.BeginInvoke( new Action(() => { this.LogHisComboBox.ItemsSource = customerShortInfo; })); } })).Start(); this.PanelLoginHistory.Visibility = Visibility.Visible; break; case "CustomerMaintenance": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCommonUse> cusromerShortInfo = this.customerInfo(); this.Dispatcher.BeginInvoke( new Action(() => { this.UserMaintenanceCutomer.ItemsSource = cusromerShortInfo; })); } })).Start(); this.Option = "ByName"; this.SubOption = "ByDate"; this.PanelUserMaintenance.Visibility = Visibility.Visible; break; case "TeamMaintenance": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCommonUse> teamShortInfo = new ObservableCollection<ModelCommonUse>(cvDatabse.Teams.Select(x => new ModelCommonUse { UserName = x.Name, Image = x.Logo })); this.Dispatcher.BeginInvoke( new Action(() => { this.temMainTeamName.ItemsSource = teamShortInfo; })); } })).Start(); this.Option = "ByName"; this.SubOption = "ByDate"; this.PanelTeamMainTenance.Visibility = Visibility.Visible; break; case "SendEmail": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<ModelCommonUse> customerShortInfo = this.customerInfo(); this.Dispatcher.BeginInvoke( new Action(() => { this.sendMailUsers.ItemsSource = customerShortInfo; })); } })).Start(); this.Option = "OneByOne"; this.PanelSendMail.Visibility = Visibility.Visible; break; case "Database": this.PanelDatabaseBackupRestore.Visibility = Visibility.Visible; break; case "Setting": this.PanelSetting.Visibility = Visibility.Visible; break; case "CustomerStatusReset": new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<CustomerAccount> logginCustomers = new ObservableCollection<CustomerAccount>(cvDatabse.CustomerAccounts.Where(x => x.Status == true)); this.Dispatcher.BeginInvoke( new Action(() => { this.userResGrid.ItemsSource = logginCustomers; })); } })).Start(); new Task( new Action(() => { using (Cafeteria_Vernier_dbEntities cvDatabse = new Cafeteria_Vernier_dbEntities()) { ObservableCollection<TeamAccount> logginCustomers = new ObservableCollection<TeamAccount>(cvDatabse.TeamAccounts.Where(x => x.Status == true)); this.Dispatcher.BeginInvoke( new Action(() => { this.TeamResGrid.ItemsSource = logginCustomers; })); } })).Start(); this.PanelStatusReset.Visibility = Visibility.Visible; break; default: break; } } catch (Exception ErrorException) { LogFileWriter.ErrorToLog(string.Format("Menu >> {0} on Click", obj.ToString()), ErrorException); Mouse.OverrideCursor = null; DXMessageBox.Show(ErrorException.Message,CvVariables.SOFTWARE_NAME,MessageBoxButton.OK,MessageBoxImage.Error); } finally { Mouse.OverrideCursor = null; } }