public ActionResult AjaxStationEquipmentsRepairAdd(int StoragesInfoID, string StationNum, string SparePartsCode, string Resonance, string PhenomenalDescription, string HandlingVResults, bool UpRepair, string Reportor, string Repairer, string ReportDate, string FaultStartDate, string FaultEndDate)
 {
     try
     {
         using (InfoManageDataContext context = new InfoManageDataContext())
         {
             if (FaultEndDate == AllConsts.MAX_DATE_HOUR_MINUTE && UpRepair == false)
                 return Json("结束时间空!", JsonRequestBehavior.AllowGet);
             StationEquipmentsRepair newStationEquipmentsMaintenance = new StationEquipmentsRepair();
             newStationEquipmentsMaintenance.StoragesInfoID = StoragesInfoID;
             newStationEquipmentsMaintenance.StationNum = StationNum;
             newStationEquipmentsMaintenance.SparePartsCode = SparePartsCode;
             newStationEquipmentsMaintenance.FaultStartDate = DateTime.ParseExact(FaultStartDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
             if (FaultEndDate == AllConsts.MAX_DATE_HOUR_MINUTE)
                 newStationEquipmentsMaintenance.FaultEndDate = DateTime.ParseExact(AllConsts.MAX_DATE_HOUR_MINUTE, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
             else
                 newStationEquipmentsMaintenance.FaultEndDate = DateTime.ParseExact(FaultEndDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
             newStationEquipmentsMaintenance.Resonance = Resonance;
             newStationEquipmentsMaintenance.PhenomenalDescription = PhenomenalDescription;
             newStationEquipmentsMaintenance.HandlingVResults = HandlingVResults;
             newStationEquipmentsMaintenance.UpRepair = UpRepair;
             newStationEquipmentsMaintenance.Reportor = Reportor;
             newStationEquipmentsMaintenance.Repairer = Repairer;
             newStationEquipmentsMaintenance.ReportDate = DateTime.Now;
             if (newStationEquipmentsMaintenance.FaultEndDate < newStationEquipmentsMaintenance.FaultStartDate)
                 return Json("开始时间不能大于结束时间!", JsonRequestBehavior.AllowGet);
             StationEquipmentsRepair result = context.StationEquipmentsRepairs.Where(c => c.StationNum.Equals(StationNum) && c.ReportDate.Year.Equals(newStationEquipmentsMaintenance.ReportDate.Year) && c.ReportDate.Month.Equals(newStationEquipmentsMaintenance.ReportDate.Month) && c.ReportDate.Day.Equals(newStationEquipmentsMaintenance.ReportDate.Day)).FirstOrDefault();
             if (result == null)
             {
                 context.StationEquipmentsRepairs.Add(newStationEquipmentsMaintenance);
                 if (newStationEquipmentsMaintenance.UpRepair)
                 {
                     StoragesInfo storage = context.StoragesInfos.Where(c => c.StoragesInfoID.Equals(StoragesInfoID)).FirstOrDefault();
                     UpRequest newRequest = new UpRequest();
                     newRequest.IsBack = false;
                     newRequest.BackIsRead = false;
                     newRequest.Requester = newStationEquipmentsMaintenance.Reportor;
                     newRequest.RequestText = storage.StoragesInfoName + "," + StationNum + ",<code>设备</code>编号:" + SparePartsCode + ",请求维修!";
                     newRequest.RequestDate = DateTime.Now;
                     newRequest.RebackDate = newRequest.RequestDate;
                     newRequest.ToUnit = (int)AllConsts.BAOZHANG_UNIT_NUM;
                     context.UpRequests.Add(newRequest);
                 }
                 context.SaveChanges();
             }
             else
             {
                 result.Resonance = newStationEquipmentsMaintenance.Resonance;
                 result.PhenomenalDescription = newStationEquipmentsMaintenance.PhenomenalDescription;
                 result.HandlingVResults = newStationEquipmentsMaintenance.HandlingVResults;
                 result.UpRepair = newStationEquipmentsMaintenance.UpRepair;
                 result.FaultStartDate = newStationEquipmentsMaintenance.FaultStartDate;
                 result.FaultEndDate = newStationEquipmentsMaintenance.FaultEndDate;
                 result.ReportDate = newStationEquipmentsMaintenance.ReportDate;
                 result.Reportor = newStationEquipmentsMaintenance.Reportor;
                 result.Repairer = newStationEquipmentsMaintenance.Repairer;
                 if (newStationEquipmentsMaintenance.UpRepair)
                 {
                     StoragesInfo storage = context.StoragesInfos.Where(c => c.StoragesInfoID.Equals(StoragesInfoID)).FirstOrDefault();
                     UpRequest newRequest = new UpRequest();
                     newRequest.IsBack = false;
                     newRequest.BackIsRead = false;
                     newRequest.Requester = newStationEquipmentsMaintenance.Reportor;
                     newRequest.RequestText = storage.StoragesInfoName + "," + StationNum + ",<code>设备</code>编号:" + SparePartsCode + ",请求维修!";
                     newRequest.RequestDate = DateTime.Now;
                     newRequest.RebackDate = newRequest.RequestDate;
                     newRequest.ToUnit = (int)AllConsts.BAOZHANG_UNIT_NUM;
                     context.UpRequests.Add(newRequest);
                 }
                 context.SaveChanges();
             }
             return Json("OK", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
Exemplo n.º 2
0
 public ActionResult AjaxSetUpRequest(string Requester, string RequestText, int ToUnit)
 {
     try
     {
         using (InfoManageDataContext context = new InfoManageDataContext())
         {
             UpRequest newRequest = new UpRequest();
             newRequest.IsBack = false;
             newRequest.BackIsRead = false;
             newRequest.Requester = Requester;
             newRequest.RequestText = RequestText;
             newRequest.RequestDate = DateTime.Now;
             newRequest.RebackDate = newRequest.RequestDate;
             newRequest.ToUnit = ToUnit;
             UpRequest olodRequest = context.UpRequests.Where(c => c.Requester.Equals(Requester) && c.RequestDate.Year.Equals(DateTime.Now.Year) && c.RequestDate.Month.Equals(DateTime.Now.Month) && c.RequestDate.Day.Equals(DateTime.Now.Day) && c.RequestDate.Hour.Equals(DateTime.Now.Hour) && c.RequestDate.Minute.Equals(DateTime.Now.Minute)).FirstOrDefault();
             if (olodRequest == null)
             {
                 context.UpRequests.Add(newRequest);
             }
             else
             {
                 olodRequest.Requester = newRequest.Requester;
                 olodRequest.RequestText = newRequest.RequestText;
                 olodRequest.ToUnit = newRequest.ToUnit;
             }
             context.SaveChanges();
             return Json("OK", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }