コード例 #1
0
        /// <summary>
        /// 删除其他出库
        /// </summary>
        /// <param name="transferOuts"></param>
        /// <returns></returns>
        public ResultData <string> RemoveTransferOuts(List <WTransferOut> transferOuts)
        {
            DatabaseContext     db    = toRepository.DbCondext;
            ResultData <string> rData = new ResultData <string>();

            try
            {
                db.BeginTransaction();

                foreach (WTransferOut u in transferOuts)
                {
                    int result = RemoveTransferOut(u);
                    if (result < 1)
                    {
                        rData.status  = -1;
                        rData.message = "只有新建状态的单据才能删除.";
                        db.AbortTransaction();
                        break;
                    }
                }

                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #2
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="transferOut"></param>
        /// <returns></returns>
        public ResultData <string> ApproveTransferOut(WTransferOut transferOut)
        {
            ResultData <string> rData = new ResultData <string>();

            if (transferOut.Lines.Count < 1)
            {
                transferOut.Lines = tolRepository.GetLinesByParentId(transferOut.ID);
            }

            DatabaseContext dbContext = toRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //出库记录
                List <WStockOut> stockOuts = new List <WStockOut>(transferOut.Lines.Count);

                //审核
                int result = toRepository.ApproveTransferOut(transferOut);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in transferOut.Lines)
                {
                    stockOuts.Add(CloneTransferOut(line, transferOut));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.DeleteStocks(stockOuts);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }

            if (rData.status == 0)
            {
                //调拨入库通知单
                WTransferInNotice inNotice = CloneInNotice(transferOut);
                rData = new WTransferInNoticeService().AddTransferInNotice(inNotice);
            }
            return(rData);
        }
コード例 #3
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="purReturn"></param>
        /// <returns></returns>
        public ResultData <string> ApprovePurchaseReturn(WPurchaseReturn purReturn)
        {
            if (purReturn.Lines.Count < 1)
            {
                purReturn.Lines = prlRepository.GetLinesByParentId(purReturn.ID);
            }

            ResultData <string> rData = CheckValid(purReturn);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = prRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //出库记录
                List <WStockOut> stockOuts = new List <WStockOut>(purReturn.Lines.Count);

                //添加其他出库
                int result = prRepository.ApprovePurchaseReturn(purReturn);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in purReturn.Lines)
                {
                    stockOuts.Add(ClonePurchaseReturn(line, purReturn));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.DeleteStocks(stockOuts);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #4
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="sellReturn"></param>
        /// <returns></returns>
        public ResultData <string> ApproveSellReturn(WSellReturn sellReturn)
        {
            ResultData <string> rData = new ResultData <string>();

            if (sellReturn.Lines.Count < 1)
            {
                sellReturn.Lines = srlRepository.GetLinesByParentId(sellReturn.ID);
            }

            DatabaseContext dbContext = srRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //入库记录
                List <WStockIn> stockIns = new List <WStockIn>(sellReturn.Lines.Count);

                //添加其他入库
                int result = srRepository.ApproveSellReturn(sellReturn);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in sellReturn.Lines)
                {
                    stockIns.Add(CloneSellReturn(line, sellReturn));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.AddStocks(stockIns);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #5
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="otherOut"></param>
        /// <returns></returns>
        public ResultData <string> ApproveOtherOut(WOtherOut otherOut)
        {
            ResultData <string> rData = new ResultData <string>();

            if (otherOut.Lines.Count < 1)
            {
                otherOut.Lines = oolRepository.GetLinesByParentId(otherOut.ID);
            }

            DatabaseContext dbContext = ooRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //出库记录
                List <WStockOut> stockOuts = new List <WStockOut>(otherOut.Lines.Count);

                //添加其他出库
                int result = ooRepository.ApproveOtherOut(otherOut);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in otherOut.Lines)
                {
                    stockOuts.Add(CloneOtherOut(line, otherOut));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.DeleteStocks(stockOuts);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #6
0
        /// <summary>
        /// 添加调拨入库单
        /// </summary>
        /// <param name="inNotice"></param>
        /// <returns></returns>
        public ResultData <string> AddTransferInNotice(WTransferInNotice inNotice)
        {
            ResultData <string> rData     = new ResultData <string>();
            DatabaseContext     dbContext = tinRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                inNotice.CreateDate   = DateTime.Now;
                inNotice.NoticeStatus = NoticeStatusEnum.New;
                inNotice.InNoticeCode = nuRepository.GetNextNumber("DBRT");
                tinRepository.Insert(inNotice);

                foreach (var line in inNotice.Lines)
                {
                    line.ParentID   = inNotice.ID;
                    line.CreateBy   = inNotice.CreateBy;
                    line.CreateDate = DateTime.Now;
                    tinllRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #7
0
        /// <summary>
        /// 添加资源
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        public object AddResource(SResource resource)
        {
            DatabaseContext dbContext = rRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加资源  添加按钮
                object id = rRepository.Insert(resource);
                foreach (SOperator o in resource.Operators)
                {
                    o.ResourceID   = Convert.ToInt32(id);
                    o.OperatorDesc = o.OperatorName;
                    oRepository.Insert(o);
                }

                dbContext.CompleteTransaction();
                return(id);
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
        }
コード例 #8
0
        /// <summary>
        /// 更新其他入库
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        public ResultData <string> UpdateOtherIn(WOtherIn otherIn)
        {
            ResultData <string> rData = CheckValid(otherIn);

            if (rData.status != 0)
            {
                return(rData);
            }

            if (otherIn.StockStatus != StockStatusEnum.New)
            {
                rData.status  = -1;
                rData.message = "单据已经审核,不能编辑.";
                return(rData);
            }

            DatabaseContext db = oiRepository.DbCondext;

            try
            {
                db.BeginTransaction();

                otherIn.UpdateDate = DateTime.Now;
                oiRepository.Update(otherIn);
                foreach (var line in otherIn.Lines)
                {
                    switch (line.CURD)
                    {
                    case CurdEnum.Add:
                        line.ParentID   = otherIn.ID;
                        line.CreateBy   = otherIn.CreateBy;
                        line.CreateDate = DateTime.Now;
                        line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                        oilRepository.Insert(line);
                        break;

                    case CurdEnum.Delete:
                        oilRepository.Delete(line);
                        break;

                    case CurdEnum.Update:
                        line.UpdateBy   = otherIn.UpdateBy;
                        line.UpdateDate = DateTime.Now;
                        line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                        oilRepository.Update(line);
                        break;
                    }
                }

                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #9
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="purchaseNotice"></param>
        /// <returns></returns>
        public ResultData <string> UpdatePurchaseNotice(WPurchaseNotice purchaseNotice)
        {
            ResultData <string> rData = CheckValid(purchaseNotice);

            if (rData.status != 0)
            {
                return(rData);
            }
            if (purchaseNotice.NoticeStatus != NoticeStatusEnum.New)
            {
                rData.status  = -1;
                rData.message = "单据已经审核,不能编辑.";
                return(rData);
            }

            DatabaseContext db = pnRepository.DbCondext;

            try
            {
                db.BeginTransaction();

                pnRepository.Update(purchaseNotice);
                foreach (var line in purchaseNotice.Lines)
                {
                    switch (line.CURD)
                    {
                    case CurdEnum.Add:
                        line.ParentID   = purchaseNotice.ID;
                        line.CreateBy   = purchaseNotice.CreateBy;
                        line.CreateDate = DateTime.Now;
                        pnlRepository.Insert(line);
                        break;

                    case CurdEnum.Delete:
                        pnlRepository.Delete(line);
                        break;

                    case CurdEnum.Update:
                        line.UpdateBy   = purchaseNotice.UpdateBy;
                        line.UpdateDate = DateTime.Now;
                        pnlRepository.Update(line);
                        break;
                    }
                }

                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #10
0
ファイル: BMaterialService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 删除物料
        /// </summary>
        /// <param name="Material"></param>
        /// <returns></returns>
        public int RemoveMaterials(List <BMaterial> Material)
        {
            DatabaseContext db = mRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                foreach (BMaterial bp in Material)
                {
                    RemoveMaterial(bp);
                }
                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(Material.Count);
        }
コード例 #11
0
        /// <summary>
        /// 删除业务伙伴
        /// </summary>
        /// <param name="BusinessPartner"></param>
        /// <returns></returns>
        public int RemoveBusinessPartners(List <BBusinessPartner> BusinessPartner)
        {
            DatabaseContext db = bpRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                foreach (BBusinessPartner bp in BusinessPartner)
                {
                    RemoveBusinessPartner(bp);
                }
                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(BusinessPartner.Count);
        }
コード例 #12
0
        /// <summary>
        /// 删除列
        /// </summary>
        /// <param name="scolumns"></param>
        /// <returns></returns>
        public int RemoveColumns(List <SColumn> scolumns)
        {
            DatabaseContext db = cRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                foreach (SColumn u in scolumns)
                {
                    RemoveColumn(u);
                }
                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(scolumns.Count);
        }
コード例 #13
0
        /// <summary>
        /// 插入新其他入库
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        public ResultData <string> AddOtherIn(WOtherIn otherIn)
        {
            ResultData <string> rData = CheckValid(otherIn);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = oiRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //入库记录
                List <WStockIn> stockIns = new List <WStockIn>(otherIn.Lines.Count);

                //添加其他入库
                otherIn.CreateDate  = DateTime.Now;
                otherIn.StockStatus = StockStatusEnum.New;
                otherIn.OtherInCode = nuRepository.GetNextNumber("QTRK");
                oiRepository.Insert(otherIn);

                foreach (var line in otherIn.Lines)
                {
                    line.ParentID   = otherIn.ID;
                    line.CreateBy   = otherIn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    oilRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #14
0
        /// <summary>
        /// 根据ID集合删除资源
        /// </summary>
        /// <param name="resourceIDs"></param>
        /// <returns></returns>
        public bool RemoveResource(int resId)
        {
            bool            result    = false;
            DatabaseContext dbContext = rRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                rRepository.RemoveOperatorByResourceID(resId);
                result = rRepository.Delete(resId);

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(result);
        }
コード例 #15
0
        /// <summary>
        /// 插入新其他出库
        /// </summary>
        /// <param name="transferOut"></param>
        /// <returns></returns>
        public ResultData <string> AddTransferOut(WTransferOut transferOut)
        {
            ResultData <string> rData = CheckValid(transferOut);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = toRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加其他出库
                transferOut.CreateDate      = DateTime.Now;
                transferOut.StockStatus     = StockStatusEnum.New;
                transferOut.StockOutType    = StockOutEnum.TransferOut;
                transferOut.TransferOutCode = nuRepository.GetNextNumber("DBCK");
                toRepository.Insert(transferOut);

                foreach (var line in transferOut.Lines)
                {
                    line.ParentID   = transferOut.ID;
                    line.CreateBy   = transferOut.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    tolRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #16
0
ファイル: WPurchaseService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 插入新采购入库
        /// </summary>
        /// <param name="purchase"></param>
        /// <returns></returns>
        public ResultData <string> AddPurchase(WPurchase purchase)
        {
            ResultData <string> rData = CheckValid(purchase);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = pRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                purchase.CreateDate   = DateTime.Now;
                purchase.StockStatus  = StockStatusEnum.New;
                purchase.PurchaseCode = nuRepository.GetNextNumber("CGRK");
                pRepository.Insert(purchase);

                foreach (var line in purchase.Lines)
                {
                    line.ParentID   = purchase.ID;
                    line.CreateBy   = purchase.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    plRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #17
0
        /// <summary>
        /// 插入新采购入库
        /// </summary>
        /// <param name="sellReturn"></param>
        /// <returns></returns>
        public ResultData <string> AddSellReturn(WSellReturn sellReturn)
        {
            ResultData <string> rData = CheckValid(sellReturn);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = srRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                sellReturn.CreateDate     = DateTime.Now;
                sellReturn.StockStatus    = StockStatusEnum.New;
                sellReturn.SellReturnCode = nuRepository.GetNextNumber("XSTK");
                srRepository.Insert(sellReturn);

                foreach (var line in sellReturn.Lines)
                {
                    line.ParentID   = sellReturn.ID;
                    line.CreateBy   = sellReturn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    srlRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #18
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="resource"></param>
        public void UpdateResource(SResource resource)
        {
            DatabaseContext dbContext = rRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                rRepository.Update(resource);
                foreach (SOperator o in resource.Operators)
                {
                    switch (o.CURD)
                    {
                    case "add":
                        o.ResourceID   = resource.ID;
                        o.OperatorDesc = o.OperatorName;
                        oRepository.Insert(o);
                        break;

                    case "delete":
                        oRepository.Delete(o);
                        break;

                    default:
                        o.OperatorDesc = o.OperatorName;
                        oRepository.Update(o);
                        break;
                    }
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
        }
コード例 #19
0
ファイル: WPurchaseService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="purchase"></param>
        /// <returns></returns>
        public int RemovePurchase(WPurchase purchase)
        {
            //查询明细
            if (purchase.Lines.Count < 1)
            {
                purchase.Lines = plRepository.GetLinesByParentId(purchase.ID);
            }

            DatabaseContext db = pRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                //删除其他出库
                int result = pRepository.RemovePurchaseByStatus(purchase.ID, StockStatusEnum.New);
                if (result > 0)
                {
                    foreach (WPurchaseLine line in purchase.Lines)
                    {
                        if (line.SourceLineID > 0)
                        {
                            //删除下推
                            pnlRepository.RemoveDownCount(line.InCount, line.SourceLineID);
                        }
                    }
                    plRepository.RemoveLinesByParentId(purchase.ID);
                }
                db.CompleteTransaction();
                return(result);
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
        }
コード例 #20
0
        /// <summary>
        /// 添加采购通知单
        /// </summary>
        /// <param name="inNotice"></param>
        /// <returns></returns>
        public ResultData <string> AddPurchaseNotice(WPurchaseNotice inNotice)
        {
            ResultData <string> rData = CheckValid(inNotice);

            if (rData.status != 0)
            {
                return(rData);
            }
            DatabaseContext dbContext = pnRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                inNotice.CreateDate   = DateTime.Now;
                inNotice.NoticeStatus = NoticeStatusEnum.New;
                inNotice.InNoticeCode = nuRepository.GetNextNumber("CGRT");
                pnRepository.Insert(inNotice);

                foreach (var line in inNotice.Lines)
                {
                    line.ParentID   = inNotice.ID;
                    line.CreateBy   = inNotice.CreateBy;
                    line.CreateDate = DateTime.Now;
                    pnlRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #21
0
ファイル: WSellService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sell"></param>
        /// <returns></returns>
        public int RemoveSell(WSell sell)
        {
            //查询明细
            if (sell.Lines.Count < 1)
            {
                sell.Lines = slRepository.GetLinesByParentId(sell.ID);
            }

            DatabaseContext db = snRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                //删除其他出库
                int result = sRepository.RemoveSellByStatus(sell.ID, StockStatusEnum.New);
                if (result > 0)
                {
                    foreach (WSellLine line in sell.Lines)
                    {
                        if (line.SourceLineID > 0)
                        {
                            //删除下推
                            snlRepository.RemoveDownCount(line.OutCount, line.SourceLineID);
                        }
                    }
                    slRepository.RemoveLinesByParentId(sell.ID);
                }
                db.CompleteTransaction();
                return(result);
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
        }
コード例 #22
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public int RemoveUsers(List <SUser> users)
        {
            DatabaseContext db = uRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                foreach (SUser u in users)
                {
                    //系统管理员,不能删除
                    if (!IsSuperUser(u))
                    {
                        RemoveUser(u);
                    }
                }
                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(users.Count);
        }
コード例 #23
0
ファイル: BLocationService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 编辑存储单元
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public bool UpdateLocation(BLocation location)
        {
            var             oldEntity = lRepository.GetLocationById(location.ID);
            int             oldOrgId  = oldEntity.OrgID;
            DatabaseContext db        = lRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                bool result = lRepository.Update(location);
                //如果修改了组织,下属的货区货位的组织也要跟着变
                if (oldOrgId != location.OrgID)
                {
                    db.Connection.Execute(string.Format("Update BLocation set OrgId={0} where ID<>{1} and TopLocationID={1}", location.OrgID, location.ID));
                }
                db.CompleteTransaction();
                return(result);
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
        }
コード例 #24
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="purchase"></param>
        /// <returns></returns>
        public ResultData <string> UpdateSellReturn(WSellReturn sellReturn)
        {
            ResultData <string> rData = CheckValid(sellReturn);

            if (rData.status != 0)
            {
                return(rData);
            }
            if (sellReturn.StockStatus != StockStatusEnum.New)
            {
                rData.status  = -1;
                rData.message = "单据已经审核,不能编辑.";
                return(rData);
            }

            DatabaseContext db = srRepository.DbCondext;

            try
            {
                db.BeginTransaction();

                foreach (var line in sellReturn.Lines)
                {
                    switch (line.CURD)
                    {
                    case CurdEnum.Add:
                        if (line.SourceLineID > 0)
                        {
                            //添加退库
                            decimal result = slRepository.AddReturnCount(line.InCount, line.SourceLineID);
                            if (result < 0)
                            {
                                db.AbortTransaction();
                                rData.status  = -1;
                                rData.message = BuilderErrorMessage(line, "入库数量大于出库单数量.");
                                return(rData);
                            }
                        }
                        line.ParentID   = sellReturn.ID;
                        line.CreateBy   = sellReturn.CreateBy;
                        line.CreateDate = DateTime.Now;
                        line.InPutCount = line.InCount;
                        line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                        srlRepository.Insert(line);
                        break;

                    case CurdEnum.Delete:
                        srlRepository.Delete(line);
                        if (line.SourceLineID > 0)
                        {
                            //删除退库
                            slRepository.RemoveReturnCount(line.InCount, line.SourceLineID);
                        }
                        break;

                    case CurdEnum.Update:
                        if (line.SourceLineID > 0)
                        {
                            decimal result = slRepository.UpdateReturnCount(line.SourceLineID, line.InCount, line.InPutCount);
                            if (result < 0)
                            {
                                db.AbortTransaction();
                                rData.status  = -1;
                                rData.message = BuilderErrorMessage(line, "入库数量大于入库单数量.");
                                return(rData);
                            }
                        }
                        line.UpdateBy   = sellReturn.UpdateBy;
                        line.InPutCount = line.InCount;
                        line.UpdateDate = DateTime.Now;
                        line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                        srlRepository.Update(line);
                        break;
                    }
                }

                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #25
0
        /// <summary>
        /// 根据入库通知添加入库
        /// </summary>
        /// <param name="sell"></param>
        /// <returns></returns>
        public ResultData <string> AddSellReturn(WSell sell, int createBy)
        {
            ResultData <string> rData = new ResultData <string>();

            if (sell.StockStatus != StockStatusEnum.Approve)
            {
                rData.status  = -1;
                rData.message = "单据未审核不能退库.";
                return(rData);
            }

            //查询明细
            if (sell.Lines.Count < 1)
            {
                sell.Lines = slRepository.GetLinesByParentId(sell.ID);
            }

            //克隆主表
            WSellReturn sellReturn = CloneInNotice(sell);

            sellReturn.CreateBy = createBy;

            foreach (var item in sell.Lines)
            {
                WSellReturnLine line = CloneInNoticeLine(item);
                if (line != null)
                {
                    sellReturn.Lines.Add(line);
                }
            }

            if (sellReturn.Lines.Count < 1)
            {
                rData.status  = -1;
                rData.message = "单据已经全部退库.";
                return(rData);
            }

            DatabaseContext dbContext = srRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加入库单
                sellReturn.CreateDate     = DateTime.Now;
                sellReturn.StockStatus    = StockStatusEnum.New;
                sellReturn.SellReturnCode = nuRepository.GetNextNumber("XSTK");
                srRepository.Insert(sellReturn);
                foreach (var line in sellReturn.Lines)
                {
                    line.ParentID   = sellReturn.ID;
                    line.CreateBy   = sellReturn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    srlRepository.Insert(line);

                    //更新入库单 添加退库
                    decimal rt = slRepository.AddReturnCount(line.InCount, line.SourceLineID);
                    if (rt < 0)
                    {
                        dbContext.AbortTransaction();
                        rData.status  = -1;
                        rData.message = BuilderNoticeLessMessage(line);
                        return(rData);
                    }
                }

                //将插入主键赋值给返回值
                rData.result = sellReturn.ID.ToString();

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }

            return(rData);
        }
コード例 #26
0
ファイル: WSellService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="sell"></param>
        /// <returns></returns>
        public ResultData <string> ApproveSell(WSell sell)
        {
            if (sell.Lines.Count < 1)
            {
                sell.Lines = slRepository.GetLinesByParentId(sell.ID);
            }

            ResultData <string> rData = CheckValid(sell);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = sRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //出库记录
                List <WStockOut> stockOuts = new List <WStockOut>(sell.Lines.Count);

                //添加其他出库
                int result = sRepository.ApproveSell(sell);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in sell.Lines)
                {
                    stockOuts.Add(CloneSell(line, sell));
                    //添加完成数量
                    if (line.SourceLineID > 0)
                    {
                        snlRepository.AddCompleteCount(line.SourceLineID, line.OutCount);
                    }
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.DeleteStocks(stockOuts);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #27
0
ファイル: WSellService.cs プロジェクト: manlsc/ESC.Core
        /// <summary>
        /// 根据通知单生成出库单
        /// </summary>
        /// <param name="outNotice"></param>
        /// <returns></returns>
        public ResultData <string> AddSell(WSellNotice outNotice, int createBy)
        {
            ResultData <string> rData = new ResultData <string>();

            if (outNotice.NoticeStatus == NoticeStatusEnum.Complete)
            {
                rData.status  = -1;
                rData.message = "单据已完成不能下推.";
                return(rData);
            }

            //查询明细
            if (outNotice.Lines.Count < 1)
            {
                outNotice.Lines = snlRepository.GetLinesByParentId(outNotice.ID);
            }

            //克隆主表
            WSell sell = CloneOutNotice(outNotice);

            sell.CreateBy = createBy;
            //克隆子表
            foreach (var item in outNotice.Lines)
            {
                WSellLine line = CloneOutNoticeLine(item);
                if (line != null)
                {
                    sell.Lines.Add(line);
                }
            }

            if (sell.Lines.Count < 1)
            {
                rData.status  = -1;
                rData.message = "单据已经全部下推.";
                return(rData);
            }

            DatabaseContext dbContext = sRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加出库单
                sell.CreateDate  = DateTime.Now;
                sell.StockStatus = StockStatusEnum.New;
                sell.SellCode    = nuRepository.GetNextNumber("XSCK");
                sRepository.Insert(sell);

                foreach (var line in sell.Lines)
                {
                    //插入出库明细
                    line.ParentID   = sell.ID;
                    line.CreateBy   = sell.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    slRepository.Insert(line);

                    //更新通知单 添加下推
                    decimal rt = snlRepository.AddDownCount(line.OutCount, line.SourceLineID);
                    if (rt < 0)
                    {
                        dbContext.AbortTransaction();
                        rData.status  = -1;
                        rData.message = BuilderNoticeLessMessage(line);
                        return(rData);
                    }
                }

                //将插入主键赋值给返回值
                rData.result = sell.ID.ToString();

                //更新通知单状态
                if (sell.SourceID > 0)
                {
                    snRepository.UpdateNoticeStatus(NoticeStatusEnum.Executing, sell.SourceID);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }

            return(rData);
        }
コード例 #28
0
        /// <summary>
        /// 根据入库通知添加入库
        /// </summary>
        /// <param name="inNotice"></param>
        /// <returns></returns>
        public ResultData <string> AddTransferIn(WTransferInNotice inNotice, int createBy)
        {
            ResultData <string> rData = new ResultData <string>();

            if (inNotice.NoticeStatus == NoticeStatusEnum.Complete)
            {
                rData.status  = -1;
                rData.message = "单据已完成不能入库.";
                return(rData);
            }
            //克隆主表
            WTransferIn transferIn = CloneInNotice(inNotice);

            transferIn.CreateBy = createBy;

            foreach (var item in inNotice.Lines)
            {
                if (item.InPutCount <= 0)
                {
                    continue;
                }
                //如果通知数量+下推数量+完成数量>当前入库数量
                if (item.InPutCount + item.DownCount + item.CompleteCount > item.InCount)
                {
                    rData.status  = -1;
                    rData.message = BuilderNoticeLessMessage(item);
                    return(rData);
                }
                //克隆明细
                transferIn.Lines.Add(CloneInNoticeLine(item));
                //更新下推数量和当前输入数量
                item.DownCount = item.DownCount + item.InPutCount;
            }

            if (transferIn.Lines.Count < 1)
            {
                rData.status  = -1;
                rData.message = "入库明细为空.";
                return(rData);
            }

            rData = CheckValid(transferIn);
            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = tiRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加入库单
                transferIn.CreateDate     = DateTime.Now;
                transferIn.StockStatus    = StockStatusEnum.New;
                transferIn.TransferInCode = nuRepository.GetNextNumber("DBRK");
                tiRepository.Insert(transferIn);
                foreach (var line in transferIn.Lines)
                {
                    line.ParentID   = transferIn.ID;
                    line.CreateBy   = transferIn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    tilRepository.Insert(line);
                }

                //更新通知单
                foreach (var item in inNotice.Lines)
                {
                    tinlRepository.AddDownCount(item);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }

            //没有放到事务,因为状态更新不是很重要,不影响业务
            bool isAll = tinlRepository.IsAllDownload(inNotice.ID);

            if (isAll)
            {
                tinRepository.UpdateNoticeStatus(NoticeStatusEnum.Complete, inNotice.ID);
            }
            else
            {
                tinRepository.UpdateNoticeStatus(NoticeStatusEnum.Executing, inNotice.ID);
            }
            return(rData);
        }
コード例 #29
0
        /// <summary>
        /// 添加盘亏出库
        /// </summary>
        /// <param name="inv"></param>
        /// <returns></returns>
        public ResultData <string> AddLoss(WInventory inv)
        {
            ResultData <string> rData = new ResultData <string>();

            if (inv.InventoryStatus == InventoryStatusEnum.Out)
            {
                rData.status  = -1;
                rData.message = "单据已经盘亏.";
                return(rData);
            }
            else if (inv.InventoryStatus == InventoryStatusEnum.Complete)
            {
                rData.status  = -1;
                rData.message = "单据已经完成.";
                return(rData);
            }

            if (ilRepository.HasNoLoss(inv.ID))
            {
                if (inv.InventoryStatus == InventoryStatusEnum.In)
                {
                    iRepository.UpdateLossStatus(inv.ID, 0, "", InventoryStatusEnum.Complete);
                }
                else
                {
                    iRepository.UpdateLossStatus(inv.ID, 0, "", InventoryStatusEnum.Out);
                }
                rData.status  = -1;
                rData.message = "单据没有盘亏记录.";
                return(rData);
            }

            DatabaseContext dbContext = ooRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                WOtherOut otherOut = new WOtherOut
                {
                    CreateBy     = inv.CreateBy,
                    CreateDate   = DateTime.Now,
                    OtherOutCode = nuRepository.GetNextNumber("QTCK"),
                    StockOutType = StockOutEnum.InvShortages,
                    StockStatus  = StockStatusEnum.New
                };

                //添加主表
                ooRepository.Insert(otherOut);

                //更新为盘点
                if (inv.InventoryStatus == InventoryStatusEnum.In)
                {
                    iRepository.UpdateLossStatus(inv.ID, otherOut.ID, otherOut.OtherOutCode, InventoryStatusEnum.Complete);
                }
                else if (inv.InventoryStatus == InventoryStatusEnum.Complete)
                {
                    rData.status  = -1;
                    rData.message = "单据已经完成.";
                    return(rData);
                }
                else
                {
                    iRepository.UpdateLossStatus(inv.ID, otherOut.ID, otherOut.OtherOutCode, InventoryStatusEnum.Out);
                }

                //添加明细
                oolRepository.AddOtherLinesByInv(otherOut, inv.ID);

                //返回插入的ID
                rData.result = otherOut.ID.ToString();

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
コード例 #30
0
        /// <summary>
        /// 根据入库单下推出库单
        /// </summary>
        /// <param name="purchase"></param>
        /// <returns></returns>
        public ResultData <string> AddPurchaseReturn(WPurchase purchase, int createBy)
        {
            ResultData <string> rData = new ResultData <string>();

            if (purchase.StockStatus != StockStatusEnum.Approve)
            {
                rData.status  = -1;
                rData.message = "单据未审核不能退库.";
                return(rData);
            }

            //查询明细
            if (purchase.Lines.Count < 1)
            {
                purchase.Lines = plRepository.GetLinesByParentId(purchase.ID);
            }

            //克隆主表
            WPurchaseReturn purReturn = ClonePuchase(purchase);

            purReturn.CreateBy = createBy;
            //克隆子表
            foreach (var item in purchase.Lines)
            {
                WPurchaseReturnLine line = ClonePurchaseLine(item);
                if (line != null)
                {
                    purReturn.Lines.Add(line);
                }
            }

            if (purReturn.Lines.Count < 1)
            {
                rData.status  = -1;
                rData.message = "单据已经全部退库.";
                return(rData);
            }

            DatabaseContext dbContext = pRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加入库单
                purReturn.CreateDate         = DateTime.Now;
                purReturn.StockStatus        = StockStatusEnum.New;
                purReturn.PurchaseReturnCode = nuRepository.GetNextNumber("CGTK");
                prRepository.Insert(purReturn);
                foreach (var line in purReturn.Lines)
                {
                    //插入入库明细
                    line.ParentID   = purReturn.ID;
                    line.CreateBy   = purReturn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    prlRepository.Insert(line);

                    //更新入库单 添加退库
                    decimal rt = plRepository.AddReturnCount(line.OutCount, line.SourceLineID);
                    if (rt < 0)
                    {
                        dbContext.AbortTransaction();
                        rData.status  = -1;
                        rData.message = BuilderNoticeLessMessage(line);
                        return(rData);
                    }
                }

                //将插入主键赋值给返回值
                rData.result = purReturn.ID.ToString();

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }

            return(rData);
        }