コード例 #1
0
ファイル: Form1.cs プロジェクト: chenboyi081/CsharpTest
        private void button1_Click(object sender, EventArgs e)
        {
            IntList intlist = new IntList();

            intlist.Add(1);
            intlist.Add(2);
            intlist.Add(3);

            MessageBox.Show(intlist[0].ToString());

            泛型.StringList slist = new StringList();
            slist.Add("100");


            MyList <int> glist = new MyList <int>();

            glist.Add(200);
            MessageBox.Show(glist.ToString());

            MyList <string> glist1 = new MyList <string>();

            glist1.Add("200");
            MessageBox.Show(glist1.ToString());

            //缓存泛型方法的调用演示
            Pig pig = CacheMgr.GetData <Pig>("pigkey");
        }
コード例 #2
0
        /// <summary>
        /// 统一验证Session[Keys.uinfo]如果为null则跳转到登陆页
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //0.0判断是否有贴跳过登录检查的特性标签
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }

            //1.0 判断session是否为null
            if (filterContext.HttpContext.Session[Keys.uinfo] == null)
            {
                //1.0.1 查询cookie[Keys.Ismemeber]是否不为null,如果成立则模拟用户的登录,再将用户实体数据存入session[Keys.uinfo]中
                if (filterContext.HttpContext.Request.Cookies[Keys.IsMember] != null)
                {
                    //1.0 取出cookie中存入的uid的值
                    string uid = filterContext.HttpContext.Request.Cookies[Keys.IsMember].Value;
                    uid = DESEncrypt.Decrypt(uid);

                    //2.0 根据uid查询出用户的实体

                    //2.0.1 从缓存中获取autofac的容器对象
                    var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer);
                    //2.0.2 找autofac容器获取IsysUserInfoServices接口的具体实现类的对象实例
                    IsysUserInfoServices userSer = cont.Resolve <IsysUserInfoServices>();

                    //2.0.3 根据userSer 集合uid查询数据
                    int iuserid  = int.Parse(uid);
                    var userinfo = userSer.QueryWhere(c => c.uID == iuserid).FirstOrDefault();
                    if (userinfo != null)
                    {
                        //2.0.4 将userinfo存入session
                        filterContext.HttpContext.Session[Keys.uinfo] = userinfo;
                    }
                    else
                    {
                        ToLogin(filterContext);
                    }
                }
                else
                {
                    //2.0 跳转到登录页面
                    // filterContext.HttpContext.Response.Redirect("/admin/login/login");

                    //ContentResult cr = new ContentResult();
                    //cr.Content = "<script>alert('您未登录');window.location='/admin/login/login';</script>";

                    ToLogin(filterContext);
                }
            }

            base.OnActionExecuting(filterContext);
        }
コード例 #3
0
        public IHttpActionResult Test(string Token)
        {
            var          c      = Token;
            var          d      = CacheMgr.GetData <DoctorInfor>(c);
            var          item   = doctorInforService.GetDoctorInfor("1");
            SimpleResult result = new SimpleResult();

            result.Resource = item;
            return(Json(result));
        }
コード例 #4
0
        /// <summary>
        /// 负责验证Session[Keys.Uinfo]是否为null,如果为null则直接跳转到登录页面
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            //0.0 判断控制器类或者action是否有贴SkipCheckLogin标签,如果有贴则阻断下面代码的运行
            if (filterContext.ControllerContext.ControllerDescriptor.GetCustomAttributes <SkipCheckLoginAttribute>().Count == 1)
            {
                return;
            }

            if (filterContext.ActionDescriptor.GetCustomAttributes <SkipCheckLoginAttribute>().Count == 1)
            {
                return;
            }

            //1.0 判断session如果为空则跳转
            if (HttpContext.Current.Session[Keys.Uinfo] == null)
            {
                //1.0 第一种提醒方式,体验不好,因为会导致页面泛白
                //filterContext.HttpContext.Response.Write("<script>alert('您未登录');window.location='/admin/login/login'</script>");

                //2.0 判断如果cookie中的数据不为空,则应该取出其中的用户主键去sysuserinfo表中再次获取实体
                //存入session
                if (HttpContext.Current.Request.Cookies[Keys.IsRemember] != null)
                {
                    //2.0.1 获取用户主键
                    string userid = HttpContext.Current.Request.Cookies[Keys.IsRemember].Value;

                    //2.0.2 根据userid去访问sysuserinfo获取数据实体
                    //2.0.2.1 从全局缓存中获取autofac的容器对象
                    IContainer autofac = CacheMgr.GetData <IContainer>(Keys.autofaccontainer);
                    //2.0.2.2 从autofac容器中获取IsysUserInfoServices的实现类的对象实例
                    IsysUserInfoServices userSer = autofac.Resolve <IsysUserInfoServices>();

                    int uid = int.Parse(userid);

                    var userinfo = userSer.QueryWhere(c => c.uID == uid).FirstOrDefault();

                    //3.0 判断userinfo是否为null
                    if (userinfo == null)
                    {
                        ToLogin(filterContext);
                    }
                    else
                    {
                        //4.0 将userinfo实体对象存入session
                        filterContext.HttpContext.Session[Keys.Uinfo] = userinfo;
                    }
                }
                else
                {
                    //统一跳转
                    ToLogin(filterContext);
                }
            }
        }
