Ejemplo n.º 1
0
        //右键删除课程(电脑)
        private async void btnCourse_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            e.Handled = true;

            try
            {
                Button btn = sender as Button;

                Match tagMatch = Regex.Match(btn.Tag.ToString(), @"\[(\d+?)\]\[(\d+?)\]");
                int   i        = int.Parse(tagMatch.Groups[1].Value);
                int   j        = int.Parse(tagMatch.Groups[2].Value);

                MessageDialog dialog = new MessageDialog("将要删除本节课,是吗?");
                dialog.Title = "温馨提示";
                dialog.Commands.Add(new UICommand("确定", async command =>
                {
                    CoursePage.Current.TipPanel.Visibility = Visibility.Visible;

                    await CourseDataService.DeleteCourse(weeklyList, i, j, weekOfTerm);

                    InitializeRootGrid(CoursePage.Current.CourseGrid);

                    CoursePage.Current.TipPanel.Visibility = Visibility.Collapsed;
                }));
                dialog.Commands.Add(new UICommand("取消"));

                await dialog.ShowAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            connection = ServiceTestHelper.GetDatabaseConnection();
            var logger = A.Fake <ILogger <CourseDataService> >();

            courseDataService = new CourseDataService(connection, logger);
        }
        protected override async Task OnInitializedAsync()
        {
            Roles = await RolesDataService.GetAllRolesAsync();

            Houses = await HouseDataService.GetAllHousesAsync();

            Courses = await CourseDataService.GetAllCoursesAsync();
        }
Ejemplo n.º 4
0
        public void Get_Course_Test()
        {
            //Arrange
            _service = new CourseDataService();

            //Act
            _service.GetCourses();

            //Assert

            Equals(_service.GetCourses());
        }
Ejemplo n.º 5
0
        //确认添加课程
        public async void btnAddConfirm_Click(object sender, RoutedEventArgs e)
        {
            var current = CoursePage.Current;

            if (string.IsNullOrEmpty(current.txtCourseName.Text) ||
                current.ComboDayOfWeek.SelectedIndex == -1 || current.ComboSelectedMode.SelectedIndex == -1 ||
                current.ComboCourseStart.SelectedIndex == -1 || current.ComboCourseEnd.SelectedIndex == -1 ||
                current.ComboWeekStart.SelectedIndex == -1 || current.ComboWeekEnd.SelectedIndex == -1)
            {
                await new MessageDialog("亲,带 * 的都是必填选项哟,先check一下下吧(●'◡'●)").ShowAsync();

                return;
            }

            Course course = new Course();

            course.FullName   = current.txtCourseName.Text;
            course.Classroom  = current.txtClassroom.Text;
            course.Teacher    = current.txtTeacher.Text;
            course.Credits    = current.txtCredit.Text;
            course.Classify   = current.txtClassify.Text;
            course.StartMark  = current.ComboCourseStart.SelectedIndex;
            course.CourseSpan = current.ComboCourseEnd.SelectedIndex - current.ComboCourseStart.SelectedIndex + 1;

            //处理UI及后台逻辑
            current.TipPanel.Visibility      = Visibility.Visible;
            current.AddCourseGrid.Visibility = Visibility.Collapsed;

            string termlyString = await CourseDataService.ProcessCourse(course, current.ComboSelectedMode.SelectedIndex, current.ComboDayOfWeek.SelectedIndex, current.ComboWeekStart.SelectedIndex, current.ComboWeekEnd.SelectedIndex);

            if (!string.IsNullOrEmpty(termlyString))
            {
                await CourseDataService.SaveTermlyJsonToIsoStoreAsync(termlyString);

                current.ViewModel.InitializeRootGrid(current.CourseGrid);

                current.TipPanel.Visibility      = Visibility.Collapsed;
                current.btnUserControl.IsEnabled = true;
            }
            else
            {
                current.TipPanel.Visibility      = Visibility.Collapsed;
                current.btnUserControl.IsEnabled = true;

                await new MessageDialog("添加课程失败了,再试一次吧~_~").ShowAsync();
            }
        }
Ejemplo n.º 6
0
 private void InitValues()
 {
     courseDataService = new CourseDataService();
     Courses           = new ObservableCollection <Course>(courseDataService.GetAll());
 }
 public FileUploadProcessorController(IHttpContextAccessor contextAccess, IHostingEnvironment envi)
 {
     context   = contextAccess.HttpContext;
     this.envi = envi;
     this.courseDataService = new CourseDataService();
 }
Ejemplo n.º 8
0
 public CourseProcessorController()
 {
     courseDataService = new CourseDataService();
 }
