示例#1
0
        //清除所有课程信息
        private async void Delete_all_Toggled(object sender, RoutedEventArgs e)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile   XmlFileInLocal;

            //读xml文件数据
            XmlFileInLocal = await folder.GetFileAsync("class");

            Stream XmlReader = await XmlFileInLocal.OpenStreamForReadAsync();

            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.Load(XmlReader);
            XmlReader.Dispose();
            if (Delete_all.IsOn == true)
            {
                foreach (var element in XmlDoc.DocumentElement)
                {
                    XmlElement each_element = (XmlElement)element;
                    foreach (var InnerElement in each_element)
                    {
                        XmlElement each_InnerElement = (XmlElement)InnerElement;
                        each_InnerElement.SetAttribute("finished", "1");
                    }
                }
            }
            else
            {
                foreach (var element in XmlDoc.DocumentElement)
                {
                    XmlElement each_element = (XmlElement)element;
                    foreach (var InnerElement in each_element)
                    {
                        XmlElement each_InnerElement = (XmlElement)InnerElement;
                        each_InnerElement.SetAttribute("finished", "1");
                    }
                }
            }
            ////保存xml到local
            StorageFile xml = await folder.CreateFileAsync("class", CreationCollisionOption.ReplaceExisting);

            Stream fileWriter = await xml.OpenStreamForWriteAsync();

            XmlDoc.Save(fileWriter);
            fileWriter.Dispose();


            //显示消息框
            await new MessageDialog("清除完成").ShowAsync();
            Delete_all.IsOn = true;
            Frame.Navigate(typeof(MainPage));
        }
示例#2
0
        private async void delete_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Button btn = (Button)sender;

            string[] index = (string[])btn.Tag;

            var day        = index[0];
            var classindex = index[1];

            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile   XmlFileInLocal;

            //读xml文件数据
            XmlFileInLocal = await folder.GetFileAsync("class");

            Stream XmlReader = await XmlFileInLocal.OpenStreamForReadAsync();

            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.Load(XmlReader);
            XmlReader.Dispose();

            foreach (var element in XmlDoc.DocumentElement)
            {
                XmlElement each_element = (XmlElement)element;
                if (each_element.Name == day)
                {
                    foreach (var InnerElement in each_element)
                    {
                        XmlElement each_InnerElement = (XmlElement)InnerElement;
                        if (each_InnerElement.GetAttribute("index") == classindex)
                        {
                            each_InnerElement.SetAttribute("finished", "1");
                        }
                    }
                }
            }

            ////保存xml到local
            StorageFile xml = await folder.CreateFileAsync("class", CreationCollisionOption.ReplaceExisting);

            Stream fileWriter = await xml.OpenStreamForWriteAsync();

            XmlDoc.Save(fileWriter);
            fileWriter.Dispose();


            Monday.Clear(); Tuesday.Clear(); Thursday.Clear(); Wednesday.Clear(); Friday.Clear(); Saturday.Clear(); Sunday.Clear();
            initialize();
        }
