Exemplo n.º 1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
                {
                    MethodReturnResult <User> result = await client.AuthenticateAsync(model.UserName, model.Password);

                    if (result.Code == 0 && result.Data != null)
                    {
                        result.Data.LastLoginTime = DateTime.Now;
                        result.Data.LastLoginIP   = HttpContext.Request.UserHostAddress;
                        using (UserServiceClient usclient = new UserServiceClient())
                        {
                            MethodReturnResult rstl = await usclient.ModifyAsync(result.Data);

                            if (rstl.Code > 0)
                            {
                                AddErrors(result);
                            }
                        }

                        SignIn(result.Data, model.RememberMe);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }
Exemplo n.º 2
0
        public IList <Resource> GetMenuResource(string loginName)
        {
            string cacheName = loginName + "_Menu";

            IList <Resource> lstMenu = HttpContext.Current.Cache[cacheName] as IList <Resource>;

            if (lstMenu == null)
            {
                using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
                {
                    MethodReturnResult <IList <Resource> > result = client.GetResourceList(loginName, ResourceType.Menu);
                    if (result.Code == 0)
                    {
                        TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);
                        HttpContext.Current.Cache.Add(cacheName
                                                      , result.Data
                                                      , new System.Web.Caching.CacheDependency(null, new string[] { HttpContext.Current.User.Identity.Name })
                                                      , System.Web.Caching.Cache.NoAbsoluteExpiration
                                                      , SessTimeOut
                                                      , System.Web.Caching.CacheItemPriority.Default
                                                      , null);
                        return(result.Data);
                    }
                }
            }
            return(lstMenu);
        }
Exemplo n.º 3
0
        public MethodReturnResult GetLot(string lotNumber)
        {
            MethodReturnResult       result = new MethodReturnResult();
            MethodReturnResult <Lot> rst    = null;
            Lot obj = null;

            using (LotQueryServiceClient client = new LotQueryServiceClient())
            {
                rst = client.Get(lotNumber);
                if (rst.Code <= 0 && rst.Data != null)
                {
                    obj = rst.Data;
                }
                else
                {
                    result.Code    = rst.Code;
                    result.Message = rst.Message;
                    result.Detail  = rst.Detail;
                    return(result);
                }
            }
            if (obj == null || obj.Status == EnumObjectStatus.Disabled)
            {
                result.Code    = 2001;
                result.Message = string.Format(WIPResources.StringResource.LotIsNotExists, lotNumber);
                return(result);
            }

            //判断用户生产线权限
            if (!string.IsNullOrEmpty(obj.PreLineCode))
            {
                IList <Resource> lstResource = new List <Resource>();
                using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
                {
                    MethodReturnResult <IList <Resource> > rst1 = client.GetResourceList(User.Identity.Name, ResourceType.ProductionLine);
                    if (rst1.Code <= 0 && rst1.Data != null)
                    {
                        lstResource = rst1.Data;
                    }
                    else
                    {
                        result.Code    = rst1.Code;
                        result.Message = rst1.Message;
                        result.Detail  = rst1.Detail;
                        return(result);
                    }
                }
                var lnq = from item in lstResource
                          where item.Data == obj.PreLineCode
                          select item;
                if (lnq.Count() == 0)
                {
                    result.Code    = 1;
                    result.Message = string.Format("用户({0})权限不足,对生产线({1})的操作不能撤销。", User.Identity.Name, obj.PreLineCode);
                    return(result);
                }
            }
            return(rst);
        }
Exemplo n.º 4
0
        public IEnumerable <SelectListItem> GetRouteOperationList()
        {
            //获取用户拥有权限的工序。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.RouteOperation);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }

            IList <string> lstPackageOperation = new List <string>();
            PagingConfig   cfg = new PagingConfig()
            {
                IsPaging = false,
                Where    = "Key.AttributeName='IsPackageOperation'"
            };

            using (RouteOperationAttributeServiceClient client = new RouteOperationAttributeServiceClient())
            {
                MethodReturnResult <IList <RouteOperationAttribute> > result = client.Get(ref cfg);

                if (result.Code <= 0 && result.Data != null)
                {
                    bool isPackageOperation = false;
                    lstPackageOperation = (from item in result.Data
                                           where bool.TryParse(item.Value, out isPackageOperation) == true &&
                                           isPackageOperation == true
                                           select item.Key.RouteOperationName).ToList();
                }
            }

            IList <RouteOperation> lst = new List <RouteOperation>();

            cfg.Where   = "Status=1";
            cfg.OrderBy = "SortSeq";

            using (RouteOperationServiceClient client = new RouteOperationServiceClient())
            {
                MethodReturnResult <IList <RouteOperation> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null)
                {
                    lst = result.Data;
                }
            }


            return(from item in lst
                   where lstPackageOperation.Contains(item.Key.ToUpper()) == false &&
                   lstResource.Any(m => m.Data.ToUpper() == item.Key.ToUpper())
                   select new SelectListItem()
            {
                Text = item.Key,
                Value = item.Key
            });
        }
