Пример #1
0
        /// <summary>
        /// Buys the course.
        /// </summary>
        /// <param name="bt">The bt.</param>
        /// <param name="courseInfo">The course information.</param>
        private async void BuyCourse(Button bt, List <Object> courseInfo)
        {
            bool isToBuy   = false;
            bool isHaveBuy = false;

            var buySure = new MessageDialog("Are you sure to buy this course?", "Buy Course");

            buySure.Commands.Add(new UICommand("Yes", (command) =>
            {
                isToBuy = true;
            }));
            buySure.Commands.Add(new UICommand("No", (command) =>
            {
                isToBuy = false;
                return;
            }));
            await buySure.ShowAsync();

            if (isToBuy)
            {
                try
                {
                    string uri = "/EnrollCourse?customer_id=" + Constants.User.ID + "&course_id=" + course.ID;
                    TaskFactory <IEnumerable <int> > tf = new TaskFactory <IEnumerable <int> >();
                    IEnumerable <int> code = await tf.FromAsync(ctx.BeginExecute <int>(new Uri(uri, UriKind.Relative), null, null), iar => ctx.EndExecute <int>(iar));

                    isHaveBuy = true;

                    if (code.FirstOrDefault() != 0)
                    {
                        isHaveBuy = false;
                        var buyError = new MessageDialog("You don't have enough money. Please contact Scott Zhao.", "Buy Failed");
                        buyError.Commands.Add(new UICommand("Close"));
                        await buyError.ShowAsync();

                        return;
                    }
                }
                catch
                {
                    ShowMessageDialog("Network connection error1!");
                    return;
                }
            }

            if (isHaveBuy)
            {
                var buyOkMsg = new MessageDialog("Do you want to start learning?", "Buy successfully");
                buyOkMsg.Commands.Add(new UICommand("Yes", (command) =>
                {
                    courseInfo.Add("attending");
                    Frame.Navigate(typeof(Coursing), courseInfo);
                }));
                buyOkMsg.Commands.Add(new UICommand("No", (command) =>
                {
                    bt.Content = "Attend";
                }));
                await buyOkMsg.ShowAsync();
            }
        }
Пример #2
0
        /// <summary>
        /// Called when [customer save change].
        /// </summary>
        /// <param name="result">The result.</param>
        private async void OnCustomerSaveChange(IAsyncResult result)
        {
            try
            {
                ctx.EndSaveChanges(result);
                Constants.User = new User(changedCustomer);
                //Constants.User = new User(changedCustomer);
                string Uri = "/AddDBLog?opr='ChangeProfile'&msg='" + Constants.User.NAME + "'";

                try
                {
                    TaskFactory <IEnumerable <bool> > tf = new TaskFactory <IEnumerable <bool> >();
                    IEnumerable <bool> resulta           = await tf.FromAsync(ctx.BeginExecute <bool>(new Uri(Uri, UriKind.Relative), null, null), iar => ctx.EndExecute <bool>(iar));
                }
                catch
                {
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Frame.GoBack();
                });
            }
            catch
            {
                ShowMessageDialog("On customer save change");
                //Network Connection error.
            }
        }
Пример #3
0
        /// <summary>
        /// Called when [customer save change].
        /// </summary>
        /// <param name="result">The result.</param>
        private async void OnCustomerSaveChange(IAsyncResult result)
        {
            try
            {
                ctx.EndSaveChanges(result);
                string Uri = "/AddDBLog?opr='SignUp'&msg='" + c.NAME + "'";
                //ctx.UpdateObject(c);

                try
                {
                    TaskFactory <IEnumerable <bool> > tf = new TaskFactory <IEnumerable <bool> >();
                    IEnumerable <bool> resulta           = await tf.FromAsync(ctx.BeginExecute <bool>(new Uri(Uri, UriKind.Relative), null, null), iar => ctx.EndExecute <bool>(iar));
                }
                catch
                {
                }
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Frame.Navigate(typeof(Login));
                });
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Msg: {0}\nInnerExp:{1}\nStackTrace: {2} ",
                                                   e.Message, e.InnerException, e.StackTrace);
                ShowMessageDialog();
                //Network Connection error.
            }
        }
