moving code our of program file

This commit is contained in:
Bobbie Hodgetts
2024-04-17 16:03:15 +01:00
parent c1e6da7a6f
commit f8452d274a
23 changed files with 122 additions and 592 deletions

View File

@@ -56,7 +56,7 @@ namespace bnhtrade.Core.Data.Amazon.ProductFee
if (result.Error.Type != null) if (result.Error.Type != null)
{ sb.AppendLine("Type: " + result.Error.Type); } { sb.AppendLine("Type: " + result.Error.Type); }
MiscFunction.EventLogInsert("Error running GetProductEstimateFee for ASIN:" + asin + ", further details attached.", 1, sb.ToString()); new Logic.Log.LogEvent().EventLogInsert("Error running GetProductEstimateFee for ASIN:" + asin + ", further details attached.", 1, sb.ToString());
throw new Exception("ProductFeeEstimate error, check logs for further details"); throw new Exception("ProductFeeEstimate error, check logs for further details");
} }

View File

@@ -56,5 +56,15 @@ namespace bnhtrade.Core.Data.Database
FbaShippingPlan = 5, FbaShippingPlan = 5,
// add the rest as needed // add the rest as needed
} }
public enum OrderChannel
{
US = 1,
UK = 2,
De = 3,
Fr = 4,
It = 5,
Es = 6,
}
} }
} }

View File

@@ -62,7 +62,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -183,17 +183,17 @@ namespace bnhtrade.Core.Data.Database.Import
} }
trans.Commit(); trans.Commit();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped."); new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );
@@ -234,7 +234,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running GetFbaReturnsReport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaReturnsReport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );

View File

@@ -59,7 +59,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -185,17 +185,17 @@ namespace bnhtrade.Core.Data.Database.Import
} }
trans.Commit(); trans.Commit();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped."); new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running ImportFbaAdustmentReport method, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running ImportFbaAdustmentReport method, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );
@@ -236,7 +236,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running GetFbaAdustmentData, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaAdustmentData, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );

View File

@@ -100,7 +100,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -276,12 +276,12 @@ namespace bnhtrade.Core.Data.Database.Import
} }
} }
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Operation complete. " + lineNumber + " items processes. " + (lineNumber - lineErrorSkip - lineNoStockSkip) + " total new items inserted, " "Operation complete. " + lineNumber + " items processes. " + (lineNumber - lineErrorSkip - lineNoStockSkip) + " total new items inserted, "
+ lineNoStockSkip + " 'No Stock' records were skipped."); + lineNoStockSkip + " 'No Stock' records were skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
@@ -290,7 +290,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Something went wrong during import, check details for more.", 1, ex.ToString()); new Logic.Log.LogEvent().EventLogInsert("Something went wrong during import, check details for more.", 1, ex.ToString());
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
} }

View File

@@ -78,7 +78,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -174,12 +174,12 @@ namespace bnhtrade.Core.Data.Database.Import
} }
} }
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Operation complete. " + lineNumber + " items processes. " + (lineNumber - lineErrorSkip - lineNoStockSkip) + " total new items inserted, " "Operation complete. " + lineNumber + " items processes. " + (lineNumber - lineErrorSkip - lineNoStockSkip) + " total new items inserted, "
+ lineNoStockSkip + " 'No Stock' records were skipped."); + lineNoStockSkip + " 'No Stock' records were skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
@@ -188,7 +188,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Something went wrong during import, check details for more.", 1, ex.ToString()); new Logic.Log.LogEvent().EventLogInsert("Something went wrong during import, check details for more.", 1, ex.ToString());
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
} }

View File

@@ -42,7 +42,7 @@ namespace bnhtrade.Core.Data.Database.Import
// create notification if amazon add extra headers // create notification if amazon add extra headers
if (columnCount > 7) if (columnCount > 7)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Amazon have added a new column to their 'Fba Inventory Receipt' report, you may want to check this out.", "Amazon have added a new column to their 'Fba Inventory Receipt' report, you may want to check this out.",
2); 2);
} }
@@ -66,7 +66,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -142,17 +142,17 @@ namespace bnhtrade.Core.Data.Database.Import
// only commit if records all complete with no errors -- ommiting duplcates relies on all records from one day being committed together // only commit if records all complete with no errors -- ommiting duplcates relies on all records from one day being committed together
trans.Commit(); trans.Commit();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert((lineNumber - (1 + lineErrorSkip + lineOutsideScope)) + " total report items inserted into db, " + lineOutsideScope + " item(s) outside of requested time scope where skipped."); new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineOutsideScope)) + " total report items inserted into db, " + lineOutsideScope + " item(s) outside of requested time scope where skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );
@@ -193,7 +193,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );

View File

@@ -66,7 +66,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -228,17 +228,17 @@ namespace bnhtrade.Core.Data.Database.Import
} }
trans.Commit(); trans.Commit();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped."); new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running ImportFbaReimbursementReport method, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running ImportFbaReimbursementReport method, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );
@@ -279,7 +279,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running GetFbaReimbursementData, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaReimbursementData, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );

View File

