예제 #1
0
        public OPResult DeleteSKU(int pid, ProStyleChange change)
        {
            var distlp = _queryDistr.LinqOP;
            var manulp = _queryManu.LinqOP;
            var syslp  = _querySys.LinqOP;

            OPResult result = null;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    distlp.Delete <BillOrderDetails>(o => o.ProductID == pid);
                    manulp.Delete <BillProductExchangeDetails>(o => o.ProductID == pid);
                    manulp.Delete <BillProductPlanDetails>(o => o.ProductID == pid);
                    manulp.Delete <BillSubcontractDetails>(o => o.ProductID == pid);
                    syslp.Delete <ProductUniqueCodeMapping>(o => o.ProductID == pid);
                    syslp.Delete <Product>(o => o.ID == pid);
                    syslp.Add <ProStyleChange>(change);
                    result = new OPResult {
                        IsSucceed = true, Message = "删除成功!"
                    };
                    scope.Complete();
                }
                catch (Exception e)
                {
                    result = new OPResult {
                        IsSucceed = false, Message = "删除出错,出错原因:\n" + e.Message + "\n请告知系统管理员,防止出现冗余数据."
                    };
                }
            }
            return(result);
        }
예제 #2
0
        public OPResult Delete(ViewProduct product)
        {
            var distlp = VMGlobal.DistributionQuery.LinqOP;
            var manulp = VMGlobal.ManufacturingQuery.LinqOP;
            var syslp  = VMGlobal.SysProcessQuery.LinqOP;
            var pid    = product.ProductID;

            if (distlp.Any <BillStoringDetails>(o => o.ProductID == pid))
            {
                return new OPResult {
                           IsSucceed = false, Message = "删除失败,该SKU已有入库记录."
                }
            }
            ;
            if (distlp.Any <BillStocktakeDetails>(o => o.ProductID == pid))
            {
                return new OPResult {
                           IsSucceed = false, Message = "删除失败,该SKU已有盘点记录."
                }
            }
            ;

            string         changeMsg = string.Format("SKU码{0}被删除.", product.ProductCode);
            ProStyleChange change    = new ProStyleChange
            {
                CreateTime  = DateTime.Now,
                CreatorID   = VMGlobal.CurrentUser.ID,
                Description = changeMsg,
                StyleID     = product.StyleID
            };
            OPResult result = new OPResult {
                IsSucceed = false, Message = "删除失败!"
            };

            using (ChannelFactory <IBillService> channelFactory = new ChannelFactory <IBillService>("BillSVC"))
            {
                IBillService service = channelFactory.CreateChannel();

                result = service.DeleteSKU(product.ProductID, change);
            }
            if (result.IsSucceed)
            {
                ObservableCollection <ViewProduct> products = (ObservableCollection <ViewProduct>)Entities;
                products.Remove(product);
                IMHelper.AsyncSendMessageTo(IMHelper.OnlineUsers, new IMessage
                {
                    Message = changeMsg
                }, IMReceiveAccessEnum.成品资料变动);
            }
            return(result);
        }
    }
}
예제 #3
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);
        }