Пример #4
0
        /// <summary>
        /// Handles the Tapped event of the deleteImage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="TappedRoutedEventArgs"/> instance containing the event data.</param>
        void deleteImage_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Image toDelImage = sender as Image;

            ctx.BeginExecute <bool>(new Uri("/RemoveNote?id=" + Convert.ToInt32(toDelImage.Tag), UriKind.Relative), OnDeleteNoteComplete, null);

            Grid toDelGrid = toDelImage.Parent as Grid;

            myNotesStackPanel.Children.Remove(toDelGrid);
        }
Пример #5
0
        /// <summary>
        /// Gets the learned percentage.
        /// </summary>
        private async void getLearnedPercentage()
        {
            double percent;

            string uri2 = "/CoursePercentByCustomer?customer_id=" + Constants.User.ID + "&course_id=" + course.ID;
            TaskFactory <IEnumerable <double> > tf = new TaskFactory <IEnumerable <double> >();
            IEnumerable <double> percentages       = await tf.FromAsync(ctx.BeginExecute <double>(new Uri(uri2, UriKind.Relative), null, null), iar => ctx.EndExecute <double>(iar));

            percent = percentages.FirstOrDefault();

            FinishPercentage.Text = "Finished " + percent * 100 + "%";
        }
Пример #6
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            categoryName = e.Parameter as string;
            Title.Text   = Constants.UpperInitialChar(categoryName);
            loadingProgressRing.IsActive = true;

            /****** 这里是所有推荐课程的搜索 ***/
            if (categoryName.Equals("Recommendation"))
            {
                TaskFactory <IEnumerable <COURSE_AVAIL> > tfRec = new TaskFactory <IEnumerable <COURSE_AVAIL> >();

                IEnumerable <COURSE_AVAIL> recCourses = await tfRec.FromAsync(ctx.BeginExecute <COURSE_AVAIL>(
                                                                                  new Uri("/GetRecommendedCourses?customer_id=" + Constants.User.ID, UriKind.Relative), null, null),
                                                                              iar => ctx.EndExecute <COURSE_AVAIL>(iar));


                categoryCourses = new StoreData();
                foreach (var c in recCourses)
                {
                    categoryCourses.AddCourse(Constants.CourseRec2Course(c));
                }
                dataCategory = categoryCourses.GetSingleGroupByCategoryTitle(categoryName);
                cvs1.Source  = dataCategory;
                loadingProgressRing.IsActive = false;


                //courseDsq = (DataServiceQuery<COURSE_AVAIL>)(from course in ctx.COURSE_AVAIL
                //                                             where course.ID > 5
                //                                             select course);
                //courseDsq.BeginExecute(OnRecommendationMannualCoursesComplete, null);
            }
            else
            {
                if (Constants.CategoryNameList.Contains(categoryName))
                {
                    courseDsq = (DataServiceQuery <COURSE_AVAIL>)(from course_avail in ctx.COURSE_AVAIL
                                                                  where course_avail.CATE_NAME == categoryName
                                                                  select course_avail);
                    courseDsq.BeginExecute(OnCategoryCoursesComplete, null);
                }
                else
                {
                    recDsq = (DataServiceQuery <COURSE_RECO_AVAIL>)(from re in ctx.COURSE_RECO_AVAIL
                                                                    where re.RECO_TITLE == categoryName
                                                                    select re);
                    recDsq.BeginExecute(OnRecommendationCoursesComplete, null);
                }
            }
            UserProfileBt.DataContext = Constants.User;
        }
