示例#1
0
        public void CreateTransactionCode(DBManager db, DateTime regisdate)
        {
            // format
            // 1. operating branch code - 2 digits
            // 2. paid method C/K/D/T/V
            // 3. yyMM 1302
            // 5. number of transaction this month XXX


            Branch branch = new Branch();

            branch.LoadFromDB(db, "branch_id=" + this._branchID);

            // find the number of transaction for the user on this month
            int numRegisted = GetTransationCountThisMonth(db, _paidMethod);



            StringBuilder buf = new StringBuilder(40);

            buf.Append(branch._branchCode);
            buf.Append(PAID_METHOD_TRANCODE[_paidMethod]);
            buf.Append(regisdate.Year.ToString().Substring(2)).Append(StringUtil.FillString(regisdate.Month.ToString(), "0", 2, true));
            buf.Append(StringUtil.FillString((numRegisted + 1).ToString(), "0", 3, true));
            // set
            this._transactionCode = buf.ToString();

            //
        }
示例#2
0
        public bool LoadBranch(DBManager db)
        {
            if (_branchID <= 0)
            {
                return(false);
            }

            _branch = new Branch();
            return(_branch.LoadFromDB(db, " branch_id=" + _branchID));
        }
示例#3
0
        // here is branch that make registration not branch of course
        public bool LoadBranch(DBManager db)
        {
            if (_branchID <= 0)
            {
                return(false);
            }

            _branch = new Branch();
            bool result = _branch.LoadFromDB(db, " branch_id=" + _branchID);

            _branchCode = _branch._branchCode;
            return(result);
        }
        protected void LoadData(string startDateString, string endDateString, string paidMethod, string branchRegisedID, String branchID, String username, int status)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            db.Connect();

            // Load branchlist
            branchList = Branch.LoadListFromDBCustom(db, "SELECT * from branch ORDER BY branch_id ");

            // Load userList all
            AppUser[] userListAll = AppUser.LoadListFromDB(db, "");
            userAllMap = new Dictionary<string, AppUser>();
            foreach (AppUser aUser in userListAll) {
                userAllMap.Add(aUser._username, aUser);
            }

            // Load userList for this login
            AppUser loginUser = (AppUser)Session[SessionVar.USER];
            String userQueryClause = "";
            if (loginUser._roleId == Role.ROLE_MANAGEMENT)
            {
                userQueryClause = " WHERE role_id >= " + Role.ROLE_MANAGEMENT;
            }
            else if (loginUser._roleId == Role.ROLE_FRONTSTAFF)
            {
                userQueryClause = " WHERE user_id = " + loginUser._userId;
            }
            userList = AppUser.LoadListFromDB(db, userQueryClause + " order by firstname");

            try
            {
                string[] s = startDateString.Split('/');

                startDate = new DateTime(Int32.Parse(s[2]), Int32.Parse(s[1]), Int32.Parse(s[0]));
            }
            catch (Exception e)
            {
                startDate = DateTime.Today;
            }

            try
            {
                string[] s = endDateString.Split('/');
                endDate = new DateTime(Int32.Parse(s[2]), Int32.Parse(s[1]), Int32.Parse(s[0]));
                endDate = endDate.AddHours(23).AddMinutes(59).AddSeconds(59);
            }
            catch (Exception e)
            {
                endDate = DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59);
            }

            // Get branch name
            if (branchRegisedID.Equals("0"))
            {
                branchName = "ทุกสาขา";
            }
            else
            {
                Branch b = new Branch();
                b.LoadFromDB(db, " branch_id=" + branchRegisedID);
                branchName = b._branchName;
            }

            // Filter user
            if (loginUser._roleId > Role.ROLE_MANAGEMENT)
            {
                if (username.Equals("all"))
                {
                    username = loginUser._username;
                }
            }

            // construct room list for the branch
            string roomList = "";
            if (!branchID.Equals("0"))
            {
                string roomSQL = "SELECT room_id FROM room where branch_id=" + branchID;
                Room[] rooms = Room.LoadListFromDBCustom(db, roomSQL);
                if (rooms.Length > 0)
                {
                    foreach (Room r in rooms)
                    {
                        roomList = roomList + "," + r._roomID;
                    }
                    roomList = "( " + roomList.Substring(1) + ")";
                }
            }

            string selectSQl = "SELECT rg.*, b.branch_code, s.firstname as student_firstname, s.surname as student_surname, s.school as student_school, s.level as student_level, c.bts_course_id as bts_course_id, c.course_name as course_name, c.course_type as course_type, c.category as course_category, c.start_date as start_date, c.end_date as end_date "
                               + " FROM registration rg, student s, course c, branch b ";
            string whereSQL = " WHERE rg.student_id=s.student_id AND rg.course_id=c.course_id "
                                + " AND rg.status=" + status
                                + " AND rg.regis_date between '" + startDate.ToString("yyyy/MM/dd HH:mm:ss", ci) + "' and '" + endDate.ToString("yyyy/MM/dd HH:mm:ss", ci) + "' "
                                + ((!paidMethod.Equals("-1")) ? " AND rg.paid_method=" + paidMethod : "")
                                + ((!branchRegisedID.Equals("0")) ? " AND rg.branch_id=" + branchRegisedID : "")
                                + ((!username.Equals("all")) ? " AND rg.username='******'" : "")
                                + ((roomList.Length > 0) ? " AND c.room_id in " + roomList : "")
                                + " AND rg.branch_id = b.branch_id "
                                + " ORDER BY rg.regis_id ";
            reg = Registration.LoadListFromDBCustom(db, selectSQl + whereSQL);
            db.Close();

            /*
            public int[] numPaidMethodCancel = new int[Registration.PAID_METHOD.Length];
            public int[] sumCostByPaidMethodCancel = new int[Registration.PAID_METHOD.Length];
            public int numCancel = 0;
            public int sumCancelCost = 0;
             */
            // prepare dict cate
            for (int j = 0; j < Config.COURSE_CATE.Length; j++)
            {
                Dictionary<string, Object> map = new Dictionary<string,object>();
                map["numByPaidMethod"] = new int[Registration.PAID_METHOD.Length];
                map["sumCostByPaidMethod"] = new int[Registration.PAID_METHOD.Length];
                map["numAll"] = 0;
                map["sumCostAll"] = 0;

                map["numByPaidMethodCancel"] = new int[Registration.PAID_METHOD.Length];

                map["sumCostByPaidMethodCancel"] = new int[Registration.PAID_METHOD.Length];
                map["numAllCancel"] = 0;
                map["sumCostAllCancel"] = 0;

                String cate = Config.COURSE_CATE[j];
                sumByCourseCate.Add(cate, map);
            }

            for (int i = 0; i < reg.Length; i++)
            {
                if (reg[i]._status == 0) // normal
                {
                    numPaidMethod[reg[i]._paidMethod]++;
                    sumCostByPaidMethod[reg[i]._paidMethod] += reg[i]._discountedCost;
                    numSuccess++;
                    sumAllCost += reg[i]._discountedCost;
                }
                else if (reg[i]._status == 1) // cancel
                {
                    numPaidMethodCancel[reg[i]._paidMethod]++;
                    sumCostByPaidMethodCancel[reg[i]._paidMethod] += reg[i]._discountedCost;
                    numCancel++;
                    sumCancelCost += reg[i]._discountedCost;
                }

                for (int j = 0; j < Config.COURSE_CATE.Length; j++)
                {

                    String cate = Config.COURSE_CATE[j];
                    Dictionary<string, Object> map = (Dictionary<string,object>)sumByCourseCate[cate];

                    if (reg[i]._courseCategotry.Equals(cate)) {

                        int[] _numByPaidMethod = (int[])map["numByPaidMethod"];
                        int[] _sumCostByPaidMethod = (int[])map["sumCostByPaidMethod"];

                        int[] _numByPaidMethodCancel = (int[])map["numByPaidMethodCancel"];
                        int[] _sumCostByPaidMethodCancel = (int[])map["sumCostByPaidMethodCancel"];

                        if (reg[i]._status == 0) // normal
                        {
                            _numByPaidMethod[reg[i]._paidMethod]++;
                            _sumCostByPaidMethod[reg[i]._paidMethod] += reg[i]._discountedCost;
                            map["numAll"] = (int)map["numAll"] + 1;
                            map["sumCostAll"] = (int)map["sumCostAll"] + reg[i]._discountedCost;
                        }
                        else if (reg[i]._status == 1) // cancel
                        {
                            _sumCostByPaidMethod[reg[i]._paidMethod]++;
                            _sumCostByPaidMethodCancel[reg[i]._paidMethod] += reg[i]._discountedCost;
                            map["numAllCancel"] = (int)map["numAllCancel"] + 1;
                            map["sumCostAllCancel"] = (int)map["sumCostAllCancel"] + reg[i]._discountedCost;
                        }

                    }
                }
            }
        }
