Exemplo n.º 1
0
 protected int GetDiscountedCost(LinkedList<Course> courses, Course aCourse)
 {
     foreach (Course c in courses)
     {
         if (aCourse._courseID == c._courseID)
         {
             return c._discountedCost;
         }
     }
     return 0;
 }
Exemplo n.º 2
0
        public void DoEditCourse(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            theCourse = new Course();
            if (!theCourse.LoadFromDB(db, "course_id=" + courseID)) theCourse = null;

            roomList = Room.LoadListFromDBCustom(db, "SELECT r.room_id, r.name, b.branch_name as branch_name FROM room r, branch b WHERE r.branch_id=b.branch_id");
            teacherList = Teacher.LoadListFromDB(db, " ORDER BY firstname");
            paidGroupList = PaidGroup.LoadListFromDB(db, " ORDER BY paid_group_id");

            db.Close();
        }
Exemplo n.º 3
0
        protected void ProcessWizAddSelectedCourse(string course_id)
        {
            // get data from session
            RegisTransaction reg = (RegisTransaction)Session[SessionVar.CURRENT_REGIS];
            if (reg == null) { reg = new RegisTransaction(); }

            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            Course course = new Course();
            course.LoadFromDB(db," course_id=" + course_id);
            db.Close();

            if (course != null)
            {
                reg.AddCourse(course);
            }

            // save back to session
            Session[SessionVar.CURRENT_REGIS] = reg;
        }
Exemplo n.º 4
0
        public static bool CreateForm(OdbcDataReader reader, Course course)
        {
            if (course._teacher == null) { course._teacher = new Teacher(); }
            if (course._paidGroup == null) { course._paidGroup = new PaidGroup(); }

            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 "course_id": course._courseID = reader.GetInt32(i);
                                      break;
                    case "bts_course_id": course._btsCourseID = reader.GetString(i);
                                      break;
                    case "course_name": course._courseName = reader.GetString(i);
                                      break;
                    case "short_name": course._shortName = reader.GetString(i);
                                      break;
                    case "course_desc": course._courseDesc = reader.GetString(i);
                                      break;
                    case "course_type": course._courseType = reader.GetString(i);
                                      break;
                    case "room_id": course._roomID = reader.GetInt32(i);
                                      break;
                    case "teacher_id": course._teacherID = reader.GetInt32(i);
                                      course._teacher._teacherID = course._teacherID;
                                      break;
                    case "paid_group_id": course._paidGroupID = reader.GetInt32(i);
                                      course._paidGroup._paidGroupID = course._paidGroupID;
                                      break;
                    case "category": course._category = reader.GetString(i);
                                      break;
                    case "start_date": course._startdate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "end_date": course._enddate = new DateTime(reader.GetDate(i).Ticks);
                                      break;
                    case "day_of_week": course._dayOfWeek = reader.GetString(i);
                                      break;
                    case "open_time": course._opentime = reader.GetString(i);
                                      break;
                    case "cost":      course._cost = reader.GetInt32(i);
                                      course._discountedCost = course._cost;
                                      break;
                    case "seat_limit": course._seatLimit = reader.GetInt32(i);
                                      break;
                    case "bank_regis_limit": course._bankRegisLimit = reader.GetInt32(i);
                                      break;
                    case "image": course._img = reader.GetString(i);
                                      break;
                    case "is_active": course._isActive = reader.GetInt32(i) > 0 ? true : false;
                                      break;
                    // helper info
                    case "teacher_firstname":
                                      course._teacher._firstname = reader.GetString(i);
                                      break;
                    case "teacher_surname":
                                      course._teacher._surname = reader.GetString(i);
                                      break;
                    case "num_registered":
                                      course._numRegistered = reader.GetInt32(i);
                                      break;

                }
            }
            return reader.HasRows;
        }
Exemplo n.º 5
0
 public static Course CreateForm(OdbcDataReader reader)
 {
     Course course = new Course();
     Course.CreateForm(reader, course);
     return course;
 }