@@ -66,7 +66,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -175,17 +175,17 @@ namespace bnhtrade.Core.Data.Database.Import
} }
trans.Commit(); trans.Commit();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert("ImportFbaRemovalOrderReport() " + (lineNumber - (1 + lineErrorSkip + lineUpdate)) + " records created, " + lineUpdate + " records updated."); new Logic.Log.LogEvent().EventLogInsert("ImportFbaRemovalOrderReport() " + (lineNumber - (1 + lineErrorSkip + lineUpdate)) + " records created, " + lineUpdate + " records updated.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running ImportFbaRemovalOrderReport method, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running ImportFbaRemovalOrderReport method, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );
@@ -228,7 +228,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running GetFbaRemovalOrderReport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running GetFbaRemovalOrderReport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );

View File

@@ -96,7 +96,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineErrorSkip = lineErrorSkip + 1; lineErrorSkip = lineErrorSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -280,17 +280,17 @@ namespace bnhtrade.Core.Data.Database.Import
} }
trans.Commit(); trans.Commit();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped."); new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
if (lineErrorSkip > 0) if (lineErrorSkip > 0)
{ {
MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );
@@ -347,7 +347,7 @@ namespace bnhtrade.Core.Data.Database.Import
// { // {
// // skip line // // skip line
// lineErrorSkip = lineErrorSkip + 1; // lineErrorSkip = lineErrorSkip + 1;
// MiscFunction.EventLogInsert( // new Logic.Log.LogEvent().EventLogInsert(
// "Line #" + lineNumber + " skipped due to no enough element in row.", // "Line #" + lineNumber + " skipped due to no enough element in row.",
// 2, // 2,
// filePath // filePath
@@ -501,17 +501,17 @@ namespace bnhtrade.Core.Data.Database.Import
// } // }
// trans.Commit(); // trans.Commit();
// Console.Write("\r"); // Console.Write("\r");
// MiscFunction.EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped."); // new Logic.Log.LogEvent().EventLogInsert((lineNumber - (1 + lineErrorSkip + lineDuplicateSkip)) + " total new items inserted, " + lineDuplicateSkip + " duplicates were skipped.");
// if (lineErrorSkip > 0) // if (lineErrorSkip > 0)
// { // {
// MiscFunction.EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); // new Logic.Log.LogEvent().EventLogInsert(lineErrorSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
// } // }
// } // }
// } // }
// //} // //}
// //catch (Exception ex) // //catch (Exception ex)
// //{ // //{
// // MiscFunction.EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited", // // new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
// // 1, // // 1,
// // ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() // // ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
// // ); // // );
@@ -618,7 +618,7 @@ namespace bnhtrade.Core.Data.Database.Import
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited", new Logic.Log.LogEvent().EventLogInsert("Error running FbaInventoryReceiptReportImport, no records were commited",
1, 1,
ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage() ex.ToString() + "\r\nTraceMessage:\r\n" + MiscFunction.TraceMessage()
); );

View File

@@ -84,7 +84,7 @@ namespace bnhtrade.Core.Data.Database.Import
{ {
// skip line // skip line
lineSkip = lineSkip + 1; lineSkip = lineSkip + 1;
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Line #" + lineNumber + " skipped due to no enough element in row.", "Line #" + lineNumber + " skipped due to no enough element in row.",
2, 2,
filePath filePath
@@ -102,7 +102,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (recordCount > 0) if (recordCount > 0)
{ {
UpdateSpapiReportId(items[indexSettlementId], reportId); UpdateSpapiReportId(items[indexSettlementId], reportId);
MiscFunction.EventLogInsert("Settlement report already imported, skipping..."); new Logic.Log.LogEvent().EventLogInsert("Settlement report already imported, skipping...");
scope.Complete(); scope.Complete();
return true; return true;
} }
@@ -285,7 +285,7 @@ namespace bnhtrade.Core.Data.Database.Import
if (sumOfAmount != settlementAmount) if (sumOfAmount != settlementAmount)
{ {
MiscFunction.EventLogInsert("Error importing settlement id'" + settlementRef + "'. Sum of inserted settlement lines (" + sumOfAmount + new Logic.Log.LogEvent().EventLogInsert("Error importing settlement id'" + settlementRef + "'. Sum of inserted settlement lines (" + sumOfAmount +
") does not match settlement amount (" + settlementAmount + ").", 1); ") does not match settlement amount (" + settlementAmount + ").", 1);
return false; return false;
} }
@@ -293,10 +293,10 @@ namespace bnhtrade.Core.Data.Database.Import
scope.Complete(); scope.Complete();
Console.Write("\r"); Console.Write("\r");
MiscFunction.EventLogInsert((lineNumber - (2 + lineSkip)) + " total settlement items inserted"); new Logic.Log.LogEvent().EventLogInsert((lineNumber - (2 + lineSkip)) + " total settlement items inserted");
if (lineSkip > 0) if (lineSkip > 0)
{ {
MiscFunction.EventLogInsert(lineSkip + " total line(s) where skipped due to insufficent number of cells on row", 1); new Logic.Log.LogEvent().EventLogInsert(lineSkip + " total line(s) where skipped due to insufficent number of cells on row", 1);
} }
} }
} }

View File

@@ -25,7 +25,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getFile.ReportFilePathIsSet) if (!getFile.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -15,7 +15,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getFile.ReportFilePathIsSet) if (!getFile.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -19,7 +19,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getFile.ReportFilePathIsSet) if (!getFile.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -15,7 +15,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getFile.ReportFilePathIsSet) if (!getFile.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -19,7 +19,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getReport.ReportFilePathIsSet) if (!getReport.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -19,7 +19,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getFile.ReportFilePathIsSet) if (!getFile.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -26,7 +26,7 @@ namespace bnhtrade.Core.Logic.Import
if (!getFile.ReportFilePathIsSet) if (!getFile.ReportFilePathIsSet)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Something went wrong retriving report from Amazon SP API. Operation cancelled.", "Something went wrong retriving report from Amazon SP API. Operation cancelled.",
2 2
); );

