private bool ValidateAndPopulateMsd2DataFromFlatFile(string record, string filename) { if (record.Length < 52) { recordErrors.AppendLine().AppendFormat('"' + record + '"' + " is not a valid record because it is missing some data"); } else { _msd2.DataSourceId = (int)DataSource.ASCII; _msd2.SenderId = _fileInfo.SenderId; var validateReportingPort = !_helperService.IsValidMsd2Port(record.Substring(8, 5)) || record.Substring(8, 5).Length < 5 ? record.Substring(8, 5) + " is not a recognised code for reporting port. " + " Enter a valid code or contact the helpdesk for advice." : String.Empty; _msd2.ReportingPort = !string.IsNullOrEmpty(validateReportingPort) ? string.Empty : record.Substring(8, 5); if (!string.IsNullOrEmpty(validateReportingPort)) { recordErrors.AppendLine().AppendFormat(validateReportingPort); } UInt16 year = 0; var strYear = record.Substring(13, 4).Length < 4 ? string.Empty : record.Substring(13, 4); UInt16.TryParse(strYear, out year); _msd2.Year = year; var validateYear = string.IsNullOrEmpty(record.Substring(13, 4).Trim()) || record.Substring(13, 4).Trim().Length < 4 || _msd2.Year == 0 ? record.Substring(13, 4) + " is not a valid year. Please correct it." : String.Empty; if (!string.IsNullOrEmpty(validateYear)) { recordErrors.AppendLine().AppendFormat(validateYear); } UInt16 qtr = 0; var strQtr = record.Substring(17, 1).Length < 1 ? string.Empty : record.Substring(17, 1); UInt16.TryParse(strQtr, out qtr); _msd2.Quarter = qtr; var validateQuarter = string.IsNullOrEmpty(record.Substring(17, 1).Trim()) || record.Substring(17, 1).Length < 1 || _msd2.Quarter == 0 ? record.Substring(30, 1) + " is not a valid quarter. Please correct it." : String.Empty; if (!string.IsNullOrEmpty(validateQuarter)) { recordErrors.AppendLine().AppendFormat(validateQuarter); } decimal grossWeightInWard = 0.0m; var strGrossWeightInward = record.Substring(18, 9).Length < 9 ? string.Empty : record.Substring(18, 9); Decimal.TryParse(strGrossWeightInward, out grossWeightInWard); _msd2.GrossWeightInward = grossWeightInWard; decimal grossWeightOutWard = 0.0m; var strGrossWeightOutward = record.Substring(27, 9).Length < 9 ? string.Empty : record.Substring(27, 9); Decimal.TryParse(strGrossWeightOutward, out grossWeightOutWard); _msd2.GrossWeightOutward = grossWeightOutWard; UInt32 totalUnitsInwards = 0; var strTotalUnitsInwards = record.Substring(36, 8).Length < 8 ? string.Empty : record.Substring(36, 8); UInt32.TryParse(strTotalUnitsInwards, out totalUnitsInwards); _msd2.TotalUnitsInward = totalUnitsInwards; UInt32 totalUnitsOutwards = 0; var strTotalUnitsOutwards = record.Substring(44, 8).Length < 8 ? string.Empty : record.Substring(44, 8); UInt32.TryParse(strTotalUnitsOutwards, out totalUnitsOutwards); _msd2.TotalUnitsOutward = totalUnitsOutwards; _msd2.PassengerVehiclesInward = 0; _msd2.PassengerVehiclesOutward = 0; var validateGrossWeights = _validateMsdData.ValidateMSD2InwardOutwadCargoWeight(_msd2); if (!string.IsNullOrEmpty(validateGrossWeights)) { recordErrors.AppendLine().AppendFormat(validateGrossWeights); } var validateYearAndQtrSubmission = _validateMsdData.ValidateYearAndQtrSubmission(_msd2.Year, _msd2.Quarter); if (!string.IsNullOrEmpty(validateYearAndQtrSubmission)) { recordErrors.AppendLine().AppendFormat(validateYearAndQtrSubmission); } _msd2.CreatedDate = DateTime.Now; _msd2.ModifiedDate = DateTime.Now; _msd2.CreatedBy = _validateMsdData.GetUserName(_fileInfo); _msd2.LastUpdatedBy = _validateMsdData.GetUserName(_fileInfo); } return(string.IsNullOrEmpty(recordErrors.ToString().Trim()) ? true : false); }
private void ValidateAndPopulateMsd2DataFromFlatFile(string[] msd2Elements) { _msd2.LastUpdatedBy = _validateMsdData.GetUserName(_fileInfo); _msd2.CreatedBy = _validateMsdData.GetUserName(_fileInfo); _msd2.DataSourceId = (int)DataSource.GESMES; _msd2.CreatedDate = DateTime.Now; _msd2.ModifiedDate = DateTime.Now; _msd2.SenderId = _fileInfo.SenderId; msd2Elements[0] = msd2Elements[0].Replace("ARR", "").Replace("++", ""); var validateReportingPort = !_helperService.IsValidMsd2Port(msd2Elements[0]) || msd2Elements[0].Length < 5 ? msd2Elements[0] + " is not a recognised code for reporting port. " + " Enter a valid code or contact the helpdesk for advice." : String.Empty; _msd2.ReportingPort = !string.IsNullOrEmpty(validateReportingPort) ? string.Empty : msd2Elements[0]; if (!string.IsNullOrEmpty(validateReportingPort)) { recordErrors.AppendLine().AppendFormat(validateReportingPort); } UInt16 year = 0; var strYear = string.IsNullOrEmpty(msd2Elements[1].Trim()) || msd2Elements[1].Trim().Length < 4 ? string.Empty : msd2Elements[1]; UInt16.TryParse(strYear, out year); _msd2.Year = year; var validateYear = _msd2.Year.ToString().Length < 4 || _msd2.Year == 0 ? msd2Elements[1].Trim() + " is not a valid year. Please correct it." : String.Empty; if (!string.IsNullOrEmpty(validateYear)) { recordErrors.AppendLine().AppendFormat(validateYear); } UInt16 qtr = 0; var strQtr = string.IsNullOrEmpty(msd2Elements[2].Trim()) || msd2Elements[2].Trim().Length < 1 ? string.Empty : msd2Elements[2]; UInt16.TryParse(strQtr, out qtr); _msd2.Quarter = qtr; var validateQuarter = _msd2.Quarter == 0 ? msd2Elements[2].Trim() + " is not a valid quarter. Please correct it." : String.Empty; if (!string.IsNullOrEmpty(validateQuarter)) { recordErrors.AppendLine().AppendFormat(validateQuarter); } decimal grossWeightInWard = 0.0m; var strGrossWeightInward = string.IsNullOrEmpty(msd2Elements[3]) ? string.Empty : msd2Elements[3]; Decimal.TryParse(strGrossWeightInward, out grossWeightInWard); _msd2.GrossWeightInward = grossWeightInWard; decimal grossWeightOutWard = 0.0m; var strGrossWeightOutward = string.IsNullOrEmpty(msd2Elements[4]) ? string.Empty : msd2Elements[4]; Decimal.TryParse(strGrossWeightOutward, out grossWeightOutWard); _msd2.GrossWeightOutward = grossWeightOutWard; UInt32 totalUnitsInwards = 0; var strTotalUnitsInwards = string.IsNullOrEmpty(msd2Elements[5]) ? string.Empty : msd2Elements[5]; UInt32.TryParse(strTotalUnitsInwards, out totalUnitsInwards); _msd2.TotalUnitsInward = totalUnitsInwards; UInt32 totalUnitsOutwards = 0; var strTotalUnitsOutwards = string.IsNullOrEmpty(msd2Elements[6]) ? string.Empty : msd2Elements[6]; UInt32.TryParse(strTotalUnitsOutwards, out totalUnitsOutwards); _msd2.TotalUnitsOutward = totalUnitsOutwards; _msd2.PassengerVehiclesInward = 0; _msd2.PassengerVehiclesOutward = 0; var validateGrossWeights = _validateMsdData.ValidateMSD2InwardOutwadCargoWeight(_msd2); if (!string.IsNullOrEmpty(validateGrossWeights)) { recordErrors.AppendLine().AppendFormat(validateGrossWeights); } var validateYearAndQtrSubmission = _validateMsdData.ValidateYearAndQtrSubmission(_msd2.Year, _msd2.Quarter); if (!string.IsNullOrEmpty(validateYearAndQtrSubmission)) { recordErrors.AppendLine().AppendFormat(validateYearAndQtrSubmission); } _msd2.FileRefId = null; }