mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 22:47: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:
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