Exemplo n.º 5
0
        public MethodReturnResult GetLotTransaction(string key)
        {
            MethodReturnResult result = new MethodReturnResult();

            LotTransaction obj = null;

            using (LotQueryServiceClient client = new LotQueryServiceClient())
            {
                MethodReturnResult <LotTransaction> rst = client.GetTransaction(key);
                if (rst.Code <= 0 && rst.Data != null)
                {
                    obj = rst.Data;
                }
                else
                {
                    result.Code    = rst.Code;
                    result.Message = rst.Message;
                    result.Detail  = rst.Detail;
                    return(result);
                }
            }
            if (obj == null)
            {
                result.Code    = 2001;
                result.Message = "被撤销操作不存在。";
                return(result);
            }
            //判断用户拥有的工序权限
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > rst = client.GetResourceList(User.Identity.Name, ResourceType.RouteOperation);
                if (rst.Code <= 0 && rst.Data != null)
                {
                    lstResource = rst.Data;
                }
                else
                {
                    result.Code    = rst.Code;
                    result.Message = rst.Message;
                    result.Detail  = rst.Detail;
                    return(result);
                }
            }
            var lnq = from item in lstResource
                      where item.Data == obj.RouteStepName
                      select item;

            if (lnq.Count() == 0)
            {
                result.Code    = 1;
                result.Message = string.Format("用户({0})权限不足,对工序({1})的操作不能撤销。", User.Identity.Name, obj.RouteStepName);
                return(result);
            }
            return(result);
        }
