internal LeaveRequestDetail(LeaveRequestRecord item) { InitializeComponent(); // 取得假別清單 foreach (var absenceRec in K12.Data.AbsenceMapping.SelectAll()) { _LeaveReference.Add(absenceRec.Name, absenceRec.Abbreviation); } //取得學校系統課程表 _PeriodList = K12.Data.PeriodMapping.SelectAll(); var studentHelper = new SmartSchool.Customization.Data.AccessHelper().StudentHelper; var stuRec = studentHelper.GetStudent("" + item.RefStudentID); //事由 labelX5.Text = item.Content.Reason; //假單編碼 textBoxX2.Text = item.key; //學生 labelX4.Text = (stuRec.RefClass != null ? ("" + stuRec.RefClass.ClassName + "班 " + stuRec.SeatNo + "號 ") : "") + "" + stuRec.StudentName; //核可狀態 labelX7.Text = item.Approved.HasValue && item.Approved.Value ? "已進入系統" : ""; //動態新增課程Col for (int ii = 0; ii < _PeriodList.Count; ii++) { DataGridViewColumn col = new DataGridViewColumn(); col.CellTemplate = new DataGridViewTextBoxCell(); col.Name = _PeriodList[ii].Name; col.Visible = true; //if (PeriodList[ii].Name == "早讀" || PeriodList[ii].Name == "升旗" || PeriodList[ii].Name == "午休") //{ // col.Width = 50; //} //else //{ // col.Width = 25; //} //自動符合欄寬 col.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; //一個字寬25 col.MinimumWidth = _PeriodList[ii].Name.Length * 25; dataGridViewX1.Columns.Add(col); } // 填表 foreach (var date in item.Content.Dates) { object[] values = new object[_PeriodList.Count + 1]; values[0] = date.Date; Dictionary <string, string> dicAbsence = new Dictionary <string, string>(); foreach (var p in date.Periods) { if (p.Absence != "") { dicAbsence.Add(p.Period, p.Absence); } } for (int i = 0; i < _PeriodList.Count; i++) { values[i + 1] = dicAbsence.ContainsKey(_PeriodList[i].Name) ? (_LeaveReference.ContainsKey(dicAbsence[_PeriodList[i].Name]) ? _LeaveReference[dicAbsence[_PeriodList[i].Name]] : "!?") : ""; } dataGridViewX1.Rows.Add(values); } }
//2016/8/9 穎驊把原本預載的功能搬到buttonX1_Click(),並把在.Designer的參考也一併註解 //private void LeaveRegistrationViewer_Load(object sender, EventArgs e) //{ //} // 搜尋 private void buttonX1_Click(object sender, EventArgs e) { //刪除舊資料 dgvResult.Rows.Clear(); var studentHelper = new SmartSchool.Customization.Data.AccessHelper().StudentHelper; AccessHelper accessHelper = new AccessHelper(); List <K12.Data.StudentRecord> StudentList = K12.Data.Student.SelectAll(); Dictionary <String, String> StuNum_To_StuID = new Dictionary <string, string>(); foreach (var StuRecord in StudentList) { if (!StuNum_To_StuID.ContainsKey(StuRecord.StudentNumber)) { StuNum_To_StuID.Add(StuRecord.StudentNumber, StuRecord.ID); } } if (dateTimeInput1.Value.Ticks == 0 || dateTimeInput2.Value.Ticks == 0) { MsgBox.Show("請選擇輸入時間區間"); return; } if (textBoxX1.Text != "" && !StuNum_To_StuID.ContainsKey(textBoxX1.Text)) { MsgBox.Show("查無此學生"); return; } //2016/8/9 穎驊註解, 原本的時間 * 10000 + 621355968000000000 為格林威治(+0)的時間,因應台灣是(+8)時區,所以必須 //再補上 8*60*60*1000*10000 =288000000000 ticks(豪微秒?) 才是真正的時間 long startDay = (dateTimeInput1.Value.Ticks - 621355968000000000 - 288000000000) / 10000; long endDay = (dateTimeInput2.Value.AddDays(1).Ticks - 621355968000000000 - 288000000000) / 10000; // 2016/8/8 父親節,穎驊改寫,選擇條件改為 ref_student_id 等於指定id 如此一來才不會選到公假單(公假單的ref_student_id 等於null) var list = accessHelper.Select <LeaveRequestRecord>((textBoxX1.Text == "" ? "ref_student_id >=0" : "ref_student_id =" + StuNum_To_StuID[textBoxX1.Text]) + " AND uqid >=" + "'" + startDay + "'" + " AND uqid < " + "'" + endDay + "'"); //選擇所有一般假單,一般假單由學生填寫,不會有ref_teacher_id //var list = accessHelper.Select<LeaveRequestRecord>("ref_student_id > 0"); //選擇所有公假單,公假單只能由老師填寫,不會有ref_student_id //var list = accessHelper.Select<LeaveRequestRecord>("ref_teacher_id >0"); list.Sort(delegate(LeaveRequestRecord lr1, LeaveRequestRecord lr2) { return(lr2.key.CompareTo(lr1.key)); }); if (list.Count == 0) { MsgBox.Show("該學生該時段無假單紀錄"); } //填值 foreach (var item in list) { var stuRec = studentHelper.GetStudent("" + item.RefStudentID); dgvResult.Rows.Add( stuRec.RefClass == null ? "" : stuRec.RefClass.ClassName, stuRec.SeatNo, stuRec.StudentNumber, stuRec.StudentName, item.key, item.Approved.HasValue && item.Approved.Value ? "已核准" : "", //2016/8/9 穎驊註解, 原本系統的時間 * 10000 + 621355968000000000 為格林威治(+0)的時間,因應台灣是(+8)時區,所以必須 //再補上 8*60*60*1000*10000 =288000000000 ticks(豪微秒?) 才是真正的時間 //簡單來說,存在資料庫的都是格林威治標準時間 new DateTime(long.Parse(item.key) * 10000 + 621355968000000000 + 288000000000).ToString("yyyy/MM/dd HH:mm:ss") ); } list_to_LeaveReqestDetail = list; }