Exemplo n.º 6
0
        public static bool CreateForm(OdbcDataReader reader, Course course)
        {
            if (course._teacher == null)
            {
                course._teacher = new Teacher();
            }
            if (course._paidGroup == null)
            {
                course._paidGroup = new PaidGroup();
            }

            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 "course_id": course._courseID = reader.GetInt32(i);
                    break;

                case "bts_course_id": course._btsCourseID = reader.GetString(i);
                    break;

                case "course_name": course._courseName = reader.GetString(i);
                    break;

                case "short_name": course._shortName = reader.GetString(i);
                    break;

                case "course_desc": course._courseDesc = reader.GetString(i);
                    break;

                case "course_type": course._courseType = reader.GetString(i);
                    break;

                case "room_id": course._roomID = reader.GetInt32(i);
                    break;

                case "teacher_id": course._teacherID = reader.GetInt32(i);
                    course._teacher._teacherID       = course._teacherID;
                    break;

                case "paid_group_id": course._paidGroupID = reader.GetInt32(i);
                    course._paidGroup._paidGroupID        = course._paidGroupID;
                    break;

                case "category": course._category = reader.GetString(i);
                    break;

                case "start_date": course._startdate = new DateTime(reader.GetDate(i).Ticks);
                    break;

                case "end_date": course._enddate = new DateTime(reader.GetDate(i).Ticks);
                    break;

                case "day_of_week": course._dayOfWeek = reader.GetString(i);
                    break;

                case "open_time": course._opentime = reader.GetString(i);
                    break;

                case "cost":      course._cost = reader.GetInt32(i);
                    course._discountedCost     = course._cost;
                    break;

                case "seat_limit": course._seatLimit = reader.GetInt32(i);
                    break;

                case "bank_regis_limit": course._bankRegisLimit = reader.GetInt32(i);
                    break;

                case "image": course._img = reader.GetString(i);
                    break;

                case "is_active": course._isActive = reader.GetInt32(i) > 0 ? true : false;
                    break;

                // helper info
                case "teacher_firstname":
                    course._teacher._firstname = reader.GetString(i);
                    break;

                case "teacher_surname":
                    course._teacher._surname = reader.GetString(i);
                    break;

                case "num_registered":
                    course._numRegistered = reader.GetInt32(i);
                    break;
                }
            }
            return(reader.HasRows);
        }
Exemplo n.º 7
0
        // refresh latest payment data
        // this table data is sensitive with high update rate env
        // TODO: ensure that high transaction rate will not affect this table
        public static int UpdatePaymentByCourse(DBManager db, Course course)
        {
            // load all courses in the same group
            Course[] coursesSameGroup = Course.LoadListFromDB(db, " WHERE paid_group_id="+course._paidGroupID + " ORDER BY " + ORDER_BY);

            int allIncome = 0; // in the same group
            foreach (Course c in coursesSameGroup)
            {
                c.LoadPaidGroup(db);

                int thisIncome = 0;
                Registration[] reg = Registration.LoadListFromDB(db, " WHERE course_id=" + c._courseID);
                for (int i = 0; i < reg.Length; i++)
                {
                    thisIncome += reg[i]._discountedCost;
                }

                Payment payment = new Payment();
                if (!payment.LoadFromDB(db, " course_id=" + c._courseID)) // not found, add new
                {
                    payment._courseID = c._courseID;
                    payment._sumAllCost = thisIncome;
                    payment._sumMaxPayable = c._paidGroup.GetMaxPayableByRate(allIncome, thisIncome);
                    payment._sumPaidCost = 0;
                    payment._lastPaidDate = DateTime.Now;
                    payment._paidRound = c._paidGroup._currentRound;
                    payment._status = Payment.STATUS_OK;
                    payment.AddToDB(db);

                }
                else
                {
                    // collect historical data
                    payment.LoadHistory(db);

                    payment._sumAllCost = thisIncome;
                    payment._sumMaxPayable = c._paidGroup.GetMaxPayableByRate(allIncome, thisIncome);
                    payment._sumPaidCost = payment.GetHistoricalSumPaidCost();
                    payment._lastPaidDate = payment.GetLatestPaidDate();
                    payment._paidRound = c._paidGroup._currentRound;
                    payment._status = Payment.STATUS_OK;
                    payment.UpdateToDB(db);

                }
                allIncome += thisIncome;
            }
            return 0;
        }
