コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            #region 安全性检查
            if (Request.UrlReferrer == null)
            {
                Response.End();
            }
            if (Request.Url.Host.ToLower() != Request.UrlReferrer.Host.ToLower() || Request.Url.Port != Request.UrlReferrer.Port)
            {
                Response.End();
            }
            #endregion
            #region 保存文件
            if (Request.Form["act"] != null)
            {
                HttpPostedFile f = imgFile.PostedFile;
                if (f.ContentLength > 0)
                {
                    string dirpath = Server.MapPath("~/") + "upload\\temp\\";

                    int    pos = f.FileName.LastIndexOf(".");
                    string Ext = f.FileName.Substring(pos, f.FileName.Length - pos).ToLower();
                    if (Ext.ToLower().IndexOf("efw") == -1)
                    {
                        Response.Write("<script>alert('文件格式不正确!');document.location='Models.aspx';</script>");
                        Response.End();
                    }

                    string filename = eBase.GetFileName() + Ext;
                    string pathname = dirpath + filename;
                    if (!Directory.Exists(dirpath))
                    {
                        Directory.CreateDirectory(dirpath);
                    }
                    f.SaveAs(pathname);

                    string _json = eBase.ReadFile(pathname);

                    try
                    {
                        System.IO.File.Delete(pathname);
                    }
                    catch
                    {
                    }

                    eJson  json     = new eJson(_json);
                    eJson  model    = json.GetCollection("a_eke_sysModels").Collection[0];
                    string file     = model.GetValue("AspxFile");
                    string aspxFile = Server.MapPath("~/System/") + file + ".log";
                    if (json.IsValue("aspxFile"))
                    {
                        string text = json.GetValue("aspxFile");
                        eBase.WriteFile(aspxFile, text);
                    }
                    string csFile = Server.MapPath("~/System/") + file + ".cs.log";
                    if (json.IsValue("csFile"))
                    {
                        string text = json.GetValue("csFile");
                        eBase.WriteFile(csFile, text);
                    }
                    string desFile = Server.MapPath("~/System/") + file + ".designer.cs.log";
                    if (json.IsValue("desFile"))
                    {
                        string text = json.GetValue("desFile");
                        eBase.WriteFile(desFile, text);
                    }
                    eOleDB.ImportJson(_json, false);


                    Response.Write("<script>alert('导入成功!');document.location='Models.aspx';</script>");
                    Response.End();
                }
            }
            #endregion
        }
コード例 #2
0
        private void Example1()
        {
            StringBuilder sb = new StringBuilder();

            #region 例1
            sb.Append("<font color=\"#ff0000\"><b>例1:</b></font><br />\r\n");
            eJson item = new eJson();
            item.Add("Name", "eFrameWork");
            item.Add("Version", "V1.0");
            sb.Append("生成:" + item.ToString() + "<br />\r\n");
            sb.Append("解析:<br />\r\n");
            eJson model1 = new eJson(item.ToString());
            foreach (string key in model1.GetKeys())
            {
                sb.Append(key + " = " + model1.GetValue(key) + "<br />\r\n");
            }
            #endregion
            #region 例2
            sb.Append("<font color=\"#ff0000\"><b>例2:</b></font><br />\r\n");
            eJson json  = new eJson();
            eJson item1 = new eJson();
            item1.Add("Name", "李先生");
            item1.Add("Sex", "男");
            json.Add(item1);

            eJson item2 = new eJson();
            item2.Add("Name", "韩小姐");
            item2.Add("Sex", "女");
            json.Add(item2);

            sb.Append("生成:" + json.ToString() + "<br />\r\n");

            sb.Append("解析:<br />\r\n");

            eJson model2 = new eJson(json.ToString());
            foreach (eJson m in model2.GetCollection())
            {
                foreach (string key in m.GetKeys())
                {
                    sb.Append(key + " = " + m.GetValue(key) + "<br>\r\n");
                }
            }
            #endregion
            #region 例3
            sb.Append("<font color=\"#ff0000\"><b>例3:</b></font><br />\r\n");
            eJson itemAll = new eJson();
            itemAll.Add("Name", "所有");
            itemAll.Add("Items", json);



            sb.Append("生成:" + itemAll.ToString() + "<br />\r\n");

            sb.Append("解析:<br />\r\n");

            eJson model3 = new eJson(itemAll.ToString());

            foreach (string key in model3.GetKeys())
            {
                if (model3.IsValue(key))
                {
                    sb.Append(key + " = " + model3.GetValue(key) + "<br />\r\n");
                }
                if (model3.IsCollection(key))
                {
                    sb.Append(key + ":<br>");
                    foreach (eJson m in model3.GetCollection(key).GetCollection())
                    {
                        foreach (string key1 in m.GetKeys())
                        {
                            sb.Append(key1 + " = " + m.GetValue(key1) + "<br>\r\n");
                        }
                    }
                }
            }
            #endregion

            #region 例4



            #endregion

            litSingle1.Text = sb.ToString();
        }