/// <summary> /// Handles the Click event of the SaveNoteButton 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 SaveNoteButton_Click(object sender, RoutedEventArgs e) { NOTE note = new NOTE(); note.TITLE = this.noteTitle.Text; note.CONTENT = this.noteContent.Text; note.LESSON_ID = allLessons[selectLessonComboBox.SelectedIndex].ID; note.CUSTOMER_ID = Constants.User.ID; note.DATE = DateTime.Now; note.SHARE = sharableCheckBox.IsChecked ?? false; if (note == null) { System.Diagnostics.Debug.WriteLine("note is null!"); } ctx.AddToNOTE(note); ctx.BeginSaveChanges(onNoteSaved, null); this.addNotePopup.IsOpen = false; ClearNote(); MessageDialog md = new MessageDialog("Note Saved", "Your note have been saved!"); await md.ShowAsync(); //md.Content = "Your note have been saved!"; }
/// <summary> /// Handles the Click event of the SaveNoteButton 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 SaveNoteButton_Click(object sender, RoutedEventArgs e) { try { editCourse.TITLE = courseTitle.Text; editCourse.INTRO = courseContent.Text; editCourse.PRICE = Convert.ToDecimal(price.Text); editCourse.CATEGORY = (categoryComboBox.SelectedItem as CATEGORY).ID; editCourse.PG = (pgComboBox.SelectedItem as PARENT_GUIDE).ID; } catch { ShowMessageDialog("Format error1! Please check your input."); return; } try { ctx.UpdateObject(editCourse); TaskFactory <DataServiceResponse> tf = new TaskFactory <DataServiceResponse>(); await tf.FromAsync(ctx.BeginSaveChanges(null, null), iar => ctx.EndSaveChanges(iar)); } catch { ShowMessageDialog("Edit failed! Network connection error.2"); EditCoursePopup.IsOpen = false; return; } ShowMessageDialog("Edit successfully!"); EditCoursePopup.IsOpen = false; }
/// <summary> /// Handles the Click event of the Button 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 Button_Click(object sender, RoutedEventArgs e) { if (InputUsername.Text.Equals(string.Empty) || InputPassword.Password.Equals(string.Empty)) { var messageDialog = new MessageDialog("Check your input!"); await messageDialog.ShowAsync(); return; } 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; } if (!InputPassword.Password.Equals(ReInputPassword.Password)) { var dialog = new MessageDialog("Passwords are not same! Try again, thx!"); await dialog.ShowAsync(); return; } if (isUserAlreadyThere()) { var dialog = new MessageDialog("Username already exists"); await dialog.ShowAsync(); return; } //CUSTOMER c = CUSTOMER.CreateCUSTOMER(null, InputUsername.Text, InputPassword.Password, null, null, null); c = new CUSTOMER() { NAME = InputUsername.Text, PASSWORD = Constants.ComputeMD5(InputPassword.Password), ALLOW = true, BALANCE = 100, }; ctx.AddToCUSTOMER(c); ctx.BeginSaveChanges(OnCustomerSaveChange, null); }
/// <summary> /// Handles the Click event of the SaveNoteButton 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 SaveNoteButton_Click(object sender, RoutedEventArgs e) { NOTE updatedNote = null; try { DataServiceQuery <NOTE> naDsq = (DataServiceQuery <NOTE>)(from selNote in ctx.NOTE where selNote.ID == changedNote.ID select selNote); TaskFactory <IEnumerable <NOTE> > changeNote = new TaskFactory <IEnumerable <NOTE> >(); updatedNote = (await changeNote.FromAsync(naDsq.BeginExecute(null, null), iar => naDsq.EndExecute(iar))).FirstOrDefault(); } catch { ShowMessageDialog("Network connection error!24"); return; } updatedNote.TITLE = noteTitle.Text; updatedNote.CONTENT = noteContent.Text; updatedNote.LESSON_ID = changedLessonID; updatedNote.DATE = DateTime.Now; updatedNote.SHARE = sharableCheckBox.IsChecked ?? false; try { ctx.UpdateObject(updatedNote); TaskFactory <DataServiceResponse> tf = new TaskFactory <DataServiceResponse>(); await tf.FromAsync(ctx.BeginSaveChanges(null, null), iar => ctx.EndSaveChanges(iar)); } catch { ShowMessageDialog("Update error25! Please check your network."); addNotePopup.IsOpen = false; return; } ShowMessageDialog("Update successfully!"); addNotePopup.IsOpen = false; }
/// <summary> /// Invoked when Add Comment button clicked and add comment. /// </summary> /// <param name="sender">The Add Comment button clicked.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void AddCommentButton_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Debug.WriteLine(newTitleTextBox.Text); if (newTitleTextBox.Text == "" || newContentTextBox.Text == "" || newTitleTextBox.Text.Trim() == "Title") { WarningTextBlock.Visibility = Visibility.Visible; return; } COMMENT commentEntity = new COMMENT(); commentEntity.COURSE_ID = course.ID.Value; commentEntity.CUSTOMER_ID = Constants.User.ID; commentEntity.TITLE = newTitleTextBox.Text; commentEntity.RATE = globalRate; commentEntity.TIME = DateTime.Now; commentEntity.CONTENT = newContentTextBox.Text; ctx.AddToCOMMENT(commentEntity); ctx.BeginSaveChanges(OnAddCommentComplete, null); }
/// <summary> /// Handles the Tapped event of the SaveImage control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="TappedRoutedEventArgs"/> instance containing the event data.</param> private async void SaveImage_Tapped(object sender, TappedRoutedEventArgs e) { if (passwordBox.Password.Equals(string.Empty) || retypePasswordBox.Password.Equals(string.Empty)) { var messageDialog = new MessageDialog("Please Check your input, Password can't be empty!"); await messageDialog.ShowAsync(); return; } if (!Constants.isEmailAvailable(email.Text)) { var messageDialog = new MessageDialog("Please Check your input, EMAIL is not Available!"); await messageDialog.ShowAsync(); return; } if (!passwordBox.Password.Equals(retypePasswordBox.Password)) { var dialog = new MessageDialog("Passwords are not same! Try again, thx!"); await dialog.ShowAsync(); return; } foreach (CUSTOMER c in csl) { if (c.NAME == Constants.User.NAME) { c.DEGREE = (string)degreeBox.SelectedItem; c.PASSWORD = Constants.ComputeMD5(passwordBox.Password); c.EMAIL = email.Text; c.BIRTHDAY = Convert.ToDateTime(birthday.Text); changedCustomer = c; ctx.UpdateObject(c); ctx.BeginSaveChanges(OnCustomerSaveChange, null); } } }
/// <summary> /// Inserts the note. /// </summary> /// <param name="note">The note.</param> /// <param name="onComplete">The on complete.</param> public void InsertNote(NOTE note, OnQueryComplete onComplete) { ctx.AddToNOTE(note); this.onUQC = onComplete; ctx.BeginSaveChanges(onQueryComplete2, null); }
/// <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(); }