Пример #7
0
        /// <summary>
        /// Handles the 1 event of the LogoutButton_Click control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private async void LogoutButton_Click_1(object sender, RoutedEventArgs e)
        {
            ((Frame)Window.Current.Content).Navigate(typeof(Login.LoginSel));
            string courseUplaodUri = "/AddDBLog?opr='Logout'&msg='" + Constants.User.NAME + "'";
            //ctx.UpdateObject(c);
            CloudEDUEntities ctx = new CloudEDUEntities(new Uri(Constants.DataServiceURI));

            try
            {
                TaskFactory <IEnumerable <bool> > tf = new TaskFactory <IEnumerable <bool> >();
                IEnumerable <bool> result            = await tf.FromAsync(ctx.BeginExecute <bool>(new Uri(courseUplaodUri, UriKind.Relative), null, null), iar => ctx.EndExecute <bool>(iar));
            }
            catch
            {
            }
        }
Пример #8
0
            /// <summary>
            /// Gets all learned.
            /// </summary>
            public async static void GetAllLearned()
            {
                if (LearnedCourses == null)
                {
                    LearnedCourses = new List <COURSE_AVAIL>();

                    CloudEDUEntities ctx = new CloudEDUEntities(new Uri(Constants.DataServiceURI));
                    TaskFactory <IEnumerable <COURSE_AVAIL> > tf = new TaskFactory <IEnumerable <COURSE_AVAIL> >();

                    IEnumerable <COURSE_AVAIL> attends = await tf.FromAsync(ctx.BeginExecute <COURSE_AVAIL>(
                                                                                new Uri("/GetAllCoursesAttendedByCustomer?customer_id=" + Constants.User.ID, UriKind.Relative), null, null),
                                                                            iar => ctx.EndExecute <COURSE_AVAIL>(iar));

                    foreach (var ca in attends)
                    {
                        LearnedCourses.Add(ca);
                    }
                }
            }
Пример #9
0
        /// <summary>
        /// Sets the attend teach number.
        /// </summary>
        public async void SetAttendTeachNumber()
        {
            try
            {
                ctx      = new CloudEDUEntities(new Uri(Constants.DataServiceURI));
                teachDsq = (DataServiceQuery <COURSE_AVAIL>)(from course in ctx.COURSE_AVAIL
                                                             where course.TEACHER_NAME == this.NAME
                                                             select course);
                TaskFactory <IEnumerable <COURSE_AVAIL> > tf = new TaskFactory <IEnumerable <COURSE_AVAIL> >();
                IEnumerable <COURSE_AVAIL> attends           = await tf.FromAsync(ctx.BeginExecute <COURSE_AVAIL>(
                                                                                      new Uri("/GetAllCoursesAttendedByCustomer?customer_id=" + this.ID, UriKind.Relative), null, null),
                                                                                  iar => ctx.EndExecute <COURSE_AVAIL>(iar));

                ATTEND_COUNT = attends.Count();
                IEnumerable <COURSE_AVAIL> teaches = await tf.FromAsync(teachDsq.BeginExecute(null, null), iar => teachDsq.EndExecute(iar));

                TEACH_COUNT = teaches.Count();
            }
            catch
            {
                ShowMessageDialog("Set Attend Teach Number ");
            }
        }
