public OPResult SaveBillStoring(BillBO <BillStoring, BillStoringDetails> bo)
        {
            using (var dbContext = new DistributionEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        BillHelper.SaveBillStoring(bo, 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 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 <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 StoringReturnGoodReject(BillBO <BillGoodReturn, BillGoodReturnDetails> bo)
        {
            using (var dbContext = new DistributionEntities())
            {
                dbContext.Entry(bo.Bill).State = EntityState.Modified;
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        //BillHelper.SaveBill<BillGoodReturn, BillGoodReturnDetails>(bo, dbContext);
                        var storing = BillHelper.GenerateStoring(bo);
                        BillHelper.SaveBillStoring(storing, dbContext);
                        //if (bo.FundAccount != null && bo.FundAccount.AlreadyIn != 0)
                        //{
                        //    bo.FundAccount.RefrenceBillCode = bo.Bill.Code;
                        //    dbContext.OrganizationFundAccount.Add(bo.FundAccount);
                        //}
                        dbContext.SaveChanges();

                        scope.Complete();
                    }
                    catch (Exception e)
                    {
                        return(new OPResult {
                            IsSucceed = false, Message = "入库失败,失败原因:\n" + e.Message
                        });
                    }
                }
            }
            return(new OPResult {
                IsSucceed = true, Message = "入库成功!"
            });
        }
Exemple #5
0
        /// <summary>
        /// 保存单据
        /// </summary>
        public static void SaveBill <T, TDetail>(BillBO <T, TDetail> bo, DbContext dbContext, bool specifcCreateTime = false)
            where T : BillBase
            where TDetail : BillDetailBase
        {
            if (!specifcCreateTime)
            {
                bo.Bill.CreateTime = DateTime.Now;
            }

            var tcontext = dbContext.Set <T>();

            if (string.IsNullOrEmpty(bo.Bill.Code))
            {
                bo.Bill.Code = BillHelper.GenerateBillCode <T>(bo.Bill.OrganizationID, dbContext);
            }

            tcontext.Add(bo.Bill);
            dbContext.SaveChanges();

            var dcontext = dbContext.Set <TDetail>();

            foreach (var d in bo.Details)
            {
                d.BillID = bo.Bill.ID;
                dcontext.Add(d);
            }
            dbContext.SaveChanges();
        }
Exemple #6
0
 /// <summary>
 /// 保存单据
 /// </summary>
 public static OPResult SaveBill <T, TDetail, TDbContext>(BillBO <T, TDetail> bo)
     where T : BillBase
     where TDetail : BillDetailBase
     where TDbContext : DbContext, new()
 {
     try
     {
         using (var dbContext = new TDbContext())
         {
             BillHelper.SaveBill <T, TDetail>(bo, dbContext);
         }
     }
     catch (Exception ex)
     {
         return(new OPResult {
             IsSucceed = false, Message = "保存失败,失败原因:\n" + ex.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 = "保存成功!"
            });
        }
 public OPResult SaveBillAllocate(BillBO <BillAllocate, BillAllocateDetails> bo)
 {
     return(BillHelper.SaveBill <BillAllocate, BillAllocateDetails, DistributionEntities>(bo));
 }
Exemple #9
0
 internal static void SaveBillStoring(BillBO <BillStoring, BillStoringDetails> bo, DbContext dbContext)
 {
     BillHelper.SaveBill <BillStoring, BillStoringDetails>(bo, dbContext);
     dbContext.Database.ExecuteSqlCommand("exec UpdateStockWhenStoreIO {0}, {1}", bo.Bill.ID, true);
 }
Exemple #10
0
        public OPResult <BillRetail> SaveBillRetail(BillRetailBO bo)
        {
            //bo.Bill.CreateTime = DateTime.Now;

            using (var dbContext = new DistributionEntities())
            {
                if (bo.RefrenseVIPUpTactics != null && bo.VIPPointRecord != null)
                {
                    IEnumerable <int> kindIDs = bo.RefrenseVIPUpTactics.Select(o => o.Tactic.FormerKindID).ToList();
                    IEnumerable <VIPCardKindMapping> mappings = dbContext.VIPCardKindMapping.Where(o => o.CardID == bo.VIPPointRecord.VIPID && kindIDs.Contains(o.KindID)).ToList();
                    foreach (var mapping in mappings)
                    {
                        var t = bo.RefrenseVIPUpTactics.First(o => o.Tactic.FormerKindID == mapping.KindID);
                        mapping.KindID = t.Tactic.AfterKindID;
                        if (t.Tactic.CutPoint != 0)
                        {
                            dbContext.VIPPointTrack.Add(new VIPPointTrack
                            {
                                CreateTime = DateTime.Now,
                                Point      = (-1 * t.Tactic.CutPoint),
                                VIPID      = bo.VIPPointRecord.VIPID,
                                Remark     = "VIP升级产生," + t.Description
                            });
                        }
                    }
                }
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        bo.Bill.Code = BillHelper.GenerateBillCode <BillRetail>(bo.Bill.OrganizationID, dbContext);
                        BillHelper.SaveBill <BillRetail, BillRetailDetails>(bo, dbContext, bo.SpecifcCreateTime);
                        foreach (var storeout in bo.BillStoreOuts)
                        {
                            storeout.Bill.CreateTime       = DateTime.Now;
                            storeout.Bill.RefrenceBillCode = bo.Bill.Code;
                            BillHelper.SaveBillStoreOut(storeout, dbContext);
                        }
                        foreach (var storing in bo.BillStorings)
                        {
                            storing.Bill.CreateTime       = DateTime.Now;
                            storing.Bill.RefrenceBillCode = bo.Bill.Code;
                            BillHelper.SaveBillStoring(storing, dbContext);
                        }
                        if (bo.VIPPointRecord != null)
                        {
                            bo.VIPPointRecord.Remark = "零售单产生,小票号" + bo.Bill.Code;
                            dbContext.VIPPointTrack.Add(bo.VIPPointRecord);

                            if (bo.Bill.PredepositPay != 0)
                            {
                                VIPPredepositTrack predepositTrack = new VIPPredepositTrack
                                {
                                    RefrenceBillCode = bo.Bill.Code,
                                    Kind             = false,
                                    OrganizationID   = bo.Bill.OrganizationID,
                                    CreatorID        = bo.Bill.CreatorID,
                                    CreateTime       = DateTime.Now,
                                    ConsumeMoney     = bo.Bill.PredepositPay,
                                    VIPID            = bo.VIPPointRecord.VIPID,
                                    Remark           = "零售单产生"
                                };
                                dbContext.VIPPredepositTrack.Add(predepositTrack);
                            }
                        }
                        if (bo.VIPBirthdayConsumption != null)
                        {
                            bo.VIPBirthdayConsumption.ConsumeDay = DateTime.Now.Date;
                            dbContext.VIPBirthdayConsumption.Add(bo.VIPBirthdayConsumption);
                        }

                        dbContext.SaveChanges();

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