public JsonResult Update(int id)
        {
            JavaScriptSerializer serialize = new JavaScriptSerializer();
            PDCPMS.DataContracts.Income.DeliverNotice noticeContract =
                serialize.Deserialize<PDCPMS.DataContracts.Income.DeliverNotice>(Request.Form["notice"]);

            if (noticeContract == null)
            {
                return Json(new { success = false, message = "输入有误" });
            }

            bool isDataValid = true;
            DeliverNotice notice = repository.FindByNotCache(id);

            notice.CompanyContract = noticeContract.CompanyContract;
            notice.DateDelivering = noticeContract.DateDelivering;
            notice.Fax = noticeContract.Fax;
            notice.ProductContractNO = noticeContract.ProductContractNO;
            notice.Sender = noticeContract.Sender;
            notice.Sign = noticeContract.Sign;
            notice.Telephone = noticeContract.Telephone;

            if (notice.GetBrokenRules().Count != 0)
            {
                return Json(new { success = false, message = "输入有误" });
            }
            else
            {
                repository[notice.Key] = notice;
            }

            notice.Waggons = RepositoryFactory.GetRepository<IDeliverWaggonRepository, DeliverWaggon>().FindBy(notice);
            IDeliverWaggonRepository waggonRepository = RepositoryFactory.GetRepository<IDeliverWaggonRepository, DeliverWaggon>(unitOfWork);

            for (int i = notice.Waggons.Count - 1; i > -1; i--)
            {
                DeliverWaggon waggon = notice.Waggons[i];

                PDCPMS.DataContracts.Income.DeliverWaggon w = noticeContract.Waggons.Where(wc => wc.Key == (long)waggon.Key).FirstOrDefault();
                if (w == null)
                {
                    // Delete Waggon
                    waggonRepository.Remove(waggon);
                }
                else
                {
                    waggon.NumberPlate = w.NumberPlate;
                    waggon.EstimatedNO = w.EstimatedNO;

                    waggonRepository[waggon.Key] = waggon;
                }
            }

            foreach (PDCPMS.DataContracts.Income.DeliverWaggon w in noticeContract.Waggons)
            {
                if (w.Key == 0)
                {
                    DeliverWaggon waggon = new DeliverWaggon(0, notice);
                    waggon.EstimatedNO = w.EstimatedNO;
                    waggon.NumberPlate = w.NumberPlate;

                    if (waggon.GetBrokenRules().Count != 0)
                    {
                        isDataValid = false;
                        break;
                    }

                    waggonRepository.Add(waggon);
                }
            }

            if (isDataValid)
            {
                unitOfWork.Commit();
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "修改来料通知单成功" };
            }
            else
            {
                return Json(new { success = false, message = "输入有误" });
            }

            return Json(new { success = true });
        }
Esempio n. 2
0
 public Pipe(long key, PipeType type, PipeCategory category, DetectionCompany company, PipeOwner owner, Producer producer,
     Supplier supplier, DeliverNotice notice, DeliverWaggon waggon)
     : base(key)
 {
     this.PipeType = type;
     this.Category = category;
     this.DetectionCompany = company;
     this.Owner = owner;
     this.Producer = producer;
     this.Supplier = supplier;
     this.DeliverNotice = notice;
     this.DeliverWaggon = waggon;
 }
        public JsonResult Create()
        {
            JavaScriptSerializer serialize = new JavaScriptSerializer();
            PDCPMS.DataContracts.Income.DeliverNotice noticeContract =
                serialize.Deserialize<PDCPMS.DataContracts.Income.DeliverNotice>(Request.Form["notice"]);

            string CompanyId = null;
            string ProducerId = null;
            if (!string.IsNullOrEmpty(Request.Form["CompanyId"]))
            {
                CompanyId = Request.Form["CompanyId"].ToString();
            }
            if (!string.IsNullOrEmpty(Request.Form["ProducerId"]))
            {
                ProducerId = Request.Form["ProducerId"].ToString();
            }

            if (noticeContract == null)
            {
                return Json(new { success = false, message = "输入有误" });
            }
            bool isDataValid = true;
            DeliverNotice notice = new DeliverNotice(0,
                RepositoryFactory.GetRepository<IDetectionCompanyRepository, DetectionCompany>().FindBy(CompanyId),
                UserSession.OnlineAccount,
                RepositoryFactory.GetRepository<IPipeTypeRepository, PipeType>().FindBy(noticeContract.PipeTypeId),
                DateTime.Now);
            notice.CompanyContract = noticeContract.CompanyContract;
            notice.DateDelivering = noticeContract.DateDelivering;
            notice.DeliverMethod = (DeliverMethod)noticeContract.DeliverMethod;
            notice.Fax = noticeContract.Fax;
            notice.Producer = RepositoryFactory.GetRepository<IProducerRepository, Producer>().FindBy(ProducerId);
            notice.ProductContractNO = noticeContract.ProductContractNO;
            notice.Sender = noticeContract.Sender;
            notice.Sign = noticeContract.Sign;
            notice.State = DeliverNoticeState.NotVerified;
            notice.Supplier = RepositoryFactory.GetRepository<ISupplierRepository, Supplier>().FindBy(noticeContract.SupplierId);
            notice.Telephone = noticeContract.Telephone;

            if (notice.GetBrokenRules().Count != 0)
            {
                return Json(new { success = false, message = "输入有误" });
            }
            else
            {
                repository.Add(notice);
            }

            foreach (PDCPMS.DataContracts.Income.DeliverWaggon w in noticeContract.Waggons)
            {
                DeliverWaggon waggon = new DeliverWaggon(0, notice);
                waggon.EstimatedNO = w.EstimatedNO;
                waggon.NumberPlate = w.NumberPlate;

                if (waggon.GetBrokenRules().Count != 0)
                {
                    isDataValid = false;
                    break;
                }

                notice.Waggons.Add(waggon);
            }

            if (isDataValid)
            {
                unitOfWork.Commit();
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "成功添加来料通知单" };
            }
            else
            {
                return Json(new { success = false, message = "输入有误" });
            }

            return Json(new { success = true });
        }
Esempio n. 4
0
        public void CopyTo(DeliverWaggon waggon)
        {
            if (waggon == null) throw new ArgumentNullException("waggon");

            waggon.ActualNO = this.ActualNO;
            waggon.AttachmentPath = this.AttachmentPath;
            waggon.Checker = this.Checker;
            waggon.EstimatedNO = this.EstimatedNO;
            waggon.NumberPlate = this.NumberPlate;
            waggon.ReceiveTime = this.ReceiveTime;
        }