Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 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.
            }
        }
Exemplo n.º 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.
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Called when [add comment complete].
 /// </summary>
 /// <param name="result">The result.</param>
 private async void OnAddCommentComplete(IAsyncResult result)
 {
     try
     {
         ctx.EndSaveChanges(result);
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             StackPanel newComment = GenerateACommentBox(Constants.User.NAME, newTitleTextBox.Text, globalRate, newContentTextBox.Text);
             commentsStackPanel.Children.Add(newComment);
             newTitleTextBox.Text = newContentTextBox.Text = "";
             globalRate           = 0;
             SetStarTextBlock(globalRate);
             WarningTextBlock.Visibility = Visibility.Collapsed;
         });
     }
     catch (DataServiceRequestException)
     {
         ShowMessageDialog("One user can only comment once.");
         ResetAfterComment();
     }
     catch
     {
         ShowMessageDialog("Network connection error!");
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Ons the note saved.
 /// </summary>
 /// <param name="iar">The iar.</param>
 private void onNoteSaved(IAsyncResult iar)
 {
     try
     {
         ctx.EndSaveChanges(iar);
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 6
0
        /// <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;
        }
Exemplo n.º 7
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();
        }