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(); } }