Пример #10
0
        /// <summary>
        /// Invoked when all uplaod button is clicked.
        /// </summary>
        /// <param name="sender">The all upload button clicked.</param>
        /// <param name="e">Event data that describes how the click was initiated.</param>
        /// <exception cref="InvalidDataException">
        /// </exception>
        private async void allUploadButton_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckCourseInfomation())
            {
                ShowMessageDialog("Format error4! Please check your upload infomation.");
                return;
            }

            addLessonButton.IsEnabled    = false;
            allUploadButton.IsEnabled    = false;
            resetUploadButton.IsEnabled  = false;
            uploadProgressBar.Visibility = Visibility.Visible;

            try
            {
                resourceDic = new Dictionary <string, int>(Constants.ResourceType.Count);
                for (int i = 0; i < Constants.ResourceType.Count; ++i)
                {
                    DataServiceQuery <RES_TYPE> dps = (DataServiceQuery <RES_TYPE>)(from res_type in ctx.RES_TYPE
                                                                                    where res_type.DESCRIPTION.Trim() == Constants.ResourceType[i]
                                                                                    select res_type);
                    TaskFactory <IEnumerable <RES_TYPE> > tf = new TaskFactory <IEnumerable <RES_TYPE> >();
                    RES_TYPE resID = (await tf.FromAsync(dps.BeginExecute(null, null), iar => dps.EndExecute(iar))).FirstOrDefault();

                    resourceDic.Add(Constants.ResourceType[i], resID.ID);
                }
            }
            catch
            {
                ShowMessageDialog("Network connection error5!");
                return;
            }

            string courseUplaodUri = "/CreateCourse?teacher_id=" + Constants.User.ID
                                     + "&title='" + courseNameTextBox.Text
                                     + "'&intro='" + CourseDescriptionTextBox.Text
                                     + "'&category_id=" + (categoryComboBox.SelectionBoxItem as CATEGORY).ID
                                     + "&price=" + Convert.ToDecimal(priceTextBox.Text)
                                     + "&pg_id=" + (pgComboBox.SelectionBoxItem as PARENT_GUIDE).ID
                                     + "&icon_url='" + toBeUploadCourse.ImageUri + "'";

            int newCourseID = 0;

            try
            {
                TaskFactory <IEnumerable <decimal> > tf = new TaskFactory <IEnumerable <decimal> >();
                IEnumerable <decimal> courses           = await tf.FromAsync(ctx.BeginExecute <decimal>(new Uri(courseUplaodUri, UriKind.Relative), null, null), iar => ctx.EndExecute <decimal>(iar));

                newCourseID = Convert.ToInt32(courses.FirstOrDefault());
                if (newCourseID == 0)
                {
                    throw new InvalidDataException();
                }
            }
            catch
            {
                ShowMessageDialog("Course upload error6! Please check your network.");
                return;
            }

            for (int i = 0; i < allLessons.Count; ++i)
            {
                Lesson newLesson       = allLessons[i];
                string lessonUploadUri = "/CreateLesson?course_id=" + newCourseID
                                         + "&content='" + newLesson.Content
                                         + "'&title='" + newLesson.Title +
                                         "'&number=" + newLesson.Number;
                int newLessonID = 0;
                try
                {
                    TaskFactory <IEnumerable <decimal> > tf = new TaskFactory <IEnumerable <decimal> >();
                    IEnumerable <decimal> lessons           = await tf.FromAsync(ctx.BeginExecute <decimal>(new Uri(lessonUploadUri, UriKind.Relative), null, null), iar => ctx.EndExecute <decimal>(iar));

                    newLessonID = Convert.ToInt32(lessons.FirstOrDefault());
                    if (newLessonID == 0)
                    {
                        throw new InvalidDataException();
                    }
                }
                catch
                {
                    ShowMessageDialog("Lesson error7! Please check your network.");
                    return;
                }

                try
                {
                    List <Resource> docsRes   = allLessons[i].GetDocList();
                    List <Resource> audiosRes = allLessons[i].GetAudioList();
                    List <Resource> videosRes = allLessons[i].GetVideoList();
                    for (int j = 0; j < docsRes.Count; ++j)
                    {
                        Resource r      = docsRes[j];
                        RESOURCE newRes = new RESOURCE();
                        newRes.LESSON_ID = newLessonID;
                        newRes.TYPE      = resourceDic["DOCUMENT"];
                        newRes.URL       = r.Uri;
                        newRes.TITLE     = r.Title;

                        ctx.AddToRESOURCE(newRes);
                    }
                    for (int j = 0; j < audiosRes.Count; ++j)
                    {
                        Resource r      = audiosRes[j];
                        RESOURCE newRes = new RESOURCE();
                        newRes.LESSON_ID = newLessonID;
                        newRes.TYPE      = resourceDic["AUDIO"];
                        newRes.URL       = r.Uri;
                        newRes.TITLE     = r.Title;

                        ctx.AddToRESOURCE(newRes);
                    }
                    for (int j = 0; j < videosRes.Count; ++j)
                    {
                        Resource r      = videosRes[j];
                        RESOURCE newRes = new RESOURCE();
                        newRes.LESSON_ID = newLessonID;
                        newRes.TYPE      = resourceDic["VIDEO"];
                        newRes.URL       = r.Uri;
                        newRes.TITLE     = r.Title;

                        ctx.AddToRESOURCE(newRes);
                    }
                    TaskFactory <DataServiceResponse> tfRes = new TaskFactory <DataServiceResponse>();
                    DataServiceResponse dsr = await tfRes.FromAsync(ctx.BeginSaveChanges(null, null), iar => ctx.EndSaveChanges(iar));
                }
                catch
                {
                    ShowMessageDialog("Uplaod error8! Please check your network");
                    return;
                }
            }
            addLessonButton.IsEnabled    = true;
            allUploadButton.IsEnabled    = true;
            resetUploadButton.IsEnabled  = true;
            uploadProgressBar.Visibility = Visibility.Collapsed;

            var finishMsg = new MessageDialog("Upload Finish! Please wait the check.", "Congratulation");

            finishMsg.Commands.Add(new UICommand("Continue upload", (command) =>
            {
                ResetPage();
            }));
            finishMsg.Commands.Add(new UICommand("Back", (command) =>
            {
                Frame.Navigate(typeof(CourseStore.Courstore));
            }));
            await finishMsg.ShowAsync();
        }
