Esempio n. 1
0
        public ResResultModel DelUser(string userName)
        {
            try
            {
                if (!HttpContext.Current.User.IsInRole("Administrators"))
                {
                    throw new ArgumentException(MC.Role_InvalidError);
                }

                var user = Membership.GetUser(userName);
                if (user == null)
                {
                    throw new CustomException(MC.GetString(MC.Params_Data_NotExist, userName));
                }
                if (!Membership.DeleteUser(userName))
                {
                    return(ResResult.Response(false, MC.M_Save_Error, ""));
                }
                new Staff().DeleteStaff(Guid.Parse(user.ProviderUserKey.ToString()));

                return(ResResult.Response(true, "", ""));
            }
            catch (CustomException ex)
            {
                return(ResResult.Response(false, ex.Message, ""));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, "" + MC.AlertTitle_Ex_Error + ":" + ex.Message, ""));
            }
        }
Esempio n. 2
0
        public ResResultModel SaveContentType(ContentTypeFmModel model)
        {
            try
            {
                if (model == null)
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, null));
                }
                if (string.IsNullOrWhiteSpace(model.Named) || string.IsNullOrWhiteSpace(model.AppCode))
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, null));
                }
                var Id       = Guid.Empty;
                var parentId = Guid.Empty;
                if (model.Id != null && !string.IsNullOrWhiteSpace(model.Id.ToString()))
                {
                    Guid.TryParse(model.Id.ToString(), out Id);
                }
                if (model.ParentId != null && !string.IsNullOrWhiteSpace(model.ParentId.ToString()))
                {
                    Guid.TryParse(model.ParentId.ToString(), out parentId);
                }
                var openness = (byte)EnumData.Openness.完全公开;
                var currTime = DateTime.Now;
                var bll      = new ContentType();
                int effect   = 0;

                if (bll.IsExistCode(model.Coded, Id))
                {
                    return(ResResult.Response(false, MC.GetString(MC.Params_CodeExistError, model.Coded), Id));
                }

                var modelInfo = new ContentTypeInfo(model.AppCode, Id, WebCommon.GetUserId(), model.Coded, model.Named, parentId, model.Step.Trim(','), model.FlagName, openness, model.Sort, model.Remark, currTime, currTime);
                if (modelInfo.Id.Equals(Guid.Empty))
                {
                    MenusDataProxy.ValidateAccess((int)EnumData.OperationAccess.新增, true);
                    modelInfo.Id   = Guid.NewGuid();
                    modelInfo.Step = modelInfo.Id.ToString() + "," + modelInfo.Step;
                    effect         = bll.InsertByOutput(modelInfo);
                }
                else
                {
                    MenusDataProxy.ValidateAccess((int)EnumData.OperationAccess.编辑, true);
                    effect = bll.Update(modelInfo);
                }
                if (effect < 1)
                {
                    return(ResResult.Response(false, MC.M_Save_Error, null));
                }

                return(ResResult.Response(true, MC.M_Save_Ok, modelInfo.Id));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, ex.Message, null));
            }
        }
Esempio n. 3
0
        public ResResultModel GetPandianAssetByBarcode(string appKey, string userName, object pandianId, string barcode)
        {
            try
            {
                var userId = WebCommon.GetUserId();

                if (string.IsNullOrWhiteSpace(barcode))
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, ""));
                }

                var gId = Guid.Empty;
                if (pandianId != null)
                {
                    Guid.TryParse(pandianId.ToString(), out gId);
                }
                if (gId.Equals(Guid.Empty))
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, ""));
                }

                var            sqlWhere = @"and pd.Id = @PandianId and ais.Barcode = @Barcode ";
                SqlParameter[] parms    =
                {
                    new SqlParameter("@PandianId", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@Barcode",   SqlDbType.VarChar, 36)
                };
                parms[0].Value = gId;
                parms[1].Value = barcode;

                var bll  = new PandianAsset();
                var list = bll.GetListByJoin(sqlWhere, parms.ToArray());
                if (list == null || list.Count == 0)
                {
                    return(ResResult.Response(false, MC.GetString(MC.Params_Data_NotExist, barcode)));
                }

                var item = list[0];

                return(ResResult.Response(true, MC.Response_Ok, JsonConvert.SerializeObject(item)));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, ex.Message, ""));
            }
        }