Exemplo n.º 8
0
        protected String[,] LoadStudentList(DBManager db)
        {
            // Load all information
            Course c = new Course();
            c.LoadFromDB(db);

            String sqlCount = "SELECT Count(*) FROM student";
            String sql = "SELECT s.student_id, s.firstname, s.surname, s.nickname, s.sex, s.birthday, s.citizen_id, s.addr, s.email, s.tel, s.tel2, s.school, s.level, s.create_date, s.is_active";

            String sqlWhere = " FROM student s"
                             + " ORDER BY s.student_id";

            int num = db.QueryCount(sqlCount);

            String[,] result = new String[num, 14];

            int n = 0;
            OdbcDataReader reader = db.Query(sql + sqlWhere);
            while (reader.Read())
            {
                int fCount = reader.FieldCount;
                for (int i = 0; i < fCount; i++)
                {
                    string name = reader.GetName(i);
                    switch (name)
                    {
                        case "student_id": result[n, 0] = Student.GetStudentID(reader.GetInt32(i).ToString());
                            break;
                        case "firstname": result[n, 1] = reader.GetString(i);
                            break;
                        case "surname": result[n, 1] = result[n, 1] + " " + reader.GetString(i);
                            break;
                        case "nickname": result[n, 2] = reader.GetString(i);
                            break;
                        case "sex": result[n, 3] = reader.GetString(i);
                            break;
                        case "birthday": result[n, 4] = reader.GetDate(i).ToString();
                            break;
                        case "citizen_id": result[n, 5] = reader.GetString(i);
                            break;
                        case "addr": result[n, 6] = reader.GetString(i);
                            break;
                        case "email": result[n, 7] = reader.GetString(i);
                            break;
                        case "tel": result[n, 8] = "=\"" + reader.GetString(i) + "\"";
                            break;
                        case "tel2": result[n, 9] = "=\"" + reader.GetString(i) + "\"";
                            break;
                        case "school": result[n, 10] = reader.GetString(i);
                            break;
                        case "level": result[n, 11] = StringUtil.ConvertEducateLevel(reader.GetInt32(i));
                            break;
                        case "create_date": result[n, 12] = reader.GetDate(i).ToString();
                            break;
                        case "is_active": result[n, 13] = (reader.GetInt32(i) == 1 ? "ปกติ" : "ลบ");
                            break;
                    }
                }
                n++;
            }

            return result;
        }
Exemplo n.º 9
0
        protected void DoViewCourse(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            theCourse = new Course();
            theCourse.LoadFromDB(db, " course_id=" + courseID);
            theCourse.LoadTeacher(db);
            theCourse.LoadPaidGroup(db);
            db.Close();

            TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\course_view.htm");
            String templateContent = reader.ReadToEnd();
            reader.Close();

            String[,] students = LoadStudentList(db, courseID);
            StringBuilder  stdTxt = new StringBuilder();
            int numStudent = (students.Length / 9);
            int numCancel = 0;
            for (int i = 0; i < numStudent; i++)
            {
                stdTxt.Append("<tr>");
                for (int j = 0; j < 9; j++)
                {
                    // edit registration
                    if (j == 8)
                    {
                        stdTxt.Append("<td>&nbsp&nbsp<a href=\"javascript:jumpToEditRegistration(" + students[i, j] + ")\"><img src=\"img/sys/edit.gif\" border=\"0\" alt=\"Edit\"></a></td>");
                        continue;
                    }

                    stdTxt.Append("<td>&nbsp&nbsp" + students[i, j]+"</td>");
                    if ((j == 6) && (students[i, j].Equals("ยกเลิก")))
                    {
                        numCancel++;
                    }

                }
                stdTxt.Append("</tr>");
            }

            String courseScheduleDetail = "-";
            if (theCourse._courseType == "คอร์สสด") {
                courseScheduleDetail =  theCourse._startdate.ToString("dd/MM/yyyy", ci) + " - " + theCourse._enddate.ToString("dd/MM/yyyy", ci) + "<br>" + theCourse._dayOfWeek + " " + theCourse._opentime;
            }

            String htmlContent =
                String.Format(templateContent
                    , Config.URL_PIC_COURSE + "/" + theCourse._img
                    , theCourse._btsCourseID + " " + theCourse._courseName
                    , theCourse._shortName
                    , theCourse._courseType
                    , theCourse._category
                    , courseScheduleDetail
                    , theCourse._teacher._firstname + " " + theCourse._teacher._surname
                    , PaidGroup.GetPaidGroupID(theCourse._paidGroupID)+ " " + theCourse._paidGroup._name
                    , StringUtil.Int2StrComma(theCourse._cost)
                    , theCourse._seatLimit.ToString()
                    , theCourse._bankRegisLimit.ToString()
                    , (numStudent - numCancel).ToString()
                    , theCourse._courseDesc
                    , "สมัคร " + numStudent + " คน ยกเลิก " + (numCancel) + " คน คงเหลือ " + (numStudent - numCancel) + " คน"
                    , stdTxt.ToString() );

            outBuf.Append(htmlContent);
        }
