Exemplo n.º 1
0
        private void SyncData()
        {
            DispatcherHelper.CheckBeginInvokeOnUI(async() =>
            {
                string message = "";

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

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

                        if (SyncUserType == SyncUserType.SyncDeviceToUser)
                        {
                            var devices = new[] { SelectedDevice };
                            var users   = SelectedSyncUserDtos.Select(u =>
                            {
                                var userId   = string.IsNullOrWhiteSpace(u.Description) ? 0 : u.Description.ToInt32();
                                var userCode = u.ID.ToString();
                                return(new User()
                                {
                                    UserID = userId, UserCode = userCode, Name = u.DisplayName
                                });
                            });

                            resultTypes = new DSProxy.DeviceServiceClient().SyncSystemUsers(devices.ToArray(), users.ToArray(), out messages);
                        }
                        else
                        {
                            var devices = DeviceDtos.FindAll(d => d.IsSelected).Select(dd => new DeviceController()
                            {
                                DeviceID = dd.ID
                            });
                            var users = SelectedSyncUserDtos.Select(u => new User()
                            {
                                UserID = u.ID, Name = u.DisplayName
                            });

                            resultTypes = new DSProxy.DeviceServiceClient().SyncDeviceUsers(devices.ToArray(), DSProxy.SyncOption.Unknown, users.ToArray(), out messages);
                        }

                        message = MessageHandler.GenerateDeviceMessage(resultTypes, messages, "同步数据成功!", "同步数据失败!");
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        message = "同步数据失败!";
                    }
                });

                await controller.CloseAsync();
                Messenger.Default.Send(new NotificationMessage(message), Tokens.SyncUserView_ShowNotification);
            });
        }
Exemplo n.º 2
0
        private void SyncData()
        {
            DispatcherHelper.CheckBeginInvokeOnUI(async() =>
            {
                string message = "";

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

                await Task.Run(() =>
                {
                    try
                    {
                        var devices = DeviceDtos.FindAll(d => d.IsSelected).Select(dd => new DeviceController()
                        {
                            DeviceID = dd.ID
                        });
                        var departments = SelectedSyncDepartmentDtos.Select(u => new Department()
                        {
                            DepartmentID = u.ID
                        });

                        string[] messages;
                        DSProxy.ResultTypes resultTypes = new DSProxy.DeviceServiceClient().SyncDepartmentUsers(departments.ToArray(), devices.ToArray(), out messages);

                        message = MessageHandler.GenerateDeviceMessage(resultTypes, messages, "同步数据成功!", "同步数据失败!");
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        message = "同步数据失败!";
                    }
                });

                await controller.CloseAsync();

                SendMessage(message);
            });
        }
Exemplo n.º 3
0
        private void QueryDeviceUser()
        {
            if (SelectedDevice == null)
            {
                SendMessage("选择设备不能为空。");
                return;
            }

            if (!string.IsNullOrWhiteSpace(UserCode) && UserCode.ToInt32() == ConvertorExtension.ConvertionFailureValue)
            {
                SendMessage("输入的人员工号值无效。");
                return;
            }

            DispatcherHelper.CheckBeginInvokeOnUI(async() =>
            {
                string message = "";
                DSProxy.DeviceUserDto[] deviceUsers = null;

                var controller = await DialogCoordinator.Instance.ShowProgressAsync(this, "查询设备人员", "查询设备人员中,请稍等");
                controller.SetIndeterminate();

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

                        deviceUsers = new DSProxy.DeviceServiceClient().QueryDeviceUsers(SelectedDevice, UserCode, out resultTypes, out messages);
                        message     = MessageHandler.GenerateDeviceMessage(resultTypes, messages, "", "查询设备人员失败!");
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        message = "查询设备人员失败!";
                    }
                });

                await controller.CloseAsync();

                if (!string.IsNullOrWhiteSpace(message))
                {
                    Messenger.Default.Send(new NotificationMessage(message), Tokens.SyncUserView_ShowNotification);
                }
                else
                {
                    DeviceUserDtos = new ObservableCollection <SelectableItem>();
                    if (deviceUsers != null && deviceUsers.Any())
                    {
                        deviceUsers.OrderBy(x => x.UserCode).ForEach(x =>
                        {
                            var item = new ComboBoxItem()
                            {
                                ID = x.UserCode, DisplayName = x.UserName
                            };
                            var conditions = new Hashtable()
                            {
                                { "UserCode", x.UserCode }
                            };
                            var userInfo = _userRepo.QueryUsersForSummaryData(conditions).FirstOrDefault();
                            if (userInfo != null)
                            {
                                item.Description = userInfo.UserID.ToString();
                            }

                            DeviceUserDtos.Add(item);
                        });
                    }
                }
            });
        }