Esempio n. 4
0
        public ResResultModel SaveUserInRole(string userName, string roleName, bool isInRole)
        {
            try
            {
                if (!HttpContext.Current.User.IsInRole("Administrators"))
                {
                    throw new ArgumentException(MC.Role_InvalidError);
                }

                if (string.IsNullOrWhiteSpace(userName))
                {
                    return(ResResult.Response(false, MC.GetString(MC.Request_InvalidArgument, "用户名"), ""));
                }
                if (string.IsNullOrWhiteSpace(roleName))
                {
                    return(ResResult.Response(false, MC.GetString(MC.Request_InvalidArgument, "角色"), ""));
                }

                if (isInRole)
                {
                    if (!Roles.IsUserInRole(userName, roleName))
                    {
                        Roles.AddUserToRole(userName, roleName);
                    }
                }
                else
                {
                    if (Roles.IsUserInRole(userName, roleName))
                    {
                        Roles.RemoveUserFromRole(userName, roleName);
                    }
                }

                return(ResResult.Response(true, "调用成功", ""));
            }
            catch (System.Configuration.Provider.ProviderException pex)
            {
                return(ResResult.Response(false, pex.Message, ""));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, ex.Message, ""));
            }
        }
Esempio n. 5
0
        public ResResultModel GetStockLocationProductList(StockLocationProductModel model)
        {
            try
            {
                if (model.PageIndex < 1)
                {
                    model.PageIndex = 1;
                }
                if (model.PageSize < 1)
                {
                    model.PageSize = 10;
                }

                if (model.KeyName == "OrderSendProduct" || model.KeyName == "OrderPickProduct")
                {
                    var spBll = new StockProduct();
                    if (model.KeyName == "OrderSendProduct")
                    {
                        var ospList = spBll.GetSelectProductListByStepName(model.PageIndex, model.PageSize, EnumData.EnumStep.发货.ToString(), null, null, model.Qty);
                        return(ResResult.Response(true, "", JsonConvert.SerializeObject(ospList)));
                    }
                    else if (model.KeyName == "OrderPickProduct")
                    {
                        var oppslList = spBll.GetSelectProductListByStepName(model.PageIndex, model.PageSize, EnumData.EnumStep.拣货.ToString(), model.ProductId, model.CustomerId, model.Qty);
                        return(ResResult.Response(true, "", JsonConvert.SerializeObject(oppslList)));
                    }
                }

                var slpBll = new StockLocationProduct();
                switch (model.KeyName)
                {
                case "ShelfMissionProduct":
                    var smpList = slpBll.GetListForShelfMissionProduct(Guid.Parse(model.ProductId.ToString()), model.Qty);
                    return(ResResult.Response(true, "", JsonConvert.SerializeObject(smpList)));

                default:
                    throw new ArgumentException(MC.GetString(MC.Params_SwitchNameNotExist, model.KeyName));
                }
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, ex.Message, null));
            }
        }
