public bool Add(TeacherTrainingScheduleRecord teacherTrainingScheduleRecord)
        {
            if (TeacherTrainingScheduleIsNotValid(teacherTrainingScheduleRecord))
                return false;

            string addTeacherTrainingScheduleString = PrepareAddString(teacherTrainingScheduleRecord);

            return databaseManager.ExecuteInsert(addTeacherTrainingScheduleString);
        }
        private void TeacherTrainingScheduleView_AddTeacherTrainingSchedule(object sender, EventArgs e)
        {
            TeacherTrainingScheduleRecord teacherTrainingScheduleRecord = new TeacherTrainingScheduleRecord();
            List<string> locationList = TeacherTrainingScheduleView.Location;
            List<string> teacherList = TeacherTrainingScheduleView.Teacher;

            if (teacherList != null && teacherList.Count > 0)
            {
                string[] teacherInfo = teacherList[0].Split('|');
                if (teacherInfo != null && teacherInfo.Length > 1)
                {
                    teacherTrainingScheduleRecord.TeacherID = teacherInfo[0];
                    teacherTrainingScheduleRecord.TeacherName = teacherInfo[1];
                }
            }

            if (locationList != null && locationList.Count > 0)
                teacherTrainingScheduleRecord.Location = locationList[0];

            teacherTrainingScheduleRecord.StartTime = TeacherTrainingScheduleView.StartTime;
            teacherTrainingScheduleRecord.EndTime = TeacherTrainingScheduleView.EndTime;
            teacherTrainingScheduleRecord.DetailAddress = TeacherTrainingScheduleView.DetailAddress;
            teacherTrainingScheduleRecord.Expense = TeacherTrainingScheduleView.Expense;

            if (TeacherTrainingScheduleModel.Add(teacherTrainingScheduleRecord))
                classScheduleHelper.PopMessage("Add teacher training schedule success");
            else
                classScheduleHelper.PopMessage("Add teacher training schedule failed");
        }
        private bool TeacherTrainingScheduleIsNotValid(TeacherTrainingScheduleRecord teacherTrainingScheduleRecord)
        {
            if (string.IsNullOrEmpty(teacherTrainingScheduleRecord.TeacherID)   ||
                string.IsNullOrEmpty(teacherTrainingScheduleRecord.TeacherName) ||
                string.IsNullOrEmpty(teacherTrainingScheduleRecord.Location)    ||
                string.IsNullOrEmpty(teacherTrainingScheduleRecord.StartTime)   ||
                string.IsNullOrEmpty(teacherTrainingScheduleRecord.EndTime))
                return true;

            return false;
        }
 private string PrepareUpdateString(TeacherTrainingScheduleRecord teacherTrainingScheduleRecord)
 {
     return string.Format("UPDATE TeacherTrainingScheduleTable " +
                           "SET TeacherID = \'{0}\' , " +
                           "TeacherName = \'{1}\' , " +
                           "Location = \'{2}\' , " +
                           "DetailAddress = \'{3}\' , " +
                           "StartTime = \'{4}\' , " +
                           "EndTime = \'{5}\' , " +
                           "Expense = \'{6}\'" +
                           "WHERE ID = {7}",
                           teacherTrainingScheduleRecord.TeacherID, teacherTrainingScheduleRecord.TeacherName,
                           teacherTrainingScheduleRecord.Location, teacherTrainingScheduleRecord.DetailAddress,
                           teacherTrainingScheduleRecord.StartTime, teacherTrainingScheduleRecord.EndTime,
                           teacherTrainingScheduleRecord.Expense, teacherTrainingScheduleRecord.ID);
 }
 private string PrepareAddString(TeacherTrainingScheduleRecord teacherTrainingScheduleRecord)
 {
     return string.Format("INSERT INTO TeacherTrainingScheduleTable " +
                          "(TeacherID, TeacherName, Location, DetailAddress, StartTime, EndTime, Expense) "+
                          "VALUES ( \'{0}\',\'{1}\',\'{2}\',\'{3}\',\'{4}\',\'{5}\',\'{6}\' )",
                          teacherTrainingScheduleRecord.TeacherID, teacherTrainingScheduleRecord.TeacherName,
                          teacherTrainingScheduleRecord.Location,  teacherTrainingScheduleRecord.DetailAddress,
                          teacherTrainingScheduleRecord.StartTime, teacherTrainingScheduleRecord.EndTime,
                          teacherTrainingScheduleRecord.Expense);
 }
        private List<TeacherTrainingScheduleRecord> GetTeacherTrainingScheduleListFromDataTable(DataTable teacherTrainingScheduleTable)
        {
            var teacherTrainingScheduleList = new List<TeacherTrainingScheduleRecord>();

            if (teacherTrainingScheduleTable == null)
                return teacherTrainingScheduleList;

            foreach (DataRow dataRow in teacherTrainingScheduleTable.Rows)
            {
                var teacherTrainingScheduleRecord = new TeacherTrainingScheduleRecord();

                teacherTrainingScheduleRecord.ID = dataRow[0].ToString();
                teacherTrainingScheduleRecord.TeacherID = dataRow[1].ToString();
                teacherTrainingScheduleRecord.TeacherName = dataRow[2].ToString();
                teacherTrainingScheduleRecord.Location = dataRow[3].ToString();
                teacherTrainingScheduleRecord.DetailAddress = dataRow[4].ToString();
                teacherTrainingScheduleRecord.StartTime = dataRow[5].ToString();
                teacherTrainingScheduleRecord.EndTime = dataRow[6].ToString();
                teacherTrainingScheduleRecord.Expense = dataRow[7].ToString();

                teacherTrainingScheduleList.Add(teacherTrainingScheduleRecord);
            }

            return teacherTrainingScheduleList;
        }
        public bool Update(TeacherTrainingScheduleRecord teacherTrainingScheduleRecord)
        {
            if (TeacherTrainingScheduleIsNotValid(teacherTrainingScheduleRecord))
                return false;

            string updateTeacherTrainingScheduleString = PrepareUpdateString(teacherTrainingScheduleRecord);

            return databaseManager.ExecuteUpdate(updateTeacherTrainingScheduleString);
        }