public OPResult AddOrUpdate(OrganizationGoodReturnRatePerQuarter entity)
        {
            if (RateIsExist(entity))
            {
                return(new OPResult {
                    IsSucceed = false, Message = "该机构已经设置了该品牌年份季度的退货率."
                });
            }
            var id = entity.ID;

            try
            {
                if (id == default(int))
                {
                    entity.ID = LinqOP.Add <OrganizationGoodReturnRatePerQuarter, int>(entity, o => o.ID);
                }
                else
                {
                    LinqOP.Update <OrganizationGoodReturnRatePerQuarter>(entity);
                }
            }
            catch (Exception e)
            {
                entity.ID = id;
                return(new OPResult {
                    IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                });
            }

            return(new OPResult {
                IsSucceed = true, Message = "保存成功."
            });
        }
Example #2
0
        private void SetStyleBYQ(ProStyleBO style)
        {
            var byq = VMGlobal.BYQs.Find(o => o.BrandID == style.BrandID && o.Year == style.Year && o.Quarter == style.Quarter);

            if (byq != null)
            {
                style.BYQID = byq.ID;
            }
            else
            {
                byq = LinqOP.Search <ProBYQ>(o => o.BrandID == style.BrandID && o.Year == style.Year && o.Quarter == style.Quarter).FirstOrDefault();
                if (byq != null)
                {
                    style.BYQID = byq.ID;
                    VMGlobal.BYQs.Add(byq);
                }
                else
                {
                    byq = new ProBYQ {
                        BrandID = style.BrandID, Year = style.Year, Quarter = style.Quarter
                    };
                    int byqID = LinqOP.Add <ProBYQ, int>(byq, o => o.ID);
                    style.BYQID = byqID;
                    byq.ID      = byqID;
                    VMGlobal.BYQs.Add(byq);
                }
            }
        }
Example #3
0
        private OPResult Update(SysUserBO user)
        {
            var roleIDs            = RolesCurrentUserCover.Select(rs => rs.ID);//加上ToList()在下面执行时就抛出Contains不支持的异常,坑爹
            List <SysUserRole> urs = new List <SysUserRole>();

            foreach (var rs in user.Roles)
            {
                SysUserRole ur = new SysUserRole
                {
                    UserId    = user.ID,
                    RoleId    = rs.ID,
                    CreatorID = VMGlobal.CurrentUser.ID
                };
                urs.Add(ur);
            }

            var brandIDs         = VMGlobal.PoweredBrands.Select(bs => bs.ID);
            List <UserBrand> ubs = new List <UserBrand>();

            foreach (var bs in user.Brands)
            {
                UserBrand ub = new UserBrand
                {
                    UserID    = user.ID,
                    BrandID   = bs.ID,
                    CreatorID = VMGlobal.CurrentUser.ID
                };
                ubs.Add(ub);
            }

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    LinqOP.Update <SysUser>(user);
                    LinqOP.Delete <SysUserRole>(ur => roleIDs.Contains(ur.RoleId) && ur.UserId == user.ID);
                    VMGlobal.SysProcessQuery.LinqOP.Delete <UserBrand>(ub => brandIDs.Contains(ub.BrandID) && ub.UserID == user.ID);
                    LinqOP.Add <SysUserRole>(urs);
                    VMGlobal.SysProcessQuery.LinqOP.Add <UserBrand>(ubs);
                    scope.Complete();
                    return(new OPResult {
                        IsSucceed = true, Message = "更新成功."
                    });
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message
                    });
                }
            }
        }