コード例 #5
0
ファイル: CheckLoginAttribute.cs プロジェクト: hyunbar777/CRM
        /// <summary>
        /// 统一验证session【keys.uinfo】如果是null跳转到登录页
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //判断是否有贴跳过登录检查的特性标签
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }
            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }
            if (filterContext.HttpContext.Session[Keys.uinfo] == null)
            {
                //1.0查询cookie【keys.Ismember]是否为空,如果成立则模拟用户的登录,
                //在将用户实体数据存入session[keys.uinfo】中

                if (filterContext.HttpContext.Request.Cookies[Keys.IsMember] != null)
                {
                    //1.0取出cookie中存入的uid的值
                    string uid = filterContext.HttpContext.Request.Cookies[Keys.IsMember].Value;

                    //2.0根据uid查询出实体
                    //2.00先从缓存中获取autofac的容器对象
                    var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer);
                    //2.01找autofac容器获取IsysUserInfoServices
                    IsysUserInfoServices userSer = cont.Resolve <IsysUserInfoServices>();
                    //2.03根据userser集合uid查询数据
                    int iuserid  = int.Parse(uid);
                    var userinfo = userSer.QueryWhere(c => c.uID == iuserid).FirstOrDefault();
                    if (userinfo != null)
                    {
                        filterContext.HttpContext.Session[Keys.uinfo] = userinfo;
                    }
                    else
                    {
                        ToLogin(filterContext);
                    }
                }

                ////法一:
                // filterContext.HttpContext.Response.Redirect("/Admin/Login/Login");
                //法二:
                //ContentResult cr = new ContentResult();
                //cr.Content = "<script>alert('您未登录');window.location='/Admin/Login/Login'</script>";
                //filterContext.Result = cr;
                else
                {
                    ToLogin(filterContext);
                }
            }
            base.OnActionExecuting(filterContext);
        }
コード例 #6
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //0.0判断是否有贴跳过权限检查的特性标签
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckPermiss), false))
            {
                return;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckPermiss), false))
            {
                return;
            }

            //1.0 获取当前触发此OnActionExecuting的aciton
            string actionName = filterContext.ActionDescriptor.ActionName.ToLower();

            //2.0 控制名称
            string controlerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();

            //3.0 获取区域的名称
            string areaName = string.Empty;

            if (filterContext.RouteData.DataTokens.ContainsKey("area"))
            {
                areaName = filterContext.RouteData.DataTokens["area"].ToString().ToLower();
            }

            //4.0 根据上面的三个成员的值作为条件去当前用户的权限按钮缓存数据查找,如果没有找到则表示没有权限
            //2.0.1 从缓存中获取autofac的容器对象
            var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer);
            IsysPermissListServices iperSer = cont.Resolve <IsysPermissListServices>();
            var list = iperSer.GetFunctionsForUserByCache(UserMgr.GetCurrentUserInfo().uID);

            var isOK = list.Any(c => c.mArea.ToLower() == areaName &&
                                c.mController.ToLower() == controlerName &&
                                c.fFunction.ToLower() == actionName);

            if (isOK == false)
            {
                isOK = list.Any(c => c.mArea.ToLower() == areaName &&
                                c.mController.ToLower() == controlerName &&
                                c.mAction.ToLower() == actionName);
            }

            if (isOK == false)//无权限
            {
                ToLogin(filterContext);
            }
        }