Ejemplo n.º 9
0
        //加载数据
        private async Task LoadCourseData(int weekOfTerm, int index)
        {
            //清空页面数据
            _sv0.Content = null;
            _sv1.Content = null;
            _sv2.Content = null;

            //周数显示
            Title = $"第 {weekOfTerm} 周";

            int daySpan     = (DateTime.Today - App.AppSettings.TermlyDate).Days;
            int currentWeek = daySpan < 0 ? -1 : daySpan / 7;

            ShowCurrentWeek = weekOfTerm - 1 == currentWeek ? Visibility.Visible : Visibility.Collapsed;

            //初始化月份及日期
            DateTime weeklyDate = App.AppSettings.TermlyDate.AddDays((weekOfTerm - 1) * 7);

            _tbkMonth.Text = $"{weeklyDate.Month}\n月";

            for (int i = 0; i < 7; i++)
            {
                _listDateDetail[i].Text = $"{weeklyDate.AddDays(i).Day.ToString()}\n周{_dayOfWeek[i]}";

                _listDateDetail[i].Opacity = weeklyDate.AddDays(i) == DateTime.Today ? 1 : 0.7;
            }

            //清空课程面板的元素
            _courseGrid.Children.Clear();

            //初始化课程序号
            for (int j = 0; j < 12; j++)
            {
                TextBlock tbkCourseRank = new TextBlock();
                tbkCourseRank.VerticalAlignment = VerticalAlignment.Center;
                tbkCourseRank.TextAlignment     = TextAlignment.Center;
                tbkCourseRank.Foreground        = new SolidColorBrush(Colors.White);
                tbkCourseRank.Text = (j + 1).ToString();
                Grid.SetColumn(tbkCourseRank, 0);
                Grid.SetRow(tbkCourseRank, j);

                _courseGrid.Children.Add(tbkCourseRank);
            }

            //从本地加载当前周课表信息
            weeklyList = new List <List <Course> >();
            weeklyList = await CourseDataService.LoadWeeklyDataFromIsoStoreAsync(weeklyList, weekOfTerm);

            if (weeklyList != null)
            {
                for (int i = 0; i < weeklyList.Count; i++)
                {
                    for (int j = 0; j < weeklyList[i].Count; j++)
                    {
                        Style  btnCourseStyle = App.Current.Resources["CourseButtonStyle"] as Style;
                        Course course         = weeklyList[i][j];

                        Button btn = new Button();

                        btn.Style      = btnCourseStyle;
                        btn.Content    = course.OverView;
                        btn.FontSize   = 9.5;
                        btn.Margin     = new Thickness(1);
                        btn.Background = bgdCourse[colorIndex];
                        btn.Tag        = $"[{i}][{j}]"; //用于标记点击时button位置

                        Grid.SetColumn(btn, i + 1);     //第一列是课程序号
                        Grid.SetRow(btn, course.StartMark);
                        Grid.SetRowSpan(btn, course.CourseSpan);

                        //btn.Click += BtnCourse_Click;
                        btn.Tapped      += btnCourse_Tapped;
                        btn.Holding     += btnCourse_Holding;
                        btn.RightTapped += btnCourse_RightTapped;
                        _courseGrid.Children.Add(btn);

                        colorIndex = colorIndex < 11 ? ++colorIndex : 0;
                    }
                }
            }
            else
            {
                await new MessageDialog("获取课表内容失败,请重启应用!!").ShowAsync();
            }

            switch (index)
            {
            case 0:
                _sv0.Content = _courseGrid;
                break;

            case 1:
                _sv1.Content = _courseGrid;
                break;

            case 2:
                _sv2.Content = _courseGrid;
                break;
            }
        }