Example #4
0
 public OPResult Audit(VoucherReceiveMoney entity)
 {
     if (entity.ID == default(int))
     {
         return(new OPResult {
             IsSucceed = false, Message = "请先保存单据."
         });
     }
     if (entity.Status)
     {
         return(new OPResult {
             IsSucceed = false, Message = "该收款单已审核."
         });
     }
     entity.Status    = true;
     entity.CheckerID = VMGlobal.CurrentUser.ID;
     entity.CheckTime = DateTime.Now;
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             LinqOP.Update <VoucherReceiveMoney>(entity);
             LinqOP.Add <OrganizationFundAccount>(
                 new OrganizationFundAccount
             {
                 BrandID          = entity.BrandID,
                 OrganizationID   = entity.OrganizationID,
                 NeedIn           = 0.0M,
                 AlreadyIn        = entity.ReceiveMoney,
                 CreatorID        = entity.CreatorID,
                 BillKind         = (int)BillTypeEnum.VoucherReceiveMoney,
                 Remark           = "收款单生成",
                 RefrenceBillCode = entity.Code
             });
             scope.Complete();
             return(new OPResult {
                 IsSucceed = true, Message = "审核成功."
             });
         }
         catch (Exception e)
         {
             entity.Status = false;
             return(new OPResult {
                 IsSucceed = false, Message = "审核失败,失败原因:\n" + e.Message
             });
         }
     }
 }
        private OPResult Add(SysOrganizationBO organization)
        {
            organization.CreatorID = VMGlobal.CurrentUser.ID;
            organization.ParentID  = VMGlobal.CurrentUser.OrganizationID;
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    int id = LinqOP.Add <SysOrganization, int>(organization, o => o.ID);
                    organization.ID = id;//将ID赋值,表明该对象不再是新增对象(新增对象ID都为0)

                    List <OrganizationBrand> obs = new List <OrganizationBrand>();
                    foreach (var b in organization.Brands)
                    {
                        OrganizationBrand ob = new OrganizationBrand
                        {
                            OrganizationID = id,
                            BrandID        = b.ID,
                            CreatorID      = organization.CreatorID,
                            CreateTime     = DateTime.Now
                        };
                        obs.Add(ob);
                    }
                    VMGlobal.SysProcessQuery.LinqOP.Add <OrganizationBrand>(obs);
                    //同时建立仓库,由于存在跨数据库操作,需要在数据库服务器上启动DTC服务
                    //后注:虽然在服务器上启动了DTC并按网上所述全部配置完毕,但却抛出“MSDTC被禁用”的异常。
                    //OrganizationLogic.AddDefaultStorage(organization);

                    scope.Complete();
                }
                catch (Exception e)
                {
                    organization.ID = default(int);
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                    });
                }
            }
            if (!VMGlobal.ChildOrganizations.Any(o => o.ID == organization.ID))
            {
                VMGlobal.ChildOrganizations.Add(organization);
            }
            _currentAndChildrenOrganizations = null;
            //OrganizationLogic.AddDefaultStorage(organization);这里去除新建默认仓库的逻辑
            return(new OPResult {
                IsSucceed = true, Message = "保存成功!"
            });
        }
Example #6
0
        private OPResult Update(SysRoleBO role)
        {
            List <SysRoleModule> rms = new List <SysRoleModule>();

            foreach (var m in role.Modules)
            {
                SysRoleModule rm = new SysRoleModule
                {
                    RoleId   = role.ID,
                    ModuleId = m.ID
                };
                rms.Add(rm);
            }
            //该角色被删除的菜单权限,拥有该角色的用户的所有下级用户的相应菜单权限也要一起删除,若同样权限是其它角色赋予则不删除
            //var oldrms = _query.LinqOP.Search<SysRoleModule>(rm => rm.RoleId == role.ID).ToList();
            //oldrms.Except(rms);//原列表中有新列表中没有的权限映射(待级联删除的)
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    LinqOP.Update <SysRole>(role);
                    LinqOP.Delete <SysRoleModule>(rm => rm.RoleId == role.ID);
                    LinqOP.Add <SysRoleModule>(rms);
                    VMGlobal.SysProcessQuery.DB.ExecuteNonQuery("CleanUpDirtyProcess", role.ID);
                    scope.Complete();
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message
                    });
                }
            }
            if (_rolesOfCurrentOrgnization != null)
            {
                var roleUpdate = _rolesOfCurrentOrgnization.FirstOrDefault(r => r.ID == role.ID);
                if (roleUpdate != null)
                {
                    int index = _rolesOfCurrentOrgnization.IndexOf(roleUpdate);
                    _rolesOfCurrentOrgnization[index] = role; //roleUpdate = role;
                }
            }
            return(new OPResult {
                IsSucceed = true, Message = "更新成功."
            });
        }
Example #7
0
        public override OPResult AddOrUpdate(VIPCard entity)
        {
            VIPCardBO card   = (VIPCardBO)entity;
            int       id     = card.ID;
            var       action = new Action(() =>
            {
                if (id != default(int))
                {
                    LinqOP.Delete <VIPCardKindMapping>(o => o.CardID == id);
                }
                var kindsmap = card.Kinds.Select(o => new VIPCardKindMapping {
                    CardID = card.ID, KindID = o.ID
                }).ToList();
                LinqOP.Add <VIPCardKindMapping>(kindsmap);
            });

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    var result = base.AddOrUpdate(entity);
                    if (!result.IsSucceed)
                    {
                        return(result);
                    }
                    else
                    {
                        action();
                    }
                    scope.Complete();
                    return(new OPResult {
                        IsSucceed = true, Message = "保存成功!"
                    });
                }
                catch (Exception e)
                {
                    card.ID = default(int);
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                    });
                }
            }
        }
