Ejemplo n.º 1
0
        public static async Task DeleteDatabaseAsync()
        {
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\Data.db");
            await conn.DropTableAsync <Course>();

            await conn.DropTableAsync <Term>();

            await conn.DropTableAsync <Exam>();

            await conn.DropTableAsync <Lesson>();

            Term.ClearData();
            Exam.ClearData();
            WeekDay.ClearData();
        }
Ejemplo n.º 2
0
        public static async Task <bool> UpdateDataAsync()
        {
            bool      updated   = false;
            WebHelper webHelper = new WebHelper();

            if (await webHelper.getAllData())
            {
                SQLiteAsyncConnection conn = new SQLiteAsyncConnection(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\Data.db");
                await conn.DropTableAsync <Term>();

                await conn.DropTableAsync <Lesson>();

                await conn.DropTableAsync <Exam>();   //删除之前的数据

                await conn.DropTableAsync <Course>(); //不提示成绩更新情况下,直接删除成绩

                await conn.CreateTablesAsync <Course, Term, Lesson, Exam>();

                await conn.InsertAllAsync(webHelper.Exams);//update exams;

                await conn.InsertAllAsync(webHelper.Terms);

                await conn.InsertAllAsync(webHelper.Lessons);

                await conn.InsertAllAsync(webHelper.Courses);

                Term.ClearData();
                Exam.ClearData();
                WeekDay.ClearData();

                updated = true;
            }

            return(updated);
            ////区分有无成绩更新,方便后续扩展出成绩提示
            //var previousCourses = terms.SelectMany(term => term.Courses);

            //var updateCourses = from course in webHelper.Courses
            //                    let previousCourse = from tempCourse in previousCourses
            //                                         where tempCourse.CourseName == course.CourseName &&
            //                                         tempCourse.TermNumber == course.TermNumber &&
            //                                         (tempCourse.GradePoints != course.GradePoints | tempCourse.MakeUpExamGrades != course.MakeUpExamGrades)
            //                                         select tempCourse
            //                    where previousCourse.Any()
            //                    select course;

            //var newCourses = from course in webHelper.Courses
            //                 let previousCourse = from tempCourse in previousCourses
            //                                      where tempCourse.CourseName == course.CourseName &&
            //                                      tempCourse.TermNumber == course.TermNumber
            //                                      select tempCourse
            //                 where !previousCourse.Any()
            //                 select course;

            //var updatedCourse = updateCourses.ToList();
            // var newcourses = newCourses.ToList();
            //if (updateCourses.Any() | newCourses.Any())
            //{
            //    try
            //    {
            //        await conn.InsertAllAsync(newCourses);
            //        await conn.UpdateAllAsync(updateCourses);

            //    }
            //    catch (Exception)
            //    {
            //        await conn.DropTableAsync<Course>();
            //        var message = new Windows.UI.Popups.MessageDialog("更新本地数据出错,建议或重试,或进入设置删除本地账号和数据或重启应用后再导入");
            //        await message.ShowAsync();
            //    }
            //    updated = true;
            //}
        }