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 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 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 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 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 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 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 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 void DoAddSubmitCourse() { Course c = new Course(); // validate data c._btsCourseID = Request["bts_course_id"]; c._courseName = Request["course_name"]; c._shortName = Request["short_name"]; c._courseType = Request["course_type"]; c._courseDesc = Request["course_desc"]; c._roomID = Int32.Parse(Request["room_id"]); c._teacherID = Int32.Parse(Request["teacher_id"]); c._paidGroupID = Int32.Parse(Request["paid_group_id"]); c._category = Request["category"]; c._startdate = StringUtil.getDate(Request["startdate"]); c._enddate = StringUtil.getDate(Request["enddate"]); c._dayOfWeek = Request["day_of_week"]; c._opentime = Request["opentime"]; c._cost = Int32.Parse(Request["cost"]); c._seatLimit = Int32.Parse(Request["seat_limit"]); c._bankRegisLimit = 0; // remove field c._img = "noimg.jpg"; if (portrait.PostedFile.FileName != "") { try { string serverFileExt = Path.GetExtension(portrait.PostedFile.FileName); Random rand = new Random((int)DateTime.Now.Ticks); string fullpath = ""; string imgname = ""; do { string randomFName = rand.Next(Int32.MaxValue).ToString(); imgname = randomFName + serverFileExt; fullpath = Config.PATH_APP_ROOT + "\\" + Config.URL_PIC_COURSE + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); c._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); // Validate if bts code okay Course[] dupBTSCourse = Course.LoadListFromDBCustom(db, "SELECT * FROM course c, payment p WHERE bts_course_id='" + c._btsCourseID + "' AND c.course_id=p.course_id AND (p.sum_max_payable>p.sum_paid_cost OR p.sum_max_payable=0)"); if (dupBTSCourse.Length == 0) { // no duplicate bts // Save to DB // Save to DB db.BeginTransaction(IsolationLevel.ReadCommitted); c.AddToDB(db); c._courseID = Course.GetMaxCourseID(db); // Update Payment with empty record Payment payment = new Payment(); payment._courseID = c._courseID; payment._sumAllCost = 0; payment._sumPaidCost = 0; payment._status = 0; payment._lastPaidDate = DateTime.Now; payment.AddToDB(db); db.Commit(); db.Close(); } }
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 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 DoAddSubmitCourse() { Course c = new Course(); // validate data c._btsCourseID = Request["bts_course_id"]; c._courseName = Request["course_name"]; c._shortName = Request["short_name"]; c._courseType = Request["course_type"]; c._courseDesc = Request["course_desc"]; c._roomID = Int32.Parse(Request["room_id"]); c._teacherID = Int32.Parse(Request["teacher_id"]); c._paidGroupID = Int32.Parse(Request["paid_group_id"]); c._category = Request["category"]; c._startdate = StringUtil.getDate(Request["startdate"]); c._enddate = StringUtil.getDate(Request["enddate"]); c._dayOfWeek = Request["day_of_week"]; c._opentime = Request["opentime"]; c._cost =Int32.Parse(Request["cost"]); c._seatLimit = Int32.Parse(Request["seat_limit"]); c._bankRegisLimit = 0; // remove field c._img = "noimg.jpg"; if (portrait.PostedFile.FileName != "") { try { string serverFileExt = Path.GetExtension(portrait.PostedFile.FileName); Random rand = new Random((int)DateTime.Now.Ticks); string fullpath = ""; string imgname = ""; do { string randomFName = rand.Next(Int32.MaxValue).ToString(); imgname = randomFName + serverFileExt; fullpath = Config.PATH_APP_ROOT + "\\" + Config.URL_PIC_COURSE + "\\" + imgname; } while (File.Exists(fullpath)); portrait.PostedFile.SaveAs(fullpath); c._img = imgname; } catch (Exception err) { errorText = err.Message + err.StackTrace; } } DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); db.Connect(); // Validate if bts code okay Course[] dupBTSCourse = Course.LoadListFromDBCustom(db, "SELECT * FROM course c, payment p WHERE bts_course_id='" + c._btsCourseID + "' AND c.course_id=p.course_id AND (p.sum_max_payable>p.sum_paid_cost OR p.sum_max_payable=0)"); if (dupBTSCourse.Length == 0) { // no duplicate bts // Save to DB // Save to DB db.BeginTransaction(IsolationLevel.ReadCommitted); c.AddToDB(db); c._courseID = Course.GetMaxCourseID(db); // Update Payment with empty record Payment payment = new Payment(); payment._courseID = c._courseID; payment._sumAllCost = 0; payment._sumPaidCost = 0; payment._status = 0; payment._lastPaidDate = DateTime.Now; payment.AddToDB(db); db.Commit(); db.Close(); } }