Ejemplo n.º 1
0
        /// <summary>
        /// 通用单表型数据grid格式化 带缓存
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="IdField"></param>
        /// <param name="TextField"></param>
        /// <param name="ComboboxValue"></param>
        /// <param name="connName"></param>
        /// <returns></returns>
        public string GetComboboxFormatter_Single(string TableName = "", string IdField = "", string TextField = "", string ComboboxValue = "", string connName = "Mms")
        {
            var    result   = "";
            string cacheKey = TableName + "_" + IdField + "_" + TextField + "_" + connName;
            var    cache    = ZCache.GetCache(cacheKey);//获取缓存DataTable

            if (cache == null)
            {
                List <dynamic> SysCodelist = new List <dynamic>();
                using (var db = Db.Context(connName))
                {
                    SysCodelist = db.Sql(string.Format("select {0} as value,{1} as text from {2}", IdField, TextField, TableName)).QueryMany <dynamic>();
                }
                ZCache.SetCache(cacheKey, SysCodelist, DateTime.Now.AddMinutes(5), TimeSpan.Zero);//设置缓存DataTable
                cache = ZCache.GetCache(cacheKey);
            }
            var cacheList = (List <dynamic>)cache;

            if (cacheList.Count > 0)
            {
                if (cacheList.Where(c => c.value == ComboboxValue).ToList().Count > 0)
                {
                    result = cacheList.Where(c => c.value == ComboboxValue).ToList().First().text;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 通用字典型数据grid格式化 带缓存
        /// </summary>
        /// <param name="CodeType"></param>
        /// <param name="ComboboxValue"></param>
        /// <returns></returns>
        public string GetComboboxFormatter(string CodeType = "", string ComboboxValue = "")
        {
            string result   = "";
            string cacheKey = "dictionary_" + CodeType;
            var    cache    = ZCache.GetCache(cacheKey);//获取缓存DataTable

            if (cache == null)
            {
                List <dynamic> SysCodelist = new List <dynamic>();
                using (var db = Db.Context("Sys"))
                {
                    SysCodelist = db.Sql(string.Format("select Value as value,Text as text from sys_code where CodeType in('{0}')", CodeType)).QueryMany <dynamic>();
                }
                ZCache.SetCache(cacheKey, SysCodelist, DateTime.Now.AddMinutes(5), TimeSpan.Zero);//设置缓存DataTable
                cache = ZCache.GetCache(cacheKey);
            }
            var cacheList = (List <dynamic>)cache;

            if (cacheList.Count() > 0)
            {
                if (cacheList.Where(c => c.value == ComboboxValue).ToList().Count > 0)
                {
                    result = cacheList.Where(c => c.value == ComboboxValue).ToList().First().text;
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        private static Dictionary <string, string> GetTableKeys(string table)
        {
            var tableKeys = ZCache.GetCache(String.Format("currentkey_{0}", table)) as Dictionary <string, string> ??
                            new Dictionary <string, string>();

            return(tableKeys);
        }
Ejemplo n.º 4
0
        // GET api/menu
        public IEnumerable <dynamic> Get()
        {
            var UserCode = SysHelper.GetUserCode();
            var TenantId = SysHelper.GetTenantId();

            dynamic result = ZCache.GetCache("MenuData");

            if (result == null && !string.IsNullOrEmpty(UserCode) && !string.IsNullOrEmpty(TenantId))
            {
                var postdata = new
                {
                    AppCode        = "EPS",
                    ApiCode        = "GetUserMenuData",
                    TenantId       = TenantId,
                    UserCode       = UserCode,
                    RequestAppCode = "MiniMES"
                };

                result = HttpHelper.PostWebApi(ZConfig.GetConfigString("APIGatewayUrl"), JsonConvert.SerializeObject(postdata), 18000);

                ZCache.SetCache("MenuData", result);
            }

            return(result);
        }
Ejemplo n.º 5
0
        public JsonResult GetCommonSearchList_Cache(string keyword = "", string tableName = "", string searchField = "", string firstFightField = "", string whereSql = "", string CacheKey = "", int CacheTime = 5, string connName = "Mms")
        {
            //ZCache.RemoveCache(CacheKey);
            var       cache          = ZCache.GetCache(CacheKey);//获取缓存DataTable
            DataTable CacheDataTable = new DataTable();

            if (cache == null)
            {
                DataTable SearchDT = GetComboGridList(tableName, searchField, firstFightField, whereSql, connName);
                ZCache.SetCache(CacheKey, SearchDT, DateTime.Now.AddMinutes(CacheTime), TimeSpan.Zero);//设置缓存DataTable
                CacheDataTable = SearchDT;
            }
            else
            {
                CacheDataTable = (DataTable)cache;
            }

            string SearchSelect = "1=1";

            if (searchField != "" && keyword != "") //如果查询字段不为空 并且 关键字keyword查询不为空 则模糊查询
            {
                SearchSelect = "";
                foreach (var item in searchField.Split(',')) //查询字段的拼接
                {
                    SearchSelect += string.Format(" {0} like '%{1}%' or", item, keyword);
                }
                if (firstFightField != "") //首拼字段的拼接
                {
                    for (int i = 0; i < firstFightField.Split(',').Length; i++)
                    {
                        SearchSelect += string.Format(" {0} like '%{1}%' or", "firstFight_" + i.ToString(), keyword);
                    }
                }
                SearchSelect = SearchSelect.Substring(0, SearchSelect.Length - 2);
            }

            DataTable SearchCacheDataRows = new DataTable();

            if (CacheDataTable.Select(SearchSelect).Count() > 0)
            {
                SearchCacheDataRows = CacheDataTable.Select(SearchSelect).Take(50).CopyToDataTable();
            }

            List <Dictionary <string, string> > combogridList = new List <Dictionary <string, string> >();

            foreach (DataRow dr in SearchCacheDataRows.Rows)
            {
                Dictionary <string, string> dct = new Dictionary <string, string>();
                foreach (DataColumn dc in SearchCacheDataRows.Columns)
                {
                    dct.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                }
                combogridList.Add(dct);
            }
            return(Json(new { total = combogridList.Count(), rows = combogridList }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        private static Dictionary <string, string> getTableKeys(string table)
        {
            var tableKeys = ZCache.GetCache(String.Format("currentkey_{0}", table)) as Dictionary <string, string>;

            if (null == tableKeys)
            {
                tableKeys = new Dictionary <string, string>();
            }

            return(tableKeys);
        }