Exemple #1
0
        public string SaveTextRes_post(HttpContext context)
        {
            bool   isCreate = false;
            IWxRes res;

            try
            {
                TextRes tres = context.Request.Form.ConvertToEntity <TextRes>();
                res = tres;

                if (tres.Id > 0)
                {
                    TextRes ores = IocObject.WeixinRes.GetResById(tres.Id) as TextRes;
                    tres.TypeId     = ores.TypeId;
                    tres.TypeName   = ores.TypeName;
                    tres.CreateTime = ores.CreateTime;
                }
                else
                {
                    isCreate        = true;
                    tres.CreateTime = DateTime.Now;
                    tres.TypeName   = "文本";
                    tres.TypeId     = 1;
                }
                tres.UpdateTime = DateTime.Now;
                tres.Content    = context.Request["Content"];
                int id = tres.Save();
            }
            catch (Exception exc)
            {
                return("{result:false,message:'" + exc.Message + "'}");
            }
            return("{result:true,message:'" + (isCreate ? "添加成功" : "保存成功") + "'}");
        }
Exemple #2
0
        private int SaveTextRes(TextRes textRes)
        {
            DataBaseAccess db   = this._dao.New();
            var            data = new object[, ]
            {
                { "@Id", textRes.Id },
                { "@ResKey", textRes.ResKey },
                { "@CreateTime", textRes.CreateTime },
                { "@UpdateTime", textRes.UpdateTime },
                { "@TypeId", textRes.TypeId },
                { "@TypeName", textRes.TypeName },
                { "@Content", textRes.Content }
            };

            if (textRes.Id > 0)
            {
                db.ExecuteNonQuery(new SqlQuery("UPDATE wx_res SET reskey=@resKey,updatetime=@updatetime WHERE id=@Id", data),
                                   new SqlQuery("Update wx_text Set wx_text.content=@Content where resId=@Id", data));
            }
            else
            {
                int row = db.ExecuteNonQuery(new SqlQuery(@"INSERT INTO wx_res (ResKey,TypeId,TypeName,CreateTime,UpdateTime)
                            VALUES (@ResKey,@TypeId,@TypeName,@CreateTime,@UpdateTime)", data));
                if (row == 1)
                {
                    int id = Convert.ToInt32(db.ExecuteScalar("SELECT MAX(id) FROM wx_res"));
                    data[0, 1] = id;
                    db.ExecuteNonQuery(new SqlQuery(@"INSERT INTO wx_text(ResId,Content)VALUES(@Id,@Content)", data));
                    return(id);
                }
            }

            return(textRes.Id);
        }
Exemple #3
0
        public static string GetString(string name, params object[] args)
        {
            TextRes sys = GetLoader();

            if (sys == null)
            {
                return(null);
            }

            string res = sys.resources.GetString(name, TextRes.Culture);

            if (args != null && args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    String value = args[i] as String;
                    if (value != null && value.Length > 1024)
                    {
                        args[i] = value.Substring(0, 1024 - 3) + "...";
                    }
                }
                return(String.Format(CultureInfo.CurrentCulture, res, args));
            }
            else
            {
                return(res);
            }
        }
Exemple #4
0
        private static TextRes GetLoader()
        {
            if (loader == null)
            {
                TextRes sr = new TextRes();
                Interlocked.CompareExchange(ref loader, sr, null);
            }

            return(loader);
        }
Exemple #5
0
        public static string GetString(string name)
        {
            TextRes sys = GetLoader();

            if (sys == null)
            {
                return(null);
            }

            return(sys.resources.GetString(name, TextRes.Culture));
        }
Exemple #6
0
        public int Save(IWxRes res)
        {
            TextRes textRes = res as TextRes;

            if (textRes != null)
            {
                return(SaveTextRes(textRes));
            }
            else
            {
                ArticleRes artRes = res as ArticleRes;
                return(this.SaveArticleRes(artRes));
            }
        }
Exemple #7
0
        public string EditTextRes(HttpContext context)
        {
            int          id   = int.Parse(context.Request["id"]);
            TemplatePage page = this._app.GetPage(this._plugin, "mg/text_res.html");
            TextRes      res  = IocObject.WeixinRes.GetResById(id) as TextRes;

            if (res == null)
            {
                page.AddVariable("content", "");
                page.AddVariable("entity", "{}");
            }
            else
            {
                page.AddVariable("content", res.Content == null ? "" : res.Content);
                page.AddVariable("entity", JsonConvert.SerializeObject(res));
            }

            return(page.ToString());
        }
Exemple #8
0
        protected void testLua()
        {
            string  path    = "";
            TextRes textRes = null;
            //LuaState ls = new LuaState();
            LuaScriptMgr luaMgr = new LuaScriptMgr();

            path    = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathLuaScript], "UtilDebug.txt");
            textRes = Ctx.m_instance.m_texMgr.getAndSyncLoad <TextRes>(path);
            Ctx.m_instance.m_luaScriptMgr.lua.DoString(textRes.text);

            LuaFunction reflf   = Ctx.m_instance.m_luaScriptMgr.lua.GetFunction("regPath");
            string      luaPath = string.Format("{0}/{1}", UtilApi.getDataPath(), "Prefabs/Resources/LuaScript");

            UtilApi.normalPath(ref luaPath);
            object[] ret = reflf.Call(luaPath);

            luaPath = string.Format("{0}/{1}", UtilApi.getDataPath(), "Plugins/x86_64");
            reflf   = Ctx.m_instance.m_luaScriptMgr.lua.GetFunction("regCPath");
            ret     = reflf.Call(luaPath);

            //path = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathLuaScript], "debugger.txt");
            //textRes = Ctx.m_instance.m_textResMgr.getAndSyncLoad<TextRes>(path);
            //ls.DoString(textRes.text);

            path    = string.Format("{0}{1}", Ctx.m_instance.m_cfg.m_pathLst[(int)ResPathType.ePathLuaScript], "TestLua.txt");
            textRes = Ctx.m_instance.m_texMgr.getAndSyncLoad <TextRes>(path);
            Ctx.m_instance.m_luaScriptMgr.lua.DoString(textRes.text);

            LuaFunction lf = Ctx.m_instance.m_luaScriptMgr.lua.GetFunction("luaFunc");

            object[] r   = lf.Call("2");
            string   str = r[0].ToString();

            //LuaTable table = Ctx.m_instance.m_luaScriptMgr.lua.GetTable("mimeself");
            //object _obj = table["encode"];
            //int aaa = 10;
        }
 protected override string GetLocalizedString(string value)
 {
     return(TextRes.GetString(value));
 }
