private void Btn1_Click(object sender, EventArgs e) { this.Visible = false; PaymentHistory form1 = new PaymentHistory(); form1.Show(); }
public async Task <IActionResult> PutPaymentHistory(Guid id, PaymentHistory paymentHistory) { if (id != paymentHistory.Id) { return(BadRequest()); } _context.Entry(paymentHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// POST: api/PaymentHistories public HttpResponseMessage PostPaymentHistory(PaymentHistory paymentHistory) { using (System.Data.Entity.DbContextTransaction transaction = db.Database.BeginTransaction()) { try { //https://www.codeproject.com/Articles/14403/Generating-Unique-Keys-in-Net paymentHistory.TranscationId = DateTime.Now.ToString().GetHashCode().ToString("x"); paymentHistory.CreatedDate = DateTime.Now; db.PaymentHistories.Add(paymentHistory); db.SaveChanges(); var userdetails = db.Users.Where(u => u.Id == paymentHistory.UserId).FirstOrDefault(); userdetails.Balance_Amount = userdetails.Balance_Amount - paymentHistory.Amount; db.Entry(userdetails).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } return(Request.CreateResponse(HttpStatusCode.OK, new { paymentHistory.Amount, paymentHistory.CreatedDate, paymentHistory.TranscationId, Routes = db.Routes.Where(r => r.RouteId == paymentHistory.RouteId).Select(r => new { r.From, r.To }), exitlocation = db.TollPlazas.Where(tp => tp.Id == paymentHistory.ExitLocId).Select(tp => tp.Location) })); }
public ActionResult Create([Bind(Include = "Id,SalaryId,Date,Sum")] PaymentHistory paymenthistory) { if (ModelState.IsValid) { ViewBag.Id = paymenthistory.Id; var test = db.Budget.Find(1); var buget = db.SalaryHistory.Find(paymenthistory.Id); if ((buget.Sum - buget.Payment) < paymenthistory.Sum) { ViewBag.Err = "Вы пытаетесь выплатить больше, чем должны."; return(View("Errors")); } else if (test.money < paymenthistory.Sum) { ViewBag.Err = "В вашем буджете не достаточно средств для выдачи Зарплаты."; return(View("Errors")); } else { db.PaymentHistory.Add(paymenthistory); db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.SalaryId = new SelectList(db.SalaryHistory, "Id", "Id", paymenthistory.SalaryId); return(View(paymenthistory)); }
public BarcodePayResponse BarcodePay(PayRequest payRequest) { _gateway = _gateways.GetByStoreId <AlipayGateway>(payRequest.GetStoreId()); var queryModel = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(payRequest.BizContent, new { body = "", total_amount = 0, out_trade_no = "", auth_code = "", subject = "" }); // 记录支付日志 var content = JsonConvert.SerializeObject(payRequest); var payHistory = new PaymentHistory(); payHistory.LogAlipayBarcodeRequestPay(queryModel.out_trade_no, queryModel.total_amount.ToString(), "saleorder", content); _db.Insert(payHistory); _db.SaveChange(); var request = new BarcodePayRequest(); request.AddGatewayData(new BarcodePayModel() { Body = queryModel.body, TotalAmount = queryModel.total_amount, Subject = queryModel.subject, OutTradeNo = queryModel.out_trade_no, AuthCode = queryModel.auth_code }); request.PaySucceed += BarcodePay_PaySucceed; request.PayFailed += BarcodePay_PayFaild; var response = _gateway.Execute(request); return(response); }
public async Task <PaymentHistory> AddPayment(PaymentHistory payment) { _db.paymentHistories.Add(payment); await _db.SaveChangesAsync(); return(payment); }
public async Task <IHttpActionResult> PutPaymentHistory(int id, PaymentHistory paymentHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != paymentHistory.paymentHistory_id) { return(BadRequest()); } db.Entry(paymentHistory).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentHistoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task<DonateViewModel> Handle(DonateCommand command, CancellationToken cancellationToken = default(CancellationToken)) { await ValidateCommand(command); var orderId = command.RequestedUserAccount.Id; // If donation is for foundation (command.UserMultiAccountId is null) then we set orderId (id of the user who makes payment) to the requested user ID var isDonationForFoundation = command.UserMultiAccountId.HasValue == false; var userPaymentForId = isDonationForFoundation ? _rootId : command.UserMultiAccountId.Value; var paymentResponse = await _bitBayPayFacade.CreatePayment(orderId, command.Amount); ValidateResponse(paymentResponse); var paymentHistory = new PaymentHistory( id: Guid.NewGuid(), paymentId: paymentResponse.Data.PaymentId, orderId: orderId, userPaymentForId: userPaymentForId, amountToPay: command.Amount, paymentFor: isDonationForFoundation ? PaymentForHelper.DonationForFoundation : PaymentForHelper.ProjectDonation ); await _paymentHistoryRepository.CreateAsync(paymentHistory); return new DonateViewModel { PaymentUrl = paymentResponse.Data.Url }; }
public async Task <IActionResult> Edit(int id, [Bind("PaymentId,TotalPayments,TotalPaid,TotalLate,TotalMonths")] PaymentHistory paymentHistory) { if (id != paymentHistory.PaymentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(paymentHistory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentHistoryExists(paymentHistory.PaymentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(paymentHistory)); }
public ActionResult DeleteConfirmed(int id) { PaymentHistory paymenthistory = db.PaymentHistory.Find(id); db.PaymentHistory.Remove(paymenthistory); db.SaveChanges(); return(RedirectToAction("Index")); }
private void paymentHistoryToolStripMenuItem_Click(object sender, EventArgs e) { PaymentHistory ledger = new PaymentHistory(); //this.Hide(); ledger.ShowDialog(); //this.Close(); }
public void TestPaymentHistory() { PaymentHistory history = GetPaymentHistory(); Assert.AreEqual(history.count, 1); Assert.AreEqual(history.next_id, "1"); Assert.AreEqual(history.payments.Count, 1); }
public async Task <ActionResult <PaymentHistory> > PostPaymentHistory(PaymentHistory paymentHistory) { paymentHistory.PaymentMadeOn = DateTime.Now; paymentHistory.Id = Guid.NewGuid(); _context.PaymentHistories.Add(paymentHistory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPaymentHistory", new { id = paymentHistory.Id }, paymentHistory)); }
public IHttpActionResult RemovePayment(PaymentHistory paymenthistorytoremove) { PaymentHistory getpaymenttoremove = unitOfWork.PaymentHistories.Get(paymenthistorytoremove.Id); getpaymenttoremove.IsTerminated = true; unitOfWork.PaymentHistories.Update(p => p.Id == getpaymenttoremove.Id, getpaymenttoremove); unitOfWork.Complete(); return(Ok("PaymentHistory removed Successfully")); }
private void SavePayResponseHistory(IResponse response, bool success) { var result = response as BarcodePayResponse; var payHistory = new PaymentHistory(); payHistory.LogWechatBarcodeResponsePay(result.OutTradeNo, result.TotalAmount.ToString(), "saleorder", result.Raw, success); _db.Insert(payHistory); _db.SaveChange(); }
public void PaymentHistoryQueryParametersTest() { APIContext context = new APIContext(AccessToken); QueryParameters queryParameters = new QueryParameters(); queryParameters.SetCount("10"); PaymentHistory history = Payment.Get(context, queryParameters); Assert.AreEqual(10, history.count); }
public void PaymentHistoryTest() { APIContext context = new APIContext(AccessToken); Dictionary <string, string> containerDictionary = new Dictionary <string, string>(); containerDictionary.Add("count", "10"); PaymentHistory paymentHistory = Payment.List(context, containerDictionary); Assert.AreEqual(10, paymentHistory.count); }
private PaymentHistoryController GetPaymentHistoryController() { _connectionFactory = new ConnectionFactory(); _context = _connectionFactory.CreateContextForSQLite(); var paymentHistory = new PaymentHistory(_context); SeedPaymentHistoryData(); return(new PaymentHistoryController(paymentHistory)); }
public async Task <IActionResult> Create([Bind("PaymentId,TotalPayments,TotalPaid,TotalLate,TotalMonths")] PaymentHistory paymentHistory) { if (ModelState.IsValid) { _context.Add(paymentHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(paymentHistory)); }
public ActionResult Edit([Bind(Include = "Id,SalaryId,Date,Sum")] PaymentHistory paymenthistory) { if (ModelState.IsValid) { db.Entry(paymenthistory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SalaryId = new SelectList(db.SalaryHistory, "Id", "Id", paymenthistory.SalaryId); return(View(paymenthistory)); }
public void GetPaymentHistory() { string accessToken = AccessToken; APIContext apiContext = new APIContext(accessToken); Dictionary <string, string> containerDictionary = new Dictionary <string, string>(); containerDictionary.Add("count", "10"); PaymentHistory paymentHistory = Payment.List(apiContext, containerDictionary); Assert.AreEqual(10, paymentHistory.count); }
public IHttpActionResult AddPayment(PaymentHistory newpaymenthistory) { Payment newpayment = unitOfWork.Payments.Get(newpaymenthistory.studentId); newpayment.amountpaid += newpaymenthistory.amount; newpayment.amountowing -= newpaymenthistory.amount; unitOfWork.Payments.Update(p => p.Id == newpayment.Id, newpayment); unitOfWork.PaymentHistories.Add(newpaymenthistory); unitOfWork.Complete(); return(Ok("One new Payment Successfully Added")); }
public bool AddPayment(int person_id, double amount, PaymentMethod type, string transaction_id = "000000") { PaymentHistory payment = new PaymentHistory() { PersonId = person_id, Amount = amount, Type = type }; return(db.Save(payment)); }
public void GetPaymentHistoryQueryParameters() { string accessToken = AccessToken; APIContext apiContext = new APIContext(accessToken); QueryParameters queryParameters = new QueryParameters(); queryParameters.SetCount("10"); PaymentHistory paymentHistory = Payment.Get(apiContext, queryParameters); Assert.AreEqual(10, paymentHistory.count); }
public IHttpActionResult GetPaymentHistory(int id) { PaymentHistory paymentHistory = db.PaymentHistory.Find(id); if (paymentHistory == null) { return(NotFound()); } return(Ok(paymentHistory)); }
public async Task <IHttpActionResult> GetPaymentHistory(int id) { PaymentHistory paymentHistory = await db.PaymentHistories.FindAsync(id); if (paymentHistory == null) { return(NotFound()); } return(Ok(paymentHistory)); }
public IHttpActionResult PostPaymentHistory(PaymentHistory paymentHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PaymentHistory.Add(paymentHistory); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = paymentHistory.Id }, paymentHistory)); }
public static PaymentHistory GetPaymentHistory() { List <Payment> paymentList = new List <Payment>(); paymentList.Add(PaymentTest.GetPaymentForSale()); PaymentHistory history = new PaymentHistory(); history.count = 1; history.payments = paymentList; history.next_id = "1"; return(history); }
private PaymentHistory PrepareNotifyPaymentHistory(Transaction transcation) { var paymentHistory = new PaymentHistory(); NotifEyeTransactionInfo transInfo = (NotifEyeTransactionInfo)transcation.TransactionInfo; paymentHistory.AccountID = transInfo.AccountID; paymentHistory.CustomerID = transInfo.CustomerID; paymentHistory.ProductName = AppConstant.NotifEye; paymentHistory.Data = JsonConvert.SerializeObject(transInfo); return(paymentHistory); }
private PaymentHistory GetPaymentHistory() { List <Payment> paymentList = new List <Payment>(); paymentList.Add(CreatePayment()); PaymentHistory history = new PaymentHistory(); history.count = 1; history.payments = paymentList; history.next_id = "1"; return(history); }
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) { 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 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(); }