Exemplo n.º 6
0
        public ActionResult GetLineStoreNames(string orderNumber)
        {
            string locationName = string.Empty;

            using (WorkOrderServiceClient client = new WorkOrderServiceClient())
            {
                MethodReturnResult <WorkOrder> result = client.Get(orderNumber);
                if (result.Code <= 0 && result.Data != null)
                {
                    locationName = result.Data.LocationName;
                }
            }

            IList <LineStore> lstLineStore = new List <LineStore>();

            using (LineStoreServiceClient client = new LineStoreServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    IsPaging = false,
                    Where    = string.Format("LocationName='{0}' AND Type='{1}' AND Status='{2}'"
                                             , locationName
                                             , Convert.ToInt32(EnumLineStoreType.Material)
                                             , Convert.ToInt32(EnumObjectStatus.Available))
                };

                MethodReturnResult <IList <LineStore> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstLineStore = result.Data;
                }
            }

            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(User.Identity.Name, ResourceType.LineStore);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }

            var lnq = from item in lstLineStore
                      where lstResource.Any(m => m.Data == item.Key)
                      select new
            {
                Key = item.Key
            };

            return(Json(lnq, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        public ActionResult GetEquipmentChangeState(string stateName)
        {
            //获取用户拥有权限的设备状态。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(User.Identity.Name, ResourceType.EquipmentState);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }
            var lnq = from item in lstResource
                      where item.Data == stateName
                      select item;

            IList <EquipmentChangeState> lst = new List <EquipmentChangeState>();

            if (lnq.Count() > 0)
            {
                //根据设备状态获取设备状态事件。
                using (EquipmentChangeStateServiceClient client = new EquipmentChangeStateServiceClient())
                {
                    PagingConfig cfg = new PagingConfig()
                    {
                        IsPaging = false,
                        Where    = string.Format(@"FromStateName='{0}'", stateName)
                    };
                    MethodReturnResult <IList <EquipmentChangeState> > result = client.Get(ref cfg);
                    if (result.Code <= 0 && result.Data != null)
                    {
                        lst = result.Data;
                    }
                }
            }


            var lnq1 = from item in lst
                       select new
            {
                Key         = item.Key,
                Text        = item.Key,
                ToStateName = item.ToStateName
            };

            return(Json(lnq1, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 8
0
        public IEnumerable <SelectListItem> GetLineStoreNameList()
        {
            //获取用户拥有权限的线边仓名称。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.LineStore);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }

            IList <LineStore> lstLineStore = new List <LineStore>();

            using (LineStoreServiceClient client = new LineStoreServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    IsPaging = false,
                    Where    = string.Format("Type='{1}' AND Status='{0}'"
                                             , Convert.ToInt32(EnumObjectStatus.Available)
                                             , Convert.ToInt32(EnumLineStoreType.Material))
                };

                MethodReturnResult <IList <LineStore> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstLineStore = result.Data;
                }
            }

            var lst = (from item in lstResource
                       where lstLineStore.Any(m => m.Key == item.Data)
                       select new SelectListItem()
            {
                Text = item.Data,
                Value = item.Data
            }).ToList();

            if (lst.Count > 0)
            {
                lst[0].Selected = true;
            }
            return(lst);
        }
Exemplo n.º 9
0
        public IEnumerable <SelectListItem> GetRouteStepNameList()
        {
            //获取用户拥有权限的工序名称。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.RouteOperation);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }

            IList <RouteOperation> lstRouteOperation = new List <RouteOperation>();

            //获取工序名称。
            using (RouteOperationServiceClient client = new RouteOperationServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    IsPaging = false,
                    Where    = string.Format("Status='{0}'", Convert.ToInt32(EnumObjectStatus.Available))
                };

                MethodReturnResult <IList <RouteOperation> > result = client.Get(ref cfg);
                if (result.Code <= 0)
                {
                    lstRouteOperation = result.Data;
                }
            }

            List <SelectListItem> lst = (from item in lstRouteOperation
                                         where lstResource.Any(m => m.Data == item.Key)
                                         orderby item.SortSeq
                                         select new SelectListItem()
            {
                Text = item.Key,
                Value = item.Key
            }).ToList();

            if (lst.Count > 0)
            {
                lst[0].Selected = true;
            }
            return(lst);
        }
Exemplo n.º 10
0
        public IEnumerable <SelectListItem> GetProductionLineList()
        {
            //获取用户拥有权限的生产线代码。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.ProductionLine);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }
            IList <ProductionLine> lstProductionLine = new List <ProductionLine>();

            //获取生产线。
            using (ProductionLineServiceClient client = new ProductionLineServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    IsPaging = false
                };

                MethodReturnResult <IList <ProductionLine> > result = client.Get(ref cfg);
                if (result.Code <= 0)
                {
                    lstProductionLine = result.Data;
                }
            }

            List <SelectListItem> lst = (from item in lstProductionLine
                                         where lstResource.Any(m => m.Data == item.Key)
                                         orderby item.LocationName
                                         select new SelectListItem()
            {
                Text = item.Key,
                Value = item.Key
            }).ToList();

            if (lst.Count > 0)
            {
                lst[0].Selected = true;
            }
            return(lst);
        }
Exemplo n.º 11
0
        public IEnumerable <SelectListItem> GetProductionLineList()
        {
            //获取用户拥有权限的生产线。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.ProductionLine);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }
            return(from item in lstResource
                   select new SelectListItem()
            {
                Text = item.Data,
                Value = item.Data
            });
        }
Exemplo n.º 12
0
        public List <string> RouteOperationList()
        {
            List <string> lst = new List <string>();
            //获取用户拥有权限的工序。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.RouteOperation);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;

                    for (int i = 0; i < lstResource.Count; i++)
                    {
                        lst.Add(result.Data.ToList <Resource>()[i].Name);
                    }
                }
            }
            return(lst);
        }
Exemplo n.º 13
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool isAuthorize = base.AuthorizeCore(httpContext);

            if (isAuthorize)
            {
                try
                {
                    string   loginName   = httpContext.User.Identity.Name;
                    TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);
                    if (httpContext.Cache.Get(loginName) == null)
                    {
                        httpContext.Cache.Insert(loginName, httpContext.Session.SessionID, null, DateTime.MaxValue, SessTimeOut);
                    }

                    string curPath = this._actionPath;
                    if (string.IsNullOrEmpty(curPath))
                    {
                        curPath = httpContext.Request.CurrentExecutionFilePath;
                    }
                    using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
                    {
                        this.AuthenticateResult = client.AuthenticateResource(loginName, ResourceType.Menu, curPath);
                        if (this.AuthenticateResult.Code > 0)
                        {
                            isAuthorize = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.AuthenticateResult         = new MethodReturnResult();
                    this.AuthenticateResult.Code    = 1000;
                    this.AuthenticateResult.Message = ex.Message;
                    this.AuthenticateResult.Detail  = ex.ToString();
                    isAuthorize = false;
                }
            }
            return(isAuthorize);
        }
