using bnhtrade.Core; using System; using System.Configuration; using System.Threading; using System.Transactions; namespace bnhtradeScheduledTasks { class Program { static Program() { } static void Main(string[] args) { if (OperatingSystem.IsWindows()) { TransactionManager.ImplicitDistributedTransactions = false; } if (args.Length == 0) { string consoleHeader = "Welcome to THE application!\n"; do { Console.Clear(); Console.WriteLine(consoleHeader); Console.WriteLine("Main Menu"); Console.WriteLine(); Console.WriteLine("<1> Amazon reports"); Console.WriteLine("<2> Stock functions"); Console.WriteLine("<3> Account functions"); Console.WriteLine(""); Console.WriteLine("<8> Start scheduled nightly tasks"); Console.WriteLine("<9> Dev functions"); Console.WriteLine(""); Console.WriteLine("<0> Exit"); Console.WriteLine(""); Console.Write("Enter an option >"); string input = Console.ReadLine(); if (input == "0") { break; } else if (input == "1") { do { Console.Clear(); Console.WriteLine(consoleHeader); Console.WriteLine("Main Menu > Amazon Reports"); Console.WriteLine(); Console.WriteLine("<1> Start nightly tasks"); Console.WriteLine(); Console.WriteLine("<2> Update FBA Inventory Data"); Console.WriteLine("<3> Update FBA Inventory Ledger Data (new)"); Console.WriteLine("<4> Update Amazon Settlement Data"); Console.WriteLine("<5> (depreciated) Update Fba Inventory Receipt Data"); Console.WriteLine("<6> Update Fba Sale Shipment Data"); Console.WriteLine("<7> Update Fba Return Data"); Console.WriteLine("<8> (depreciated) Update Fba Adustment Data"); Console.WriteLine("<9> Update Fba Removal Order Data"); Console.WriteLine("<10> Add all invoices to export queue"); Console.WriteLine(); Console.WriteLine("<0> Back"); Console.WriteLine(""); Console.Write("Enter an option >"); input = Console.ReadLine(); if (input == "0") { break; } else if (input == "1") { Console.Clear(); new bnhtrade.Core.Logic.Utilities.NightlyRoutine().DownloadAll(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "2") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaInventory().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "3") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaInventoryLedgerDetail().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "4") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonSettlement().SyncDatabase(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "5") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaInventoryReceipt().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "6") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaSaleShipment().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "7") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaCustomerReturn().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "8") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaInventoryAdjustment().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "9") { Console.Clear(); new bnhtrade.Core.Logic.Import.AmazonFbaRemovalOrder().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "10") { Console.Clear(); new bnhtrade.Core.Logic.Export.AccountInvoice.QueueService().ImportAll(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } } while (true); } else if (input == "2") { do { Console.Clear(); Console.WriteLine(consoleHeader); Console.WriteLine("Main Menu > Stock Funcions"); Console.WriteLine(); Console.WriteLine("Stock Reconciliation"); Console.WriteLine(); Console.WriteLine("<1> Update Fba Stock Import Data"); Console.WriteLine("<2> Process Fba Stock Import Data"); Console.WriteLine("<3> Reconcile stock transactions"); Console.WriteLine("<4> Run all above"); Console.WriteLine(); Console.WriteLine("<5> (temp) Update Amazon/Sku Min Max values"); Console.WriteLine(); Console.WriteLine("<0> Back"); Console.WriteLine(""); Console.Write("Enter an option >"); input = Console.ReadLine(); if (input == "0") { break; } else if (input == "1") { Console.Clear(); try { new bnhtrade.Core.Logic.Import.Amazon().SyncAllWithDatabase(); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "2") { Console.Clear(); try { new bnhtrade.Core.Logic.Stock.SkuTransactionImport().ImportAll(); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "3") { Console.Clear(); //try //{ var recon = new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(); recon.ReconcileStockTransactions(false); Console.WriteLine(recon.ItemsCompleted + " of " + (recon.ItemsCompleted + recon.ItemsRemaining) + " items completed."); Console.WriteLine("Current transaction ID=" + recon.CurrentSkuTransaction.SkuTransactionId); Console.WriteLine(recon.ProgressMessage); Console.WriteLine(""); //} //catch (Exception ex) //{ //Console.WriteLine(ex.Message.ToString()); //} Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "4") { Console.Clear(); try { new bnhtrade.Core.Logic.Import.Amazon().SyncAllWithDatabase(); new bnhtrade.Core.Logic.Stock.SkuTransactionImport().ImportAll(); new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile().ReconcileStockTransactions(false); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "5") { Console.Clear(); //try //{ Console.WriteLine("Currently disabled"); //bnhtrade.Core.Inventory.InventoryPricing.AmazonMinMaxTemp(sqlConnectionString); //} //catch (Exception ex) //{ //Console.WriteLine(ex.Message.ToString()); //} Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } } while (true); } else if (input == "3") { do { Console.Clear(); Console.WriteLine(consoleHeader); Console.WriteLine("Main Menu > Account"); Console.WriteLine(); Console.WriteLine("<1> Update HMRC Exchange Rates"); Console.WriteLine("<2> Generate invoices for export queue"); Console.WriteLine(); Console.WriteLine("<0> Back"); Console.WriteLine(""); Console.Write("Enter an option >"); input = Console.ReadLine(); if (input == "0") { break; } else if (input == "1") { Console.Clear(); new bnhtrade.Core.Logic.Account.CurrencyService().UpdateHmrcExchageRates(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "2") { Console.Clear(); var queueService = new bnhtrade.Core.Logic.Export.AccountInvoice.QueueService(); queueService.ImportAll(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } } while (true); } else if (input == "8") { Console.Clear(); new bnhtrade.Core.Logic.Utilities.NightlyRoutine().DownloadAll(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "9") { do { Console.Clear(); Console.WriteLine(consoleHeader); Console.WriteLine("Main Menu > Dev Funcions"); Console.WriteLine(); Console.WriteLine("<1> Test some randon function I've set here"); Console.WriteLine("<2> Test Account"); Console.WriteLine("<3> Test Export"); Console.WriteLine("<4> Test Import"); Console.WriteLine("<5> Test Logic"); Console.WriteLine("<6> Test SKU"); Console.WriteLine("<7> Test Stock"); Console.WriteLine("<8> Test Amazon SP-API"); Console.WriteLine("<9> Test Amazon"); Console.WriteLine(" Test SP-API Fulfilment Inbound"); Console.WriteLine(); Console.WriteLine("<0> Back"); Console.WriteLine(""); Console.Write("Enter an option >"); input = Console.ReadLine(); if (input == "0") { break; } else if (input == "1") { Console.Clear(); var obj = new bnhtrade.Core.Test.Amazon.SP_API.VariousCalls(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "2") { Console.Clear(); new bnhtrade.Core.Test.Account.Account(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "3") { Console.Clear(); new bnhtrade.Core.Test.Export.Export(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "4") { Console.Clear(); new bnhtrade.Core.Test.Import.Report(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "5") { Console.Clear(); new bnhtrade.Core.Test.Logic.Logic(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "6") { Console.Clear(); new bnhtrade.Core.Logic.Sku.Price.FbaPricing().Update(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "7") { Console.Clear(); new bnhtrade.Core.Test.Stock.Stock(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "8") { Console.Clear(); new bnhtrade.Core.Test.Amazon.SP_API.Reports(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "9") { Console.Clear(); new bnhtrade.Core.Test.Amazon.Amazon(); Console.WriteLine("Nothing to do here"); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } else if (input == "a") { Console.Clear(); new bnhtrade.Core.Test.Amazon.SP_API.FulfillmentInboundV0(); Console.WriteLine("Done"); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } } while (true); } } while (true); } else { if (args.Length > 1) { Console.WriteLine("Currently only one command line argument is accepted. Exiting application..."); Thread.Sleep(3000); } else { if (args[0] == "RunAll") { Console.WriteLine("Starting all reports download..."); Thread.Sleep(3000); Console.Clear(); new bnhtrade.Core.Logic.Utilities.NightlyRoutine().DownloadAll(); Console.WriteLine("Finished!! Exiting application..."); Thread.Sleep(3000); } else if (args[0] == "StockReconcileUnsafe") { Console.WriteLine("Starting (unsafe) stock reconciliation..."); Console.Clear(); var recon = new bnhtrade.Core.Logic.Stock.SkuTransactionReconcile(); recon.ReconcileStockTransactions(false); Console.WriteLine("Progress: " + recon.ProgressMessage); Console.WriteLine("Reconciled date: " + recon.LastItemDateTime.ToString()); Console.WriteLine("Transactions completed: " + recon.ItemsCompleted); Console.WriteLine("Transactions remaining: " + recon.ItemsRemaining); if (!recon.ReconciliationComplete) { Console.WriteLine("Halted at Stock Transaction ID: " + recon.CurrentSkuTransaction.SkuTransactionId); } Console.WriteLine("Exiting application..."); } else { Console.WriteLine("Command line parameter not recognised. Exiting application..."); Thread.Sleep(3000); } } Environment.Exit(0); } } } }