示例#3
0
        ////保存
        private async void save_Click(object sender, RoutedEventArgs e)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile   XmlFileInLocal;

            //读现有xml到内存
            XmlFileInLocal = await folder.GetFileAsync("class");

            Stream XmlReader = await XmlFileInLocal.OpenStreamForReadAsync();

            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.Load(XmlReader);
            XmlReader.Dispose();
            //修改内存中xml
            foreach (var element in XmlDoc.DocumentElement)
            {
                XmlElement each_element = (XmlElement)element;
                if (each_element.Name == day)
                {
                    foreach (var InnerElement in each_element)
                    {
                        XmlElement each_InnerElement = (XmlElement)InnerElement;
                        if (each_InnerElement.GetAttribute("index") == classindex)
                        {
                            //Debug.WriteLine(acourse.class_name_property+"#######################");
                            each_InnerElement.SetAttribute("name", acourse.class_name_property);
                            each_InnerElement.SetAttribute("duration", acourse.class_duration_property);
                            each_InnerElement.SetAttribute("type", acourse.class_type_property.ToString());
                            each_InnerElement.SetAttribute("room", acourse.class_room_property);
                            each_InnerElement.SetAttribute("score", acourse.class_score_property);
                            each_InnerElement.SetAttribute("teacher", acourse.class_teacher_property);
                            each_InnerElement.SetAttribute("weeklimit", acourse.class_weeklimit_property.ToString());
                            each_InnerElement.SetAttribute("finished", "0");

                            string st = start_time.Time.ToString().Remove(start_time.Time.ToString().Length - 3, 3);
                            string et = end_time.Time.ToString().Remove(end_time.Time.ToString().Length - 3, 3);

                            each_InnerElement.SetAttribute("startTime", st);
                            each_InnerElement.SetAttribute("endTime", et);

                            //Debug.WriteLine(each_InnerElement.GetAttribute("name") + "!!!!!");
                        }
                    }
                }
                else
                {
                    foreach (var InnerElement in each_element)
                    {
                        XmlElement each_InnerElement = (XmlElement)InnerElement;
                        if (each_InnerElement.GetAttribute("index") == classindex)
                        {
                            string st = start_time.Time.ToString().Remove(start_time.Time.ToString().Length - 3, 3);
                            string et = end_time.Time.ToString().Remove(end_time.Time.ToString().Length - 3, 3);

                            each_InnerElement.SetAttribute("startTime", st);
                            each_InnerElement.SetAttribute("endTime", et);

                            //Debug.WriteLine(each_InnerElement.GetAttribute("name") + "!!!!!");
                        }
                    }
                }
            }

            ////保存xml到local
            StorageFile xml = await folder.CreateFileAsync("class", CreationCollisionOption.ReplaceExisting);

            Stream fileWriter = await xml.OpenStreamForWriteAsync();

            XmlDoc.Save(fileWriter);
            fileWriter.Dispose();

            Frame.GoBack();
        }
示例#4
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            //导航传来参数
            string[] index = (string[])e.Parameter;
            day        = index[0];
            classindex = index[1];

            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile   XmlFileInLocal;

            //读xml文件数据
            XmlFileInLocal = await folder.GetFileAsync("class");

            Stream XmlReader = await XmlFileInLocal.OpenStreamForReadAsync();

            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.Load(XmlReader);
            XmlReader.Dispose();

            foreach (var element in XmlDoc.DocumentElement)
            {
                XmlElement each_element = (XmlElement)element;
                if (each_element.Name == day)
                {
                    foreach (var InnerElement in each_element)
                    {
                        XmlElement each_InnerElement = (XmlElement)InnerElement;
                        if (each_InnerElement.GetAttribute("index") == classindex)
                        {
                            acourse.class_name_property      = each_InnerElement.GetAttribute("name");
                            acourse.class_duration_property  = each_InnerElement.GetAttribute("duration");
                            acourse.class_score_property     = each_InnerElement.GetAttribute("score");
                            acourse.class_type_property      = Convert.ToInt32(each_InnerElement.GetAttribute("type"));
                            acourse.class_room_property      = each_InnerElement.GetAttribute("room");
                            acourse.class_teacher_property   = each_InnerElement.GetAttribute("teacher");
                            acourse.class_weeklimit_property = Convert.ToInt32(each_InnerElement.GetAttribute("weeklimit"));
                            //将课程属性绑定到整个grid元素

                            acourse.class_startTime = each_InnerElement.GetAttribute("startTime");
                            acourse.class_endTime   = each_InnerElement.GetAttribute("endTime");


                            var start_hour   = acourse.class_startTime.Substring(0, 2);
                            var start_minute = acourse.class_startTime.Substring(3, 2);

                            var end_hour   = acourse.class_endTime.Substring(0, 2);
                            var end_minute = acourse.class_endTime.Substring(3, 2);

                            try
                            {
                                acourse.startTime = new TimeSpan(Convert.ToInt32(start_hour), Convert.ToInt32(start_minute), 0);
                                acourse.endTime   = new TimeSpan(Convert.ToInt32(end_hour), Convert.ToInt32(end_minute), 0);
                            }
                            catch (Exception)
                            {
                            }

                            MainGrid.DataContext = acourse;
                        }
                    }
                }
            }
        }
