private async void AddDialog4_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { try { if (SCSnoTB.Text != "" && SCCnoTB.Text != "" && ScoreTB.Text != "") { conn.Insert(new SC() { Sno = SCSnoTB.Text, Cno = SCCnoTB.Text, Score = Convert.ToDouble(ScoreTB.Text) }); PopupNotice popupNotice = new PopupNotice("添加成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } } catch (SQLiteException) { MessageDialog AboutDialog = new MessageDialog("违反了约束条件!", "提示"); await AboutDialog.ShowAsync(); } catch (FormatException) { MessageDialog AboutDialog = new MessageDialog("信息格式出现错误!", "提示"); await AboutDialog.ShowAsync(); } }
private async void QueryBtn3_Click(object sender, RoutedEventArgs e) { if (QueryCno.Text != "") { var datalist = conn.Query <Course>("select *from Course where Cno = ?", QueryCno.Text); if (datalist.Count != 0) { CouViewModel.CourseDatas.Clear(); foreach (var item in datalist) { CouViewModel.CourseDatas.Add(new CourseData() { Cname = "课程名:" + item.Cname, Cno = "课程号:" + item.Cno, Tno = "任课老师工号:" + item.Tno, Credit = "学分:" + item.Credit }); } QueryDialog3.Hide(); PopupNotice popupNotice = new PopupNotice("查找成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("该课程不存在!", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("请输入待查询课程的课程号!", "提示"); await AboutDialog.ShowAsync(); } }
private async void AddDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { try { if (SnameTB.Text != "" && SnoTB.Text != "" && _sex != "" && AgeTB.Text != "" && Spassword.Text != "") { conn.Insert(new Student() { Sname = SnameTB.Text, Sno = SnoTB.Text, Sex = _sex, Age = Convert.ToInt32(AgeTB.Text), Password = Spassword.Text }); PopupNotice popupNotice = new PopupNotice("添加成功"); popupNotice.ShowAPopup(); RefreshStuList(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } } catch { MessageDialog AboutDialog = new MessageDialog("该学生已存在!", "提示"); await AboutDialog.ShowAsync(); } }
private async void QueryBtn2_Click(object sender, RoutedEventArgs e) { if (QueryTno.Text != "") { var datalist = conn.Query <Teacher>("select *from Teacher where Tno = ?", QueryTno.Text); if (datalist.Count != 0) { TeaViewModel.TeacherDatas.Clear(); foreach (var item in datalist) { TeaViewModel.TeacherDatas.Add(new TeacherData() { Tname = "姓名:" + item.Tname, Tno = "工号:" + item.Tno, JobTitle = "职称:" + item.JobTitle, Salary = "年龄:" + item.Salary }); } QueryDialog2.Hide(); PopupNotice popupNotice = new PopupNotice("查找成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("该教师不存在!", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("请输入待查询教师的工号!", "提示"); await AboutDialog.ShowAsync(); } }
private async void UpdatePasswordDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (OldPasswordTB.Text != "" && NewPasswordTB.Text != "" && ConfirmNewPasswordTB.Text != "") { var _password = conn.ExecuteScalar <string>("select Password from Student where Sno = ?", Login.Current.UserName.Text); if (OldPasswordTB.Text == _password) { if (NewPasswordTB.Text == ConfirmNewPasswordTB.Text) { conn.Execute("update Student set Password = ? where Sno = ?", NewPasswordTB.Text, Login.Current.UserName.Text); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("新密码两次输入不一致!", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("原密码错误!", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } }
private async void AddDialog2_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { try { if (TnoTB.Text != "" && TnameTB.Text != "" && JobTitleTB.Text != "" && SalaryTB.Text != "") { conn.Insert(new Teacher() { Tname = TnameTB.Text, Tno = TnoTB.Text, JobTitle = JobTitleTB.Text, Salary = Convert.ToDouble(SalaryTB.Text) }); PopupNotice popupNotice = new PopupNotice("添加成功"); popupNotice.ShowAPopup(); RefreshTeaList(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } } catch (FormatException) { MessageDialog AboutDialog = new MessageDialog("信息格式出现错误!", "提示"); await AboutDialog.ShowAsync(); } catch { MessageDialog AboutDialog = new MessageDialog("该教师已存在!", "提示"); await AboutDialog.ShowAsync(); } }
private async void QueryBtn_Click(object sender, RoutedEventArgs e) { if (QuerySno.Text != "") { var datalist = conn.Query <Student>("select *from Student where Sno = ?", QuerySno.Text); if (datalist.Count != 0) { StuViewModel.StudentDatas.Clear(); foreach (var item in datalist) { StuViewModel.StudentDatas.Add(new StudentData() { Sname = "姓名:" + item.Sname, Sno = "学号:" + item.Sno, Sex = "性别:" + item.Sex, Age = "年龄:" + item.Age.ToString(), Password = "******" + item.Password }); } QueryDialog.Hide(); PopupNotice popupNotice = new PopupNotice("查找成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("该学生不存在!", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("请输入待查询学生的学号!", "提示"); await AboutDialog.ShowAsync(); } }
private async void QueryBtn4_Click(object sender, RoutedEventArgs e) { if (QuerySCSno.Text != "" && QuerySCCno.Text != "") { var datalist = conn.Query <SC>("select *from SC where Sno = ? and Cno = ?", QuerySCSno.Text, QuerySCCno.Text); if (datalist.Count != 0) { SCViewModel.SCDatas.Clear(); foreach (var item in datalist) { SCViewModel.SCDatas.Add(new SCData() { Sno = "学号:" + item.Sno, Cno = "课程号:" + item.Cno, Score = "成绩:" + item.Score }); } QueryDialog4.Hide(); PopupNotice popupNotice = new PopupNotice("查找成功"); popupNotice.ShowAPopup(); SCList.IsChecked = true; } else { MessageDialog AboutDialog = new MessageDialog("未找到成绩!", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("请输入待查询学生的学号!", "提示"); await AboutDialog.ShowAsync(); } }
private void DeleteBtn4_Click(object sender, RoutedEventArgs e) { conn.Execute("delete from SC where Sno = ? and Cno = ?", SCItem.Sno.Substring(3), SCItem.Cno.Substring(4)); SCViewModel.SCDatas.Remove(SCItem); DeleteDialog4.Hide(); PopupNotice popupNotice = new PopupNotice("删除成功"); popupNotice.ShowAPopup(); }
private void DeleteBtn3_Click(object sender, RoutedEventArgs e) { conn.Execute("delete from Course where Cno = ?", CourseItem.Cno.Substring(4)); CouViewModel.CourseDatas.Remove(CourseItem); DeleteDialog3.Hide(); PopupNotice popupNotice = new PopupNotice("删除成功"); popupNotice.ShowAPopup(); }
private void DeleteBtn_Click(object sender, RoutedEventArgs e) { conn.Execute("delete from Student where Sno = ?", StudentItem.Sno.Substring(3)); StuViewModel.StudentDatas.Remove(StudentItem); DeleteDialog.Hide(); PopupNotice popupNotice = new PopupNotice("删除成功"); popupNotice.ShowAPopup(); }
public void UseCloudData() { var result = GetCloudTaskData(); try { JArray localTaskArray = (JArray)JsonConvert.DeserializeObject(result); List <TaskJson> taskJsons = new List <TaskJson>(); PushData pushData = new PushData(); pushData.UserName = userName; pushData.Token = token; foreach (var item in localTaskArray) { TaskJson taskJson = new TaskJson { TaskId = item["TaskId"].ToString(), TaskName = item["TaskName"].ToString(), Date = item["Date"].ToString(), Star = item["Star"].ToString(), Done = item["Done"].ToString(), Remark = item["Remark"].ToString(), UpdateTime = item["UpdateTime"].ToString(), IsDelete = item["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = item["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } pushData.TaskList = taskJsons; string pushDataJsonStr = JsonConvert.SerializeObject(pushData); PushDataToLocal(pushDataJsonStr); } catch (Exception e) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步失败:" + e.Message); popupNotice.ShowAPopup(); }); } }
private void MainPage_OnLoaded(object sender, RoutedEventArgs e) { int m = ((MainPageViewModel)DataContext).JudgeState(); if (m == 0) { PopupNotice popupNotice = new PopupNotice("正在加载天气等信息,请稍等呢,亲!", 3000); popupNotice.ShowAPopup(); } ((MainPageViewModel)DataContext).ToFirstCommand.Execute(null); }
private async void UpdateButton_Click(object sender, RoutedEventArgs e) { string _event = AddEvent.Text.Trim(); _Event = _event; if (_Date != null && _event != "" && _Color != "" && _TintOpacity >= 0) { List <DataTemple> datalist = All.Current.conn.Query <DataTemple>("select * from DataTemple where Schedule_name = ?", All.Current.str1); try { All.Current.conn.Execute("delete from DataTemple where Schedule_name = ?", All.Current.str1); All.Current.conn.Insert(new DataTemple() { Schedule_name = _event, CalculatedDate = _Date, Date = _PickDate, BgColor = _Color, TintOpacity = _TintOpacity, IsTop = _isTop, AddTime = "" }); localSettings.Values[_event + _PickDate] = _tip; All.Current.NewTB.Visibility = Visibility.Collapsed; All.Current.NewTB2.Visibility = Visibility.Collapsed; } catch { MessageDialog AboutDialog = new MessageDialog("此日程已被添加,请勿重复添加~", "提示"); await AboutDialog.ShowAsync(); foreach (var item in datalist) { All.Current.conn.Insert(new DataTemple() { Schedule_name = item.Schedule_name, CalculatedDate = item.CalculatedDate, Date = item.Date, BgColor = item.BgColor, TintOpacity = item.TintOpacity, IsTop = "0", AddTime = "" }); } return; } bool isPinned = SecondaryTile.Exists(All.Current.str1); if (isPinned) { SecondaryTile toBeDeleted = new SecondaryTile(All.Current.str1); await toBeDeleted.RequestDeleteAsync(); } MainPage.Current.MyNav.SelectedItem = MainPage.Current.MyNav.MenuItems[0]; Frame.Navigate(typeof(All)); All.Current.LoadDateData(); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("请确保填入完整的信息!", "提示"); await AboutDialog.ShowAsync(); } }
private void DeleteBtn2_Click(object sender, RoutedEventArgs e) { // 手动SQL版(不能级联删除) // conn.Execute("delete from Teacher where Tno = ?", TeacherItem.Tno.Substring(3)); // ORM版 var teacher = conn.GetWithChildren <Teacher>(TeacherItem.Tno.Substring(3)); conn.Delete(teacher, recursive: true); TeaViewModel.TeacherDatas.Remove(TeacherItem); DeleteDialog2.Hide(); PopupNotice popupNotice = new PopupNotice("删除成功"); popupNotice.ShowAPopup(); }
private async void UpdateDialog3_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (CnameTB2.Text != "" && CnoTB2.Text != "" && CTnoTB2.Text != "" && CreditTB2.Text != "") { conn.Execute("update Course set Cname = ? where Cno = ?", CnameTB2.Text, CnoTB2.Text.Substring(4)); conn.Execute("update Course set Credit = ? where Cno = ?", CreditTB2.Text, CnoTB2.Text.Substring(4)); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); RefreshCouList(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } }
private async void UpdateDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (SNameTB2.Text != "" && SnoTB2.Text != "" && SexTB2.Text != "" && AgeTB2.Text != "") { conn.Execute("update Student set Sex = ? where Sno = ?", SexTB2.Text, SnoTB2.Text.Substring(3)); conn.Execute("update Student set Age = ? where Sno = ?", AgeTB2.Text, SnoTB2.Text.Substring(3)); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); Initialize(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } }
private void PushDataToCloud(string pushDataJsonStr) { try { HttpClient client = new HttpClient(); HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://msdate.monreeing.com:3000/data/pushdata/"); requestMessage.Content = new StringContent(pushDataJsonStr); requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.SendAsync(requestMessage).GetAwaiter().GetResult(); if (response.StatusCode.ToString() == "OK") { string str = response.Content.ReadAsStringAsync().Result.ToString(); JObject jo = JObject.Parse(str); string responseCode = jo["Code"].ToString(); string responseMsg = jo["Message"].ToString(); if (responseCode.Equals("0")) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步成功!"); popupNotice.ShowAPopup(); }); } else { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步失败:" + responseMsg); popupNotice.ShowAPopup(); }); } } else { } } catch (Exception e) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步失败:" + e.Message); popupNotice.ShowAPopup(); }); } }
private async void UpdateDialog2_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (TnameTB2.Text != "" && TnoTB2.Text != "" && JobTitleTB2.Text != "" && SalaryTB2.Text != "") { conn.Execute("update Teacher set Tname = ? where Tno = ?", TnameTB2.Text, TnoTB2.Text.Substring(3)); conn.Execute("update Teacher set JobTitle = ? where Tno = ?", JobTitleTB2.Text, TnoTB2.Text.Substring(3)); conn.Execute("update Teacher set Salary = ? where Tno = ?", SalaryTB2.Text, TnoTB2.Text.Substring(3)); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); RefreshTeaList(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } }
private async void UpdateDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (SnameTB2.Text != "" && SnoTB2.Text != "" && SexTB2 != null && AgeTB2.Text != "" && Spassword2.Text != "") { conn.Execute("update Student set Sname = ? where Sno = ?", SnameTB2.Text, SnoTB2.Text.Substring(3)); conn.Execute("update Student set Sex = ? where Sno = ?", SexTB2.SelectedItem.ToString(), SnoTB2.Text.Substring(3)); conn.Execute("update Student set Age = ? where Sno = ?", AgeTB2.Text, SnoTB2.Text.Substring(3)); conn.Execute("update Student set Password = ? where Sno = ?", Spassword2.Text, SnoTB2.Text.Substring(3)); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); RefreshStuList(); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } }
private async void LoginBtn_Click(object sender, RoutedEventArgs e) { if (StuBtn.IsChecked == true) { localSettings.Values["Sno"] = "1706300005"; localSettings.Values["StuPassword"] = "******"; if (localSettings.Values["Sno"].ToString().Equals(UserName.Text) && localSettings.Values["StuPassword"].Equals(UserPassword.Password)) { MainPage.Current.MyFrame.Navigate(typeof(StudentView)); PopupNotice popupNotice = new PopupNotice("登录成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("学号或密码错误!请重新输入。", "提示"); await AboutDialog.ShowAsync(); } } else { if (ManageBtn.IsChecked == true) { localSettings.Values["Mno"] = "1706300005"; localSettings.Values["ManagePassword"] = "******"; if (localSettings.Values["Mno"].ToString().Equals(UserName.Text) && localSettings.Values["ManagePassword"].Equals(UserPassword.Password)) { MainPage.Current.MyFrame.Navigate(typeof(ManagementView)); PopupNotice popupNotice = new PopupNotice("登录成功"); popupNotice.ShowAPopup(); } else { MessageDialog AboutDialog = new MessageDialog("管理员账号或密码错误!请重新输入。", "提示"); await AboutDialog.ShowAsync(); } } else { MessageDialog AboutDialog = new MessageDialog("请选择用户类型。", "提示"); await AboutDialog.ShowAsync(); } } }
private async void UpdateDialog4_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { if (SCScoreTB3.Text != "") { conn.Execute("update SC set Score = ? where Sno = ? and Cno = ?", SCScoreTB3.Text, SCSnoTB3.Text.Substring(3), SCCnoTB3.Text.Substring(4)); PopupNotice popupNotice = new PopupNotice("修改成功"); popupNotice.ShowAPopup(); SCViewModel.SCDatas.Clear(); SCViewModel.SCDatas.Add(new SCData() { Sno = SCSnoTB3.Text, Cno = SCCnoTB3.Text, Score = "成绩:" + SCScoreTB3.Text }); } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } }
private async void AddDialog3_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { try { if (CnoTB.Text != "" && CnameTB.Text != "" && CreditTB.Text != "") { var teacher = conn.Find <Teacher>(CTnoTB.Text); if (teacher != null) { var course = new Course() { Cname = CnameTB.Text, Cno = CnoTB.Text, Credit = Convert.ToDouble(CreditTB.Text), Teacher = teacher }; conn.InsertWithChildren(course); PopupNotice popupNotice = new PopupNotice("添加成功"); popupNotice.ShowAPopup(); RefreshCouList(); } else { throw SQLiteException.New(SQLite3.Result.Error, "教师不存,课之焉附?"); } } else { MessageDialog AboutDialog = new MessageDialog("请将信息填写完整!", "提示"); await AboutDialog.ShowAsync(); } } catch (SQLiteException) { MessageDialog AboutDialog = new MessageDialog("违反了约束条件!", "提示"); await AboutDialog.ShowAsync(); } catch (FormatException) { MessageDialog AboutDialog = new MessageDialog("信息格式出现错误!", "提示"); await AboutDialog.ShowAsync(); } }
private void PushDataToLocal(string pushDataJsonStr) { try { JObject userInfoJson = JObject.Parse(pushDataJsonStr); string taskListJsonStr = userInfoJson["TaskList"].ToString(); JArray taskListJson = (JArray)JsonConvert.DeserializeObject(taskListJsonStr); conn.BeginTransaction(); // 事务开始 foreach (var item in taskListJson) { string stepListJsonStr = item["TaskStepList"].ToString(); JArray stepListJson = (JArray)JsonConvert.DeserializeObject(stepListJsonStr); foreach (var subItem in stepListJson) { bool finish = false; if (subItem["Done"].ToString().Equals("1")) { finish = true; } List <ToDoTaskSteps> tempList0 = conn.Query <ToDoTaskSteps>("select * from ToDoTaskSteps where TaskId = ? and StepId = ?", item["TaskId"].ToString(), subItem["StepId"].ToString()); if (tempList0.Count == 0) { conn.Insert(new ToDoTaskSteps() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Finish = false, UnFinish = true, UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }); } else { conn.Execute("update ToDoTaskSteps set Content = ?, Finish = ?, UnFinish = ?, UpdateTime = ?, IsDelete = ? where TaskId = ? and StepId = ?", subItem["Content"].ToString(), finish, !finish, subItem["UpdateTime"].ToString(), subItem["IsDelete"].ToString(), subItem["TaskId"].ToString(), subItem["StepId"].ToString()); } } List <ToDoTasks> tempList1 = conn.Query <ToDoTasks>("select * from ToDoTasks where TaskId = ?", item["TaskId"].ToString()); if (tempList1.Count == 0) { conn.Insert(new ToDoTasks() { TaskId = item["TaskId"].ToString(), Name = item["TaskName"].ToString(), Date = item["Date"].ToString(), Star = item["Star"].ToString(), Remark = item["Remark"].ToString(), Done = item["Done"].ToString(), UpdateTime = item["UpdateTime"].ToString(), IsDelete = item["IsDelete"].ToString() }); } else { conn.Execute("update ToDoTasks set Name = ?, Date = ?, Star = ?, Remark = ?, Done = ?, UpdateTime = ?, IsDelete = ? where Name = ? and TaskId = ?", item["TaskName"].ToString(), item["Date"].ToString(), item["Star"].ToString(), item["Remark"].ToString(), item["Done"].ToString(), item["UpdateTime"].ToString(), item["IsDelete"].ToString(), item["TaskName"].ToString(), item["TaskId"].ToString()); } } conn.Commit(); // 事务结束 this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步成功!"); popupNotice.ShowAPopup(); }); } catch (Exception e) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步异常:" + e.Message); popupNotice.ShowAPopup(); }); } }
public void MergeData() { try { var localData = GetLocalTaskData(); var cloudData = GetCloudTaskData(); JArray cloudTaskArray = (JArray)JsonConvert.DeserializeObject(cloudData); JArray localTaskArray = (JArray)JsonConvert.DeserializeObject(localData); List <TaskJson> taskJsons = new List <TaskJson>(); PushData pushData = new PushData(); pushData.UserName = userName; pushData.Token = token; foreach (var cloudTaskItem in cloudTaskArray) { string taskId = cloudTaskItem["TaskId"].ToString(); List <ToDoTasks> tempList = conn.Query <ToDoTasks>("select * from ToDoTasks where TaskId = ?", taskId); if (tempList.Count == 0) { TaskJson taskJson = new TaskJson { TaskId = cloudTaskItem["TaskId"].ToString(), TaskName = cloudTaskItem["TaskName"].ToString(), Date = cloudTaskItem["Date"].ToString(), Star = cloudTaskItem["Star"].ToString(), Done = cloudTaskItem["Done"].ToString(), Remark = cloudTaskItem["Remark"].ToString(), UpdateTime = cloudTaskItem["UpdateTime"].ToString(), IsDelete = cloudTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = cloudTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } else { string localUpdateTimeStr = tempList[0].UpdateTime; string cloudUpdateTimeStr = cloudTaskItem["UpdateTime"].ToString(); DateTime localUpdateTime = Convert.ToDateTime(localUpdateTimeStr); DateTime cloudUpdateTime = Convert.ToDateTime(cloudUpdateTimeStr); if (cloudUpdateTime >= localUpdateTime) { TaskJson taskJson = new TaskJson { TaskId = cloudTaskItem["TaskId"].ToString(), TaskName = cloudTaskItem["TaskName"].ToString(), Date = cloudTaskItem["Date"].ToString(), Star = cloudTaskItem["Star"].ToString(), Done = cloudTaskItem["Done"].ToString(), Remark = cloudTaskItem["Remark"].ToString(), UpdateTime = cloudTaskItem["UpdateTime"].ToString(), IsDelete = cloudTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = cloudTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } else { TaskJson taskJson = new TaskJson { TaskId = tempList[0].TaskId, TaskName = tempList[0].Name, Date = tempList[0].Date, Star = tempList[0].Star, Done = tempList[0].Done, Remark = tempList[0].Remark, UpdateTime = tempList[0].UpdateTime, IsDelete = tempList[0].IsDelete }; List <StepJson> stepJsons = new List <StepJson>(); List <ToDoTaskSteps> subTempList = conn.Query <ToDoTaskSteps>("select * from ToDoTaskSteps where TaskId = ?", taskId); foreach (var subItem in subTempList) { StepJson stepJson = new StepJson() { TaskId = subItem.TaskId, StepId = subItem.StepId, Content = subItem.Content, UpdateTime = subItem.UpdateTime, IsDelete = subItem.IsDelete }; if (subItem.Finish) { stepJson.Done = "1"; } else { stepJson.Done = "0"; } stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } } } foreach (var localTaskItem in localTaskArray) { string taskId = localTaskItem["TaskId"].ToString(); foreach (var cloudTaskItem in cloudTaskArray) { bool isItemOnCloud = false; if (cloudTaskItem["TaskId"].ToString().Equals(taskId)) { isItemOnCloud = true; string localUpdateTimeStr = localTaskItem["UpdateTime"].ToString(); string cloudUpdateTimeStr = cloudTaskItem["UpdateTime"].ToString(); DateTime localUpdateTime = Convert.ToDateTime(localUpdateTimeStr); DateTime cloudUpdateTime = Convert.ToDateTime(cloudUpdateTimeStr); if (cloudUpdateTime >= localUpdateTime) { TaskJson taskJson = new TaskJson { TaskId = cloudTaskItem["TaskId"].ToString(), TaskName = cloudTaskItem["TaskName"].ToString(), Date = cloudTaskItem["Date"].ToString(), Star = cloudTaskItem["Star"].ToString(), Done = cloudTaskItem["Done"].ToString(), Remark = cloudTaskItem["Remark"].ToString(), UpdateTime = cloudTaskItem["UpdateTime"].ToString(), IsDelete = cloudTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = cloudTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } else { TaskJson taskJson = new TaskJson { TaskId = localTaskItem["TaskId"].ToString(), TaskName = localTaskItem["TaskName"].ToString(), Date = localTaskItem["Date"].ToString(), Star = localTaskItem["Star"].ToString(), Done = localTaskItem["Done"].ToString(), Remark = localTaskItem["Remark"].ToString(), UpdateTime = localTaskItem["UpdateTime"].ToString(), IsDelete = localTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = localTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } } if (!isItemOnCloud) { TaskJson taskJson = new TaskJson { TaskId = localTaskItem["TaskId"].ToString(), TaskName = localTaskItem["TaskName"].ToString(), Date = localTaskItem["Date"].ToString(), Star = localTaskItem["Star"].ToString(), Done = localTaskItem["Done"].ToString(), Remark = localTaskItem["Remark"].ToString(), UpdateTime = localTaskItem["UpdateTime"].ToString(), IsDelete = localTaskItem["IsDelete"].ToString() }; List <StepJson> stepJsons = new List <StepJson>(); string taskStepListStr = localTaskItem["TaskStepList"].ToString(); JArray localStepArray = (JArray)JsonConvert.DeserializeObject(taskStepListStr); foreach (var subItem in localStepArray) { StepJson stepJson = new StepJson() { TaskId = subItem["TaskId"].ToString(), StepId = subItem["StepId"].ToString(), Content = subItem["Content"].ToString(), Done = subItem["Done"].ToString(), UpdateTime = subItem["UpdateTime"].ToString(), IsDelete = subItem["IsDelete"].ToString() }; stepJsons.Add(stepJson); } taskJson.TaskStepList = stepJsons; taskJsons.Add(taskJson); } } } pushData.TaskList = taskJsons; string pushDataJsonStr = JsonConvert.SerializeObject(pushData); PushDataToLocal(pushDataJsonStr); PushDataToCloud(pushDataJsonStr); this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步成功!"); popupNotice.ShowAPopup(); }); } catch (Exception e) { this.Invoke(() => { PopupNotice popupNotice = new PopupNotice("同步失败:" + e.Message); popupNotice.ShowAPopup(); }); } }