public AttendanceMeg(UDTCourseDef Course) { //課程Record記錄 _Course = Course; //本課程的修課學生 _StudentList = _accessHelper.Select<UDTScselectDef>("ref_course_id=" + _Course.UID); _StudentList.Sort(SortScselect); StudentDic = GetStudentRecord(); //上課日期,與節次 _TimeSectionList = _accessHelper.Select<UDTTimeSectionDef>("ref_course_id=" + Course.UID); //取得本課程學生的所有缺曠記錄 // 加入判斷當課程沒有修課學生處理 if (_StudentIDList.Count > 0) AttendanceList = _accessHelper.Select<UDTAttendanceDef>("ref_student_id in ('" + string.Join("','", _StudentIDList) + "') and ref_course_id=" + _Course.UID); else AttendanceList = new List<UDTAttendanceDef>(); }
private void btnSave_Click(object sender, EventArgs e) { try { if (CheckData()) { UDTCourseDef courseData = new UDTCourseDef(); // 畫面上資訊 courseData.CourseName = txtCourseName.Text; if (Global._TeacherNameIDDict.ContainsKey(cbxCourseTeacher.Text)) courseData.RefTeacherID = Global._TeacherNameIDDict[cbxCourseTeacher.Text]; courseData.SubjectName = txtSubjectName.Text; if (string.IsNullOrWhiteSpace(txtSubjectLevel.Text)) courseData.SubjectLevel = null; else courseData.SubjectLevel = int.Parse(txtSubjectLevel.Text); courseData.Credit = int.Parse(txtCredit.Text); courseData.SubjectType = cbxSubjectType.Text; courseData.DeptName = cbxDeptName.Text; courseData.SchoolYear = iptSchoolYear.Value; courseData.Semester = iptSemester.Value; courseData.Month = iptMonth.Value; List<UDTCourseDef> dataList = new List<UDTCourseDef>(); dataList.Add(courseData); UDTTransfer.UDTCourseInsert(dataList); // 檢查名冊是否已有,沒有新增一筆 bool addData = true; foreach (UDTTimeListDef data in _AllTimeList) { if (data.SchoolYear == iptSchoolYear.Value && data.Semester == iptSemester.Value && data.Month == iptMonth.Value) { addData = false; break; } } if (addData) { List<UDTTimeListDef> addList = new List<UDTTimeListDef>(); UDTTimeListDef da = new UDTTimeListDef(); da.SchoolYear = iptSchoolYear.Value; da.Semester = iptSemester.Value; da.Month = iptMonth.Value; da.Name = iptSchoolYear.Value + "學年度第" + iptSemester.Value + "學期" + iptMonth.Value + "梯次"; addList.Add(da); UDTTransfer.UDTTimeListInsert(addList); } FISCA.Presentation.Controls.MsgBox.Show("儲存完成."); RetakeEvents.RaiseAssnChanged(); this.Close(); } } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show("新增課程過程發生錯誤"+ex.Message); } }
private int SortCourse(UDTCourseDef a, UDTCourseDef b) { return a.CourseName.CompareTo(b.CourseName); }
/// <summary> /// 執行分批匯入 /// </summary> /// <param name="Rows">IRowStream集合</param> /// <returns>回傳分批匯入執行完成訊息</returns> public override string Import(List<IRowStream> Rows) { mTask.Wait(); mstrLog.Clear(); if (mOption.SelectedKeyFields.Count == 4 && mOption.SelectedKeyFields.Contains(constSchoolYear) && mOption.SelectedKeyFields.Contains(constSemester) && mOption.SelectedKeyFields.Contains(constCourseName) && mOption.SelectedKeyFields.Contains(constMonth)) { #region 取得已存在的排課課程資料 List<UDTCourseDef> mCourseExtensions = new List<UDTCourseDef>(); List<string> CourseIDs = new List<string>(); foreach (IRowStream Row in Rows) { string CourseName = Row.GetValue(constCourseName); string SchoolYear = Row.GetValue(constSchoolYear); string Semester = Row.GetValue(constSemester); string Month = Row.GetValue(constMonth); //根據課程名稱、學年度及學期尋找是否有對應的課程 string CourseKey = CourseName + "," + SchoolYear + "," + Semester + "," + Month; string CourseID = mCourseNameIDs.ContainsKey(CourseKey) ? mCourseNameIDs[CourseKey] : string.Empty; if (!string.IsNullOrEmpty(CourseID)) CourseIDs.Add(CourseID); } string CourseIDsCondition = string.Join(",", CourseIDs.ToArray()); if (!string.IsNullOrEmpty(CourseIDsCondition)) mCourseExtensions = mHelper.Select<UDTCourseDef>("uid in (" + CourseIDsCondition + ")"); #endregion if (mOption.Action == ImportAction.Update) { #region Step2:針對每筆匯入每筆資料檢查,判斷是新增或是更新 List<UDTCourseDef> InsertRecords = new List<UDTCourseDef>(); List<UDTCourseDef> UpdateRecords = new List<UDTCourseDef>(); foreach (IRowStream Row in Rows) { string CourseName = Row.GetValue(constCourseName); string SchoolYear = Row.GetValue(constSchoolYear); string Semester = Row.GetValue(constSemester); string Month = Row.GetValue(constMonth); //根據課程名稱、學年度及學期尋找是否有對應的課程 string CourseKey = CourseName + "," + SchoolYear + "," + Semester + "," + Month; int? CourseID = null; UDTCourseDef vCourseExtension = null; if (mCourseNameIDs.ContainsKey(CourseKey)) CourseID = K12.Data.Int.ParseAllowNull(mCourseNameIDs[CourseKey]); if (CourseID.HasValue) { //尋找是否有對應的課程排課資料 vCourseExtension = mCourseExtensions .Find(x => x.UID.Equals(K12.Data.Int.GetString(CourseID))); if (vCourseExtension != null) { if (mOption.SelectedFields.Contains(constSubjectType)) vCourseExtension.SubjectType = Row.GetValue(constSubjectType); if (mOption.SelectedFields.Contains(constSubject)) vCourseExtension.SubjectName = Row.GetValue(constSubject); if (mOption.SelectedFields.Contains(constSubjectLevel)) vCourseExtension.SubjectLevel = K12.Data.Int.ParseAllowNull(Row.GetValue(constSubjectLevel)); if (mOption.SelectedFields.Contains(constCredit)) vCourseExtension.Credit = K12.Data.Int.Parse(Row.GetValue(constCredit)); if (mOption.SelectedFields.Contains(constDept)) vCourseExtension.DeptName = Row.GetValue(constDept); if (mOption.SelectedFields.Contains(constTeacherName)) { string TeacherName = Row.GetValue(constTeacherName); if (mTeacherNameIDs.ContainsKey(TeacherName)) vCourseExtension.RefTeacherID = K12.Data.Int.Parse(mTeacherNameIDs[TeacherName]); } UpdateRecords.Add(vCourseExtension); } #endregion } #region 新增CourseExtension else { vCourseExtension = new UDTCourseDef(); vCourseExtension.SchoolYear = K12.Data.Int.Parse(Row.GetValue(constSchoolYear)); vCourseExtension.Semester = K12.Data.Int.Parse(Row.GetValue(constSemester)); vCourseExtension.Month = K12.Data.Int.Parse(Row.GetValue(constMonth)); vCourseExtension.CourseName = Row.GetValue(constCourseName); if (mOption.SelectedFields.Contains(constSubjectType)) vCourseExtension.SubjectType = Row.GetValue(constSubjectType); if (mOption.SelectedFields.Contains(constSubject)) vCourseExtension.SubjectName = Row.GetValue(constSubject); if (mOption.SelectedFields.Contains(constSubjectLevel)) vCourseExtension.SubjectLevel = K12.Data.Int.ParseAllowNull(Row.GetValue(constSubjectLevel)); if (mOption.SelectedFields.Contains(constCredit)) vCourseExtension.Credit = K12.Data.Int.Parse(Row.GetValue(constCredit)); if (mOption.SelectedFields.Contains(constDept)) vCourseExtension.DeptName = Row.GetValue(constDept); if (mOption.SelectedFields.Contains(constTeacherName)) { string TeacherName = Row.GetValue(constTeacherName); if (mTeacherNameIDs.ContainsKey(TeacherName)) vCourseExtension.RefTeacherID = K12.Data.Int.Parse(mTeacherNameIDs[TeacherName]); } InsertRecords.Add(vCourseExtension); } #endregion } #region Step3:實際新增或更新資料 if (InsertRecords.Count > 0) { List<string> NewIDs = mHelper.InsertValues(InsertRecords); mstrLog.AppendLine("已新增" + InsertRecords.Count + "筆課程資料。"); //在新增完後不需更新mCourseExtensions變數,因為來源資料不允許相同的課程重覆做新增 } if (UpdateRecords.Count > 0) { mHelper.UpdateValues(UpdateRecords); mstrLog.AppendLine("已更新" + UpdateRecords.Count + "筆課程資料。"); //在更新完後不需更新mCourseExtensions變數,因為來源資料不允許相同的課程重覆做更新 } #endregion } } // else if (mOption.Action == ImportAction.Delete) // { // #region 刪除資料 // ////要刪除的排課課程資料 // //List<CourseExtension> DeleteRecords = new List<CourseExtension>(); // ////針對每筆記錄 // //foreach (IRowStream Row in Rows) // //{ // // //取得鍵值為課程名稱、學年度及學期 // // string CourseName = Row.GetValue(constCourseName); // // string SchoolYear = Row.GetValue(constSchoolYear); // // string Semester = Row.GetValue(constSemester); // // //根據課程名稱、學年度及學期尋找是否有對應的課程 // // string CourseKey = CourseName + "," + SchoolYear + "," + Semester; // // string CourseID = mCourseNameIDs.ContainsKey(CourseKey) ? mCourseNameIDs[CourseKey] : string.Empty; // // //若有找到課程資料 // // if (!string.IsNullOrEmpty(CourseID)) // // { // // //尋找是否有對應的排課課程資料 // // CourseExtension vCourseExtension = mCourseExtensions // // .Find(x => x.CourseID.Equals(K12.Data.Int.Parse(CourseID))); // // //若有找到則加入到刪除的集合中 // // if (vCourseExtension != null) // // DeleteRecords.Add(vCourseExtension); // // } // //} // ////若是要刪除的集合大於0才執行 // //if (DeleteRecords.Count > 0) // //{ // // //mHelper.DeletedValues(DeleteRecords); // // //mstrLog.AppendLine("已刪除"+DeleteRecords.Count+"筆排課課程資料。"); // // //在刪除完後不需更新mCourseExtensions變數,因為來源資料不允許相同的課程重覆做刪除 // //} // #endregion // } //} return mstrLog.ToString(); }
void _bgWorker_DoWork(object sender, DoWorkEventArgs e) { foreach (UDTCourseDef data in UDTTransfer.UDTCourseSelectUIDs(_CourseID)) _CourseData = data; // 取得課程 CourseList = UDTTransfer.UDTCourseSelectAllDict().Values.ToList(); }
void _bgWorkerCreateData_DoWork(object sender, DoWorkEventArgs e) { // 清空原有舊資料 // 課程 if (_DelCourseIDList.Count > 0) { List<UDTCourseDef> delCourseList = new List<UDTCourseDef>(); foreach (UDTCourseDef data in _hasCourseDefList) { int coid = int.Parse(data.UID); if (_DelCourseIDList.Contains(coid)) delCourseList.Add(data); } UDTTransfer.UDTCourseDelete(delCourseList); // 課程修課 List<UDTScselectDef> delScselect = new List<UDTScselectDef>(); foreach (UDTScselectDef data in _hasScselectDefList) if (_DelCourseIDList.Contains(data.CourseID)) delScselect.Add(data); UDTTransfer.UDTSCSelectDelete(delScselect); // 課程時間區間 List<UDTTimeSectionDef> delTimeSectionList = new List<UDTTimeSectionDef>(); foreach (UDTTimeSectionDef data in _hasTimeSectionDefList) if (_DelCourseIDList.Contains(data.CourseID)) delTimeSectionList.Add(data); UDTTransfer.UDTTimeSectionDelete(delTimeSectionList); // 課程缺曠 List<UDTAttendanceDef> delAttendanceList = new List<UDTAttendanceDef>(); foreach (UDTAttendanceDef data in _hasAttendanceDefList) if (_DelCourseIDList.Contains(data.CourseID)) delAttendanceList.Add(data); UDTTransfer.UDTAttendanceDelete(delAttendanceList); } // 新增課程使用 List<UDTCourseDef> InsertCourseList = new List<UDTCourseDef>(); // 取得新增後課程使用 List<UDTCourseDef> NewInsertedCourseList = new List<UDTCourseDef>(); // 新增時間區間使用 List<UDTTimeSectionDef> InsertTimeSectionList = new List<UDTTimeSectionDef>(); // 新增修課學生 List<UDTScselectDef> InsertSCSelectList = new List<UDTScselectDef>(); List<string> courseNameAdd = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J","L","M","N","O","P" }.ToList(); // 產生課程資料 foreach (SubjectCourseBase scb in _SubjectCourseBaseList) { for (int i = 0; i < scb.CreateCount; i++) { UDTCourseDef data = new UDTCourseDef(); data.SchoolYear = scb.SchoolYear; data.Semester = scb.Semester; data.Month = scb.Month; data.Credit = scb.Credit; data.SubjectType = scb.SubjectType; data.SubjectName = scb.SubjectName; data.SubjectLevel = scb.SubjectLevel; data.DeptName = scb.DeptName; // 課程名稱使用科目名稱加級別 if (data.SubjectLevel.HasValue) data.CourseName = scb.SubjectName + QueryData.GetNumber(scb.SubjectLevel.Value.ToString()) +courseNameAdd[i]; else data.CourseName = scb.SubjectName + courseNameAdd[i]; InsertCourseList.Add(data); scb.CourseNameList.Add(data.CourseName); } } // 課程名稱與ID對照 Dictionary<string, int> courseIDDict = new Dictionary<string, int>(); if (InsertCourseList.Count > 0) { // 新增課程並取回新增的課程資料 List<string> CIDList = UDTTransfer.UDTCourseInsert(InsertCourseList); NewInsertedCourseList = UDTTransfer.UDTCourseSelectUIDs(CIDList); // 課程名稱與ID對照 foreach (UDTCourseDef data in NewInsertedCourseList) { if (!courseIDDict.ContainsKey(data.CourseName)) courseIDDict.Add(data.CourseName, int.Parse(data.UID)); } // 建立時間區間 // 取得日期 List<DateTime> dateList = new List<DateTime>(); foreach (DataGridViewRow drv in dgDate.Rows) dateList.Add((DateTime)drv.Tag); // 處理時間區間 foreach (SubjectCourseBase scb in _SubjectCourseBaseList) { if (scb.PeriodXml == null) continue; List<int> PeriodList = new List<int>(); foreach (XElement elm in scb.PeriodXml.Elements("Period")) PeriodList.Add(int.Parse(elm.Value)); // 課程名稱 foreach (string courseName in scb.CourseNameList) { if (courseIDDict.ContainsKey(courseName)) { int cid = courseIDDict[courseName]; foreach (DateTime dt in dateList) { foreach (int per in PeriodList) { UDTTimeSectionDef dataTs = new UDTTimeSectionDef(); dataTs.CourseID = cid; dataTs.Period = per; dataTs.Date = dt; InsertTimeSectionList.Add(dataTs); } } } } } // 新增寫入時間區間 if (InsertTimeSectionList.Count > 0) UDTTransfer.UDTTimeSectionInsert(InsertTimeSectionList); // 新增修課學生 foreach (SubjectCourseBase scb in _SubjectCourseBaseList) { if (scb.CreateCount < 1) continue; int MaxStudCount = scb.MaxStudentCount; int NewCount = (int)Math.Round(((decimal)scb.StudentIDList.Count / (decimal)scb.CreateCount), 0); if (NewCount > MaxStudCount) MaxStudCount = NewCount; List<int> cousreIDList = new List<int>(); foreach (string name in scb.CourseNameList) { if (courseIDDict.ContainsKey(name)) cousreIDList.Add(courseIDDict[name]); } // 修課學生 int courseIdx = 0, seatno = 1; if (cousreIDList.Count > 0) { foreach (SubjectCourseStudentBase stud in scb.StudentIDList) { if (seatno > MaxStudCount) { seatno = 1; courseIdx++; } UDTScselectDef scselect = new UDTScselectDef(); scselect.CourseID = cousreIDList[courseIdx]; scselect.SeatNo = seatno; scselect.StudentID = stud.StudentID; scselect.Type = stud.Type; InsertSCSelectList.Add(scselect); seatno++; } } } // 新增修課學生 if (InsertSCSelectList.Count > 0) { UDTTransfer.UDTSCSelectInsert(InsertSCSelectList); } } }