Esempio n. 1
0
        private void showAlertMessaageToUser()
        {
            MessageBoxResult result = MessageBox.Show("你已经修改了相关内容,请确认是否保存数据?",
                                                      "Confirmation", MessageBoxButton.YesNoCancel);

            if (result == MessageBoxResult.Yes)
            {
                // Yes code here
                CourseWeekViewModel.getInstance().selectedClassId = ((int)ClassesBox.SelectedValue);
                CourseWeekViewModel.getInstance().saveOneWeekCourseData();//TODO should be in thread.
                CourseWeekViewModel.getInstance().clealrOneWeekCourse();
                refreshData();
            }
            else if (result == MessageBoxResult.No)
            {
                // No code here
                CourseWeekViewModel.getInstance().selectedClassId = ((int)ClassesBox.SelectedValue);
                CourseWeekViewModel.getInstance().clealrOneWeekCourse();
                refreshData();
            }
            else
            {
                // Cancel code here, do nothing.
                ClassesBox.SelectedIndex = ClassViewModel.getInstance().getGradeIndexById(CourseWeekViewModel.getInstance().selectedClassId);
            }
        }
        private void init()
        {
            //Fetch data from memory.
            mEditingColumn  = (int)Application.Current.Properties["OneWeekCourseEditingColumn"];
            mEditingRow     = (int)Application.Current.Properties["OneWeekCourseEditingRow"];
            mCourseWeekItem = CourseWeekViewModel.getInstance().getCourseWeekItemByJieCi(mEditingRow, mEditingColumn);

            //Start to give related value to collection.
            courseTeacherComboBox.ItemsSource = ClassViewModel.getInstance().allTeachers;
            ;
            courseGroupComboBox.ItemsSource    = CourseWeekViewModel.getInstance().allCourseGroup;
            courseLocationComboBox.ItemsSource = CourseWeekViewModel.getInstance().allCourseLocations;

            if (mCourseWeekItem != null)
            {
                //Means modify data.
                courseTeacherComboBox.SelectedIndex  = ClassViewModel.getInstance().getTeacherIndexById(mCourseWeekItem.teacherid);
                courseGroupComboBox.SelectedIndex    = CourseWeekViewModel.getInstance().getCourseGroupIndexById(mCourseWeekItem.coursegroupid);
                courseLocationComboBox.SelectedIndex = CourseWeekViewModel.getInstance().getCourseLocationIndexById(mCourseWeekItem.locationid);
                contentDescTextBox.Text = mCourseWeekItem.contentdesc;
            }
            else
            {
                //It means we should create the new one.
                mCourseWeekItem         = new CourseWeekItem();
                mCourseWeekItem.gradeid = CourseWeekViewModel.getInstance().selectedClassId;
                mCourseWeekItem.weekno  = CourseWeekViewModel.getInstance().courseWeekNoForDB;
                mCourseWeekItem.weekday = mEditingColumn + 1;
                mCourseWeekItem.jieci   = (mEditingColumn + 1) * 10 + mEditingRow;

                //Bind the initial comboBox value.
                courseTeacherComboBox.SelectedIndex  = ClassViewModel.getInstance().getTeacherIndexById(CourseWeekViewModel.getInstance().defaultTeacherId);
                courseLocationComboBox.SelectedIndex = CourseWeekViewModel.getInstance().getCourseLocationIndexById(CourseWeekViewModel.getInstance().defaultLocationId);
            }
        }
Esempio n. 3
0
 void worker_initDataCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     //Bind Data to UI.
     weeknoTextBlock.Text     = "第" + CourseWeekViewModel.getInstance().courseWeekNoForDisplay + "周课程表";
     ClassesBox.ItemsSource   = ClassViewModel.getInstance().allClasses;
     ClassesBox.SelectedIndex = ClassViewModel.getInstance().getClassIndexById(CourseWeekViewModel.getInstance().selectedClassId);
     bindDataToUI();
 }
Esempio n. 4
0
        private string getJieCiDescription(int row, int column)
        {
            CourseWeekItem item = CourseWeekViewModel.getInstance().getCourseWeekItemByJieCi(row, column);

            if (item != null)
            {
                return(CourseWeekViewModel.getInstance().getCourseGroupById(item.coursegroupid).courseName + "\n" +
                       item.contentdesc + "\n" +
                       ClassViewModel.getInstance().getTeacherById(item.teacherid).name + "\n" +
                       CourseWeekViewModel.getInstance().getLocationById(item.locationid).location + "\n");
            }
            else
            {
                return("");
            }
        }
Esempio n. 5
0
 private void GradesBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     //If the user has data need to be saved. we should alert the user.
     if (mFirstEnter)
     {
         mFirstEnter = false;
     }
     else
     {
         if (CourseWeekViewModel.getInstance().contentHasChanged)
         {
             showAlertMessaageToUser();
         }
         else
         {
             CourseWeekViewModel.getInstance().selectedClassId = ((int)ClassesBox.SelectedValue);
             CourseWeekViewModel.getInstance().clealrOneWeekCourse();
             refreshData();
         }
     }
 }
        private void confirmBtn_Click(object sender, RoutedEventArgs e)
        {
            int    oldCourseGroupId    = mCourseWeekItem.coursegroupid;
            int    oldCourseTeacherId  = mCourseWeekItem.teacherid;
            int    oldCourseLocationId = mCourseWeekItem.locationid;
            string oldCouseContentDesc = mCourseWeekItem.contentdesc;

            //bind the new data.
            if (courseGroupComboBox.SelectedValue != null)
            {
                mCourseWeekItem.coursegroupid = (int)courseGroupComboBox.SelectedValue;
            }
            mCourseWeekItem.teacherid   = (int)courseTeacherComboBox.SelectedValue;
            mCourseWeekItem.locationid  = (int)courseLocationComboBox.SelectedValue;
            mCourseWeekItem.contentdesc = contentDescTextBox.Text;

            if ((mCourseWeekItem.id != -1 && (oldCourseGroupId != mCourseWeekItem.coursegroupid ||
                                              oldCourseTeacherId != mCourseWeekItem.teacherid ||
                                              oldCourseLocationId != mCourseWeekItem.locationid ||
                                              !oldCouseContentDesc.Equals(mCourseWeekItem.contentdesc))))
            {
                //This means has modified the original data.
                CourseWeekViewModel.getInstance().contentHasChanged = true;
            }

            //Save new data into memory.
            if (mCourseWeekItem.id == -1 && CourseWeekViewModel.getInstance().isNeedTOSaveInMemoryByJieCi(mEditingRow, mEditingColumn))
            {
                //this means we have added new data.
                CourseWeekViewModel.getInstance().saveCourseWeekItemInMemory(mCourseWeekItem);
                CourseWeekViewModel.getInstance().contentHasChanged = true;
            }


            //Close the window.
            Close();
        }
Esempio n. 7
0
 void refreshData()
 {
     //TODO should be run in thread.
     CourseWeekViewModel.getInstance().worker_reloadOneWeekCourseDataFromDatabase();
     bindDataToUI();
 }
Esempio n. 8
0
 public void worker_initData(object sender, DoWorkEventArgs e)
 {
     //Do the logic to judge init from database or newMaker.
     //CourseWeekViewModel.getInstance().worker_initDataFromDatabase();
     CourseWeekViewModel.getInstance().worker_initDataFromDatabase(false);
 }
Esempio n. 9
0
 private void saveDataToDBBtn_Click(object sender, RoutedEventArgs e)
 {
     CourseWeekViewModel.getInstance().saveOneWeekCourseData();
 }