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 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();
        }
예제 #3
0
        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);
        }