private void FillLocationListDropdownList(DataGridView view, int rowNum, TeacherRecord teacherRecord)
        {
            if (string.IsNullOrEmpty(teacherRecord.LocationList))
                return;

            string[] locationList = teacherRecord.LocationList.Split('|');

            if (locationList == null || locationList.Length <= 0)
                return;

            foreach (var location in locationList)
            {
                if (string.IsNullOrEmpty(location))
                    continue;

                ((DataGridViewComboBoxCell) view.Rows[rowNum].Cells["Column_LocationList"]).Items.Add(
                    location);
            }

            if (((DataGridViewComboBoxCell)view.Rows[rowNum].Cells["Column_LocationList"]).Items.Count > 0)
            {
                ((DataGridViewComboBoxCell) view.Rows[rowNum].Cells["Column_LocationList"]).Value =
                    ((DataGridViewComboBoxCell) view.Rows[rowNum].Cells["Column_LocationList"]).Items[0];
            }
        }
        private void SystemUserView_UpdateTeacher(object sender, EventArgs e)
        {
            TeacherRecord teacherRecord = new TeacherRecord();

            teacherRecord.ID = editTeacherView.TeacherID;
            teacherRecord.TeacherName = editTeacherView.TeacherName;
            teacherRecord.TeacherSex = editTeacherView.TeacherSex;
            teacherRecord.Birthday = editTeacherView.Birthday;
            teacherRecord.NativePlace = editTeacherView.NativePlace;
            teacherRecord.WorkPlace = editTeacherView.WorkPlace;
            teacherRecord.PhotoIDNumber = editTeacherView.PhotoIDNumber;
            teacherRecord.GraduateSchool = editTeacherView.GraduateSchool;
            teacherRecord.EducationBackground = editTeacherView.EducationBackground;
            teacherRecord.PhoneNumber = editTeacherView.PhoneNumber;
            teacherRecord.TeachClass = editTeacherView.TeachClass;
            teacherRecord.TeacherResume = editTeacherView.TeacherResume;
            teacherRecord.TeacherDetailInfo = editTeacherView.TeacherDetailInfo;
            teacherRecord.Photo = editTeacherView.Photo;
            teacherRecord.LocationList = editTeacherView.SelectedLocationList;

            bool updateTeacherResult = editTeacherModel.Update(teacherRecord);

            if (updateTeacherResult)
            {
                classScheduleHelper.PopMessage(@"Update teacher success",
                                               @"Update teacher",
                                               MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                classScheduleHelper.PopMessage(@"Update teacher failed",
                                               @"Update teacher",
                                               MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void add_teacher_returns_true_when_successfully_add_a_teacher()
        {
            mockDatabaseManager.Setup(mock => mock.ExecuteInsert(It.IsAny<string>())).Returns(true);

            sut.SetDatabaseManager(mockDatabaseManager.Object);

            TeacherRecord teacher = new TeacherRecord
                                        {
                                            TeacherName = TEACHERNAME,
                                            TeacherSex = TEACHERSEX,
                                            Birthday = BIRTHDAY,
                                            NativePlace = NATIVEPLACE,
                                            WorkPlace = WORKPLACE,
                                            PhotoIDNumber = PHOTOIDNUMBER,
                                            EducationBackground = EDUCATIONBACKGROUND,
                                            GraduateSchool = GRADUATESCHOOL,
                                            PhoneNumber = PHONENUMBER,
                                            TeachClass = TEACHCLASS,
                                            TeacherResume = TEACHERRESUME,
                                            TeacherDetailInfo = TEACHERDETAILINFO,
                                            Photo = PHOTO,
                                            LocationList = LOCATIONLIST
                                        };

            var result = sut.Add(teacher);

            Assert.IsTrue(result);

            string insertString = string.Format("INSERT INTO TeacherTable " +
                                 "(TeacherName, TeacherSex, Birthday, NativePlace, WorkPlace, PhotoIDNumber, " +
                                 "GraduateSchool, EducationBackground, PhoneNumber, TeachClass, TeacherResume, " +
                                 "TeacherDetailInfo, Photo, LocationList) " +
                                 "VALUES ( \'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\'," +
                                 "\'{6}\',\'{7}\',\'{8}\',\'{9}\',\'{10}\'," +
                                 "\'{11}\',\'{12}\',\'{13}\' )",
                                 TEACHERNAME,TEACHERSEX,BIRTHDAY,NATIVEPLACE,WORKPLACE,PHOTOIDNUMBER,
                                 GRADUATESCHOOL,EDUCATIONBACKGROUND,PHONENUMBER, TEACHCLASS, TEACHERRESUME,
                                 TEACHERDETAILINFO,PHOTO,LOCATIONLIST);

            mockDatabaseManager.Verify(mock => mock.ExecuteInsert(insertString), Times.Once());
        }
        private void TeacherView_AddTeacher(object sender, EventArgs e)
        {
            TeacherRecord teacherRecord = new TeacherRecord();

            teacherRecord.TeacherName = TeacherView.TeacherName;
            teacherRecord.TeacherSex = TeacherView.TeacherSex;
            teacherRecord.Birthday = TeacherView.Birthday;
            teacherRecord.NativePlace = TeacherView.NativePlace;
            teacherRecord.WorkPlace = TeacherView.WorkPlace;
            teacherRecord.PhotoIDNumber = TeacherView.PhotoIDNumber;
            teacherRecord.GraduateSchool = TeacherView.GraduateSchool;
            teacherRecord.EducationBackground = TeacherView.EducationBackground;
            teacherRecord.PhoneNumber = TeacherView.PhoneNumber;
            teacherRecord.TeachClass = TeacherView.TeachClass;
            teacherRecord.TeacherResume = TeacherView.TeacherResume;
            teacherRecord.TeacherDetailInfo = TeacherView.TeacherDetailInfo;
            teacherRecord.Photo = TeacherView.Photo;
            teacherRecord.LocationList = TeacherView.SelectedLocationList;

            if (teacherModel.Add(teacherRecord))
                classScheduleHelper.PopMessage("Add Teacher success");
            else
                classScheduleHelper.PopMessage("Add Teacher failed");
        }
 private bool TeacherIsNotValid(TeacherRecord teacherRecord)
 {
     return string.IsNullOrEmpty(teacherRecord.TeacherName)
         || string.IsNullOrEmpty(teacherRecord.TeacherSex);
 }
 private string PrepareUpdateString(TeacherRecord teacherRecord)
 {
     return string.Format("UPDATE TeacherTable " +
                          "SET TeacherName = \'{0}\' , " +
                          "TeacherSex = \'{1}\' , " +
                          "Birthday = \'{2}\' , " +
                          "NativePlace = \'{3}\' , " +
                          "WorkPlace = \'{4}\' , " +
                          "PhotoIDNumber = \'{5}\' , " +
                          "GraduateSchool = \'{6}\' , " +
                          "EducationBackground = \'{7}\' , " +
                          "PhoneNumber = \'{8}\' , " +
                          "TeachClass = \'{9}\' , " +
                          "TeacherResume = \'{10}\' , " +
                          "TeacherDetailInfo = \'{11}\' , " +
                          "Photo = \'{12}\' , " +
                          "LocationList = \'{13}\' " +
                          "WHERE ID = {14}",
                          teacherRecord.TeacherName, teacherRecord.TeacherSex,
                          teacherRecord.Birthday, teacherRecord.NativePlace,
                          teacherRecord.WorkPlace, teacherRecord.PhotoIDNumber,
                          teacherRecord.GraduateSchool, teacherRecord.EducationBackground,
                          teacherRecord.PhoneNumber, teacherRecord.TeachClass,
                          teacherRecord.TeacherResume, teacherRecord.TeacherDetailInfo,
                          teacherRecord.Photo, teacherRecord.LocationList, teacherRecord.ID);
 }
 private string PrepareAddString(TeacherRecord teacherRecord)
 {
     return string.Format("INSERT INTO TeacherTable " +
                          "(TeacherName, TeacherSex, Birthday, NativePlace, WorkPlace, PhotoIDNumber, " +
                          "GraduateSchool, EducationBackground, PhoneNumber, TeachClass, TeacherResume, " +
                          "TeacherDetailInfo, Photo, LocationList) " +
                          "VALUES ( \'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\'," +
                          "\'{6}\',\'{7}\',\'{8}\',\'{9}\',\'{10}\'," +
                          "\'{11}\',\'{12}\',\'{13}\' )",
                          teacherRecord.TeacherName,teacherRecord.TeacherSex,teacherRecord.Birthday,teacherRecord.NativePlace,teacherRecord.WorkPlace,teacherRecord.PhotoIDNumber,
                          teacherRecord.GraduateSchool,teacherRecord.EducationBackground,teacherRecord.PhoneNumber,teacherRecord.TeachClass,teacherRecord.TeacherResume,
                          teacherRecord.TeacherDetailInfo,teacherRecord.Photo, teacherRecord.LocationList);
 }
        private List<TeacherRecord> GetTeacherListFromDataTable(DataTable teacherTable)
        {
            var teacherList = new List<TeacherRecord>();

            if (teacherTable == null)
                return teacherList;

            foreach (DataRow dataRow in teacherTable.Rows)
            {
                var teacherRecord = new TeacherRecord();

                teacherRecord.ID                = dataRow[0].ToString();
                teacherRecord.TeacherName       = dataRow[1].ToString();
                teacherRecord.TeacherSex        = dataRow[2].ToString();
                teacherRecord.Birthday          = dataRow[3].ToString();
                teacherRecord.NativePlace       = dataRow[4].ToString();
                teacherRecord.WorkPlace         = dataRow[5].ToString();
                teacherRecord.PhotoIDNumber     = dataRow[6].ToString();
                teacherRecord.GraduateSchool    = dataRow[7].ToString();
                teacherRecord.EducationBackground = dataRow[8].ToString();
                teacherRecord.PhoneNumber       = dataRow[9].ToString();
                teacherRecord.TeachClass        = dataRow[10].ToString();
                teacherRecord.TeacherResume     = dataRow[11].ToString();
                teacherRecord.TeacherDetailInfo = dataRow[12].ToString();
                teacherRecord.Photo             = dataRow[13].ToString();
                teacherRecord.LocationList      = dataRow[14].ToString();

                teacherList.Add(teacherRecord);
            }

            return teacherList;
        }
        public bool Update(TeacherRecord teacherRecord)
        {
            if (TeacherIsNotValid(teacherRecord))
                return false;

            string updateTeacherString = PrepareUpdateString(teacherRecord);

            return databaseManager.ExecuteUpdate(updateTeacherString);
        }
        public TeacherRecord GetTeacherByID(string teacherID)
        {
            TeacherRecord teacherRecord = new TeacherRecord();

            try
            {
                List<TeacherRecord> teacherList;

                string queryTeacherString = PrepareQueryTeacherByIDString(teacherID);

                var teacherTable = databaseManager.ExecuteQuery(queryTeacherString);

                teacherList = GetTeacherListFromDataTable(teacherTable);

                if (teacherList != null && teacherList.Count > 0)
                    teacherRecord = teacherList[0];
            }
            catch (Exception)
            {
            }

            return teacherRecord;
        }
        public bool Add(TeacherRecord teacherRecord)
        {
            if (TeacherIsNotValid(teacherRecord))
                return false;

            string addTeacherString = PrepareAddString(teacherRecord);

            return databaseManager.ExecuteInsert(addTeacherString);
        }
        public void add_teacher_return_false_when_teacher_is_not_valid()
        {
            mockDatabaseManager.Setup(mock => mock.ExecuteInsert(It.IsAny<string>())).Returns(true);

            sut.SetDatabaseManager(mockDatabaseManager.Object);

            TeacherRecord teacher = new TeacherRecord
            {
                TeacherName = string.Empty,
                TeacherSex = TEACHERSEX,
                Birthday = BIRTHDAY,
                NativePlace = NATIVEPLACE,
                WorkPlace = WORKPLACE,
                PhotoIDNumber = PHOTOIDNUMBER,
                EducationBackground = EDUCATIONBACKGROUND,
                GraduateSchool = GRADUATESCHOOL,
                PhoneNumber = PHONENUMBER,
                TeachClass = TEACHCLASS,
                TeacherResume = TEACHERRESUME,
                TeacherDetailInfo = TEACHERDETAILINFO,
                Photo = PHOTO,
                LocationList = LOCATIONLIST
            };

            var result = sut.Add(teacher);

            Assert.IsFalse(result);

            mockDatabaseManager.Verify(mock => mock.ExecuteInsert(It.IsAny<string>()), Times.Never());
        }
        public void update_teacher_return_true_when_successfully_update_a_teacher()
        {
            TeacherRecord teacherRecord = new TeacherRecord
            {
                ID = "1",
                TeacherName = TEACHERNAME,
                TeacherSex = TEACHERSEX,
                Birthday = BIRTHDAY,
                NativePlace = NATIVEPLACE,
                WorkPlace = WORKPLACE,
                PhotoIDNumber = PHOTOIDNUMBER,
                EducationBackground = EDUCATIONBACKGROUND,
                GraduateSchool = GRADUATESCHOOL,
                PhoneNumber = PHONENUMBER,
                TeachClass = TEACHCLASS,
                TeacherResume = TEACHERRESUME,
                TeacherDetailInfo = TEACHERDETAILINFO,
                Photo = PHOTO,
                LocationList = LOCATIONLIST
            };

            mockDatabaseManager.Setup(foo => foo.ExecuteUpdate(It.IsAny<string>())).Returns(true);
            sut.SetDatabaseManager(mockDatabaseManager.Object);

            var result = sut.Update(teacherRecord);
            Assert.IsTrue(result);

            string updateString = string.Format("UPDATE TeacherTable " +
                                 "SET TeacherName = \'{0}\' , " +
                                 "TeacherSex = \'{1}\' , " +
                                 "Birthday = \'{2}\' , " +
                                 "NativePlace = \'{3}\' , " +
                                 "WorkPlace = \'{4}\' , " +
                                 "PhotoIDNumber = \'{5}\' , " +
                                 "GraduateSchool = \'{6}\' , " +
                                 "EducationBackground = \'{7}\' , " +
                                 "PhoneNumber = \'{8}\' , " +
                                 "TeachClass = \'{9}\' , " +
                                 "TeacherResume = \'{10}\' , " +
                                 "TeacherDetailInfo = \'{11}\' , " +
                                 "Photo = \'{12}\' , " +
                                 "LocationList = \'{13}\' " +
                                 "WHERE ID = {14}",
                                 teacherRecord.TeacherName, teacherRecord.TeacherSex,
                                 teacherRecord.Birthday, teacherRecord.NativePlace,
                                 teacherRecord.WorkPlace, teacherRecord.PhotoIDNumber,
                                 teacherRecord.GraduateSchool, teacherRecord.EducationBackground,
                                 teacherRecord.PhoneNumber, teacherRecord.TeachClass,
                                 teacherRecord.TeacherResume, teacherRecord.TeacherDetailInfo,
                                 teacherRecord.Photo, teacherRecord.LocationList, teacherRecord.ID);

            mockDatabaseManager.Verify(foo => foo.ExecuteUpdate(updateString), Times.Once());
        }