示例#5
0
 public void DoEditBranch(string branchID)
 {
     DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
     theBranch = new Branch();
     if (!theBranch.LoadFromDB(db, "branch_id=" + branchID)) theBranch = null;
 }
示例#6
0
        public bool LoadBranch(DBManager db)
        {
            if (_branchID <= 0) return false;

            _branch = new Branch();
            return _branch.LoadFromDB(db, " branch_id=" + _branchID);
        }
示例#7
0
        public void CreateTransactionCode(DBManager db, DateTime regisdate)
        {
            // format
            // 1. operating branch code - 2 digits
            // 2. paid method C/K/D/T/V
            // 3. yyMM 1302
            // 5. number of transaction this month XXX

            Branch branch = new Branch();
            branch.LoadFromDB(db, "branch_id=" + this._branchID);

            // find the number of transaction for the user on this month
            int numRegisted = GetTransationCountThisMonth(db, _paidMethod);

            StringBuilder buf = new StringBuilder(40);
            buf.Append(branch._branchCode);
            buf.Append(PAID_METHOD_TRANCODE[_paidMethod]);
            buf.Append(regisdate.Year.ToString().Substring(2)).Append(StringUtil.FillString(regisdate.Month.ToString(), "0", 2, true));
            buf.Append(StringUtil.FillString((numRegisted + 1).ToString(), "0", 3, true));
            // set
            this._transactionCode = buf.ToString();

            //
        }