示例#5
0
        //数据读取初始化
        async void initialize()
        {
            switch (DateTime.Now.DayOfWeek.ToString())
            {
            case "Monday":
                dayofweek.Text = "星期一" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;

            case "Tuesday":
                dayofweek.Text = "星期二" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;

            case "Wednesday":
                dayofweek.Text = "星期三" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;

            case "Thursday":
                dayofweek.Text = "星期四" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;

            case "Friday":
                dayofweek.Text = "星期五" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;

            case "Saturday":
                dayofweek.Text = "星期六" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;

            case "Sunday":
                dayofweek.Text = "星期天" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
                break;
            }


            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile   XmlFileInApp, XmlFileInLocal;

            //如果本地文件夹内不存在xml记录,复制安装包内xml过去
            if (await folder.TryGetItemAsync("class") == null)
            {
                //获取安装包内xml
                XmlFileInApp = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///data\class.xml"));

                Stream XmlReader = await XmlFileInApp.OpenStreamForReadAsync();

                //读取xml到内存
                XmlDocument xml = new XmlDocument();
                xml.Load(XmlReader);
                //在本地新建xml文件
                XmlFileInLocal = await folder.CreateFileAsync("class", CreationCollisionOption.ReplaceExisting);

                //保存xml文件到local
                Stream XmlWriter = await XmlFileInLocal.OpenStreamForWriteAsync();

                xml.Save(XmlWriter);
                XmlWriter.Dispose();
            }
            //读xml文件
            XmlFileInLocal = await folder.GetFileAsync("class");

            Stream XmlReader1 = await XmlFileInLocal.OpenStreamForReadAsync();

            XmlDocument XmlDoc = new XmlDocument();

            XmlDoc.Load(XmlReader1);

            foreach (var element in XmlDoc.DocumentElement)
            {
                XmlElement each_element = (XmlElement)element;
                //Debug.WriteLine(each_element.Name);

                foreach (var InnerElement in each_element)
                {
                    XmlElement each_InnerElement = (XmlElement)InnerElement;
                    //Debug.WriteLine(each_InnerElement.Name);//Debug.WriteLine(each_InnerElement.GetAttribute("duration"));
                    Course acourse = new Course();
                    acourse.class_name_property     = each_InnerElement.GetAttribute("name");
                    acourse.class_index_property[0] = each_element.Name;
                    acourse.class_index_property[1] = each_InnerElement.GetAttribute("index");
                    acourse.class_duration_property = each_InnerElement.GetAttribute("duration");
                    acourse.class_startTime         = each_InnerElement.GetAttribute("startTime");
                    acourse.class_endTime           = each_InnerElement.GetAttribute("endTime");
                    acourse.class_room_property     = each_InnerElement.GetAttribute("room");
                    acourse.class_score_property    = each_InnerElement.GetAttribute("score");
                    acourse.class_teacher_property  = each_InnerElement.GetAttribute("teacher");
                    acourse.class_type_property     = Convert.ToInt32(each_InnerElement.GetAttribute("type"));

                    switch (acourse.class_type_property)
                    {
                    case 0:
                        acourse.class_tag_property = "必修";
                        break;

                    case 1:
                        acourse.class_tag_property = "选修";
                        break;

                    case 2:
                        acourse.class_tag_property = "旁听";
                        break;

                    case 3:
                        acourse.class_tag_property = "专业课";
                        break;

                    case 4:
                        acourse.class_tag_property = "非学分绩";
                        break;

                    case 5:
                        acourse.class_tag_property = "学分绩";
                        break;
                    }


                    acourse.class_weeklimit_property = Convert.ToInt32(each_InnerElement.GetAttribute("weeklimit"));
                    acourse.class_finished_property  = each_InnerElement.GetAttribute("finished");
                    //Debug.WriteLine(acourse.class_index_property);
                    switch (each_element.Name)
                    {
                    case "Monday":
                        Monday.Add(acourse);
                        break;

                    case "Tuesday":
                        Tuesday.Add(acourse);
                        break;

                    case "Wednesday":
                        Wednesday.Add(acourse);
                        break;

                    case "Thursday":
                        Thursday.Add(acourse);
                        break;

                    case "Friday":
                        Friday.Add(acourse);
                        break;

                    case "Saturday":
                        Saturday.Add(acourse);
                        break;

                    case "Sunday":
                        Sunday.Add(acourse);
                        break;
                    }
                }

                day1.DataContext = Monday;
                day2.DataContext = Tuesday;
                day3.DataContext = Wednesday;
                day4.DataContext = Thursday;
                day5.DataContext = Friday;
                day6.DataContext = Saturday;
                day7.DataContext = Sunday;
            }
        }