Exemplo n.º 14
0
        public bool AuthenticateResourceFunction(string functionCode)
        {
            bool isAuthorize = true;

            try
            {
                using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
                {
                    MethodReturnResult result = client.AuthenticateResource(HttpContext.Current.User.Identity.Name, ResourceType.MenuItemFunction, functionCode);
                    if (result.Code > 0)
                    {
                        isAuthorize = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isAuthorize = false;
            }

            return(isAuthorize);
        }
Exemplo n.º 15
0
        public IEnumerable <SelectListItem> GetLineStoreNameList()
        {
            //获取用户拥有权限的线边仓名称。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.LineStore);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }
            IList <LineStore> lst = new List <LineStore>();
            PagingConfig      cfg = new PagingConfig()
            {
                IsPaging = false,
                Where    = "Status=1",
                OrderBy  = "Type,Key"
            };

            using (LineStoreServiceClient client = new LineStoreServiceClient())
            {
                MethodReturnResult <IList <LineStore> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null)
                {
                    lst = result.Data;
                }
            }
            return(from item in lst
                   where lstResource.Any(m => m.Data.ToUpper() == item.Key.ToUpper())
                   select new SelectListItem()
            {
                Text = item.Key,
                Value = item.Key
            });
        }
Exemplo n.º 16
0
        /// <summary>
        /// 取得线别代码
        /// </summary>
        /// <returns></returns>
        public IEnumerable <SelectListItem> GetLineList()
        {
            //获取用户拥有权限的生产线。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(HttpContext.Current.User.Identity.Name, ResourceType.ProductionLine);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }

            IList <ProductionLine> lst = new List <ProductionLine>();
            PagingConfig           cfg = new PagingConfig()
            {
                IsPaging = false
            };

            using (ProductionLineServiceClient client = new ProductionLineServiceClient())
            {
                MethodReturnResult <IList <ProductionLine> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null)
                {
                    lst = result.Data;
                }
            }

            return(from item in lst
                   where lstResource.Any(m => m.Data.ToUpper() == item.Key.ToUpper())
                   select new SelectListItem()
            {
                Text = string.Format("{0}[{1}]", item.Name, item.Key),
                Value = item.Key
            });
        }
Exemplo n.º 17
0
        public ActionResult GetLineStoreNames(string routeOperationName, string productionLineCode)
        {
            string locationName = string.Empty;

            //获取生产线所在区域
            using (ProductionLineServiceClient client = new ProductionLineServiceClient())
            {
                MethodReturnResult <ProductionLine> result = client.Get(productionLineCode);
                if (result.Code <= 0 && result.Data != null)
                {
                    locationName = result.Data.LocationName;
                }
            }
            //获取区域所在车间。
            using (LocationServiceClient client = new LocationServiceClient())
            {
                MethodReturnResult <Location> result = client.Get(locationName);
                if (result.Code <= 0 && result.Data != null)
                {
                    locationName = result.Data.ParentLocationName;
                }
            }
            IList <LineStore> lstLineStore = new List <LineStore>();

            //根据车间和工序获取线边仓。
            using (LineStoreServiceClient client = new LineStoreServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    IsPaging = false,
                    Where    = string.Format(@"LocationName='{0}' 
                                            AND (RouteOperationName IS NULL OR RouteOperationName='' OR RouteOperationName='{1}')
                                            AND Type='{2}'
                                            AND Status='{3}'"
                                             , locationName
                                             , routeOperationName
                                             , Convert.ToInt32(EnumLineStoreType.Material)
                                             , Convert.ToInt32(EnumObjectStatus.Available))
                };

                MethodReturnResult <IList <LineStore> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstLineStore = result.Data;
                }
            }
            //根据用户获取拥有权限的线边仓。
            IList <Resource> lstResource = new List <Resource>();

            using (UserAuthenticateServiceClient client = new UserAuthenticateServiceClient())
            {
                MethodReturnResult <IList <Resource> > result = client.GetResourceList(User.Identity.Name, ResourceType.LineStore);
                if (result.Code <= 0 && result.Data != null)
                {
                    lstResource = result.Data;
                }
            }

            var lnq = from item in lstLineStore
                      where lstResource.Any(m => m.Data == item.Key)
                      select new
            {
                Key = item.Key
            };

            return(Json(lnq, JsonRequestBehavior.AllowGet));
        }