protected void DoEditSubmitPaidGroup(string groupID) { PaidGroup group = new PaidGroup(); // validate data group._paidGroupID = Int32.Parse(groupID); group._name = Request["name"]; StringBuilder sb = new StringBuilder(); sb.Append(Request["bound1"]); sb.Append(":"); sb.Append(Request["rate1"]); sb.Append(";"); sb.Append(Request["bound2"]); sb.Append(":"); sb.Append(Request["rate2"]); sb.Append(";"); sb.Append(Request["bound3"]); sb.Append(":"); sb.Append(Request["rate3"]); sb.Append(";"); sb.Append(Request["bound4"]); sb.Append(":"); sb.Append(Request["rate4"]); sb.Append(";"); sb.Append(Request["bound5"]); sb.Append(":"); sb.Append(Request["rate5"]); sb.Append(";"); sb.Append(Request["bound6"]); sb.Append(":"); sb.Append(Request["rate6"]); sb.Append(";"); sb.Append(Request["bound7"]); sb.Append(":"); sb.Append(Request["rate7"]); sb.Append(";"); sb.Append(Request["bound8"]); sb.Append(":"); sb.Append(Request["rate8"]); sb.Append(";"); sb.Append(Request["bound9"]); sb.Append(":"); sb.Append(Request["rate9"]); sb.Append(";"); sb.Append(Request["bound10"]); sb.Append(":"); sb.Append(Request["rate10"]); group._rawRateInfo = group.BuildRateInfoString(sb.ToString()); group._rateInfo = PaidRateInfo.Parse(group._rawRateInfo); // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); group.UpdateToDB(db); db.Close(); }
protected List <string> GetListUser(string branch_id) { List <string> list = new List <String>(); if (string.IsNullOrEmpty(branch_id)) { return(list); } string sql = "SELECT username,firstname,surname FROM user WHERE branch_id='" + branch_id + "'"; string ret = String.Empty; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); OdbcDataReader reader = db.Query(sql); int fCount = reader.FieldCount; while (reader.Read()) { string tmp = "[" + reader.GetString(0).ToUpper() + "] " + reader.GetString(1) + " " + reader.GetString(2); list.Add(tmp); } db.Close(); return(list); }
protected void AddMockStudent(int num) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); Random rand = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < num; i++) { Student t = new Student(); t._firstname = StringUtil.RandomString(8, true); t._surname = StringUtil.RandomString(12, true); t._nickname = StringUtil.RandomString(7, true); t._img = "student" + rand.Next(1, 6) + ".jpg"; t._birthday = new DateTime(rand.Next(1980, 2005), rand.Next(1, 13), rand.Next(1, 29)); t._school = StringUtil.RandomString(20, true); t._tel = "08" + rand.Next(10000000, 99999999); t._tel2 = "08" + rand.Next(10000000, 99999999); t._sex = (rand.Next(0, 2) > 0?"Male":"Female"); t._addr = StringUtil.RandomString(50, true); t.AddToDB(db); } }
protected void DoAddSubmitPaidGroup() { PaidGroup group = new PaidGroup(); group._paidGroupID = Int32.Parse(Request["groupID"]); group._name = Request["name"]; StringBuilder sb = new StringBuilder(); sb.Append(Request["bound1"]); sb.Append(":"); sb.Append(Request["rate1"]); sb.Append(";"); sb.Append(Request["bound2"]); sb.Append(":"); sb.Append(Request["rate2"]); sb.Append(";"); sb.Append(Request["bound3"]); sb.Append(":"); sb.Append(Request["rate3"]); sb.Append(";"); sb.Append(Request["bound4"]); sb.Append(":"); sb.Append(Request["rate4"]); sb.Append(";"); sb.Append(Request["bound5"]); sb.Append(":"); sb.Append(Request["rate5"]); sb.Append(";"); sb.Append(Request["bound6"]); sb.Append(":"); sb.Append(Request["rate6"]); sb.Append(";"); sb.Append(Request["bound7"]); sb.Append(":"); sb.Append(Request["rate7"]); sb.Append(";"); sb.Append(Request["bound8"]); sb.Append(":"); sb.Append(Request["rate8"]); sb.Append(";"); sb.Append(Request["bound9"]); sb.Append(":"); sb.Append(Request["rate9"]); sb.Append(";"); sb.Append(Request["bound10"]); sb.Append(":"); sb.Append(Request["rate10"]); group._rawRateInfo = group.BuildRateInfoString(sb.ToString()); group._rateInfo = PaidRateInfo.Parse(group._rawRateInfo); // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); group.AddToDB(db); db.Close(); }
protected void DoAddSubmitUser() { AppUser u = new AppUser(); // validate data u._username = Request["username"]; u._passwd = Request["passwd"]; u._firstname = Request["firstname"]; u._surname = Request["surname"]; u._roleId = Int32.Parse(Request["role_id"]); u._branchID = Int32.Parse(Request["branch_id"]); // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); try { u.AddToDB(db); } catch (Exception e) { // show message? } db.Close(); }
protected void DoInitPrintAll(string regisTransactionID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); outBuf = new StringBuilder(); // find one of registration from list by transaction id AppUser user = (AppUser)Session[SessionVar.USER]; Registration[] reg = Registration.LoadListFromDB(db, " WHERE transaction_id=" + regisTransactionID + " AND branch_id=" + user._branchID + " ORDER BY regis_id "); // print PageBreaker pb = new PageBreaker(Config.PAGE_BREAK_MAX); StringBuilder tmpBuf = Registration.PrintCard(db, reg[0]._regisID); pb.Print(outBuf, tmpBuf, Config.PAGE_BREAK_CARD); outBuf.AppendLine("<br>"); pb.Print(outBuf, Registration.PrintReceipt(db, reg[0]._regisID, "สำหรับนักเรียน"), Config.PAGE_BREAK_RECEIPT); outBuf.AppendLine("<br>"); pb.Print(outBuf, Registration.PrintReceipt(db, reg[0]._regisID, "สำหรับโรงเรียน"), Config.PAGE_BREAK_RECEIPT); db.Close(); // Save to session Session[SessionVar.PRINT_INFO] = new StringBuilder(outBuf.ToString()); }
protected void AddMockStudent(int num) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); Random rand = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < num; i++) { Student t = new Student(); t._firstname = StringUtil.RandomString(8, true); t._surname = StringUtil.RandomString(12, true); t._nickname = StringUtil.RandomString(7, true); t._img = "student"+rand.Next(1,6)+".jpg"; t._birthday = new DateTime(rand.Next(1980, 2005), rand.Next(1, 13), rand.Next(1, 29)); t._school = StringUtil.RandomString(20, true); t._tel = "08" + rand.Next(10000000, 99999999); t._tel2 = "08" + rand.Next(10000000, 99999999); t._sex = (rand.Next(0,2)>0?"Male":"Female"); t._addr = StringUtil.RandomString(50, true); t.AddToDB(db); } }
protected void DoEditSubmitTeacher(string teacherID) { Teacher t = new Teacher(); // validate data t._teacherID = Int32.Parse(teacherID); t._firstname = Request["firstname"]; t._surname = Request["surname"]; t._citizenID = Request["citizen_id"]; t._sex = Request["sex"]; t._tel = Request["tel"]; t._email = Request["email"]; t._addr = Request["addr"]; //t._subject = Request["subject"]; 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(); } // default to old value t._img = Request["img_old"]; 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_TEACHER + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); t._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.UpdateToDB(db); db.Close(); }
protected StringBuilder DoInitPrinRegistrationReceipt(string regisID, string title) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); StringBuilder tmpBuf = Registration.PrintReceipt(db, Int32.Parse(regisID), title); db.Close(); return(tmpBuf); }
protected void DoDeletePaidGroup(string groupID) { PaidGroup group = new PaidGroup(); group._paidGroupID = Int32.Parse(groupID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); group.DeleteToDB(db); db.Close(); }
protected void DoRemoveTeacherSubmit(String paidGroupID, String teacherID) { PaidGroup group = new PaidGroup(); group._paidGroupID = Int32.Parse(paidGroupID); // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); group.RemoveTeacherToDB(db, teacherID); db.Close(); }
protected void DoDeleteUser(string username) { AppUser u = new AppUser(); u._username = username; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); u.DeleteToDB(db); db.Close(); }
protected void DoDeleteBranch(string branchID) { Branch t = new Branch(); t._branchID = Int32.Parse(branchID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.DeleteToDB(db); db.Close(); }
protected void DoDeleteStudent(string studentID) { Student t = new Student(); t._studentID = Int32.Parse(studentID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.DeleteToDB(db); db.Close(); }
protected void DoDeleteRoom(string roomID) { Room t = new Room(); t._roomID = Int32.Parse(roomID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.DeleteToDB(db); db.Close(); }
// TODO: Check duplicated registration protected void ProcessRegistration(RegisTransaction reg) { AppUser user = (AppUser)Session[SessionVar.USER]; // Collect additional variable // * User information comes from session NOT DB reg._username = user._username; reg._paidMethod = Int32.Parse(Request["paid_method"]); if (Session[SessionVar.BRANCH_SELECTED] == null) { reg._branchID = user._branchID; } else { reg._branchID = Int32.Parse((String)Session[SessionVar.BRANCH_SELECTED]); user._branchID = reg._branchID; Session[SessionVar.USER] = user; } reg._paiddate = StringUtil.getDate(Request["paid_date"]); // seat for (int i = 0; i < Request.Form.AllKeys.Length; i++) { if (Request.Form.AllKeys[i].StartsWith("seat_no")) { string courseID = Request.Form.AllKeys[i].Substring(7); string seatNo = Request[Request.Form.AllKeys[i]]; try { reg._seatNoMap.Add(courseID, seatNo); } catch (Exception ex) { } continue; } if (Request.Form.AllKeys[i].StartsWith("note")) { string courseID = Request.Form.AllKeys[i].Substring(4); string note = Request[Request.Form.AllKeys[i]]; try { reg._noteMap.Add(courseID, note); } catch (Exception ex) { } continue; } } DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); reg.AddToDB(db); db.Close(); }
protected void DoDeletePromotion(string promotionID) { Promotion t = new Promotion(); t._promotionID = Int32.Parse(promotionID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.DeleteToDB(db); db.Close(); }
protected void DoDeleteTeacher(string teacherID) { Teacher t = new Teacher(); t._teacherID = Int32.Parse(teacherID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); // delete paid_group_teacher_mapping first db.Execute("DELETE FROM paid_group_teacher_mapping WHERE teacher_id=" + teacherID); // delete teacher t.DeleteToDB(db); db.Commit(); db.Close(); }
public static int GetMaxRecord() { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); OdbcDataReader reader = db.Query("SELECT MAX(teacher_id) FROM teacher"); if (!reader.Read()) { return(0); } long max = reader.IsDBNull(0) ? -1 : reader.GetInt64(0); db.Close(); return((int)(max + 1)); }
protected void DoEditSubmitBranch(string branchID) { Branch b = new Branch(); // validate data b._branchID = Int32.Parse(branchID); b._branchName = Request["branch_name"]; b._branchCode = Request["branch_code"]; b._address = Request["address"]; b._tel = Request["tel"]; b._supervisor = Request["supervisor"]; // default to old value b._img = Request["img_old"]; 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_BRANCH + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); b._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); b.UpdateToDB(db); db.Close(); }
protected void DoEditRegistration(string regisID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); theReg = new Registration(); theReg.LoadFromDB(db, " regis_id=" + regisID); theReg.LoadCourse(db); theReg.LoadStudent(db); theReg.LoadBranch(db); // Branch branch = new Branch(); // branch.LoadFromDB(db, " branch_id=" + theReg._branchID); // Generate HTML content TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\registration_edit.htm"); String templateContent = reader.ReadToEnd(); reader.Close(); string promotionTxt = theReg._promotionID > 0 ? "<a href=\"PromotionManage.aspx?actPage=view&targetID=" + theReg._promotionID + "\" >" + Promotion.GetPromotionID(theReg._promotionID) + " </a>" : "-"; String htmlContent = String.Format(templateContent , theReg.GetRegisTransactionID() , Registration.GetRegistrationID(theReg._regisID) , "<a href=\"CourseManage.aspx?actPage=view&targetID=" + theReg._course._courseID + "\" >" + theReg._course._btsCourseID + " " + theReg._course._courseName + "</a>" , promotionTxt , "<a href=\"StudentManage.aspx?actPage=view&targetID=" + theReg._studentID + "\" >" + Student.GetStudentID(theReg._student._studentID) + " " + theReg._student._firstname + " " + theReg._student._surname + "</a>" , StringUtil.ConvertYearToEng(theReg._regisdate, "yyyy/MM/dd HH:mm:ss") , StringUtil.ConvertYearToEng(theReg._paiddate, "yyyy/MM/dd") , theReg._branch._branchName , StringUtil.Int2StrComma(theReg._fullCost) , StringUtil.Int2StrComma(theReg._discountedCost) , Registration.GetPaidMethodText(theReg._paidMethod.ToString()) , theReg._seatNo , theReg._username , Registration.GetStatusText(theReg._status) ); outBuf.Append(htmlContent); db.Close(); }
protected void DoRefund(string regisID) { int status = Int32.Parse(Request.Form.Get("status")); int refundCost = Int32.Parse(Request.Form.Get("refund_cost")); string paidMethod = Request.Form.Get("paid_method"); string note = Request.Form.Get("note"); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); theReg = new Registration(); theReg._status = status; theReg.LoadFromDB(db, " regis_id=" + regisID); theReg.LoadCourse(db); // TODO: Check if the fund is paid to teacher? if (refundCost <= theReg._discountedCost) { theReg._discountedCost -= refundCost; } theReg._status = status; theReg._paidMethod = Int32.Parse(paidMethod); theReg._note = note; // Save to DB theReg.UpdateToDB(db); // Update payment Payment.UpdatePaymentByCourse(db, theReg._course); db.Commit(); db.Close(); if (refundCost > 0) { msgText = "คืนเงิน " + refundCost + " บาท เรียบร้อยแล้ว คงเหลือเงิน " + theReg._discountedCost + " บาท"; } else { msgText = "แก้ไขข้อมูลเรียบร้อย"; } }
protected string GetBranchName(int branch_id) { if (branch_id <= 0) { return(""); } string sql = "SELECT branch_name FROM branch WHERE branch_id='" + branch_id + "'"; string ret = String.Empty; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); OdbcDataReader reader = db.Query(sql); reader.Read(); ret = reader.GetString(0); db.Close(); return(ret); }
protected void DoEditSubmitPromotion(string promotionID) { Promotion p = new Promotion(); // validate data p._promotionID = Int32.Parse(promotionID); p._promotionName = Request["promotion_name"]; p._promotionDesc = Request["promotion_desc"]; p._cost = Int32.Parse(Request["cost"]); p._isActive = Request["is_active"] != null ? true : false; // read selected course ArrayList idList = new ArrayList(); for (int i = 0; i < Request.Form.AllKeys.Length; i++) { if (Request.Form.AllKeys[i].StartsWith("course")) { string s = Request.Form.AllKeys[i].Substring(6); idList.Add(s); } } p._courses = new Course[idList.Count]; int n = 0; foreach (string id in idList) { try { Course c = new Course(); c._courseID = Int32.Parse(id); p._courses[n++] = c; } catch (Exception e) { Console.WriteLine(e.StackTrace); } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); p.UpdateToDB(db); db.Close(); }
protected void DoEditSubmitRoom(string roomID) { try { Room r = new Room(); // validate data r._roomID = Int32.Parse(roomID); r._name = Request["roomname"]; r._branchID = Int32.Parse(Request["branch_id"]); r._seatNo = Int32.Parse(Request["seat_no"]); r._description = Request["description"]; // default to old value r._img = Request["img_old"]; if (portrait.PostedFile.FileName != "") { 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_ROOM + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); r._img = imgname; } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); r.UpdateToDB(db); db.Close(); } catch (Exception err) { errorText = err.Message + err.StackTrace; Response.Redirect("RoomManage.aspx?actPage=edit&targetID=" + targetID + "&errorText=ข้อมูลไม่ถูกต้อง โปรดตรวจสอบอีกครั้ง"); } }
protected void DoAddSubmitBranch() { Branch b = new Branch(); // validate data b._branchName = Request["branch_name"]; b._branchCode = Request["branch_code"]; b._address = Request["address"]; b._tel = Request["tel"]; b._supervisor = Request["supervisor"]; b._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_BRANCH + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); b._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); b.AddToDB(db); db.Close(); }
protected void DoEditRegistration(string regisID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); theReg = new Registration(); theReg.LoadFromDB(db, " regis_id=" + regisID); theReg.LoadCourse(db); theReg.LoadStudent(db); theReg.LoadBranch(db); // Branch branch = new Branch(); // branch.LoadFromDB(db, " branch_id=" + theReg._branchID); // Generate HTML content TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\registration_edit.htm"); String templateContent = reader.ReadToEnd(); reader.Close(); string promotionTxt = theReg._promotionID > 0 ? "<a href=\"PromotionManage.aspx?actPage=view&targetID="+ theReg._promotionID + "\" >" + Promotion.GetPromotionID(theReg._promotionID) + " </a>" : "-"; String htmlContent = String.Format(templateContent , theReg.GetRegisTransactionID() , Registration.GetRegistrationID(theReg._regisID) , "<a href=\"CourseManage.aspx?actPage=view&targetID=" + theReg._course._courseID + "\" >" + theReg._course._btsCourseID + " " + theReg._course._courseName + "</a>" , promotionTxt , "<a href=\"StudentManage.aspx?actPage=view&targetID=" + theReg._studentID + "\" >" + Student.GetStudentID(theReg._student._studentID) + " " + theReg._student._firstname + " " + theReg._student._surname + "</a>" , StringUtil.ConvertYearToEng(theReg._regisdate, "yyyy/MM/dd HH:mm:ss") , StringUtil.ConvertYearToEng(theReg._paiddate, "yyyy/MM/dd") , theReg._branch._branchName , StringUtil.Int2StrComma(theReg._fullCost) , StringUtil.Int2StrComma(theReg._discountedCost) , Registration.GetPaidMethodText(theReg._paidMethod.ToString()) , theReg._seatNo , theReg._username , Registration.GetStatusText(theReg._status) ); outBuf.Append(htmlContent); db.Close(); }
protected void DoEditSubmitRegistration(string regisID) { string paidMethod = Request.Form.Get("paid_method"); string note = Request.Form.Get("note"); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); theReg = new Registration(); theReg.LoadFromDB(db, " regis_id=" + regisID); // Save to DB theReg.UpdateToDB(db); db.Commit(); db.Close(); msgText = "แก้ไขข้อมูลเรียบร้อย"; }
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(); } } }
protected void AddMockTeacher(int num) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); Random rand = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < num; i++) { Teacher t = new Teacher(); t._firstname = StringUtil.RandomString(11, true); t._surname = StringUtil.RandomString(16, true); t._img = "teacher" + rand.Next(1, 6) + ".jpg"; t._birthday = new DateTime(rand.Next(1900, 2005), rand.Next(1, 13), rand.Next(1, 29)); t._subject = StringUtil.RandomString(30, true); t._tel = "08" + rand.Next(10000000, 99999999); t._sex = (rand.Next(0, 2) > 0 ? "Male" : "Female"); t._addr = StringUtil.RandomString(50, true); t.AddToDB(db); } }
protected void DoEditSubmitUser(string username) { AppUser u = new AppUser(); // validate data u._username = username; //FIX if (!String.IsNullOrEmpty(Request["passwd"])) // Check validate??? { u._passwd = AppUser.GetMD5Encoded(Request["passwd"]); } u._firstname = Request["firstname"]; u._surname = Request["surname"]; u._roleId = Int32.Parse(Request["role_id"]); u._branchID = Int32.Parse(Request["branch_id"]); // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); u.UpdateToDB(db); db.Close(); }
protected int DoPaidSubmitPayment(string courseID) { string paidCost = Request["paid_cost"]; string receiverTeacherID = Request["receiver_teacher_id"]; AppUser user = (AppUser)Session[SessionVar.USER]; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); Payment pay = new Payment(); pay.LoadFromDB(db, " course_id=" + courseID); pay.LoadCourse(db); PaidGroup pg = new PaidGroup(); pg.LoadFromDB(db, " paid_group_id=" + pay._course._paidGroupID); // Add history PaymentHistory ph = new PaymentHistory(pay, pg, Int32.Parse(paidCost), Int32.Parse(receiverTeacherID), user); ph.AddToDB(db); // refresh Payment record Payment.UpdatePaymentByCourse(db, Int32.Parse(courseID)); db.Commit(); // find latest payment pay.LoadHistory(db); int latestPaymentID = pay._historyList.Last.Value._paymentID; db.Close(); return(latestPaymentID); }
protected void DoInitPrintAll(string regisTransactionID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); outBuf = new StringBuilder(); // find one of registration from list by transaction id AppUser user = (AppUser)Session[SessionVar.USER]; Registration[] reg = Registration.LoadListFromDB(db, " WHERE transaction_id="+regisTransactionID+" AND branch_id="+ user._branchID +" ORDER BY regis_id "); // print PageBreaker pb = new PageBreaker(Config.PAGE_BREAK_MAX); StringBuilder tmpBuf = Registration.PrintCard(db, reg[0]._regisID); pb.Print(outBuf, tmpBuf, Config.PAGE_BREAK_CARD); outBuf.AppendLine("<br>"); pb.Print(outBuf, Registration.PrintReceipt(db, reg[0]._regisID, "สำหรับนักเรียน"), Config.PAGE_BREAK_RECEIPT); outBuf.AppendLine("<br>"); pb.Print(outBuf, Registration.PrintReceipt(db, reg[0]._regisID, "สำหรับโรงเรียน"), Config.PAGE_BREAK_RECEIPT); db.Close(); // Save to session Session[SessionVar.PRINT_INFO] = new StringBuilder(outBuf.ToString()); }
protected void DoAddSubmitTeacher() { Teacher t = new Teacher(); // validate data t._firstname = Request["firstname"]; t._surname = Request["surname"]; t._citizenID = Request["citizen_id"]; t._sex = Request["sex"]; t._tel = Request["tel"]; t._email = Request["email"]; t._addr = Request["addr"]; //t._subject = Request["subject"]; 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._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_TEACHER + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); t._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.AddToDB(db); 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 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 DoViewPayment(string courseID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); thePayment = new Payment(); thePayment.LoadFromDB(db, " course_id=" + courseID); thePayment.LoadHistory(db); thePayment.LoadCourse(db); Course c = thePayment._course; c.LoadTeacher(db); c.LoadPaidGroup(db); // preload all branches Dictionary<int, Branch> branches = Branch.LoadListFromDBAsMap(db, ""); PaidGroup pg = new PaidGroup(); pg.LoadFromDB(db, " paid_group_id="+c._paidGroupID); // Load teachers in this group listTeacher = pg.LoadMemberTeachers(db); // Generate HTML content TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\payment_view.htm"); String templateContent = reader.ReadToEnd(); reader.Close(); // Construct Teacher List StringBuilder teachTxt = new StringBuilder(); for (int i=0;i<listTeacher.Length;i++){ string link = "TeacherManage.aspx?actPage=edit&targetID=" + listTeacher[i]._teacherID; teachTxt.Append("<a href=\"" + link + "\" >" + listTeacher[i]._firstname + " " + listTeacher[i]._surname + "</a><br>"); } // Construct RaitInfo List StringBuilder rinfoTxt = new StringBuilder(); for (int i = 0; i < pg._rateInfo.Length; i++) { rinfoTxt.Append("มากกว่า " + StringUtil.Int2StrComma(pg._rateInfo[i]._bound) + " บาท ได้รับ " + pg._rateInfo[i]._percent + " %<br>"); } // Construct Paid history StringBuilder phTxt = new StringBuilder(); foreach (PaymentHistory ph in thePayment._historyList) { ph.LoadReceiver(db); ph.LoadUser(db); Branch b = branches[ph._branchID]; string link = "TeacherManage.aspx?actPage=edit&targetID=" + ph._receiverTeacherID; phTxt.AppendLine("<tr><td align=center>" + PaymentHistory.GetPaymentHistoryID(ph._paymentID) + "</td>"); phTxt.AppendLine("<td align=center>" + StringUtil.ConvertYearToEng(ph._paidDate, "yyyy/MM/dd HH:mm:ss") + "</td>"); phTxt.AppendLine("<td align=center>" + StringUtil.Int2StrComma(ph._paidCost) + "</td>"); phTxt.AppendLine("<td align=center><a href=\""+link+"\" >" + ph._receiverTeacher._firstname + " " + ph._receiverTeacher._surname + "</a></td>"); phTxt.AppendLine("<td align=center>" + ph._user._firstname + " " + ph._user._surname + "</td>"); phTxt.AppendLine("<td align=center>" + b._branchName + "</td>"); phTxt.AppendLine("<td align=center><a href=\"javascript:doInitPrint(" + ph._paymentID + ")\"><img src=\"" + Config.URL_PIC_SYS + "/view.gif\" border=0></a> </td>"); } String htmlContent = String.Format(templateContent , c._courseName , "<a href=\"TeacherManage.aspx?actPage=edit&targetID="+c._teacherID + "\" >" + c._teacher._firstname + " " + c._teacher._surname + "</a>" , PaidGroup.GetPaidGroupID(c._paidGroupID) + " " + c._paidGroup._name , teachTxt.ToString() , rinfoTxt.ToString() , StringUtil.Int2StrComma(thePayment._sumAllCost) , StringUtil.Int2StrComma(thePayment._sumMaxPayable) , StringUtil.Int2StrComma(thePayment._sumPaidCost) , StringUtil.Int2StrComma(thePayment._sumMaxPayable - thePayment._sumPaidCost) , phTxt.ToString() ); outBuf.Append(htmlContent); db.Close(); }
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 DoEditSubmitStudent(string studentID) { Student t = new Student(); // validate data t._studentID = Int32.Parse(studentID); 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(); } // default to old value t._img = Request["img_old"]; 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; } } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); t.UpdateToDB(db); db.Close(); }
protected void DoAddSubmitRoom() { try { Room r = new Room(); // validate data r._name = Request["roomname"]; r._branchID = Int32.Parse(Request["branch_id"]); r._seatNo = Int32.Parse(Request["seat_no"]); r._description = Request["description"]; r._img = "noimg.jpg"; if (portrait.PostedFile.FileName != "") { 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_ROOM + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); r._img = imgname; } // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); r.AddToDB(db); db.Close(); } catch (Exception err) { errorText = err.Message + err.StackTrace; Response.Redirect("RoomManage.aspx?actPage=add&errorText=ข้อมูลไม่ถูกต้อง โปรดตรวจสอบอีกครั้ง"); } }
public static int GetMaxRecord() { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); OdbcDataReader reader = db.Query("SELECT MAX(teacher_id) FROM teacher"); if (!reader.Read()) return 0; long max = reader.IsDBNull(0) ? -1 : reader.GetInt64(0); db.Close(); return (int)(max+1); }
protected void DoDeleteTeacher(string teacherID) { Teacher t = new Teacher(); t._teacherID = Int32.Parse(teacherID); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); // delete paid_group_teacher_mapping first db.Execute("DELETE FROM paid_group_teacher_mapping WHERE teacher_id="+teacherID); // delete teacher t.DeleteToDB(db); db.Commit(); db.Close(); }
protected void DoAddTeacherSubmit(String paidGroupID, String teacherID) { PaidGroup group = new PaidGroup(); group._paidGroupID = Int32.Parse(paidGroupID); // Save to DB DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); group.AddTeacherToDB(db, teacherID); db.Close(); }
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; } } } } }
protected List<string> GetListUser(string branch_id) { List<string> list = new List<String>(); if (string.IsNullOrEmpty(branch_id)) return list; string sql = "SELECT username,firstname,surname FROM user WHERE branch_id='" + branch_id + "'"; string ret = String.Empty; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); OdbcDataReader reader = db.Query(sql); int fCount = reader.FieldCount; while (reader.Read()) { string tmp = "[" + reader.GetString(0).ToUpper() + "] " + reader.GetString(1) + " " + reader.GetString(2); list.Add(tmp); } db.Close(); return list; }
protected string GetRoleName(int role_id) { if (role_id <= 0) return ""; string sql = "SELECT name FROM role WHERE role_id='" + role_id + "'"; string ret = String.Empty; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); OdbcDataReader reader = db.Query(sql); reader.Read(); ret = reader.GetString(0); db.Close(); return ret; }
protected void DoEditSubmitCourse(string courseID) { Course c = new Course(); // validate data c._courseID = Int32.Parse(courseID); 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 // default to old value c._img = Request["img_old"]; 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 c.course_id<>" + c._courseID + " 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 c.UpdateToDB(db); db.Close(); } }
protected int DoPaidSubmitPayment(string courseID) { string paidCost = Request["paid_cost"]; string receiverTeacherID = Request["receiver_teacher_id"]; AppUser user = (AppUser)Session[SessionVar.USER]; DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); db.BeginTransaction(IsolationLevel.ReadCommitted); Payment pay = new Payment(); pay.LoadFromDB(db, " course_id="+courseID); pay.LoadCourse(db); PaidGroup pg = new PaidGroup(); pg.LoadFromDB(db, " paid_group_id="+pay._course._paidGroupID); // Add history PaymentHistory ph = new PaymentHistory(pay, pg, Int32.Parse(paidCost), Int32.Parse(receiverTeacherID), user); ph.AddToDB(db); // refresh Payment record Payment.UpdatePaymentByCourse(db, Int32.Parse(courseID)); db.Commit(); // find latest payment pay.LoadHistory(db); int latestPaymentID = pay._historyList.Last.Value._paymentID; db.Close(); return latestPaymentID; }
protected void DoInitPrintReceiptPaymentData(string paymentID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); PaymentHistory pm = new PaymentHistory(); pm.LoadFromDB(db, " payment_id="+paymentID); pm.LoadCourse(db); pm._course.LoadTeacher(db); pm._course.LoadPaidGroup(db); // load teacher in this group Teacher[] listTeacher = pm._course._paidGroup.LoadMemberTeachers(db); pm.LoadReceiver(db); // preload all branches Dictionary<int, Branch> branches = Branch.LoadListFromDBAsMap(db, ""); // Load PaymentHistory BEFORE this PaymentHistory[] pmList = PaymentHistory.LoadListFromDB(db, " WHERE course_id='" + pm._courseID + "' and payment_id<='" + pm._paymentID + "' ORDER BY payment_id"); // Construct Teacher List StringBuilder teachTxt = new StringBuilder(); for (int i = 0; i < listTeacher.Length; i++) { string link = "TeacherManage.aspx?actPage=edit&targetID=" + listTeacher[i]._teacherID; teachTxt.Append(listTeacher[i]._firstname + " " + listTeacher[i]._surname + "<br>"); } // Construct Paid history StringBuilder phTxt = new StringBuilder(); for (int i=0;i<pmList.Length;i++) { PaymentHistory ph = pmList[i]; ph.LoadReceiver(db); ph.LoadUser(db); Branch b = branches[ph._branchID]; string link = "TeacherManage.aspx?actPage=edit&targetID=" + ph._receiverTeacherID; phTxt.AppendLine("<tr><td align=center>" + PaymentHistory.GetPaymentHistoryID(ph._paymentID) + "</td>"); phTxt.AppendLine("<td align=center>" + StringUtil.ConvertYearToEng(ph._paidDate, "yyyy/MM/dd HH:mm:ss ") + "</td>"); phTxt.AppendLine("<td align=center>" + StringUtil.Int2StrComma(ph._paidCost) + "</td>"); phTxt.AppendLine("<td align=center>" + ph._receiverTeacher._firstname + " " + ph._receiverTeacher._surname + "</td>"); phTxt.AppendLine("<td align=center>" + ph._user._firstname + " "+ ph._user._surname+ "</td>"); phTxt.AppendLine("<td align=center>" + b._branchName + "</td>"); } // User AppUser user = new AppUser(); user.LoadFromDB(db, " username='******'"); // Generate HTML content TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\payment_print.htm"); String templateContent = reader.ReadToEnd(); reader.Close(); String htmlContent = String.Format(templateContent , StringUtil.ConvertYearToEng(pm._paidDate, "yyyy/MM/dd HH:mm:ss") , pm._receiverTeacher._firstname + " " + pm._receiverTeacher._surname , pm._course._btsCourseID + " \"" + pm._course._courseName + "\"" , StringUtil.Int2StrComma(pm._paidCost) , pm._course._teacher._firstname + " " + pm._course._teacher._surname , PaidGroup.GetPaidGroupID(pm._course._paidGroup._currentRound) , teachTxt.ToString() , StringUtil.Int2StrComma(pm._sumMaxPayable) , StringUtil.Int2StrComma(pm._sumPaidCost + pm._paidCost) , phTxt.ToString() , user._firstname + " " + user._surname ); outBuf.Append(htmlContent); db.Close(); }
protected 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 StringBuilder DoInitPrinRegistrationReceipt(string regisID, string title) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); StringBuilder tmpBuf = Registration.PrintReceipt(db, Int32.Parse(regisID), title); db.Close(); return tmpBuf; }