예제 #1
0
        private void UpdateDepartmentDetailViewModel(TreeViewNode selectedNode)
        {
            try
            {
                if (selectedNode.ID == -1)
                {
                    return;
                }

                var dept       = AuthorizationDepartments.FirstOrDefault(d => d.DepartmentID == selectedNode.ID);
                var parentDept = AuthorizationDepartments.FirstOrDefault(d => dept.Parent != null && d.DepartmentID == dept.Parent.DepartmentID);

                SelectedDepartmentDetailViewModel = new DepartmentDetailViewModel()
                {
                    ID                = dept.DepartmentID,
                    DepartmentName    = dept.Name,
                    DepartmentCode    = dept.DepartmentCode,
                    OwnedDevices      = dept.DeviceAssociations.ToList(),
                    DeviceRole        = AuthorizationDeviceRoles.First(r => r.DeviceRoleID == dept.DeviceRoleID),
                    ParentDepartment  = parentDept,
                    CurrentDepartment = dept,
                };

                RaisePropertyChanged(null);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #2
0
        public UserViewModel(User userInfo)
        {
            SaveCmd              = new RelayCommand(Save);
            CancelCmd            = new RelayCommand(() => Close(""));
            UploadImageCmd       = new RelayCommand <string>(UploadImage);
            DepartmentChangedCmd = new RelayCommand(ProcessDepartmentChangedCmd);

            CurrentUser         = userInfo;
            DepartmentInfo      = new Department();
            UserID              = userInfo.UserID;
            IsAddMode           = userInfo.UserID == 0;
            StartDate           = DateTime.Now;
            Birthday            = DateTime.Now;
            UserType            = UserType.Employee;
            ViewModelAttachment = new ViewModelAttachment <User>();
            Avator              = _userAvatorService.GetAvator(_userAvatorService.DefaultAvatorFileName);
            Title = IsAddMode ? "新增人员" : "修改人员";

            if (!IsAddMode) //Edit mode
            {
                UserType              = userInfo.Type;
                UserCode              = userInfo.UserCode;
                Name                  = userInfo.Name;
                Status                = userInfo.Status == GeneralStatus.Enabled;
                StartDate             = userInfo.StartDate;
                EndDate               = userInfo.EndDate;
                Phone                 = userInfo.Phone;
                Avator                = _userAvatorService.GetAvator(userInfo.Photo);
                DepartmentInfo        = AuthorizationDepartments.FirstOrDefault(d => d.DepartmentID == userInfo.DepartmentID);
                CurrentDepartmentName = DepartmentInfo.Name;
                Gender                = userInfo.Gender;
                LastName              = userInfo.UserPropertyInfo.FirstName;
                FirstName             = userInfo.UserPropertyInfo.FirstName;
                Nationality           = userInfo.UserPropertyInfo.Nationality;
                NativePlace           = userInfo.UserPropertyInfo.NativePlace;
                Birthday              = userInfo.UserPropertyInfo.Birthday;
                Marriage              = userInfo.UserPropertyInfo.Marriage;
                PoliticalStatus       = (userInfo.UserPropertyInfo.PoliticalStatus != null)
                    ? (PoliticalStatus)userInfo.UserPropertyInfo.PoliticalStatus : PoliticalStatus.Unknown;
                Degree = (userInfo.UserPropertyInfo.Degree != null)
                    ? (DegreeStatus)userInfo.UserPropertyInfo.Degree : DegreeStatus.Unknown;
                HomeNumber     = userInfo.UserPropertyInfo.HomeNumber;
                EnglishName    = userInfo.UserPropertyInfo.EnglishName;
                Company        = userInfo.UserPropertyInfo.Company;
                TechnicalTitle = userInfo.UserPropertyInfo.TechnicalTitle;
                TechnicalLevel = userInfo.UserPropertyInfo.TechnicalLevel;
                IDType         = userInfo.UserPropertyInfo.IDType;
                IDNumber       = userInfo.UserPropertyInfo.IDNumber;
                SocialNumber   = userInfo.UserPropertyInfo.SocialNumber;
                Email          = userInfo.UserPropertyInfo.Email;
                Address        = userInfo.UserPropertyInfo.Address;
                Postcode       = userInfo.UserPropertyInfo.Postcode;
                Remark         = userInfo.UserPropertyInfo.Remark;
            }

            DeviceRoleListBoxSource = GetDeviceRoleListBoxSource();
        }
예제 #3
0
 private void SelectAllDepartments()
 {
     AuthorizationDepartments.ForEach(t =>
     {
         if (SelectedSyncDepartmentDtos.All(sy => sy.ID != t.DepartmentID))
         {
             SelectedSyncDepartmentDtos.Add(new ComboBoxItem()
             {
                 ID = t.DepartmentID, DisplayName = t.Name
             });
         }
     });
 }
예제 #4
0
        private List <TreeViewNode> BuildTreeViewSource()
        {
            var treeViewRoots = new List <TreeViewNode>();

            var rootDepartments = AuthorizationDepartments.FindAll(d => d.Parent == null);

            foreach (var rootDepartment in rootDepartments)
            {
                var rootNode = BuildTreeNode(AuthorizationDepartments, rootDepartment);
                treeViewRoots.Add(rootNode);
            }

            return(treeViewRoots);
        }
예제 #5
0
        private void ProcessDeleteDepartmentCmd()
        {
            try
            {
                if (SelectedDepartmentDetailViewModel == null)
                {
                    Messenger.Default.Send(new NotificationMessage("请先选择部门!"), Tokens.DepartmentPage_ShowNotification);
                    return;
                }

                string assiciationErrorMessage = "";
                if (AuthorizationDepartments.Any(d => d.Parent != null && d.Parent.DepartmentID == SelectedDepartmentDetailViewModel.CurrentDepartment.DepartmentID))
                {
                    assiciationErrorMessage += "选中部门存在子部门,请先删除所属子部门!\n";
                }

                var userRepo        = NinjectBinder.GetRepository <IUserRepository>();
                var departmentUsers = userRepo.Query(new Hashtable()
                {
                    { "DepartmentID", SelectedDepartmentDetailViewModel.CurrentDepartment.DepartmentID }
                });
                if (departmentUsers.Any())
                {
                    assiciationErrorMessage += "选中部门存在人员,请先删除所属人员!\n";
                }

                if (!string.IsNullOrWhiteSpace(assiciationErrorMessage))
                {
                    Messenger.Default.Send(new NotificationMessage(assiciationErrorMessage), Tokens.DepartmentPage_ShowNotification);
                    return;
                }

                string question = string.Format("确定删除部门:{0}吗?", SelectedDepartmentDetailViewModel.DepartmentName);
                Messenger.Default.Send(new NotificationMessageAction(this, question, DeleteDepartment), Tokens.DepartmentPage_ShowQuestion);

                TreeViewSource = BuildTreeViewSource();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #6
0
        private void AddDepartment()
        {
            try
            {
                var departmentDetailViewModel = new DepartmentDetailViewModel();
                Messenger.Default.Send(new OpenWindowMessage()
                {
                    DataContext = departmentDetailViewModel
                }, Tokens.OpenDepartmentView);

                if (departmentDetailViewModel.CurrentDepartment.DepartmentID != 0)
                {
                    AuthorizationDepartments.Add(departmentDetailViewModel.CurrentDepartment);
                }
                TreeViewSource = BuildTreeViewSource();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #7
0
        private void DeleteDepartment()
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                string message = "";
                try
                {
                    _departmentRepository.Delete(SelectedDepartmentDetailViewModel.ID);
                    message = "删除部门成功!";

                    AuthorizationDepartments.Remove(SelectedDepartmentDetailViewModel.CurrentDepartment);
                    TreeViewSource = BuildTreeViewSource();
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    message = "删除部门失败!";
                }
                Messenger.Default.Send(new NotificationMessage(message), Tokens.DepartmentPage_ShowNotification);
            });
        }