Example #1
0
        /// <summary>
        /// 通过留言信息
        /// </summary>
        /// <returns></returns>
        private Hashtable GetUpdateInfo(HttpContext context)
        {
            Hashtable htRet = new Hashtable();

            try
            {
                string sMode = CConvert.ToString(context.Request["mode"]).Trim();
                if (sMode == "")
                {
                    sMode = "1";//默认【部分更新】
                }

                string sVerCode  = CConvert.ToString(context.Request["vercode"]).Trim();
                string sLastTime = CConvert.ToString(context.Request["lasttime"]).Trim();

                DBIndex dbm = new DBIndex();

                DataSet ds = dbm.getVercodeInfoByCode(sVerCode);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    htRet["ok"]  = false;
                    htRet["msg"] = "授权码错误";
                    return(htRet);
                }


                if (sMode == "2")
                {
                    sLastTime = "2010-01-01 00:00:00";
                }
                //临时文件夹
                string sUpdTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                string sPath    = AppConfig.ImagePath + sVerCode + "/";

                if (Directory.Exists(sPath) == false)
                {
                    Directory.CreateDirectory(sPath);
                }

                DirectoryInfo di = new DirectoryInfo(sPath);
                di.Delete(true);
                if (Directory.Exists(sPath + "anima/") == false)
                {
                    Directory.CreateDirectory(sPath + "anima/");
                }
                if (Directory.Exists(sPath + "train/") == false)
                {
                    Directory.CreateDirectory(sPath + "train/");
                }
                if (Directory.Exists(sPath + "test/") == false)
                {
                    Directory.CreateDirectory(sPath + "test/");
                }
                if (Directory.Exists(sPath + "view/") == false)
                {
                    Directory.CreateDirectory(sPath + "view/");
                }


                //返回的json数据
                Hashtable htJson = new Hashtable();

                //获取最近更新日期之后的 卡通图标
                ArrayList lstAnima = new ArrayList();
                DataSet   dsAnima  = dbm.getAnimaByTime(sLastTime);

                foreach (DataRow dr in dsAnima.Tables[0].Rows)
                {
                    Hashtable ht = new Hashtable();
                    ht["id"]        = CConvert.ToString(dr["img_id"]);
                    ht["file_name"] = CConvert.ToString(dr["file_name"]);

                    File.Copy(AppConfig.ImagePath + "anima/" + CConvert.ToString(dr["file_name"]), sPath + "anima/" + CConvert.ToString(dr["file_name"]));
                    lstAnima.Add(ht);
                }
                htJson["anima"] = lstAnima;

                //课堂训练
                ArrayList lstTrain = new ArrayList();

                DataSet dsTrain = dbm.getTrainByTime("1", sLastTime);
                foreach (DataRow dr in dsTrain.Tables[0].Rows)
                {
                    Hashtable ht = new Hashtable();

                    ht["id"]      = CConvert.ToString(dr["train_id"]);
                    ht["title"]   = CConvert.ToString(dr["title"]);
                    ht["photo"]   = CConvert.ToString(dr["photo"]);
                    ht["content"] = CConvert.ToString(dr["content"]);
                    ht["words"]   = CConvert.ToString(dr["words"]);
                    ht["speed"]   = CConvert.ToString(dr["speed"]);

                    File.Copy(AppConfig.ImagePath + "train/" + CConvert.ToString(dr["photo"]), sPath + "train/" + CConvert.ToString(dr["photo"]));

                    lstTrain.Add(ht);
                }
                htJson["train"] = lstTrain;



                //阅读测评
                ArrayList lstTest = new ArrayList();

                DataSet dsTest = dbm.getTrainByTime("2", sLastTime);
                foreach (DataRow dr in dsTest.Tables[0].Rows)
                {
                    Hashtable ht = new Hashtable();

                    ht["id"]      = CConvert.ToString(dr["train_id"]);
                    ht["title"]   = CConvert.ToString(dr["title"]);
                    ht["photo"]   = CConvert.ToString(dr["photo"]);
                    ht["content"] = CConvert.ToString(dr["content"]);
                    ht["words"]   = CConvert.ToString(dr["words"]);
                    ht["speed"]   = CConvert.ToString(dr["speed"]);
                    File.Copy(AppConfig.ImagePath + "test/" + CConvert.ToString(dr["photo"]), sPath + "test/" + CConvert.ToString(dr["photo"]));

                    lstTest.Add(ht);
                }
                htJson["test"] = lstTest;


                //测评问题
                ArrayList lstQues = new ArrayList();
                DataSet   dsQues  = dbm.getQuesByTime("2", sLastTime);
                foreach (DataRow dr in dsQues.Tables[0].Rows)
                {
                    Hashtable ht = new Hashtable();

                    ht["id"]       = CConvert.ToString(dr["q_id"]);
                    ht["q_type"]   = CConvert.ToString(dr["q_type"]);
                    ht["train_id"] = CConvert.ToString(dr["train_id"]);
                    ht["title"]    = CConvert.ToString(dr["title"]);
                    ht["op1"]      = CConvert.ToString(dr["op1"]);
                    ht["op2"]      = CConvert.ToString(dr["op2"]);
                    ht["op3"]      = CConvert.ToString(dr["op3"]);
                    ht["op4"]      = CConvert.ToString(dr["op4"]);
                    ht["answer"]   = CConvert.ToString(dr["answer"]);

                    lstQues.Add(ht);
                }
                htJson["question"] = lstQues;


                //视幅拓展训练
                ArrayList lstView = new ArrayList();
                DataSet   dsView  = dbm.getViewByTime(sLastTime);
                foreach (DataRow dr in dsView.Tables[0].Rows)
                {
                    Hashtable ht = new Hashtable();

                    ht["id"]      = CConvert.ToString(dr["viewtrain_id"]);
                    ht["type"]    = CConvert.ToString(dr["vt_type"]);
                    ht["title"]   = CConvert.ToString(dr["title"]);
                    ht["photo"]   = CConvert.ToString(dr["photo"]);
                    ht["content"] = CConvert.ToString(dr["content"]);
                    ht["route"]   = CConvert.ToString(dr["route"]);
                    ht["v_desc"]  = CConvert.ToString(dr["v_desc"]);

                    File.Copy(AppConfig.ImagePath + "view/" + CConvert.ToString(dr["photo"]), sPath + "view/" + CConvert.ToString(dr["photo"]));

                    lstView.Add(ht);
                }
                htJson["view"] = lstView;


                JavaScriptSerializer jss = new JavaScriptSerializer();

                StreamWriter sw = new StreamWriter(sPath + "data.json");
                sw.Write(jss.Serialize(htJson));
                sw.Flush();
                sw.Close();

                ZipOutputStream s = new ZipOutputStream(File.Create(AppConfig.ImagePath + sVerCode + sUpdTime + ".zip"));

                s.SetLevel(6);

                Compress(sPath, sPath, s);

                s.Finish();
                s.Close();

                htRet["ok"]       = true;
                htRet["lasttime"] = sUpdTime;
                htRet["file"]     = AppConfig.SiteRoot + "upload/" + sVerCode + sUpdTime + ".zip";


                dbm.InsertUpdateLog(sVerCode);
            }
            catch (Exception ex)
            {
                htRet["ok"]  = false;
                htRet["msg"] = "处理失败!" + ex.Message;
            }
            return(htRet);
        }