示例#8
0
        // here is branch that make registration not branch of course
        public bool LoadBranch(DBManager db)
        {
            if (_branchID <= 0) return false;

            _branch = new Branch();
            bool result = _branch.LoadFromDB(db, " branch_id=" + _branchID);
            _branchCode = _branch._branchCode;
            return result;
        }
示例#9
0
        public static StringBuilder PrintCard(DBManager db, int regisID)
        {
            StringBuilder outBuf = new StringBuilder();

            Registration theReg = new Registration();
            theReg.LoadFromDB(db, " regis_id=" + regisID);
            theReg.LoadCourse(db);
            theReg.LoadStudent(db);
            Branch branch = new Branch();
            branch.LoadFromDB(db, " branch_id=" + theReg._branchID);
            AppUser authorizer = new AppUser();
            authorizer.LoadFromDB(db, " username='******'");

            // Load all registration in the same transaction
            Registration[] reg = Registration.LoadListFromDBIncludeCourseHelper(db, " r.transaction_id="+theReg._transactionID + " AND r.branch_id="+theReg._branchID);

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

            int[] rowH = { 22, 20, 20, 20, 20, 20, 20 };

            StringBuilder courseCalendar = new StringBuilder();
            for (int i = 0; i < reg.Length; i++)
            {
                reg[i].LoadCourse(db);
                Branch b = reg[i]._course.LoadBranchInfo(db);

                courseCalendar.Append("<tr height=\"24px\">");
                courseCalendar.Append("<td width=\"38px\" align=left><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">&nbsp&nbsp&nbsp" + reg[i]._btsCourseID + "</font></td>");
                courseCalendar.Append("<td width=\"100px\" align=left><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">&nbsp" + reg[i]._courseShortName + "</font></td>");
                courseCalendar.Append("<td width=\"17px\" align=left><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + b._branchCode + "</font></td>");
                courseCalendar.Append("<td width=\"48px\"><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + StringUtil.ConvertYearToEng(reg[i]._course._startdate, "dd/MM/yy") + "</font></td>");
                courseCalendar.Append("<td width=\"25px\"><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + reg[i]._course._dayOfWeek+"</font></td>");
                courseCalendar.Append("<td width=\"70px\"><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + reg[i]._course._opentime + "</font></td>");

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

            /*
                <tr height="10px"><td colspan=2></td></tr>
            <tr><td width="10px" align="right">&nbsp</td><td><font size=2>คอร์ส: {4}</font></td></tr>
            <tr><td align="right">&nbsp</td><td><font size=2>ชื่อคอร์ส: {5} </font></td></tr>
            <tr><td align="right">&nbsp</td><td><font size=2>วันที่เริ่ม: {6}</font></td></tr>
            <tr><td align="right">&nbsp</td><td><font size=2>เวลา: {7}</font></td></tr>
            <tr><td align="right">&nbsp</td><td><font size=2>หนังสือ: </font></td></tr>
            */

            String htmlContent =
                String.Format(templateContent
                    , theReg._student._firstname + " " + theReg._student._surname
                    , Student.GetStudentID(theReg._student._studentID)
                    , StringUtil.ConvertYearToEng(theReg._regisdate, "dd/MM/yyyy")
                    , authorizer._firstname + " " + authorizer._surname
                    , reg[0].GetRegisTransactionID()
                    , courseCalendar.ToString()
                    );

            outBuf.Append(htmlContent);
            return outBuf;
        }
示例#10
0
        public static StringBuilder PrintCard(DBManager db, int regisID)
        {
            StringBuilder outBuf = new StringBuilder();

            Registration theReg = new Registration();

            theReg.LoadFromDB(db, " regis_id=" + regisID);
            theReg.LoadCourse(db);
            theReg.LoadStudent(db);
            Branch branch = new Branch();

            branch.LoadFromDB(db, " branch_id=" + theReg._branchID);
            AppUser authorizer = new AppUser();

            authorizer.LoadFromDB(db, " username='******'");

            // Load all registration in the same transaction
            Registration[] reg = Registration.LoadListFromDBIncludeCourseHelper(db, " r.transaction_id=" + theReg._transactionID + " AND r.branch_id=" + theReg._branchID);

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

            reader.Close();

            int[] rowH = { 22, 20, 20, 20, 20, 20, 20 };

            StringBuilder courseCalendar = new StringBuilder();

            for (int i = 0; i < reg.Length; i++)
            {
                reg[i].LoadCourse(db);
                Branch b = reg[i]._course.LoadBranchInfo(db);

                courseCalendar.Append("<tr height=\"24px\">");
                courseCalendar.Append("<td width=\"38px\" align=left><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">&nbsp&nbsp&nbsp" + reg[i]._btsCourseID + "</font></td>");
                courseCalendar.Append("<td width=\"100px\" align=left><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">&nbsp" + reg[i]._courseShortName + "</font></td>");
                courseCalendar.Append("<td width=\"17px\" align=left><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + b._branchCode + "</font></td>");
                courseCalendar.Append("<td width=\"48px\"><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + StringUtil.ConvertYearToEng(reg[i]._course._startdate, "dd/MM/yy") + "</font></td>");
                courseCalendar.Append("<td width=\"25px\"><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + reg[i]._course._dayOfWeek + "</font></td>");
                courseCalendar.Append("<td width=\"70px\"><font style=\"font: 10px 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif;\">" + reg[i]._course._opentime + "</font></td>");

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


/*
 *              <tr height="10px"><td colspan=2></td></tr>
 *  <tr><td width="10px" align="right">&nbsp</td><td><font size=2>คอร์ส: {4}</font></td></tr>
 *  <tr><td align="right">&nbsp</td><td><font size=2>ชื่อคอร์ส: {5} </font></td></tr>
 *  <tr><td align="right">&nbsp</td><td><font size=2>วันที่เริ่ม: {6}</font></td></tr>
 *  <tr><td align="right">&nbsp</td><td><font size=2>เวลา: {7}</font></td></tr>
 *  <tr><td align="right">&nbsp</td><td><font size=2>หนังสือ: </font></td></tr>
 */

            String htmlContent =
                String.Format(templateContent
                              , theReg._student._firstname + " " + theReg._student._surname
                              , Student.GetStudentID(theReg._student._studentID)
                              , StringUtil.ConvertYearToEng(theReg._regisdate, "dd/MM/yyyy")
                              , authorizer._firstname + " " + authorizer._surname
                              , reg[0].GetRegisTransactionID()
                              , courseCalendar.ToString()
                              );

            outBuf.Append(htmlContent);
            return(outBuf);
        }