Exemplo n.º 10
0
        protected String DoInitPrintStudentList(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            theCourse = new Course();
            theCourse.LoadFromDB(db);

            String[,] students = LoadStudentList(db, courseID);
            StringBuilder  stdTxt = new StringBuilder();
            for (int i=0;i<students.Length/9;i++) {
                stdTxt.Append("<tr>");
                for (int j = 0; j < 8; j++)
                {
                    stdTxt.Append("<td nowrap><font size=2>&nbsp&nbsp" + students[i, j]+"</font></td>");

                }
                stdTxt.Append("</tr>");
            }

            TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\course_print_student.htm");
            String templateContent = reader.ReadToEnd();
            reader.Close();

            String htmlContent =
                String.Format(templateContent
                    , theCourse._btsCourseID + " " + theCourse._courseName
                    , stdTxt.ToString() );

            return htmlContent;
        }
Exemplo n.º 11
0
        protected String DoSaveStudentListAsExcel(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            theCourse = new Course();
            theCourse._courseID = Int32.Parse(courseID);
            theCourse.LoadFromDB(db);

            String prefix = "course_students_";
            int numDel = DeleteOldReportFile(prefix);
            log.StampLine(Logger.INFO, "Delete old " + prefix + " " + numDel + " files");

            DateTime now = DateTime.Now;
            String dateStr = StringUtil.FillString(now.Ticks.ToString(), "0", 20, true) + "_"
                + StringUtil.FillString(Session.GetHashCode().ToString(), "0", 10, true);

            String filename = prefix + dateStr + ".csv";
            String physPath = Config.PATH_APP_ROOT + "\\file\\" + filename;
            String urlPath = "file/" + filename;

            FileStream fs = File.Open(physPath, FileMode.OpenOrCreate, FileAccess.Write);
            TextWriter writer = new StreamWriter(fs, System.Text.Encoding.UTF8);

            StringBuilder stdTxt = new StringBuilder();

            /*

            Encoding tis620 = Encoding.GetEncoding("tis-620");
            Encoding utf8 = Encoding.UTF8;

            Encoding encFrom = Encoding.Unicode;
            Encoding encTo = Encoding.UTF8;

            String unicodeString = "รหัสชีวิต";
            // Convert the string into a byte[].
             byte[] unicodeBytes = encFrom.GetBytes(unicodeString);

             // Perform the conversion from one encoding to the other.
             byte[] asciiBytes = Encoding.Convert(encFrom, encTo, unicodeBytes);

             // Convert the new byte[] into a char[] and then into a string.
             // This is a slightly different approach to converting to illustrate
             // the use of GetCharCount/GetChars.
             char[] asciiChars = new char[encTo.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
             encTo.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);

            //         char[] unicodeChars = new char[encFrom.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];
            //         encFrom.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);

             //stdTxt.Append("ก");
            */
            /*
             stdTxt.Append(asciiChars + "\n");
             stdTxt.Append(unicodeString + "\n");
               // stdTxt.Append(unicodeChars+"\n");
            stdTxt.Append("คิดถึงจัง");*/

             //stdTxt.AppendLine((asciiString);
             //stdTxt.AppendLine(unicodeString);
            // รหัส,ชื่อ-นามสกุล,โรงเรียน,โทร.,อีเมล์,จำนวนเงิน,หมายเหตุ

            //stdTxt.Append(StringUtil.GetExcelEncodingPrefix());

            stdTxt.Append("รายชิ้อนักเรียนที่ลงทะเบียนคอร์ส " + theCourse._btsCourseID + " " + theCourse._courseName + "\n");
            stdTxt.Append("วันที่สมัคร,ชื่อ-นามสกุล,โรงเรียน,โทร.,อีเมล์,จำนวนเงิน, สถานะ, หมายเหตุ \n" );

            String[,] students = LoadStudentList(db, courseID);
            for (int i = 0; i < students.Length / 9; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    stdTxt.Append(StringUtil.AddCSVDQuote(students[i, j])+",");

                }
                stdTxt.AppendLine("");

                if (i % 100 == 99)
                {
                    writer.Write(stdTxt);
                    stdTxt = new StringBuilder();
                }
            }
            if (stdTxt.Length > 0)
            {
                writer.Write(stdTxt);
            }

            writer.Close();

            return urlPath;
        }
