protected void DoListRegister(string searchStr) { // get Page int pg = 1; if (Request["pg"]!=null) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; // listRegistration = new List<Registration>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); if (searchStr.Trim().Length > 0) searchStr = " WHERE " + searchStr; int numRec = db.QueryCount("SELECT Count(*) FROM registration " + searchStr); OdbcDataReader reader = db.Query("SELECT * FROM registration " + searchStr + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Registration regis = Registration.CreateForm(reader); outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + regis._regisID + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._transactionID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._regisdate.ToString("dd/MM/yyyy",ci) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._studentID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._courseID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._fullCost + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._promotionID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._discountedCost + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._isPaid.ToString() + " </td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (maxpg % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>"+i+"</b> "); } else { outBuf2.Append(String.Format("<a href=\"ReportRegis.aspx?pg={0}\">{1}</a> ", i.ToString(), i.ToString())); } } }
protected void DoListRoom(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listRoom = new List<Room>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string whereSQL = Room.GetQSearchSQL(searchStr); if (whereSQL.Length > 0) whereSQL = " WHERE " + whereSQL; int numRec = db.QueryCount("SELECT Count(*) FROM room " + whereSQL); if (whereSQL.Length > 0) whereSQL = whereSQL + " AND r.branch_id=b.branch_id "; else whereSQL = " WHERE r.branch_id=b.branch_id "; OdbcDataReader reader = db.Query("SELECT r.*,b.branch_name as branch_name FROM room r, branch b " + whereSQL +"ORDER BY room_id LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg-1)*Config.TBRECORD_PER_PAGE)) ); int i = 0; while (reader.Read()) { Room room = Room.CreateForm(reader); string divtxt = Config.URL_PIC_TEACHER + "/" + room._img; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + " align=center valign=top width=100px>" +Room.GetRoomID(room._roomID) + "  </th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left><p><b>ห้อง: </b>" + room._name + "</p>"); outBuf.Append("<p><b>สาขา: </b>" + room._branchName + " </p>"); outBuf.Append("<p><b>จำนวนที่นั่ง: </b>" + room._seatNo + " </p>"); outBuf.Append("<p><b>รายละเอียด: </b></p><p>" + room._description.Replace("\r\n","<br>") + " </p>"); outBuf.Append(" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center><a href=\"" + Config.URL_PIC_ROOM + "/" + room._img + "\" ><img border=0 width=200px height=150px src=\"" + Config.URL_PIC_ROOM + "/" + room._img + "\" ></a></td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + room._roomID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this room?')) { setVal('actPage','delete');setVal('targetID','" + room._roomID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>"+i+"</b> "); } else { outBuf2.Append(String.Format("<a href=\"TeacherManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } }
protected void DoListRegistration(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"]!=null)) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"", "class=\"td1_grey\"" }, { "class=\"specalt\"", "class=\"alt\"", "class=\"td1_grey\"" } }; string grey = "class=\"thspec_grey\""; listRegistration = new List<Registration>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); string qSearchSQL = Registration.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) qSearchSQL = " WHERE " + qSearchSQL; // add join condition qSearchSQL = qSearchSQL + ((qSearchSQL.Trim().Length > 0) ? " AND " : " WHERE ") + " rg.student_id=st.student_id AND rg.course_id=c.course_id "; int numRec = db.QueryCount("SELECT Count(*) FROM registration rg, student st, course c " + qSearchSQL); OdbcDataReader reader = db.Query("SELECT rg.*, st.firstname as student_firstname, st.surname as student_surname, c.bts_course_id as bts_course_id, c.course_name FROM registration rg, student st, course c " + qSearchSQL + " ORDER BY regis_id desc " + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; int j = 0; int currentRegisTransactionID = 0; while (reader.Read()) { Registration reg = Registration.CreateForm(reader); if (reg._transactionID != currentRegisTransactionID) { currentRegisTransactionID = reg._transactionID; j++; reg.LoadBranch(db); outBuf.Append("<tr>"); outBuf.Append("<th colspan=9 scope=\"row\" abbr=\"Model\" " + bgclass[j % 2, 0] + "><b>" + reg.GetRegisTransactionID() + "</b></th>"); outBuf.Append("</tr>\n"); } string studentInfo = "<a href=\"StudentManage.aspx?actPage=view&targetID="+reg._studentID+"\" >" + Student.GetStudentID(reg._studentID) +" "+ reg._studentFirstname + " " + reg._studentSurname + "</a>"; string courseInfo = "<a href=\"CourseManage.aspx?actPage=view&targetID=" + reg._courseID + "\" >" + reg._btsCourseID + " " + reg._courseName + "</a>"; string costInfo = StringUtil.Int2StrComma(reg._discountedCost); string statusInfo = Registration.GetStatusText(reg._status); if (reg._status > 0) { costInfo = "<font color=red>" + costInfo + "</font>"; statusInfo = "<font color=red>" + statusInfo + "</font>"; } outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[j % 2, 0] + ">" + Registration.GetRegistrationID(reg._regisID) + "</th>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>" + reg._regisdate.ToString("dd/MM/yyyy HH:mm", ci) + " </td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>" + reg._paiddate.ToString("dd/MM/yyyy", ci) + " </td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=left>" + courseInfo + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=left>" + studentInfo + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=right>" + costInfo + " </td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>" + statusInfo + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=left>" + reg._note + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>"); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + reg._regisID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:setVal('actPage','init_print_all');setVal('targetID','" + reg._regisID + "');doSubmit()\"><img src=\"img/sys/print.gif\" border=0 alt=\"พิมพ์ทุกอย่าง\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); outBuf2.Append(String.Format("<a href=\"RegistrationManage.aspx?pg={0}&qsearch={1}\">{2}</a><< ", "1", searchStr, "First")); for (i = pg - 10; i <= pg + 10; i++) { if ((i <= 0) || (i > maxpg)) { continue; } if (i == pg) { outBuf2.Append("<b>"+i+"</b> "); } else { outBuf2.Append(String.Format("<a href=\"RegistrationManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } outBuf2.Append(String.Format(" >><a href=\"RegistrationManage.aspx?pg={0}&qsearch={1}\">{2}</a> ", maxpg.ToString(), searchStr, "Last")); }
protected void DoListBranch(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listBranch = new List<Branch>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Branch.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) qSearchSQL = " WHERE " + qSearchSQL; int numRec = db.QueryCount("SELECT Count(*) FROM branch " + qSearchSQL); OdbcDataReader reader = db.Query("SELECT * FROM branch " + qSearchSQL + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Branch branch = Branch.CreateForm(reader); string divtxt = Config.URL_PIC_BRANCH + "/" + branch._img; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + " align=center valign=top width=100px>" + Branch.GetBranchID(branch._branchID) + "  </th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>"+branch._branchCode+"</td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left><p><b>สาขา: </b>" + branch._branchName + "</p>"); outBuf.Append("<p><b>ที่ตั้ง: </b>" + branch._address.Replace("\r\n", "<br>") + " </p>"); outBuf.Append("<p><b>เบอร์ติดต่อ: </b>" + branch._tel + " </p>"); outBuf.Append("<p><b>ชื่อผู้ดูแล: </b>" + branch._supervisor + " </p>"); outBuf.Append(" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center><a href=\"" + Config.URL_PIC_BRANCH + "/" + branch._img + "\" ><img border=0 width=200px height=150px src=\"" + Config.URL_PIC_BRANCH + "/" + branch._img + "\" ></a></td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + branch._branchID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this branch?')) { setVal('actPage','delete');setVal('targetID','" + branch._branchID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"BranchManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListCourse(string searchStr, bool isNewSearch, string filter) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } if ((filter == null) || (filter.Length == 0) || ((!filter.Equals("all")) && (!filter.Equals("only_close")))) { filter = "only_open"; } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listCourse = new List <Course>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Course.GetQSearchSQL(searchStr); //filter string curDate = "'" + DateTime.Now.ToString("yyyy-MM-dd", ci) + "'"; // "'2011-05-01'"; string filterSQL = ""; if (filter.Equals("only_open")) { filterSQL = "( end_date > " + curDate + " or course_type='คอร์ส DVD' )"; } else if (filter.Equals("only_close")) { filterSQL = "( end_date < " + curDate + " or course_type='คอร์ส DVD' )"; } if (filterSQL.Length > 0) { if (qSearchSQL.Trim().Length > 0) { qSearchSQL = qSearchSQL + " AND " + filterSQL; } else { qSearchSQL = filterSQL; } } // Add WHERE if (qSearchSQL.Trim().Length > 0) { qSearchSQL = " WHERE " + qSearchSQL; } int numRec = db.QueryCount("SELECT Count(*) FROM course c " + qSearchSQL); // add join condition qSearchSQL = qSearchSQL + ((qSearchSQL.Trim().Length > 0)?" AND ":" WHERE ") + " c.teacher_id=t.teacher_id"; String subQuery = " (SELECT count(*) FROM registration r WHERE r.status=0 AND r.course_id=c.course_id) "; OdbcDataReader reader = db.Query("SELECT c.*,t.firstname as teacher_firstname, t.surname as teacher_surname, " + subQuery + " AS num_registered " + " FROM course c, teacher t " + qSearchSQL + " order by bts_course_id desc LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Course course = Course.CreateForm(reader); // byte[] raw = Encoding.Default.GetBytes(course._firstname); // course._firstname = Encoding.GetEncoding("tis-620").GetString(raw); string divtxt = Config.URL_PIC_COURSE + "/" + course._img; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + course._btsCourseID + (course._numRegistered >= course._seatLimit ? "<br><font color=red>[เต็ม]</font>":"") + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " ><a href=\"CourseManage.aspx?actPage=view&targetID=" + course._courseID + "\" >" + "<b>" + course._courseName + "</b></a><br>" + course._courseDesc + "</td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + StringUtil.Int2StrComma(course._cost) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + course._startdate.ToString("dd/MM/yyyy", ci) + " - " + course._enddate.ToString("dd/MM/yyyy", ci) + "<br>" + course._dayOfWeek + " " + course._opentime + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + course._teacher._firstname + " " + course._teacher._surname + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','view');setVal('targetID','" + course._courseID + "');doSubmit()\"><img src=\"img/sys/view.gif\" border=0 alt=\"View detail\"></a> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + course._courseID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this course?')) { setVal('actPage','delete');setVal('targetID','" + course._courseID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); outBuf2.Append(String.Format("<a href=\"CourseManage.aspx?pg={0}&qsearch={1}\">{2}</a><< ", "1", searchStr, "First")); for (i = pg - 5; i <= pg + 5; i++) { if ((i <= 0) || (i > maxpg)) { continue; } if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"CourseManage.aspx?pg={0}&qsearch={1}&filter={2}\">{0}</a> ", i.ToString(), searchStr, filter)); } } outBuf2.Append(String.Format(" >><a href=\"CourseManage.aspx?pg={0}&qsearch={1}\">{2}</a> ", maxpg.ToString(), searchStr, "Last")); // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListUser(string searchStr) { // get Page int pg = 1; if (Request["pg"] != null) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listUser = new List<AppUser>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); int numRec = db.QueryCount("SELECT Count(*) FROM user " + GetQSearchSQL(searchStr)); OdbcDataReader reader = db.Query("SELECT * FROM user " + GetQSearchSQL(searchStr) + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { AppUser user = BTS.Entity.AppUser.CreateForm(reader); // byte[] raw = Encoding.Default.GetBytes(user._firstname); // user._firstname = Encoding.GetEncoding("tis-620").GetString(raw); outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + user._userId + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left ><a href=\"#\" >" + user._username + "</a> </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left ><a href=\"#\" >" + user._firstname + " " + user._surname + "</a> </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + GetRoleName(user._roleId) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + GetBranchName(user._branchID) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + user._username + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this user?')) { setVal('actPage','delete');setVal('targetID','" + user._username + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (maxpg % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"Administrator.aspx?pg={0}\">{1}</a> ", i.ToString(), i.ToString())); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListStudent(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listStudent = new List <Student>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Student.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) { qSearchSQL = " WHERE " + qSearchSQL; } else // search all { qSearchSQL = " WHERE is_active=1 "; } int numRec = db.QueryCount("SELECT Count(*) FROM student " + qSearchSQL); OdbcDataReader reader = db.Query("SELECT * FROM student " + qSearchSQL + "order by student_id desc LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Student student = Student.CreateForm(reader); // byte[] raw = Encoding.Default.GetBytes(student._firstname); // student._firstname = Encoding.GetEncoding("tis-620").GetString(raw); int age = ((DateTime.Now.Year * 12 + DateTime.Now.Month) - (student._birthday.Year * 12 + student._birthday.Month)) / 12; string divtxt = Config.URL_PIC_STUDENT + "/" + student._img; string studentTxt = "<a href=\"StudentManage.aspx?actPage=view&targetID=" + student._studentID + "\" onmouseover=\"showDiv('" + divtxt + "')\" onmouseout=\"hideDiv()\" >" + student._firstname + " " + student._surname + "(" + student._nickname + ")" + "</a>"; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + Student.GetStudentID(student._studentID) + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + studentTxt + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center > <img width=20 height=24 src=\"" + Config.URL_PIC_SYS + (student._sex.Equals("Male")?"/boy.gif":"/girl.gif") + "\" >"); /* * for (int j = 0; j < ssList[i].skill.Count; j++) * { * outBuf.Append("<LI><a href=\"SkillHandling.aspx#sdid" + ssList[i].skill[j].id + "\" onmouseover=\"showChecklist(" + ssList[i].skill[j].id + ")\" onmouseout=\"hideCheckList()\" >" + ssList[i].skill[j].name + "</a>"); * }*/ outBuf.Append(" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + age + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + student._school + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + StringUtil.ConvertEducateLevel(student._level) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + student.GetTel() + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + student._email + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + student._studentID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this student?')) { setVal('actPage','delete');setVal('targetID','" + student._studentID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); outBuf2.Append(String.Format("<a href=\"StudentManage.aspx?pg={0}&qsearch={1}\">{2}</a><< ", "1", searchStr, "First")); for (i = pg - 5; i <= pg + 5; i++) { if ((i <= 0) || (i > maxpg)) { continue; } if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"StudentManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } outBuf2.Append(String.Format(" >><a href=\"StudentManage.aspx?pg={0}&qsearch={1}\">{2}</a> ", maxpg.ToString(), searchStr, "Last")); // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListUser(string searchStr) { // get Page int pg = 1; if (Request["pg"] != null) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listUser = new List <AppUser>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); int numRec = db.QueryCount("SELECT Count(*) FROM user " + GetQSearchSQL(searchStr)); OdbcDataReader reader = db.Query("SELECT * FROM user " + GetQSearchSQL(searchStr) + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { AppUser user = BTS.Entity.AppUser.CreateForm(reader); // byte[] raw = Encoding.Default.GetBytes(user._firstname); // user._firstname = Encoding.GetEncoding("tis-620").GetString(raw); outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + user._userId + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left ><a href=\"#\" >" + user._username + "</a> </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left ><a href=\"#\" >" + user._firstname + " " + user._surname + "</a> </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + GetRoleName(user._roleId) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + GetBranchName(user._branchID) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + user._username + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this user?')) { setVal('actPage','delete');setVal('targetID','" + user._username + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (maxpg % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"Administrator.aspx?pg={0}\">{1}</a> ", i.ToString(), i.ToString())); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListPaidGroup(string searchStr) { // get Page int pg = 1; if (Request["pg"] != null) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); int numRec = db.QueryCount("SELECT Count(*) FROM paid_group " + GetQSearchSQL(searchStr)); OdbcDataReader reader = db.Query("SELECT * FROM paid_group " + GetQSearchSQL(searchStr) + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { PaidGroup group = BTS.Entity.PaidGroup.CreateForm(reader); // teacher member list Teacher[] memberList = group.LoadMemberTeachers(db); StringBuilder memberTxt = new StringBuilder(); for (int j = 0; j < memberList.Length; j++) { String txt = Teacher.GetTeacherID(memberList[j]._teacherID) + " " + memberList[j]._firstname + " " + memberList[j]._surname; memberTxt.Append("<a href=\"TeacherManage.aspx?actPage=view&targetID=" + memberList[j]._teacherID + "\">" + txt + "<br>"); } outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + PaidGroup.GetPaidGroupID(group._paidGroupID) + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + group._name + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + group._rawRateInfo + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left >" + memberTxt + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + group._paidGroupID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this user?')) { setVal('actPage','delete');setVal('targetID','" + group._paidGroupID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (maxpg % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"PaidGroupManage.aspx?pg={0}\">{1}</a> ", i.ToString(), i.ToString())); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListPaymentByTeacher(string teacherID, string searchStr, bool isNewSearch) { DBManager db; db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); listTeacher = Teacher.LoadListFromDB(db, " WHERE is_active=1 ORDER BY firstname "); if (teacherID == null) { return; } // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"", "class=\"td1_grey\"", "class=\"td1_red\"" }, { "class=\"specalt\"", "class=\"alt\"", "class=\"td1_grey\"", "class=\"td1_red\"" } }; string grey = "class=\"thspec_grey\""; string red = "class=\"thspec_red\""; listPayment = new List <Payment>(); AppUser user = (AppUser)Session[SessionVar.USER]; filterPayment = Request["filter_payment"]; if (filterPayment == null) { filterPayment = "0"; // by default } string whereSQL = " pm.course_id=c.course_id AND c.teacher_id=t.teacher_id AND c.room_id = r.room_id "; // only admin can view all payment if (!user.IsAdmin()) { whereSQL = whereSQL + " AND r.branch_id=" + user._branchID; } // filter only payable courses if (filterPayment.Equals("0")) { whereSQL = whereSQL + " AND sum_max_payable<>sum_paid_cost "; } int numRec = db.QueryCount("SELECT Count(*) FROM payment pm, course c, teacher t, room r WHERE " + whereSQL); OdbcDataReader reader = db.Query("SELECT pm.course_id as course_id ,c.bts_course_id as bts_course_id ,c.course_name as course_name, t.paid_group_id as paid_group_id" + ", pm.sum_all_cost as sum_all_cost, pm.sum_max_payable as sum_max_payable, pm.sum_paid_cost as sum_paid_cost " + "FROM payment pm, course c, teacher t, room r WHERE " + whereSQL + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Payment payment = Payment.CreateForm(reader); string chbname = "course" + payment._courseID; int sumPayable = payment._sumMaxPayable - payment._sumPaidCost; int n = 1; if (sumPayable == 0) { n = 2; } else if (sumPayable < 0) { n = 3; } string bgcolor = (sumPayable == 0) ? grey : red; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + (sumPayable > 0 ? bgclass[i % 2, 0] : bgcolor) + ">" + payment._btsCourseID + "</th>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><input type=\"checkbox\" name=\"" + chbname + "\" id=\"" + chbname + "\" />" + "</td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " ><a href=\"CourseManage.aspx?actPage=view&targetID=" + payment._courseID + "\" >" + payment._courseName + "</a></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center >" + PaidGroup.GetPaidGroupID(payment._paidGroupID) + "</td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b>" + StringUtil.Int2StrComma(payment._sumAllCost) + "</b></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b><font color=blue>" + StringUtil.Int2StrComma(payment._sumMaxPayable) + "</font></b></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b><font color=red>" + StringUtil.Int2StrComma(payment._sumPaidCost) + "</font></b></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b><font color=green>" + StringUtil.Int2StrComma(sumPayable) + "</font></b></td>"); /* outBuf.Append("<td " + bgclass[i % 2, n] + " align=center>" + payment._lastPaidDate.ToString("dd/MM/yyyy HH:mm", ci) + " </td>"); */ outBuf.Append("<td " + bgclass[i % 2, n] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','view');setVal('targetID','" + payment._courseID + "');doSubmit()\"><img src=\"img/sys/view.gif\" border=0 alt=\"View detail\"></a> "); // outBuf.Append("<a href=\"javascript:if (confirm('Delete this payment?')) { setVal('actPage','delete');setVal('targetID','" + payment._paymentID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"PaymentManage.aspx?pg={0}&filter_payment={1}&qsearch={1}\">{0}</a> ", i.ToString(), filterPayment, searchStr)); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListPaidGroup(string searchStr) { // get Page int pg = 1; if (Request["pg"] != null) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); int numRec = db.QueryCount("SELECT Count(*) FROM paid_group " + GetQSearchSQL(searchStr)); OdbcDataReader reader = db.Query("SELECT * FROM paid_group " + GetQSearchSQL(searchStr) + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { PaidGroup group = BTS.Entity.PaidGroup.CreateForm(reader); // teacher member list Teacher[] memberList = group.LoadMemberTeachers(db); StringBuilder memberTxt = new StringBuilder(); for (int j = 0; j < memberList.Length; j++) { String txt = Teacher.GetTeacherID(memberList[j]._teacherID) + " " + memberList[j]._firstname + " " + memberList[j]._surname; memberTxt.Append( "<a href=\"TeacherManage.aspx?actPage=view&targetID="+memberList[j]._teacherID+"\">"+ txt + "<br>"); } outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + PaidGroup.GetPaidGroupID(group._paidGroupID) + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + group._name + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + group._rawRateInfo + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left >" + memberTxt + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + group._paidGroupID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this user?')) { setVal('actPage','delete');setVal('targetID','" + group._paidGroupID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (maxpg % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"PaidGroupManage.aspx?pg={0}\">{1}</a> ", i.ToString(), i.ToString())); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListCourse(string searchStr, bool isNewSearch, string filter) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) pg = Int32.Parse(Request["pg"]); if ((filter==null) || (filter.Length==0) || ((!filter.Equals("all")) && (!filter.Equals("only_close")))) { filter = "only_open"; } string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listCourse = new List<Course>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Course.GetQSearchSQL(searchStr); //filter string curDate = "'"+DateTime.Now.ToString("yyyy-MM-dd", ci)+"'"; // "'2011-05-01'"; string filterSQL = ""; if (filter.Equals("only_open")) { filterSQL = "( end_date > "+ curDate + " or course_type='คอร์ส DVD' )"; } else if (filter.Equals("only_close")) { filterSQL = "( end_date < " + curDate + " or course_type='คอร์ส DVD' )"; } if (filterSQL.Length > 0) { if (qSearchSQL.Trim().Length > 0) { qSearchSQL = qSearchSQL + " AND " + filterSQL; } else { qSearchSQL = filterSQL; } } // Add WHERE if (qSearchSQL.Trim().Length > 0) qSearchSQL = " WHERE " + qSearchSQL; int numRec = db.QueryCount("SELECT Count(*) FROM course c " + qSearchSQL); // add join condition qSearchSQL = qSearchSQL + ((qSearchSQL.Trim().Length > 0)?" AND ":" WHERE ") + " c.teacher_id=t.teacher_id"; String subQuery = " (SELECT count(*) FROM registration r WHERE r.status=0 AND r.course_id=c.course_id) "; OdbcDataReader reader = db.Query("SELECT c.*,t.firstname as teacher_firstname, t.surname as teacher_surname, " + subQuery + " AS num_registered " + " FROM course c, teacher t " + qSearchSQL + " order by bts_course_id desc LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Course course = Course.CreateForm(reader); // byte[] raw = Encoding.Default.GetBytes(course._firstname); // course._firstname = Encoding.GetEncoding("tis-620").GetString(raw); string divtxt = Config.URL_PIC_COURSE + "/" + course._img; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + course._btsCourseID + (course._numRegistered >= course._seatLimit ? "<br><font color=red>[เต็ม]</font>":"") + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " ><a href=\"CourseManage.aspx?actPage=view&targetID=" + course._courseID + "\" >" + "<b>" + course._courseName + "</b></a><br>" + course._courseDesc + "</td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + StringUtil.Int2StrComma(course._cost) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + course._startdate.ToString("dd/MM/yyyy", ci) + " - " + course._enddate.ToString("dd/MM/yyyy", ci) + "<br>" + course._dayOfWeek + " " + course._opentime + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + course._teacher._firstname + " " + course._teacher._surname + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','view');setVal('targetID','" + course._courseID + "');doSubmit()\"><img src=\"img/sys/view.gif\" border=0 alt=\"View detail\"></a> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + course._courseID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this course?')) { setVal('actPage','delete');setVal('targetID','" + course._courseID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); outBuf2.Append(String.Format("<a href=\"CourseManage.aspx?pg={0}&qsearch={1}\">{2}</a><< ", "1", searchStr, "First")); for (i = pg - 5; i <= pg + 5; i++) { if ((i <= 0) || (i > maxpg)) { continue; } if (i == pg) { outBuf2.Append("<b>"+i+"</b> "); } else { outBuf2.Append(String.Format("<a href=\"CourseManage.aspx?pg={0}&qsearch={1}&filter={2}\">{0}</a> ", i.ToString(), searchStr, filter)); } } outBuf2.Append(String.Format(" >><a href=\"CourseManage.aspx?pg={0}&qsearch={1}\">{2}</a> ", maxpg.ToString(), searchStr, "Last")); // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListRegister(string searchStr) { // get Page int pg = 1; if (Request["pg"] != null) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; // listRegistration = new List<Registration>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); if (searchStr.Trim().Length > 0) { searchStr = " WHERE " + searchStr; } int numRec = db.QueryCount("SELECT Count(*) FROM registration " + searchStr); OdbcDataReader reader = db.Query("SELECT * FROM registration " + searchStr + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Registration regis = Registration.CreateForm(reader); outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + regis._regisID + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._transactionID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._regisdate.ToString("dd/MM/yyyy", ci) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._studentID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._courseID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._fullCost + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._promotionID + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._discountedCost + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + regis._isPaid.ToString() + " </td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (maxpg % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"ReportRegis.aspx?pg={0}\">{1}</a> ", i.ToString(), i.ToString())); } } }
protected Student ProcessWizAddNewStudent() { Student t = new Student(); // validate data t._firstname = Request["firstname"]; t._surname = Request["surname"]; t._nickname = Request["nickname"]; t._citizenID = Request["citizen_id"]; t._sex = Request["sex"]; t._tel = Request["tel1"] + Request["tel2"] + Request["tel3"]; t._tel2 = Request["tel21"] + Request["tel22"] + Request["tel23"]; t._email = Request["email"]; t._addr = Request["addr"]; t._school = Request["school"]; t._level = Int32.Parse(Request["level"]); t._quiz = Student.EncodeQuizText(Page.Request); if (Request["birthday"] != null) { string[] s = Request["birthday"].Split('/'); t._birthday = new DateTime(Int32.Parse(s[2]) - 543, Int32.Parse(s[1]), Int32.Parse(s[0])); } else { t._birthday = new DateTime(); } t._create_date = DateTime.Today; t._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_STUDENT + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); t._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; return null; } } // Do validation // Save to DB and read to get student id // Need to use transaction 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(); db.BeginTransaction(IsolationLevel.ReadCommitted); // validate // duplicate citizen id if (t._citizenID.Length > 0) { int count = db.QueryCount("SELECT COUNT(*) FROM student WHERE citizen_id='" + t._citizenID + "'"); if (count > 0) { errorText = "รหัสบัตรประชาชน " + t._citizenID + " มีอยู่ในระบบแล้ว"; return null; } } // Save to DB t.AddToDB(db); // Get just saved student Student savedStudent = new Student(); savedStudent.LoadFromDBCustom(db, "SELECT * FROM student ORDER BY student_id DESC LIMIT 1"); db.Commit(); return savedStudent; } catch (Exception e) { errorText = "พบปัญหาบางประการ ข้อมูลไม่ถูกบันทึก"; return null; } finally { db.Close(); } }
protected void DoListRegistration(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"", "class=\"td1_grey\"" }, { "class=\"specalt\"", "class=\"alt\"", "class=\"td1_grey\"" } }; string grey = "class=\"thspec_grey\""; listRegistration = new List <Registration>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); string qSearchSQL = Registration.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) { qSearchSQL = " WHERE " + qSearchSQL; } // add join condition qSearchSQL = qSearchSQL + ((qSearchSQL.Trim().Length > 0) ? " AND " : " WHERE ") + " rg.student_id=st.student_id AND rg.course_id=c.course_id "; int numRec = db.QueryCount("SELECT Count(*) FROM registration rg, student st, course c " + qSearchSQL); OdbcDataReader reader = db.Query("SELECT rg.*, st.firstname as student_firstname, st.surname as student_surname, c.bts_course_id as bts_course_id, c.course_name FROM registration rg, student st, course c " + qSearchSQL + " ORDER BY regis_id desc " + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; int j = 0; int currentRegisTransactionID = 0; while (reader.Read()) { Registration reg = Registration.CreateForm(reader); if (reg._transactionID != currentRegisTransactionID) { currentRegisTransactionID = reg._transactionID; j++; reg.LoadBranch(db); outBuf.Append("<tr>"); outBuf.Append("<th colspan=9 scope=\"row\" abbr=\"Model\" " + bgclass[j % 2, 0] + "><b>" + reg.GetRegisTransactionID() + "</b></th>"); outBuf.Append("</tr>\n"); } string studentInfo = "<a href=\"StudentManage.aspx?actPage=view&targetID=" + reg._studentID + "\" >" + Student.GetStudentID(reg._studentID) + " " + reg._studentFirstname + " " + reg._studentSurname + "</a>"; string courseInfo = "<a href=\"CourseManage.aspx?actPage=view&targetID=" + reg._courseID + "\" >" + reg._btsCourseID + " " + reg._courseName + "</a>"; string costInfo = StringUtil.Int2StrComma(reg._discountedCost); string statusInfo = Registration.GetStatusText(reg._status); if (reg._status > 0) { costInfo = "<font color=red>" + costInfo + "</font>"; statusInfo = "<font color=red>" + statusInfo + "</font>"; } outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[j % 2, 0] + ">" + Registration.GetRegistrationID(reg._regisID) + "</th>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>" + reg._regisdate.ToString("dd/MM/yyyy HH:mm", ci) + " </td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>" + reg._paiddate.ToString("dd/MM/yyyy", ci) + " </td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=left>" + courseInfo + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=left>" + studentInfo + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=right>" + costInfo + " </td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>" + statusInfo + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=left>" + reg._note + "</td>"); outBuf.Append("<td " + bgclass[j % 2, 1] + " align=center>"); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + reg._regisID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:setVal('actPage','init_print_all');setVal('targetID','" + reg._regisID + "');doSubmit()\"><img src=\"img/sys/print.gif\" border=0 alt=\"พิมพ์ทุกอย่าง\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); outBuf2.Append(String.Format("<a href=\"RegistrationManage.aspx?pg={0}&qsearch={1}\">{2}</a><< ", "1", searchStr, "First")); for (i = pg - 10; i <= pg + 10; i++) { if ((i <= 0) || (i > maxpg)) { continue; } if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"RegistrationManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } outBuf2.Append(String.Format(" >><a href=\"RegistrationManage.aspx?pg={0}&qsearch={1}\">{2}</a> ", maxpg.ToString(), searchStr, "Last")); }
protected void DoListBranch(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listBranch = new List <Branch>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Branch.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) { qSearchSQL = " WHERE " + qSearchSQL; } int numRec = db.QueryCount("SELECT Count(*) FROM branch " + qSearchSQL); OdbcDataReader reader = db.Query("SELECT * FROM branch " + qSearchSQL + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Branch branch = Branch.CreateForm(reader); string divtxt = Config.URL_PIC_BRANCH + "/" + branch._img; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + " align=center valign=top width=100px>" + Branch.GetBranchID(branch._branchID) + "  </th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + branch._branchCode + "</td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left><p><b>สาขา: </b>" + branch._branchName + "</p>"); outBuf.Append("<p><b>ที่ตั้ง: </b>" + branch._address.Replace("\r\n", "<br>") + " </p>"); outBuf.Append("<p><b>เบอร์ติดต่อ: </b>" + branch._tel + " </p>"); outBuf.Append("<p><b>ชื่อผู้ดูแล: </b>" + branch._supervisor + " </p>"); outBuf.Append(" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center><a href=\"" + Config.URL_PIC_BRANCH + "/" + branch._img + "\" ><img border=0 width=200px height=150px src=\"" + Config.URL_PIC_BRANCH + "/" + branch._img + "\" ></a></td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + branch._branchID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this branch?')) { setVal('actPage','delete');setVal('targetID','" + branch._branchID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"BranchManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListStudent(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listStudent = new List<Student>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Student.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) { qSearchSQL = " WHERE " + qSearchSQL; } else // search all { qSearchSQL = " WHERE is_active=1 "; } int numRec = db.QueryCount("SELECT Count(*) FROM student " + qSearchSQL); OdbcDataReader reader = db.Query("SELECT * FROM student " + qSearchSQL + "order by student_id desc LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Student student = Student.CreateForm(reader); // byte[] raw = Encoding.Default.GetBytes(student._firstname); // student._firstname = Encoding.GetEncoding("tis-620").GetString(raw); int age = ((DateTime.Now.Year * 12 + DateTime.Now.Month) - (student._birthday.Year * 12 + student._birthday.Month)) / 12; string divtxt = Config.URL_PIC_STUDENT + "/" + student._img; string studentTxt = "<a href=\"StudentManage.aspx?actPage=view&targetID="+student._studentID+"\" onmouseover=\"showDiv('"+divtxt+"')\" onmouseout=\"hideDiv()\" >" + student._firstname + " " + student._surname + "("+ student._nickname +")" + "</a>"; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + ">" + Student.GetStudentID(student._studentID) + "</th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >"+studentTxt+" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center > <img width=20 height=24 src=\"" + Config.URL_PIC_SYS + (student._sex.Equals("Male")?"/boy.gif":"/girl.gif") + "\" >" ); /* for (int j = 0; j < ssList[i].skill.Count; j++) { outBuf.Append("<LI><a href=\"SkillHandling.aspx#sdid" + ssList[i].skill[j].id + "\" onmouseover=\"showChecklist(" + ssList[i].skill[j].id + ")\" onmouseout=\"hideCheckList()\" >" + ssList[i].skill[j].name + "</a>"); }*/ outBuf.Append(" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + age + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + student._school + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center>" + StringUtil.ConvertEducateLevel(student._level) + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + student.GetTel() + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " >" + student._email + " </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + student._studentID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this student?')) { setVal('actPage','delete');setVal('targetID','" + student._studentID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); outBuf2.Append(String.Format("<a href=\"StudentManage.aspx?pg={0}&qsearch={1}\">{2}</a><< ", "1", searchStr, "First")); for (i = pg-5; i <= pg+5; i++) { if ((i <= 0) || (i>maxpg)) { continue; } if (i == pg) { outBuf2.Append("<b>"+i+"</b> "); } else { outBuf2.Append(String.Format("<a href=\"StudentManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } outBuf2.Append(String.Format(" >><a href=\"StudentManage.aspx?pg={0}&qsearch={1}\">{2}</a> ", maxpg.ToString(), searchStr, "Last")); // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListPaymentByTeacher(string teacherID, string searchStr, bool isNewSearch) { DBManager db; db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); listTeacher = Teacher.LoadListFromDB(db, " WHERE is_active=1 ORDER BY firstname "); if (teacherID == null) return; // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) pg = Int32.Parse(Request["pg"]); string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"", "class=\"td1_grey\"", "class=\"td1_red\"" }, { "class=\"specalt\"", "class=\"alt\"", "class=\"td1_grey\"", "class=\"td1_red\"" } }; string grey = "class=\"thspec_grey\""; string red = "class=\"thspec_red\""; listPayment = new List<Payment>(); AppUser user = (AppUser)Session[SessionVar.USER]; filterPayment = Request["filter_payment"]; if (filterPayment == null) filterPayment = "0"; // by default string whereSQL = " pm.course_id=c.course_id AND c.teacher_id=t.teacher_id AND c.room_id = r.room_id "; // only admin can view all payment if (!user.IsAdmin()) { whereSQL = whereSQL + " AND r.branch_id=" + user._branchID; } // filter only payable courses if (filterPayment.Equals("0")) { whereSQL = whereSQL + " AND sum_max_payable<>sum_paid_cost "; } int numRec = db.QueryCount("SELECT Count(*) FROM payment pm, course c, teacher t, room r WHERE " + whereSQL); OdbcDataReader reader = db.Query("SELECT pm.course_id as course_id ,c.bts_course_id as bts_course_id ,c.course_name as course_name, t.paid_group_id as paid_group_id" + ", pm.sum_all_cost as sum_all_cost, pm.sum_max_payable as sum_max_payable, pm.sum_paid_cost as sum_paid_cost " + "FROM payment pm, course c, teacher t, room r WHERE " + whereSQL + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Payment payment = Payment.CreateForm(reader); string chbname = "course" + payment._courseID; int sumPayable = payment._sumMaxPayable - payment._sumPaidCost; int n = 1; if (sumPayable == 0) n = 2; else if (sumPayable < 0) n = 3; string bgcolor = (sumPayable == 0) ? grey : red; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + (sumPayable > 0 ? bgclass[i % 2, 0] : bgcolor) + ">" + payment._btsCourseID + "</th>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><input type=\"checkbox\" name=\"" + chbname + "\" id=\"" + chbname + "\" />" + "</td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " ><a href=\"CourseManage.aspx?actPage=view&targetID=" + payment._courseID + "\" >" + payment._courseName + "</a></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center >" + PaidGroup.GetPaidGroupID(payment._paidGroupID) + "</td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b>" + StringUtil.Int2StrComma(payment._sumAllCost) + "</b></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b><font color=blue>" + StringUtil.Int2StrComma(payment._sumMaxPayable) + "</font></b></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b><font color=red>" + StringUtil.Int2StrComma(payment._sumPaidCost) + "</font></b></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><b><font color=green>" + StringUtil.Int2StrComma(sumPayable) + "</font></b></td>"); /* outBuf.Append("<td " + bgclass[i % 2, n] + " align=center>" + payment._lastPaidDate.ToString("dd/MM/yyyy HH:mm", ci) + " </td>"); */ outBuf.Append("<td " + bgclass[i % 2, n] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','view');setVal('targetID','" + payment._courseID + "');doSubmit()\"><img src=\"img/sys/view.gif\" border=0 alt=\"View detail\"></a> "); // outBuf.Append("<a href=\"javascript:if (confirm('Delete this payment?')) { setVal('actPage','delete');setVal('targetID','" + payment._paymentID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"PaymentManage.aspx?pg={0}&filter_payment={1}&qsearch={1}\">{0}</a> ", i.ToString(), filterPayment, searchStr)); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected void DoListPromotion(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"", "class=\"td1_grey\"" }, { "class=\"specalt\"", "class=\"alt\"", "class=\"td1_grey\"" } }; string grey = "class=\"thspec_grey\""; listPromotion = new List <Promotion>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string qSearchSQL = Promotion.GetQSearchSQL(searchStr); if (qSearchSQL.Trim().Length > 0) { qSearchSQL = " WHERE " + qSearchSQL; } int numRec = db.QueryCount("SELECT Count(*) FROM promotion p " + qSearchSQL); // add join condition //qSearchSQL = qSearchSQL + ((qSearchSQL.Trim().Length > 0)?" AND ":" WHERE ") + " c.teacher_id=t.teacher_id"; Promotion[] promotions = Promotion.LoadListFromDBCustom(db, "SELECT p.* FROM promotion p " + qSearchSQL + " ORDER BY is_active desc, promotion_id " + " LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); for (int i = 0; i < promotions.Length; i++) { Promotion.LoadCourseList(db, promotions[i]); Promotion p = promotions[i]; int n = p._isActive ? 1 : 2; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + (p._isActive? bgclass[i % 2, 0] : grey) + " valign=top >" + Promotion.GetPromotionID(p._promotionID) + "</th>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><img border=0 src=\"" + Config.URL_PIC_SYS + "/" + (p._isActive?"green":"red") + "light.gif\" ></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " ><a href=\"#\" >" + "<b>" + p._promotionName + "</b></a><br>" + p._promotionDesc + "</td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " ><ul>"); int fullCost = 0; for (int j = 0; j < p._courses.Length; j++) { fullCost += p._courses[j]._cost; outBuf.Append("<li>" + p._courses[j]._courseName + " (<font color=red>" + p._courses[j]._cost + "</font>)</li>"); } int discount = 0; if (fullCost > 0) { discount = 100 - ((p._cost * 100 / fullCost)); } outBuf.Append("</ul></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center ><font color=red><strike>" + fullCost + "</strike></font></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center >" + p._cost + " <br><font color=red>(" + discount + "% off)</font></td>"); outBuf.Append("<td " + bgclass[i % 2, n] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + p._promotionID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this promotion?')) { setVal('actPage','delete');setVal('targetID','" + p._promotionID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (int i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"PromotionManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } // <a href="#">1</a> <b>2</b> <a href="#">3</a> <a href="#">4</a> }
protected bool DoAddSubmitStudent() { Student t = new Student(); // validate data t._firstname = Request["firstname"]; t._surname = Request["surname"]; t._nickname = Request["nickname"]; t._citizenID = Request["citizen_id"]; t._sex = Request["sex"]; t._tel = Request["tel1"] + Request["tel2"] + Request["tel3"]; t._tel2 = Request["tel21"] + Request["tel22"] + Request["tel23"]; t._email = Request["email"]; t._addr = Request["addr"]; t._school = Request["school"]; t._level = Int32.Parse(Request["level"]); t._quiz = Student.EncodeQuizText(Page.Request); if (Request["birthday"] != null) { string[] s = Request["birthday"].Split('/'); t._birthday = new DateTime(Int32.Parse(s[2]) - 543, Int32.Parse(s[1]), Int32.Parse(s[0])); } else { t._birthday = new DateTime(); } t._create_date = DateTime.Today; t._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_STUDENT + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); t._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } 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(); // validate // duplicate citizen id if (t._citizenID.Length > 0) { int count = db.QueryCount("SELECT COUNT(*) FROM student WHERE citizen_id='" + t._citizenID + "'"); if (count > 0) { errorText = "รหัสบัตรประชาชน " + t._citizenID + " มีอยู่ในระบบแล้ว"; return(false); } } // Save to DB t.AddToDB(db); } catch (Exception e) { errorText = "พบปัญหาบางประการ ข้อมูลไม่ถูกบันทึก"; return(false); } finally { db.Close(); } return(true); }
protected void DoListRoom(string searchStr, bool isNewSearch) { // get Page int pg = 1; if ((!isNewSearch) && (Request["pg"] != null)) { pg = Int32.Parse(Request["pg"]); } string[,] bgclass = new string[, ] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; listRoom = new List <Room>(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); string whereSQL = Room.GetQSearchSQL(searchStr); if (whereSQL.Length > 0) { whereSQL = " WHERE " + whereSQL; } int numRec = db.QueryCount("SELECT Count(*) FROM room " + whereSQL); if (whereSQL.Length > 0) { whereSQL = whereSQL + " AND r.branch_id=b.branch_id "; } else { whereSQL = " WHERE r.branch_id=b.branch_id "; } OdbcDataReader reader = db.Query("SELECT r.*,b.branch_name as branch_name FROM room r, branch b " + whereSQL + "ORDER BY room_id LIMIT " + Config.TBRECORD_PER_PAGE + " OFFSET " + (((pg - 1) * Config.TBRECORD_PER_PAGE))); int i = 0; while (reader.Read()) { Room room = Room.CreateForm(reader); string divtxt = Config.URL_PIC_TEACHER + "/" + room._img; outBuf.Append("<tr>"); outBuf.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + " align=center valign=top width=100px>" + Room.GetRoomID(room._roomID) + "  </th>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=left><p><b>ห้อง: </b>" + room._name + "</p>"); outBuf.Append("<p><b>สาขา: </b>" + room._branchName + " </p>"); outBuf.Append("<p><b>จำนวนที่นั่ง: </b>" + room._seatNo + " </p>"); outBuf.Append("<p><b>รายละเอียด: </b></p><p>" + room._description.Replace("\r\n", "<br>") + " </p>"); outBuf.Append(" </td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center><a href=\"" + Config.URL_PIC_ROOM + "/" + room._img + "\" ><img border=0 width=200px height=150px src=\"" + Config.URL_PIC_ROOM + "/" + room._img + "\" ></a></td>"); outBuf.Append("<td " + bgclass[i % 2, 1] + " align=center> "); outBuf.Append("<a href=\"javascript:setVal('actPage','edit');setVal('targetID','" + room._roomID + "');doSubmit()\"><img src=\"img/sys/edit.gif\" border=0 alt=\"Edit\"></a> "); outBuf.Append("<a href=\"javascript:if (confirm('Delete this room?')) { setVal('actPage','delete');setVal('targetID','" + room._roomID + "');doSubmit(); }\"><img src=\"img/sys/delete.gif\" border=0 alt=\"Delete\"></a> "); outBuf.Append("</td>"); outBuf.Append("</tr>\n"); i++; } db.Close(); // calculate max page int maxpg = numRec / Config.TBRECORD_PER_PAGE; if (maxpg < 1) { maxpg = 1; } else if (numRec % Config.TBRECORD_PER_PAGE > 0) { maxpg++; } // Generate Page Navi HTML outBuf2.Append("<b>Page</b> "); for (i = 1; i <= maxpg; i++) { if (i == pg) { outBuf2.Append("<b>" + i + "</b> "); } else { outBuf2.Append(String.Format("<a href=\"TeacherManage.aspx?pg={0}&qsearch={1}\">{0}</a> ", i.ToString(), searchStr)); } } }