private void SetImage(string imgPath, bool isImgExceed = false) { bool isCreate; ImageScanWindow scan = CreateOrActiveWindow(out isCreate); scan.Show(); //Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => //{ if (_currentPath != imgPath) { this.img.Dispose(); AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { try { scan.Dispatcher.Invoke(new Action(() => { scan.loading.Visibility = Visibility.Visible; })); //this.img.Visibility = Visibility.Collapsed; //this.tbInfo.Text = "图片加载中..."; //BitmapImage img = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute)); if (isImgExceed) { App.Current.Dispatcher.Invoke(() => { this.img.Visibility = Visibility.Visible; scan.loading.Visibility = Visibility.Collapsed; BitmapImage img = new BitmapImage(); img.BeginInit(); img.CacheOption = BitmapCacheOption.OnLoad; img.UriSource = new Uri(IMAssets.ImageDeal.ImgLoadFail); img.EndInit(); img.Freeze(); this.tbInfo.Text = "图片已过期!"; this.img.Source = img; //SetProperty(imgPath, scan, img, false); SetState(true); }); return(null); } else { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = new MemoryStream(File.ReadAllBytes(imgPath)); //bitmap.StreamSource = new MemoryStream(ImageHelper.ImageToBytes(path)); bitmap.EndInit(); bitmap.Freeze(); return(bitmap); } } catch { try { BitmapImage img = new BitmapImage(); img.BeginInit(); img.CacheOption = BitmapCacheOption.OnLoad; if (imgPath == IMAssets.ImageDeal.DefaultHeadImage) { img.UriSource = new Uri(imgPath); } else { img.StreamSource = new MemoryStream(ImageHelper.ImageToBytes(imgPath)); } img.EndInit(); img.Freeze(); return(img); } catch { App.Current.Dispatcher.Invoke(() => { this.img.Visibility = Visibility.Collapsed; scan.loading.Visibility = Visibility.Collapsed; IMClient.Helper.MessageHelper.LoadImgContent(_target); _currentPath = imgPath; this.Title = this.tbName.Text = System.IO.Path.GetFileName(imgPath); this.tbInfo.Text = "加载失败!"; SetState(true); }); return(null); } } }, (ex, data) => { if (data == null) { return; } scan.Dispatcher.Invoke(new Action(() => { loading.Visibility = Visibility.Collapsed; })); SetProperty(imgPath, scan, data, false); _currentPath = imgPath; this.Title = this.tbName.Text = System.IO.Path.GetFileName(imgPath); //Task.Delay(30).ContinueWith(task => //{ // scan.Dispatcher.Invoke(new Action(() => // { if (scan.WindowState == WindowState.Minimized) { scan.WindowState = WindowState.Normal; } SetState(true); scan.Activate(); //})); //}); //})); }); } else { SetState(true); } }
public ActivityListViewModel(bool isAdminId, string groupId) { _isAdminId = isAdminId; if (!_isAdminId) { IsShowBtnAddActivity = false; } _groupId = groupId; _activityInfoList = new ObservableCollection <ActivityInfoModel>(); var errCode = 0; var errMsg = string.Empty; AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { AntSdkGetGroupActivitysInput intput = new AntSdkGetGroupActivitysInput { groupId = _groupId, activityStatus = 0, pageNum = _page, pageSize = _size, userId = AntSdkService.AntSdkCurrentUserInfo.userId }; var activityList = AntSdkService.GetGroupActivitys(intput, ref errCode, ref errMsg); return(activityList); }, (ex, datas) => { if (datas?.list != null && datas.list.Count > 0) { foreach (var activityInfo in datas.list) { var tempInfoModel = new ActivityInfoModel(); tempInfoModel.IsHaveActivity = activityInfo.voteFlag; if (activityInfo.userId == AntSdkService.AntSdkCurrentUserInfo.userId) { tempInfoModel.IsbtnDeleteVisibility = true; } tempInfoModel.ActivityId = activityInfo.activityId; tempInfoModel.ActivitySate = activityInfo.activityStatus == 2; tempInfoModel.ActivityTitle = activityInfo.theme; //AntSdkContact_User user = AntSdkService.AntSdkListContactsEntity.users.Find(c => c.userId == activityInfo.userId); if (!string.IsNullOrEmpty(activityInfo.picture)) { var index = activityInfo.picture.LastIndexOf("/", StringComparison.Ordinal) + 1; var fileNameIndex = activityInfo.picture.LastIndexOf(".", StringComparison.Ordinal); var fileName = activityInfo.picture.Substring(index, fileNameIndex - index); string strUrl = activityInfo.picture.Replace(fileName, fileName + "_80x80"); try { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new System.Uri(strUrl); image.DecodePixelWidth = 800; image.EndInit(); //image.Freeze(); tempInfoModel.ActivityThemePicture = image; } catch (Exception e) { LogHelper.WriteError("[ActivityListViewModel_ImageOnLoad]:" + e.Message + e.StackTrace + e.Source); } } tempInfoModel.ActivityAddress = activityInfo.address; tempInfoModel.CreatedActivityDate = activityInfo.createTime; if (!string.IsNullOrEmpty(activityInfo.startTime)) { tempInfoModel.ActivityDate = Convert.ToDateTime(activityInfo.startTime).ToString("yyyy-MM-dd HH:mm"); } _activityInfoList.Add(tempInfoModel); } _isFirst = datas.isFirstPage; _isLast = datas.isLastPage; IsPaging = !_isLast; } else { IsActivityData = true; IsPaging = false; } }); }
/// <summary> /// 分页查询投票数据 /// </summary> private void LoadVotesData() { AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { var errCode = 0; var errMsg = string.Empty; AntSdkGetGroupActivitysInput intput = new AntSdkGetGroupActivitysInput { groupId = _groupId, activityStatus = 0, pageNum = _page, pageSize = _size, userId = AntSdkService.AntSdkCurrentUserInfo.userId }; var activityList = AntSdkService.GetGroupActivitys(intput, ref errCode, ref errMsg); return(activityList); }, (ex, datas) => { ActivityInfoList.Clear(); if (datas?.list != null && datas.list.Count > 0) { foreach (var activityInfo in datas.list) { var tempInfoModel = new ActivityInfoModel(); tempInfoModel.IsHaveActivity = activityInfo.voteFlag; if (activityInfo.userId == AntSdkService.AntSdkCurrentUserInfo.userId) { tempInfoModel.IsbtnDeleteVisibility = true; } tempInfoModel.ActivityId = activityInfo.activityId; tempInfoModel.ActivitySate = activityInfo.activityStatus == 2; tempInfoModel.ActivityTitle = activityInfo.theme; AntSdkContact_User user = AntSdkService.AntSdkListContactsEntity.users.Find(c => c.userId == activityInfo.userId); if (user != null) { if (!string.IsNullOrEmpty(activityInfo.picture)) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new System.Uri(activityInfo.picture); image.DecodePixelWidth = 800; image.EndInit(); image.Freeze(); tempInfoModel.ActivityThemePicture = image; } tempInfoModel.ActivityAddress = activityInfo.address; tempInfoModel.CreatedActivityDate = activityInfo.createTime; if (!string.IsNullOrEmpty(activityInfo.startTime)) { tempInfoModel.ActivityDate = Convert.ToDateTime(activityInfo.startTime).ToString("yyyy-MM-dd HH:mm"); } } //tempInfoModel.UserHeadUrl= _activityInfoList.Add(tempInfoModel); } } if (datas != null) { _isFirst = datas.isFirstPage; _isLast = datas.isLastPage; } }); }
/// <summary> /// 分页查询投票数据 /// </summary> private void LoadVotesData() { DateTime serverDateTime = DateTime.Now; AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { var errCode = 0; var errMsg = string.Empty; AntSdkQuerySystemDateOuput serverResult = AntSdkService.AntSdkGetCurrentSysTime(ref errCode, ref errMsg); if (serverResult != null) { serverDateTime = PublicTalkMothed.ConvertStringToDateTime(serverResult.systemCurrentTime); } var voteList = AntSdkService.GetGroupVotes(_groupId, ref errCode, ref errMsg, _page, _size, AntSdkService.AntSdkCurrentUserInfo.userId); return(voteList); }, (ex, datas) => { VoteInfoList.Clear(); if (datas?.content != null && datas.content.Count > 0) { foreach (var voteInfo in datas.content) { var tempInfoModel = new VoteInfoModel(); tempInfoModel.IsHaveVoted = voteInfo.voted; if (voteInfo.createdBy == AntSdkService.AntSdkCurrentUserInfo.userId) { tempInfoModel.IsbtnDeleteVisibility = true; } tempInfoModel.VoteId = voteInfo.id; tempInfoModel.VoteSate = DateTime.Compare(Convert.ToDateTime(voteInfo.expiryTime), serverDateTime) < 0; tempInfoModel.VoteTitle = voteInfo.title + (voteInfo.secret ? "(匿名)" : ""); tempInfoModel.UserID = voteInfo.createdBy; AntSdkContact_User user = AntSdkService.AntSdkListContactsEntity.users.Find(c => c.userId == voteInfo.createdBy); if (user != null) { tempInfoModel.Explain = user.userNum + user.userName + " 编辑于 " + DataConverter.FormatTimeByCreateTime(voteInfo.createdDate); if (!string.IsNullOrWhiteSpace(user.picture) && publicMethod.IsUrlRegex(user.picture)) { var userImage = GlobalVariable.ContactHeadImage.UserHeadImages.FirstOrDefault( m => m.UserID == user.userId); tempInfoModel.UserHeadUrl = string.IsNullOrEmpty(userImage?.Url) ? user.picture : userImage.Url; } else { tempInfoModel.UserHeadUrl = GlobalVariable.DefaultImage.UserHeadDefaultImage; } } //tempInfoModel.UserHeadUrl= _voteInfoList.Add(tempInfoModel); } } if (datas != null) { _isFirst = datas.first; _isLast = datas.last; } }); }
/// <summary> /// 加载活动参与者 /// </summary> private void LoadActivityParticipators() { AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { var errCode = 0; var errMsg = string.Empty; AntSdkGetGroupActivityParticipatorInput participatorInput = new AntSdkGetGroupActivityParticipatorInput { groupId = _groupId, activityId = _activityId, pageNum = pageNum, pageSize = pageSize }; try { return(AntSdkService.GetGroupActivityParticipators(participatorInput, ref errCode, ref errMsg)); } catch (Exception ex) { LogHelper.WriteError("活动参与者接口异常:" + ex.Message + ex.Source + ex.StackTrace); return(null); } }, (ex, datas) => { if (datas == null) { return; } if (datas.list.Count > 0) { ActivityParticipators.Clear(); foreach (var participatorInfo in datas.list) { AntSdkContact_User contactUser = AntSdkService.AntSdkListContactsEntity.users.Find( c => c.userId == participatorInfo.userId); var activityParticipatorInfo = new ActivityParticipator(); if (contactUser != null) { activityParticipatorInfo.ParticipatorId = contactUser.userId; activityParticipatorInfo.ParticipatorName = contactUser.userNum + contactUser.userName; if (!string.IsNullOrWhiteSpace(contactUser.picture) && publicMethod.IsUrlRegex(contactUser.picture)) { var userImage = GlobalVariable.ContactHeadImage.UserHeadImages.FirstOrDefault( m => m.UserID == contactUser.userId); activityParticipatorInfo.ParticipatorHeadPic = string.IsNullOrEmpty(userImage?.Url) ? contactUser.picture : userImage.Url; } else { activityParticipatorInfo.ParticipatorHeadPic = GlobalVariable.DefaultImage.UserHeadDefaultImage; } } else { activityParticipatorInfo.ParticipatorId = participatorInfo.userId; activityParticipatorInfo.ParticipatorHeadPic = !string.IsNullOrEmpty(participatorInfo.picture) ? participatorInfo.picture : GlobalVariable.DefaultImage.UserHeadDefaultImage; activityParticipatorInfo.ParticipatorName = participatorInfo.userNum + participatorInfo.userName; } ActivityParticipators.Add(activityParticipatorInfo); } ParticipatorsCount = ActivityParticipators.Count; } }); }
public ActivityDetailsViewModel(int activityId, string groupId) { _activityId = activityId; _groupId = groupId; var errCode = 0; var errMsg = string.Empty; DateTime serverDateTime = DateTime.Now; AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { AntSdkGetGroupActivityDetailsInput input = new AntSdkGetGroupActivityDetailsInput { userId = AntSdkService.AntSdkCurrentUserInfo.userId, activityId = activityId, groupId = groupId }; AntSdkQuerySystemDateOuput serverResult = AntSdkService.AntSdkGetCurrentSysTime(ref errCode, ref errMsg); if (serverResult != null) { serverDateTime = PublicTalkMothed.ConvertStringToDateTime(serverResult.systemCurrentTime); } var output = AntSdkService.GetActivityInfo(input, ref errCode, ref errMsg); return(output); }, (ex, datas) => { if (datas != null) { ActivityTitle = datas.theme; if (!string.IsNullOrEmpty(datas.picture)) { try { BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new System.Uri(datas.picture); image.DecodePixelWidth = 800; image.EndInit(); ActivityThemePic = image; } catch (Exception e) { LogHelper.WriteError("[ActivityDetailsViewModel_ImageOnLoad]:" + e.Message + e.StackTrace + e.Source); } } ActivityAddress = datas.address; ActivityIntroduce = datas.description; latitude = datas.latitude; longitude = datas.longitude; Console.Out.WriteLine(""); var startTime = DateTime.Now; var endTime = DateTime.Now.AddMinutes(30); if (!string.IsNullOrEmpty(datas.startTime) && !string.IsNullOrEmpty(datas.endTime)) { startTime = Convert.ToDateTime(datas.startTime); endTime = Convert.ToDateTime(datas.endTime); TimeSpan timeSpan = endTime - startTime; if (endTime.Year - startTime.Year == 0 && endTime.Day - startTime.Day == 0) { ActivityDateTime = startTime.ToString("yyyy-MM-dd HH:mm") + "-" + endTime.ToString("HH:mm"); } else { ActivityDateTime = startTime.ToString("yyyy-MM-dd HH:mm") + " " + endTime.ToString("yyyy-MM-dd HH:mm"); } } else { ActivityDateTime = startTime.ToString("yyyy-MM-dd HH:mm") + "-" + endTime.ToString("HH:mm"); } ParticipatorsCount = datas.voteCount ?? 0; if (datas.activityStatus == 1) { if (!datas.voteFlag) { if (DateTime.Compare(startTime, serverDateTime) <= 0) { ActivityStateContent = "已开始"; IsParticipatedActivity = false; } else { ActivityStateContent = "报名参加"; IsParticipatedActivity = true; } } else { ActivityStateContent = "已报名"; IsParticipatedActivity = false; } } else { ActivityStateContent = "已结束"; IsParticipatedActivity = false; } LoadActivityParticipators(); } }); }
/// <summary> /// 加载历史登录用户 /// </summary> public void LoadHistoryUsers() { AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { var task = SDKClient.SDKClient.Instance.GetAccountListDESC(); // var task = await SDKClient.SDKClient.Instance.GetAccountListDESC(); //var task = await SDKClient.SDKClient.Instance.GetAccountListDESC(); if (task == null || task.Result.Count == 0) { //this.SetStackPanelVisibility?.Invoke(); return(null); } return(task.Result); }, (ex, data) => { if (data == null || data.Count == 0) { IsQuickLogin = false; ChangeLoginAccount(null); return; } var tempData = data.Where(m => !string.IsNullOrEmpty(m.token)).OrderByDescending(m => m.lastlastLoginTime).ToList(); if (tempData.Count > 0) { historyAccountDB = tempData[0]; if (historyAccountDB.FirstLoginTime != null && DateTime.Now.Day - historyAccountDB.FirstLoginTime.Value.Day <= 7) { IsQuickLogin = true; } else { IsQuickLogin = false; ChangeLoginAccount(null); return; } } else { IsQuickLogin = false; ChangeLoginAccount(null); return; } IsQuickLogin = true; //foreach (var item in data) //{ UserModel user = new UserModel(); user.PhoneNumber = historyAccountDB.loginId; user.HeadImg = IMClient.Helper.ImageHelper.GetAccountFace(historyAccountDB.headPic, (s) => App.Current.Dispatcher.Invoke(() => user.HeadImg = s)); user.HeadImgMD5 = historyAccountDB.headPic; user.DisplayName = historyAccountDB.userName; LoginUser login = new LoginUser(user); if (historyAccountDB.loginModel != SDKClient.Model.LoginMode.None) { if (historyAccountDB.lastlastLoginTime.HasValue) { var interval = DateTime.Now - historyAccountDB.lastlastLoginTime.Value; if (interval.TotalDays < 30) { login.IsSavePassword = !string.IsNullOrEmpty(historyAccountDB.password) && !string.IsNullOrEmpty(historyAccountDB.loginId); login.Password = historyAccountDB.password; } else { login.IsSavePassword = false; login.Password = string.Empty; App.Current.Dispatcher.BeginInvoke(new Action(() => { this.HistoryUsers.Remove(login); })); } } else { } } App.Current.Dispatcher.BeginInvoke(new Action(() => { this.HistoryUsers.Add(login); if (this.SelectedLogin == null) { this.SetStackPanelVisibility?.Invoke(); this.SelectedLogin = this.HistoryUsers.FirstOrDefault(); } })); //} }); }
/// <summary> /// 获取服务器考勤记录 /// </summary> public void GetServicePunchClocksData(bool isNewRecord = false) { if (isNewRecord) { _isLast = false; } if (_isLast) { return; } AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () => { if (isNewRecord) { timer?.Stop(); timer = null; _page = 0; todayAttendanceRecords = null; } _page++; var errorCode = 0; var errorMsg = string.Empty; var punchClocksOutput = AntSdkService.GetPunchClocks(AntSdkService.AntSdkLoginOutput.userId, _page, _size, ref errorCode, ref errorMsg); return(punchClocksOutput); }, (ex, datas) => { if (isNewRecord) { AttendanceRecords.Clear(); } if (datas != null && datas.list.Count > 0) { var serverDateTime = PublicTalkMothed.ConvertStringToDateTime(datas.systemTime); var punchClocksOutputList = datas.list.OrderByDescending(m => m.attendId); foreach (var punchClocks in datas.list) { var exitAttendanceRecord = AttendanceRecords.FirstOrDefault(m => m.AttendId == punchClocks.attendId); if (exitAttendanceRecord != null) { continue; } var attendanceRecord = new AttendanceRecord(); attendanceRecord.AttendId = punchClocks.attendId; attendanceRecord.VerifyState = punchClocks.status; attendanceRecord.PuncherTimeStamp = punchClocks.attendTime; if (attendanceRecord.VerifyState == 0) { attendanceRecord.IsbtnVerify = true; attendanceRecord.VerifyDescribe = "待验证"; } else if (attendanceRecord.VerifyState == 1) { attendanceRecord.VerifyDescribe = "验证过期"; } else if (attendanceRecord.VerifyState == 2) { attendanceRecord.VerifyDescribe = "打卡成功"; } var diffMinute = serverDateTime - PublicTalkMothed.ConvertStringToDateTime(punchClocks.attendTime); if ((diffMinute.Days > 0 || diffMinute.TotalMinutes > 20) && attendanceRecord.VerifyState == 0) { attendanceRecord.IsbtnVerify = false; attendanceRecord.VerifyDescribe = "验证过期"; attendanceRecord.VerifyState = 1; } if (!string.IsNullOrEmpty(punchClocks.attendTime)) { attendanceRecord.PuncherDateTime = PublicTalkMothed.ConvertStringToDateTime(punchClocks.attendTime); } else { attendanceRecord.PuncherDateTime = DateTime.Now; } attendanceRecord.PuncherAddress = punchClocks.address; if (attendanceRecord.PuncherDateTime.Year - DateTime.Now.Year > 0) { attendanceRecord.PuncherDate = attendanceRecord.PuncherDateTime.ToString("yyyy年MM月dd日"); } else { attendanceRecord.PuncherDate = attendanceRecord.PuncherDateTime.ToString("MM月dd日"); } attendanceRecord.PuncherTime = attendanceRecord.PuncherDateTime.ToString("HH:mm"); AttendanceRecords.Insert(0, attendanceRecord); } _isFirst = datas.isFirstPage; _isLast = datas.isLastPage; var tempAttendanceRecord = AttendanceRecords.FirstOrDefault(m => m.IsbtnVerify); if (tempAttendanceRecord != null) { LoadData(tempAttendanceRecord); } } else { } }); }