コード例 #7
0
        public static sysUserInfo GetUserByID(object userid)
        {
            if (userid == null)
            {
                return(new sysUserInfo()
                {
                });
            }
            int iuser = int.Parse(userid.ToString());

            var autofac = CacheMgr.GetData <IContainer>(Keys.AutofacContainer);
            IsysUserInfoServices userSer = autofac.Resolve <IsysUserInfoServices>();

            return(userSer.QueryWhere(c => c.uID == iuser).FirstOrDefault());
        }
コード例 #8
0
 public static sysUserInfo GetCurrentUserInfo()
 {
     if (HttpContext.Current.Request.Cookies[Keys.uinfo] != null)
     {
         string sessionId = HttpContext.Current.Request.Cookies[Keys.uinfo].Value;
         //从缓存中获取autofac的容器对象
         var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer);
         //获取到依赖注入数据
         ICacheManager cacheManager = cont.Resolve <ICacheManager>();
         return(cacheManager.Get <sysUserInfo>(sessionId));
     }
     return(new sysUserInfo()
     {
     });
 }
コード例 #9
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //1.0 判断如果贴有    [SkipCheckLogin]则跳过登录检查
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false))
            {
                return;
            }

            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false))
            {
                return;
            }

            if (filterContext.HttpContext.Session[Keys.uinfo] == null)
            {
                //1.0 判断cookie是否有值
                if (filterContext.HttpContext.Request.Cookies[Keys.isremember] == null)
                {
                    //2.0 跳转到登录页面
                    ToLogin(filterContext);
                }
                else
                {
                    //3.0 获取cookie中存好的用户id
                    string uid = filterContext.HttpContext.Request.Cookies[Keys.isremember].Value;

                    //4.0 存全局缓存中获取autofac容器对象
                    var container = CacheMgr.GetData <IContainer>(Keys.autofac);

                    //4.0 根据uid去表sysuserinfo中查询用户对象重新赋值给Session[Keys.uinfo]
                    //IsysUserInfoServices userServics = container.Resolve<IsysUserInfoServices>();
                    //int iuserid = uid.AsInt();
                    //var userinfo = userServics.QueryWhere(c => c.uID == iuserid).FirstOrDefault();
                    //if (userinfo == null)
                    //{
                    //    ToLogin(filterContext);
                    //}
                    //else
                    //{
                    //    filterContext.HttpContext.Session[Keys.uinfo] = userinfo;

                    //    //设置缓存
                    //    container.Resolve<IsysPermissListServices>().GetPermissListByUid(userinfo.uID);
                    //}
                }
            }
        }
コード例 #10
0
        //  #region   针对 此表的 特殊操作 写在此处

        //    /// <summary>
        //    /// 负责用户权限按钮进行数据缓存操作,以及以后直接从缓存中使用
        //    /// </summary>
        //    /// <param name="userid"></param>
        //    /// <returns></returns>
        //            public List<CRM.Model.Usp_GetFunctionsForUser15_Result> GetFuctionsForUserByCache(int userid)
        //            {
        //                //注意: 缓存中的key 一定是每个用户有一个,彼此不重复
        //                string cachekey = Keys.PermissFuctionsForUser + userid;
        //               //1.0 从缓存中 根据户用获取其权限数据
        //                object data = CacheMgr.GetData<List<CRM.Model.Usp_GetFunctionsForUser15_Result>>(cachekey);
        //                if (data == null)
        //                {
        //                    //从数据库获取一份权限按钮数据
        //                    var prmisslist = baseDal.RunProc<CRM.Model.Usp_GetFunctionsForUser15_Result> ("Usp_GetFunctionsForUser15" , userid);
        //                    // 将数据加入缓存
        //                    CacheMgr.SetData(cachekey, prmisslist);
        //                    return prmisslist;
        //                }

        //                return data as List<CRM.Model.Usp_GetFunctionsForUser15_Result>;
        //            }
        // #endregion

        #region 针对此表的特殊操作写在此处

        /// <summary>
        /// 负责将用户权限按钮数据进行缓存操作,以及以后直接从缓存中获取
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public List <Usp_GetFunctionsForUser15_Result> GetFuctionsForUserByCache(int userid)
        {
            //注意:缓存key一定是每个用户有一个,彼此不重复
            string cacheKey = Keys.PermissFuctionsForUser + userid;

            //1.0 从缓存中根据用户获取其权限按钮数据
            object data = CacheMgr.GetData <List <Usp_GetFunctionsForUser15_Result> >(cacheKey);

            if (data == null)
            {
                //从数据库获取一份权限按钮数据
                var prmisslist = baseDal.RunProc <Usp_GetFunctionsForUser15_Result>("Usp_GetFunctionsForUser15  " + userid);
                //将数据加入缓存
                CacheMgr.SetData(cacheKey, prmisslist);

                return(prmisslist);
            }

            return(data as List <Usp_GetFunctionsForUser15_Result>);
        }