Example #8
0
 private OPResult Add(ProStyleBO style)
 {
     style.CreatorID = VMGlobal.CurrentUser.ID;
     //TransactionScopeOption在事务嵌套时比较有用
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             SetStyleBYQ(style);
             int id = LinqOP.Add <ProStyle, int>(style, s => s.ID);
             style.ID = id;//将ID赋值,表明该对象不再是新增对象(新增对象ID都为0)
             List <Product> products = new List <Product>();
             foreach (var color in style.Colors)
             {
                 foreach (var size in style.Sizes)
                 {
                     Product product = new Product
                     {
                         Code      = style.Code + color.Code + size.Code,//成品SKU码生成规则=款号+色号+尺码
                         StyleID   = style.ID,
                         ColorID   = color.ID,
                         SizeID    = size.ID,
                         CreatorID = VMGlobal.CurrentUser.ID
                     };
                     products.Add(product);
                 }
             }
             LinqOP.Add <Product>(products);
             scope.Complete();
             return(new OPResult {
                 IsSucceed = true, Message = "保存成功!"
             });
         }
         catch (Exception e)
         {
             style.ID = default(int);
             return(new OPResult {
                 IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
             });
         }
     }
 }
Example #9
0
 public OPResult SetStylesForTactic(int tacticID, IEnumerable <RetailTacticProStyleMapping> mapping)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             LinqOP.Delete <RetailTacticProStyleMapping>(o => o.TacticID == tacticID);
             LinqOP.Add <RetailTacticProStyleMapping>(mapping);
             scope.Complete();
             return(new OPResult {
                 IsSucceed = true
             });
         }
         catch (Exception e)
         {
             return(new OPResult {
                 IsSucceed = false, Message = "设置失败,失败原因:\n" + e.Message
             });
         }
     }
 }
Example #10
0
 private OPResult Add(SysRoleBO role)
 {
     role.CreatorID      = VMGlobal.CurrentUser.ID;
     role.OrganizationID = VMGlobal.CurrentUser.OrganizationID;
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             int id = LinqOP.Add <SysRole, int>(role, r => r.ID);
             role.ID = id;
             List <SysRoleModule> rms = new List <SysRoleModule>();
             foreach (var m in role.Modules)
             {
                 SysRoleModule rm = new SysRoleModule
                 {
                     RoleId   = id,
                     ModuleId = m.ID
                 };
                 rms.Add(rm);
             }
             LinqOP.Add <SysRoleModule>(rms);
             if (_rolesOfCurrentOrgnization != null)//新增成功后同步更新_rolesOfCurrentOrgnization
             {
                 _rolesOfCurrentOrgnization.Add(role);
             }
             scope.Complete();
             return(new OPResult {
                 IsSucceed = true, Message = "保存成功."
             });
         }
         catch (Exception e)
         {
             role.ID = default(int);
             return(new OPResult {
                 IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
             });
         }
     }
 }
Example #11
0
        public override OPResult AddOrUpdate(ProBrand entity)
        {
            int id = entity.ID;

            using (TransactionScope scope = new TransactionScope())
            {
                var result = base.AddOrUpdate(entity);
                if (result.IsSucceed)
                {
                    if (id == default(int))
                    {
                        var ub = new UserBrand {
                            UserID = VMGlobal.CurrentUser.ID, BrandID = entity.ID, CreateTime = DateTime.Now, CreatorID = VMGlobal.CurrentUser.ID
                        };
                        var ob = new OrganizationBrand {
                            OrganizationID = VMGlobal.CurrentUser.OrganizationID, BrandID = entity.ID, CreateTime = DateTime.Now, CreatorID = VMGlobal.CurrentUser.ID
                        };
                        LinqOP.Add <UserBrand>(ub);
                        LinqOP.Add <OrganizationBrand>(ob);
                    }
                    scope.Complete();

                    var brand = VMGlobal.PoweredBrands.Find(o => o.ID == entity.ID);
                    if (brand == null)
                    {
                        VMGlobal.PoweredBrands.Add(entity);
                    }
                    else
                    {
                        int index = VMGlobal.PoweredBrands.IndexOf(brand);
                        VMGlobal.PoweredBrands[index] = entity;
                    }
                }
                return(result);
            }
        }