Пример #11
0
        /// <summary>
        /// Handles the Click event of the LoginButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            InputUsername.IsEnabled = InputPassword.IsEnabled = LoginButton.IsEnabled = SignUpButton.IsEnabled = false;

            //login
            if (InputUsername.Text.Equals(emptyUsername) || InputPassword.Password.Equals(string.Empty))
            {
                var messageDialog = new MessageDialog("Check your input!");
                await messageDialog.ShowAsync();

                return;
            }
            //InputUsername.Text
            if (!Constants.isUserNameAvailable(InputUsername.Text))
            {
                var messageDialog = new MessageDialog("Check your input! Username can only contain 1-9 a-z and _");
                await messageDialog.ShowAsync();

                return;
            }
            //try
            //{
            //    TaskFactory<IEnumerable<CUSTOMER>> tf = new TaskFactory<IEnumerable<CUSTOMER>>();
            //    customerDsq = (DataServiceQuery<CUSTOMER>)(from user in ctx.CUSTOMER where user.NAME == InputUsername.Text select user);
            //    IEnumerable<CUSTOMER> cs = await tf.FromAsync(customerDsq.BeginExecute(null, null), iar => customerDsq.EndExecute(iar));
            //    csl = new List<CUSTOMER>(cs);
            //}
            //catch (Exception ex)
            //{
            //    System.Diagnostics.Debug.WriteLine("login request error: {0}", ex.Message);
            //    ShowMessageDialog();
            //}
            bool isLogined = false;

            try
            {
                foreach (CUSTOMER c in Constants.csl)
                {
                    if (c.NAME == InputUsername.Text)
                    {
                        if (c.PASSWORD == Constants.ComputeMD5(InputPassword.Password))
                        {
                            //login success
                            //CUSTOMER
                            //Constants.User = c;
                            System.Diagnostics.Debug.WriteLine(c.PASSWORD);
                            string Uri;
                            //User
                            if (!c.ALLOW)
                            {
                                var notAllowed = new MessageDialog("The User is forbidden!");
                                await notAllowed.ShowAsync();

                                Uri = "/AddDBLog?opr='TryLoginFailBecauseUserForbiddened'&msg='" + c.NAME + "'";
                                //ctx.UpdateObject(c);

                                try
                                {
                                    TaskFactory <IEnumerable <bool> > tf = new TaskFactory <IEnumerable <bool> >();
                                    IEnumerable <bool> result            = await tf.FromAsync(ctx.BeginExecute <bool>(new Uri(Uri, UriKind.Relative), null, null), iar => ctx.EndExecute <bool>(iar));
                                }
                                catch
                                {
                                }
                                return;
                            }
                            Constants.Save <bool>("AutoLog", (bool)CheckAutoLogin.IsChecked);
                            Constants.User = new User(c);
                            isLogined      = true;
                            System.Diagnostics.Debug.WriteLine("login success");
                            Uri = "/AddDBLog?opr='Login'&msg='" + Constants.User.NAME + "'";
                            //ctx.UpdateObject(c);

                            try
                            {
                                TaskFactory <IEnumerable <bool> > tf = new TaskFactory <IEnumerable <bool> >();
                                IEnumerable <bool> result            = await tf.FromAsync(ctx.BeginExecute <bool>(new Uri(Uri, UriKind.Relative), null, null), iar => ctx.EndExecute <bool>(iar));
                            }
                            catch
                            {
                            }
                            Frame.Navigate(typeof(Courstore));
                            // navigate
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine("Msg: {0}\nInnerExp:{1}\nStackTrace: {2} ",
                                                   exp.Message, exp.InnerException, exp.StackTrace);
                ShowMessageDialog();
            }
            // login fail
            if (isLogined)
            {
                return;
            }
            var msgDialog = new MessageDialog("Username Or Password is wrong");
            await msgDialog.ShowAsync();

            InputUsername.IsEnabled = InputPassword.IsEnabled = LoginButton.IsEnabled = SignUpButton.IsEnabled = true;
        }
Пример #12
0
        /// <summary>
        /// DataServiceQuery callback method to refresh the UI.
        /// </summary>
        /// <param name="result">Async operation result.</param>
        private async void OnCourseAvailComplete(IAsyncResult result)
        {
            coursesData = new StoreData();

            try
            {
                /************************ 搜索推荐课程 *********************/
                TaskFactory <IEnumerable <COURSE_AVAIL> > tfRec = new TaskFactory <IEnumerable <COURSE_AVAIL> >();

                IEnumerable <COURSE_AVAIL> recCourses = await tfRec.FromAsync(ctx.BeginExecute <COURSE_AVAIL>(
                                                                                  new Uri("/GetRecommendedCourses?customer_id=" + Constants.User.ID, UriKind.Relative), null, null),
                                                                              iar => ctx.EndExecute <COURSE_AVAIL>(iar));

                //DataServiceQuery<COURSE_AVAIL> recCourseDsq = (DataServiceQuery<COURSE_AVAIL>)(from rc in ctx.COURSE_AVAIL
                //                                                                               where rc.ID > 5
                //                                                                               select rc);
                //TaskFactory<IEnumerable<COURSE_AVAIL>> recTF = new TaskFactory<IEnumerable<COURSE_AVAIL>>();
                //IEnumerable<COURSE_AVAIL> recCourses = await recTF.FromAsync(recCourseDsq.BeginExecute(null, null), iar => recCourseDsq.EndExecute(iar));

                foreach (var c in recCourses)
                {
                    coursesData.AddCourse(Constants.CourseRec2Course(c));
                }
                /************************ 搜索推荐课程 *********************/
            }
            catch
            {
                coursesData = new StoreData();
            }


            try
            {
                DataServiceQuery <COURSE_RECO_AVAIL> craDsq = (DataServiceQuery <COURSE_RECO_AVAIL>)(from re in ctx.COURSE_RECO_AVAIL
                                                                                                     select re);
                TaskFactory <IEnumerable <COURSE_RECO_AVAIL> > tf = new TaskFactory <IEnumerable <COURSE_RECO_AVAIL> >();
                IEnumerable <COURSE_RECO_AVAIL> recommendation    = await tf.FromAsync(craDsq.BeginExecute(null, null), iar => craDsq.EndExecute(iar));

                foreach (var re in recommendation)
                {
                    coursesData.AddCourse(Constants.CourseRecAvail2Course(re));
                }
                IEnumerable <COURSE_AVAIL> courses = courseDsq.EndExecute(result);
                foreach (var c in courses)
                {
                    coursesData.AddCourse(Constants.CourseAvail2Course(c));
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    dataCategory = coursesData.GetGroupsByCategory();
                    cvs1.Source  = dataCategory;
                    (SemanticZoom.ZoomedOutView as ListViewBase).ItemsSource = cvs1.View.CollectionGroups;
                    loadingProgressRing.IsActive = false;
                });
            }
            catch
            {
                ShowMessageDialog("on course avail complete");
                // Network Connection error.
            }
        }
Пример #13
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            SetAllTextBlock();
            allCourses = new List <Course>();
            loadingProgressRing.IsActive = true;

            var borders = from b in topograph.Children.OfType <Border>()
                          select b;

            List <string> courseNameList = new List <string>();
            List <CloudEDU.Common.Constants.CourseAvaiStates> courseStatesList = new List <Constants.CourseAvaiStates>();

            foreach (Border border in borders)
            {
                TextBlock textBlock      = border.Child as TextBlock;
                string    courseShowName = textBlock.Text.Replace("\n", " ");
                courseNameList.Add(textBlock.Text);
                courseStatesList.Add(Constants.DepCourse.GetCourseLearnedState(courseShowName));
            }
            SetAllCoursesStates(courseNameList, courseStatesList);


            SetCourseState("Compute\nArchitecture", Constants.CourseAvaiStates.NotLearnedDisable);

            try
            {
                teachDsq = (DataServiceQuery <COURSE_AVAIL>)(from course in ctx.COURSE_AVAIL
                                                             where course.TEACHER_NAME == Constants.User.NAME
                                                             select course);

                TaskFactory <IEnumerable <COURSE_AVAIL> > tf = new TaskFactory <IEnumerable <COURSE_AVAIL> >();

                IEnumerable <COURSE_AVAIL> attends = await tf.FromAsync(ctx.BeginExecute <COURSE_AVAIL>(
                                                                            new Uri("/GetAllCoursesAttendedByCustomer?customer_id=" + Constants.User.ID, UriKind.Relative), null, null),
                                                                        iar => ctx.EndExecute <COURSE_AVAIL>(iar));

                IEnumerable <COURSE_AVAIL> teaches = await tf.FromAsync(teachDsq.BeginExecute(null, null), iar => teachDsq.EndExecute(iar));

                DataServiceQuery <COURSE_AVAIL> allCoursesDsq = (DataServiceQuery <COURSE_AVAIL>)(from c in ctx.COURSE_AVAIL
                                                                                                  select c);
                IEnumerable <COURSE_AVAIL> allCoursesEnum = await tf.FromAsync(allCoursesDsq.BeginExecute(null, null), iar => allCoursesDsq.EndExecute(iar));

                foreach (var c in allCoursesEnum)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    allCourses.Add(tmpCourse);
                }

                courseData = new StoreData();
                foreach (var c in attends)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    tmpCourse.IsBuy   = true;
                    tmpCourse.IsTeach = false;
                    courseData.AddCourse(tmpCourse);
                }
                foreach (var c in teaches)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    tmpCourse.IsTeach = true;
                    tmpCourse.IsBuy   = false;
                    courseData.AddCourse(tmpCourse);
                }

                dataCategory = courseData.GetGroupsByAttendingOrTeaching();
                cvs1.Source  = dataCategory;
                UserProfileBt.DataContext = Constants.User;
            }
            catch
            {
                ShowMessageDialog("on navi to");
            }

            loadingProgressRing.IsActive = false;
        }