Exemplo n.º 12
0
        protected void DoDeleteCourse(string courseID)
        {
            Course t = new Course();
            t._courseID = Int32.Parse(courseID);
            DBManager db = null;
            try {
                db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
                db.Connect();

                // Check if payment id paid all
                // If no, unable to delete this course
                // Else
                // Update status=1 (invalid)
                Payment payment = new Payment();
                if (payment.LoadFromDB(db, " course_id=" + courseID))
                {
                    if (payment._sumPaidCost < payment._sumAllCost) // not yet paid all
                    {
                        errorText = "ยังมีเงินที่เบิกจ่ายไม่หมด " + (payment._sumAllCost - payment._sumPaidCost);
                        return;
                    }
                    else
                    {
                        payment._status = Payment.STATUS_INVALID;
                        payment.UpdateToDB(db);
                    }
                }

                // Delete course
                t.DeleteToDB(db);
            } finally {
                if (db!=null) db.Close();
            }
        }
Exemplo n.º 13
0
        public bool LoadCourse(DBManager db)
        {
            if (_courseID <= 0) return false;
            _course = new Course();
            _course.LoadFromDB(db, " course_id=" + _courseID);

            // Assign loaded data to helper
            this._btsCourseID = _course._btsCourseID;

            this._courseType = _course._courseType;
            this._courseCategotry = _course._category;
            this._courseStart = _course._startdate;
            this._courseEnd = _course._enddate;

            return true;
        }
Exemplo n.º 14
0
 public static LinkedList <Course> CopyList(LinkedList <Course> clist)
 {
     Course[] tmpArray = new Course[clist.Count];
     clist.CopyTo(tmpArray, 0);
     return(new LinkedList <Course>(tmpArray));
 }
