249 lines
10 KiB
C#
249 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using DotNetDBF;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace BodyshopUploader.Utils.Decoder
|
|
{
|
|
class EstimateDecoder
|
|
{
|
|
public static class CIECAEstimateImport
|
|
{
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// Decode the set of estimate files based on the creation of an envelope file.
|
|
/// </summary>
|
|
/// <param name="FilePath">Full path to the envelope file that was created/updated.</param>
|
|
/// <returns></returns>
|
|
public static dynamic DecodeEstimate(string FilePath)
|
|
{
|
|
dynamic ret = new JObject();
|
|
|
|
ret.ciecaid = Path.GetFileNameWithoutExtension(FilePath);
|
|
|
|
string _dir = Path.GetDirectoryName(FilePath) + @"\";
|
|
|
|
ParseAd1File(ref ret, _dir);
|
|
ParseVehFile(ref ret, _dir);
|
|
ParseStlFile(ref ret, _dir);
|
|
ParseTtlFile(ref ret, _dir);
|
|
ParseLinFile(ref ret, _dir);
|
|
|
|
return ret;
|
|
}
|
|
|
|
public static void ParseAd1File(ref dynamic j, string RootFilePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(j.ciecaid.Value))
|
|
{
|
|
return;
|
|
}
|
|
logger.Trace(@"Parsing AD1 at: {0}{1}", RootFilePath, j.ciecaid.Value);
|
|
|
|
int retryNumber = 0;
|
|
while (retryNumber < 11)
|
|
{
|
|
try
|
|
{
|
|
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + "A.ad1", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
{
|
|
var reader = new DBFReader(fis);
|
|
reader.SetSelectFields(new string[] { "INS_CO_ID", "INS_CO_NM", "INS_ADDR1", "INS_ADDR2", "INS_CITY", "INS_ST",
|
|
"INS_ZIP", "INS_CTRY", "INS_PH1", "CLM_NO", "OWNR_LN", "OWNR_FN", "OWNR_EA", "OWNR_PH1" });
|
|
var readValues = reader.NextRecord();
|
|
j.Claim_Source = readValues[0].ToString();
|
|
j.Claim_Number = readValues[1].ToString();
|
|
j.Owner_Ln = readValues[2].ToString();
|
|
j.Owner_Fn = readValues[3].ToString();
|
|
j.Owner_Email = readValues[4].ToString();
|
|
j.Owner_Phone = readValues[5].ToString();
|
|
return;
|
|
}
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
logger.Trace(ex, "Unable to open AD1 file. Retrying. ");
|
|
retryNumber++;
|
|
Thread.Sleep(3000);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static void ParseVehFile(ref dynamic j, string RootFilePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
|
|
|
|
logger.Trace(@"Parsing Veh at: {0}{1}", RootFilePath, j.ciecaid.Value);
|
|
|
|
int retryNumber = 0;
|
|
while (retryNumber < 11)
|
|
{
|
|
try
|
|
{
|
|
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + "v.veh", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
{
|
|
var reader = new DBFReader(fis);
|
|
reader.SetSelectFields(new string[] { "V_MODEL_YR", "V_MAKEDESC", "V_MODEL", "V_COLOR", "PLATE_NO", "V_VIN" });
|
|
var readValues = reader.NextRecord();
|
|
j.V_Model_Yr = readValues[0].ToString();
|
|
j.V_Make_Desc = readValues[1].ToString();
|
|
j.V_Model = readValues[2].ToString();
|
|
j.V_Color = readValues[3].ToString();
|
|
j.Lic_Plate = readValues[4].ToString();
|
|
j.V_Vin = readValues[5].ToString();
|
|
|
|
}
|
|
return;
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
logger.Trace(ex, "Unable to open VEH file. Retrying. ");
|
|
retryNumber++;
|
|
Thread.Sleep(3000);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void ParseTtlFile(ref dynamic j, string RootFilePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
|
|
|
|
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.ciecaid.Value);
|
|
|
|
|
|
|
|
int retryNumber = 0;
|
|
while (retryNumber < 11)
|
|
{
|
|
try
|
|
{
|
|
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".ttl", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
{
|
|
var reader = new DBFReader(fis);
|
|
reader.SetSelectFields(new string[] { "G_TTL_AMT" });
|
|
var readValues = reader.NextRecord();
|
|
j.Claim_Total = Convert.ToDecimal(readValues[0].ToString());
|
|
}
|
|
return;
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
logger.Trace(ex, "Unable to open TTL file. Retrying. ");
|
|
retryNumber++;
|
|
Thread.Sleep(3000);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void ParseStlFile(ref dynamic j, string RootFilePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
|
|
|
|
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.ciecaid.Value);
|
|
|
|
|
|
|
|
int retryNumber = 0;
|
|
while (retryNumber < 11)
|
|
{
|
|
try
|
|
{
|
|
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".stl", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
{
|
|
var reader = new DBFReader(fis);
|
|
reader.SetSelectFields(new string[] { "TTL_TYPECD", "T_HRS" });
|
|
var _rc = reader.RecordCount;
|
|
for (var i = 0; i < _rc; i++)
|
|
{
|
|
var readValues = reader.NextRecord();
|
|
switch (readValues[0])
|
|
{
|
|
|
|
//Labor Code
|
|
case "LAB":
|
|
j.BodyHrs = Convert.ToDecimal(readValues[1]);
|
|
break;
|
|
case "LAR":
|
|
j.RefHrs = Convert.ToDecimal(readValues[1]);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
logger.Trace(ex, "Unable to open STL file. Retrying. ");
|
|
retryNumber++;
|
|
Thread.Sleep(3000);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static void ParseLinFile(ref dynamic j, string RootFilePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
|
|
|
|
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.ciecaid.Value);
|
|
//j.JobSublets = new List<JobSublet>();
|
|
|
|
string _maxSupp = "";
|
|
|
|
int retryNumber = 0;
|
|
while (retryNumber < 11)
|
|
{
|
|
try
|
|
{
|
|
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".lin", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
{
|
|
var reader = new DBFReader(fis);
|
|
reader.SetSelectFields(new string[] { "PART_TYPE", "LINE_DESC", "UNQ_SEQ", "LINE_IND" });
|
|
var _rc = reader.RecordCount;
|
|
for (var i = 0; i < _rc; i++)
|
|
{
|
|
var readValues = reader.NextRecord();
|
|
//Find Max Supplement Number
|
|
if (string.Compare(_maxSupp, readValues[3].ToString()) < 0)
|
|
{
|
|
_maxSupp = readValues[3].ToString();
|
|
}
|
|
|
|
switch (readValues[3])
|
|
{
|
|
|
|
//Labor Code
|
|
case "PAS":
|
|
case "PASL":
|
|
//j.JobSublets.Add(new JobSublet()
|
|
//{
|
|
// SubletDesc = readValues[1].ToString(),
|
|
// Unq_Seq = Convert.ToInt32(readValues[2])
|
|
//});
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
j.MaxSupplement = _maxSupp;
|
|
return;
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
logger.Trace(ex, "Unable to open LIN file. Retrying. ");
|
|
retryNumber++;
|
|
Thread.Sleep(3000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|