//預載上一個月和下一個月 private void PreLoadLastNextMonth() { //小於0為沒有Cache //等於0為Cache不會過期 //大於0為多少分鐘後清掉Cache if (this.CacheMinuteTTL >= 0) { Task.Factory.StartNew(() => { GetUserData.AsyncPOST(UserID, UserPWD, MeetingListDate.AddMonths(-1) , (userObj1, dateTime1) => { try { PreLoadLastNextMonthDict[dateTime1] = userObj1; GetUserData.AsyncPOST(UserID, UserPWD, MeetingListDate.AddMonths(1) , (userObj2, dateTime2) => { try { PreLoadLastNextMonthDict[dateTime2] = userObj2; } catch (Exception ex) { LogTool.Debug(ex); } }); if (this.CacheMinuteTTL > 0) { if (CacheThread != null) { CacheThread.Abort(); } CacheThread = new Thread(delegate() { Thread.Sleep(this.CacheMinuteTTL * 60 * 1000); PreLoadLastNextMonthDict.Clear(); }); CacheThread.IsBackground = true; CacheThread.Start(); } } catch (Exception ex) { LogTool.Debug(ex); } }); }); } }
// private void btnLastNext_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { SV.ScrollToVerticalOffset(1); Image img = sender as Image; if (img.Name.Equals("btnLast")) { MeetingListDate = MeetingListDate.AddMonths(-1); } else { MeetingListDate = MeetingListDate.AddMonths(1); } // 非同步POST方法 MouseTool.ShowLoading(); //檢查是否有網路連線 Network.HttpRequest hr = new Network.HttpRequest(); if (NetworkTool.CheckNetwork() > 0) { Task.Factory.StartNew(() => { //無快取機制 //GetUserData.AsyncPOST(UserID, UserPWD // , MeetingListDate // , (userObj, dateTime) => GetUserData_DoAction(userObj, dateTime)); //有快取機制 if (PreLoadLastNextMonthDict.ContainsKey(MeetingListDate) == true) { GetUserData_DoAction(PreLoadLastNextMonthDict[MeetingListDate], MeetingListDate); //預載上一個月和下一個月 PreLoadLastNextMonth(); } else { GetUserData.AsyncPOST(UserID, UserPWD , MeetingListDate , (userObj, dateTime) => { GetUserData_DoAction(userObj, dateTime); //預載上一個月和下一個月 PreLoadLastNextMonth(); }); } }); //}).ContinueWith(task => //{ // //預載上一個月 // //Thread.Sleep(100); // //GetUserData.AsyncPOST(UserID, UserPWD // // , MeetingListDate.AddMonths(-1) // // , (userObj, dateTime) => { LastNextDict[dateTime] = userObj; }); //}).ContinueWith(task => //{ // //預載下一個月 // //Thread.Sleep(100); // //GetUserData.AsyncPOST(UserID, UserPWD // // , MeetingListDate.AddMonths(1) // // , (userObj, dateTime) => { LastNextDict[dateTime] = userObj; }); //}); } else { //DB查詢日期 DataTable dt = MSCE.GetDataTable("select UserJson from UserData where UserID =@1 and ListDate=@2" , UserID , DateTool.MonthFirstDate(MeetingListDate).ToString("yyyyMMdd")); User user = new User(); if (dt.Rows.Count > 0) { user = JsonConvert.DeserializeObject <User>(dt.Rows[0]["UserJson"].ToString()); } else { dt = MSCE.GetDataTable("select top 1 UserJson from UserData where UserID =@1" , UserID); if (dt.Rows.Count > 0) { user = JsonConvert.DeserializeObject <User>(dt.Rows[0]["UserJson"].ToString()); } user.MeetingList = new UserMeeting[0]; } GetUserData_DoAction(user, MeetingListDate); } //, () => { this.Dispatcher.BeginInvoke(new Action(() => { AutoClosingMessageBox.Show("無法取得資料,請稍後再試"); })); }); #region 步POST方法 //User user=GetUserData.POST(UserID, UserPWD, // DateTool.MonthFirstDate(MeetingListDate).ToString("yyyyMMdd"), // DateTool.MonthLastDate(MeetingListDate).ToString("yyyyMMdd")); //if (user != null) //{ // if (user.MeetingList.Length < 1) // txtNothing.Visibility = Visibility.Visible; // InitUI(user.MeetingList, MeetingListDate); // // 會議列表的上下一頁不要複寫Buton的JSON了 // // HomeUserButtonAryJSON = JsonConvert.SerializeObject(user.EnableButtonList); //} //else //{ // AutoClosingMessageBox.Show("無法取得資料,請稍後再試"); //} #endregion // 先做UI,再把按鈕的JSON存下來 string SQL = @"update NowLogin Set MeetingListDate=@1"; //,HomeUserButtonAryJSON=@2 int success = MSCE.ExecuteNonQuery(SQL, MeetingListDate.ToString("yyyy/MM/dd")); //, HomeUserButtonAryJSON); if (success < 1) { LogTool.Debug(new Exception(@"DB失敗: " + SQL)); } }
private void GetNewMeeting_DoAction(string dataString) { // 先判斷是否要invoke if (this.Dispatcher.CheckAccess() == false) { // 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。 this.Dispatcher.BeginInvoke(new Action <string>(GetNewMeeting_DoAction), dataString); } else { try { string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String; XDocument xml = null; string State = ""; try { xml = XDocument.Parse(dataString); State = xml.Element("User").Attribute("State").Value.Trim(); } catch (Exception ex) { LogTool.Debug(ex); } switch (State) { case "0": string NewAddMeetingID = xml.Element("User").Element("MeetingData").Attribute("ID").Value.Trim(); string BeginTime = xml.Element("User").Element("MeetingData").Attribute("BeginTime").Value.Trim(); DateTime date = DateTime.Now; bool IsValid = DateTime.TryParse(BeginTime, out date); if (IsValid == false) { date = DateTime.Now; } // 先做UI,再把按鈕的JSON存下來 //string SQL = @"update NowLogin Set MeetingListDate=@1,NewAddMeetingID=@2";//,HomeUserButtonAryJSON=@2 //int success = MSCE.ExecuteNonQuery(SQL, date.ToString("yyyy/MM/dd"),NewAddMeetingID);//, HomeUserButtonAryJSON); //if (success < 1) // LogTool.Debug(new Exception(@"DB失敗: " + SQL)); this.NewAddMeetingID = NewAddMeetingID; // 非同步POST方法 MouseTool.ShowLoading(); //GetUserData.AsyncPOST(UserID, UserPWD // , date // , (userObj, dateTime) => GetUserData_DoAction(userObj, dateTime)); if (NetworkTool.CheckNetwork() > 0) { GetUserData.AsyncPOST(UserID, UserPWD , date , (userObj, dateTime) => GetUserData_DoAction(userObj, dateTime)); } else { //DB查詢日期 DataTable dt = MSCE.GetDataTable("select UserJson from UserData where UserID =@1 and ListDate=@2" , UserID , DateTool.MonthFirstDate(MeetingListDate).ToString("yyyyMMdd")); User user = new User(); if (dt.Rows.Count > 0) { user = JsonConvert.DeserializeObject <User>(dt.Rows[0]["UserJson"].ToString()); } else { dt = MSCE.GetDataTable("select top 1 UserJson from UserData where UserID =@1" , UserID); if (dt.Rows.Count > 0) { user = JsonConvert.DeserializeObject <User>(dt.Rows[0]["UserJson"].ToString()); } user.MeetingList = new UserMeeting[0]; } GetUserData_DoAction(user, MeetingListDate); } AutoClosingMessageBox.Show(string.Format("成功加入{0}", CourseOrMeeting_String)); //重整列表 break; case "1": //AutoClosingMessageBox.Show(string.Format("該機關非{0}人員", CourseOrMeeting_String)); AutoClosingMessageBox.Show(string.Format("本{0}未邀請貴機關單位參與", CourseOrMeeting_String)); //AutoClosingMessageBox.Show("該機關非與會人員"); break; case "2": AutoClosingMessageBox.Show("已加入過"); break; case "3": AutoClosingMessageBox.Show(string.Format("{0}不存在", CourseOrMeeting_String)); break; case "4": AutoClosingMessageBox.Show(string.Format("{0}尚未發佈", CourseOrMeeting_String)); break; case "5": AutoClosingMessageBox.Show("無此使用者"); break; case "6": AutoClosingMessageBox.Show("加入失敗"); break; case "7": AutoClosingMessageBox.Show("機密會議"); break; case "8": AutoClosingMessageBox.Show("會議已取消"); break; default: AutoClosingMessageBox.Show("新增錯誤,請聯絡系統管理人員"); break; } } catch (Exception ex) { AutoClosingMessageBox.Show("新增錯誤,請聯絡系統管理人員"); LogTool.Debug(ex); } txtPinCode.Text = ""; MouseTool.ShowArrow(); } }