public void DoEditTeacher(string teacherID) { DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); //Load GroupList groupList = PaidGroup.LoadListFromDB(db, ""); theTeacher = new Teacher(); if (!theTeacher.LoadFromDB(db, "teacher_id=" + teacherID)) theTeacher = null; // List Course History string[,] bgclass = new string[,] { { "class=\"spec\"", "class=\"td1\"" }, { "class=\"specalt\"", "class=\"alt\"" } }; string query = "SELECT * from course "; query = query + "WHERE teacher_id='"; query = query + teacherID + "' order by start_date desc"; OdbcDataReader reader = db.Query(query); int i = 0; while (reader.Read()) { Course course = Course.CreateForm(reader); outBuf3.Append("<tr>"); outBuf3.Append("<th scope=\"row\" abbr=\"Model\" " + bgclass[i % 2, 0] + " align=center>" + course._startdate.ToString("dd MMM yyyy", ci) + " </th>"); outBuf3.Append("<td " + bgclass[i % 2, 1] + " align=center>" + course._btsCourseID + " </td>"); outBuf3.Append("<td " + bgclass[i % 2, 1] + " align=left>" + course._courseName + " </td>"); outBuf3.Append("<td " + bgclass[i % 2, 1] + " >" + course._cost + " </td>"); outBuf3.Append("</tr>\n"); i++; } db.Close(); }
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(); }
public static bool CreateForm(OdbcDataReader reader, Teacher teacher) { int fCount = reader.FieldCount; for (int i = 0; i < fCount; i++) { string name = reader.GetName(i); // Map to DB field. Need to change if db changed switch (name) { case "teacher_id": teacher._teacherID = reader.GetInt32(i); break; case "sex": teacher._sex = reader.GetString(i); break; case "addr": teacher._addr = reader.GetString(i); break; case "tel": teacher._tel = reader.GetString(i); break; case "email": teacher._email = reader.GetString(i); break; case "birthday": teacher._birthday = new DateTime(reader.GetDate(i).Ticks); break; case "firstname": teacher._firstname = reader.GetString(i); break; case "surname": teacher._surname = reader.GetString(i); break; case "citizen_id": teacher._citizenID = reader.GetString(i); break; case "image": teacher._img = reader.GetString(i); break; case "subject": teacher._subject = reader.GetString(i); break; case "is_active": teacher._isActive = reader.GetInt32(i) > 0 ? true : false; break; } } return reader.HasRows; }
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); } }
// load all teacher NOT in this paidgroup // paidGroupID must be set before public Teacher[] LoadNonMemberTeachers(DBManager db) { if (this._paidGroupID == 0) return null; String subQuery = "SELECT teacher_id FROM paid_group_teacher_mapping WHERE paid_group_id='" + this._paidGroupID + "'"; String sql = "SELECT * FROM teacher WHERE is_active=1 AND teacher_id NOT IN ( " + subQuery + " ) ORDER BY teacher_id"; OdbcDataReader reader = db.Query(sql); LinkedList<Teacher> list = new LinkedList<Teacher>(); while (reader.Read()) { list.AddLast(Teacher.CreateForm(reader)); } Teacher[] entities = new Teacher[list.Count]; int i = 0; foreach (Teacher t in list) { entities[i++] = t; } return entities; }
public static Teacher CreateForm(OdbcDataReader reader) { Teacher teacher = new Teacher(); Teacher.CreateForm(reader, teacher); return teacher; }
public static Teacher[] LoadListFromDB(DBManager db, string sqlCriteria) { OdbcDataReader reader = db.Query("SELECT * FROM teacher " + sqlCriteria); LinkedList<Teacher> list = new LinkedList<Teacher>(); while (reader.Read()) { list.AddLast(Teacher.CreateForm(reader)); } Teacher[] entities = new Teacher[list.Count]; int i = 0; foreach (Teacher t in list) { entities[i++] = t; } return entities; }
protected void DoViewTeacher(string teacherID) { outBuf = new StringBuilder(); DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC); theTeacher = new Teacher(); theTeacher.LoadFromDB(db, " teacher_id=" + teacherID); PaidGroup[] memberInGroup = theTeacher.LoadAssosicatedPaidGroup(db); // Query payment // Payment[] pays1 = Payment.LoadListFromDBbyTeacherID(db, teacherID); // Payment[] pays2 = Payment.LoadListFromDBbyTeacherIDInPaidGroup(db, teacherID); db.Close(); // List out all paid group that the teacher is member StringBuilder memberGroupTxt = new StringBuilder(); for (int i = 0; i < memberInGroup.Length; i++) { memberGroupTxt.Append("  "+PaidGroup.GetPaidGroupID(memberInGroup[i]._paidGroupID)+ " " + memberInGroup[i]._name + "<br>"); } /* // Only teach by himself int sumAllCost = 0; int sumMaxPayable = 0; int sumPaidCost = 0; StringBuilder pay1Txt = new StringBuilder(); for (int i = 0; i < pays1.Length; i++) { sumAllCost += pays1[i]._sumAllCost; sumMaxPayable += pays1[i]._sumMaxPayable; sumPaidCost += pays1[i]._sumPaidCost; string courseTxt = "<a href=\"CourseManage.aspx?actPage=view&targetID=" + pays1[i]._courseID + "\" >" + pays1[i]._btsCourseID + " " + pays1[i]._courseName + "</a>"; pay1Txt.AppendLine("<tr>"); pay1Txt.AppendLine("<td align=left> " + courseTxt + "</td>"); pay1Txt.AppendLine("<td align=center> " + pays1[i]._courseStartDate.ToString("dd/MM/yyyy", ci) + " - " + pays1[i]._courseEndDate.ToString("dd/MM/yyyy", ci) + "</td>"); pay1Txt.AppendLine("<td align=center> " + StringUtil.Int2StrComma(pays1[i]._sumAllCost) + "</td>"); pay1Txt.AppendLine("<td align=center> " + StringUtil.Int2StrComma(pays1[i]._sumMaxPayable) + "</td>"); pay1Txt.AppendLine("<td align=center> " + StringUtil.Int2StrComma(pays1[i]._sumPaidCost) + "</td>"); pay1Txt.AppendLine("</tr>"); } // Summary pay1Txt.AppendLine("<tr>"); pay1Txt.AppendLine("<td align=center colspan=2 > <b>รวม </b></td>"); pay1Txt.AppendLine("<td align=center><b> " + StringUtil.Int2StrComma(sumAllCost) + "</b></td>"); pay1Txt.AppendLine("<td align=center><b> " + StringUtil.Int2StrComma(sumMaxPayable) + "</b></td>"); pay1Txt.AppendLine("<td align=center><b> " + StringUtil.Int2StrComma(sumPaidCost) + "</b></td>"); pay1Txt.AppendLine("</tr>"); // All in paidgroup int sumAllCost2 = 0; int sumMaxPayable2 = 0; int sumPaidCost2 = 0; StringBuilder pay2Txt = new StringBuilder(); for (int i = 0; i < pays2.Length; i++) { sumAllCost2 += pays2[i]._sumAllCost; sumMaxPayable2 += pays2[i]._sumMaxPayable; sumPaidCost2 += pays2[i]._sumPaidCost; string courseTxt = "<a href=\"CourseManage.aspx?actPage=view&targetID=" + pays2[i]._courseID + "\" >" + pays2[i]._btsCourseID + " " + pays2[i]._courseName + "</a>"; pay2Txt.AppendLine("<tr>"); pay2Txt.AppendLine("<td align=left> " + courseTxt + "</td>"); pay2Txt.AppendLine("<td align=center> " + pays2[i]._courseStartDate.ToString("dd/MM/yyyy", ci) + " - " + pays2[i]._courseEndDate.ToString("dd/MM/yyyy", ci) + "</td>"); pay2Txt.AppendLine("<td align=center> " + StringUtil.Int2StrComma(pays2[i]._sumAllCost) + "</td>"); pay2Txt.AppendLine("<td align=center> " + StringUtil.Int2StrComma(pays2[i]._sumMaxPayable) + "</td>"); pay2Txt.AppendLine("<td align=center> " + StringUtil.Int2StrComma(pays2[i]._sumPaidCost) + "</td>"); pay2Txt.AppendLine("</tr>"); } // Summary pay2Txt.AppendLine("<tr>"); pay2Txt.AppendLine("<td align=center colspan=2 > <b>รวม </b></td>"); pay2Txt.AppendLine("<td align=center><b> " + StringUtil.Int2StrComma(sumAllCost2) + "</b></td>"); pay2Txt.AppendLine("<td align=center><b> " + StringUtil.Int2StrComma(sumMaxPayable2) + "</b></td>"); pay2Txt.AppendLine("<td align=center><b> " + StringUtil.Int2StrComma(sumPaidCost2) + "</b></td>"); pay2Txt.AppendLine("</tr>"); */ /* StringBuilder rateTxt = new StringBuilder(); int currentRate = theTeacher._paidGroup.GetCurrentRate(sumAllCost2); PaidRateInfo[] rate = theTeacher._paidGroup._rateInfo; for (int i = 0; i < rate.Length; i++) { string bgcolor = ""; if (currentRate == rate[i]._percent) { bgcolor = " bgcolor=\"#FFB148\" "; } rateTxt.AppendLine("<tr>"); rateTxt.AppendLine("<td align=center " + bgcolor + "> " + StringUtil.Int2StrComma(rate[i]._bound) + " </td>"); rateTxt.AppendLine("<td align=center " + bgcolor + "> " + rate[i]._percent + "% </td>"); rateTxt.AppendLine("</tr>"); } */ TextReader reader = new StreamReader(Config.PATH_APP_ROOT + "\\template\\teacher_view.htm"); String templateContent = reader.ReadToEnd(); reader.Close(); String htmlContent = String.Format(templateContent , Config.URL_PIC_TEACHER + "/" + theTeacher._img , Teacher.GetTeacherID(theTeacher._teacherID) , theTeacher._firstname + " " + theTeacher._surname , theTeacher._subject , Config.URL_PIC_SYS + (theTeacher._sex.Equals("Male") ? "/boy.gif" : "/girl.gif") , theTeacher._birthday.ToString("dd/MM/yyyy", ci) , theTeacher._citizenID , theTeacher._addr , theTeacher._tel , theTeacher._email , memberGroupTxt.ToString() , ""// pay1Txt.ToString() , ""//pay2Txt.ToString() ); outBuf.Append(htmlContent); }
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 bool LoadTeacher(DBManager db) { if (_teacherID <=0 ) return false; _teacher = new Teacher(); _teacher.LoadFromDB(db, " teacher_id="+_teacherID); return true; }