Exemplo n.º 15
0
        protected void ProcessWizListSelectedCourse(string enableAction, bool recalculatePromotion)
        {
            bool enableAct;
            Boolean.TryParse(enableAction,out enableAct);

            outBuf.Append("<br>");
            // get data from session
            RegisTransaction reg = (RegisTransaction)Session[SessionVar.CURRENT_REGIS];
            if (reg == null) { return; }
            if (reg._courses.Count == 0)
            {
                outBuf.Append("&nbsp&nbspยังไม่ได้เลือกคอร์ส");
            }

            if (recalculatePromotion)
            {

                // copy to temp list
                Course[] courses = new Course[reg._courses.Count];
                reg._courses.CopyTo(courses, 0);
                LinkedList<Course> copyCourses = new LinkedList<Course>(courses);

                // find matching promotions
                DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);

                PromotionMatcher matcher = Promotion.LoadFromDBByMatchingCourses(db, reg._courses);
                db.Close();

                // store back to reg
                reg._modCourses = (matcher._matchedCourses != null) ? matcher._matchedCourses : new LinkedList<Course>();
                reg._modPromotions = (matcher._matchedPromotions != null) ? matcher._matchedPromotions : new LinkedList<Promotion>();
                Session[SessionVar.CURRENT_REGIS] = reg;
            }

            // print
            Promotion[] proArray = new Promotion[reg._modPromotions.Count];
            reg._modPromotions.CopyTo(proArray, 0);

            int sumCost = 0;
            int sumFullCost = 0;
            outBuf.Append("<table>");
            for (int i = 0; i < proArray.Length; i++)
            {
                sumCost+=proArray[i]._discountedCost;
                outBuf.Append("<tr valign=middle><td>&nbsp&nbsp&nbsp</td><td>" + Promotion.GetPromotionID(proArray[i]._promotionID) + " " + proArray[i]._promotionName);
                string costTxt = StringUtil.Int2StrComma(proArray[i]._discountedCost);
                if (!enableAct)
                {
                    costTxt = " <a href=\"javascript:modifyPCost(" + proArray[i]._promotionID + "," + proArray[i]._discountedCost + ")\" >" + StringUtil.Int2StrComma(proArray[i]._discountedCost) + "</a>";
                }
                if (proArray[i]._cost != proArray[i]._discountedCost)
                {
                    costTxt = " <strike>" + StringUtil.Int2StrComma(proArray[i]._cost) + "</strike> &nbsp ลดพิเศษเหลือ " + costTxt;
                }

                outBuf.Append(" ( <strike>" + StringUtil.Int2StrComma(proArray[i].GetFullCost()) + "</strike> &nbsp"+costTxt+" )</td></tr>");
                for (int j = 0; j < proArray[i]._courses.Length; j++)
                {
                    Course c = proArray[i]._courses[j];
                    sumFullCost += c._cost;
                    string jsShowDiv = " onmouseover=\"queryCourseDetail(" + c._courseID + ");showDivAt('divdetail')\" onmouseout=\"hideDiv('divdetail')\" ";
                    string icon = "<img style=\"cursor:pointer\" border=0 src=\"" + Config.URL_PIC_SYS + "/info.gif\" " + jsShowDiv + ">";
                    string courseLine = c._btsCourseID + "&nbsp" + c._courseName;
                    string costLine = " ( <strike>" + StringUtil.Int2StrComma(c._cost) + "</strike> )";

                    if (enableAct)
                    {
                        courseLine = "<a href=\"javascript:removeCourse('" + c._courseID + "')\">" + courseLine + "</a>";
                    }
                    outBuf.Append("<tr valign=middle><td>&nbsp&nbsp" + icon + "</td><td>&nbsp&nbsp&nbsp" + courseLine + costLine + "</td></tr>");
                    // remove from copied list
                    //copyCourses.Remove(c);
                }
            }

            // print no promotion
            foreach (Course c in reg._modCourses)
            {
                sumCost+=c._discountedCost;
                sumFullCost += c._cost;
                string jsShowDiv = " onmouseover=\"queryCourseDetail(" + c._courseID + ");showDivAt('divdetail')\" onmouseout=\"hideDiv('divdetail')\" ";
                string icon = "<img style=\"cursor:pointer\" border=0 src=\"" + Config.URL_PIC_SYS + "/info.gif\" " + jsShowDiv + ">";
                string courseLine = c._btsCourseID + "&nbsp" + c._courseName;
                if (enableAct)
                {
                    courseLine = "<a href=\"javascript:removeCourse('" + c._courseID + "')\">" + courseLine + "</a>";
                }

                string costTxt = " ( ";
                if (c._cost != c._discountedCost)
                {
                    costTxt = costTxt + " <strike>" + StringUtil.Int2StrComma(c._cost) + "</strike> &nbsp ลดพิเศษเหลือ ";
                }
                if (!enableAct)
                {
                    costTxt = costTxt + "<a href=\"javascript:modifyCCost(" + c._courseID + "," + c._discountedCost + ")\" >" + StringUtil.Int2StrComma(c._discountedCost) + "</a> )";
                }
                else
                {
                    costTxt = costTxt + StringUtil.Int2StrComma(c._discountedCost) + " )";
                }

                outBuf.Append("<tr valign=middle><td>&nbsp&nbsp" + icon + "</td><td>" + courseLine + costTxt + "</td></tr>");
            }
            outBuf.Append("</table><br><br>");
            outBuf.Append("&nbsp&nbsp<b>รวมค่าใช้จ่ายทั้งหมด <strike>"+ StringUtil.Int2StrComma(sumFullCost) +"</strike>&nbsp<font size=2 color=red>" + StringUtil.Int2StrComma(sumCost) + "</font> บาท</b>" );
        }
