private void btnInsert_Click(object sender, EventArgs e) { DAO.StudentFitnessRecord rec = new DAO.StudentFitnessRecord(); rec.StudentID = PrimaryKey; rec.SchoolYear = int.Parse(K12.Data.School.DefaultSchoolYear); rec.TestDate = DateTime.Today; Forms.FrmFitnessRecord frm = new Forms.FrmFitnessRecord(rec, Forms.FrmFitnessRecord.accessType.Insert); if (frm.ShowDialog() == DialogResult.OK) { _BGRun(); } }
public FrmFitnessRecord(DAO.StudentFitnessRecord rec, accessType actType) { InitializeComponent(); _studRec = Student.SelectByID(rec.StudentID); _fitnessRec = rec; _actType = actType; _LogTransfer = new Log.LogTransfer(); if(_actType == accessType.Edit) this.TitleText = _FrmTitleEdit; else this.TitleText = _FrmTitleAdd; }
public FrmFitnessRecord(DAO.StudentFitnessRecord rec, accessType actType) { InitializeComponent(); _studRec = Student.SelectByID(rec.StudentID); _fitnessRec = rec; _actType = actType; _LogTransfer = new Log.LogTransfer(); if (_actType == accessType.Edit) { this.TitleText = _FrmTitleEdit; } else { this.TitleText = _FrmTitleAdd; } }
private void btnUpdate_Click(object sender, EventArgs e) { if (lvFitnessList.SelectedItems.Count > 0) { DAO.StudentFitnessRecord rec = lvFitnessList.SelectedItems[0].Tag as DAO.StudentFitnessRecord; if (rec != null) { Forms.FrmFitnessRecord frm = new Forms.FrmFitnessRecord(rec, Forms.FrmFitnessRecord.accessType.Edit); if (frm.ShowDialog() == DialogResult.OK) { _BGRun(); } } } else { FISCA.Presentation.Controls.MsgBox.Show("請選擇資料."); } }
public FrmFitnessRecord(DAO.StudentFitnessRecord rec, accessType actType) { InitializeComponent(); _studRec = Student.SelectByID(rec.StudentID); _fitnessRec = rec; _actType = actType; _LogTransfer = new Log.LogTransfer(); if (_actType == accessType.Edit) { this.Text = _FrmTitleEdit; //修改模式無法變更學年度 this.integerInput1.Enabled = false; } else { this.Text = _FrmTitleAdd; } }
private ListViewItem ConvertToListViewItem(DAO.StudentFitnessRecord rec) { ListViewItem item = new ListViewItem(); item.Tag = rec; // 學年度 item.Text = rec.SchoolYear.ToString(); // 測驗日期 item.SubItems.Add(rec.TestDate.ToShortDateString()); // 學校類別 item.SubItems.Add(rec.SchoolCategory); // 身高 item.SubItems.Add(rec.Height); // 身高常模 item.SubItems.Add(rec.HeightDegree); // 體重 item.SubItems.Add(rec.Weight); // 體重常模 item.SubItems.Add(rec.WeightDegree); // 坐姿體前彎 item.SubItems.Add(rec.SitAndReach); // 坐姿體前彎常模 item.SubItems.Add(rec.SitAndReachDegree); // 立定跳遠 item.SubItems.Add(rec.StandingLongJump); // 立定跳遠常模 item.SubItems.Add(rec.StandingLongJumpDegree); // 仰臥起坐 item.SubItems.Add(rec.SitUp); // 仰臥起坐常模 item.SubItems.Add(rec.SitUpDegree); // 心肺適能 item.SubItems.Add(rec.Cardiorespiratory); // 心肺適能常模 item.SubItems.Add(rec.CardiorespiratoryDegree); return(item); }
private void btnDelete_Click(object sender, EventArgs e) { if (lvFitnessList.SelectedItems.Count > 0) { DAO.StudentFitnessRecord rec = lvFitnessList.SelectedItems[0].Tag as DAO.StudentFitnessRecord; if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除體適能紀錄?", "刪除體適能紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey); string studStr = "學號:" + studRec.StudentNumber + ",姓名:" + studRec.Name + ","; Log.LogTransfer LogTransfer = new Log.LogTransfer(); Utility.SetLogData(LogTransfer, rec); LogTransfer.SaveDeleteLog("學生.體適能-刪除", "刪除", studStr, "", "student", studRec.ID); DAO.StudentFitness.DeleteByRecord(rec); _BGRun(); } } else { FISCA.Presentation.Controls.MsgBox.Show("請選擇資料."); } }
/// <summary> /// 主要是給匯出時用的 /// </summary> /// <param name="studentRecord"></param> /// <param name="fitnessRecord"></param> /// <param name="isExportDegree"></param> public void SetDataForExport(DAO.StudentInfo studentRecord, DAO.StudentFitnessRecord fitnessRecord, bool isExportDegree) { // 測驗日期 SetColumnValue("測驗日期", Utility.ConvertDateTimeToChineseDateTime(fitnessRecord.TestDate)); // 學校類別 SetColumnValue("學校類別", fitnessRecord.SchoolCategory); // 年級 SetColumnValue("年級", studentRecord.Class_Grade_Year); // 班級名稱 SetColumnValue("班級名稱", studentRecord.Class_Class_Name); // 班級序號 for sort SetOthersValue("班級序號", studentRecord.Class_Display_Order); // 學號/座號 SetColumnValue("學號/座號", studentRecord.Student_Student_Number); // 性別 SetColumnValue("性別", studentRecord.Student_Gender); // 身分證字號 SetColumnValue("身分證字號", studentRecord.Student_ID_Number); // 生日 SetColumnValue("生日", studentRecord.Student_Birthday); // 身高 SetColumnValue("身高", fitnessRecord.Height); // 體重 SetColumnValue("體重", fitnessRecord.Weight); // 坐姿體前彎 SetColumnValue("坐姿體前彎", fitnessRecord.SitAndReach); // 立定跳遠 SetColumnValue("立定跳遠", fitnessRecord.StandingLongJump); // 仰臥起坐 SetColumnValue("仰臥起坐", fitnessRecord.SitUp); // 心肺適能 SetColumnValue("心肺適能", fitnessRecord.Cardiorespiratory); // 姓名 for sort SetOthersValue("姓名", studentRecord.Student_Name); if (isExportDegree == true) { // 身高常模 SetColumnValue("身高常模", fitnessRecord.HeightDegree); // 體重常模 SetColumnValue("體重常模", fitnessRecord.WeightDegree); // 坐姿體前彎常模 SetColumnValue("坐姿體前彎常模", fitnessRecord.SitAndReachDegree); // 立定跳遠常模 SetColumnValue("立定跳遠常模", fitnessRecord.StandingLongJumpDegree); // 仰臥起坐常模 SetColumnValue("仰臥起坐常模", fitnessRecord.SitUpDegree); // 心肺適能常模 SetColumnValue("心肺適能常模", fitnessRecord.CardiorespiratoryDegree); } }
/// <summary> /// 主要是給匯出時用的 /// </summary> /// <param name="classRecord"></param> /// <param name="studentRecord"></param> /// <param name="fitnessRecord"></param> public void SetDataForExport(ClassRecord classRecord, StudentRecord studentRecord, DAO.StudentFitnessRecord fitnessRecord, bool isExportDegree) { // 測驗日期 SetColumnValue("測驗日期", Utility.ConvertDateTimeToChineseDateTime(fitnessRecord.TestDate)); // 學校類別 SetColumnValue("學校類別", fitnessRecord.SchoolCategory); if (classRecord != null) { // 年級 if (classRecord.GradeYear.HasValue) { SetColumnValue("年級", classRecord.GradeYear.Value.ToString()); } // 班級名稱 SetColumnValue("班級名稱", classRecord.Name); // 班級序號 for sort SetOthersValue("班級序號", classRecord.DisplayOrder); } // 學號/座號 SetColumnValue("學號/座號", studentRecord.StudentNumber); // 性別 SetColumnValue("性別", Utility.ConvertDBGenderToOutGender(studentRecord.Gender)); // 身分證字號 SetColumnValue("身分證字號", studentRecord.IDNumber); // 生日 SetColumnValue("生日", Utility.ConvertDateTimeToChineseDateTime(studentRecord.Birthday)); // 身高 SetColumnValue("身高", fitnessRecord.Height); // 體重 SetColumnValue("體重", fitnessRecord.Weight); // 坐姿體前彎 SetColumnValue("坐姿體前彎", fitnessRecord.SitAndReach); // 立定跳遠 SetColumnValue("立定跳遠", fitnessRecord.StandingLongJump); // 仰臥起坐 SetColumnValue("仰臥起坐", fitnessRecord.SitUp); // 心肺適能 SetColumnValue("心肺適能", fitnessRecord.Cardiorespiratory); // 姓名 for sort SetOthersValue("姓名", studentRecord.Name); if (isExportDegree == true) { // 身高常模 SetColumnValue("身高常模", fitnessRecord.HeightDegree); // 體重常模 SetColumnValue("體重常模", fitnessRecord.WeightDegree); // 坐姿體前彎常模 SetColumnValue("坐姿體前彎常模", fitnessRecord.SitAndReachDegree); // 立定跳遠常模 SetColumnValue("立定跳遠常模", fitnessRecord.StandingLongJumpDegree); // 仰臥起坐常模 SetColumnValue("仰臥起坐常模", fitnessRecord.SitUpDegree); // 心肺適能常模 SetColumnValue("心肺適能常模", fitnessRecord.CardiorespiratoryDegree); } }
public override string Import(List<IRowStream> Rows) { _InsertRecList.Clear(); _UpdateRecList.Clear(); // 取得 Rows內學號, 學年度 List<string> StudentNumberList = new List<string>(); Dictionary<string, string> SchoolYearDic = new Dictionary<string, string>(); foreach (IRowStream row in Rows) { string StudentNumber = Utility.GetIRowValueString(row, "學號"); string SchoolYear = Utility.GetIRowValueString(row, "學年度"); if (string.IsNullOrEmpty(StudentNumber)) continue; if (string.IsNullOrEmpty(SchoolYear)) continue; StudentNumberList.Add(StudentNumber); if (!SchoolYearDic.ContainsKey(SchoolYear)) { SchoolYearDic.Add(SchoolYear, ""); } } // 透過學號去取得學生ID Dictionary<string, string> StudNumDict = DAO.FDQuery.GetStudenIdDictByStudentNumber(StudentNumberList); // 根據學年度, 學生ID取得體適能的資料 List<DAO.StudentFitnessRecord> fitnessRecList = DAO.StudentFitness.SelectByStudentIDListAndSchoolYear(StudNumDict.Values.ToList<string>(), SchoolYearDic.Keys.ToList<string>()); int totalCount = 0; // 判斷每一筆資料是要新增還是更新 foreach(IRowStream row in Rows) { totalCount++; this.ImportProgress = totalCount; bool isInsert = true; // 用來判斷此筆資料是否要新增 DAO.StudentFitnessRecord fitnessRec = new DAO.StudentFitnessRecord(); string StudentNumber = Utility.GetIRowValueString(row, "學號"); int? SchoolYear = Utility.GetIRowValueInt(row, "學年度"); DateTime? TestDate = Utility.GetIRowValueDateTime(row, "測驗日期"); // 如果"學號"或"學年度"或"測驗日期"沒有資料, 換到下一筆 if(string.IsNullOrEmpty(StudentNumber)) continue; if(!SchoolYear.HasValue) continue; if(!TestDate.HasValue) continue; // 透過學號換成學生ID string StudentID = ""; if(StudNumDict.ContainsKey(StudentNumber)) { StudentID = StudNumDict[StudentNumber]; } else { // 如果無法取得學生ID, 就換到下一筆 continue; } // 判斷此筆資料是否已在DB foreach(DAO.StudentFitnessRecord rec in fitnessRecList) { if (rec.SchoolYear == SchoolYear && rec.StudentID == StudentID && rec.TestDate == TestDate) { isInsert = false; fitnessRec = rec; break; } } // 新增資料 if(isInsert == true) { #region 處理新增資料 // 學生系統編號 fitnessRec.StudentID = StudentID; // 學年度 fitnessRec.SchoolYear = SchoolYear.Value; // 測驗日期 fitnessRec.TestDate = TestDate.Value; // 學校類別 fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別"); // 身高 fitnessRec.Height = Utility.GetIRowValueString(row, "身高"); // 身高常模 fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模"); // 體重 fitnessRec.Weight = Utility.GetIRowValueString(row, "體重"); // 體重常模 fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模"); // 坐姿體前彎 fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎"); // 坐姿體前彎常模 fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模"); // 立定跳遠 fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠"); // 立定跳遠常模 fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模"); // 仰臥起坐 fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐"); // 仰臥起坐常模 fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模"); // 心肺適能 fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能"); // 心肺適能常模 fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模"); #endregion } // 更新資料 else { #region 處理更新資料 // "學號/座號", "學年度", "測驗日期" 無法更新 // 學校類別 if (_Option.SelectedFields.Contains("學校類別")) fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別"); // 身高 if (_Option.SelectedFields.Contains("身高")) fitnessRec.Height = Utility.GetIRowValueString(row, "身高"); // 身高常模 if (_Option.SelectedFields.Contains("身高常模")) fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模"); // 體重 if (_Option.SelectedFields.Contains("體重")) fitnessRec.Weight = Utility.GetIRowValueString(row, "體重"); // 體重常模 if (_Option.SelectedFields.Contains("體重常模")) fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模"); // 坐姿體前彎 if (_Option.SelectedFields.Contains("坐姿體前彎")) fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎"); // 坐姿體前彎常模 if (_Option.SelectedFields.Contains("坐姿體前彎常模")) fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模"); // 立定跳遠 if (_Option.SelectedFields.Contains("立定跳遠")) fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠"); // 立定跳遠常模 if (_Option.SelectedFields.Contains("立定跳遠常模")) fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模"); // 仰臥起坐 if (_Option.SelectedFields.Contains("仰臥起坐")) fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐"); // 仰臥起坐常模 if (_Option.SelectedFields.Contains("仰臥起坐常模")) fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模"); // 心肺適能 if (_Option.SelectedFields.Contains("心肺適能")) fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能"); // 心肺適能常模 if (_Option.SelectedFields.Contains("心肺適能常模")) fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模"); #endregion } if(isInsert == true) _InsertRecList.Add(fitnessRec); else _UpdateRecList.Add(fitnessRec); } // end of 判斷每一筆資料是要新增還是更新 // 執行更新或新增 if (_InsertRecList.Count >0 ) DAO.StudentFitness.InsertByRecordList(_InsertRecList); if (_UpdateRecList.Count > 0) DAO.StudentFitness.UpdateByRecordList(_UpdateRecList); // Log Log.LogTransfer logTransfer = new Log.LogTransfer(); StringBuilder logData = new StringBuilder(); int insertCnt = _InsertRecList.Count; int updateCnt = _UpdateRecList.Count; logData.Append("總共匯入").Append((insertCnt + updateCnt)).Append("筆,"); logData.Append("新增:").Append(insertCnt).Append("筆,"); logData.Append("更新:").Append(updateCnt).Append("筆"); logTransfer.SaveLog("學生.體適能-匯入", "匯入", "student", "", logData); return ""; }
public override string Import(List <IRowStream> Rows) { _InsertRecList.Clear(); _UpdateRecList.Clear(); // 取得 Rows內學號, 學年度 List <string> StudentNumberList = new List <string>(); Dictionary <string, string> SchoolYearDic = new Dictionary <string, string>(); foreach (IRowStream row in Rows) { string StudentNumber = Utility.GetIRowValueString(row, "學號"); string SchoolYear = Utility.GetIRowValueString(row, "學年度"); if (string.IsNullOrEmpty(StudentNumber)) { continue; } if (string.IsNullOrEmpty(SchoolYear)) { continue; } StudentNumberList.Add(StudentNumber); if (!SchoolYearDic.ContainsKey(SchoolYear)) { SchoolYearDic.Add(SchoolYear, ""); } } // 透過學號去取得學生ID Dictionary <string, string> StudNumDict = DAO.FDQuery.GetStudenIdDictByStudentNumber(StudentNumberList); // 根據學年度, 學生ID取得體適能的資料 List <DAO.StudentFitnessRecord> fitnessRecList = DAO.StudentFitness.SelectByStudentIDListAndSchoolYear(StudNumDict.Values.ToList <string>(), SchoolYearDic.Keys.ToList <string>()); int totalCount = 0; // 判斷每一筆資料是要新增還是更新 foreach (IRowStream row in Rows) { totalCount++; this.ImportProgress = totalCount; bool isInsert = true; // 用來判斷此筆資料是否要新增 DAO.StudentFitnessRecord fitnessRec = new DAO.StudentFitnessRecord(); string StudentNumber = Utility.GetIRowValueString(row, "學號"); int? SchoolYear = Utility.GetIRowValueInt(row, "學年度"); DateTime?TestDate = Utility.GetIRowValueDateTime(row, "測驗日期"); // 如果"學號"或"學年度"或"測驗日期"沒有資料, 換到下一筆 if (string.IsNullOrEmpty(StudentNumber)) { continue; } if (!SchoolYear.HasValue) { continue; } if (!TestDate.HasValue) { continue; } // 透過學號換成學生ID string StudentID = ""; if (StudNumDict.ContainsKey(StudentNumber)) { StudentID = StudNumDict[StudentNumber]; } else { // 如果無法取得學生ID, 就換到下一筆 continue; } // 判斷此筆資料是否已在DB foreach (DAO.StudentFitnessRecord rec in fitnessRecList) { if (rec.SchoolYear == SchoolYear && rec.StudentID == StudentID && rec.TestDate == TestDate) { isInsert = false; fitnessRec = rec; break; } } // 新增資料 if (isInsert == true) { #region 處理新增資料 // 學生系統編號 fitnessRec.StudentID = StudentID; // 學年度 fitnessRec.SchoolYear = SchoolYear.Value; // 測驗日期 fitnessRec.TestDate = TestDate.Value; // 學校類別 fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別"); // 身高 fitnessRec.Height = Utility.GetIRowValueString(row, "身高"); // 身高常模 fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模"); // 體重 fitnessRec.Weight = Utility.GetIRowValueString(row, "體重"); // 體重常模 fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模"); // 坐姿體前彎 fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎"); // 坐姿體前彎常模 fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模"); // 立定跳遠 fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠"); // 立定跳遠常模 fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模"); // 仰臥起坐 fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐"); // 仰臥起坐常模 fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模"); // 心肺適能 fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能"); // 心肺適能常模 fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模"); #endregion } // 更新資料 else { #region 處理更新資料 // "學號/座號", "學年度", "測驗日期" 無法更新 // 學校類別 if (_Option.SelectedFields.Contains("學校類別")) { fitnessRec.SchoolCategory = Utility.GetIRowValueString(row, "學校類別"); } // 身高 if (_Option.SelectedFields.Contains("身高")) { fitnessRec.Height = Utility.GetIRowValueString(row, "身高"); } // 身高常模 if (_Option.SelectedFields.Contains("身高常模")) { fitnessRec.HeightDegree = Utility.GetIRowValueString(row, "身高常模"); } // 體重 if (_Option.SelectedFields.Contains("體重")) { fitnessRec.Weight = Utility.GetIRowValueString(row, "體重"); } // 體重常模 if (_Option.SelectedFields.Contains("體重常模")) { fitnessRec.WeightDegree = Utility.GetIRowValueString(row, "體重常模"); } // 坐姿體前彎 if (_Option.SelectedFields.Contains("坐姿體前彎")) { fitnessRec.SitAndReach = Utility.GetIRowValueString(row, "坐姿體前彎"); } // 坐姿體前彎常模 if (_Option.SelectedFields.Contains("坐姿體前彎常模")) { fitnessRec.SitAndReachDegree = Utility.GetIRowValueString(row, "坐姿體前彎常模"); } // 立定跳遠 if (_Option.SelectedFields.Contains("立定跳遠")) { fitnessRec.StandingLongJump = Utility.GetIRowValueString(row, "立定跳遠"); } // 立定跳遠常模 if (_Option.SelectedFields.Contains("立定跳遠常模")) { fitnessRec.StandingLongJumpDegree = Utility.GetIRowValueString(row, "立定跳遠常模"); } // 仰臥起坐 if (_Option.SelectedFields.Contains("仰臥起坐")) { fitnessRec.SitUp = Utility.GetIRowValueString(row, "仰臥起坐"); } // 仰臥起坐常模 if (_Option.SelectedFields.Contains("仰臥起坐常模")) { fitnessRec.SitUpDegree = Utility.GetIRowValueString(row, "仰臥起坐常模"); } // 心肺適能 if (_Option.SelectedFields.Contains("心肺適能")) { fitnessRec.Cardiorespiratory = Utility.GetIRowValueString(row, "心肺適能"); } // 心肺適能常模 if (_Option.SelectedFields.Contains("心肺適能常模")) { fitnessRec.CardiorespiratoryDegree = Utility.GetIRowValueString(row, "心肺適能常模"); } #endregion } if (isInsert == true) { _InsertRecList.Add(fitnessRec); } else { _UpdateRecList.Add(fitnessRec); } } // end of 判斷每一筆資料是要新增還是更新 // 執行更新或新增 if (_InsertRecList.Count > 0) { DAO.StudentFitness.InsertByRecordList(_InsertRecList); } if (_UpdateRecList.Count > 0) { DAO.StudentFitness.UpdateByRecordList(_UpdateRecList); } // Log Log.LogTransfer logTransfer = new Log.LogTransfer(); StringBuilder logData = new StringBuilder(); int insertCnt = _InsertRecList.Count; int updateCnt = _UpdateRecList.Count; logData.Append("總共匯入").Append((insertCnt + updateCnt)).Append("筆,"); logData.Append("新增:").Append(insertCnt).Append("筆,"); logData.Append("更新:").Append(updateCnt).Append("筆"); logTransfer.SaveLog("學生.體適能-匯入", "匯入", "student", "", logData); return(""); }
private void btnInsert_Click(object sender, EventArgs e) { DAO.StudentFitnessRecord rec = new DAO.StudentFitnessRecord(); rec.StudentID = PrimaryKey; rec.SchoolYear = int.Parse(K12.Data.School.DefaultSchoolYear); rec.TestDate = DateTime.Today; Forms.FrmFitnessRecord frm = new Forms.FrmFitnessRecord(rec, Forms.FrmFitnessRecord.accessType.Insert); if(frm.ShowDialog() == DialogResult.OK) _BGRun(); }
// 主要邏輯區塊 void BGW_DoWork(object sender, DoWorkEventArgs e) { string fileName = (string)((object[])e.Argument)[0]; #region 取得需要的資料 int SchoolYear = integerInput1.Value; bool ExportDegree = ckExportDegree.Checked; // 取得選取的學生ID List <string> studentIDList = K12.Presentation.NLDPanels.Student.SelectedSource; // 取得學生的基本資料包括班級資料 List <DAO.StudentInfo> studentRecords = DAO.FDQuery.GetStudnetInfoByIDList(studentIDList); // 取得學生的體適能資料 List <DAO.StudentFitnessRecord> FitnessRecords = DAO.StudentFitness.SelectByStudentIDListAndSchoolYear(studentIDList, SchoolYear); Dictionary <string, DAO.StudentFitnessRecord> FitnessRecordsDic = new Dictionary <string, DAO.StudentFitnessRecord>(); foreach (DAO.StudentFitnessRecord each in FitnessRecords) { if (!FitnessRecordsDic.ContainsKey(each.StudentID)) { FitnessRecordsDic.Add(each.StudentID, each); } } // Excel的表頭 string[] ExcelColumnNames; if (ExportDegree == true) { ExcelColumnNames = Global._ExcelDataDegreeTitle; } else { ExcelColumnNames = Global._ExcelDataTitle; } #endregion // 所有資料得集合 List <ExcelRowRecord> excelRowRecords = new List <ExcelRowRecord>(); #region 把資料組合起來 // 學生 foreach (DAO.StudentInfo student in studentRecords) { if (FitnessRecordsDic.ContainsKey(student.Student_ID)) { DAO.StudentFitnessRecord fitnessRecord = FitnessRecordsDic[student.Student_ID]; // 設定輸出的欄位 ExcelRowRecord rec = new ExcelRowRecord(ExcelColumnNames); // 設定每個欄位的值 rec.SetDataForExport(student, fitnessRecord, ExportDegree); excelRowRecords.Add(rec); } else { // 設定輸出的欄位 ExcelRowRecord rec = new ExcelRowRecord(ExcelColumnNames); // 設定每個欄位的值 rec.SetDataForExport(student, null, ExportDegree); excelRowRecords.Add(rec); } } // end of foreach (StudentRecord student in studentRecords) #endregion // 排序 excelRowRecords.Sort(SortData); // 開起現有的樣板檔案 Workbook report = new Workbook(); // 2016/7/19 穎驊修正,因應使用新的Aspose,存檔都建議使用xlsx,如果還是使用舊資源"102學年度體適能上傳資料格式.xls", //使用者在存檔的時候,會跳出"存檔類型與副檔名不相同"的錯誤,所以我把舊的檔案複製一份重新存檔成"體適能資料上傳格式_xlsx版_",以後都會使用這個新檔案 // 目前應該是沒有甚麼問題。 //MemoryStream ms = new MemoryStream(Properties.Resources.體適能資料上傳格式); MemoryStream ms = new MemoryStream(Properties.Resources.體適能資料上傳格式_xlsx版_); report.Open(ms); Worksheet sheet = report.Worksheets[0]; sheet.Name = Global._SheetName; // 輸出表頭 int RowIndex = _START_ROW - 1; int colIndex = 0; foreach (string columnName in ExcelColumnNames) { sheet.Cells[RowIndex, colIndex++].PutValue(columnName); } //填入資料 RowIndex = _START_ROW; foreach (ExcelRowRecord excelRowRecord in excelRowRecords) { if (RowIndex > _MAX_ROW_COUNT) { break; } SetDataDetail(sheet, excelRowRecord, RowIndex); RowIndex++; } // 儲存結果 e.Result = new object[] { report, fileName, RowIndex > _MAX_ROW_COUNT }; }