Esempio n. 6
0
        public ResResultModel SaveRoleMenu(RoleMenuFmModel model)
        {
            try
            {
                if (model == null)
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, ""));
                }
                if (string.IsNullOrWhiteSpace(model.MenuItemJson))
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, ""));
                }
                model.MenuItemJson = HttpUtility.UrlDecode(model.MenuItemJson);
                if (string.IsNullOrWhiteSpace(model.RoleName) && string.IsNullOrWhiteSpace(model.UserName))
                {
                    return(ResResult.Response(false, MC.Request_Params_InvalidError, ""));
                }
                List <RoleMenuFmInfo> list = JsonConvert.DeserializeObject <List <RoleMenuFmInfo> >(model.MenuItemJson);
                string   roleId            = "";
                string   userId            = "";
                var      isRole            = !string.IsNullOrWhiteSpace(model.RoleName);
                RoleMenu roleMenuBll       = null;
                UserMenu userMenuBll       = null;
                if (isRole)
                {
                    roleMenuBll = new RoleMenu();
                    var roleBll   = new Role();
                    var roleModel = roleBll.GetModel(model.RoleName);
                    if (roleModel == null)
                    {
                        return(ResResult.Response(false, MC.GetString(MC.Request_NotExist, "角色'" + model.RoleName + "'对应数据"), ""));
                    }
                    roleId = roleModel.RoleId.ToString();
                }
                else
                {
                    userMenuBll = new UserMenu();
                    userId      = Membership.GetUser(model.UserName).ProviderUserKey.ToString();
                }
                var menuBll = new Menus();
                foreach (var item in list)
                {
                    var menuModel = menuBll.GetModel(Guid.Parse(item.MenuId.ToString()));
                    menuModel.AllowRoles = menuModel.AllowRoles.Replace("*", "");
                    var isChanged       = false;
                    var isAccessChanged = false;
                    var isInsert        = false;
                    var apaItems        = new List <string>();

                    if (isRole)
                    {
                        var roleMenuModel = roleMenuBll.GetModel(Guid.Parse(roleId), Guid.Parse(item.MenuId.ToString()));
                        if (roleMenuModel == null)
                        {
                            isInsert             = true;
                            roleMenuModel        = new RoleMenuInfo();
                            roleMenuModel.RoleId = Guid.Parse(roleId);
                            roleMenuModel.MenuId = Guid.Parse(item.MenuId.ToString());
                        }
                        if (!string.IsNullOrEmpty(roleMenuModel.OperationAccess))
                        {
                            apaItems = roleMenuModel.OperationAccess.Split(',').ToList();
                        }

                        #region 允许角色

                        if (item.IsView)
                        {
                            if (!menuModel.AllowRoles.Contains(roleId))
                            {
                                var allowRoles = menuModel.AllowRoles.Split(',').ToList();
                                allowRoles.Add(roleId);
                                menuModel.AllowRoles = string.Join(",", allowRoles.ToArray()).Trim(',');
                                isChanged            = true;
                            }
                        }
                        else
                        {
                            if (menuModel.AllowRoles.Contains(roleId))
                            {
                                var allowRoles = menuModel.AllowRoles.Split(',').ToList();
                                allowRoles.Remove(roleId);
                                if (allowRoles.Count > 0)
                                {
                                    menuModel.AllowRoles = string.Join(",", allowRoles.ToArray()).Trim(',');
                                }
                                else
                                {
                                    menuModel.AllowRoles = "";
                                }
                                isChanged = true;
                            }
                        }

                        #endregion

                        #region 角色其它权限

                        if (item.IsAdd)
                        {
                            if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString()))
                            {
                                apaItems.Add(((int)EnumData.EnumOperationAccess.新增).ToString());
                                roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                isAccessChanged = true;
                            }
                        }
                        else
                        {
                            if (apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString()))
                            {
                                apaItems.Remove(((int)EnumData.EnumOperationAccess.新增).ToString());
                                isAccessChanged = true;
                                if (apaItems.Count > 0)
                                {
                                    roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                }
                                else
                                {
                                    roleMenuModel.OperationAccess = "";
                                }
                            }
                        }
                        if (item.IsDelete)
                        {
                            if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString()))
                            {
                                apaItems.Add(((int)EnumData.EnumOperationAccess.除).ToString());
                                roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                isAccessChanged = true;
                            }
                        }
                        else
                        {
                            if (apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString()))
                            {
                                apaItems.Remove(((int)EnumData.EnumOperationAccess.除).ToString());
                                isAccessChanged = true;
                                if (apaItems.Count > 0)
                                {
                                    roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                }
                                else
                                {
                                    roleMenuModel.OperationAccess = "";
                                }
                            }
                        }
                        if (item.IsEdit)
                        {
                            if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString()))
                            {
                                apaItems.Add(((int)EnumData.EnumOperationAccess.编辑).ToString());
                                roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                isAccessChanged = true;
                            }
                        }
                        else
                        {
                            if (apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString()))
                            {
                                apaItems.Remove(((int)EnumData.EnumOperationAccess.编辑).ToString());
                                isAccessChanged = true;
                                if (apaItems.Count > 0)
                                {
                                    roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                }
                                else
                                {
                                    roleMenuModel.OperationAccess = "";
                                }
                            }
                        }

                        #endregion

                        if (isAccessChanged)
                        {
                            if (isInsert)
                            {
                                roleMenuBll.Insert(roleMenuModel);
                            }
                            else
                            {
                                roleMenuBll.Update(roleMenuModel);
                            }
                        }
                    }
                    else
                    {
                        var userMenuInfo = userMenuBll.GetModel(Guid.Parse(userId), Guid.Parse(item.MenuId.ToString()));
                        if (userMenuInfo == null)
                        {
                            isInsert            = true;
                            userMenuInfo        = new UserMenuInfo();
                            userMenuInfo.UserId = Guid.Parse(userId);
                            userMenuInfo.MenuId = Guid.Parse(item.MenuId.ToString());
                        }
                        if (!string.IsNullOrEmpty(userMenuInfo.OperationAccess))
                        {
                            apaItems = userMenuInfo.OperationAccess.Split(',').ToList();
                        }

                        #region 拒绝用户

                        if (item.IsView)
                        {
                            if (!menuModel.DenyUsers.Contains(userId))
                            {
                                var denyUsers = menuModel.DenyUsers.Split(',').ToList();
                                denyUsers.Add(userId);
                                menuModel.DenyUsers = string.Join(",", denyUsers.ToArray()).Trim(',');
                                isChanged           = true;
                            }
                        }
                        else
                        {
                            if (menuModel.DenyUsers.Contains(userId))
                            {
                                var denyUsers = menuModel.DenyUsers.Split(',').ToList();
                                denyUsers.Remove(userId);
                                if (denyUsers.Count > 0)
                                {
                                    menuModel.DenyUsers = string.Join(",", denyUsers.ToArray()).Trim(',');
                                }
                                else
                                {
                                    menuModel.DenyUsers = "";
                                }
                                isChanged = true;
                            }
                        }

                        #endregion

                        #region 拒绝用户其它权限

                        if (item.IsAdd)
                        {
                            if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString()))
                            {
                                apaItems.Add(((int)EnumData.EnumOperationAccess.新增).ToString());
                                userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                isAccessChanged = true;
                            }
                        }
                        else
                        {
                            if (apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString()))
                            {
                                apaItems.Remove(((int)EnumData.EnumOperationAccess.新增).ToString());
                                isAccessChanged = true;
                                if (apaItems.Count > 0)
                                {
                                    userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                }
                                else
                                {
                                    userMenuInfo.OperationAccess = "";
                                }
                            }
                        }
                        if (item.IsDelete)
                        {
                            if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString()))
                            {
                                apaItems.Add(((int)EnumData.EnumOperationAccess.除).ToString());
                                userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                isAccessChanged = true;
                            }
                        }
                        else
                        {
                            if (apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString()))
                            {
                                apaItems.Remove(((int)EnumData.EnumOperationAccess.除).ToString());
                                isAccessChanged = true;
                                if (apaItems.Count > 0)
                                {
                                    userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                }
                                else
                                {
                                    userMenuInfo.OperationAccess = "";
                                }
                            }
                        }
                        if (item.IsEdit)
                        {
                            if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString()))
                            {
                                apaItems.Add(((int)EnumData.EnumOperationAccess.编辑).ToString());
                                userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                isAccessChanged = true;
                            }
                        }
                        else
                        {
                            if (apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString()))
                            {
                                apaItems.Remove(((int)EnumData.EnumOperationAccess.编辑).ToString());
                                isAccessChanged = true;
                                if (apaItems.Count > 0)
                                {
                                    userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(',');
                                }
                                else
                                {
                                    userMenuInfo.OperationAccess = "";
                                }
                            }
                        }

                        #endregion

                        if (isAccessChanged)
                        {
                            if (isInsert)
                            {
                                userMenuBll.Insert(userMenuInfo);
                            }
                            else
                            {
                                userMenuBll.Update(userMenuInfo);
                            }
                        }
                    }

                    if (isChanged)
                    {
                        menuBll.Update(menuModel);
                    }
                }

                return(ResResult.Response(true, "", ""));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, "异常:" + ex.Message + "", ""));
            }
        }