示例#1
0
        protected void DoViewPayment(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            db.Connect();

            thePayment = new Payment();
            thePayment.LoadFromDB(db, " course_id=" + courseID);
            thePayment.LoadHistory(db);
            thePayment.LoadCourse(db);
            Course c = thePayment._course;
            c.LoadTeacher(db);
            c.LoadPaidGroup(db);
            // preload all branches
            Dictionary<int, Branch> branches = Branch.LoadListFromDBAsMap(db, "");

            PaidGroup pg = new PaidGroup();
            pg.LoadFromDB(db, " paid_group_id="+c._paidGroupID);
            // Load teachers in this group
            listTeacher = pg.LoadMemberTeachers(db);

            // Generate HTML content
            TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\payment_view.htm");
            String templateContent = reader.ReadToEnd();
            reader.Close();

            // 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("<a href=\"" + link + "\" >" + listTeacher[i]._firstname + " " + listTeacher[i]._surname + "</a><br>");
            }

            // Construct RaitInfo List
            StringBuilder rinfoTxt = new StringBuilder();
            for (int i = 0; i < pg._rateInfo.Length; i++)
            {
                rinfoTxt.Append("มากกว่า " + StringUtil.Int2StrComma(pg._rateInfo[i]._bound) + " บาท ได้รับ " + pg._rateInfo[i]._percent + " %<br>");
            }

            // Construct Paid history
            StringBuilder phTxt = new StringBuilder();
            foreach (PaymentHistory ph in thePayment._historyList)
            {
                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><a href=\""+link+"\" >" + ph._receiverTeacher._firstname + " " + ph._receiverTeacher._surname + "</a></td>");
                phTxt.AppendLine("<td align=center>" + ph._user._firstname + " " + ph._user._surname + "</td>");
                phTxt.AppendLine("<td align=center>" + b._branchName + "</td>");
                phTxt.AppendLine("<td align=center><a href=\"javascript:doInitPrint(" + ph._paymentID + ")\"><img src=\"" + Config.URL_PIC_SYS + "/view.gif\" border=0></a> </td>");
            }

            String htmlContent =
                String.Format(templateContent
                    , c._courseName
                    , "<a href=\"TeacherManage.aspx?actPage=edit&targetID="+c._teacherID + "\" >" + c._teacher._firstname + " " + c._teacher._surname + "</a>"
                    , PaidGroup.GetPaidGroupID(c._paidGroupID) + " " + c._paidGroup._name
                    , teachTxt.ToString()
                    , rinfoTxt.ToString()
                    , StringUtil.Int2StrComma(thePayment._sumAllCost)
                    , StringUtil.Int2StrComma(thePayment._sumMaxPayable)
                    , StringUtil.Int2StrComma(thePayment._sumPaidCost)
                    , StringUtil.Int2StrComma(thePayment._sumMaxPayable - thePayment._sumPaidCost)
                    , phTxt.ToString()
                    );

            outBuf.Append(htmlContent);

            db.Close();
        }
示例#2
0
        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;
        }