Beispiel #1
0
        // Display ViewRegitrasionInformation
        public ActionResult ViewRegitrasionInfomation(int?fileExcelId, int?truckStatus)
        {
            Logger.Info("ViewRegitrasionInfomation for file Excel with id = " + fileExcelId);
            List <ExcelDetail>  list      = null;
            ListResultViewModel listModel = null;

            // Filter by truckStatus if it have. If not will get all
            try
            {
                ViewBag.fileExcelId = fileExcelId ?? default(int);
                list = new List <ExcelDetail>();
                // Get list of excel rows was filtered
                if (truckStatus.HasValue)
                {
                    list = _excelDetailService.GetListByStatus(fileExcelId ?? default(int), truckStatus.Value);
                }
                // Get all excel rows
                else
                {
                    list = _excelDetailService.GetListByFileExcelId(fileExcelId ?? default(int));
                }
                var fileExcel       = _fileExeclService.GetById(fileExcelId ?? default(int));
                var listExcelDetail = new List <ResultViewModel>();
                // Assign data to list ResultViewModel
                foreach (var item in list)
                {
                    string result    = DefineStatus(item.TruckStatus);
                    var    rowResult = new ResultViewModel
                    {
                        TruckNo     = item.TruckNo,
                        ChassicNo   = item.ChassisNo,
                        DriverName  = item.DriverName,
                        DriverId    = item.DriverId,
                        Result      = result,
                        TruckStatus = item.TruckStatus
                    };
                    listExcelDetail.Add(rowResult);
                }
                // Assign data to ListReultViewModel
                listModel                  = new ListResultViewModel();
                listModel.VesselCode       = _oraVoyage.GetByVoyCode(fileExcel.VoyCode).CODE;
                listModel.VesselName       = _oraVoyage.GetByVoyCode(fileExcel.VoyCode).NAME;
                listModel.Customer         = _cusService.GetById(fileExcel.CustomerId ?? default(int)).NAME;
                listModel.FileName         = fileExcel.ExcelName;
                listModel.ResultViewModels = listExcelDetail;
                // Create ListItem for FliterDropdownlist
                List <SelectListItem> listItem = FilterDropDown(truckStatus);
                ViewBag.Items = listItem;
            }
            catch (Exception ex)
            {
                Logger.Info(ex.Message, ex);
                return(RedirectToAction("Error", "Log"));
            }
            return(View("ViewRegitrasionInfomation", listModel));
        }
