public static void Delete(StudentByBus route) { List<ActiveRecord> schs = new List<ActiveRecord>(); schs.Add(route); udtHelper.DeletedValues(schs); if (ItemChanged != null) ItemChanged(null, EventArgs.Empty); }
public static string Insert(StudentByBus route) { List<ActiveRecord> logs = new List<ActiveRecord>(); logs.Add(route); List<string> newIDs = udtHelper.InsertValues(logs); if (ItemChanged != null) ItemChanged(null, EventArgs.Empty); return newIDs[0]; }
private void reloadstatus() { if (cboBusRange.Text != "") { StudentByBus studentbus = new StudentByBus(); studentbus = StudentByBusDAO.SelectByBusYearAndTimeNameAndStudntID(this.intSchoolYear.Value, cboBusRange.Text, K12.Presentation.NLDPanels.Student.SelectedSource[0]); BusSetup bussetup = new BusSetup(); if (BusSetupDAO.SelectByBusYear(this.intSchoolYear.Value).Count == 0) { MessageBox.Show("此年度無校車紀錄,請重新選擇!"); return; } else bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, this.cboBusRange.Text); List<BusStop> busstops = BusStopDAO.SelectByBusTimeNameOrderByStopID(bussetup.BusTimeName); if (studentbus == null) { } else { BusStop stu_busstop = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, studentbus.BusStopID); this.textBusStop.Text = stu_busstop.BusStopID; this.textBusStopName.Text = stu_busstop.BusStopName; } } }
private void btnReport_Click(object sender, EventArgs e) { StudentByBus studentbus = new StudentByBus(); StudentByBus CurrentStudentbus = new StudentByBus(); string CurrentBusStopName = ""; BusSetup bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, cboBusRange.Text); //List<string> newStuNumberList = new List<string>(); List<string> StudentIDList = K12.Presentation.NLDPanels.Student.SelectedSource; List<StudentRecord> stuRec = Student.SelectByIDs(StudentIDList); Dictionary<string, StudentByBus> studentbusRecord = new Dictionary<string, StudentByBus>(); studentbus = StudentByBusDAO.SelectByBusYearAndTimeNameAndStudntID(this.intSchoolYear.Value, this.cboBusRange.Text, StudentIDList[0]); if (studentbus != null) { if (textBusStop.Text != "" && textBusStop.Text != studentbus.BusStopID) studentbus.BusStopID = textBusStop.Text; BusStop buses = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, textBusStop.Text); CurrentBusStopName = buses.BusStopName; int total = 0; if (studentbus.DateCount > 0) total = buses.BusMoney * studentbus.DateCount; else total = buses.BusMoney * bussetup.DateCount; int div_value = total / 10; if ((total - div_value * 10) < 5) studentbus.BusMoney = div_value * 10; else studentbus.BusMoney = div_value * 10 + 10; studentbus.Save(); CurrentStudentbus = studentbus; } else { StudentByBus newstudentbus = new StudentByBus(); if (textBusStop.Text != "") newstudentbus.BusStopID = textBusStop.Text; BusStop buses = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, textBusStop.Text); CurrentBusStopName = buses.BusStopName; newstudentbus.BusRangeName = cboBusRange.Text; newstudentbus.BusStopID = textBusStop.Text; newstudentbus.BusTimeName = bussetup.BusTimeName; newstudentbus.ClassName = stuRec[0].Class.Name; newstudentbus.ClassID = stuRec[0].Class.ID; newstudentbus.DateCount = bussetup.DateCount; newstudentbus.SchoolYear = bussetup.BusYear; newstudentbus.StudentID = stuRec[0].ID; int total = buses.BusMoney * bussetup.DateCount; int div_value = total / 10; if ((total - div_value * 10) < 5) newstudentbus.BusMoney = div_value * 10; else newstudentbus.BusMoney = div_value * 10 + 10; newstudentbus.Save(); CurrentStudentbus = newstudentbus; } //if (!File.Exists(Application.StartupPath + "\\Customize\\校車繳費單樣版.doc")) //{ // MessageBox.Show("『" + Application.StartupPath + "\\Customize\\校車繳費單樣版.doc』檔案不存在,請確認後重新執行!"); // return; //} //if (!File.Exists(Application.StartupPath + "\\Customize\\校車繳費單樣版-現有學生.doc")) //{ // MessageBox.Show("『" + Application.StartupPath + "\\Customize\\校車繳費單樣版-現有學生.doc』檔案不存在,請確認後重新執行!"); // return; //} //Document Template = new Document(Application.StartupPath + "\\Customize\\校車繳費單樣版-現有學生.doc"); Document Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.校車繳費單樣版_現有學生)); //Document Template = new Document(); //mPreference = TemplatePreference.GetInstance(); //if (mPreference.UseDefaultTemplate) // Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.校車繳費單樣版_新生)); //else // Template = new Aspose.Words.Document(mPreference.CustomizeTemplate); Document doc = new Document(); Payment SelectPayment = cboPayment.SelectedItem as Payment; //新增收費明細。 List<PaymentDetail> StudentDetails = new List<PaymentDetail>(); SelectPayment.FillFull(); List<PaymentDetail> AllStudentdetail = PaymentDetail.GetByTarget("Student", StudentIDList); List<PaymentDetail> Studentdetail = new List<PaymentDetail>(); List<PaymentDetail> CurrentDetails = new List<PaymentDetail>(); List<PaymentHistory> historys = new List<PaymentHistory>(); List<string> ids = new List<string>(); foreach (PaymentDetail var in AllStudentdetail) { if (var.Extensions["校車收費年度"] != intSchoolYear.Value.ToString() || var.Extensions["校車收費名稱"] != cboBusRange.SelectedItem.ToString()) continue; Studentdetail.Add(var); } if (Studentdetail.Count == 0) { PaymentDetail detail = new PaymentDetail(SelectPayment); //設定「收費明細」所屬的收費。 detail.RefTargetID = stuRec[0].ID;//搭乘校車新生ID。 detail.RefTargetType = "Student"; detail.Amount = CurrentStudentbus.BusMoney; //要收多少錢。 //detail.Extensions.Add("校車收費年度", intSchoolYear.Value.ToString()); detail.Extensions.Add("校車收費年度", SelectPayment.SchoolYear.ToString()); detail.Extensions.Add("校車收費學期", SelectPayment.Semester.ToString()); detail.Extensions.Add("校車收費名稱", cboBusRange.SelectedItem.ToString()); detail.Extensions.Add("MergeField::代碼", textBusStop.Text); detail.Extensions.Add("MergeField::站名", CurrentBusStopName); detail.Extensions.Add("MergeField::" + "學號", stuRec[0].StudentNumber); detail.Extensions.Add("MergeField::" + "姓名", stuRec[0].Name); detail.Extensions.Add("MergeField::" + "班級", stuRec[0].Class.Name); detail.Extensions.Add("開始日期", bussetup.BusStartDate.ToString()); detail.Extensions.Add("結束日期", bussetup.BusEndDate.ToString()); detail.Extensions.Add("搭車天數", CurrentStudentbus.DateCount.ToString()); StudentDetails.Add(detail); //先加到一個 List 中。 List<string> detailIDs = new List<string>(); detailIDs = PaymentDetail.Insert(StudentDetails.ToArray()); //新增到資料庫中。 CurrentDetails = PaymentDetail.GetByIDs(detailIDs.ToArray()); foreach (PaymentDetail pd in CurrentDetails) { MotherForm.SetStatusBarMessage("條碼產生中...."); Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pd); history.Amount = pd.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); } ids = PaymentHistory.Insert(historys); } else { foreach (PaymentDetail pdetail in Studentdetail) { CurrentDetails.Add(pdetail); if (pdetail.Extensions["校車收費名稱"] == cboBusRange.SelectedItem.ToString() && int.Parse(pdetail.Extensions["校車收費年度"]) == intSchoolYear.Value) { if ((pdetail.Extensions["MergeField::代碼"] != textBusStop.Text && pdetail.Extensions["MergeField::站名"] != CurrentBusStopName) || int.Parse(pdetail.Extensions["搭車天數"]) != CurrentStudentbus.DateCount) { if (CurrentStudentbus.DateCount > 0) { pdetail.Extensions["搭車天數"] = CurrentStudentbus.DateCount.ToString(); pdetail.Amount = CurrentStudentbus.BusMoney; } List<PaymentDetail> pdetails = new List<PaymentDetail>(); pdetail.Amount = CurrentStudentbus.BusMoney; pdetail.Extensions["MergeField::代碼"] = textBusStop.Text; pdetail.Extensions["MergeField::站名"] = CurrentBusStopName; pdetails.Add(pdetail); PaymentDetail.Update(pdetails.ToArray()); //更新到資料庫中。 //註銷先前之繳費單 pdetail.CancelExistReceipts(); foreach (PaymentDetail pd in CurrentDetails) { MotherForm.SetStatusBarMessage("條碼產生中...."); Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pd); history.Amount = pd.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); } ids = PaymentHistory.Insert(historys); continue; } else { pdetail.FillHistories(); IList<PaymentHistory> historyss = pdetail.Histories; if (historyss == null) return; foreach (PaymentHistory history in historyss) { if (history.Receipt.Cancelled) continue; else { ids.Add(history.UID); break; } } } } } } historys = PaymentHistory.GetByIDs(ids.ToArray()); //產生繳費單 ReceiptDocument rdoc = new ReceiptDocument(Template); //如果要自定樣版,可以用這個建構式。 List<PaymentReceipt> prRecood = new List<PaymentReceipt>(); foreach (PaymentHistory history in historys) { MotherForm.SetStatusBarMessage("繳費單產生中...."); Application.DoEvents(); prRecood.Add(history.Receipt); } doc = rdoc.Generate2(prRecood); if (doc.Sections.Count != 0) { string path = Path.Combine(Application.StartupPath, "Reports"); string reportName = "繳費單"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { 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 { doc.Save(path, SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd1 = new System.Windows.Forms.SaveFileDialog(); sd1.Title = "另存新檔"; sd1.FileName = "繳費單.doc"; sd1.Filter = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(sd1.FileName, SaveFormat.Doc); System.Diagnostics.Process.Start(sd1.FileName); } catch { System.Windows.Forms.MessageBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } } MotherForm.SetStatusBarMessage("繳費單產生完成。"); this.Close(); }
private void cboBusRange_SelectedIndexChanged(object sender, EventArgs e) { #region cboBusRange異動 this.labelX3.Text = ""; if (cboBusRange.Text != "") { StudentByBus studentbus = new StudentByBus(); studentbus = StudentByBusDAO.SelectByBusYearAndTimeNameAndStudntID(this.intSchoolYear.Value, cboBusRange.Text, K12.Presentation.NLDPanels.Student.SelectedSource[0]); BusSetup bussetup = new BusSetup(); if (BusSetupDAO.SelectByBusYear(this.intSchoolYear.Value).Count == 0) { MessageBox.Show("此年度無校車紀錄,請重新選擇!"); return; } else bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, this.cboBusRange.Text); List<BusStop> busstops = BusStopDAO.SelectByBusTimeNameOrderByStopID(bussetup.BusTimeName); if (studentbus == null) { } else { BusStop stu_busstop = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, studentbus.BusStopID); this.textBusStop.Text = stu_busstop.BusStopID; this.textBusStopName.Text = stu_busstop.BusStopName; } //讀取系統中所有的收費模組(日期設定)。 List<Payment> pays = Payment.GetAll(); int next_schoolYear = 0; string next_semester = "上學期"; if (this.cboSemester.Text == "上學期") { next_schoolYear = this.intSchoolYear.Value; next_semester = "下學期"; } else next_schoolYear = this.intSchoolYear.Value + 1; this.cboPayment.Items.Clear(); if (pays.Count > 0) { foreach (Payment pay in pays) //if ((pay.SchoolYear == this.intSchoolYear.Value && pay.Semester == (this.cboSemester.Text == "上學期" ? 1 : 2)) || (pay.SchoolYear == next_schoolYear && pay.Semester == (next_semester == "上學期" ? 1 : 2))) if (pay.SchoolYear == this.intSchoolYear.Value && pay.Semester == (this.cboSemester.Text == "上學期" ? 1 : 2)) if (pay.Name == this.cboBusRange.Text) this.cboPayment.Items.Add(pay); } if (cboPayment.Items.Count == 0) { this.btnReport.Enabled = false; MessageBox.Show("請先設定收費模組"); this.Close(); return; } else { this.cboPayment.SelectedIndex = 0; this.cboPayment.Enabled = false; Payment selectPayment = cboPayment.SelectedItem as Payment; if (!selectPayment.Extensions.ContainsKey("DefaultExpiration")) { this.btnReport.Enabled = false; MessageBox.Show("請先設定收費之截止日期"); this.Close(); return; } else { DateTime dutedate; if (!DateTime.TryParse(selectPayment.Extensions["DefaultExpiration"], out dutedate)) { this.btnReport.Enabled = false; MessageBox.Show("請先設定收費之截止日期"); this.Close(); return; } else this.dtDueDate.Value = DateTime.Parse(selectPayment.Extensions["DefaultExpiration"]); List<PaymentDetail> Studentdetail = PaymentDetail.GetByTarget("Student", K12.Presentation.NLDPanels.Student.SelectedSource); if (Studentdetail.Count > 0) { foreach (PaymentDetail pdetail in Studentdetail) { if (pdetail.Extensions["校車收費名稱"] == cboBusRange.SelectedItem.ToString() && int.Parse(pdetail.Extensions["校車收費年度"]) == intSchoolYear.Value) { pdetail.FillHistories(); IList<PaymentHistory> historyss = pdetail.Histories; if (historyss == null) this.labelX3.Text = "未產生過繳費單"; else this.labelX3.Text = "已產生過繳費單"; } } } else this.labelX3.Text = "未產生過繳費單"; } } if (this.textBusStop.Text.Length == 4) { this.btnReport.Enabled = true; this.dtDueDate.Enabled = false; } else { this.btnReport.Enabled = false; this.dtDueDate.Enabled = false; } } #endregion }
//依站代碼、學號排序副程式 static int CompareSNumber(StudentByBus a, StudentByBus b) { return a.StudentID.CompareTo(b.StudentID); }
static void iWizardBusStudentPayment_ImportPackage(object sender, ImportLibrary.ImportPackageEventArgs e) { List<Data.StudentByBus> importItems = new List<Data.StudentByBus>(); foreach (var row in e.Items) { Data.StudentByBus importData = new Data.StudentByBus(); if (row.ID != "") importData = 搭車紀錄資料庫[row.ID]; //Data.StudentByBus importData = (row.ID != "") ? 學生搭車紀錄資料庫[學生資料庫[row["學號"]].ID][row["搭車年度"] + row["期間名稱"]] : new Data.StudentByBus(); //if (_DeletedBusStudents.Contains(importData)) // _DeletedBusStudents.Remove(importData); string bustime = ""; string busid = ""; int daycount = 0; foreach (var field in e.ImportFields) { string value = row[field]; switch (field) { default: break; case "搭車天數": if (value.Length > 0) importData.DateCount = int.Parse(value); break; case "車費": if (value.Length > 0) importData.BusMoney = int.Parse(value); else importData.BusMoney = 0; break; case "是否繳費": if (value.Length > 0) { if (value == "是" || value == "Yes" || value == "True") importData.PayStatus = true; else importData.PayStatus = false; } else importData.PayStatus = false; break; case "繳費日期": if (value.Length > 0) importData.PayDate = DateTime.Parse(value); break; case "備註": importData.comment = value; break; } } importItems.Add(importData); } importItems.SaveAll(); }
static void iWizardBusStudent_ImportPackage(object sender, ImportLibrary.ImportPackageEventArgs e) { List<Data.StudentByBus> importItems = new List<Data.StudentByBus>(); foreach (var row in e.Items) { Data.StudentByBus importData = new Data.StudentByBus(); if (row.ID != "") importData = 學生搭車紀錄資料庫[學生資料庫[row["學號"]].ID][row["搭車年度"] + row["期間名稱"]]; //Data.StudentByBus importData = (row.ID != "") ? 學生搭車紀錄資料庫[學生資料庫[row["學號"]].ID][row["搭車年度"] + row["期間名稱"]] : new Data.StudentByBus(); //if (_DeletedBusStudents.Contains(importData)) // _DeletedBusStudents.Remove(importData); string bustime = ""; string busid = ""; int daycount = 0; foreach (var field in e.ImportFields) { string value = row[field]; if (field == "校車時段") bustime = value; if (field == "代碼") busid = value; if (field == "天數") daycount = int.Parse(value); switch (field) { default: break; case "校車時段": importData.BusTimeName = value; break; case "代碼": importData.BusStopID = value; break; case "期間名稱": importData.BusRangeName = value; break; case "班級": importData.ClassName = value; if (班級資料庫.ContainsKey(value)) importData.ClassID = 班級資料庫[value].ID; break; case "學號": if (importData.ClassID == null) importData.ClassID = 學生資料庫[value].Class.ID; importData.StudentID = 學生資料庫[value].ID; break; case "搭車年度": if (value.Length > 0) importData.SchoolYear = int.Parse(value); break; case "天數": if (value.Length > 0) importData.DateCount = int.Parse(value); break; case "車費": if (value.Length > 0) importData.BusMoney = int.Parse(value); else importData.BusMoney = 0; break; case "是否繳費": if (value.Length > 0) { if (value == "是" || value == "Yes" || value == "True") importData.PayStatus = true; else importData.PayStatus = false; } else importData.PayStatus = false; break; case "繳費日期": if (value.Length > 0) importData.PayDate = DateTime.Parse(value); break; case "備註": importData.comment = value; break; } } int total = 校車站名資料庫[bustime][busid].BusMoney * daycount; int div_value = total / 10; if ((total - div_value * 10) < 5) importData.BusMoney = div_value * 10; else importData.BusMoney = div_value * 10 + 10; //importData.BusMoney = 校車站名資料庫[bustime][busid].BusMoney * daycount; importItems.Add(importData); } importItems.SaveAll(); }
private void cboBusRange_SelectedIndexChanged(object sender, EventArgs e) { #region cboBusRange異動 this.labelX3.Text = ""; if (cboBusRange.Text != "") { StudentByBus studentbus = new StudentByBus(); foreach (MySchoolModule.NewStudentRecord nsr in NewStudent.Instance.SelectedList) studentbus = StudentByBusDAO.SelectByBusYearAndTimeNameAndStudntID(this.intSchoolYear.Value, cboBusRange.Text, nsr.UID); BusSetup bussetup = new BusSetup(); if (BusSetupDAO.SelectByBusYear(this.intSchoolYear.Value).Count == 0) { MessageBox.Show("此年度無校車紀錄,請重新選擇!"); return; } else bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, cboBusRange.Text); List<BusStop> busstops = BusStopDAO.SelectByBusTimeNameOrderByStopID(bussetup.BusTimeName); //Dictionary<string, BusStop> busstopRecord = new Dictionary<string, BusStop>(); //this.cboBusStopID.Items.Clear(); //foreach (BusStop busstop in busstops) //{ // this.cboBusStopID.Items.Add(busstop.BusStopID + " " + busstop.BusStopName); // busstopRecord.Add(busstop.BusStopID, busstop); //} if (studentbus == null) { } else { BusStop stu_busstop = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, studentbus.BusStopID); //if (busstopRecord.ContainsKey(stu_busstop.BusStopID)) // this.cboBusStopID.SelectedIndex = busstopRecord.Keys.ToList().IndexOf(stu_busstop.BusStopID); this.textBusStop.Text = stu_busstop.BusStopID; this.textBusStopName.Text = stu_busstop.BusStopName; } //讀取系統中所有的收費模組(日期設定)。 List<Payment> pays = Payment.GetAll(); this.cboPayment.Items.Clear(); if (pays.Count > 0) { foreach (Payment pay in pays) if (pay.SchoolYear == this.intSchoolYear.Value && pay.Semester == (this.cboSemester.Text == "上學期" ? 1 : 2)) if (pay.Name == this.cboBusRange.Text) this.cboPayment.Items.Add(pay); } if (cboPayment.Items.Count == 0) { this.btnReport.Enabled = false; MessageBox.Show("請先設定收費模組"); this.Close(); return; } else { this.cboPayment.SelectedIndex = 0; this.cboPayment.Enabled = false; Payment selectPayment = cboPayment.SelectedItem as Payment; if (!selectPayment.Extensions.ContainsKey("DefaultExpiration")) { this.btnReport.Enabled = false; MessageBox.Show("請先設定收費之截止日期"); this.Close(); return; } else { DateTime dutedate; if (!DateTime.TryParse(selectPayment.Extensions["DefaultExpiration"], out dutedate)) { this.btnReport.Enabled = false; MessageBox.Show("請先設定收費之截止日期"); this.Close(); return; } else this.dtDueDate.Value = DateTime.Parse(selectPayment.Extensions["DefaultExpiration"]); List<PaymentDetail> Studentdetail = PaymentDetail.GetByTarget("NewStudent", NewStudent.Instance.SelectedList[0].UID); if (Studentdetail.Count > 0) { foreach (PaymentDetail pdetail in Studentdetail) { if (pdetail.Extensions["校車收費名稱"] == cboBusRange.SelectedItem.ToString() && int.Parse(pdetail.Extensions["校車收費年度"]) == intSchoolYear.Value) { pdetail.FillHistories(); IList<PaymentHistory> historyss = pdetail.Histories; if (historyss == null) this.labelX3.Text = "未產生過繳費單"; else this.labelX3.Text = "已產生過繳費單"; } } } else this.labelX3.Text = "未產生過繳費單"; } } if (this.textBusStop.Text.Length == 4) { this.btnReport.Enabled = true; this.dtDueDate.Enabled = false; } else { this.btnReport.Enabled = false; this.dtDueDate.Enabled = false; } } #endregion }
//依搭車年度、期間名稱排序副程式 static int CompareYearRange(StudentByBus a, StudentByBus b) { if (a.SchoolYear == b.SchoolYear) { return a.BusRangeName.CompareTo(b.BusRangeName); } else return a.SchoolYear.CompareTo(b.SchoolYear); }
//依搭車年度、期間名稱、班級、學生ID排序副程式 static int CompareSchoolYear(StudentByBus a, StudentByBus b) { if (a.SchoolYear == b.SchoolYear) { if (a.BusRangeName == b.BusRangeName) { if (a.ClassName == b.ClassName) { return a.StudentID.CompareTo(b.StudentID); } else return a.ClassName.CompareTo(b.ClassName); } else return a.BusRangeName.CompareTo(b.BusRangeName); } else return a.SchoolYear.CompareTo(b.SchoolYear); }
//依班級、學生ID排序副程式 static int CompareBusClass(StudentByBus a, StudentByBus b) { if (a.ClassName == b.ClassName) { return a.StudentID.CompareTo(b.StudentID); } else return a.ClassName.CompareTo(b.ClassName); }
public static string Update(StudentByBus route) { List<ActiveRecord> schs = new List<ActiveRecord>(); schs.Add(route); udtHelper.UpdateValues(schs); if (ItemChanged != null) ItemChanged(null, EventArgs.Empty); return route.UID; }
private void reloadstatus() { if (cboBusRange.Text != "") { StudentByBus studentbus = new StudentByBus(); foreach (MySchoolModule.NewStudentRecord nsr in NewStudent.Instance.SelectedList) studentbus = StudentByBusDAO.SelectByBusYearAndTimeNameAndStudntID(this.intSchoolYear.Value, cboBusRange.Text, nsr.UID); BusSetup bussetup = new BusSetup(); if (BusSetupDAO.SelectByBusYear(this.intSchoolYear.Value).Count == 0) { MessageBox.Show("此年度無校車紀錄,請重新選擇!"); return; } else bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, cboBusRange.Text); List<BusStop> busstops = BusStopDAO.SelectByBusTimeNameOrderByStopID(bussetup.BusTimeName); if (studentbus == null) { } else { BusStop stu_busstop = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, studentbus.BusStopID); this.textBusStop.Text = stu_busstop.BusStopID; this.textBusStopName.Text = stu_busstop.BusStopName; } } }
private void savebtn_Click(object sender, EventArgs e) { List<Data.StudentByBus> _Source = new List<Data.StudentByBus>(); Data.StudentByBus sbr = new Data.StudentByBus(); BusSetup bussetup = BusSetupDAO.SelectByBusYearAndRange(int.Parse(this.cboYear.Text), this.cboRange.Text); _Source.Clear(); for (int i = studentdataGridView.Rows.Count - 1; i >= 0; i--) { sbr = (Data.StudentByBus)studentdataGridView.Rows[i].Tag; if (sbr == null && (studentdataGridView[2, i].Value == null || studentdataGridView[2, i].Value.ToString() == "")) continue; if (sbr == null) sbr = new Data.StudentByBus(); sbr.StudentID = (string)studentdataGridView[9, i].Value; sbr.ClassName = (string)studentdataGridView[0, i].Value; sbr.ClassID = (string)studentdataGridView[11, i].Value; sbr.BusStopID = studentdataGridView[2, i].Value.ToString().Substring(0, 4); BusStop buses = BusStopDAO.SelectByBusTimeNameAndByStopID(bussetup.BusTimeName, sbr.BusStopID); sbr.PayStatus = (bool)studentdataGridView[5, i].Value; DateTime PayDate; if (studentdataGridView[6, i].Value.ToString() != "" && DateTime.TryParse(studentdataGridView[6, i].Value.ToString(), out PayDate)) sbr.PayDate = DateTime.Parse(studentdataGridView[6, i].Value.ToString()); sbr.DateCount = int.Parse(studentdataGridView[7, i].Value.ToString()); int total = buses.BusMoney * sbr.DateCount; int div_value = total / 10; sbr.comment = (string)studentdataGridView[8, i].Value; sbr.BusRangeName = bussetup.BusRangeName; sbr.BusTimeName = bussetup.BusTimeName; if ((total - div_value * 10) < 5) sbr.BusMoney = div_value * 10; else sbr.BusMoney = div_value * 10 + 10; sbr.SchoolYear = int.Parse(this.cboYear.Text); _Source.Add(sbr); } _Source.SaveAll(); RefreshDataGrid(); MessageBox.Show("儲存成功!"); }
private void btnReport_Click(object sender, EventArgs e) { List<StudentByBus> studentbus = new List<StudentByBus>(); StudentByBus CurrentStudentbus = new StudentByBus(); string CurrentBusStopName = ""; BusSetup bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, cboBusRange.Text); //List<string> newStuNumberList = new List<string>(); List<string> newStudentIDList = new List<string>(); List<MySchoolModule.NewStudentRecord> newStu = new List<MySchoolModule.NewStudentRecord>(); Dictionary<string, StudentByBus> studentbusRecord = new Dictionary<string, StudentByBus>(); foreach (MySchoolModule.NewStudentRecord nsr in NewStudent.Instance.SelectedList) { //if (!newStuNumberList.Contains(nsr.Number)) // newStuNumberList.Add(nsr.Number); if (!newStudentIDList.Contains(nsr.UID)) newStudentIDList.Add(nsr.UID); newStu.Add(nsr); } studentbus = StudentByBusDAO.SelectByBusYearAndTimeNameAndStudntList(this.intSchoolYear.Value, cboBusRange.Text, newStudentIDList); foreach (StudentByBus var in studentbus) if (!studentbusRecord.ContainsKey(var.StudentID)) studentbusRecord.Add(var.StudentID, var); //if (!File.Exists(Application.StartupPath + "\\Customize\\校車繳費單樣版.doc")) //{ // MessageBox.Show("『" + Application.StartupPath + "\\Customize\\校車繳費單樣版.doc』檔案不存在,請確認後重新執行!"); // return; //} //if (!File.Exists(Application.StartupPath + "\\Customize\\校車繳費單樣版-新生.doc")) //{ // MessageBox.Show("『" + Application.StartupPath + "\\Customize\\校車繳費單樣版-新生.doc』檔案不存在,請確認後重新執行!"); // return; //} //Document Template = new Document(Application.StartupPath + "\\Customize\\校車繳費單樣版-新生.doc"); Document Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.校車繳費單樣版_新生)); //Document Template = new Document(); //mPreference = TemplatePreference.GetInstance(); //if (mPreference.UseDefaultTemplate) // Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.校車繳費單樣版_新生)); //else // Template = new Aspose.Words.Document(mPreference.CustomizeTemplate); Document doc = new Document(); Payment SelectPayment = cboPayment.SelectedItem as Payment; //新增收費明細。 List<PaymentDetail> StudentDetails = new List<PaymentDetail>(); SelectPayment.FillFull(); List<PaymentDetail> Studentdetail = PaymentDetail.GetByTarget("NewStudent", newStudentIDList); List<PaymentDetail> CurrentDetails = new List<PaymentDetail>(); List<PaymentHistory> historys = new List<PaymentHistory>(); List<string> ids = new List<string>(); if (Studentdetail.Count == 0) { foreach (MySchoolModule.NewStudentRecord nsr in NewStudent.Instance.SelectedList) { PaymentDetail detail = new PaymentDetail(SelectPayment); //設定「收費明細」所屬的收費。 detail.RefTargetID = NewStudent.Instance.SelectedList[0].UID;//搭乘校車新生ID。 detail.RefTargetType = "NewStudent"; detail.Amount = studentbusRecord[nsr.UID].BusMoney; //要收多少錢。 detail.Extensions.Add("校車收費年度", SelectPayment.SchoolYear.ToString()); detail.Extensions.Add("校車收費學期", SelectPayment.Semester.ToString()); detail.Extensions.Add("校車收費名稱", cboBusRange.SelectedItem.ToString()); detail.Extensions.Add("MergeField::代碼", textBusStop.Text); detail.Extensions.Add("MergeField::站名", CurrentBusStopName); detail.Extensions.Add("MergeField::" + "學號", NewStudent.Instance.SelectedList[0].Number); detail.Extensions.Add("MergeField::" + "姓名", NewStudent.Instance.SelectedList[0].Name); detail.Extensions.Add("MergeField::" + "科別", NewStudent.Instance.SelectedList[0].Dept); detail.Extensions.Add("開始日期", bussetup.BusStartDate.ToString()); detail.Extensions.Add("結束日期", bussetup.BusEndDate.ToString()); detail.Extensions.Add("搭車天數", studentbusRecord[nsr.UID].DateCount.ToString()); StudentDetails.Add(detail); //先加到一個 List 中。 } List<string> detailIDs = new List<string>(); detailIDs = PaymentDetail.Insert(StudentDetails.ToArray()); //新增到資料庫中。 //如果要馬上使用物件的話,需要用回傳的 UID 清單再將資料 Select 出來 //因為這樣物件中才會包含 UID 資料。 CurrentDetails = PaymentDetail.GetByIDs(detailIDs.ToArray()); foreach (PaymentDetail pd in CurrentDetails) { MotherForm.SetStatusBarMessage("條碼產生中...."); Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pd); history.Amount = pd.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); } ids = PaymentHistory.Insert(historys); } else { foreach (PaymentDetail pdetail in Studentdetail) { CurrentDetails.Add(pdetail); pdetail.FillHistories(); if (pdetail.Extensions["校車收費名稱"] == cboBusRange.SelectedItem.ToString() && int.Parse(pdetail.Extensions["校車收費年度"]) == intSchoolYear.Value) { if (CancelExist.Checked) { //註銷先前之繳費單 pdetail.CancelExistReceipts(); if (studentbusRecord[pdetail.RefTargetID].DateCount > 0) { pdetail.Extensions["搭車天數"] = studentbusRecord[pdetail.RefTargetID].DateCount.ToString(); pdetail.Amount = studentbusRecord.ContainsKey(pdetail.RefTargetID) ? studentbusRecord[pdetail.RefTargetID].BusMoney : 0; PaymentDetail.Update(pdetail); } MotherForm.SetStatusBarMessage("條碼產生中...."); Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pdetail); history.Amount = pdetail.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); } else { IList<PaymentHistory> historyss = pdetail.Histories; if (historyss == null) return; foreach (PaymentHistory history in historyss) { ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 ids.Add(history.UID); } } } } if (CancelExist.Checked) ids = PaymentHistory.Insert(historys); } historys = PaymentHistory.GetByIDs(ids.ToArray()); //產生繳費單 ReceiptDocument rdoc = new ReceiptDocument(Template); //如果要自定樣版,可以用這個建構式。 List<PaymentReceipt> prRecood = new List<PaymentReceipt>(); foreach (PaymentHistory history in historys) { MotherForm.SetStatusBarMessage("繳費單產生中...."); Application.DoEvents(); prRecood.Add(history.Receipt); } doc = rdoc.Generate1(prRecood); if (doc.Sections.Count != 0) { string path = Path.Combine(Application.StartupPath, "Reports"); string reportName = "繳費單"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { 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 { doc.Save(path, SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd1 = new System.Windows.Forms.SaveFileDialog(); sd1.Title = "另存新檔"; sd1.FileName = "繳費單.doc"; sd1.Filter = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(sd1.FileName, SaveFormat.Doc); System.Diagnostics.Process.Start(sd1.FileName); } catch { System.Windows.Forms.MessageBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } } MotherForm.SetStatusBarMessage("繳費單產生完成。"); this.Close(); }
private void btnReport_Click(object sender, EventArgs e) { if (cboDept.Text == "") { MessageBox.Show("請選擇科別再重新執行!"); return; } List<StudentByBus> studentbus = new List<StudentByBus>(); StudentByBus CurrentStudentbus = new StudentByBus(); BusSetup bussetup = BusSetupDAO.SelectByBusYearAndRange(this.intSchoolYear.Value, cboBusRange.Text); //List<string> newStuNumberList = new List<string>(); List<string> AllStudentIDList = new List<string>(); List<string> StudentIDList = new List<string>(); List<SHStudentRecord> stuRec = new List<SHStudentRecord>(); Dictionary<string, StudentByBus> studentbusRecord = new Dictionary<string, StudentByBus>(); Dictionary<string, List<SHStudentRecord>> studentClassRecord = new Dictionary<string, List<SHStudentRecord>>(); studentbus = StudentByBusDAO.SelectByBusYearAndTimeName(this.intSchoolYear.Value, this.cboBusRange.Text); Dictionary<string, BusStop> BusStopRecord = new Dictionary<string, BusStop>(); List<BusStop> BusStops = new List<BusStop>(); if (this.cboBusRange.Text.IndexOf("夜輔") >= 0) BusStops = BusStopDAO.SelectByBusTimeName("夜輔"); else BusStops = BusStopDAO.SelectByBusTimeName("日校校車"); foreach (BusStop var in BusStops) { if (!BusStopRecord.ContainsKey(var.BusStopID)) BusStopRecord.Add(var.BusStopID, var); } int nowSet = 0; int nowPercent = 0; foreach (StudentByBus var in studentbus) { MotherForm.SetStatusBarMessage("正在讀取學生搭車資料", nowSet++ * 10 / studentbus.Count); if (var.BusStopID == "0000") continue; //if (var.comment != "99測試") // continue; if (!studentbusRecord.ContainsKey(var.StudentID)) studentbusRecord.Add(var.StudentID, var); if (!AllStudentIDList.Contains(var.StudentID)) AllStudentIDList.Add(var.StudentID); } stuRec = SHStudent.SelectByIDs(AllStudentIDList); Dictionary<int, string> ClassIDs = new Dictionary<int, string>(); List<int> orderClassIDs = new List<int>(); int orderval = 0; nowPercent = 10; nowSet = 0; foreach (SHStudentRecord var in stuRec) { MotherForm.SetStatusBarMessage("正在讀取學生資料", nowPercent + nowSet++ * 50 / stuRec.Count); if (var.Status != StudentRecord.StudentStatus.一般) continue; if (cboDept.Text != "") { if (cboDept.Text == "多媒體設計科") { if (var.Department.Name.IndexOf("多媒體") < 0) continue; } else { if (var.Department.Name != cboDept.Text) continue; } } if (int.Parse(var.Class.GradeYear.ToString()) == 3) orderval = 47 + int.Parse(var.Class.DisplayOrder); else orderval = (int.Parse(var.Class.GradeYear.ToString()) - 1) * 23 + int.Parse(var.Class.DisplayOrder); if (!ClassIDs.ContainsKey(orderval)) { ClassIDs.Add(orderval, var.Class.ID); orderClassIDs.Add(orderval); } if (!studentClassRecord.ContainsKey(var.Class.ID)) studentClassRecord.Add(var.Class.ID, new List<SHStudentRecord>()); if (!studentClassRecord[var.Class.ID].Contains(var)) studentClassRecord[var.Class.ID].Add(var); if (!StudentIDList.Contains(var.ID)) StudentIDList.Add(var.ID); } orderClassIDs.Sort(); int stucount = 0; for (int i = 0; i < orderClassIDs.Count; i++) { studentClassRecord[ClassIDs[orderClassIDs[i]]].Sort(CompareStudentNumber); stucount += studentClassRecord[ClassIDs[orderClassIDs[i]]].Count; } //if (!File.Exists(Application.StartupPath + "\\Customize\\校車繳費單樣版.doc")) //{ // MessageBox.Show("『" + Application.StartupPath + "\\Customize\\校車繳費單樣版.doc』檔案不存在,請確認後重新執行!"); // return; //} //if (!File.Exists(Application.StartupPath + "\\Customize\\校車繳費單樣版-現有學生.doc")) //{ // MessageBox.Show("『" + Application.StartupPath + "\\Customize\\校車繳費單樣版-現有學生.doc』檔案不存在,請確認後重新執行!"); // return; //} //Document Template = new Document(Application.StartupPath + "\\Customize\\校車繳費單樣版-現有學生.doc"); Document Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.校車繳費單樣版_現有學生)); //Document Template = new Document(); //mPreference = TemplatePreference.GetInstance(); //if (mPreference.UseDefaultTemplate) // Template = new Aspose.Words.Document(new MemoryStream(Properties.Resources.校車繳費單樣版_新生)); //else // Template = new Aspose.Words.Document(mPreference.CustomizeTemplate); Document doc = new Document(); Payment SelectPayment = cboPayment.SelectedItem as Payment; //新增收費明細。 List<PaymentDetail> StudentDetails = new List<PaymentDetail>(); SelectPayment.FillFull(); List<PaymentDetail> AllStudentdetail = PaymentDetail.GetByTarget("Student", StudentIDList); List<PaymentDetail> Studentdetail = new List<PaymentDetail>(); List<PaymentDetail> CurrentDetails = new List<PaymentDetail>(); List<PaymentHistory> historys = new List<PaymentHistory>(); List<string> ids = new List<string>(); foreach (PaymentDetail var in AllStudentdetail) { if (var.Extensions["校車收費年度"] != intSchoolYear.Value.ToString() || var.Extensions["校車收費名稱"] != cboBusRange.SelectedItem.ToString()) continue; Studentdetail.Add(var); } int paymentcount = 0; nowPercent = 60; nowSet = 0; string oldclass = ""; bool loseHistory = false; if (Studentdetail.Count == 0) { for (int i = 0; i < orderClassIDs.Count; i++) foreach (SHStudentRecord nsr in studentClassRecord[ClassIDs[orderClassIDs[i]]]) { MotherForm.SetStatusBarMessage("正在產生校車繳費資料", nowPercent + nowSet++ * 30 / stucount); PaymentDetail detail = new PaymentDetail(SelectPayment); //設定「收費明細」所屬的收費。 detail.RefTargetID = nsr.ID; //搭乘校車學生ID。 detail.RefTargetType = "Student"; detail.Amount = studentbusRecord.ContainsKey(nsr.ID) ? studentbusRecord[nsr.ID].BusMoney : 0; //要收多少錢。 //detail.Extensions.Add("校車收費年度", intSchoolYear.Value.ToString()); detail.Extensions.Add("校車收費年度", SelectPayment.SchoolYear.ToString()); detail.Extensions.Add("校車收費學期", SelectPayment.Semester.ToString()); detail.Extensions.Add("校車收費名稱", cboBusRange.SelectedItem.ToString()); detail.Extensions.Add("MergeField::代碼", studentbusRecord.ContainsKey(nsr.ID) ? studentbusRecord[nsr.ID].BusStopID : ""); detail.Extensions.Add("MergeField::站名", studentbusRecord.ContainsKey(nsr.ID) ? BusStopRecord[studentbusRecord[nsr.ID].BusStopID].BusStopName : ""); detail.Extensions.Add("MergeField::" + "學號", nsr.StudentNumber); detail.Extensions.Add("MergeField::" + "姓名", nsr.Name); detail.Extensions.Add("MergeField::" + "班級", nsr.Class.Name.Substring(0, 3)); detail.Extensions.Add("開始日期", bussetup.BusStartDate.ToString()); detail.Extensions.Add("結束日期", bussetup.BusEndDate.ToString()); detail.Extensions.Add("搭車天數", studentbusRecord[nsr.ID].DateCount.ToString()); StudentDetails.Add(detail); //先加到一個 List 中。 paymentcount++; } List<string> detailIDs = new List<string>(); detailIDs = PaymentDetail.Insert(StudentDetails.ToArray()); //新增到資料庫中。 //如果要馬上使用物件的話,需要用回傳的 UID 清單再將資料 Select 出來 //因為這樣物件中才會包含 UID 資料。 CurrentDetails = PaymentDetail.GetByIDs(detailIDs.ToArray()); foreach (PaymentDetail pd in CurrentDetails) { if (oldclass != pd.Extensions["MergeField::" + "班級"]) MotherForm.SetStatusBarMessage(pd.Extensions["MergeField::" + "班級"] + "條碼產生中....", 90); Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pd); history.Amount = pd.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); oldclass = pd.Extensions["MergeField::" + "班級"]; } ids = PaymentHistory.Insert(historys); } else { foreach (PaymentDetail pdetail in Studentdetail) { if (paymentcount == 0) MotherForm.SetStatusBarMessage("正在讀取校車繳費資料", nowPercent + nowSet++ * 30 / stucount); CurrentDetails.Add(pdetail); pdetail.FillHistories(); if (pdetail.Extensions["校車收費名稱"] == cboBusRange.SelectedItem.ToString() && int.Parse(pdetail.Extensions["校車收費年度"]) == intSchoolYear.Value) { if (CancelExist.Checked) { //註銷先前之繳費單 pdetail.CancelExistReceipts(); if (studentbusRecord[pdetail.RefTargetID].DateCount > 0) { pdetail.Extensions["搭車天數"] = studentbusRecord[pdetail.RefTargetID].DateCount.ToString(); pdetail.Amount = studentbusRecord.ContainsKey(pdetail.RefTargetID) ? studentbusRecord[pdetail.RefTargetID].BusMoney : 0; //要收多少錢。 } if (pdetail.Extensions["MergeField::" + "班級"].Length > 3) pdetail.Extensions["MergeField::" + "班級"] = pdetail.Extensions["MergeField::" + "班級"].Substring(0, 3); PaymentDetail.Update(pdetail); if (oldclass != pdetail.Extensions["MergeField::" + "班級"]) MotherForm.SetStatusBarMessage(pdetail.Extensions["MergeField::" + "班級"] + "條碼產生中....", 90); Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pdetail); history.Amount = pdetail.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); paymentcount++; } else { //if (!pdetail.Extensions.ContainsKey("MergeField::站名")) // pdetail.Extensions.Add("MergeField::站名", BusStopRecord[studentbusRecord["19998"].BusStopID].BusStopName); //PaymentDetail.Update(pdetail); if (oldclass != pdetail.Extensions["MergeField::" + "班級"]) MotherForm.SetStatusBarMessage(pdetail.Extensions["MergeField::" + "班級"] + "條碼產生中....", 90); IList<PaymentHistory> historyss = pdetail.Histories; if (historyss == null) return; if (historyss.Count == 0) { Application.DoEvents(); //新增一筆繳費記錄。 PaymentHistory history = new PaymentHistory(pdetail); history.Amount = pdetail.Amount; //通常會與金額與繳費明細一樣。 ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 historys.Add(history); loseHistory = true; } else { foreach (PaymentHistory history in historyss) { //if (!history.Receipt.Extensions.ContainsKey("MergeField::站名")) // history.Receipt.Extensions.Add("MergeField::站名", BusStopRecord[studentbusRecord["19764"].BusStopID].BusStopName); //PaymentHistory.Update(history); ((Payment)cboPayment.SelectedItem).CalculateReceiptBarcode(history); //計算條碼資料,計算時需要「Payment」物件。 ids.Add(history.UID); } } paymentcount++; } } oldclass = pdetail.Extensions["MergeField::" + "班級"]; } if (CancelExist.Checked || (loseHistory && historys.Count > 0)) ids = PaymentHistory.Insert(historys); } historys = PaymentHistory.GetByIDs(ids.ToArray()); Dictionary<string, Dictionary<string, PaymentHistory>> StudentHistorys = new Dictionary<string, Dictionary<string, PaymentHistory>>(); Dictionary<string, List<string>> StudentNumberList = new Dictionary<string, List<string>>(); foreach (PaymentHistory history in historys) { if (!StudentHistorys.ContainsKey(history.PaymentDetail.Extensions["MergeField::班級"])) StudentHistorys.Add(history.PaymentDetail.Extensions["MergeField::班級"], new Dictionary<string, PaymentHistory>()); if (!StudentHistorys[history.PaymentDetail.Extensions["MergeField::班級"]].ContainsKey(history.PaymentDetail.Extensions["MergeField::學號"])) StudentHistorys[history.PaymentDetail.Extensions["MergeField::班級"]].Add(history.PaymentDetail.Extensions["MergeField::學號"], history); if (!StudentNumberList.ContainsKey(history.PaymentDetail.Extensions["MergeField::班級"])) StudentNumberList.Add(history.PaymentDetail.Extensions["MergeField::班級"], new List<string>()); if (!StudentNumberList[history.PaymentDetail.Extensions["MergeField::班級"]].Contains(history.PaymentDetail.Extensions["MergeField::學號"])) StudentNumberList[history.PaymentDetail.Extensions["MergeField::班級"]].Add(history.PaymentDetail.Extensions["MergeField::學號"]); } foreach (string var in StudentNumberList.Keys) StudentNumberList[var].Sort(); //產生繳費單 ReceiptDocument rdoc = new ReceiptDocument(Template); //如果要自定樣版,可以用這個建構式。 List<PaymentReceipt> prRecood = new List<PaymentReceipt>(); nowPercent = 90; nowSet = 0; foreach (string var in StudentHistorys.Keys) { for (int i = 0; i < StudentNumberList[var].Count; i++) { //MotherForm.SetStatusBarMessage("繳費單產生中...."); MotherForm.SetStatusBarMessage(var + "繳費單產生中....", nowPercent + nowSet++ * 10 / historys.Count); Application.DoEvents(); prRecood.Add(StudentHistorys[var][StudentNumberList[var][i]].Receipt); } // 產生現有學生校車用繳費單 doc = rdoc.Generate2(prRecood); if (doc.Sections.Count != 0) { Completed(doc, var); } prRecood.Clear(); } MotherForm.SetStatusBarMessage("繳費單產生完成共" + paymentcount + "筆。"); this.Close(); }