mirror of
https://github.com/stokebob/BealeEngineering.git
synced 2026-03-21 15:47:15 +00:00
57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Transactions;
|
|
|
|
namespace BealeEngineering.Core.Data.Database.Client
|
|
{
|
|
public class CreatePurchaseOrderAllocation : Connection
|
|
{
|
|
public CreatePurchaseOrderAllocation(string sqlConnectionString) : base(sqlConnectionString)
|
|
{
|
|
|
|
}
|
|
public int ByDictionary(Dictionary<int, int> saleInvoiceIdToPoLineId)
|
|
{
|
|
int rowsCreated = 0;
|
|
if (saleInvoiceIdToPoLineId == null || !saleInvoiceIdToPoLineId.Any())
|
|
{
|
|
throw new Exception("No data passed to function.");
|
|
}
|
|
|
|
using (TransactionScope scope = new TransactionScope())
|
|
{
|
|
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
foreach (var item in saleInvoiceIdToPoLineId)
|
|
{
|
|
using (SqlCommand cmd = new SqlCommand(@"
|
|
INSERT INTO ClientPurchaseOrderLineSalesInvoice (
|
|
ClientPurchaseOrderLineID
|
|
,SaleInvoiceID
|
|
)
|
|
VALUES (
|
|
@clientPurchaseOrderLineID
|
|
,@saleInvoiceID
|
|
)
|
|
", conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("@clientPurchaseOrderLineID", item.Value);
|
|
cmd.Parameters.AddWithValue("@saleInvoiceID", item.Key);
|
|
|
|
rowsCreated = rowsCreated + cmd.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
scope.Complete();
|
|
}
|
|
return rowsCreated;
|
|
}
|
|
}
|
|
}
|