private static int loadSchoolInfo_Local() { string dir = Application.StartupPath + "\\conf\\"; string filename = m_schoolid + ".conf"; FileOper fo = new FileOper(dir, filename); string data = fo.ReadFile(); if (data.Length > 0) { //TODO: 如果文件中有,从文件中获取 //TODO: 如果文件中没有,则从DB中获取 g_SchoolInfoStr = data; SchoolInfo info = JsonOper.DeserializeJsonToObject <SchoolInfo>(data); Global.setSchoolname(info.schoolname); g_szClasses = info.classlist; return(1); } else { return(0); } }
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); } }