Пример #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);
        }
Пример #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);
        }
Пример #3
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);
        }
Пример #4
0
        private static void SetCacheKey(string table, string field, string key)
        {
            var tableKeys = GetTableKeys(table);
            var fieldKeys = GetFieldKeys(tableKeys, field);

            tableKeys[field] = ZConvert.ToString(MaxOfAllKey(fieldKeys, key));
            ZCache.SetCache(String.Format("currentkey_{0}", table), tableKeys);
        }
Пример #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));
        }
Пример #6
0
        public ActionResult Index()
        {
            ViewBag.CnName = "STD MiniMES系统";
            ViewBag.EnName = "STD MiniMES System";

            var Token = Request["Token"];

            if (!string.IsNullOrEmpty(Token))
            {
                string APIGatewayUrl = ZConfig.GetConfigString("APIGatewayUrl");
                var    data          = new
                {
                    AppCode = "EPS",
                    ApiCode = "PostValidateToken",
                    Token   = Token
                };

                var result = HttpHelper.PostWebApi(APIGatewayUrl, JsonConvert.SerializeObject(data), 18000);
                if (result != null)
                {
                    if (result.status == true)
                    {
                        var UserInfo = result.UserInfo;

                        //调用框架中的登录机制
                        var loginer = new LoginerBase
                        {
                            UserId   = UserInfo.UserId,
                            UserType = "2",
                            TenantId = UserInfo.TenantId,
                            UserCode = UserInfo.UserCode,
                            UserName = UserInfo.UserName,
                            ShiftId  = UserInfo.ShiftId
                        };

                        var effectiveHours = ZConfig.GetConfigInt("LoginEffectiveHours");
                        FormsAuth.SignIn(loginer.UserCode, loginer, 60 * effectiveHours);

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

                        return(Redirect("Home"));
                    }
                }

                //return View("授权Token验证失败!单击<a href='" + ZConfig.GetConfigString("GatewayServer") + "'>这里</a>返回登录页面。");
                return(Redirect(ZConfig.GetConfigString("GatewayServer") + "/Login"));
            }
            else
            {
                //return View("授权参数错误!单击<a href='" + ZConfig.GetConfigString("GatewayServer") + "'>这里</a>返回登录页面。");
                //return View();
                return(Redirect(ZConfig.GetConfigString("GatewayServer") + "/Login"));
            }
        }