Beispiel #1
0
        private async void UpdateDoorState(object sender, DoorControlOption option)
        {
            var menuItem   = (MenuItem)sender;
            var panel      = menuItem.Tag as StackPanel;
            var floordoor  = panel.DataContext as FloorDoorViewModel;
            var doorInfo   = FloorDoorManager.GetInstance().AuthorizationDoors.FirstOrDefault(x => x.DeviceDoorID == floordoor.DoorID);
            var deviceCode = ApplicationManager.GetInstance().AuthorizationDevices.First(x => x.DeviceID == doorInfo.DeviceID).Code.ToInt32();

            string message = "";

            var controller = await MessageBoxSingleton.Instance.ShowProgressAsync("同步数据", "同步数据中,请稍等", false);

            controller.SetIndeterminate();

            await Task.Run(() =>
            {
                try
                {
                    string[] messages;

                    Int32 doorIndex    = doorInfo.Code.ToInt32();
                    var selectedOption = (DeviceProxy.DoorControlOption)option.GetHashCode();

                    ResultTypes resultTypes = new DeviceServiceClient().UpdateDoorState(deviceCode, doorIndex, selectedOption, out messages);
                    message = MessageHandler.GenerateDeviceMessage(resultTypes, messages, "操作设备成功!", "操作设备失败!");
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    message = "操作设备失败!";
                }
            });

            await controller.CloseAsync();

            MessageBoxSingleton.Instance.ShowDialog(message, "");

            if (option == DoorControlOption.KeepClose)
            {
                UpdateDoorColerByState(panel, false);
            }
            else if (option == DoorControlOption.Open || option == DoorControlOption.KeepOpen)
            {
                UpdateDoorColerByState(panel, true);
            }
        }
Beispiel #2
0
 private void SelectDeviceDoor()
 {
     try
     {
         if (IsSelected == false)
         {
             if (FloorDoorManager.GetInstance().AuthorizationFloorDoor.Any(x => x.DoorID == DeviceDoorID))
             {
                 string message = "门已经和楼层绑定,不能禁用!";
                 Messenger.Default.Send(new NotificationMessage(message), Tokens.DeviceView_ShowNotification);
                 IsSelected = true;
                 RaisePropertyChanged("IsSelected");
                 return;
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
 }
Beispiel #3
0
 public void InitDoorListBox()
 {
     Doors = new ObservableCollection <FloorDoorViewModel>();
     foreach (var authDoor in FloorDoorManager.GetInstance().AuthorizationDoors)
     {
         var floorDoorViewModel = new FloorDoorViewModel();
         var bindedDoor         = FloorDoorManager.GetInstance().AuthorizationFloorDoor.FirstOrDefault(x => x.DoorID == authDoor.DeviceDoorID);
         if (bindedDoor != null)
         {
             floorDoorViewModel          = Mapper.Map <FloorDoorViewModel>(bindedDoor);
             floorDoorViewModel.DoorName = authDoor.Name;
             floorDoorViewModel.Enabled  = (bindedDoor.FloorID == 0 || bindedDoor.FloorID == FloorID);
         }
         else
         {
             floorDoorViewModel.DoorID   = authDoor.DeviceDoorID;
             floorDoorViewModel.DoorName = authDoor.Name;
             floorDoorViewModel.Enabled  = true;
         }
         Doors.Add(floorDoorViewModel);
     }
 }
Beispiel #4
0
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            try
            {
                Log.Info("Trigger Floor monitor timer event...");
                if (_selectedFloorViewModel != null && _selectedFloorViewModel.Doors.Any())
                {
                    Log.InfoFormat("Floor monitor timer check doors for floor id: {0}", _selectedFloorViewModel.FloorID);
                    foreach (var floordoorId in _dropDoorDict.Keys)
                    {
                        var         doorInfo   = FloorDoorManager.GetInstance().AuthorizationDoors.FirstOrDefault(x => x.DeviceDoorID == floordoorId);
                        var         deviceCode = ApplicationManager.GetInstance().AuthorizationDevices.First(x => x.DeviceID == doorInfo.DeviceID).Code.ToInt32();
                        ResultTypes resultTypes;
                        string[]    messages;
                        Int32       doorIndex = doorInfo.Code.ToInt32();

                        bool isopened = new DeviceServiceClient().GetDoorState(deviceCode, doorIndex, out resultTypes, out messages);
                        if (resultTypes == ResultTypes.Ok)
                        {
                            Log.InfoFormat("Floor monitor timer gets state result: [doorId={0}, isopened={1}]", floordoorId, isopened);
                            Dispatcher.Invoke(() =>
                            {
                                UpdateDoorColerByState(_dropDoorDict[floordoorId], isopened);
                            });
                        }
                        else
                        {
                            Log.Warn(messages.ConvertToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("OnTimedEvent error", ex);
                MessageBoxSingleton.Instance.ShowDialog("内部错误", "");
            }
        }
Beispiel #5
0
        private async void ViewStuff(object sender)
        {
            var menuItem   = (MenuItem)sender;
            var panel      = menuItem.Tag as StackPanel;
            var floordoor  = panel.DataContext as FloorDoorViewModel;
            var doorInfo   = FloorDoorManager.GetInstance().AuthorizationDoors.FirstOrDefault(x => x.DeviceDoorID == floordoor.DoorID);
            var deviceInfo = ApplicationManager.GetInstance().AuthorizationDevices.First(x => x.DeviceID == doorInfo.DeviceID);

            var inHouseUserService = new InHouseUserService();
            var deviceGroupEnabled = inHouseUserService.HasBindDeviceGroup(deviceInfo);

            if (deviceGroupEnabled == false)
            {
                MessageBoxSingleton.Instance.ShowDialog("此设备还未绑定设备组,无法查看人员列表", "");
                return;
            }

            string      errorMessage = "";
            List <User> inHouseUsers = null;

            var controller = await MessageBoxSingleton.Instance.ShowProgressAsync("准备数据", "准备数据中,请稍等", false);

            controller.SetIndeterminate();

            await Task.Run(() =>
            {
                try
                {
                    inHouseUsers = inHouseUserService.GetInHouseUsers(deviceInfo);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    errorMessage = "查看人员列表失败!";
                }
            });

            await controller.CloseAsync();

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                MessageBoxSingleton.Instance.ShowDialog(errorMessage, "");
                return;
            }

            if (inHouseUsers != null)
            {
                var vms = new List <UserViewModel>();
                inHouseUsers.ForEach(x => vms.Add(new UserViewModel(x)));

                var inHouseUserViewModel = new InHouseUserViewModel()
                {
                    UserViewModels = new ObservableCollection <UserViewModel>(vms)
                };

                var view = new InHouseUserView()
                {
                    DataContext = inHouseUserViewModel
                };
                view.ShowDialog();
            }
        }