mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
Feature: Sync MWS Shipment with Database
Various restructuring and misc. features added. Removed reliance on ABrain Amazon MWS NuGet package, added Amazon's own C# lib
This commit is contained in:
83
src/bnhtrade.Core/Test/InboundShipmentInfo.cs
Normal file
83
src/bnhtrade.Core/Test/InboundShipmentInfo.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using FBAInboundServiceMWS.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Test
|
||||
{
|
||||
public class InboundShipmentInfo
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
public InboundShipmentInfo(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
}
|
||||
public void SetDatabase()
|
||||
{
|
||||
var info = new Model.AmazonFBAInbound.ShipmentInfo();
|
||||
info.AmazonShipmentId = "BOBBIE2";
|
||||
info.DestinationFulfillmentCenterId = "HODG";
|
||||
info.LastUpdatedUtc = DateTime.UtcNow;
|
||||
info.ShipmentName = "the one";
|
||||
info.ShipmentStatus = "WORKING";
|
||||
|
||||
bool all = info.IsSetAll();
|
||||
bool allHead = info.IsSetAllHeaderInfo();
|
||||
|
||||
var itemInfoList = new List<Model.AmazonFBAInbound.ShipmentItemInfo>();
|
||||
|
||||
var itemInfo01 = new Model.AmazonFBAInbound.ShipmentItemInfo();
|
||||
itemInfo01.AmazonFNSKU = "Z0000000";
|
||||
itemInfo01.AmazonShipmentId = "BOBBIE2";
|
||||
itemInfo01.QuantityReceived = 4;
|
||||
itemInfo01.QuantityAllocated = 2;
|
||||
itemInfo01.SKUNumber = "000291-10";
|
||||
itemInfoList.Add(itemInfo01);
|
||||
|
||||
var itemInfo02 = new Model.AmazonFBAInbound.ShipmentItemInfo();
|
||||
itemInfo02.AmazonFNSKU = "Z0000001";
|
||||
itemInfo02.AmazonShipmentId = "BOBBIE2";
|
||||
itemInfo02.QuantityReceived = 3;
|
||||
itemInfo02.QuantityAllocated = 5;
|
||||
itemInfo02.SKUNumber = "000292-10";
|
||||
|
||||
itemInfoList.Add(itemInfo02);
|
||||
|
||||
info.ShipmentItemInfoList = itemInfoList;
|
||||
|
||||
//foreach (var item in itemInfoList)
|
||||
//{
|
||||
// Console.WriteLine("Qty Allocated: " + item.SKUNumber);
|
||||
// Console.WriteLine("Qty Allocated: " + item.QuantityAllocated);
|
||||
// Console.WriteLine("Qty Received: " + item.QuantityReceived);
|
||||
//}
|
||||
|
||||
var howto = new Data.Database.FBAInbound.SetShipmentInfo(sqlConnectionString);
|
||||
howto.Excecute(info);
|
||||
|
||||
var testkkkk = new Data.Database.FBAInbound.GetShipmentPrimaryKey(sqlConnectionString);
|
||||
int pknumber = testkkkk.ByAmazonShipmentId("FBA15CJCZ12");
|
||||
Console.WriteLine("ShipmentPK: " + pknumber);
|
||||
}
|
||||
public void GetMWSInfo()
|
||||
{
|
||||
var request = new ListInboundShipmentsRequest();
|
||||
|
||||
request.LastUpdatedBefore = new DateTime(2019, 06, 21);
|
||||
request.LastUpdatedAfter = new DateTime(2019, 01, 01);
|
||||
|
||||
var task = new Data.AmazonMWS.FBAInbound.ListInboundShipments();
|
||||
task.LastUpdatedBefore = new DateTime(2019, 06, 25);
|
||||
task.LastUpdatedAfter = new DateTime(2018, 01, 01);
|
||||
var result = task.GetShipmentInfo();
|
||||
|
||||
}
|
||||
public void Test()
|
||||
{
|
||||
var job = new Logic.AmazonFBAInbound.UpdateDatabaseShipmentInfo(sqlConnectionString);
|
||||
job.GetNew();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/bnhtrade.Core/Test/InboundShipmentInfoSync.cs
Normal file
17
src/bnhtrade.Core/Test/InboundShipmentInfoSync.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Test
|
||||
{
|
||||
class InboundShipmentInfoSync
|
||||
{
|
||||
public InboundShipmentInfoSync(string sqlConnectionString)
|
||||
{
|
||||
//var request = new Logic.AmazonFBAInbound.ShipmentInfoUpdateDatabase(sqlConnectionString);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
80
src/bnhtrade.Core/Test/SQLLoop.cs
Normal file
80
src/bnhtrade.Core/Test/SQLLoop.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace bnhtrade.Core.Test
|
||||
{
|
||||
public class SQLLoop
|
||||
{
|
||||
public void Go(string sqlConnectionString)
|
||||
{
|
||||
using (TransactionScope scope = new TransactionScope())
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
MiscFunction.ConsoleUpdate("Starting.....");
|
||||
conn.Open();
|
||||
|
||||
int count = 0;
|
||||
int total;
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT COUNT(StockJournalID)
|
||||
FROM tblStockJournal
|
||||
", conn))
|
||||
{
|
||||
total = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
|
||||
var progress = new UI.Utility.ConsoleProgressBar(total, "Processing " + total + " records...");
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT * FROM tblStockJournal
|
||||
", conn))
|
||||
{
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
count = count + 1;
|
||||
//progress.Report(2677);
|
||||
progress.Report(count);
|
||||
|
||||
int journalId = reader.GetInt32(0);
|
||||
DateTime entryDate = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc);
|
||||
DateTime modifiedDate = DateTime.SpecifyKind(reader.GetDateTime(5), DateTimeKind.Utc);
|
||||
DateTime postDate = entryDate;
|
||||
DateTime minPostDate = DateTime.SpecifyKind(new DateTime(2015, 06, 24), DateTimeKind.Utc);
|
||||
|
||||
if (modifiedDate < entryDate)
|
||||
{ postDate = entryDate; }
|
||||
if (postDate < minPostDate)
|
||||
{ postDate = minPostDate; }
|
||||
|
||||
using (
|
||||
SqlCommand updateCmd = new SqlCommand(@"
|
||||
UPDATE tblStockJournal
|
||||
SET PostDate = @postDate
|
||||
WHERE StockJournalID = @journalId;
|
||||
", conn))
|
||||
{
|
||||
updateCmd.Parameters.AddWithValue("@journalId", journalId);
|
||||
updateCmd.Parameters.AddWithValue("@postDate", postDate.ToUniversalTime());
|
||||
|
||||
updateCmd.ExecuteNonQuery();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
progress.Dispose();
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user