View File

@@ -15,7 +15,7 @@ namespace bnhtrade.Core.Logic.Import
{ {
string operation = "Import Amazon Settlement Reports"; string operation = "Import Amazon Settlement Reports";
MiscFunction.EventLogInsert("Started '" + operation + "' operation."); new Logic.Log.LogEvent().EventLogInsert("Started '" + operation + "' operation.");
// get avaiable reports from amazon api // get avaiable reports from amazon api
var spapiReportIdList = amazonReport.ListAvaliableReports(); var spapiReportIdList = amazonReport.ListAvaliableReports();
@@ -23,7 +23,7 @@ namespace bnhtrade.Core.Logic.Import
if (reportCount == 0) if (reportCount == 0)
{ {
MiscFunction.EventLogInsert("Exiting '" + operation + "' operation. No settlement reports availble on Amazon SP-API."); new Logic.Log.LogEvent().EventLogInsert("Exiting '" + operation + "' operation. No settlement reports availble on Amazon SP-API.");
return; return;
} }
@@ -47,7 +47,7 @@ namespace bnhtrade.Core.Logic.Import
if (!spapiReportIdList.Any()) if (!spapiReportIdList.Any())
{ {
MiscFunction.EventLogInsert("Exiting '" + operation + "' operation. No new reports to import (" + reportCount + " avaibale)."); new Logic.Log.LogEvent().EventLogInsert("Exiting '" + operation + "' operation. No new reports to import (" + reportCount + " avaibale).");
return; return;
} }
@@ -58,7 +58,7 @@ namespace bnhtrade.Core.Logic.Import
UI.Console.WriteLine("Importing settlement report " + (i + 1) + " of " + spapiReportIdList.Count() + " (ReportID:" + spapiReportIdList[i] + ")."); UI.Console.WriteLine("Importing settlement report " + (i + 1) + " of " + spapiReportIdList.Count() + " (ReportID:" + spapiReportIdList[i] + ").");
var filePath = amazonReport.GetFile(spapiReportIdList[i]); var filePath = amazonReport.GetFile(spapiReportIdList[i]);
bool ack = dbImport.ByFlatFile(filePath, spapiReportIdList[i]); bool ack = dbImport.ByFlatFile(filePath, spapiReportIdList[i]);
MiscFunction.EventLogInsert("Settlment Report imported (ReportID:" + spapiReportIdList[i] + ")."); new Logic.Log.LogEvent().EventLogInsert("Settlment Report imported (ReportID:" + spapiReportIdList[i] + ").");
} }
return; return;

View File

@@ -114,6 +114,22 @@ namespace bnhtrade.Core.Logic.Log
Execute(); Execute();
} }
/// <summary>
/// Depreciated, do not use!
/// </summary>
public void EventLogInsert(string detailShort = "", int eventType = 3, string detailLong = "", DateTime eventDateTime = default(DateTime), bool consolePrint = true)
{
this.eventType = eventType;
DetailShort = detailShort;
if (!string.IsNullOrEmpty(detailLong))
DetailLong = detailLong;
if (!(eventDateTime == default(DateTime)))
this.eventDateTimeUtc = eventDateTime;
this.printToConsole = consolePrint;
Execute();
Initialise();
}
public void Initialise() public void Initialise()
{ {
eventDateTimeUtc = null; eventDateTimeUtc = null;

View File

@@ -120,7 +120,7 @@ namespace bnhtrade.Core.Logic.Stock
{ {
ProgressMessage = "New 'Transaction-Type' encountered"; ProgressMessage = "New 'Transaction-Type' encountered";
//Console.Write("\r"); //Console.Write("\r");
//MiscFunction.EventLogInsert(errMessage, 1); //new Logic.Log.LogEvent().EventLogInsert(errMessage, 1);
break; break;
} }

View File

@@ -19,7 +19,7 @@ namespace bnhtrade.Core.Logic.Utilities
public void DownloadAll() public void DownloadAll()
{ {
MiscFunction.EventLogInsert("Nightly scheduled tasks started."); new Logic.Log.LogEvent().EventLogInsert("Nightly scheduled tasks started.");
var stock = new bnhtrade.Core.Stock.StockReconciliation(); var stock = new bnhtrade.Core.Stock.StockReconciliation();
var export = new bnhtrade.Core.Logic.Export.AmazonSettlement(dbCredentials.ConnectionString); var export = new bnhtrade.Core.Logic.Export.AmazonSettlement(dbCredentials.ConnectionString);
@@ -46,14 +46,14 @@ namespace bnhtrade.Core.Logic.Utilities
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Exception caught running all report get method, see for further details", "Exception caught running all report get method, see for further details",
1, 1,
ex.ToString() ex.ToString()
); );
} }
} }
MiscFunction.EventLogInsert("Nightly scheduled tasks finished."); new Logic.Log.LogEvent().EventLogInsert("Nightly scheduled tasks finished.");
} }
} }
} }

View File

