Inheritance: BaseModel
        private static ScheduledToastNotification GenerateAlarmNotification(MyRemind remind)
        {
            ToastContent content = new ToastContent()
            {
                Scenario = ToastScenario.Alarm,

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                                            {
                                                new AdaptiveText()
                                                {
                                                    Text = $"提醒: {remind.Title}"
                                                },

                                                new AdaptiveText()
                                                {
                                                    Text = remind.Content
                                                }
                                            }
                    }
                },
                Actions = new ToastActionsSnoozeAndDismiss()//自动创建一个自动本地化的有延迟提醒时间间隔,贪睡和取消的按钮,贪睡时间由系统自动处理
            };
            return new ScheduledToastNotification(content.GetXml(), remind.time)
            {
                Tag = GetTag(remind)
            };

        }
        public static async Task<string> AddAllRemind(MyRemind remind, TimeSpan beforeTime)
        {
            id = "";
            for (int i = 0; i < App.selectedWeekNumList.Count; i++)
            {

                for (int r = 0; r < 6; r++)
                {
                    for (int c = 0; c < 7; c++)
                    {
                        if (App.timeSet[r, c].IsCheck)
                        {
                            remind.time = App.selectedWeekNumList[i].WeekNumOfMonday.AddDays(c) + App.timeSet[r, c].Time - beforeTime;
                            if (remind.time < DateTime.Now.ToUniversalTime())
                            {

                            }
                            else
                            {
                                await AddRemind(remind);
                            }

                        }
                    }
                }
            }
            return id;
        }
 public static string GetTag(MyRemind remind)
 {
     string temp = remind.Id_system.GetHashCode().ToString();
     id += temp + ",";
     // Tag needs to be 16 chars or less, so hash the Id
     return temp;
 }
        private static void addNotification(MyRemind remind)
        {

            ScheduledToastNotification scheduledNotifi = GenerateAlarmNotification(remind);

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledNotifi);
        }
 public static async Task AddRemind(MyRemind remind)
 {
     remind.Id_system = Guid.NewGuid();
     await Task.Run(delegate
     {
         addNotification(remind);
     });
 }
        public static async void DeleteRemindItem(string tag)
        {
            using (var conn = new SQLiteConnection(new SQLitePlatformWinRT(), App.RemindListDBPath))
            {
                var list = conn.Table<RemindListDB>();
                var array = list.Where(i => i.Id_system.Equals(tag));
                PasswordCredential user = GetCredential.getCredential("ZSCY");
                string stuNum, idNum;
                stuNum = user.UserName;
                idNum = user.Password;
                foreach (var item in array)
                {
                    MyRemind remind = new MyRemind()
                    {
                        StuNum = stuNum,
                        Id = item.Id,
                        IdNum = idNum
                    };

                    await NetWork.httpRequest(ApiUri.deleteRemindApi, NetWork.deleteRemind(remind));
                }
                list.Delete(i => i.Id_system.Equals(tag));
            }
            string[] TagArray = tag.Split(',');
            var notifier = ToastNotificationManager.CreateToastNotifier();

            for (int i = 0; i < TagArray.Count(); i++)
            {
                var scheduledNotifs = notifier.GetScheduledToastNotifications()
              .Where(n => n.Tag.Equals(TagArray[i]));

                // Remove all of those from the schedule
                foreach (var n in scheduledNotifs)
                {
                    notifier.RemoveFromSchedule(n);
                }
            }
        }
        private async void SaveEditRemind_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (TitleTextBox.Text == "")
            {
                new ErrorNotification("标题不能为空").Show();
                return;

            }
            else
            {
                if (SelectedTimeTextBlock.Text == "")
                {
                    new ErrorNotification("请选择提醒时间").Show();
                    return;
                }
                else
                {
                    if (SelectedWeekNumTextBlock.Text == "")
                    {
                        new ErrorNotification("请选择提醒周数").Show();
                        return;
                    }
                    else
                    {
                        if (SelectedRemindTextBlock.Text == "")
                        {
                            new ErrorNotification("请选择提前时间").Show();
                            return;
                        }
                        else
                        {
                            string resource = "ZSCY";
                            PasswordCredential userCredential = GetCredential.getCredential(resource);
                            string stuNum, idNum;
                            stuNum = userCredential.UserName;
                            idNum = userCredential.Password;
                            Debug.WriteLine("{0},{1}", stuNum, idNum);
                            MyRemind myRemind = new MyRemind();
                            myRemind.DateItems = new List<DateItemModel>();
                            myRemind.Id = tempID;
                            for (int i = 0; i < 7; i++)
                            {
                                for (int j = 0; j < 6; j++)
                                    if (App.timeSet[j, i].IsCheck)
                                    {
                                        //dateItem.Class += j.ToString() + ",";
                                        //dateItem.Day += i.ToString() + ",";
                                        DateItemModel dateItem = new DateItemModel();

                                        dateItem.Class = j.ToString();
                                        dateItem.Day = i.ToString();
                                        for (int k = 0; k < App.selectedWeekNumList.Count; k++)
                                        {
                                            dateItem.Week += App.selectedWeekNumList[k].WeekNum + ",";
                                        }
                                        dateItem.Week = dateItem.Week.Remove(dateItem.Week.Length - 1);
                                        myRemind.DateItems.Add(dateItem);
                                    }
                            }
                            if (SelRemindListView.SelectedIndex == 0)
                            {
                                myRemind.Time = null;
                            }
                            else
                            {

                                myRemind.Time = beforeTime[SelRemindListView.SelectedIndex].BeforeTime.TotalMinutes.ToString();
                            }
                            myRemind.Title = TitleTextBox.Text;
                            myRemind.Content = ContentTextBox.Text;
                            string databaseJson = JsonConvert.SerializeObject(myRemind);
                            myRemind.IdNum = idNum;
                            myRemind.StuNum = stuNum;

                            try
                            {
                                string content = await NetWork.httpRequest(ApiUri.editRemindApi, NetWork.editRemind(myRemind));
                            }
                            catch
                            {
                                Debug.WriteLine("网络问题请求失败");
                            }
                            string id_system = "";
                            RemindListDB temp = new RemindListDB();
                            if (beforeTime[SelRemindListView.SelectedIndex].isRemind)
                            {
                                TimeSpan time = beforeTime[SelRemindListView.SelectedIndex].BeforeTime;
                                //设置通知
                                 temp = DatabaseMethod.ToModel(myRemind.Id);
                                string[] TagArray = temp.Id_system.Split(',');
                                var notifier = ToastNotificationManager.CreateToastNotifier();

                                for (int i = 0; i < TagArray.Count(); i++)
                                {
                                    var scheduledNotifs = notifier.GetScheduledToastNotifications()
                                  .Where(n => n.Tag.Equals(TagArray[i]));

                                    // Remove all of those from the schedule
                                    foreach (var n in scheduledNotifs)
                                    {
                                        notifier.RemoveFromSchedule(n);
                                    }
                                }
                                //重新添加
                                id_system = await RemindHelp.AddAllRemind(myRemind, time);
                            }
                            else
                            {

                            }
                            DatabaseMethod.EditDatabase(temp.Num,myRemind.Id, databaseJson, id_system);
                            DatabaseMethod.ReadDatabase(Visibility.Visible);
                            App.isLoad = false;
                            App.selectedWeekNumList.Clear();
                        }
                    }
                }
            }
            this.NavigationCacheMode = NavigationCacheMode.Disabled;
            this.Visibility = Visibility.Collapsed;
        }
 private void RewriteRemindGridButton_Tapped(object sender, TappedRoutedEventArgs e)
 {
     int i = RemindListView.SelectedIndex;
     isSave = true;
     MyRemind remind = new MyRemind();
     remind = App.remindList[i];
     App.isLoad = false;
     ListGrid2.Visibility = Visibility.Visible;
     Frame2.Navigate(typeof(EditRemindPage), remind);
 }
        public static async void SyncRemind()
        {
            List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();
            PasswordCredential user = GetCredential.getCredential("ZSCY");
            paramList.Add(new KeyValuePair<string, string>("stuNum", user.UserName));
            paramList.Add(new KeyValuePair<string, string>("idNum", user.Password));
            string content = "";
            try
            {
                content = await NetWork.httpRequest(ApiUri.getRemindApi, paramList);
            }
            catch
            {

                Debug.WriteLine("网络问题请求失败");
            }
            //相当于MyRemind
            GetRemindModel getRemid = JsonConvert.DeserializeObject<GetRemindModel>(content);

            try
            {

                getRemid = await JsonConvert.DeserializeObjectAsync<GetRemindModel>(content);
            }
            catch (Exception e)
            {
                Debug.Write(e);
            }
            List<string> getRemindList_json = new List<string>();
            List<MyRemind> remindList = new List<MyRemind>();
            #region 返回的json格式和添加的风格不一样,转换
            foreach (var item in getRemid.DataItems)
            {
                //getRemindList_json.Add(getRemid.DataItems[0].Id.ToString());
                MyRemind mr = new MyRemind();
                List<DateItemModel> dim = new List<DateItemModel>();
                //每个MyRemind的date
                foreach (var itemData in item.DateItems)
                {
                    DateItemModel dateitme = new DateItemModel();
                    string week = "";
                    foreach (var itemWeek in itemData.WeekItems)
                    {
                        week += itemWeek + ",";
                    }
                    week = week.Remove(week.Length - 1);
                    dateitme.Class = itemData.Class.ToString();
                    dateitme.Day = itemData.Day.ToString();
                    dateitme.Week = week;
                    dim.Add(dateitme);
                }
                mr.Title = item.Title;
                mr.Content = item.Content;
                mr.DateItems = dim;
                mr.Time = item.Time;
                mr.Id = item.Id.ToString();
                remindList.Add(mr);

            }
            #endregion
            List<string> RemindTagList = new List<string>();
            RemindTagList = DatabaseMethod.ClearRemindItem() as List<string>;
            var notifier = ToastNotificationManager.CreateToastNotifier();
            if (RemindTagList != null)
            {

                for (int i = 0; i < RemindTagList.Count(); i++)
                {
                    var scheduledNotifs = notifier.GetScheduledToastNotifications()
                  .Where(n => n.Tag.Equals(RemindTagList[i]));

                    // Remove all of those from the schedule
                    foreach (var n in scheduledNotifs)
                    {
                        notifier.RemoveFromSchedule(n);
                    }
                }
            }

            foreach (var remindItem in remindList)
            {
                string id = await SyncAllRemind(remindItem);
                DatabaseMethod.ToDatabase(remindItem.Id, JsonConvert.SerializeObject(remindItem), id);
            }
            DatabaseMethod.ReadDatabase(Windows.UI.Xaml.Visibility.Collapsed);
        }
        public static async Task<string> SyncAllRemind(MyRemind remind)
        {

            id = "";
            if (remind.Time != null)
            {
                int min = int.Parse(remind.Time) % 60;
                int hour = int.Parse(remind.Time) / 60;
                int day = hour / 24;
                TimeSpan beforeTime = new TimeSpan(day, hour, min, 0);


                List<SelectedWeekNum> weeklist = new List<SelectedWeekNum>();
                foreach (var item in remind.DateItems)
                {
                    var itemWeekList = item.Week.Split(',');
                    var itemClassList = int.Parse(item.Class);
                    var itemDayList = int.Parse(item.Day);
                    TimeSet classTime = new TimeSet();
                    classTime.Set(itemClassList);
                    for (int i = 0; i < itemWeekList.Count(); i++)
                    {
                        SelectedWeekNum swn = new SelectedWeekNum();
                        //TODO 周数是是从第一周开始所以week设置要减一
                        swn.SetWeekTime(int.Parse(itemWeekList[i]) - 1);
                        remind.time = swn.WeekNumOfMonday.AddDays(itemDayList) + classTime.Time - beforeTime;
                        if (remind.time.Ticks < DateTime.Now.Ticks)
                        {

                        }
                        else
                        {
                            await AddRemind(remind);
                        }
                    }
                }
            }
            return id;
        }
 public static string ToJson(MyRemind myRemind)
 {
     string json;
     json = JsonConvert.SerializeObject(myRemind);
     return json;
 }
 public static List<KeyValuePair<string, string>> deleteRemind(MyRemind myRemind)
 {
     List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();
     paramList.Add(new KeyValuePair<string, string>("stuNum", myRemind.StuNum));
     paramList.Add(new KeyValuePair<string, string>("idNum", myRemind.IdNum));
     paramList.Add(new KeyValuePair<string, string>("id", myRemind.Id));
     return paramList;
 }
 public static List<KeyValuePair<string, string>> editRemind(MyRemind myRemind)
 {
     List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();
     paramList.Add(new KeyValuePair<string, string>("stuNum", myRemind.StuNum));
     paramList.Add(new KeyValuePair<string, string>("idNum", myRemind.IdNum));
     paramList.Add(new KeyValuePair<string, string>("id", myRemind.Id));
     string dataJson = JsonConvert.SerializeObject(myRemind.DateItems);
     //dataJson = dataJson.Remove(0);//删掉第一个{
     //dataJson = dataJson.Remove(dataJson.Length - 1);//删掉最后一个}
     //string date = "[";
     //string _class = "";
     //string day = "";
     //for (int i = 0; i < myRemind.DateItems.Count; i++)
     //{
     //    string dateJson = JsonConvert.SerializeObject(myRemind.DateItems[i]);
     //    date += $"{dateJson},";
     //    //day = myRemind.DateItems[i].Day + ",";
     //    //_class = myRemind.DateItems[i].Class + ",";
     //}
     //day=day.Remove(day.Length - 1);
     //_class=_class.Remove(_class.Length - 1);
     //date = date.Remove(date.Length - 1) + "]";
     //paramList.Add(new KeyValuePair<string, string>("week", myRemind.DateItems[0].Week));
     //paramList.Add(new KeyValuePair<string, string>("class", _class));
     //paramList.Add(new KeyValuePair<string, string>("day", day));
     paramList.Add(new KeyValuePair<string, string>("data", dataJson));
     paramList.Add(new KeyValuePair<string, string>("title", myRemind.Title));
     paramList.Add(new KeyValuePair<string, string>("time", myRemind.Time));
     paramList.Add(new KeyValuePair<string, string>("content", myRemind.Content));
     return paramList;
 }
        public static List<KeyValuePair<string, string>> addRemind(MyRemind myRemind)
        {
            List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();
            paramList.Add(new KeyValuePair<string, string>("stuNum", myRemind.StuNum));
            paramList.Add(new KeyValuePair<string, string>("idNum", myRemind.IdNum));
            string date = "[";

            for (int i = 0; i < myRemind.DateItems.Count; i++)
            {
                string dateJson = JsonConvert.SerializeObject(myRemind.DateItems[i]);
                date += $"{dateJson},";
            }
            date = date.Remove(date.Length - 1) + "]";

            paramList.Add(new KeyValuePair<string, string>("date", date));
            paramList.Add(new KeyValuePair<string, string>("title", myRemind.Title));
            paramList.Add(new KeyValuePair<string, string>("time", myRemind.Time));
            paramList.Add(new KeyValuePair<string, string>("content", myRemind.Content));
            return paramList;
        }
        //private void EditRemindPage_BackRequested(object sender, BackRequestedEventArgs e)
        //{
        //    if (SelRemindGrid.Visibility == Visibility.Visible)
        //    {
        //        SelRemindGrid.Visibility = Visibility.Visible;
        //        SystemNavigationManager.GetForCurrentView().BackRequested -= EditRemindPage_BackRequested ;
        //        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
        //    }
        //    else
        //    {
        //        this.NavigationCacheMode = NavigationCacheMode.Disabled;
        //        this.Visibility = Visibility.Collapsed;
        //        SystemNavigationManager.GetForCurrentView().BackRequested -= EditRemindPage_BackRequested; 
        //        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
        //    }
        //}

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter != null && !App.isLoad)
            {
                App.isLoad = true;
                App.SelectedTime.SelTimeString = "";
                App.selectedWeek.WeekNumString = "";

                MyRemind temp = new MyRemind();
                temp = e.Parameter as MyRemind;
                tempID = temp.Id;
                int x = 0;
                for (int i = 0; i < beforeTime.Count; i++)
                {
                    if (temp.Time != null)
                    {

                        if (beforeTime[i].getBeforeTime() == int.Parse(temp.Time))
                        {
                            x = i;
                            break;
                        }
                    }
                    else
                        x = 0;
                }
                SelRemindListView.SelectedIndex = indexBefore = x;
                TitleTextBox.Text = temp.Title;

                ContentTextBox.Text = temp.Content;
                string s = temp.DateItems[0].Week;
                App.selectedWeek.WeekNumString = s + ",";
                string[] weekArray = s.Split(',');
                for (int i = 0; i < weekArray.Count(); i++)
                {
                    SelectedWeekNum wNum = new SelectedWeekNum()
                    {
                        WeekNum = int.Parse(weekArray[i])
                    };
                    wNum.SetWeekTime(int.Parse(weekArray[i]));
                    App.selectedWeekNumList.Add(wNum);
                }
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        App.timeSet[i, j] = new TimeSet();
                    }
                }
                foreach (var item in temp.DateItems)
                {
                    App.timeSet[int.Parse(item.Class), int.Parse(item.Day)].IsCheck = true;
                    App.SelectedTime.SelTimeString += CourseList(int.Parse(item.Class), int.Parse(item.Day)) + " ";
                }
            }

        }
        private async void SaveEditRemind_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (TitleTextBox.Text == "")
            {
                new ErrorNotification("标题不能为空").Show();
                return;

            }
            else
            {
                if (SelectedTimeTextBlock.Text == "")
                {
                    new ErrorNotification("请选择提醒时间").Show();
                    return;
                }
                else
                {
                    if (SelectedWeekNumTextBlock.Text == "")
                    {
                        new ErrorNotification("请选择提醒周数").Show();
                        return;
                    }
                    else
                    {
                        if (SelectedRemindTextBlock.Text == "")
                        {
                            new ErrorNotification("请选择提前时间").Show();
                            return;
                        }
                        else
                        {
                            string resource = "ZSCY";
                            PasswordCredential userCredential = GetCredential.getCredential(resource);
                            string stuNum, idNum;
                            stuNum = userCredential.UserName;
                            idNum = userCredential.Password;
                            Debug.WriteLine("{0},{1}", stuNum, idNum);
                            MyRemind myRemind = new MyRemind();
                            myRemind.DateItems = new List<DateItemModel>();
                            for (int i = 0; i < 7; i++)
                            {
                                for (int j = 0; j < 6; j++)
                                    if (App.timeSet[j, i].IsCheck)
                                    {
                                        //dateItem.Class += j.ToString() + ",";
                                        //dateItem.Day += i.ToString() + ",";
                                        DateItemModel dateItem = new DateItemModel();

                                        dateItem.Class = j.ToString();
                                        dateItem.Day = i.ToString();
                                        for (int k = 0; k < App.selectedWeekNumList.Count; k++)
                                        {
                                            dateItem.Week += App.selectedWeekNumList[k].WeekNum + ",";
                                        }
                                        dateItem.Week = dateItem.Week.Remove(dateItem.Week.Length - 1);
                                        myRemind.DateItems.Add(dateItem);
                                    }
                            }
                            myRemind.Time = beforeTime[SelRemindListView.SelectedIndex].BeforeTime.TotalMinutes.ToString();
                            myRemind.Title = TitleTextBox.Text;
                            myRemind.Content = ContentTextBox.Text;

                            myRemind.IdNum = idNum;
                            myRemind.StuNum = stuNum;
                            try
                            {
                                AddRemindReturn returnStatus = new AddRemindReturn();
                                //string content = await NetWork.getHttpWebRequest(ApiUri.addRemindApi, NetWork.addRemind(myRemind), 0, true);
                                string content = await NetWork.httpRequest(ApiUri.addRemindApi, NetWork.addRemind(myRemind));
                                returnStatus = JsonConvert.DeserializeObject<AddRemindReturn>(content);
                                myRemind.Id = returnStatus.Id;
                            }
                            catch
                            {

                            }
                            string id_system = "";
                            if (beforeTime[SelRemindListView.SelectedIndex].isRemind)
                            {
                                TimeSpan time = beforeTime[SelRemindListView.SelectedIndex].BeforeTime;
                                //设置通知
                                id_system = await RemindHelp.AddAllRemind(myRemind, time);
                            }
                            else
                            {

                            }
                            myRemind.IdNum = "";
                            myRemind.StuNum = "";
                            string databaseJson = JsonConvert.SerializeObject(myRemind);
                            DatabaseMethod.ToDatabase(myRemind.Id, databaseJson, id_system);
                        }
                    }
                }
            }

            Initialization();
        }
        private static string ClassMixDay(ref MyRemind remind)
        {
            string temp = "";
            for (int i = 0; i < remind.DateItems.Count; i++)
            {
                temp += ConvertDay(int.Parse(remind.DateItems[i].Day)) + ConvertClass(int.Parse(remind.DateItems[i].Class)) + "节、";
            }

            temp = temp.Remove(temp.Length - 1);
            return temp;
        }