Beispiel #2
0
 ///
 /// <summary>
 /// Assign Truck to Voyage
 /// </summary>
 /// <param name="trkNo">Truck No</param>
 /// <param name="voyId">Voyage Id</param>
 /// <param name="partnerId">Partner id</param>
 /// <returns></returns>
 ///
 public bool AssignTrkToVoy(string trkNo, string voyCode, int partnerId)
 {
     Logger.Info("AssignTrkToVoy trkNo=" + trkNo + " voyCode=" + voyCode + " partnerId=" + partnerId);
     try
     {
         PARTNER_TRUCK assigned;
         _oraTruckService           = new OraTruckService();
         _oraTruckPartnerRepository = new OraTruckPartnerRepository();
         _oraVoyageService          = new OraVoyageService();
         _oraPartnerRepository      = new OraPartnerRepository();
         //Find Voyage by voyage code
         var voyage = _oraVoyageService.GetByVoyCode(voyCode);
         //Find Truck by truck no
         var truck = _oraTruckService.GetByTruckNo(trkNo);
         //Find Partner by Id
         var partner = _oraPartnerRepository.GetById(partnerId);
         //Check if voyage or truck or parner is in database
         if (voyage == null || truck == null || partner == null)
         {
             return(false);
         }
         //Create an Assigned object
         assigned = new PARTNER_TRUCK
         {
             PNR_ID = partnerId,
             TRK_ID = truck.ID,
             VOY_ID = voyage.ID
         };
         _oraTruckPartnerRepository.Insert(assigned);
         return(true);
     }
     catch (Exception e)
     {
         Logger.Error("AssignTrkToVoy Error: ", e);
         throw e;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Get Truck Information
 /// </summary>
 /// <param name="excelId">excel detail Id</param>
 /// <returns>View</returns>
 public ActionResult GetInfoRegis(int excelId, int?excelDetailId)
 {
     try
     {
         var model = new GetRegisInfoViewModel();
         int truckOnProcessingId = 0;
         if (TempData[Resource_GetTruck.truckinfo] != null)
         {
             var truckinfo = (TRUCK)TempData[Resource_GetTruck.truckinfo];
             if (truckinfo.ID != 0)
             {
                 model.Truck = truckinfo;
             }
         }
         var lstExcelDetail = _excelDetailService.GetListByFileExcelId(excelId).ToList();
         if (lstExcelDetail.Any())
         {
             var chuathaotac = new ExcelDetail();
             if (excelDetailId == null)
             {
                 chuathaotac = lstExcelDetail.Where(x => x.TruckStatus == TruckStatus.NotYetCheck).FirstOrDefault();
             }
             else
             {
                 chuathaotac = lstExcelDetail.Where(x => x.Id == excelDetailId).FirstOrDefault();
             }
             if (chuathaotac != null)
             {
                 ConnectToVR();
                 model.OnProcessing  = true;
                 model.ExcelDetailId = chuathaotac.Id;
                 model.FileExcelId   = chuathaotac.FileExcelId;
                 if (chuathaotac.TruckNo != null)
                 {
                     model.LicensePlate = chuathaotac.TruckNo;
                 }
                 else
                 {
                     model.LicensePlate = chuathaotac.ChassisNo;
                 }
                 truckOnProcessingId   = chuathaotac.Id;
                 model.CaptchaURL      = TempData[Resource_GetTruck.captchaURL].ToString();
                 model.HaveNotCheckYet = true;
             }
             else
             {
                 var randomtruck = lstExcelDetail.FirstOrDefault();
                 truckOnProcessingId = randomtruck.Id;
                 if (randomtruck.TruckNo != null)
                 {
                     model.Truck = _oraTruckService.GetByTruckNo(randomtruck.TruckNo);
                 }
                 else
                 {
                     model.Truck = _oraTruckService.GetByTruckNo(randomtruck.ChassisNo);
                 }
                 model.LicensePlate = randomtruck.TruckNo;
                 //model.Status = TruckStatus.OnProcessing;
                 model.OnProcessing    = true;
                 model.HaveNotCheckYet = false;
             }
             lstExcelDetail.ForEach(x =>
             {
                 var newPlate = new PlateViewModel
                 {
                     PlateStatus   = x.TruckStatus,
                     ExcelDetailId = x.Id,
                 };
                 if (x.Id == truckOnProcessingId)
                 {
                     newPlate.OnProcessing = true;
                 }
                 if (x.TruckNo != null)
                 {
                     newPlate.PlateNo = x.TruckNo;
                 }
                 else
                 {
                     newPlate.PlateNo = x.ChassisNo;
                 }
                 model.PlateLst.Add(newPlate);
             });
             var getFileExceldata = _fileExcelService.GetById(lstExcelDetail.FirstOrDefault().FileExcelId);
             model.Customer = _customerService.GetById(getFileExceldata.CustomerId.Value).NAME;
             //model.Customer = "Green Feed"; //for testing
             model.VesselName = _oraVoyageService.GetByVoyCode(getFileExceldata.VoyCode).NAME;
             //model.VesselName = "Thong Nhat 1"; //for testing
             if (TempData[Resource_GetTruck.errorWhenSubmit] != null)
             {
                 TempData[Resource_GetTruck.message] = TempData[Resource_GetTruck.errorWhenSubmit].ToString();
             }
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         Logger.Info("GetInfoRegis:", ex);
         return(View()); //for testing
     }
 }
Beispiel #4
0
 ///
 /// <summary>
 /// Save file's content to database
 /// Separate Truck and Remooc
 /// </summary>
 /// <param name="lstExcelDetail">the content need to be saved</param>
 /// <param name="voyId">Voyage Id</param>
 /// <returns></returns>
 ///
 private bool SaveExcelDetail(List <ExcelDetail> lstExcelDetail, string voyCode, int partnerId)
 {
     Logger.Info("SaveExcelDetail voyCode=" + voyCode);
     try
     {
         foreach (var detail in lstExcelDetail)
         {
             //Check if truck in file content has TruckNo
             if (!string.IsNullOrEmpty(detail.TruckNo))
             {
                 VOYAGE voyage = _oraVoyageService.GetByVoyCode(voyCode);
                 //Get Truck's status
                 detail.TruckStatus = IsTruckValidForVoy(detail.TruckNo, voyage.ID);
                 ExcelDetail entityTruck  = null;
                 ExcelDetail entityRemooc = null;
                 ExcelDetail detailRemooc = null;
                 //Check if truck has remooc
                 if (!string.IsNullOrEmpty(detail.ChassisNo))
                 {
                     //Create ExcelDetail object contains info of remooc
                     detailRemooc = SetRemoocInfo(detail, voyage.ID);
                     //set Truck's remooc null
                     detail.ChassisNo = null;
                 }
                 //entity ExcelDetail contains Truck's info
                 entityTruck = _excelDetailRepository.Insert(detail);
                 //Check if there is remooc
                 if (detailRemooc != null)
                 {
                     detailRemooc.LinkedId = entityTruck.Id; //Remooc used by tractor
                     entityRemooc          = _excelDetailRepository.Insert(detailRemooc);
                 }
                 //Not null if inserting ExcelDetail object successfully
                 if (entityTruck != null)
                 {
                     //Check if entity ExcelDetail contains Remooc's info is not null
                     if (entityRemooc != null)
                     {
                         //Contractor has remooc
                         InsertTruckAfterChecking(entityTruck, STR_CONST_TRACTOR);
                         InsertTruckAfterChecking(entityRemooc, STR_CONST_REMOOC);
                         AssignTruckToVoyage(entityTruck.TruckNo, voyCode, partnerId);
                         AssignTruckToVoyage(entityRemooc.TruckNo, voyCode, partnerId);
                     }
                     else
                     {
                         //Truck Type
                         InsertTruckAfterChecking(entityTruck, STR_CONST_TRUCK);
                         AssignTruckToVoyage(entityTruck.TruckNo, voyCode, partnerId);
                     }
                 }
                 else
                 {
                     return(false); //Can't add
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error("SaveExcelDetail Error: ", e);
         throw e;
     }
     return(true);
 }