// Load data from db into itself public override bool LoadFromDB(DBManager db, string sqlCriteria) { OdbcDataReader reader = db.Query("SELECT * FROM payment_history WHERE " + sqlCriteria); if (!reader.Read()) { return(false); } return(PaymentHistory.CreateForm(reader, this)); }
// Caution: this method implies that the history list is orderly loaded by date. // It won't go to query historical data in db so the best way to use this method is calling LoadHistory() first public DateTime GetLatestPaidDate() { if (_historyList.Count == 0) { return(DateTime.Now); } PaymentHistory ph = _historyList.Last.Value; return(ph._paidDate); }
public static bool CreateForm(OdbcDataReader reader, PaymentHistory paymentHistory) { int fCount = reader.FieldCount; for (int i = 0; i < fCount; i++) { string name = reader.GetName(i); // Map to DB field. Need to change if db changed switch (name) { case "payment_id": paymentHistory._paymentID = reader.GetInt32(i); break; case "course_id": paymentHistory._courseID = reader.GetInt32(i); break; case "paid_cost": paymentHistory._paidCost = reader.GetInt32(i); break; case "paid_date": paymentHistory._paidDate = new DateTime(reader.GetDateTime(i).Ticks); break; case "sum_all_cost": paymentHistory._sumAllCost = reader.GetInt32(i); break; case "sum_max_payable": paymentHistory._sumMaxPayable = reader.GetInt32(i); break; case "sum_paid_cost": paymentHistory._sumPaidCost = reader.GetInt32(i); break; case "cost_info": paymentHistory._costInfo = reader.GetString(i); break; case "paid_round": paymentHistory._paidRound = reader.GetInt32(i); break; case "receiver_teacher_id": paymentHistory._receiverTeacherID = reader.GetInt32(i); break; case "username": paymentHistory._username = reader.GetString(i); break; case "branch_id": paymentHistory._branchID = reader.GetInt32(i); break; // helper info } } return(reader.HasRows); }
public bool LoadHistory(DBManager db) { if (_courseID <= 0) { return(false); } _historyList.Clear(); PaymentHistory[] ph = PaymentHistory.LoadListFromDB(db, " WHERE course_id=" + this._courseID + " ORDER BY paid_date"); for (int i = 0; i < ph.Length; i++) { _historyList.AddLast(ph[i]); } return(true); }
public static PaymentHistory[] LoadListFromDBCustom(DBManager db, string sqlAll) { OdbcDataReader reader = db.Query(sqlAll); LinkedList <PaymentHistory> list = new LinkedList <PaymentHistory>(); while (reader.Read()) { list.AddLast(PaymentHistory.CreateForm(reader)); } PaymentHistory[] entities = new PaymentHistory[list.Count]; int i = 0; foreach (PaymentHistory t in list) { entities[i++] = t; } return(entities); }
protected void DoInitPrintReceiptPaymentData(string paymentID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); PaymentHistory pm = new PaymentHistory(); pm.LoadFromDB(db, " payment_id="+paymentID); pm.LoadCourse(db); pm._course.LoadTeacher(db); pm._course.LoadPaidGroup(db); // load teacher in this group Teacher[] listTeacher = pm._course._paidGroup.LoadMemberTeachers(db); pm.LoadReceiver(db); // preload all branches Dictionary<int, Branch> branches = Branch.LoadListFromDBAsMap(db, ""); // Load PaymentHistory BEFORE this PaymentHistory[] pmList = PaymentHistory.LoadListFromDB(db, " WHERE course_id='" + pm._courseID + "' and payment_id<='" + pm._paymentID + "' ORDER BY payment_id"); // Construct Teacher List StringBuilder teachTxt = new StringBuilder(); for (int i = 0; i < listTeacher.Length; i++) { string link = "TeacherManage.aspx?actPage=edit&targetID=" + listTeacher[i]._teacherID; teachTxt.Append(listTeacher[i]._firstname + " " + listTeacher[i]._surname + "<br>"); } // Construct Paid history StringBuilder phTxt = new StringBuilder(); for (int i=0;i<pmList.Length;i++) { PaymentHistory ph = pmList[i]; ph.LoadReceiver(db); ph.LoadUser(db); Branch b = branches[ph._branchID]; string link = "TeacherManage.aspx?actPage=edit&targetID=" + ph._receiverTeacherID; phTxt.AppendLine("<tr><td align=center>" + PaymentHistory.GetPaymentHistoryID(ph._paymentID) + "</td>"); phTxt.AppendLine("<td align=center>" + StringUtil.ConvertYearToEng(ph._paidDate, "yyyy/MM/dd HH:mm:ss ") + "</td>"); phTxt.AppendLine("<td align=center>" + StringUtil.Int2StrComma(ph._paidCost) + "</td>"); phTxt.AppendLine("<td align=center>" + ph._receiverTeacher._firstname + " " + ph._receiverTeacher._surname + "</td>"); phTxt.AppendLine("<td align=center>" + ph._user._firstname + " "+ ph._user._surname+ "</td>"); phTxt.AppendLine("<td align=center>" + b._branchName + "</td>"); } // User AppUser user = new AppUser(); user.LoadFromDB(db, " username='******'"); // Generate HTML content TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\payment_print.htm"); String templateContent = reader.ReadToEnd(); reader.Close(); String htmlContent = String.Format(templateContent , StringUtil.ConvertYearToEng(pm._paidDate, "yyyy/MM/dd HH:mm:ss") , pm._receiverTeacher._firstname + " " + pm._receiverTeacher._surname , pm._course._btsCourseID + " \"" + pm._course._courseName + "\"" , StringUtil.Int2StrComma(pm._paidCost) , pm._course._teacher._firstname + " " + pm._course._teacher._surname , PaidGroup.GetPaidGroupID(pm._course._paidGroup._currentRound) , teachTxt.ToString() , StringUtil.Int2StrComma(pm._sumMaxPayable) , StringUtil.Int2StrComma(pm._sumPaidCost + pm._paidCost) , phTxt.ToString() , user._firstname + " " + user._surname ); outBuf.Append(htmlContent); db.Close(); }
protected int DoPaidSubmitPayment(string courseID) { string paidCost = Request["paid_cost"]; string receiverTeacherID = Request["receiver_teacher_id"]; AppUser user = (AppUser)Session[SessionVar.USER]; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); Payment pay = new Payment(); pay.LoadFromDB(db, " course_id="+courseID); pay.LoadCourse(db); PaidGroup pg = new PaidGroup(); pg.LoadFromDB(db, " paid_group_id="+pay._course._paidGroupID); // Add history PaymentHistory ph = new PaymentHistory(pay, pg, Int32.Parse(paidCost), Int32.Parse(receiverTeacherID), user); ph.AddToDB(db); // refresh Payment record Payment.UpdatePaymentByCourse(db, Int32.Parse(courseID)); db.Commit(); // find latest payment pay.LoadHistory(db); int latestPaymentID = pay._historyList.Last.Value._paymentID; db.Close(); return latestPaymentID; }
public static LinkedList <PaymentHistory> CopyList(LinkedList <PaymentHistory> clist) { PaymentHistory[] tmpArray = new PaymentHistory[clist.Count]; clist.CopyTo(tmpArray, 0); return(new LinkedList <PaymentHistory>(tmpArray)); }
public static bool CreateForm(OdbcDataReader reader, PaymentHistory paymentHistory) { int fCount = reader.FieldCount; for (int i = 0; i < fCount; i++) { string name = reader.GetName(i); // Map to DB field. Need to change if db changed switch (name) { case "payment_id": paymentHistory._paymentID = reader.GetInt32(i); break; case "course_id": paymentHistory._courseID = reader.GetInt32(i); break; case "paid_cost": paymentHistory._paidCost = reader.GetInt32(i); break; case "paid_date": paymentHistory._paidDate = new DateTime(reader.GetDateTime(i).Ticks); break; case "sum_all_cost": paymentHistory._sumAllCost = reader.GetInt32(i); break; case "sum_max_payable": paymentHistory._sumMaxPayable = reader.GetInt32(i); break; case "sum_paid_cost": paymentHistory._sumPaidCost = reader.GetInt32(i); break; case "cost_info": paymentHistory._costInfo = reader.GetString(i); break; case "paid_round": paymentHistory._paidRound = reader.GetInt32(i); break; case "receiver_teacher_id": paymentHistory._receiverTeacherID = reader.GetInt32(i); break; case "username": paymentHistory._username = reader.GetString(i); break; case "branch_id": paymentHistory._branchID = reader.GetInt32(i); break; // helper info } } return reader.HasRows; }
public static PaymentHistory CreateForm(OdbcDataReader reader) { PaymentHistory paymentHistory = new PaymentHistory(); PaymentHistory.CreateForm(reader, paymentHistory); return paymentHistory; }
public static LinkedList<PaymentHistory> CopyList(LinkedList<PaymentHistory> clist) { PaymentHistory[] tmpArray = new PaymentHistory[clist.Count]; clist.CopyTo(tmpArray, 0); return new LinkedList<PaymentHistory>(tmpArray); }
public static PaymentHistory[] LoadListFromDBCustom(DBManager db, string sqlAll) { OdbcDataReader reader = db.Query(sqlAll); LinkedList<PaymentHistory> list = new LinkedList<PaymentHistory>(); while (reader.Read()) { list.AddLast(PaymentHistory.CreateForm(reader)); } PaymentHistory[] entities = new PaymentHistory[list.Count]; int i = 0; foreach (PaymentHistory t in list) { entities[i++] = t; } return entities; }