Exemple #10
0
        public IWxRes GetResById(int id)
        {
            IWxRes res = null;
            DataBaseAccess db = this._dao.New();
            db.ExecuteReader("SELECT Id ,ResKey,TypeId,TypeName,CreateTime,UpdateTime FROM wx_res WHERE Id=" + id.ToString(), rd =>
            {
                if (rd.Read())
                {
                    int typeId = rd.GetInt32(2);
                    if (typeId == 1)
                    {
                        res = new TextRes
                        {
                            CreateTime = rd.GetDateTime(4),
                            UpdateTime = rd.GetDateTime(5),
                            TypeId = typeId,
                            TypeName = rd.GetString(3),
                            ResKey = rd.GetString(1),
                            Id = rd.GetInt32(0)
                        };
                    }
                    else
                    {
                        res = new ArticleRes
                        {
                            CreateTime = rd.GetDateTime(4),
                            UpdateTime = rd.GetDateTime(5),
                            TypeId = typeId,
                            ResKey = rd.GetString(1),
                            TypeName = rd.GetString(3),
                            Id = rd.GetInt32(0)
                        };
                    }
                }
            });

            if (res != null)
            {
                TextRes tRes;
                ArticleRes atRes;

                if ((tRes = (res as TextRes)) != null)
                {
                    db.ExecuteReader("SELECT Content FROM wx_text Where resid=" + tRes.Id.ToString(), rd =>
                    {
                        if (rd.Read())
                        {
                            tRes.Content = rd.GetString(0);
                        }
                    });
                }
                else
                {
                    atRes = res as ArticleRes;

                    db.ExecuteReader("SELECT * FROM wx_art_item WHERE resid=" + atRes.Id.ToString() + " ORDER BY sort,id", rd =>
                    {
                        if (rd.HasRows)
                        {
                            atRes.Items = rd.ToEntityList<ArticleResItem>();
                        }

                    });

                    if (atRes.Items != null)
                    {
                        foreach (var articleResItem in atRes.Items)
                        {
                            articleResItem.SetArticle(atRes);
                        }
                    }
                    else
                    {
                        atRes.Items = new List<ArticleResItem>();
                    }
                }
            }

            return res;
        }
