Exemplo n.º 1
0
 ///
 /// <summary>
 /// Create Remooc object from row data of file excel
 /// </summary>
 /// <param name="detail">Row data of file excel read before</param>
 /// <param name="voyId">Voyage Id</param>
 /// <returns></returns>
 ///
 private ExcelDetail SetRemoocInfo(ExcelDetail detail, int voyId)
 {
     Logger.Info("SetChassisInfo voyId=" + voyId);
     try
     {
         //Set value for Remooc object
         ExcelDetail RemoocInfo = new ExcelDetail
         {
             ChassisNo   = detail.ChassisNo,
             LinkedId    = detail.Id,
             DriverId    = detail.DriverId,
             DriverName  = detail.DriverName,
             LicenseNo   = detail.LicenseNo,
             FileExcelId = detail.FileExcelId
         };
         //Get Remooc's status
         RemoocInfo.TruckStatus = IsTruckValidForVoy(RemoocInfo.ChassisNo, voyId);
         return(RemoocInfo);
     }
     catch (Exception e)
     {
         Logger.Error("SetChassisInfo Error", e);
         throw e;
     }
 }
Exemplo n.º 2
0
 ///
 /// <summary>
 /// Store truck's info in file excel into database
 /// </summary>
 /// <param name="detail">truck's info</param>
 ///
 private void InsertTruckAfterChecking(ExcelDetail detail, string truckType)
 {
     Logger.Info("InsertTruck truckType=" + truckType);
     try
     {
         TRUCK truck = null;
         if (!string.IsNullOrEmpty(detail.TruckNo))
         {
             //Find truck in database by Truck No
             truck = _oraTruckService.GetByTruckNo(detail.TruckNo);
         }
         else
         {
             //Not a truck or tractor
             //Find truck by Remooc No
             truck = _oraTruckService.GetByTruckNo(detail.ChassisNo);
         }
         if (truck == null)
         {
             //There isn't the truck in database before
             //Create new truck object
             List <ExcelDetail> lstExcel = new List <ExcelDetail>();
             lstExcel.Add(detail);
             //get Truck No or Chassis No
             var   TruckNo  = !string.IsNullOrEmpty(detail.TruckNo) ? detail.TruckNo : detail.ChassisNo;
             TRUCK newTruck = new TRUCK
             {
                 TRK_NO   = TruckNo,
                 TRK_TYPE = truckType
             };
             var addedTruck = _oraTruckRepository.Insert(newTruck);
         }
     }
     catch (Exception e)
     {
         Logger.Error("InsertTruck Error: ", e);
         throw e;
     }
 }
Exemplo n.º 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
     }
 }
Exemplo n.º 4
0
 //public IEnumerable<ExcelDetail> GetListByFileExcelId(int fileExcelId)
 //{
 //    return _exRepository.FindBy(x => x.FileExcelId == fileExcelId);
 //}
 public ExcelDetail Update(ExcelDetail exceldetail)
 {
     return _excelDetailRepository.Update(exceldetail);
 }
Exemplo n.º 5
0
 public ExcelDetail Insert(ExcelDetail fileDetail)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
        ///
        /// <summary>
        /// Read File Excel
        /// </summary>
        /// <param name="file">file need to be read</param>
        /// <param name="excelId">Id file need to be read</param>
        /// <returns>File's content</returns>
        ///
        private List <ExcelDetail> ReadFile(HttpPostedFileBase file, int excelId, int Continue = 2)
        {
            Logger.Info("ReadFile fileName=" + file.FileName + " excelId=" + excelId);
            try
            {
                ExcelPackage       package        = new ExcelPackage(file.InputStream);
                ExcelWorksheet     workSheet      = package.Workbook.Worksheets.First();
                List <ExcelDetail> lstExcelDetail = new List <ExcelDetail>();
                int i;
                //Read info from row Continue of file
                for (var rowNumber = Continue; rowNumber <= workSheet.Dimension.End.Row; rowNumber++)
                {
                    var         row         = workSheet.Cells[rowNumber, 1, rowNumber, workSheet.Dimension.End.Column];
                    ExcelDetail excelDetail = new ExcelDetail();
                    //Read from Cell i of row Continue of file;

                    //Get each Cell of row Continue
                    for (i = 1; i <= workSheet.Dimension.End.Column; i++)
                    {
                        //If file's column number is more than Max
                        if (i >= (int)OrderInExcelFile.Max)
                        {
                            return(null);
                        }
                        switch (i)
                        {
                        case (int)OrderInExcelFile.TruckNo:
                            excelDetail.TruckNo = RemoveSymbol(workSheet.Cells[rowNumber, i].Text);
                            break;

                        case (int)OrderInExcelFile.ChassicNo:
                            excelDetail.ChassisNo = RemoveSymbol(workSheet.Cells[rowNumber, i].Text);
                            break;

                        case (int)OrderInExcelFile.DriverName:
                            excelDetail.DriverName = RemoveSymbol(workSheet.Cells[rowNumber, i].Text);
                            break;

                        case (int)OrderInExcelFile.DriverId:
                            excelDetail.DriverId = RemoveSymbol(workSheet.Cells[rowNumber, i].Text);
                            break;

                        case (int)OrderInExcelFile.LiscenseNo:
                            excelDetail.LicenseNo = RemoveSymbol(workSheet.Cells[rowNumber, i].Text);
                            break;

                        default: break;
                        }
                    }
                    //If content's column number is not enough
                    if (workSheet.Dimension.End.Column < ((int)OrderInExcelFile.Max - 1))
                    {
                        return(null);
                    }
                    //Add object read from row Continue to lstExcelDetail
                    excelDetail.FileExcelId = excelId;
                    excelDetail.TruckStatus = TruckStatus.NotYetCheck;
                    lstExcelDetail.Add(excelDetail);
                }
                return(lstExcelDetail);
            }
            catch (Exception e)
            {
                Logger.Error("ReadFile Error: ", e);
                throw e;
            }
        }
Exemplo n.º 7
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);
 }