コード例 #11
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //0.0   //判断action方法所在的控制器是否有贴
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckPermissAttribute), false))
            {
                return;
            }

            //判断action方法是否有贴
            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckPermissAttribute), false))
            {
                return;
            }

            //1.0 获取action名称
            string actionName = filterContext.ActionDescriptor.ActionName.ToLower();

            //2.0 获取控制器名称
            string ctrlName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();

            //3.0 获取区域名称
            string areaName = string.Empty;

            if (filterContext.RouteData.DataTokens.ContainsKey("area"))
            {
                areaName = filterContext.RouteData.DataTokens["area"].ToString().ToLower();
            }

            //4.0 根据上述三个条件去用户权限数据缓存中查询
            //4.0.1 获取缓存数据
            var container = CacheMgr.GetData <IContainer>(Keys.autofac);

            //var permissList = container.Resolve<IServices.IsysPermissListServices>().GetPermissListByUid(UserMgr.GetUserInfo().uID);

            //4.0.2 去permissList中查询一下当前请求的action方法是否存在
            ////bool isOk = permissList.Any(c => c.mArea.ToLower() == areaName
            //    && c.mController.ToLower() == ctrlName
            //    && c.fFunction.ToLower() == actionName);

            //如果没有权限
            if (!true)
            {
                //5.0 判断是否为ajax请求
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    JsonResult json = new JsonResult();
                    json.Data = new { status = 2, msg = "没有权限" };
                    json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

                    filterContext.Result = json;
                }
                else
                {
                    //浏览器请求
                    ViewResult view = new ViewResult();
                    view.ViewName = "/Views/Shared/NoPermiss.cshtml";

                    filterContext.Result = view;
                }
            }
        }
コード例 #12
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpContext context = HttpContext.Current;
            //从缓存中获取autofac的容器对象
            var cont = CacheMgr.GetData <IContainer>(Keys.AutofacContainer);
            //获取到依赖注入数据
            ICacheManager cacheManager = cont.Resolve <ICacheManager>();

            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }
            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLogin), false))
            {
                return;
            }
            //判断session是否为null
            if (filterContext.HttpContext.Request.Cookies[Keys.uinfo] == null)
            {
                if (filterContext.HttpContext.Request.Cookies[Keys.IsMember] != null)
                {
                    //取出cookie中存入的uid的值
                    string uid = filterContext.HttpContext.Request.Cookies[Keys.IsMember].Value;

                    //获取到依赖注入数据
                    IsysUserInfoServices userSer = cont.Resolve <IsysUserInfoServices>();

                    int iuserid  = int.Parse(uid);
                    var userinfo = userSer.QueryWhere(c => c.uID == iuserid).FirstOrDefault();
                    if (userinfo != null)
                    {
                        //将userinfo存入session
                        //filterContext.HttpContext.Session[Keys.uinfo] = userinfo;

                        //改用redis存储用户信息

                        //改用redis缓存
                        string sessionId = Guid.NewGuid().ToString("N");//必须保证Memcache的key唯一
                        cacheManager.Set(sessionId, userinfo, TimeSpan.FromHours(1));
                        //filterContext.HttpContext.Request.Cookies[Keys.uinfo].Value = sessionId;
                        context.Response.Cookies[Keys.uinfo].Value = sessionId;//将自创的用户信息以Cookie的形式返回给浏览器。
                        BaseController.LoginUser = userinfo;
                    }
                    else
                    {
                        ToLogin(filterContext);
                    }
                }
                else
                {
                    ToLogin(filterContext);
                }
            }
            else
            {
                string      sessionId = filterContext.HttpContext.Request.Cookies[Keys.uinfo].Value;
                sysUserInfo obj       = cacheManager.Get <sysUserInfo>(sessionId);//获取Memcache中的数据.
                if (obj != null)
                {
                    BaseController.LoginUser = obj;
                    //模拟滑动过期时间。
                    cacheManager.Set(sessionId, obj, TimeSpan.FromHours(1));
                }
                else
                {
                    ToLogin(filterContext);
                }
            }
        }
