Beispiel #1
0
        //預載上一個月和下一個月
        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);
                        }
                    });
                });
            }
        }
Beispiel #2
0
        //
        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));
            }
        }