Пример #1
0
 public PipeOutgoingRecord(string key, OutgoingNotice notice, Pipe pipe, DateTime dateCreated)
     : base(key)
 {
     this.OutgoingNotice = notice;
     this.Pipe = pipe;
     this.DateCreated = dateCreated;
 }
        protected IEnumerable<PDCPMS.Model.Common.Pipe> Find(OutgoingNotice notice)
        {
            try
            {
                if (notice == null)
                {
                    throw new ArgumentNullException("OutgoingNotice is null!!!");
                }

                //Account onlineAccount = UserSession.OnlineAccount;
                IPipeRepository pipeRepository = RepositoryFactory.GetRepository<IPipeRepository, PDCPMS.Model.Common.Pipe>(unitOfWork);

                // Li Zheng 2010.11.14
                //IList<PDCPMS.Model.Common.Pipe> pipes = pipeRepository.FindAll();
                IList<PDCPMS.Model.Common.Pipe> pipes = pipeRepository.FindBy(notice);

                //IList<PDCPMS.Model.Common.Pipe> results = new List<PDCPMS.Model.Common.Pipe>();

                // 不需要执行
                //foreach (var p in pipes)
                //{
                //    if (PipePolicy.CanSentout(p) &&
                //        p.BusinessLength.HasValue &&
                //        p.WorkLength.HasValue &&
                //        p.Weight.HasValue &&
                //        (int)p.PipeType.Key == (int)notice.PipeType.Key
                //        )
                //    {
                //        results.Add(p); ;
                //    }
                //}

                return pipes.AsEnumerable();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Create(string Key, String DiggerId, int PipeTypeId, float Need, string Project, string Instruction)
        {
            IPipeRepository pipeRepository = RepositoryFactory.GetRepository<IPipeRepository, PDCPMS.Model.Common.Pipe>(unitOfWork);
            IPipeTypeRepository ptRepository = RepositoryFactory.GetRepository<IPipeTypeRepository, PipeType>(unitOfWork);

            if (DiggerId == null)
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("页面信息丢失,发料通知单({0})添加失败!", Key), DisappearDelay = 5000, Type = HintMessageType.Error };
            }

            PipeType pt = ptRepository.FindBy(PipeTypeId);
            //Digger digger = RepositoryFactory.GetRepository<IDiggerRepository, Digger>().FindBy(DiggerId);
            Digger digger = RepositoryFactory.GetRepository<IDiggerRepository, Digger>().FindNoCache(DiggerId);

            if (digger == null && digger.Name==null)
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("找不到井名,发料通知单({0})添加失败!", Key), DisappearDelay = 5000, Type = HintMessageType.Error };
            }

            Account onlineAccount = UserSession.OnlineAccount;

            Key = onlineAccount.DetectionCompany.Code + Key;
            OutgoingNotice notice = new OutgoingNotice(Key, onlineAccount.DetectionCompany, pt, digger, onlineAccount, DateTime.Now);
            notice.Need = Need;
            notice.Project = Project;
            notice.Instruction = Instruction;
            notice.State = OutgoingNoticeState.Created;

            if (repository.FindByNotCache(Key) != null)
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("发料通知单号{0}已存在,请尝试使用其他编号", Key) };
                TempData["InvalidModel"] = notice;
            }
            if (digger == null || onlineAccount == null || pt == null)
            {
                TempData["InvalidModel"] = notice;
                TempData["InvalidModel"] = notice;

                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("发料通知单({0})添加失败!", Key), DisappearDelay = 5000, Type = HintMessageType.Error };
            }
            else
            {
                repository.Add(notice);
                unitOfWork.Commit();

                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("发料通知单({0})添加成功", Key), DisappearDelay = 5000 };
            }

            return RedirectToAction("Add");
        }