/// <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; }
/// <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); } } }
/// <summary> /// Called when [delete note complete]. /// </summary> /// <param name="result">The result.</param> private void OnDeleteNoteComplete(IAsyncResult result) { try { bool res = ctx.EndExecute <bool>(result).FirstOrDefault(); if (res) { ShowMessageDialog("Delete sucessfully!"); } else { ShowMessageDialog("Delete error.22"); } } catch { ShowMessageDialog("Network connection error.23"); } }
/// <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. } }
/// <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(); } }
/// <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 "); } }
/// <summary> /// Called when [upload course complete]. /// </summary> /// <param name="result">The result.</param> private void OnUploadCourseComplete(IAsyncResult result) { ctx.EndExecute(result); }
/// <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 { } }
/// <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 + "%"; }
/// <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. } }
/// <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; }
/// <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. } }
/// <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; }