コード例 #13
0
        public object SysEnergyAnalsys(DateTime currtime, DateTime begtime)
        {
            //找到每个空压站的最大和最小流量
            var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime).GroupBy(g => g.StationID).Select(s => new
            {
                Maxvalue = s.Max(i => i.Main_Q),
                Minvalue = s.Min(i => i.Main_Q),
                sta      = s.Key
            }).ToList();
            //获取缓存对象,任何阈值设定界面值的修改,都要缓存当前
            List <BB_Threshold> cacheThre = CacheMgr.GetData <List <BB_Threshold> >("threshold");

            //判断是否有缓存存在,不存在重新设置
            if (cacheThre == null)
            {
                List <BB_Threshold> threshold = thresholdal.QueryWhere().ToList();
                CacheMgr.SetData("threshold", threshold);
                cacheThre = threshold;
            }
            //目标压力
            decimal setPress = (decimal)cacheThre.Where(x => x.Name.Equals("管网压力设定")).FirstOrDefault().CurrentValue;
            //设定间隔
            decimal intval = (decimal)cacheThre.Where(x => x.Name.Equals("管网压力设定间隔")).FirstOrDefault().CurrentValue;
            List <List <decimal> > dvalue    = new List <List <decimal> >();
            List <List <decimal> > setdvalue = new List <List <decimal> >();

            foreach (var item in res)
            {
                decimal max  = (decimal)item.Maxvalue / 15000;
                int     imax = (int)max + 1; //最大开机数
                decimal min  = (decimal)item.Minvalue / 15000;
                int     imin = (int)min;     //最小开机数
                if (item.sta == "S004")
                {
                    if (imax > 7)
                    {
                        imax = 7;
                    }
                }
                else
                {
                    if (imax > 6)
                    {
                        imax = 6;
                    }
                }
                int            n          = imax - imin;           //开机数差
                List <decimal> press      = new List <decimal>();  //压力设定集合
                List <decimal> value      = new List <decimal>();  //空压机集合
                decimal        countvalue = setPress + intval * n; //基础压力设定值
                #region 空压机填充
                for (int i = 0; i < imin; i++)
                {
                    value.Add(countvalue);
                    value.Add(0);
                    value.Add(0);
                    value.Add(0);
                }
                for (int i = 0; i < n; i++)
                {
                    if (i == 0)
                    {
                        value.Add(0);
                        value.Add(countvalue - intval * (i + 1));
                        value.Add(0);
                        value.Add(0);
                    }
                    else if (i == 1)
                    {
                        value.Add(0);
                        value.Add(0);
                        value.Add(countvalue - intval * (i + 1));
                        value.Add(0);
                    }
                    else
                    {
                        for (int j = 0; j < n - 2; j++)
                        {
                            value.Add(0);
                            value.Add(0);
                            value.Add(0);
                            value.Add(countvalue - intval * (i + 1));
                        }
                    }
                }
                #endregion
                press.Add(countvalue);
                //压力设定填充
                for (int i = 0; i < n; i++)
                {
                    press.Add((countvalue - intval * (i + 1)));
                }
                if (press.Count() < 4)
                {
                    press.Add(0);
                }
                setdvalue.Add(press);
                if (item.sta == "S004")
                {
                    if (value.Count() < 28)
                    {
                        int     vcount = value.Count();
                        decimal one    = value[vcount - 4];
                        decimal two    = value[vcount - 3];
                        decimal three  = value[vcount - 2];
                        decimal four   = value[vcount - 1];
                        for (int i = 0; i < (28 - vcount) / 4; i++)
                        {
                            value.Add(one);
                            value.Add(two);
                            value.Add(three);
                            value.Add(four);
                        }
                    }
                }
                else
                {
                    if (value.Count() < 24)
                    {
                        int     vcount = value.Count();
                        decimal one    = value[vcount - 4];
                        decimal two    = value[vcount - 3];
                        decimal three  = value[vcount - 2];
                        decimal four   = value[vcount - 1];
                        for (int i = 0; i < (24 - vcount) / 4; i++)
                        {
                            value.Add(one);
                            value.Add(two);
                            value.Add(three);
                            value.Add(four);
                        }
                    }
                }
                dvalue.Add(value);
            }
            var tranres = new
            {
                disarr = setdvalue,
                arr    = dvalue
            };
            return(tranres);
        }