Exemplo n.º 16
0
        protected String[,] LoadStudentList(DBManager db, string courseID)
        {
            // Load all information
            Course c = new Course();
            c.LoadFromDB(db);

            String sqlCount = "SELECT Count(*) ";
            String sql = "SELECT r.regis_date, s.firstname, s.surname, s.email, s.tel, s.school ,r.discounted_cost as discounted_cost, r.note as note, r.status as status, r.regis_id as regis_id ";

            String sqlWhere = " FROM student s, registration r "
                             + " WHERE s.student_id=r.student_id AND s.is_active=1 AND r.course_id=" + courseID + " ORDER BY r.status, s.firstname, s.surname";

            int num = db.QueryCount(sqlCount + sqlWhere);

            String[,] result = new String[num,9];

            int n = 0;
            OdbcDataReader reader =  db.Query(sql + sqlWhere);
            while (reader.Read())
            {
                int fCount = reader.FieldCount;
                for (int i = 0; i < fCount; i++)
                {
                    string name = reader.GetName(i);
                    switch (name)
                    {
                        case "regis_date": result[n, 0] = new DateTime(reader.GetDateTime(i).Ticks).ToString();
                                           break;
                        case "firstname":  result[n,1] = reader.GetString(i);
                                           break;
                        case "surname": result[n, 1] = result[n, 1] + " " + reader.GetString(i);
                                           break;
                        case "school": result[n, 2] = reader.GetString(i);
                                           break;
                        case "tel": result[n, 3] =  reader.GetString(i);
                                           break;
                        case "email": result[n, 4] = reader.GetString(i);
                                           break;
                        case "discounted_cost": result[n, 5] = reader.GetInt32(i).ToString();
                                           break;
                        case "status": result[n, 6] = (reader.GetInt32(i)==0?"ปกติ":"ยกเลิก");
                                           break;
                        case "note": result[n, 7] = reader.GetString(i);
                                           break;
                        case "regis_id": result[n, 8] = reader.GetInt32(i).ToString();
                                           break;
                    }
                }
                n++;
            }

            return result;
        }
Exemplo n.º 17
0
        protected void ProcessWizQueryCourseDetail(string courseID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            Course c = new Course();
            c.LoadFromDB(db, " course_id="+courseID);
            c.LoadTeacher(db);
            db.Close();

            TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\" + AjaxSvc.WIZ_Q_COURSE_DETAIL + ".htm");
            String templateContent = reader.ReadToEnd();
            reader.Close();

            String htmlContent =
                String.Format(templateContent
                    , Config.URL_PIC_COURSE + "/" + c._img
                    , c._btsCourseID + " " + c._courseName
                    , c._startdate.ToString("dd/MM/yyyy", ci) + " - " + c._enddate.ToString("dd/MM/yyyy", ci) + "<br>"
                      + c._dayOfWeek + " " + c._opentime
                    , c._teacher._firstname + " " + c._teacher._surname
                    , StringUtil.Int2StrComma(c._cost)
                    , c._courseDesc);

            outBuf.Append(htmlContent);
        }
