mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-25 09:07:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
113
src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs
Normal file
113
src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
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.Data.Database.Account
|
||||
{
|
||||
public class ReadInvoiceLineItem : Connection
|
||||
{
|
||||
public ReadInvoiceLineItem(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
Innit();
|
||||
}
|
||||
|
||||
public Dictionary<string, int> AccountCodeList { get; private set; }
|
||||
|
||||
public Dictionary<string, string> TaxCodeList { get; private set; }
|
||||
|
||||
private void Innit()
|
||||
{
|
||||
AccountCodeList = new Dictionary<string, int>();
|
||||
TaxCodeList = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public Model.Account.InvoiceLineItem ByItemCode(string itemCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemCode)) { return null; }
|
||||
|
||||
var result = ByItemCode(new List<string>{ itemCode });
|
||||
|
||||
if (!result.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result[itemCode];
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, Model.Account.InvoiceLineItem> ByItemCode(List<string> itemCodeList)
|
||||
{
|
||||
Innit();
|
||||
var resultList = new Dictionary<string, Model.Account.InvoiceLineItem>();
|
||||
|
||||
if (itemCodeList == null || !itemCodeList.Any())
|
||||
{ return resultList; }
|
||||
|
||||
string sql = @"
|
||||
SELECT tblAccountInvoiceLineItem.ItemCode
|
||||
,tblAccountInvoiceLineItem.ItemName
|
||||
,tblAccountInvoiceLineItem.ItemDescription
|
||||
,tblAccountInvoiceLineItem.IsNewReviewRequired
|
||||
,tblAccountInvoiceLineItem.InvoiceLineEntryEnable
|
||||
,tblAccountChartOf.AccountCode
|
||||
,tblAccountTaxCode.TaxCode
|
||||
FROM tblAccountInvoiceLineItem
|
||||
LEFT OUTER JOIN tblAccountTaxCode ON tblAccountInvoiceLineItem.AccountTaxCodeID_Default = tblAccountTaxCode.AccountTaxCodeID
|
||||
LEFT OUTER JOIN tblAccountChartOf ON tblAccountInvoiceLineItem.AccountChartOfID_Default = tblAccountChartOf.AccountChartOfID
|
||||
WHERE ";
|
||||
|
||||
var whereBuilder = new WhereBuilder();
|
||||
whereBuilder.In("tblAccountInvoiceLineItem.ItemCode", itemCodeList);
|
||||
sql += whereBuilder.SqlWhereString;
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
foreach (var param in whereBuilder.ParameterList)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(param.Key, param.Value);
|
||||
}
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var result = new Model.Account.InvoiceLineItem();
|
||||
|
||||
result.ItemCode = reader.GetString(0);
|
||||
result.Name = reader.GetString(1);
|
||||
if (!reader.IsDBNull(2)) { result.Description = reader.GetString(2); }
|
||||
result.IsNewReviewRequired = reader.GetBoolean(3);
|
||||
result.InvoiceLineEntryEnabled = reader.GetBoolean(4);
|
||||
|
||||
if (!reader.IsDBNull(5))
|
||||
{
|
||||
AccountCodeList.Add(result.ItemCode, reader.GetInt32(5));
|
||||
}
|
||||
if (!reader.IsDBNull(6))
|
||||
{
|
||||
TaxCodeList.Add(result.ItemCode, reader.GetString(6));
|
||||
}
|
||||
|
||||
resultList.Add(result.ItemCode, result);
|
||||
}
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user