public OPResult <string> SaveBillCannibalize(BillBO <BillCannibalize, BillCannibalizeDetails> bo)
        {
            using (var dbContext = new DistributionEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        BillHelper.SaveBill <BillCannibalize, BillCannibalizeDetails>(bo, dbContext);
                        var storeout = BillHelper.GenerateStoreOut(bo);
                        BillHelper.SaveBillStoreOut(storeout, dbContext);

                        dbContext.SaveChanges();

                        scope.Complete();
                    }
                    catch (Exception e)
                    {
                        return(new OPResult <string> {
                            IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                        });
                    }
                }
            }
            return(new OPResult <string> {
                IsSucceed = true, Message = "保存成功!", Result = bo.Bill.Code
            });
        }
        public OPResult SaveBillStoreMove(BillBO <BillStoreMove, BillStoreMoveDetails> bo)
        {
            using (var dbContext = new DistributionEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        BillHelper.SaveBill <BillStoreMove, BillStoreMoveDetails>(bo, dbContext);
                        var storeout = BillHelper.GenerateStoreOut(bo);
                        storeout.Bill.StorageID = bo.Bill.StorageIDOut;
                        BillHelper.SaveBillStoreOut(storeout, dbContext);
                        var storing = BillHelper.GenerateStoring(bo);
                        storing.Bill.StorageID = bo.Bill.StorageIDIn;
                        BillHelper.SaveBillStoring(storing, dbContext);

                        dbContext.SaveChanges();

                        scope.Complete();
                    }
                    catch (Exception e)
                    {
                        return(new OPResult {
                            IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                        });
                    }
                }
            }
            return(new OPResult {
                IsSucceed = true, Message = "保存成功!"
            });
        }
        public OPResult SaveBillDelivery(BillDeliveryBO bo)
        {
            using (var dbContext = new DistributionEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        bo.Bill.Code = BillHelper.GenerateBillCode <BillDelivery>(bo.Bill.ToOrganizationID, dbContext, o => o.ToOrganizationID == bo.Bill.ToOrganizationID);
                        BillHelper.SaveBill <BillDelivery, BillDeliveryDetails>(bo, dbContext);
                        var storeout = BillHelper.GenerateStoreOut(bo);
                        BillHelper.SaveBillStoreOut(storeout, dbContext);
                        if (bo.FundAccount != null && bo.FundAccount.NeedIn != 0)
                        {
                            bo.FundAccount.RefrenceBillCode = bo.Bill.Code;
                            dbContext.OrganizationFundAccount.Add(bo.FundAccount);
                        }
                        if (bo.Bill.IsWriteDownOrder)
                        {
                            //冲减订单
                            bo.Details.ForEach(d => dbContext.Database.ExecuteSqlCommand("exec UpdateOrderWhenDelivery {0}, {1},{2}", bo.Bill.ToOrganizationID, d.ProductID, d.Quantity));
                        }
                        dbContext.SaveChanges();

                        scope.Complete();
                    }
                    catch (Exception e)
                    {
                        return(new OPResult {
                            IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                        });
                    }
                }
            }
            return(new OPResult {
                IsSucceed = true, Message = "保存成功!"
            });
        }