Exemple #11
0
        private int SaveTextRes(TextRes textRes)
        {
            DataBaseAccess db = this._dao.New();
            var data = new object[,]
            {
                {"@Id", textRes.Id},
                {"@ResKey", textRes.ResKey},
                {"@CreateTime", textRes.CreateTime},
                {"@UpdateTime", textRes.UpdateTime},
                {"@TypeId", textRes.TypeId},
                {"@TypeName", textRes.TypeName},
                {"@Content", textRes.Content}
            };

            if (textRes.Id > 0)
            {
                db.ExecuteNonQuery(new SqlQuery("UPDATE wx_res SET reskey=@resKey,updatetime=@updatetime WHERE id=@Id", data),
                    new SqlQuery("Update wx_text Set wx_text.content=@Content where resId=@Id", data));
            }
            else
            {
                int row = db.ExecuteNonQuery(new SqlQuery(@"INSERT INTO wx_res (ResKey,TypeId,TypeName,CreateTime,UpdateTime)
                            VALUES (@ResKey,@TypeId,@TypeName,@CreateTime,@UpdateTime)", data));
                if (row == 1)
                {
                    int id = Convert.ToInt32(db.ExecuteScalar("SELECT MAX(id) FROM wx_res"));
                    data[0, 1] = id;
                    db.ExecuteNonQuery(new SqlQuery(@"INSERT INTO wx_text(ResId,Content)VALUES(@Id,@Content)", data));
                    return id;
                }
            }

            return textRes.Id;
        }
Exemple #12
0
        public IWxRes GetResByKey(string resKey)
        {
            IWxRes         res = null;
            DataBaseAccess db  = this._dao.New();

            db.ExecuteReader(new SqlQuery("SELECT Id ,ResKey,TypeId,TypeName,CreateTime,UpdateTime FROM wx_res WHERE ResKey=@ResKey",
                                          new object[, ]
            {
                { "@ResKey", resKey }
            }), rd =>
            {
                if (rd.Read())
                {
                    int typeId = rd.GetInt32(2);
                    if (typeId == 1)
                    {
                        res = new TextRes
                        {
                            CreateTime = rd.GetDateTime(4),
                            UpdateTime = rd.GetDateTime(5),
                            TypeId     = typeId,
                            TypeName   = rd.GetString(3),
                            ResKey     = rd.GetString(1),
                            Id         = rd.GetInt32(0)
                        };
                    }
                    else
                    {
                        res = new ArticleRes
                        {
                            CreateTime = rd.GetDateTime(4),
                            UpdateTime = rd.GetDateTime(5),
                            TypeId     = typeId,
                            ResKey     = rd.GetString(1),
                            TypeName   = rd.GetString(3),
                            Id         = rd.GetInt32(0)
                        };
                    }
                }
            });

            if (res != null)
            {
                TextRes    tRes;
                ArticleRes atRes;

                if ((tRes = (res as TextRes)) != null)
                {
                    db.ExecuteReader("SELECT Content FROM wx_text Where resid=" + tRes.Id.ToString(), rd =>
                    {
                        if (rd.Read())
                        {
                            tRes.Content = rd.GetString(0);
                        }
                    });
                }
                else
                {
                    atRes = res as ArticleRes;

                    db.ExecuteReader("SELECT * FROM wx_art_item WHERE resid=" + atRes.Id.ToString() + " ORDER BY sort,id", rd =>
                    {
                        if (rd.HasRows)
                        {
                            atRes.Items = rd.ToEntityList <ArticleResItem>();
                        }
                    });

                    if (atRes.Items != null)
                    {
                        foreach (var articleResItem in atRes.Items)
                        {
                            articleResItem.SetArticle(atRes);
                        }
                    }
                    else
                    {
                        atRes.Items = new List <ArticleResItem>();
                    }
                }
            }

            return(res);
        }