public static int loadSchoolInfo(int schoolid, string authcode) { int ret = 0; string dir = Application.StartupPath + "\\conf\\"; string filename = schoolid + ".conf"; FileOper fo = new FileOper(dir, filename); string strSchoolInfo = Common.getSchoolInfo(schoolid, authcode); if (strSchoolInfo.Length > 0) { SchoolInfo info = JsonOper.DeserializeJsonToObject <SchoolInfo>(strSchoolInfo); if (info.schoolid > 0) { Global.saveSchoolConfig(schoolid, authcode); g_szAwardType = info.awardtypelist; //更新本地缓存 fo.WriteFile(strSchoolInfo); g_SchoolInfoStr = strSchoolInfo; Log.Info("Global.loadSchoolInfo() ...2-ok!"); Log.Debug(g_SchoolInfoStr); ret = 1; } } else { Log.Info("getSchoolInfo error, load from conf now..."); string data = fo.ReadFile(); if (data.Length > 0) { g_SchoolInfoStr = data; ret = 2; } Log.Info("Global.loadSchoolInfo() ...2-err..." + g_SchoolInfoStr); } //if (strSchoolInfo.Length > 0) if (ret == 1) { SchoolInfo info = JsonOper.DeserializeJsonToObject <SchoolInfo>(g_SchoolInfoStr); User[] si = info.teacherlist; List <User> teacherlist = new List <User>(); foreach (User u in si) { teacherlist.Add(u); } int nDel = m_db.delTeachers(m_schoolid); int nAdd = m_db.addUser(teacherlist); int a = nDel; Global.setSchoolID(schoolid); Global.setSchoolname(info.schoolname); m_db.delSchool(info.schoolid); m_db.addSchool(info.schoolid, info.schoolname); g_szClasses = info.classlist; int nClassDel = m_db.delClassBySchoolid(m_schoolid); int nClassAdd = 0; foreach (Classes c in g_szClasses) { nClassAdd += m_db.addClass(c); } Log.Info("Global.loadSchoolInfo() nClassDel=" + nClassDel + ", nClassAdd=" + nClassAdd); string coursetimes = info.coursetime; m_db.delCourseTime(); m_db.addCourseTime(coursetimes); Log.Info("Global.loadSchoolInfo() Over."); g_SchoolInfoStr = strSchoolInfo; } else if (ret == 2) { Log.Info("getSchoolInfo error."); SchoolInfo info = JsonOper.DeserializeJsonToObject <SchoolInfo>(g_SchoolInfoStr); User[] si = info.teacherlist; List <User> teacherlist = new List <User>(); foreach (User u in si) { teacherlist.Add(u); } Global.setSchoolID(schoolid); Global.setSchoolname(info.schoolname); g_szClasses = info.classlist; } if (g_SchoolInfoStr.Length == 0) { return(-1); } else { return(1); } }
public static bool loadClassInfo() { if (m_classid == -1) { return(false); } Classes c = m_db.getClassById(m_classid); if (c != null) { Global.setClassID(c.id); Global.setClassname(c.name); Global.setGrade(c.grade); } string dir = Application.StartupPath + "\\conf\\"; string filename = m_schoolid + "-" + m_classid + ".conf"; FileOper fo = new FileOper(dir, filename); string strClassInfo = Common.getClassInfo(); if (strClassInfo.Length > 0) { //更新本地缓存 fo.WriteFile(strClassInfo); g_ClassInfoStr = strClassInfo; Log.Info("Global.loadClassInfo() ...2-ok!"); Log.Debug(g_ClassInfoStr); } else { Log.Error("getClassInfo error."); g_ClassInfoStr = fo.ReadFile(); Log.Error("Global.loadClassInfo() ...2-err..." + g_ClassInfoStr); } if (g_ClassInfoStr.Length > 0) { g_ClassInfo = JsonOper.DeserializeJsonToObject <ClassInfo>(g_ClassInfoStr); g_StudentInfoArray = g_ClassInfo.Data.Student; g_TeacherArray = g_ClassInfo.Data.Teacher; int nClassID = g_ClassInfo.Data.ID; int nGrade = g_ClassInfo.Data.Grade; Global.setGrade(nGrade); Global.setClassID(nClassID); Global.setClassname(g_ClassInfo.Data.Name); Global.setUploadInvalidData(g_ClassInfo.Data.UploadInvalidData); g_Studentlist.Clear(); foreach (StudentInfo s in g_StudentInfoArray) { User u = new User(); u.id = Int32.Parse(s.ID); u.name = s.Name; u.seat = s.SEAT.Replace("-", ""); u.type = 2;//student u.schoolid = m_schoolid; u.classid = nClassID; u.imageurl = s.imageurl; string pinying = Util.GetPinyin(s.Name); u.pinying = pinying; s.pinyin = pinying; //u.classname = Global.getClassname(); g_Studentlist.Add(u); } //write to RueSqlite.db { //更新学生信息 if (g_Studentlist.Count > 0) { int nDel = m_db.delUser(nClassID, 2); int nAdd = m_db.addUser(g_Studentlist); int a = nDel; } } } return(true); }