Exemplo n.º 18
0
        protected void DoAddSubmitCourse()
        {
            Course c = new Course();

            // validate data
            c._btsCourseID = Request["bts_course_id"];
            c._courseName = Request["course_name"];
            c._shortName = Request["short_name"];
            c._courseType = Request["course_type"];
            c._courseDesc = Request["course_desc"];
            c._roomID = Int32.Parse(Request["room_id"]);
            c._teacherID = Int32.Parse(Request["teacher_id"]);
            c._paidGroupID = Int32.Parse(Request["paid_group_id"]);
            c._category = Request["category"];

            c._startdate = StringUtil.getDate(Request["startdate"]);
            c._enddate = StringUtil.getDate(Request["enddate"]);
            c._dayOfWeek = Request["day_of_week"];
            c._opentime = Request["opentime"];

            c._cost =Int32.Parse(Request["cost"]);
            c._seatLimit = Int32.Parse(Request["seat_limit"]);
            c._bankRegisLimit = 0; // remove field

            c._img = "noimg.jpg";
            if (portrait.PostedFile.FileName != "")
            {
                try
                {
                    string serverFileExt = Path.GetExtension(portrait.PostedFile.FileName);
                    Random rand = new Random((int)DateTime.Now.Ticks);
                    string fullpath = "";
                    string imgname = "";
                    do
                    {
                        string randomFName = rand.Next(Int32.MaxValue).ToString();
                        imgname = randomFName + serverFileExt;
                        fullpath = Config.PATH_APP_ROOT + "\\" + Config.URL_PIC_COURSE + "\\" + imgname;
                    } while (File.Exists(fullpath));

                    portrait.PostedFile.SaveAs(fullpath);
                    c._img = imgname;
                }
                catch (Exception err)
                {
                    errorText = err.Message + err.StackTrace;
                }
            }

            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            db.Connect();
            // Validate if bts code okay
            Course[] dupBTSCourse = Course.LoadListFromDBCustom(db, "SELECT * FROM course c, payment p WHERE bts_course_id='" + c._btsCourseID + "' AND c.course_id=p.course_id AND (p.sum_max_payable>p.sum_paid_cost OR p.sum_max_payable=0)");
            if (dupBTSCourse.Length == 0)
            {
                // no duplicate bts
                // Save to DB
                // Save to DB
                db.BeginTransaction(IsolationLevel.ReadCommitted);

                c.AddToDB(db);
                c._courseID = Course.GetMaxCourseID(db);

                // Update Payment with empty record
                Payment payment = new Payment();
                payment._courseID = c._courseID;
                payment._sumAllCost = 0;
                payment._sumPaidCost = 0;
                payment._status = 0;
                payment._lastPaidDate = DateTime.Now;
                payment.AddToDB(db);

                db.Commit();
                db.Close();
            }
        }
Exemplo n.º 19
0
 public void AddCourse(Course course)
 {
     foreach (Course c in _courses)
     {
         if (c._courseID == course._courseID) return;
     }
     _courses.AddLast(course);
 }
Exemplo n.º 20
0
        public static Course[] LoadListFromDBCustom(DBManager db, string sqlAll)
        {
            OdbcDataReader reader = db.Query(sqlAll);
            LinkedList<Course> list = new LinkedList<Course>();
            while (reader.Read())
            {
                list.AddLast(Course.CreateForm(reader));
            }

            Course[] entities = new Course[list.Count];
            int i = 0;
            foreach (Course t in list)
            {
                entities[i++] = t;
            }
            return entities;
        }
Exemplo n.º 21
0
 public static int UpdatePaymentByCourse(DBManager db, int courseID)
 {
     Course c = new Course();
     c.LoadFromDB(db, " course_id="+courseID);
     return UpdatePaymentByCourse(db, c);
 }
Exemplo n.º 22
0
 public static LinkedList<Course> CopyList(LinkedList<Course> clist)
 {
     Course[] tmpArray = new Course[clist.Count];
     clist.CopyTo(tmpArray, 0);
     return new LinkedList<Course>(tmpArray);
 }
Exemplo n.º 23
0
        public bool LoadCourse(DBManager db)
        {
            if (_courseID <= 0) return false;
            _course = new Course();
            _course.LoadFromDB(db, " course_id=" + _courseID);

            // Assign loaded data to helper
            this._btsCourseID = _course._btsCourseID;
            return true;
        }
Exemplo n.º 24
0
 public bool LoadCourse(DBManager db)
 {
     if (_courseID <= 0) return false;
     _course = new Course();
     _course.LoadFromDB(db, " course_id=" + _courseID);
     return true;
 }