Ejemplo n.º 10
0
        public async static Task Update()
        {
            StorageSettings settings = new StorageSettings();

            if (settings.UserSignedIn)
            {
                //计算当前周数以及当天是一周中的哪一天
                int daySpan = (DateTime.Today - settings.TermlyDate).Days;
                if (daySpan < 0 || daySpan / 7 > settings.WeekNum)
                {
                    return;
                }

                int weekOfTerm = daySpan / 7;
                int temp       = (int)DateTime.Today.DayOfWeek;//0表示一周的开始(周日),所以需要根据自身需要做个修订
                int dayOfWeek  = temp == 0 ? 6 : --temp;

                //获取所需课程数据 (上课20分钟内不更新)
                var weeklyList = await CourseDataService.LoadWeeklyDataFromIsoStoreAsync(weekOfTerm + 1); //当前周数据

                var dailyList = weeklyList[dayOfWeek];                                                    //当天数据
                var result    = from c in dailyList
                                where !string.IsNullOrEmpty(c.FullName) && DateTime.Now < Convert.ToDateTime(c.StartTime).AddMinutes(20)
                                select c;
                Debug.WriteLine(result.Count());

                //更新磁贴
                if (result.Count() > 0)
                {
                    var         c                      = result.First();
                    XmlDocument wideTileXML            = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150IconWithBadgeAndText);
                    XmlNodeList wideTileTestAttributes = wideTileXML.GetElementsByTagName("text");
                    wideTileTestAttributes[0].AppendChild(wideTileXML.CreateTextNode(c.FullName));
                    wideTileTestAttributes[1].AppendChild(wideTileXML.CreateTextNode($"时间: {c.StartTime} - {c.EndTime}"));
                    wideTileTestAttributes[2].AppendChild(wideTileXML.CreateTextNode("地点: " + c.Classroom));

                    XmlNodeList wideTileImageAttributes = wideTileXML.GetElementsByTagName("image");
                    ((XmlElement)wideTileImageAttributes[0]).SetAttribute("src", "ms-appx:///Assets/Toast.png");
                    TileNotification notification = new TileNotification(wideTileXML);
                    //notification.ExpirationTime = DateTime
                    TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);
                    //TileUpdateManager.CreateTileUpdaterForSecondaryTile("SecondaryTile")?.Update(notification);

                    XmlDocument badgeXml     = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
                    XmlElement  badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
                    badgeElement.SetAttribute("value", result.Count().ToString());
                    BadgeNotification badge = new BadgeNotification(badgeXml);
                    BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);
                    //TileUpdateManager.CreateTileUpdaterForSecondaryTile("SecondaryTile")?.Update(notification);

                    //未开放二级磁贴选项
                    //if (SecondaryTile.Exists("SecondaryTile"))
                    //{
                    //    notification = new TileNotification(wideTileXML);
                    //    badge = new BadgeNotification(badgeXml);
                    //    TileUpdateManager.CreateTileUpdaterForSecondaryTile("SecondaryTile").Update(notification);
                    //    BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile("SecondaryTile").Update(badge);
                    //}
                }
                else
                {
                    //清空磁贴
                    TileUpdateManager.CreateTileUpdaterForApplication().Clear();
                    BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();

                    //if (SecondaryTile.Exists("SecondaryTile"))//应用中未设置二级磁贴
                    //{
                    //    TileUpdateManager.CreateTileUpdaterForSecondaryTile("SecondaryTile").Clear();
                    //    BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile("SecondaryTile").Clear();
                    //}

                    if (settings.PushNotification && DateTime.Now.Hour >= 21 && settings.NotificationDate != DateTime.Today)//每天晚上9点钟以后推送一次
                    {
                        //检查次日是否有课
                        if (++dayOfWeek == 7)
                        {
                            weekOfTerm++;
                            dayOfWeek = 0;
                        }
                        weeklyList = await CourseDataService.LoadWeeklyDataFromIsoStoreAsync(weekOfTerm);

                        dailyList = weeklyList[dayOfWeek];

                        result = from c in dailyList
                                 where !string.IsNullOrEmpty(c.FullName)
                                 select c;
                        Debug.WriteLine(result.Count());

                        if (result.Count() != 0)
                        {
                            settings.NotificationDate = DateTime.Today;

                            XmlDocument toastXML          = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                            var         toastTextElements = toastXML.GetElementsByTagName("text");
                            toastTextElements[0].AppendChild(toastXML.CreateTextNode(String.Format($"亲,你明天共有{result.Count()}节课,不要迟到哟!(●ˇ∀ˇ●)")));
                            ToastNotification notification = new ToastNotification(toastXML);
                            ToastNotificationManager.CreateToastNotifier().Show(notification);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public async Task <int> GetTermlyJsonAsync(string id, string pwd, string code, bool rememberPwd)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                await new MessageDialog("哦~啊~网络出故障了,检查下网络连接吧(T_T)!!").ShowAsync();

                return(0);
            }

            try
            {
                HttpClientHandler handler = new HttpClientHandler();
                HttpClient        client  = new HttpClient(handler);

                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("user", id);
                dic.Add("pwd", pwd);
                dic.Add("code", code);
                dic.Add("key", "xiaoz");
                dic.Add("clientCookie", ClientCookie);
                dic.Add("viewState", ViewState);
                dic.Add("target", "course");

                FormUrlEncodedContent content = new FormUrlEncodedContent(dic);
                HttpResponseMessage   msg     = await client.PostAsync(APIs.APIs.APIGetCourse + (new Random()).Next(), content);

                string termlyJson = await msg.Content.ReadAsStringAsync();

                if (msg.StatusCode == HttpStatusCode.OK)
                {
                    if (termlyJson.Contains("["))
                    {
                        //存储用户信息
                        App.AppSettings.UserId       = id;
                        App.AppSettings.UserPassword = pwd;
                        App.AppSettings.RememberPwd  = rememberPwd;

                        //将开学时间和总周数保存至本地设置
                        if (msg.Headers.Contains("termlyDate"))
                        {
                            App.AppSettings.TermlyDate = Convert.ToDateTime(msg.Headers.GetValues("termlyDate").ToList()[0]);
                        }
                        if (msg.Headers.Contains("weekNum"))
                        {
                            App.AppSettings.WeekNum = Convert.ToInt32(msg.Headers.GetValues("weekNum").ToList()[0]);
                        }

                        //将Json保存至本地
                        return(await CourseDataService.SaveTermlyJsonToIsoStoreAsync(termlyJson));
                    }
                    else
                    {
                        Debug.WriteLine(termlyJson);

                        return(2);//信息不正确
                    }
                }
                else
                {
                    return(3);//登录超时等情况
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);

                return(-1);//发生异常
            }
        }