@@ -574,7 +574,7 @@ namespace bnhtrade.Core
if (reader.Read()) if (reader.Read())
{ {
string errText = "Multiple lines in currency exchange table for '" + currencyCode + "' where [EndDate]=" + periodEndLast.ToString(); string errText = "Multiple lines in currency exchange table for '" + currencyCode + "' where [EndDate]=" + periodEndLast.ToString();
MiscFunction.EventLogInsert(errText, 1); new Logic.Log.LogEvent().EventLogInsert(errText, 1);
throw new Exception(errText); throw new Exception(errText);
} }
} }
@@ -945,438 +945,6 @@ namespace bnhtrade.Core
namespace Stock namespace Stock
{ {
public class StockCreate
{
private int WIP_StockInsert(string sqlConnectionString, int accountJournalType, int stockJournalType, string currencyCode, decimal amount,
int quantity, int productId, int conditionId, int accountTaxCodeId, DateTime entryDate, int debitStatusId)
{
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// add account journal entry
int accountJournalId = Account.AccountQuery.AccountJournalInsert(sqlConnectionString, accountJournalType, entryDate, currencyCode, amount);
// make the stock insert
int stockId = WIP_StockInsertSub(sqlConnectionString, productId, conditionId, accountTaxCodeId,
accountJournalId, stockJournalType, entryDate, quantity, debitStatusId);
scope.Complete();
return stockId;
}
}
private int WIP_StockInsertSub(string sqlConnectionString, int productId, int conditionId, int accountTaxCodeId,
int accountJournalId, int stockJournalTypeId, DateTime stockJournalEntryDate, int quantity, int statusDebitId)
{
stockJournalEntryDate = DateTime.SpecifyKind(stockJournalEntryDate, DateTimeKind.Utc);
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// ensure account journal id hasn't already been added to stock table
int count = 0;
using (SqlCommand cmd = new SqlCommand(@"
SELECT Count(tblStock.StockID) AS CountOfID
FROM tblStock
WHERE (((tblStock.AccountJournalID)=@accountJouranlId));
", conn))
{
cmd.Parameters.AddWithValue("@accountJouranlId", accountJournalId);
count = (int)cmd.ExecuteScalar();
}
if (count == 1)
{
throw new Exception("Add account journal entry already assigned to stock line.");
}
else if (count > 1)
{
throw new Exception("Houston we have a problem! An account journal entry is assigned to " + count + " stock lines.");
}
// ensure the debit for the account journal transaction is to an 'Asset' account type
using (SqlCommand cmd = new SqlCommand(@"
SELECT
Count(tblAccountJournalPost.AccountJournalPostID) AS CountOfAccountJournalPostID
FROM
(tblAccountJournalPost
INNER JOIN tblAccountChartOf
ON tblAccountJournalPost.AccountChartOfID = tblAccountChartOf.AccountChartOfID)
INNER JOIN tblAccountChartOfType
ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID
WHERE
tblAccountJournalPost.AmountGbp>=0
AND tblAccountChartOfType.BasicType='Asset'
AND tblAccountJournalPost.AccountJournalID=@accountJournalId;
", conn))
{
cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId);
if ((int)cmd.ExecuteScalar() < 1)
{
throw new Exception("Supplied AccountJournal entry must debit an 'Asset' account type.");
}
}
// get statusCreditId for stock journal type
int statusCreditId;
using (SqlCommand cmd = new SqlCommand(@"
SELECT
tblStockJournalType.StockStatusID_Credit
FROM
tblStockJournalType
WHERE
tblStockJournalType.StockJournalTypeID=@stockJournalTypeId
AND tblStockJournalType.StockStatusID_Credit Is Not Null;
", conn))
{
cmd.Parameters.AddWithValue("@stockJournalTypeId", stockJournalTypeId);
object obj = cmd.ExecuteScalar();
if (obj == null)
{
throw new Exception("Default credit status not set for StockJournalTypeID=" + stockJournalTypeId);
}
else
{
statusCreditId = (int)obj;
}
}
// get/set an skuId
int skuId = Logic.Sku.GetSkuIdByType.Request(sqlConnectionString, productId, conditionId, accountTaxCodeId, true);
// add the entry to the stock table (minus stockJournalId)
int stockId = 0;
using (SqlCommand cmd = new SqlCommand(@"
INSERT INTO tblStock
(SkuID, AccountJournalID)
OUTPUT INSERTED.StockID
VALUES
(@skuId, @accountJournalId);
", conn))
{
cmd.Parameters.AddWithValue("@skuId", skuId);
cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId);
stockId = (int)cmd.ExecuteScalar();
}
// insert stock journal entry
var journalPosts = new List<(int statusId, int quantity)>();
journalPosts.Add((statusDebitId, quantity));
journalPosts.Add((statusCreditId, (quantity * -1)));
int stockJournalId = Stock.StockJournal.StockJournalInsert(sqlConnectionString, stockJournalTypeId, stockId, journalPosts, stockJournalEntryDate, true);
// update the stock table
using (SqlCommand cmd = new SqlCommand(@"
UPDATE tblStock
SET StockJournalID=@stockJournalId
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockJournalId", stockJournalId);
cmd.Parameters.AddWithValue("@stockId", stockId);
count = cmd.ExecuteNonQuery();
if (count < 1)
{
throw new Exception("New stock insert cancelled, failed to update StockJournalID");
}
}
scope.Complete();
return stockId;
}
}
private static void WIP_StockDelete(string sqlConnectionString, int stockId)
{
int accountJournalType = 0;
int stockJournalType = 0;
// get stock and account types
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// ensure stockId is owner-introduced
using (SqlCommand cmd = new SqlCommand(@"
SELECT
tblStockJournal.StockJournalTypeID, tblAccountJournal.AccountJournalTypeID
FROM
(tblStock INNER JOIN tblAccountJournal
ON tblStock.AccountJournalID = tblAccountJournal.AccountJournalID)
INNER JOIN tblStockJournal
ON tblStock.StockJournalID = tblStockJournal.StockJournalID
WHERE
(((tblStock.StockID)=@stockId));
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
accountJournalType = reader.GetInt32(1);
stockJournalType = reader.GetInt32(0);
}
else
{
throw new Exception("Integrity check failed, cancelling StockDeleteOwnerIntroduced");
}
}
}
// check stock journal type is not restricted
// owner inventory introduced
if (stockJournalType == 2)
{
// no dramas
}
else
{
throw new Exception("Manual delete of this stock type is not supported, use the moethod that created it!");
}
// check there is only one stock journal entry for stock item
using (SqlCommand cmd = new SqlCommand(@"
SELECT Count(tblStockJournal.StockJournalID) AS CountOfStockJournalID
FROM tblStockJournal
WHERE (((tblStockJournal.StockID)=@stockId));
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
int count = (int)cmd.ExecuteScalar();
if (count > 1)
{
throw new Exception("Delete " + count + " stock journal entries (other than source entry), before peforming this operation.");
}
}
// remove account journal entry
Stock.StockCreate.WIP_StockDeleteSubAccountJournalEntry(sqlConnectionString, stockId);
// remove stock
Stock.StockCreate.WIP_StockDeleteSub(sqlConnectionString, stockId);
scope.Complete();
}
}
private static void WIP_StockDeleteSub(string sqlConnectionString, int stockId)
{
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// check for accountJournalId on stock table
using (SqlCommand cmd = new SqlCommand(@"
SELECT AccountJournalID
FROM tblStock
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
object obj = cmd.ExecuteScalar();
if (obj == null)
{
throw new Exception("StockID=" + stockId + " does not exist.");
}
else if (obj == DBNull.Value)
{
// nothing to do all is good
}
else
{
int id = (int)obj;
if (id > 0)
{
throw new Exception("StockID=" + stockId + " remove account journal entry using method that created it first.");
}
}
}
// get stockJournalId
int stockJournalId;
using (SqlCommand cmd = new SqlCommand(@"
SELECT StockJournalID
FROM tblStock
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
try
{
stockJournalId = (int)cmd.ExecuteScalar();
}
catch
{
throw new Exception("Could not retrive StockJournalID for StockID=" + stockId);
}
}
// remove stockJournalId from stock table
using (SqlCommand cmd = new SqlCommand(@"
UPDATE tblStock
SET StockJournalID=NULL
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
int count = cmd.ExecuteNonQuery();
if (count != 2) // we need to count the LastUpdated trigger!
{
throw new Exception("Failed to remove StockJournalID from stock table StockID=" + stockId);
}
}
// delete stock journal entry
Stock.StockJournal.StockJournalDelete(sqlConnectionString, stockJournalId);
// delete stock table entry
using (SqlCommand cmd = new SqlCommand(@"
DELETE FROM tblStock
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
int count = cmd.ExecuteNonQuery();
if (count != 1)
{
throw new Exception("StockID = " + stockId + " delete failed");
}
else
{
scope.Complete();
}
}
}
}
// to be used by other methods within a transaction scope
private static void WIP_StockDeleteSubAccountJournalEntry(string sqlConnectionString, int stockId)
{
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// get the account journal id
int accountJournalId = 0;
using (SqlCommand cmd = new SqlCommand(@"
SELECT AccountJournalID
FROM tblStock
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
object obj = cmd.ExecuteScalar();
if (obj == null)
{
throw new Exception("StockID=" + stockId + " does not exist.");
}
else if (obj == DBNull.Value)
{
throw new Exception("AccountJournalID not found for StockID=" + stockId);
}
else
{
accountJournalId = (int)obj;
}
}
// remove entry from stock table
using (SqlCommand cmd = new SqlCommand(@"
UPDATE tblStock
SET AccountJournalID=NULL
WHERE StockID=@stockId;
", conn))
{
cmd.Parameters.AddWithValue("@stockId", stockId);
int count = cmd.ExecuteNonQuery();
if (count != 2) // must include last modified trigger
{
throw new Exception("Failed to set AccountJournalID to NULL on stock table for StockID=" + stockId);
}
}
// delete account journal entry
Account.AccountQuery.AccountJournalDelete(sqlConnectionString, accountJournalId);
scope.Complete();
}
}
public static int WIP_StockInsertPurchase(string sqlConnectionString, int productId, int conditionId, int accountTaxCodeId, int accountJournalId, int quantity, int statusDebitId)
{
DateTime stockJournalEntryDate;
int stockJournalTypeId = 1;
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// retrive info from purchase invoice line/transaction
using (SqlCommand cmd = new SqlCommand(@"
SELECT tblAccountJournal.EntryDate
FROM tblAccountJournal
WHERE (((tblAccountJournal.AccountJournalID)=@accountJournalId));
", conn))
{
cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId);
stockJournalEntryDate = DateTime.SpecifyKind((DateTime)cmd.ExecuteScalar(), DateTimeKind.Utc);
}
}
return new Stock.StockCreate().WIP_StockInsertSub(sqlConnectionString, productId, conditionId, accountTaxCodeId, accountJournalId, stockJournalTypeId, stockJournalEntryDate, quantity, statusDebitId);
}
public static int WIP_StockInsertOwnerIntroduced(string sqlConnectionString, decimal amount, int quantity, int productId, int conditionId, int accountTaxCodeId, DateTime entryDate, int debitStatusId)
{
int accountJournalType = 3;
int stockJournalType = 2;
string currencyCode = "GBP";
return new Stock.StockCreate().WIP_StockInsert(sqlConnectionString, accountJournalType, stockJournalType, currencyCode, amount, quantity, productId, conditionId, accountTaxCodeId, entryDate, debitStatusId);
}
public static void WIP_StockDeletePurchase(string sqlConnectionString, int stockId)
{
WIP_StockDeleteSub(sqlConnectionString, stockId);
}
public static void WIP_StockDeleteOwnerIntroduced(string sqlConnectionString, int stockId)
{
WIP_StockDelete(sqlConnectionString, stockId);
}
}
public class StockJournal public class StockJournal
{ {
// only to be assessable via code, use stock relocate to move stock bewtween status' // only to be assessable via code, use stock relocate to move stock bewtween status'
@@ -2060,7 +1628,7 @@ namespace bnhtrade.Core
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Exception caught running UpdateFbaStockImportData, see for further details", "Exception caught running UpdateFbaStockImportData, see for further details",
1, 1,
ex.ToString() ex.ToString()
@@ -2096,7 +1664,7 @@ namespace bnhtrade.Core
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Exception caught running ProcessFbaStockImportData, see for further details", "Exception caught running ProcessFbaStockImportData, see for further details",
1, 1,
ex.ToString() ex.ToString()
@@ -2107,7 +1675,7 @@ namespace bnhtrade.Core
public void ProcessFbaInventoryReceiptData(string sqlConnectionString) public void ProcessFbaInventoryReceiptData(string sqlConnectionString)
{ {
MiscFunction.EventLogInsert("Starting TransposeFbaInventoryReceiptReport()"); new Logic.Log.LogEvent().EventLogInsert("Starting TransposeFbaInventoryReceiptReport()");
int transposeCount = 0; int transposeCount = 0;
int transposeSkip = 0; int transposeSkip = 0;
int transactionTypeIdPos; int transactionTypeIdPos;
@@ -2128,7 +1696,7 @@ namespace bnhtrade.Core
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("TransposeFbaInventoryReceiptReport() failed to retrive 'TransactionTypeID from method, cancelling operation. More details available.", 1, ex.ToString()); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaInventoryReceiptReport() failed to retrive 'TransactionTypeID from method, cancelling operation. More details available.", 1, ex.ToString());
return; return;
} }
@@ -2138,7 +1706,7 @@ namespace bnhtrade.Core
int temp; int temp;
temp = Stock.StockJournal.StockTransactionTypeIdInsert(sqlConnectionString, stockJournalTypeId, matchStringPos); temp = Stock.StockJournal.StockTransactionTypeIdInsert(sqlConnectionString, stockJournalTypeId, matchStringPos);
temp = Stock.StockJournal.StockTransactionTypeIdInsert(sqlConnectionString, stockJournalTypeId, matchStringNeg); temp = Stock.StockJournal.StockTransactionTypeIdInsert(sqlConnectionString, stockJournalTypeId, matchStringNeg);
MiscFunction.EventLogInsert("TransposeFbaInventoryReceiptReport() function requires that both +ve and -ve types are setup. Cancelling operation", 2); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaInventoryReceiptReport() function requires that both +ve and -ve types are setup. Cancelling operation", 2);
return; return;
} }
@@ -2290,12 +1858,12 @@ namespace bnhtrade.Core
} }
} }
} }
MiscFunction.EventLogInsert("TransposeFbaInventoryReceiptReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaInventoryReceiptReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped.");
if (transposeSkip > 0) { MiscFunction.EventLogInsert(transposeSkip + " number records skipped during TransposeFbaInventoryReceiptReport() operation.", 2); } if (transposeSkip > 0) { new Logic.Log.LogEvent().EventLogInsert(transposeSkip + " number records skipped during TransposeFbaInventoryReceiptReport() operation.", 2); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Exception catch, aborting TransposeFbaInventoryReceiptReport(), see detailed info. " new Logic.Log.LogEvent().EventLogInsert("Exception catch, aborting TransposeFbaInventoryReceiptReport(), see detailed info. "
+ transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString()); + transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString());
} }
} }
@@ -2310,7 +1878,7 @@ namespace bnhtrade.Core
var hack = new Stock.StockReconciliation(); var hack = new Stock.StockReconciliation();
hack.WIP_GetSetFbaOrderRefs(sqlConnectionString); hack.WIP_GetSetFbaOrderRefs(sqlConnectionString);
MiscFunction.EventLogInsert("Starting TransposeFbaSaleShipmentReport()"); new Logic.Log.LogEvent().EventLogInsert("Starting TransposeFbaSaleShipmentReport()");
int transposeCount = 0; int transposeCount = 0;
int transposeSkip = 0; int transposeSkip = 0;
int stockJouranlTypeId = 7; int stockJouranlTypeId = 7;
@@ -2327,7 +1895,7 @@ namespace bnhtrade.Core
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("TransposeFbaSaleShipmentReport() failed to retrive 'TransactionTypeID from method, cancelling operation. More details available.", 1, ex.ToString()); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaSaleShipmentReport() failed to retrive 'TransactionTypeID from method, cancelling operation. More details available.", 1, ex.ToString());
return; return;
} }
@@ -2422,12 +1990,12 @@ namespace bnhtrade.Core
} }
scope.Complete(); scope.Complete();
} }
MiscFunction.EventLogInsert("TransposeFbaSaleShipmentReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaSaleShipmentReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped.");
if (transposeSkip > 0) { MiscFunction.EventLogInsert(transposeSkip + " number records skipped during TransposeFbaSaleShipmentReport() operation.", 2); } if (transposeSkip > 0) { new Logic.Log.LogEvent().EventLogInsert(transposeSkip + " number records skipped during TransposeFbaSaleShipmentReport() operation.", 2); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Exception catch, aborting TransposeFbaSaleShipmentReport(), see detailed info. " new Logic.Log.LogEvent().EventLogInsert("Exception catch, aborting TransposeFbaSaleShipmentReport(), see detailed info. "
+ transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString()); + transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString());
} }
} }
@@ -2485,7 +2053,7 @@ namespace bnhtrade.Core
public void ProcessFbaReturnsData(string sqlConnectionString) public void ProcessFbaReturnsData(string sqlConnectionString)
{ {
MiscFunction.EventLogInsert("Starting TransposeFbaReturnsReport()"); new Logic.Log.LogEvent().EventLogInsert("Starting TransposeFbaReturnsReport()");
int transposeCount = 0; int transposeCount = 0;
int transposeSkip = 0; int transposeSkip = 0;
int stockJournalTypeId = 9; int stockJournalTypeId = 9;
@@ -2607,19 +2175,19 @@ namespace bnhtrade.Core
} }
} }
} }
MiscFunction.EventLogInsert("TransposeFbaReturnsReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaReturnsReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped.");
if (transposeSkip > 0) { MiscFunction.EventLogInsert(transposeSkip + " number records skipped during TransposeFbaReturnsReport() operation.", 2); } if (transposeSkip > 0) { new Logic.Log.LogEvent().EventLogInsert(transposeSkip + " number records skipped during TransposeFbaReturnsReport() operation.", 2); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Exception catch, aborting TransposeFbaReturnsReport(), see detailed info. " new Logic.Log.LogEvent().EventLogInsert("Exception catch, aborting TransposeFbaReturnsReport(), see detailed info. "
+ transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString()); + transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString());
} }
} }
public void ProcessFbaAdustmentData(string sqlConnectionString) public void ProcessFbaAdustmentData(string sqlConnectionString)
{ {
MiscFunction.EventLogInsert("Starting TransposeFbaAdustmentReport()"); new Logic.Log.LogEvent().EventLogInsert("Starting TransposeFbaAdustmentReport()");
int transposeCount = 0; int transposeCount = 0;
int transposeSkip = 0; int transposeSkip = 0;
int stockJournalTypeId = 8; int stockJournalTypeId = 8;
@@ -2691,7 +2259,7 @@ namespace bnhtrade.Core
} }
else else
{ {
MiscFunction.EventLogInsert( new Logic.Log.LogEvent().EventLogInsert(
"Aborted TransposeFbaAdustmentReport(), no reason code was found in import table/file. Check imput data.", "Aborted TransposeFbaAdustmentReport(), no reason code was found in import table/file. Check imput data.",
1); 1);
return; return;
@@ -2713,7 +2281,7 @@ namespace bnhtrade.Core
//{ //{
// string errorMessage = // string errorMessage =
// "New transaction-type created/detected while running TransposeFbaAdustmentReport. Stock transaction table incomplete, update transaction-type table and run import/transpose again before stock reconciliation. WHERE ImportFbaInventoryAdjustmentReportID=" + importTableId; // "New transaction-type created/detected while running TransposeFbaAdustmentReport. Stock transaction table incomplete, update transaction-type table and run import/transpose again before stock reconciliation. WHERE ImportFbaInventoryAdjustmentReportID=" + importTableId;
// //MiscFunction.EventLogInsert(errorMessage, 1); // //new Logic.Log.LogEvent().EventLogInsert(errorMessage, 1);
// throw new Exception(errorMessage); // throw new Exception(errorMessage);
//} //}
@@ -2983,12 +2551,12 @@ namespace bnhtrade.Core
} }
} }
MiscFunction.EventLogInsert("TransposeFbaAdustmentReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaAdustmentReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped.");
if (transposeSkip > 0) { MiscFunction.EventLogInsert(transposeSkip + " number records skipped during TransposeFbaAdustmentReport() operation.", 2); } if (transposeSkip > 0) { new Logic.Log.LogEvent().EventLogInsert(transposeSkip + " number records skipped during TransposeFbaAdustmentReport() operation.", 2); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Exception catch, aborting TransposeFbaAdustmentReport(), see detailed info. " new Logic.Log.LogEvent().EventLogInsert("Exception catch, aborting TransposeFbaAdustmentReport(), see detailed info. "
+ transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString()); + transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString());
} }
@@ -3006,7 +2574,7 @@ namespace bnhtrade.Core
* and also the 'Cost of goods' amounts moved to the appropreate account id * and also the 'Cost of goods' amounts moved to the appropreate account id
*/ */
MiscFunction.EventLogInsert("Starting TransposeFbaRemovalOrderReport()"); new Logic.Log.LogEvent().EventLogInsert("Starting TransposeFbaRemovalOrderReport()");
int transposeCount = 0; int transposeCount = 0;
int transposeSkip = 0; int transposeSkip = 0;
int stockJournalTypeId = 11; int stockJournalTypeId = 11;
@@ -3124,19 +2692,19 @@ namespace bnhtrade.Core
} }
} }
} }
MiscFunction.EventLogInsert("ProcessFbaReimbursementData() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); new Logic.Log.LogEvent().EventLogInsert("ProcessFbaReimbursementData() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped.");
if (transposeSkip > 0) { MiscFunction.EventLogInsert(transposeSkip + " number records skipped during TransposeFbaRemovalOrderReport() operation.", 2); } if (transposeSkip > 0) { new Logic.Log.LogEvent().EventLogInsert(transposeSkip + " number records skipped during TransposeFbaRemovalOrderReport() operation.", 2); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Exception catch, aborting ProcessFbaReimbursementData(), see detailed info. " new Logic.Log.LogEvent().EventLogInsert("Exception catch, aborting ProcessFbaReimbursementData(), see detailed info. "
+ transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString()); + transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString());
} }
} }
public void ProcessReportFbaRemovalOrder(string sqlConnectionString) public void ProcessReportFbaRemovalOrder(string sqlConnectionString)
{ {
MiscFunction.EventLogInsert("Starting TransposeFbaRemovalOrderReport()"); new Logic.Log.LogEvent().EventLogInsert("Starting TransposeFbaRemovalOrderReport()");
int transposeCount = 0; int transposeCount = 0;
int transposeSkip = 0; int transposeSkip = 0;
int stockJournalTypeId = 10; int stockJournalTypeId = 10;
@@ -3244,12 +2812,12 @@ namespace bnhtrade.Core
} }
} }
} }
MiscFunction.EventLogInsert("TransposeFbaRemovalOrderReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); new Logic.Log.LogEvent().EventLogInsert("TransposeFbaRemovalOrderReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped.");
if (transposeSkip > 0) { MiscFunction.EventLogInsert(transposeSkip + " number records skipped during TransposeFbaRemovalOrderReport() operation.", 2); } if (transposeSkip > 0) { new Logic.Log.LogEvent().EventLogInsert(transposeSkip + " number records skipped during TransposeFbaRemovalOrderReport() operation.", 2); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MiscFunction.EventLogInsert("Exception catch, aborting TransposeFbaRemovalOrderReport(), see detailed info. " new Logic.Log.LogEvent().EventLogInsert("Exception catch, aborting TransposeFbaRemovalOrderReport(), see detailed info. "
+ transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString()); + transposeCount + " total records completed, " + transposeSkip + " records skipped.", 1, ex.ToString());
} }
} }
@@ -3495,54 +3063,6 @@ namespace bnhtrade.Core
public class MiscFunction public class MiscFunction
{ {
public static void EventLogInsert
(string detailShort = "", int eventType = 3, string detailLong = "", DateTime eventDateTime = default(DateTime), bool consolePrint = true)
{
// login credentials only allow insert on log table
string userId = "Log_bnhtrade";
string password = "52ya9dky55cniyynwro5e48mV9";
string sqlConnectionString =
"Data Source=SQL-Server;Initial Catalog=e2A;Persist Security Info=TRUE;User ID=" + userId +
";Password=" + password + ";MultipleActiveResultSets=TRUE";
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
{
using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
{
sqlConn.Open();
if (detailShort.Length == 0)
{
throw new ArgumentException("The string parameter detailShort is empty, this is a required paramenter.");
}
if (eventDateTime == default(DateTime))
{
eventDateTime = DateTime.UtcNow;
}
try
{
using (SqlCommand cmd = new SqlCommand(
"INSERT INTO tblLogEvent ( EventDateTime, LogEventTypeID, LogEventSourceID, Detail, DetailLong )" +
"VALUES ( @eventDateTime, @eventType, 1, @detailShort, @detailLong );"
, sqlConn))
{
cmd.Parameters.AddWithValue("@eventDateTime", eventDateTime);
cmd.Parameters.AddWithValue("@eventType", eventType);
cmd.Parameters.AddWithValue("@detailShort", detailShort);
cmd.Parameters.AddWithValue("@detailLong", detailLong);
cmd.ExecuteNonQuery();
}
UI.Console.WriteLine(detailShort);
}
catch (Exception ex)
{
UI.Console.WriteLine("WTF!!!! Error with error logging, jobs foooked!");
throw ex;
}
scope.Complete();
}
}
}
public static string TraceMessage( public static string TraceMessage(
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
@@ -3555,21 +3075,5 @@ namespace bnhtrade.Core
"\r\n\tsource line number: " + sourceLineNumber; "\r\n\tsource line number: " + sourceLineNumber;
return traceMessage; return traceMessage;
} }
public static void MwsThrottleWait(int waitSeconds)
{
MiscFunction.EventLogInsert("MWS request throttled, retrying in " + waitSeconds + " seconds...");
string consoleMessage = "{0} seconds remaining...";
UI.Console.Wait(consoleMessage, waitSeconds * 1000);
}
public static string GetTempFilePath(string fileName)
{
string directoryPath = Path.GetTempPath()
+ "_" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
+ "\\File\\";
System.IO.Directory.CreateDirectory(directoryPath);
string fullPath = directoryPath + fileName;
return fullPath;
}
} }
} }