Example #12
0
        private OPResult Update(ProStyleBO style)
        {
            SetStyleBYQ(style);
            ProStyle       orginStyle    = LinqOP.GetById <ProStyle>(style.ID);
            List <Product> productsExist = LinqOP.Search <Product>(p => p.StyleID == style.ID).ToList();
            List <Product> products      = new List <Product>();

            foreach (var color in style.Colors)
            {
                foreach (var size in style.Sizes)
                {
                    var     pcode   = style.Code + color.Code + size.Code;
                    Product product = productsExist.FirstOrDefault(p => p.ColorID == color.ID && p.SizeID == size.ID);
                    if (product != null)
                    {
                        if (orginStyle.Code != style.Code)
                        {
                            product.Code = pcode;
                            products.Add(product);
                        }
                    }
                    else
                    {
                        product = new Product
                        {
                            Code      = pcode,
                            StyleID   = style.ID,
                            ColorID   = color.ID,
                            SizeID    = size.ID,
                            CreatorID = VMGlobal.CurrentUser.ID
                        };
                        products.Add(product);
                    }
                }
            }

            string changeMsg = "";

            if (orginStyle.Price != style.Price)
            {
                changeMsg += string.Format("单价从{0}变动为{1},", orginStyle.Price, style.Price);
            }
            if (orginStyle.Code != style.Code)
            {
                changeMsg += string.Format("款号从{0}变动为{1},", orginStyle.Code, style.Code);
            }
            if (products.Count > 0)
            {
                changeMsg += "增加了SKU码:";
                products.ForEach(o =>
                {
                    changeMsg += (o.Code + ",");
                });
            }
            changeMsg = changeMsg.TrimEnd(',');

            OPResult result = null;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    LinqOP.Update <ProStyle>(style);
                    LinqOP.AddOrUpdate <Product>(products);
                    if (!string.IsNullOrEmpty(changeMsg))
                    {
                        ProStyleChange change = new ProStyleChange
                        {
                            CreateTime  = DateTime.Now,
                            CreatorID   = VMGlobal.CurrentUser.ID,
                            Description = changeMsg,
                            StyleID     = style.ID
                        };
                        LinqOP.Add <ProStyleChange>(change);
                        style.Changes.Insert(0, change);
                    }
                    result = new OPResult {
                        IsSucceed = true, Message = "更新成功!"
                    };
                    scope.Complete();
                }
                catch (Exception e)
                {
                    result = new OPResult {
                        IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message
                    };
                }
            }
            if (result.IsSucceed && !string.IsNullOrEmpty(changeMsg))
            {
                IMHelper.AsyncSendMessageTo(IMHelper.OnlineUsers, new IMessage
                {
                    Message = changeMsg
                }, IMReceiveAccessEnum.成品资料变动);
            }
            return(result);
        }
Example #13
0
        //用户对应的各种数据集合,避免在UI绑定时频繁操作数据库
        //private void RefreshAttachData()
        //{
        //    var users = (List<SysUser>)Users.SourceCollection;
        //    var uIDs = users.Select<SysUser, int>(u => u.ID);

        //    var urs = _query.QueryProvider.GetTable<SysUserRole>("SysUserRole");
        //    var queryUR = from ur in urs where uIDs.Contains(ur.UserId) select ur;
        //    UserRoles = queryUR.ToList();

        //    var ubs = _queryDistribution.QueryProvider.GetTable<UserBrand>("UserBrand");
        //    var queryUB = from ub in ubs where uIDs.Contains(ub.UserID) select ub;
        //    UserBrands = queryUB.ToList();

        //    var oIDs = users.Select<SysUser, int>(u => u.OrganizationID);
        //    Organizations = _query.LinqOP.Search<SysOrganization>(o => oIDs.Contains(o.ID)).ToList();
        //}

        private OPResult Add(SysUserBO user)
        {
            int?userpointlimit = null;

            try
            {
                userpointlimit = this.GetUserPointLimit();
                if (userpointlimit == null)
                {
                    return new OPResult {
                               IsSucceed = false, Message = "保存失败,失败原因:\n无法确认用户点数是否存在上限,请联系软件公司。"
                    }
                }
                ;
                if ((userpointlimit != -1) && userpointlimit <= LinqOP.Search <SysUser>().Count())
                {
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n超过用户点数限制,若要增加用户点数,请联系软件公司。"
                    });
                }
            }
            catch (Exception e)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                });
            }
            string oginalPWD = user.Password;

            user.CreatorID = VMGlobal.CurrentUser.ID;
            user.Password  = oginalPWD.ToMD5String();
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    int id = LinqOP.Add <SysUser, int>(user, r => r.ID);
                    user.ID = id;
                    List <SysUserRole> urs = new List <SysUserRole>();
                    foreach (var r in user.Roles)
                    {
                        SysUserRole ur = new SysUserRole
                        {
                            UserId    = id,
                            RoleId    = r.ID,
                            CreatorID = VMGlobal.CurrentUser.ID
                        };
                        urs.Add(ur);
                    }
                    LinqOP.Add <SysUserRole>(urs);

                    List <UserBrand> ubs = new List <UserBrand>();
                    foreach (var b in user.Brands)
                    {
                        UserBrand ub = new UserBrand
                        {
                            UserID    = id,
                            BrandID   = b.ID,
                            CreatorID = VMGlobal.CurrentUser.ID
                        };
                        ubs.Add(ub);
                    }
                    VMGlobal.SysProcessQuery.LinqOP.Add <UserBrand>(ubs);
                    scope.Complete();
                    return(new OPResult {
                        IsSucceed = true, Message = "保存成功."
                    });
                }
                catch (Exception e)
                {
                    user.ID       = default(int);
                    user.Password = oginalPWD;
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                    });
                }
            }
        }