Files
bnhtrade/src/bnhtrade.Core/Test/SQLLoop.cs
Bobbie Hodgetts 29f9fae508 Added invoice export function and started implementation of unitofwork pattern (#43)
* complete read invoices from db

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* updated nuget package spapi

* WIP

* wip, now test

* wip, jut need to fix tax inclusive line amounts not supported

* wip

* wip, before I f everything up

* no, it complies now, this is the one before I f everything up

* wip

* wip

* wip, logic ready for testing

* wip it builds!!!!

* wip tested, working, need to complete the gui section

* wip

* wip

* wip - created export invoice data delete, time for testing

* wip testing phase

* wip - delete function fully tested and working

* wip on to sorting out the issue with settlement invoices not tallying

* wip

* wip

* wip

* wip

* wip before I complete change the ReadInvoiceLineItem sections

* that appears to have worked, on with the main quest

* no it's doesn't work, saving before i remove the confusing cache system (just use a dictionary!!)

* wipping picadilli

* wip

* wip

* implemented uow on inovice export, now for testing

* wip

* wip all tested do invoice currency convertion fearure

* wip

* pretty much done so long as xero accepts the exported invoices

* Complete!
2025-06-26 23:29:22 +01:00

81 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.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))
{
UI.Console.WriteLine("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.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();
}
}
}
}
}