179 lines
6.1 KiB
C#
179 lines
6.1 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 ProManagerPartner.Utils
|
|
{
|
|
class CCCPartsPriceChange
|
|
{
|
|
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
private static string workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
|
|
private static string emsBasePath = workingDirectory + @"\EmsBase";
|
|
private static string TempEmsDir = Properties.Settings.Default.PpcExportPath;
|
|
|
|
private static Encoding DbfFileCharEncoding = Encoding.ASCII;
|
|
private static byte DbfFileSignature = DBFSignature.DBase3; //DBFSignature.WithMemo;
|
|
|
|
private static byte DbfFileLanguageDriver = 0; //0x37;
|
|
|
|
public static void SendPartsPriceChange(dynamic Job)
|
|
{
|
|
Directory.CreateDirectory(TempEmsDir);
|
|
GenerateLinFile(Job);
|
|
GenerateEnvFile(Job);
|
|
}
|
|
|
|
public static void GenerateLinFile(dynamic Job)
|
|
{
|
|
try
|
|
{
|
|
DBFField[] StandardEmsFields = Utils.OEConnection.ReadDbfFields(emsBasePath + @"\EMS.LIN");
|
|
|
|
using (var fileStream = File.Create(TempEmsDir + $@"\{Utils.OEConnection.GenerateFileName(Job)}.LIN"))
|
|
{
|
|
using (var writer = new DBFWriter())
|
|
{
|
|
writer.CharEncoding = DbfFileCharEncoding;
|
|
writer.Signature = DbfFileSignature;
|
|
writer.LanguageDriver = DbfFileLanguageDriver;
|
|
|
|
writer.Fields = StandardEmsFields;
|
|
|
|
|
|
|
|
foreach (var jobline in Job.joblines)
|
|
{
|
|
writer.AddRecord(
|
|
jobline?.line_no?.Value,
|
|
jobline?.line_ind?.Value,
|
|
null, //jobline?.line_ref?.Value,
|
|
jobline?.tran_code?.Value ?? "2",
|
|
null, //jobline?.db_ref?.Value,
|
|
jobline?.unq_seq?.Value,
|
|
null, //jobline?.who_pays?.Value,
|
|
jobline?.line_desc?.Value,
|
|
null, //jobline?.part_type?.Value,
|
|
//partsOrderLine.jobline?.part_type?.Value,
|
|
null, //partsOrderLine.jobline?.part_descj?.Value,
|
|
null, //jobline?.glass_flag?.Value,
|
|
null, //jobline?.oem_partno?.Value,
|
|
null, //jobline?.price_inc?.Value,
|
|
null, //jobline?.alt_part_i?.Value,
|
|
null, //jobline?.tax_part?.Value,
|
|
null, //jobline?.db_price?.Value,
|
|
jobline.act_price?.Value,
|
|
jobline?.price_j?.Value,
|
|
null, //jobline?.cert_part?.Value,
|
|
null, //jobline?.part_qty?.Value,
|
|
null, //jobline?.alt_co_id?.Value,
|
|
null, //jobline?.alt_partno?.Value,
|
|
null, //jobline?.alt_overrd?.Value,
|
|
null, //jobline?.alt_partm?.Value,
|
|
null, //jobline?.prt_dsmk_p?.Value,
|
|
null, //jobline?.prt_dsmk_m?.Value,
|
|
null, //jobline?.mod_lbr_ty?.Value,
|
|
null, //jobline?.db_hrs?.Value,
|
|
null, //jobline?.mod_lb_hrs?.Value,
|
|
null, //jobline?.lbr_inc?.Value,
|
|
null, //jobline?.lbr_op?.Value,
|
|
null, //jobline?.lbr_hrs_j?.Value,
|
|
null, //jobline?.lbr_typ_j?.Value,
|
|
null, //jobline?.lbr_op_j?.Value,
|
|
null, //jobline?.paint_stg?.Value,
|
|
null, //jobline?.paint_tone?.Value,
|
|
null, //jobline?.lbr_tax?.Value,
|
|
null, //jobline?.lbr_amt?.Value,
|
|
null, //jobline?.misc_amt?.Value,
|
|
null, //jobline?.misc_sublt?.Value,
|
|
null, //jobline?.misc_tax?.Value,
|
|
null, //jobline?.bett_type?.Value,
|
|
null, //jobline?.bett_pctg?.Value,
|
|
null, //jobline?.bett_amt?.Value,
|
|
null //jobline?.bett_tax?.Value
|
|
|
|
|
|
); ;
|
|
}
|
|
|
|
|
|
|
|
writer.Write(fileStream);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex, "Error when creating LIN file."); throw ex;
|
|
}
|
|
|
|
}
|
|
public static void GenerateEnvFile(dynamic Job)
|
|
{
|
|
try
|
|
{
|
|
DBFField[] StandardEmsFields = Utils.OEConnection.ReadDbfFields(emsBasePath + @"\EMS.ENV");
|
|
|
|
using (var fileStream = File.Create(TempEmsDir + $@"\{Utils.OEConnection.GenerateFileName(Job)}.ENV"))
|
|
{
|
|
using (var writer = new DBFWriter())
|
|
{
|
|
writer.CharEncoding = DbfFileCharEncoding;
|
|
writer.Signature = DbfFileSignature;
|
|
writer.LanguageDriver = DbfFileLanguageDriver;
|
|
|
|
writer.Fields = StandardEmsFields;
|
|
|
|
writer.AddRecord(
|
|
"C",//EST_SYSTEM,
|
|
null,//"21.3",//SW_VERSION,
|
|
null,//"OCT_21_V",//DB_VERSION,
|
|
null,//DB_DATE
|
|
"",//UNQFILE_ID,
|
|
Job.ro_number?.Value,//RO_ID,
|
|
Job.ciecaid?.Value,//ESTFILE_ID,
|
|
null,//GetSupplementNumber(Job),//SUPP_NO,
|
|
null, //EST_CTRY,
|
|
null,//TOP_SECRET,
|
|
null,//H_TRANS_ID,
|
|
null,//H_CTRL_NO,
|
|
Job.trans_type?.Value,//TRANS_TYPE,
|
|
false,//STATUS,
|
|
null,// Job.create_dt?.Value,//CREATE_DT,
|
|
null,//Job.create_tm?.Value,//CREATE_TM,
|
|
null,//TRANSMT_DT,
|
|
null,//TRANSMT_TM,
|
|
true,//INCL_ADMIN,
|
|
true,//INCL_VEH,
|
|
Job.incl_est?.Value,//INCL_EST,
|
|
true,//INCL_PROFL,
|
|
true,//INCL_TOTAL,
|
|
false,//INCL_VENDR,
|
|
null//EMS_VER,
|
|
); ;
|
|
|
|
writer.Write(fileStream);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex, "Error when creating ENV file."); throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|