private void SearchStudentRange() { #region 日期選擇 dataGridView.Rows.Clear(); _semesterProvider.SetDate(dateTimeInput1.Value); _students = SortClassIndex.K12Data_StudentRecord(_students); foreach (StudentRecord student in _students) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dataGridView); row.Cells[0].Tag = student.ID; row.Cells[ColumnIndex["班級"]].Value = (student.Class != null) ? student.Class.Name : ""; row.Cells[ColumnIndex["姓名"]].Value = student.Name; row.Cells[ColumnIndex["學號"]].Value = student.StudentNumber; row.Cells[ColumnIndex["座號"]].Value = student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : ""; row.Cells[ColumnIndex["學年度"]].Value = _semesterProvider.SchoolYear; row.Cells[ColumnIndex["學期"]].Value = _semesterProvider.Semester; row.Cells[ColumnIndex["學年度"]].Tag = new SemesterCellInfo(_semesterProvider.SchoolYear.ToString()); row.Cells[ColumnIndex["學期"]].Tag = new SemesterCellInfo(_semesterProvider.Semester.ToString()); RowTag tag = new RowTag(); tag.Date = dateTimeInput1.Value; tag.IsNew = true; row.Tag = tag; dataGridView.Rows.Add(row); } #endregion }
/// <summary> /// 排序2個學生 /// </summary> private int SortByStudent(VolunteerRecord vr1, VolunteerRecord vr2) { if (StudentDic.ContainsKey(vr1.RefStudentID) && StudentDic.ContainsKey(vr2.RefStudentID)) { StudentRecord sr1 = StudentDic[vr1.RefStudentID]; StudentRecord sr2 = StudentDic[vr2.RefStudentID]; return(SortClassIndex.SortStudentDouble(sr1, sr2)); } else { return(0); } }
//覆寫 public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { #region 志願數 int 學生選填志願數 = GetVolunteerData.GetVolumnteerCount(); StudentDic = new Dictionary <string, StudentRecord>(); #endregion //Dictionary<string, int> IndexDic = new Dictionary<string, int>(); //int j = 1; List <string> FieldList = new List <string>(); FieldList.Add("學年度"); //目前欄位 FieldList.Add("學期"); //目前欄位 for (int x = 1; x <= 學生選填志願數; x++) { FieldList.Add(string.Format("志願{0}", x)); //目前欄位 //IndexDic.Add(string.Format("志願{0}", x), j); //j++; } List <CLUBRecord> ClubList = tool._A.Select <CLUBRecord>(); Dictionary <string, CLUBRecord> CLUBDic = new Dictionary <string, CLUBRecord>(); foreach (CLUBRecord each in ClubList) { if (!CLUBDic.ContainsKey(each.UID)) { CLUBDic.Add(each.UID, each); } } //取得所選學生之社團志願序(學年度/學期/學生 為單位) wizard.ExportableFields.AddRange(FieldList); wizard.ExportPackage += (sender, e) => { List <VolunteerRecord> VolUnDic = GetVolunteerData.GetStudentVolunteerDic(e.List); //取得學生清單 List <StudentRecord> StudentList = Student.SelectByIDs(e.List); StudentList = SortClassIndex.K12Data_StudentRecord(StudentList); foreach (StudentRecord each in StudentList) { if (!StudentDic.ContainsKey(each.ID)) { StudentDic.Add(each.ID, each); } } VolUnDic.Sort(SortByStudent); for (int i = 0; i < VolUnDic.Count; i++) { #region MyRegion VolunteerRecord vr = VolUnDic[i]; RowData row = new RowData(); row.ID = VolUnDic[i].RefStudentID; if (!string.IsNullOrEmpty(vr.Content)) { Dictionary <string, string> dic = new Dictionary <string, string>(); DSXmlHelper dsx = new DSXmlHelper(); dsx.Load(vr.Content); foreach (XmlElement each in dsx.BaseElement.SelectNodes("Club")) { string index = each.GetAttribute("Index"); string clubID = each.GetAttribute("Ref_Club_ID"); if (CLUBDic.ContainsKey(clubID)) { if (!dic.ContainsKey("志願" + index)) { dic.Add("志願" + index, CLUBDic[clubID].ClubName); } } } foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "學年度": row.Add(field, "" + VolUnDic[i].SchoolYear); break; case "學期": row.Add(field, "" + VolUnDic[i].Semester); break; } if (dic.ContainsKey(field)) { row.Add(field, dic[field]); } } } } e.Items.Add(row); #endregion } }; }
/// <summary> /// 取得學生的社團記錄 /// </summary> private void GetAndSortStudent() { SCjoinObjDic.Clear(); ClassByStudentDic.Clear(); //取得班級清單 List <string> ClassIDList = K12.Presentation.NLDPanels.Class.SelectedSource; foreach (ClassRecord each in Class.SelectByIDs(ClassIDList)) { if (!ClassDic.ContainsKey(each.ID)) { ClassDic.Add(each.ID, each); } } //取得學生清單 List <StudentRecord> studentList = K12.Data.Student.SelectByClassIDs(ClassIDList); studentList = SortClassIndex.K12Data_StudentRecord(studentList); foreach (StudentRecord stud in studentList) { if (CheckStatus(stud)) { if (string.IsNullOrEmpty(stud.RefClassID)) { continue; } //班級:學生ID清單:學生Record if (!ClassByStudentDic.ContainsKey(stud.RefClassID)) { ClassByStudentDic.Add(stud.RefClassID, new List <StudentRecord>()); } if (!ClassByStudentDic[stud.RefClassID].Contains(stud)) { ClassByStudentDic[stud.RefClassID].Add(stud); } //學生ID:特殊Obj StudentSCjoinObj sc = new StudentSCjoinObj(stud); if (!SCjoinObjDic.ContainsKey(stud.ID)) { SCjoinObjDic.Add(stud.ID, sc); } } } List <string> StudentIDList = new List <string>(); foreach (StudentRecord sr in studentList) { if (!StudentIDList.Contains(sr.ID)) { StudentIDList.Add(sr.ID); } } //由學生ID去比對SCJoin List <SCJoin> SCJoinLIst = _AccessHelper.Select <SCJoin>("ref_student_id in ('" + string.Join("','", StudentIDList) + "')"); List <CLUBRecord> CLUBList = GetCLUB(SCJoinLIst); Dictionary <string, CLUBRecord> CLUBDic = new Dictionary <string, CLUBRecord>(); foreach (CLUBRecord each in CLUBList) { if (each.SchoolYear == _SchoolYear && each.Semester == _Semester) { if (!CLUBDic.ContainsKey(each.UID)) { CLUBDic.Add(each.UID, each); } } } //由SCJoin的ref_club_id取得社團資料 foreach (SCJoin each in SCJoinLIst) { if (SCjoinObjDic.ContainsKey(each.RefStudentID)) { if (CLUBDic.ContainsKey(each.RefClubID)) { SCjoinObjDic[each.RefStudentID].CLUBRecord.Add(CLUBDic[each.RefClubID]); } } } }
private void SearchDateRange() { #region 日期選擇 DateTime start = dateTimeInput1.Value; DateTime end = dateTimeInput2.Value; dataGridView.Rows.Clear(); TimeSpan ts = dateTimeInput2.Value - dateTimeInput1.Value; if (ts.Days > 1500) { FISCA.Presentation.Controls.MsgBox.Show("您選取了" + ts.Days.ToString() + "天\n由於選取日期區間過長,請重新設定日期!"); _currentStartDate = dateTimeInput1.Value = DateTime.Today; _currentEndDate = dateTimeInput2.Value = DateTime.Today; return; } List <SHStudentRecord> CatchStudentList = SHStudent.SelectByIDs(_studentList); CatchStudentList = SortClassIndex.SHSchoolData_SHStudentRecord(CatchStudentList); bool ColorTrue = true; foreach (SHStudentRecord each in CatchStudentList) { DateTime date = start; if (ColorTrue) { ColorTrue = false; } else { ColorTrue = true; } while (date.CompareTo(end) <= 0) { if (!nowWeekDay.Contains(date.DayOfWeek)) //這裡 { date = date.AddDays(1); continue; } string dateValue = date.ToShortDateString(); DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dataGridView); if (ColorTrue) { SetDataGridViewColor(row, ColorTrue); } else { SetDataGridViewColor(row, ColorTrue); } RowTag tag = new RowTag(); tag.Date = date; tag.IsNew = true; row.Tag = tag; //RowTag row.Cells[0].Tag = each.ID; //系統編號 row.Cells[ColumnIndex["班級"]].Value = each.Class != null ? each.Class.Name : ""; row.Cells[ColumnIndex["座號"]].Value = each.SeatNo.HasValue ? each.SeatNo.Value.ToString() : ""; row.Cells[ColumnIndex["姓名"]].Value = each.Name; row.Cells[ColumnIndex["學號"]].Value = each.StudentNumber; row.Cells[ColumnIndex["日期"]].Value = dateValue; row.Cells[ColumnIndex["星期"]].Value = GetDayOfWeekInChinese(date.DayOfWeek); _semesterProvider.SetDate(date); row.Cells[ColumnIndex["學年度"]].Value = _semesterProvider.SchoolYear.ToString(); row.Cells[ColumnIndex["學期"]].Value = _semesterProvider.Semester.ToString(); date = date.AddDays(1); dataGridView.Rows.Add(row); } } #endregion }
public void Export() { //取得班級ID List <string> ClassIDList = K12.Presentation.NLDPanels.Class.SelectedSource; List <string> 會影響全勤的假別 = new List <string>(); foreach (AbsenceMappingInfo each in AbsenceMapping.SelectAll()) { if (!each.Noabsence) { 會影響全勤的假別.Add(each.Name); } } //取得班級學生 List <StudentRecord> StudentList = Student.SelectByClassIDs(ClassIDList); //所有學生 Dictionary <string, StudentRecord> StudentDic = new Dictionary <string, StudentRecord>(); //不全勤學生 Dictionary <string, StudentRecord> noOK_StudentList = new Dictionary <string, StudentRecord>(); //全勤的學生 Dictionary <string, StudentRecord> OK_StudentList = new Dictionary <string, StudentRecord>(); foreach (StudentRecord each in StudentList) { if (each.Status == StudentRecord.StudentStatus.一般 || each.Status == StudentRecord.StudentStatus.延修) { if (!StudentDic.ContainsKey(each.ID)) { StudentDic.Add(each.ID, each); } } } //取得學生所有的缺曠資料 //如果沒有缺曠記錄的 //就算是全勤 List <AttendanceRecord> TestList = Attendance.SelectByStudentIDs(StudentDic.Keys); List <AttendanceRecord> AttendanceList = new List <AttendanceRecord>(); if (checkBoxX1.Checked) { //相同學年度/學期 foreach (AttendanceRecord attendnace in TestList) { int schoolYear = int.Parse(cboSchoolYear.SelectedItem.ToString()); int semester = int.Parse(cboSemester.SelectedItem.ToString()); if (attendnace.SchoolYear == schoolYear && attendnace.Semester == semester) { AttendanceList.Add(attendnace); } } } else { AttendanceList.AddRange(TestList); } foreach (AttendanceRecord each in AttendanceList) { foreach (K12.Data.AttendancePeriod period in each.PeriodDetail) { if (會影響全勤的假別.Contains(period.AbsenceType)) { if (!noOK_StudentList.ContainsKey(period.RefStudentID)) { noOK_StudentList.Add(period.RefStudentID, StudentDic[period.RefStudentID]); } } } } foreach (StudentRecord each in StudentDic.Values) { if (!noOK_StudentList.ContainsKey(each.ID)) { if (!OK_StudentList.ContainsKey(each.ID)) { OK_StudentList.Add(each.ID, each); } } } List <StudentRecord> StudentRecordList = new List <StudentRecord>(); foreach (StudentRecord each in OK_StudentList.Values) { StudentRecordList.Add(each); } StudentRecordList = SortClassIndex.K12Data_StudentRecord(StudentRecordList); Workbook book = new Workbook(); Worksheet sheet = book.Worksheets[0]; string schoolName = School.ChineseName; Cell A1 = sheet.Cells["A1"]; A1.Style.Borders.SetColor(Color.Black); string A1Name = schoolName + " "; if (checkBoxX1.Checked) { A1Name += "(" + cboSchoolYear.SelectedItem.ToString() + "/" + cboSemester.SelectedItem.ToString() + ") "; } A1Name += "全勤學生名單"; sheet.Name = "全勤學生名單"; A1.PutValue(A1Name); A1.Style.HorizontalAlignment = TextAlignmentType.Center; sheet.Cells.Merge(0, 0, 1, 5); FormatCell(sheet.Cells["A2"], "編號"); FormatCell(sheet.Cells["B2"], "班級"); FormatCell(sheet.Cells["C2"], "座號"); FormatCell(sheet.Cells["D2"], "姓名"); FormatCell(sheet.Cells["E2"], "學號"); int index = 1; foreach (StudentRecord e in StudentRecordList) { int rowIndex = index + 2; FormatCell(sheet.Cells["A" + rowIndex], index.ToString()); FormatCell(sheet.Cells["B" + rowIndex], string.IsNullOrEmpty(e.RefClassID) ? "" : e.Class.Name); FormatCell(sheet.Cells["C" + rowIndex], e.SeatNo.HasValue ? e.SeatNo.Value.ToString() : ""); FormatCell(sheet.Cells["D" + rowIndex], e.Name); FormatCell(sheet.Cells["E" + rowIndex], e.StudentNumber); index++; } string path = Path.Combine(Application.StartupPath, "Reports"); path = Path.Combine(path, book.Worksheets[0].Name + ".xls"); int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } try { book.Save(path); } catch (IOException) { try { FileInfo file = new FileInfo(path); string nameTempalte = file.FullName.Replace(file.Extension, "") + "{0}.xls"; int count = 1; string fileName = string.Format(nameTempalte, count); while (File.Exists(fileName)) { fileName = string.Format(nameTempalte, count++); } book.Save(fileName); path = fileName; } catch (Exception ex) { MsgBox.Show("檔案儲存失敗:" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception ex) { MsgBox.Show("檔案儲存失敗:" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { Process.Start(path); } catch (Exception ex) { MsgBox.Show("檔案開啟失敗:" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }