Пример #1
0
        private void updateNodeOrder(int nodeId, int rootId)
        {
            var allNodes = UnitOfWork.EntitySet <Report>()
                           .FromSql("CALL getTreeNodes({0},{1})", nodeId, rootId)
                           .ToList();
            var rootNode = allNodes.Find(nd => nd.ReportId == nodeId);

            if (rootNode != null)
            {
                CalaOrder(rootNode);
                UnitOfWork.AcceptAllChanges();
            }
        }
Пример #2
0
        public ResponseMessage <ReportViewModel> DeleteReport(RequestMessage <ReportViewModel> reqMsg)
        {
            var rptViewModel   = reqMsg.Playload.FirstOrDefault();
            var existNodeLists = UnitOfWork?.EntitySet <Report>()
                                 .FromSql("CALL getTreeNodes({0},{1})", rptViewModel.ReportId, rptViewModel.RootId)
                                 .ToList();
            var existNode = existNodeLists.Where(r => r.ReportId == rptViewModel.ReportId)
                            .FirstOrDefault();

            UnitOfWork.DeleteNode(existNode, (nd) => nd.Childs);
            UnitOfWork.AcceptAllChanges();
            if (rptViewModel.RootId != rptViewModel.ReportId)
            {
                updateNodeOrder(rptViewModel.RootId, rptViewModel.RootId);
                UnitOfWork.AcceptAllChanges();
            }
            return(okResponse(rptViewModel));
        }
Пример #3
0
        public ResponseMessage <BomNodeViewModel> DeleteBomNode(RequestMessage <BomNodeViewModel> reqMsg)
        {
            var bomNodeViewModel = reqMsg.Playload.FirstOrDefault();
            var existNodeLists   = UnitOfWork?.EntitySet <BomStructure>()
                                   .FromSql("CALL getBomNodes({0},{1})", bomNodeViewModel.BomStructureId, bomNodeViewModel.RootId)
                                   .ToList();
            var existNode = existNodeLists.Where(r => r.BomStructureId == bomNodeViewModel.BomStructureId).FirstOrDefault();

            UnitOfWork.DeleteNode(existNode, (nd) => nd.Childs);
            UnitOfWork.AcceptAllChanges();
            if (bomNodeViewModel.BomStructureId != bomNodeViewModel.RootId)
            {
                //找出根结点和根版次
                updateNodeOrder(bomNodeViewModel.RootId, bomNodeViewModel.RootId);
                UnitOfWork.AcceptAllChanges();
            }
            return(okResponse(bomNodeViewModel));
        }
Пример #4
0
        private void UpdateAllRefNodeByVersion(int nowRootId, int nowVersionId, int oldVersionId)
        {
            var nowNodes    = GetBomNodesByVersion(nowVersionId, nowRootId);
            var allRefNodes = GetAllRefNodeByVersion(oldVersionId);
            var nowRootNode = nowNodes.Find(nd => nd.ParentId == null && nd.NodeVersionId == nd.RootVersionId);

            Func <BomStructure, BomStructure> getNewNode = bNode => new BomStructure()
            {
                Parent        = bNode,
                ParentId      = bNode.BomStructureId,
                RootVersionId = bNode.RootVersionId,
                RootId        = bNode.RootId
            };
            Action <BomStructure, BomStructure> getConfig = (bNode1, bNode2) =>
            {
                bNode2.BomStructureId = bNode1.BomStructureId;
                bNode2.RootVersionId  = bNode1.RootVersionId;
                bNode2.RootId         = bNode1.RootId;
            };
            Func <BomStructure, BomStructure, bool>   getKey    = (bNode1, bNode2) => bNode1.BomStructureId == bNode2.BomStructureId;
            Func <BomStructure, List <BomStructure> > getChilds = bNode => bNode.Childs;
            Func <BomStructure, int> getCompareKey = bNode => bNode.BomStructureId;

            foreach (var nd in allRefNodes.Where(nd => nd.NodeVersionId == oldVersionId))
            {
                UnitOfWork.UpdateNodeValues(nd, nowRootNode, getChilds, getCompareKey, getKey, getNewNode, getConfig);
                // updateNodeOrder(nd.RootId, nd.RootId);
                var allNodes = UnitOfWork.EntitySet <BomStructure>()
                               .FromSql("CALL getBomNodes({0},{1})", nd.RootId, nd.RootId)
                               .ToList();
                var rootNode = allNodes.Find(bnd => bnd.BomStructureId == nd.RootId);
                if (rootNode != null)
                {
                    CalaOrder(rootNode);
                }
            }
            UnitOfWork.AcceptAllChanges();
        }
Пример #5
0
        public ResponseMessage <ReportViewModel> CreateOrUpdateReport(RequestMessage <ReportViewModel> reqMsg)
        {
            try
            {
                var rptViewModel = reqMsg.Playload.FirstOrDefault();
                if (rptViewModel.ParentId == null || rptViewModel.RootId <= 0)
                {
                    return(BadResponse(rptViewModel));
                }

                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <ReportViewModel, Report>();
                    cfg.CreateMap <Report, ReportViewModel>();
                });

                Func <Report, Report> getNewNode = rpt => new Report()
                {
                    Parent   = rpt,
                    ParentId = rpt.ReportId,
                    RootId   = rpt.RootId
                };
                Action <Report, Report> getConfig = (rpt1, rpt2) =>
                {
                    rpt2.ReportId = rpt1.ReportId;
                    rpt2.RootId   = rpt1.RootId;
                };
                Func <Report, Report, bool>   getKey        = (rpt1, rpt2) => rpt1.ReportId == rpt2.ReportId;
                Func <Report, List <Report> > getChilds     = rpt => rpt.Childs;
                Func <Report, int>            getCompareKey = rpt => rpt.ReportId;

                var nowReport = Mapper.Map <ReportViewModel, Report>(rptViewModel);

                if (nowReport.ReportId <= 0)
                {
                    var existRpt = new Report()
                    {
                        Parent = nowReport.Parent, ParentId = nowReport.Parent.ParentId, RootId = nowReport.RootId
                    };
                    UnitOfWork.InsertEntity(existRpt);
                    UnitOfWork.AddNodeValues(existRpt, nowReport, getChilds, getNewNode, getConfig);
                    nowReport = existRpt;
                }
                else
                {
                    var existReportList = UnitOfWork.EntitySet <Report>()
                                          .FromSql("CALL getTreeNodes({0},{1})", rptViewModel.ReportId, rptViewModel.RootId)
                                          .ToList();
                    var existReport = existReportList.FirstOrDefault(r => r.ReportId == rptViewModel.ReportId);
                    UnitOfWork.UpdateNodeValues(existReport, nowReport, getChilds, getCompareKey, getKey, getNewNode, getConfig);
                    nowReport = existReport;
                }
                UnitOfWork.AcceptAllChanges();
                updateNodeOrder(nowReport.RootId, nowReport.RootId);
                return(okResponse(Mapper.Map <Report, ReportViewModel>(nowReport)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                // return BadResponse(reqMsg.Playload.FirstOrDefault());
            }
            return(BadResponse(new ReportViewModel()));
        }
Пример #6
0
        public ResponseMessage <ReportViewModel> CreateOrUpdateRootReport(RequestMessage <ReportViewModel> reqMsg)
        {
            try
            {
                var rptViewModel = reqMsg.Playload.FirstOrDefault();

                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <ReportViewModel, Report>();
                    cfg.CreateMap <Report, ReportViewModel>();
                });

                Func <Report, Report> getNewNode = rpt => new Report()
                {
                    Parent   = rpt,
                    ParentId = rpt.ReportId,
                    RootId   = rpt.RootId
                };
                Action <Report, Report> getConfig = (rpt1, rpt2) =>
                {
                    rpt2.ReportId = rpt1.ReportId;
                    rpt2.RootId   = rpt1.RootId;
                };
                Func <Report, Report, bool>   getKey        = (rpt1, rpt2) => rpt1.ReportId == rpt2.ReportId;
                Func <Report, List <Report> > getChilds     = rpt => rpt.Childs;
                Func <Report, int>            getCompareKey = rpt => rpt.ReportId;

                var nowReport = Mapper.Map <ReportViewModel, Report>(rptViewModel);

                if (nowReport.ReportId <= 0)
                {
                    var existRpt = new Report()
                    {
                        Parent = null, ParentId = null
                    };
                    UnitOfWork.InsertEntity(existRpt);
                    existRpt.RootId = existRpt.ReportId;
                    UnitOfWork.AddNodeValues(existRpt, nowReport, getChilds, getNewNode, getConfig);
                    nowReport = existRpt;
                }
                else
                {
                    var existReportList = UnitOfWork.EntitySet <Report>()
                                          .Where(r => r.RootId == rptViewModel.ReportId)
                                          .ToList();
                    var existReport = existReportList.FirstOrDefault(r => r.ReportId == rptViewModel.ReportId && r.ParentId == null);
                    nowReport.Parent   = null;
                    nowReport.ParentId = null;
                    UnitOfWork.UpdateNodeValues(existReport, nowReport, getChilds, getCompareKey, getKey, getNewNode, getConfig);
                    nowReport = existReport;
                }
                CalaOrder(nowReport);
                UnitOfWork.AcceptAllChanges();
                if (nowReport.RootId < 0)
                {
                    // var retCount = UnitOfWork.ExecuteSqlCommand("update Reports set RootId = {1} where RootId ={0}", nowReport.RootId, nowReport.ReportId);
                    UnitOfWork.UpdateLocalNodeValues(nowReport, (nd) => nd.Childs, (nd) => nd.RootId = nowReport.ReportId);
                    UnitOfWork.AcceptAllChanges();
                }
                return(okResponse(Mapper.Map <Report, ReportViewModel>(nowReport)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                // return BadResponse(reqMsg.Playload.FirstOrDefault());
            }
            return(BadResponse(new ReportViewModel()));
        }
Пример #7
0
        public ResponseMessage <BomNodeViewModel> UpsertBomNode(RequestMessage <BomNodeViewModel> reqMsg)
        {
            try
            {
                var bNodeViewModel = reqMsg.Playload.FirstOrDefault();
                if (bNodeViewModel.ParentId == null || bNodeViewModel.BomStructureId <= 0)
                {
                    return(BadResponse(bNodeViewModel));
                }

                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <BomNodeViewModel, BomStructure>();
                    cfg.CreateMap <BomStructure, BomNodeViewModel>();
                });

                Func <BomStructure, BomStructure> getNewNode = bNode => new BomStructure()
                {
                    Parent        = bNode,
                    ParentId      = bNode.BomStructureId,
                    RootVersionId = bNode.RootVersionId,
                    RootId        = bNode.RootId
                };
                Action <BomStructure, BomStructure> getConfig = (bNode1, bNode2) =>
                {
                    bNode2.BomStructureId = bNode1.BomStructureId;
                    bNode2.RootVersionId  = bNode1.RootVersionId;
                    bNode2.RootId         = bNode1.RootId;
                };
                Func <BomStructure, BomStructure, bool>   getKey    = (bNode1, bNode2) => bNode1.BomStructureId == bNode2.BomStructureId;
                Func <BomStructure, List <BomStructure> > getChilds = bNode => bNode.Childs;
                Func <BomStructure, int> getCompareKey = bNode => bNode.BomStructureId;

                var nowBomNode = Mapper.Map <BomNodeViewModel, BomStructure>(bNodeViewModel);

                if (nowBomNode.BomStructureId <= 0)
                {
                    var existBNode = new BomStructure()
                    {
                        Parent        = nowBomNode.Parent,
                        ParentId      = nowBomNode.Parent.ParentId,
                        RootVersionId = nowBomNode.RootVersionId,
                        RootId        = nowBomNode.RootId
                    };
                    UnitOfWork.InsertEntity(existBNode);
                    UnitOfWork.AddNodeValues(existBNode, nowBomNode, getChilds, getNewNode, getConfig);
                    nowBomNode = existBNode;
                }
                else
                {
                    var existBomNodeList = UnitOfWork.EntitySet <BomStructure>()
                                           .FromSql("CALL getBomNodes({0},{1})", bNodeViewModel.BomStructureId, bNodeViewModel.RootId)
                                           .ToList();
                    var existBNode = existBomNodeList.FirstOrDefault(r => r.BomStructureId == bNodeViewModel.BomStructureId);
                    UnitOfWork.UpdateNodeValues(existBNode, nowBomNode, getChilds, getCompareKey, getKey, getNewNode, getConfig);
                    nowBomNode = existBNode;
                }
                UnitOfWork.AcceptAllChanges();
                updateNodeOrder(nowBomNode.RootId, nowBomNode.RootId);
                return(okResponse(Mapper.Map <BomStructure, BomNodeViewModel>(nowBomNode)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                // return BadResponse(reqMsg.Playload.FirstOrDefault());
            }
            return(BadResponse(new BomNodeViewModel()));
        }
Пример #8
0
        public ResponseMessage <BomNodeViewModel> UpsertRootBomNode(RequestMessage <BomNodeViewModel> reqMsg)
        {
            try
            {
                var bNodeViewModel = reqMsg.Playload.FirstOrDefault();
                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <BomNodeViewModel, BomStructure>();
                    cfg.CreateMap <BomStructure, BomNodeViewModel>();
                    cfg.CreateMap <ProductVersion, ProductVersionViewModel>();
                    cfg.CreateMap <ProductVersionViewModel, ProductVersion>();
                    cfg.CreateMap <Product, ProductViewModel>();
                    cfg.CreateMap <ProductViewModel, Product>();
                });

                Func <BomStructure, BomStructure> getNewNode = bs => new BomStructure()
                {
                    Parent        = bs,
                    ParentId      = bs.BomStructureId,
                    RootVersionId = bs.RootVersionId,
                    RootId        = bs.RootId
                };
                Action <BomStructure, BomStructure> getConfig = (bs1, bs2) =>
                {
                    bs2.BomStructureId = bs1.BomStructureId;
                    bs2.RootVersionId  = bs1.RootVersionId;
                    bs2.RootId         = bs1.RootId;
                };
                Func <BomStructure, BomStructure, bool>   getKey    = (bNode1, bNode2) => bNode1.BomStructureId == bNode2.BomStructureId;
                Func <BomStructure, List <BomStructure> > getChilds = bNode => bNode.Childs;
                Func <BomStructure, int> getCompareKey = bNode => bNode.BomStructureId;

                var nowBomNode = Mapper.Map <BomNodeViewModel, BomStructure>(bNodeViewModel);

                if (nowBomNode.BomStructureId <= 0)
                {
                    var existBomNode = new BomStructure()
                    {
                        Parent = null, ParentId = null, RootVersionId = nowBomNode.NodeVersionId
                    };
                    UnitOfWork.InsertEntity(existBomNode);
                    existBomNode.RootId = existBomNode.BomStructureId;
                    UnitOfWork.AddNodeValues(existBomNode, nowBomNode, getChilds, getNewNode, getConfig);
                    nowBomNode = existBomNode;
                }
                else
                {
                    var existBomNodeList = UnitOfWork.EntitySet <BomStructure>()
                                           .Where(bomNd => bomNd.RootId == bNodeViewModel.BomStructureId)
                                           .ToList();
                    var existBomNode = existBomNodeList.FirstOrDefault(bomNd => bomNd.BomStructureId == bNodeViewModel.BomStructureId && bomNd.ParentId == null);
                    nowBomNode.Parent   = null;
                    nowBomNode.ParentId = null;
                    UnitOfWork.UpdateNodeValues(existBomNode, nowBomNode, getChilds, getCompareKey, getKey, getNewNode, getConfig);
                    nowBomNode = existBomNode;
                }
                CalaOrder(nowBomNode); //计算序号,层次,结点左序号,结点右序号,数量
                                       // CalaNeedTotal(nowBomNode); //计算数量
                UnitOfWork.AcceptAllChanges();
                if (nowBomNode.RootId < 0)
                {
                    // var retCount = UnitOfWork.ExecuteSqlCommand("update Reports set RootId = {1} where RootId ={0}", nowReport.RootId, nowReport.ReportId);
                    UnitOfWork.UpdateLocalNodeValues(nowBomNode, (nd) => nd.Childs, (nd) => nd.RootId = nowBomNode.BomStructureId);
                    UnitOfWork.AcceptAllChanges();
                }
                return(okResponse(Mapper.Map <BomStructure, BomNodeViewModel>(nowBomNode)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                // return BadResponse(reqMsg.Playload.FirstOrDefault());
            }
            return(BadResponse(new BomNodeViewModel()));
        }