Feature repricing min max (#10)

amazon settlement import/export improvements
This commit is contained in:
2020-05-01 09:08:23 +01:00
committed by GitHub
parent 56647c7648
commit 43d61c2ef8
118 changed files with 7930 additions and 3021 deletions

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Account
{
public class CreateInvoiceLineItem : Connection
{
public CreateInvoiceLineItem(string sqlConnectionString) : base(sqlConnectionString)
{
}
public int CreateDefault(string itemCode)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(@"
INSERT INTO tblAccountInvoiceLineItem ( ItemName, ItemCode )
OUTPUT INSERTED.AccountInvoiceLineItemID
VALUES ( @itemName, @itemCode )
", conn))
{
cmd.Parameters.AddWithValue("@itemName", itemCode);
cmd.Parameters.AddWithValue("@itemCode", itemCode);
object obj = cmd.ExecuteScalar();
if (obj == null || obj == DBNull.Value)
{
throw new Exception("Error inserting new defalt invoice line item into database");
}
return (int)obj;
}
}
}
}
}

View File

@@ -9,62 +9,34 @@ namespace bnhtrade.Core.Data.Database.Account
{
public class ReadAccountCode : Connection
{
private bool allRetrived;
private Dictionary<int, Model.Account.AccountCode> cache;
protected ReadAccountCode(string sqlConnectionString) : base(sqlConnectionString)
private Data.Database.WhereBuilder sqlWhere = new WhereBuilder();
private List<Model.Account.AccountCode> resultList;
public ReadAccountCode(string sqlConnectionString) : base(sqlConnectionString)
{
allRetrived = false;
cache = new Dictionary<int, Model.Account.AccountCode>();
}
protected void ClearCache()
public List<Model.Account.AccountCode> All()
{
allRetrived = false;
cache.Clear();
Innit();
return Execute(null, null);
}
public List<Model.Account.AccountCode> GetAll()
public List<Model.Account.AccountCode> ByAccountCode(List<int> accountCodeList)
{
if (allRetrived == false)
Innit();
if (accountCodeList == null || !accountCodeList.Any())
{
UpdateCache(-1);
allRetrived = true;
return resultList;
}
var returnList = new List<Model.Account.AccountCode>();
foreach (var item in cache)
{
returnList.Add(item.Value);
}
return returnList;
sqlWhere.In("tblAccountChartOf.AccountCode", accountCodeList, " WHERE ");
return Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList);
}
public Model.Account.AccountCode GetByAccountCode(int accountCode)
{
if (cache.ContainsKey(accountCode))
{
return cache[accountCode];
}
else if (allRetrived)
{
return null;
}
else
{
UpdateCache(accountCode);
if (cache.ContainsKey(accountCode))
{
return cache[accountCode];
}
else
{
return null;
}
}
}
protected void UpdateCache(int accountCode = -1)
{
var dicCache = new Dictionary<int, Model.Account.AccountCode>();
bool whereClause = false;
private List<Model.Account.AccountCode> Execute(string sqlWhere, Dictionary<string, object> parameters)
{
//build sql query
string sqlString = @"
SELECT tblAccountChartOf.AccountChartOfID
@@ -74,13 +46,8 @@ namespace bnhtrade.Core.Data.Database.Account
,tblAccountChartOfType.AccountChartOfType
,tblAccountChartOfType.BasicType
FROM tblAccountChartOf
INNER JOIN tblAccountChartOfType ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID";
if (accountCode > -1)
{
whereClause = true;
sqlString = sqlString + @"
WHERE (((tblAccountChartOf.AccountCode) = @accountCode))";
}
INNER JOIN tblAccountChartOfType ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID
" + sqlWhere;
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
@@ -88,9 +55,12 @@ namespace bnhtrade.Core.Data.Database.Account
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
if (whereClause)
if (parameters != null)
{
cmd.Parameters.AddWithValue("@accountCode", accountCode);
foreach (var parameter in parameters)
{
cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
}
}
using (SqlDataReader reader = cmd.ExecuteReader())
@@ -108,30 +78,19 @@ namespace bnhtrade.Core.Data.Database.Account
result.Type = reader.GetString(4);
result.BasicType = reader.GetString(5);
if (whereClause)
{
if (cache.ContainsKey(result.AccountCodeId))
{
cache.Remove(result.AccountCodeId);
}
cache.Add(result.AccountCodeId, result);
}
else
{
dicCache.Add(result.AccountCodeId, result);
}
resultList.Add(result);
}
}
return resultList;
}
}
}
// update cache
if (!whereClause)
{
cache.Clear();
allRetrived = true;
cache = dicCache;
}
}
private void Innit()
{
resultList = new List<Model.Account.AccountCode>();
}
}
}

View 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;
}
}
}
}
}
}

View File

@@ -1,148 +0,0 @@
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 ReadInvoiceLineItemCode : Connection
{
public ReadInvoiceLineItemCode(string sqlConnectionString) : base (sqlConnectionString)
{
cacheLineItemByTablePk = new Dictionary<int, Model.Account.InvoiceLineItem>();
cacheTablePkByItemCode = new Dictionary<string, int>();
}
private Dictionary<int, Model.Account.InvoiceLineItem> cacheLineItemByTablePk;
private Dictionary<string, int> cacheTablePkByItemCode;
public bool InsertNewOnNoMatch { get; set; } = false;
public string NewTypeTitle { get; } = "NEW TYPE";
public void CacheClear()
{
cacheLineItemByTablePk.Clear();
cacheTablePkByItemCode.Clear();
}
private void CacheRemove(int tablePk)
{
if (cacheLineItemByTablePk.ContainsKey(tablePk))
{
string itemCode = cacheLineItemByTablePk[tablePk].ItemCode;
cacheLineItemByTablePk.Remove(tablePk);
cacheTablePkByItemCode.Remove(itemCode);
}
}
public void CacheRemove(string itemCode)
{
if (cacheTablePkByItemCode.ContainsKey(itemCode))
{
CacheRemove(cacheTablePkByItemCode[itemCode]);
}
}
private void CacheUpdate(int tablePk, Model.Account.InvoiceLineItem lineItem)
{
if (cacheLineItemByTablePk.ContainsKey(tablePk))
{
CacheRemove(tablePk);
}
cacheLineItemByTablePk.Add(tablePk, lineItem);
cacheTablePkByItemCode.Add(lineItem.ItemCode, tablePk);
}
public Model.Account.InvoiceLineItem ByItemCode(string itemCode, bool forceCacheUpdate = false)
{
// check cache
if (!forceCacheUpdate && cacheTablePkByItemCode.ContainsKey(itemCode))
{
return cacheLineItemByTablePk[cacheTablePkByItemCode[itemCode]];
}
var returnObject = new Model.Account.InvoiceLineItem();
returnObject.ItemCode = itemCode;
using (TransactionScope scopeSupress = new TransactionScope(TransactionScopeOption.Suppress))
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(@"
SELECT tblExportAccountInvoiceLineType.ExportAccountInvoiceLineTypeID
,tblExportAccountInvoiceLineType.TypeTitle
,tblExportAccountInvoiceLineType.TypeDescription
,tblExportAccountInvoiceLineType.IsNewReviewRequired
,tblExportAccountInvoiceLineType.InvoiceLineEntryEnable
,tblAccountChartOf.AccountCode
,tblAccountTaxCode.TaxCode
FROM (
tblExportAccountInvoiceLineType LEFT JOIN tblAccountChartOf ON tblExportAccountInvoiceLineType.AccountChartOfID_Default = tblAccountChartOf.AccountChartOfID
)
LEFT JOIN tblAccountTaxCode ON tblExportAccountInvoiceLineType.AccountTaxCodeID_Default = tblAccountTaxCode.AccountTaxCodeID
WHERE (((tblExportAccountInvoiceLineType.MatchString) = @matchString))
", conn))
{
cmd.Parameters.AddWithValue("@matchString", returnObject.ItemCode);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
int tablePk = reader.GetInt32(0);
returnObject.Title = reader.GetString(1);
if (!reader.IsDBNull(2)) { returnObject.Description = reader.GetString(2); }
returnObject.IsNewReviewRequired = reader.GetBoolean(3);
returnObject.InvoiceLineEntryEnabled = reader.GetBoolean(4);
if (!reader.IsDBNull(5)) { returnObject.DefaultAccountCode = reader.GetInt32(5); }
if (!reader.IsDBNull(6)) { returnObject.DefaultTaxCode = reader.GetString(6); }
// add to cache
CacheUpdate(tablePk, returnObject);
// return object
return returnObject;
}
}
}
// insert new and retrive new value, if required
if (InsertNewOnNoMatch)
{
int tablePk = 0;
returnObject.Title = NewTypeTitle;
returnObject.ItemCode = itemCode;
returnObject.IsNewReviewRequired = true;
using (SqlCommand insertCmd = new SqlCommand(@"
INSERT INTO tblExportAccountInvoiceLineType ( TypeTitle, MatchString )
OUTPUT INSERTED.ExportAccountInvoiceLineTypeID
VALUES ( @typeTitle, @matchString )
", conn))
{
insertCmd.Parameters.AddWithValue("@typeTitle", returnObject.Title);
insertCmd.Parameters.AddWithValue("@matchString", returnObject.ItemCode);
tablePk = (int)insertCmd.ExecuteScalar();
scopeSupress.Complete();
}
// add to cache
CacheUpdate(tablePk, returnObject);
// return object
return returnObject;
}
else
{
return null;
}
}
}
}
}

View File

@@ -9,165 +9,32 @@ namespace bnhtrade.Core.Data.Database.Account
{
public class ReadTaxCode : Connection
{
private bool allRetrived;
private Dictionary<string, Model.Account.TaxCode> cache;
private Data.Database.WhereBuilder whereBuilder;
public ReadTaxCode(string sqlConnectionString) : base(sqlConnectionString)
{
allRetrived = false;
cache = new Dictionary<string, Model.Account.TaxCode>();
whereBuilder = new WhereBuilder();
}
private void ClearCache()
private List<Model.Account.TaxCodeInfo> Execute(string sqlWhere, Dictionary<string, object> parameters)
{
allRetrived = false;
cache.Clear();
}
public List<Model.Account.TaxCode> GetAll()
{
if (allRetrived == false)
{
UpdateCache(null);
allRetrived = true;
}
var resultList = new List<Model.Account.TaxCodeInfo>();
var returnList = new List<Model.Account.TaxCode>();
foreach (var item in cache)
{
returnList.Add(item.Value);
}
return returnList;
}
public Dictionary<string, Model.Account.TaxCode> BySkuNumber(List<string> skuNumberList)
{
// check input list for items
if (skuNumberList == null || !skuNumberList.Any())
{
return null;
}
// build SQL string
string sqlString = @"
SELECT
tblSku.skuSkuNumber, tblAccountTaxCode.TaxCode
FROM
tblAccountTaxCode INNER JOIN tblSku ON tblAccountTaxCode.AccountTaxCodeID = tblSku.AccountTaxCodeID
WHERE
";
var parameterValueList = new List<Tuple<string, string>>();
foreach (var item in skuNumberList)
{
if (!string.IsNullOrWhiteSpace(item))
{
int count = parameterValueList.Count;
var parameterValue = new Tuple<string, string>("@parameter" + count, item);
parameterValueList.Add(parameterValue);
if (count == 0)
{
sqlString = sqlString + @"
skuSkuNumber = " + parameterValue.Item1;
}
else
{
sqlString = sqlString + @"
OR skuSkuNumber = " + parameterValue.Item1;
}
}
}
if (parameterValueList.Count == 0)
{
return null;
}
// execute query and build result list
var skuTaxCodeList = new List<Tuple<string, string>>();
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
foreach (var item in parameterValueList)
{
cmd.Parameters.AddWithValue(item.Item1, item.Item2);
}
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
return null;
}
while (reader.Read())
{
var skuTaxCode = new Tuple<string, string>(
reader.GetString(0),
reader.GetString(1)
);
skuTaxCodeList.Add(skuTaxCode);
}
}
}
// build dictionary of skuNumber to TaxCodeInfo
var returnDictionary = new Dictionary<string, Model.Account.TaxCode>();
foreach (var item in skuTaxCodeList)
{
returnDictionary.Add(item.Item1, GetByTaxCodeId(item.Item2));
}
return returnDictionary;
}
}
public Model.Account.TaxCode GetByTaxCodeId(string taxCode)
{
if (cache.ContainsKey(taxCode))
{
return cache[taxCode];
}
else if (allRetrived)
{
return null;
}
else
{
UpdateCache(taxCode);
if (cache.ContainsKey(taxCode))
{
return cache[taxCode];
}
else
{
return null;
}
}
}
private void UpdateCache(string taxCode)
{
var dicCache = new Dictionary<string, Model.Account.TaxCode>();
bool whereClause = false;
//build sql query
string sqlString = @"
SELECT
TaxCode
,TaxRateName
,TaxRateMultiplierNet
,TaxRateMultiplierGross
,TaxCodeName
,TaxCodeDescription
,TaxRatePercent
,IsMarginScheme
,IsValidOnExpense
,IsVailidOnIncome
,Description
,IsActive
,TaxType
FROM tblAccountTaxCode";
if (!string.IsNullOrWhiteSpace(taxCode))
{
whereClause = true;
sqlString = sqlString + @"
WHERE TaxCode = @taxCode";
}
sqlString += sqlWhere;
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
@@ -175,9 +42,9 @@ namespace bnhtrade.Core.Data.Database.Account
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
if (whereClause)
foreach (var paramter in parameters)
{
cmd.Parameters.AddWithValue("@taxCode", taxCode);
cmd.Parameters.AddWithValue(paramter.Key, paramter.Value);
}
using (SqlDataReader reader = cmd.ExecuteReader())
@@ -186,42 +53,160 @@ namespace bnhtrade.Core.Data.Database.Account
{
while (reader.Read())
{
var result = new Model.Account.TaxCode();
string taxCodeId = reader.GetString(0);
string name = reader.GetString(1);
string description = null;
if (!reader.IsDBNull(2)) { description = reader.GetString(2); }
decimal rate = reader.GetDecimal(3);
bool isMargin = reader.GetBoolean(4);
bool isValidOnExpense = reader.GetBoolean(5);
bool isValidOnIncome = reader.GetBoolean(6);
bool isActive = reader.GetBoolean(7);
string taxType = reader.GetString(8);
result.TaxCodeId = reader.GetString(0);
result.TaxRateTitle = reader.GetString(1);
result.NetAmountMultiplier = reader.GetDecimal(2);
result.GrossAmountMultiplier = reader.GetDecimal(3);
result.IsValidOnExpense = reader.GetBoolean(4);
result.IsValidOnIncome = reader.GetBoolean(5);
if (!reader.IsDBNull(6)) { result.TaxRateDescription = reader.GetString(6); }
result.IsActive = reader.GetBoolean(7);
result.TaxType = reader.GetString(8);
var result = new Model.Account.TaxCodeInfo(
taxCodeId,
name,
description,
rate,
isMargin,
isValidOnExpense,
isValidOnIncome,
taxType,
isActive);
if (whereClause)
{
if (cache.ContainsKey(result.TaxCodeId))
{
cache.Remove(result.TaxCodeId);
}
cache.Add(result.TaxCodeId, result);
}
else
{
dicCache.Add(result.TaxCodeId, result);
}
resultList.Add(result);
}
}
}
}
}
// update cache
if (!whereClause)
return resultList;
}
public List<Model.Account.TaxCodeInfo> GetByTaxCode(List<string> taxcodeList)
{
var resultList = new List<Model.Account.TaxCodeInfo>();
if (taxcodeList == null || !taxcodeList.Any())
{
cache.Clear();
allRetrived = true;
cache = dicCache;
return resultList;
}
whereBuilder.Innit();
whereBuilder.In("TaxCode", taxcodeList, "WHERE");
return Execute(whereBuilder.SqlWhereString, whereBuilder.ParameterList);
}
public List<Model.Account.TaxCodeInfo> GetAllActive()
{
string sqlWhere = @"
WHERE IsActive=@isActive;";
var parameters = new Dictionary<string, object>();
parameters.Add("@isActive", true);
return Execute(sqlWhere, parameters);
}
public Dictionary<string, string> GetTaxCodeBySkuNumber(List<string> skuNumberList)
{
var resultList = new Dictionary<string, string>();
if (skuNumberList == null || !skuNumberList.Any())
{
return resultList;
}
string sql = @"
SELECT tblSku.skuSkuNumber
,tblAccountTaxCode.TaxCode
FROM tblSku
INNER JOIN tblAccountTaxCode ON tblSku.AccountTaxCodeID = tblAccountTaxCode.AccountTaxCodeID ";
whereBuilder.Innit();
whereBuilder.In("tblSku.skuSkuNumber", skuNumberList, "WHERE");
sql += whereBuilder.SqlWhereString;
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(sql, conn))
{
foreach (var param in whereBuilder.ParameterList)
{
cmd.Parameters.AddWithValue(param.Key, param.Value);
}
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
return resultList;
}
while (reader.Read())
{
resultList.Add(reader.GetString(0), reader.GetString(1));
}
}
}
}
return resultList;
}
public Dictionary<string, string> GetTaxCodeByInvoiceLineItemCode(List<string> lineItemCode)
{
var resultList = new Dictionary<string, string>();
if (lineItemCode == null || !lineItemCode.Any())
{
return resultList;
}
string sql = @"
SELECT tblAccountInvoiceLineItem.ItemCode
,tblAccountTaxCode.TaxCode
FROM tblAccountInvoiceLineItem
LEFT OUTER JOIN tblAccountTaxCode ON tblAccountInvoiceLineItem.AccountTaxCodeID_Default = tblAccountTaxCode.AccountTaxCodeID
";
whereBuilder.Innit();
whereBuilder.In("tblAccountInvoiceLineItem.ItemCode", lineItemCode, "WHERE");
sql += whereBuilder.SqlWhereString;
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(sql, conn))
{
foreach (var param in whereBuilder.ParameterList)
{
cmd.Parameters.AddWithValue(param.Key, param.Value);
}
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
return resultList;
}
while (reader.Read())
{
if (reader.IsDBNull(1)) { resultList.Add(reader.GetString(0), null); }
else { resultList.Add(reader.GetString(0), reader.GetString(1)); }
}
}
}
}
return resultList;
}
}
}

View File

@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.AmazonShipment
{
public class ReadShipmentInfo : Connection
{
private List<string> shipmentIdList;
public ReadShipmentInfo(string sqlConnectionString) : base(sqlConnectionString)
{
}
/// <summary>
/// Return active shipments only. Default is false.
/// </summary>
public bool ReturnOnlyActiveShipments { get; set; } = false;
private bool IsSetFbaShipmentIdList
{
get
{
if (FbaShipmentIdList == null || !FbaShipmentIdList.Any()) { return false; }
else { return true; }
}
}
/// <summary>
/// Filter results by Amazon's shipment Id.
/// </summary>
private List<string> FbaShipmentIdList
{
get { return shipmentIdList; }
set
{
if (value != null)
{
// clean list
shipmentIdList = new List<string>();
foreach (string item in value)
{
if (item.Length > 0)
{
shipmentIdList.Add(item);
}
}
if (!FbaShipmentIdList.Any())
{
shipmentIdList = null;
throw new Exception("Invalid shipment Id set");
}
}
}
}
public Model.AmazonFba.ShipmentInfo HeaderByFbaShipmentId(string fbaShipmentId)
{
if (string.IsNullOrWhiteSpace(fbaShipmentId))
{
return null;
}
var list = new List<string> { fbaShipmentId };
var result = HeaderByFbaShipmentId(list);
if (result.Any())
{
return result[0];
}
else
{
return null;
}
}
public List<Model.AmazonFba.ShipmentInfo> HeaderByFbaShipmentId(List<string> fbaShipmentIdList)
{
FbaShipmentIdList = fbaShipmentIdList;
if (IsSetFbaShipmentIdList)
{
string sql = @"
AND tblAmazonShipment.ShipmentId IN @shipmentId ";
var parameters = new DynamicParameters();
parameters.Add("@shipmentId", FbaShipmentIdList);
return HeaderInfo(sql, parameters);
}
else
{
return new List<Model.AmazonFba.ShipmentInfo>();
}
}
/// <summary>
/// Retrives table primary key 'AmazonShipmentID' for tblAmazonShipment
/// </summary>
/// <param name="amazonShipmentId">Amazon's inbound FBA shipment Id.</param>
/// <returns>Primary key or -1 if match isn't found.</returns>
private List<Model.AmazonFba.ShipmentInfo> HeaderInfo(string sqlWhere, DynamicParameters parameters)
{
// build the sql string
string sql = @"
SELECT tblAmazonShipment.AmazonShipmentID
,tblAmazonShipment.ShipmentName
,tblAmazonShipment.ShipmentId AS FbaShipmentId
,tblAmazonShipment.CenterId
,tblAmazonShipment.ShipmentStatus
,tblAmazonShipment.LastUpdated
,tblAmazonShipment.IsClosed
,tblStockStatus.StockStatusID AS ShipmentStockStatusId
,tblStockStatus.StockStatus AS ShipmentStockStatus
FROM tblAmazonShipment
LEFT OUTER JOIN tblStockStatus ON tblAmazonShipment.ShipmentStockStatusID = tblStockStatus.StockStatusID
WHERE 1=1 ";
sql += sqlWhere;
if (ReturnOnlyActiveShipments)
{
sql = sql + @"
AND IsClosed = 0";
}
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
var result = conn.Query<Model.AmazonFba.ShipmentInfo>(sql, parameters).ToList();
// set datetime kind
for (int i = 0; i < result.Count; i++)
{
if (result[i].IsSetLastUpdated())
{
result[i].LastUpdated = DateTime.SpecifyKind(result[i].LastUpdated, DateTimeKind.Utc);
}
}
return result;
}
}
}
}

View File

@@ -5,14 +5,18 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.FBAInbound
namespace bnhtrade.Core.Data.Database.AmazonShipment
{
public class GetShipmentPrimaryKey : Connection
public class ReadShipmentPrimaryKey : Connection
{
private bool enableCache = false;
private Dictionary<string, int> shipmentPKByAmazonShipmentIdDic;
private Dictionary<int, string> amazonShipmentIdByShipmentPKDic;
public GetShipmentPrimaryKey(string sqlConnectionString) : base(sqlConnectionString) { }
public ReadShipmentPrimaryKey(string sqlConnectionString) : base(sqlConnectionString)
{
}
public bool CacheEnabled
{
get { return enableCache; }
@@ -30,6 +34,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
}
}
}
private void ClearCache()
{
if (CacheEnabled)
@@ -38,6 +43,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
amazonShipmentIdByShipmentPKDic.Clear();
}
}
private void DeleteCachedShipmentPK(int shipmentPrimaryKey)
{
if (CacheEnabled)
@@ -50,6 +56,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
}
}
}
/// <summary>
/// Retrives table primary key 'AmazonShipmentID' for tblAmazonShipment
/// </summary>
@@ -99,6 +106,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
UpdateCache(shipmentPK, amazonShipmentId);
return shipmentPK;
}
private void UpdateCache(int shipmentPK, string amazonShipmentId)
{
if (CacheEnabled)

View File

@@ -6,20 +6,24 @@ using System.Text;
using System.Threading.Tasks;
using System.Transactions;
namespace bnhtrade.Core.Data.Database.FBAInbound
namespace bnhtrade.Core.Data.Database.AmazonShipment
{
public class SetShipmentInfo : Connection
{
private GetShipmentPrimaryKey getPK;
private Data.Database.SKU.GetSkuId skuIdLoopkup;
public SetShipmentInfo(string sqlConnectionString) : base(sqlConnectionString) { }
private GetShipmentPrimaryKey GetPK
private ReadShipmentPrimaryKey getPK;
private Data.Database.Sku.GetSkuId skuIdLoopkup;
public SetShipmentInfo(string sqlConnectionString) : base(sqlConnectionString)
{
}
private ReadShipmentPrimaryKey GetPK
{
get
{
if (getPK == null)
{
getPK = new GetShipmentPrimaryKey(sqlConnectionString);
getPK = new ReadShipmentPrimaryKey(sqlConnectionString);
}
return getPK;
}
@@ -28,18 +32,20 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
getPK = value;
}
}
private Data.Database.SKU.GetSkuId SkuIdLoopkup
private Data.Database.Sku.GetSkuId SkuIdLoopkup
{
get
{
if (skuIdLoopkup == null)
{
skuIdLoopkup = new SKU.GetSkuId(sqlConnectionString);
skuIdLoopkup = new Sku.GetSkuId(sqlConnectionString);
}
return skuIdLoopkup;
}
}
public void Excecute(Model.AmazonFBAInbound.ShipmentInfo info)
public void Excecute(Model.AmazonFba.ShipmentInfo info)
{
using (var scope = new TransactionScope())
{
@@ -54,7 +60,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
}
// get tablePK
int shipmentPK = GetPK.ByAmazonShipmentId(info.AmazonShipmentId);
int shipmentPK = GetPK.ByAmazonShipmentId(info.FbaShipmentId);
// add or update shipment header info
if (shipmentPK == -1)
@@ -106,7 +112,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
}
}
public void ExcecuteByList(List<Model.AmazonFBAInbound.ShipmentInfo> infoList)
public void ExcecuteByList(List<Model.AmazonFba.ShipmentInfo> infoList)
{
using (var scope = new TransactionScope())
{
@@ -138,7 +144,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
}
}
private int InsertShipmentHeaderInfo(Model.AmazonFBAInbound.ShipmentInfo info)
private int InsertShipmentHeaderInfo(Model.AmazonFba.ShipmentInfo info)
{
if (!info.IsSetAll())
{
@@ -149,7 +155,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
{
conn.Open();
if (GetPK.ByAmazonShipmentId(info.AmazonShipmentId) != -1)
if (GetPK.ByAmazonShipmentId(info.FbaShipmentId) != -1)
{
throw new Exception("Shipment insert failed, shipment with same Amazon Id already exists.");
}
@@ -189,10 +195,10 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
{
cmd.Parameters.AddWithValue("@amazonShipmentCount", sequenceNumber);
cmd.Parameters.AddWithValue("@shipmentName", info.ShipmentName);
cmd.Parameters.AddWithValue("@shipmentId", info.AmazonShipmentId);
cmd.Parameters.AddWithValue("@shipmentId", info.FbaShipmentId);
cmd.Parameters.AddWithValue("@centerId", info.DestinationFulfillmentCenterId);
cmd.Parameters.AddWithValue("@shipmentStatus", info.ShipmentStatus);
cmd.Parameters.AddWithValue("@lastUpdated", info.LastUpdatedUtc);
cmd.Parameters.AddWithValue("@lastUpdated", info.LastUpdated.ToUniversalTime());
cmd.Parameters.AddWithValue("@isClosed", info.ShipmentIsClosed);
int tablePk = (int)cmd.ExecuteScalar();
@@ -203,9 +209,9 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
}
}
private void UpdateShipmentHeaderInfo(Model.AmazonFBAInbound.ShipmentInfo info)
private void UpdateShipmentHeaderInfo(Model.AmazonFba.ShipmentInfo info)
{
int tablePK = GetPK.ByAmazonShipmentId(info.AmazonShipmentId);
int tablePK = GetPK.ByAmazonShipmentId(info.FbaShipmentId);
if (tablePK == -1)
{
throw new Exception("Shipment insert failed, shipment with same Amazon Id already exists.");
@@ -229,7 +235,7 @@ namespace bnhtrade.Core.Data.Database.FBAInbound
{
cmd.Parameters.AddWithValue("@shipmentName", info.ShipmentName);
cmd.Parameters.AddWithValue("@shipmentStatus", info.ShipmentStatus);
cmd.Parameters.AddWithValue("@lastUpdated", info.LastUpdatedUtc);
cmd.Parameters.AddWithValue("@lastUpdated", info.LastUpdated.ToUniversalTime());
cmd.Parameters.AddWithValue("@isClosed", info.ShipmentIsClosed);
cmd.Parameters.AddWithValue("@tablePK", tablePK);

View File

@@ -10,11 +10,14 @@ namespace bnhtrade.Core.Data.Database
public class Connection
{
protected readonly string sqlConnectionString;
public Connection(string sqlConnectionString)
{
// setup sql parameters
if (sqlConnectionString.Length == 0)
{ throw new Exception("Zero length sql connectionstring passed"); }
if (string.IsNullOrWhiteSpace(sqlConnectionString))
{
throw new Exception("Zero length sql connection string passed");
}
this.sqlConnectionString = sqlConnectionString;
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database
{
public static class Constants
{
public static int GetProductConditionIdNew()
{
return 10;
}
}
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Export
{
public class CreateAmazonFeedSubmission : Connection
{
public CreateAmazonFeedSubmission (string sqlConnectionString) : base(sqlConnectionString)
{
}
public int Execute(string feedType, Model.Data.DatabaseFileStream fileStreamData)
{
// write to db
int id = 0;
var result = new Model.Export.AmazonFeedSubmission();
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(@"
INSERT INTO tblExportAmazonFeedSubmission (
FileData
,FileExtention
,FileSize
,FileMD5base64
,ExportAmazonFeedSubmissionTypeID
,ExportAmazonFeedSubmissionStatusID )
OUTPUT
INSERTED.ExportAmazonFeedSubmissionID
,INSERTED.FileGUID
VALUES (
@fileData
,@fileExtention
,@fileSize
,@fileMD5base64
,(SELECT ExportAmazonFeedSubmissionTypeID
FROM tblExportAmazonFeedSubmissionType
WHERE FeedType = @feedType )
,(SELECT ExportAmazonFeedSubmissionStatusID
FROM tblExportAmazonFeedSubmissionStatus
WHERE FeedProcessingStatus = 'New' )
)
", conn))
{
fileStreamData.FileData.Position = 0;
cmd.Parameters.AddWithValue("@fileData", fileStreamData.FileData.ToArray());
cmd.Parameters.AddWithValue("@fileExtention", fileStreamData.FileExtention);
cmd.Parameters.AddWithValue("@fileSize", fileStreamData.FileSize);
cmd.Parameters.AddWithValue("@fileMD5base64", fileStreamData.FileMD5base64);
cmd.Parameters.AddWithValue("@feedType", feedType);
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
throw new Exception("Insert returned no rows");
reader.Read();
id = reader.GetInt32(0);
fileStreamData.FileGUID = reader.GetGuid(1);
}
return id;
}
}
}
}
}

View File

@@ -10,88 +10,15 @@ namespace bnhtrade.Core.Data.Database.Export
{
public class CreateSalesInvoice : Connection
{
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
public CreateSalesInvoice(string sqlConnectionString) : base(sqlConnectionString)
{
}
public void SaveInvoice(List<Model.Account.SalesInvoice> invoiceList)
public void Execute(List<Model.Account.SalesInvoice> invoiceList)
{
using (TransactionScope scope = new TransactionScope())
{
// get table pks for invoice type line and fill in invoice line details
var readItemCode = new Data.Database.Account.ReadInvoiceLineItemCode(sqlConnectionString);
readItemCode.InsertNewOnNoMatch = true;
bool newTypeFound = false;
bool newTypeTitleFound = false;
for (int i = 0; i < invoiceList.Count(); i++)
{
for (int j = 0; j < invoiceList[i].InvoiceLineList.Count(); j++)
{
var itemCodeInfo = readItemCode.ByItemCode(invoiceList[i].InvoiceLineList[j].ItemCode);
if (itemCodeInfo.InvoiceLineEntryEnabled == false)
{
invoiceList[i].InvoiceAmount = invoiceList[i].InvoiceAmount - invoiceList[i].InvoiceLineList[j].GrossTotalAmount;
invoiceList[i].InvoiceLineList.RemoveAt(j);
j = j - 1;
continue;
}
else if (itemCodeInfo.IsNewReviewRequired)
{
newTypeFound = true;
}
else
{
if (itemCodeInfo.Title == readItemCode.NewTypeTitle)
{ newTypeTitleFound = true; }
else
{
invoiceList[i].InvoiceLineList[j].AccountCode = itemCodeInfo.DefaultAccountCode;
invoiceList[i].InvoiceLineList[j].TaxCode = itemCodeInfo.DefaultTaxCode;
invoiceList[i].InvoiceLineList[j].Description = itemCodeInfo.Title;
}
}
}
}
if (newTypeFound || newTypeTitleFound)
{
if (newTypeFound)
{
log.LogError("New line ItemCode found. Add item code default values and then try again.");
}
if (newTypeTitleFound)
{
log.LogError("ItemCode found with the incomplete title '" + readItemCode.NewTypeTitle + "'. Update title and then try again.");
}
return;
}
// add temp invoice numbers to invoices
var sequence = new Programmability.Sequence(sqlConnectionString);
for (int i = 0; i < invoiceList.Count(); i++)
{
if (invoiceList[i].InvoiceNumberIsSet)
{
var log = new Logic.Log.LogEvent();
log.LogError("Unexpected invoice number found.");
return;
}
invoiceList[i].InvoiceNumber = "_tmp" + sequence.GetNext("ExportTempInvoiceNumber").ToString("00000000");
}
// validate the list of invoices
var validateInvoice = new Logic.Account.ValidateSalesInvoice();
validateInvoice.InvoiceLineDescriptionIsRequired = false;
validateInvoice.IsValidInvoice(invoiceList);
if (validateInvoice.ErrorListIsSet)
{
log.LogError("Invalid Sales invoice(s) found during Amazon Settlement process. See extended info.", validateInvoice.ErrorListToString());
return;
}
validateInvoice = null;
using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
{
sqlConn.Open();
@@ -134,7 +61,7 @@ namespace bnhtrade.Core.Data.Database.Export
cmd.Parameters.AddWithValue("@currencyCode", invoiceList[i].InvoiceCurrencyCode);
cmd.Parameters.AddWithValue("@markComplete", false);
cmd.Parameters.AddWithValue("@invoiceNumber", invoiceList[i].InvoiceNumber);
cmd.Parameters.AddWithValue("@invoiceAmount", invoiceList[i].InvoiceAmount);
cmd.Parameters.AddWithValue("@invoiceAmount", invoiceList[i].InvoiceTotalAmount);
invoiceId = (int)cmd.ExecuteScalar();
}
@@ -145,7 +72,7 @@ namespace bnhtrade.Core.Data.Database.Export
using (SqlCommand cmd = new SqlCommand(@"
INSERT INTO tblExportAccountInvoiceLine (
ExportAccountInvoiceID
,ExportAccountInvoiceLineTypeID
,AccountInvoiceLineItemID
,NetAmount
,AccountChartOfID
,TaxAmount
@@ -155,9 +82,9 @@ namespace bnhtrade.Core.Data.Database.Export
VALUES (
@invoiceId
,(
SELECT ExportAccountInvoiceLineTypeID
FROM tblExportAccountInvoiceLineType
WHERE MatchString = @itemCode
SELECT AccountInvoiceLineItemID
FROM tblAccountInvoiceLineItem
WHERE ItemCode = @itemCode
)
,@netAmount
,(
@@ -176,10 +103,10 @@ namespace bnhtrade.Core.Data.Database.Export
{
cmd.Parameters.AddWithValue("@invoiceID", invoiceId);
cmd.Parameters.AddWithValue("@itemCode", invoiceList[i].InvoiceLineList[j].ItemCode);
cmd.Parameters.AddWithValue("@netAmount", invoiceList[i].InvoiceLineList[j].TotalNetAmount);
cmd.Parameters.AddWithValue("@accountCode", invoiceList[i].InvoiceLineList[j].AccountCode);
cmd.Parameters.AddWithValue("@netAmount", invoiceList[i].InvoiceLineList[j].UnitAmount);
cmd.Parameters.AddWithValue("@accountCode", invoiceList[i].InvoiceLineList[j].AccountCode.AccountCodeId);
cmd.Parameters.AddWithValue("@taxAmount", invoiceList[i].InvoiceLineList[j].TaxAmount);
cmd.Parameters.AddWithValue("@taxCode", invoiceList[i].InvoiceLineList[j].TaxCode);
cmd.Parameters.AddWithValue("@taxCode", invoiceList[i].InvoiceLineList[j].TaxCode.TaxCode);
int lineId = (int)cmd.ExecuteScalar();
}
@@ -190,4 +117,4 @@ namespace bnhtrade.Core.Data.Database.Export
}
}
}
}
}

View File

@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Export
{
public class ReadAmazonFeedSubmission : Connection
{
public ReadAmazonFeedSubmission(string sqlConnectionString) : base(sqlConnectionString)
{
}
public bool RetriveFile { get; set; } = false;
public List<Model.Export.AmazonFeedSubmission> ByAmazonFeedSubmissionId(List<string> submissionId)
{
throw new NotImplementedException();
}
public List<Model.Export.AmazonFeedSubmission> GetOpenFeeds()
{
string sql = @"
WHERE tblExportAmazonFeedSubmissionStatus.FeedComplete = @feedComplete
AND FeedSubmissionId IS NOT NULL;";
var parameters = new Dictionary<string, object> { { "@feedComplete", false } };
return Execute(sql, parameters);
}
private List<Model.Export.AmazonFeedSubmission> Execute(string sqlWhereClause, Dictionary<string, object> parameters)
{
var returnList = new List<Model.Export.AmazonFeedSubmission>();
// build the sql string
string sql = @"
SELECT tblExportAmazonFeedSubmissionType.FeedType
,tblExportAmazonFeedSubmission.FeedSubmissionId
,tblExportAmazonFeedSubmissionStatus.FeedProcessingStatus
,tblExportAmazonFeedSubmission.SubmittedDate
,tblExportAmazonFeedSubmission.StartedProcessingDate
,tblExportAmazonFeedSubmission.CompletedProcessingDate";
if (RetriveFile)
sql += @"
,tblExportAmazonFeedSubmission.FileGUID
,tblExportAmazonFeedSubmission.FileData
,tblExportAmazonFeedSubmission.FileExtention
,tblExportAmazonFeedSubmission.FileSize
,tblExportAmazonFeedSubmission.FileMD5base64";
sql += @"
FROM tblExportAmazonFeedSubmission
INNER JOIN tblExportAmazonFeedSubmissionStatus
ON tblExportAmazonFeedSubmission.ExportAmazonFeedSubmissionStatusID
= tblExportAmazonFeedSubmissionStatus.ExportAmazonFeedSubmissionStatusID
INNER JOIN tblExportAmazonFeedSubmissionType
ON tblExportAmazonFeedSubmission.ExportAmazonFeedSubmissionTypeID
= tblExportAmazonFeedSubmissionType.ExportAmazonFeedSubmissionTypeID";
sql += sqlWhereClause;
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(sql, conn))
{
if (parameters != null || !parameters.Any())
{
foreach(var parameter in parameters)
{
cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
}
}
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
return returnList;
while (reader.Read())
{
var submission = new Model.Export.AmazonFeedSubmission();
if (!reader.IsDBNull(0))
submission.FeedType = reader.GetString(0);
if (!reader.IsDBNull(1))
submission.FeedSubmissionId = reader.GetString(1);
if (!reader.IsDBNull(2))
submission.FeedProcessingStatus = reader.GetString(2);
if (!reader.IsDBNull(3))
submission.SubmittedDate = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc);
if (!reader.IsDBNull(4))
submission.StartedProcessingDate = DateTime.SpecifyKind(reader.GetDateTime(4), DateTimeKind.Utc);
if (!reader.IsDBNull(5))
submission.CompletedProcessingDate = DateTime.SpecifyKind(reader.GetDateTime(5), DateTimeKind.Utc);
if (RetriveFile)
{
var file = new Model.Data.DatabaseFileStream();
file.FileGUID = reader.GetGuid(6);
byte[] fileData = (byte[])reader[7];
file.FileData = new System.IO.MemoryStream(fileData);
file.FileExtention = reader.GetString(8);
file.FileSize = reader.GetInt32(9);
file.FileMD5base64 = reader.GetString(10);
submission.File = file;
}
returnList.Add(submission);
}
}
}
}
return returnList;
}
}
}

View File

@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Export
{
public class UpdateAmazonFeedSubmission : Connection
{
public UpdateAmazonFeedSubmission(string sqlConnectionString) : base(sqlConnectionString)
{
}
public void AddAmazonFeedId(int exportAmazonFeedSubmissionID, string amazonFeedId)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(@"
SELECT COUNT (ExportAmazonFeedSubmissionID)
FROM tblExportAmazonFeedSubmission
WHERE FeedSubmissionId = @amazonFeedId", conn))
{
cmd.Parameters.AddWithValue("@amazonFeedId", amazonFeedId);
int i = (int)cmd.ExecuteScalar();
if (i > 0)
throw new Exception("Amazon submission Id already exists in table");
}
using (var cmd = new SqlCommand(@"
UPDATE tblExportAmazonFeedSubmission
SET FeedSubmissionId = @amazonFeedId
WHERE ExportAmazonFeedSubmissionID=@exportAmazonFeedSubmissionID", conn))
{
cmd.Parameters.AddWithValue("@amazonFeedId", amazonFeedId);
cmd.Parameters.AddWithValue("@exportAmazonFeedSubmissionID", exportAmazonFeedSubmissionID);
int i = cmd.ExecuteNonQuery();
if (i == 0)
throw new Exception("Error updating table.");
}
}
}
public void UpdateStatusInfo(Model.Export.AmazonFeedSubmission feedSubmission)
{
UpdateStatusInfo(new List<Model.Export.AmazonFeedSubmission> { feedSubmission });
}
public void UpdateStatusInfo(List<Model.Export.AmazonFeedSubmission> feedSubmissionList)
{
if (feedSubmissionList == null || !feedSubmissionList.Any())
return;
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
for (int i = 0; i < feedSubmissionList.Count; i++)
{
if (!feedSubmissionList[i].IsSetFeedSubmissionId)
throw new Exception("Amazon Feed Submission Id required");
if (!feedSubmissionList[i].IsSetFeedProcessingStatus)
throw new Exception("Amazon Feed stauts required");
string sql = @"
UPDATE tblExportAmazonFeedSubmission
SET ExportAmazonFeedSubmissionStatusID =
(SELECT ExportAmazonFeedSubmissionStatusID
FROM tblExportAmazonFeedSubmissionStatus
WHERE FeedProcessingStatus = @feedProcessingStatus )
,SubmittedDate = @submittedDate
,StartedProcessingDate = @startedProcessingDate
,CompletedProcessingDate = @completedProcessingDate
WHERE FeedSubmissionId = @feedSubmissionId;";
using (var cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@feedSubmissionId", feedSubmissionList[i].FeedSubmissionId);
cmd.Parameters.AddWithValue("@feedProcessingStatus", feedSubmissionList[i].FeedProcessingStatus);
if (!feedSubmissionList[i].IsSetSubmittedDate) { cmd.Parameters.AddWithValue("@submittedDate", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@submittedDate", feedSubmissionList[i].SubmittedDate.ToUniversalTime()); }
if (!feedSubmissionList[i].IsSetStartedProcessingDate) { cmd.Parameters.AddWithValue("@startedProcessingDate", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@startedProcessingDate", feedSubmissionList[i].StartedProcessingDate.ToUniversalTime()); }
if (!feedSubmissionList[i].IsSetCompletedProcessingDate) { cmd.Parameters.AddWithValue("@completedProcessingDate", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@completedProcessingDate", feedSubmissionList[i].CompletedProcessingDate.ToUniversalTime()); }
int j = cmd.ExecuteNonQuery();
if (j == 0)
throw new Exception("Error updating table.");
}
}
}
}
}
}

View File

@@ -1,157 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.FBAInbound
{
public class GetShipmentHeaderInfo : Connection
{
private List<string> shipmentIdList;
public GetShipmentHeaderInfo(string sqlConnectionString) : base(sqlConnectionString) { }
/// <summary>
/// Return active shipments only. Default is false.
/// </summary>
public bool ActiveShipments { get; set; } = false;
public bool IsSetActiveShipments { get { return true; } }
public bool IsSetShipmentIdList
{
get
{
if (ShipmentIdList == null || !ShipmentIdList.Any()) { return false; }
else { return true; }
}
}
/// <summary>
/// Filter results by Amazon's shipment Id.
/// </summary>
public List<string> ShipmentIdList
{
get { return shipmentIdList; }
set
{
if (value != null)
{
// clean list
shipmentIdList = new List<string>();
foreach (string item in value)
{
if (item.Length > 0)
{
shipmentIdList.Add(item);
}
}
if (!ShipmentIdList.Any())
{
shipmentIdList = null;
throw new Exception("Invalid shipment Id set");
}
}
}
}
/// <summary>
/// Retrives table primary key 'AmazonShipmentID' for tblAmazonShipment
/// </summary>
/// <param name="amazonShipmentId">Amazon's inbound FBA shipment Id.</param>
/// <returns>Primary key or -1 if match isn't found.</returns>
public List<Model.AmazonFBAInbound.ShipmentInfo> Execute()
{
// build the sql string
int countShipId = 0;
string sqlString = @"
SELECT
AmazonShipmentID
,ShipmentName
,ShipmentId
,CenterId
,ShipmentStatus
,LastUpdated
,IsClosed
FROM
tblAmazonShipment
WHERE
1 = 1";
if (ActiveShipments)
{
sqlString = sqlString + @"
AND IsClosed = 0";
}
var dicShipIdByParameterString = new Dictionary<string, string>();
if (IsSetShipmentIdList)
{
foreach (string item in ShipmentIdList)
{
countShipId = countShipId + 1;
string parameterString = "@shipmentId" + countShipId;
dicShipIdByParameterString.Add(parameterString, item);
if (countShipId == 1)
{
sqlString = sqlString + @"
AND ( ShipmentId = " + parameterString;
}
else
{
sqlString = sqlString + @"
OR ShipmentId = " + parameterString;
}
}
if (countShipId > 0)
{
sqlString = sqlString + " )";
}
}
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
// add shipId parameters
if (ShipmentIdList.Any())
{
foreach (var item in dicShipIdByParameterString)
{
cmd.Parameters.AddWithValue(item.Key, item.Value);
}
}
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
// no records
return null;
}
var infoList = new List<Model.AmazonFBAInbound.ShipmentInfo>();
while (reader.Read())
{
var info = new Model.AmazonFBAInbound.ShipmentInfo();
int tablePK = reader.GetInt32(0);
info.ShipmentName = reader.GetString(1);
info.AmazonShipmentId = reader.GetString(2);
info.DestinationFulfillmentCenterId = reader.GetString(3);
info.ShipmentStatus = reader.GetString(4);
info.LastUpdatedUtc = reader.GetDateTime(5);
bool dbIsClosed = reader.GetBoolean(6);
// db consistancy check
if (dbIsClosed != info.ShipmentIsClosed)
{
throw new Exception("Data inconstitancy in database: check shipment IsClosed where AmazonShipmentID=" + tablePK);
}
// update cache
infoList.Add(info);
}
return infoList;
}
}
}
}
}
}

View File

@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Import
{
public class ReadFbaInventoryAge : Connection
{
public ReadFbaInventoryAge(string sqlConnectionString): base(sqlConnectionString)
{
}
public (int MinAge, int MaxAge)? BySkuNumber(string skuNumber, string orderChannel)
{
int minAge = 0;
int maxAge = 0;
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd03 = new SqlCommand(@"
SELECT [snapshot-date]
,[inv-age-0-to-90-days]
,[inv-age-91-to-180-days]
,[inv-age-181-to-270-days]
,[inv-age-271-to-365-days]
,[inv-age-365-plus-days]
FROM tblImportFbaInventoryAgeReport
WHERE sku = @skuNumber AND marketplace = @orderChannel
", conn))
{
cmd03.Parameters.AddWithValue("@skuNumber", skuNumber);
cmd03.Parameters.AddWithValue("@orderChannel", orderChannel);
using (var reader03 = cmd03.ExecuteReader())
{
if (reader03.Read())
{
// final min age
if (reader03.GetInt32(1) > 0) { minAge = 1; }
else
{
if (reader03.GetInt32(2) > 0) { minAge = 91; }
else
{
if (reader03.GetInt32(3) > 0) { minAge = 181; }
else
{
if (reader03.GetInt32(4) > 0) { minAge = 271; }
else
{
if (reader03.GetInt32(5) > 0) { minAge = 366; }
}
}
}
}
//find max age
if (reader03.GetInt32(5) > 0) { maxAge = 2147483647; }
else
{
if (reader03.GetInt32(4) > 0) { maxAge = 365; }
else
{
if (reader03.GetInt32(3) > 0) { maxAge = 270; }
else
{
if (reader03.GetInt32(2) > 0) { maxAge = 180; }
else
{
if (reader03.GetInt32(1) > 0) { maxAge = 90; }
}
}
}
}
}
else
{
return null;
}
}
}
}
return (minAge, maxAge);
}
}
}

View File

@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Import
{
public class ReadFbaSaleShipment : Connection
{
public ReadFbaSaleShipment(string sqlConnectionString): base(sqlConnectionString)
{
}
public Dictionary<string, decimal> GetMaxSalePrice(List<string> skuNumber, int timePeriodDay)
{
var returnList = new Dictionary<string, decimal>();
if (skuNumber == null || !skuNumber.Any())
{
return returnList;
}
string sql = @"
SELECT sku
,Max(ISNULL([tblImportFbaSaleShipment].[item-price], 0) + ISNULL([tblImportFbaSaleShipment].[item-tax], 0)) AS Expr1
FROM tblImportFbaSaleShipment
WHERE (
(sku IN (";
for (int i = 0; i < skuNumber.Count; i++)
{
if (!(i + 1 == skuNumber.Count))
{
sql += "@skuNumber" + i + ", ";
}
else
{
sql += "@skuNumber" + i + "))";
}
}
sql += @"
AND ((tblImportFbaSaleShipment.[shipment-date]) >= @shipDateFilter)
)
GROUP BY sku;";
using (var conn = new SqlConnection(sqlConnectionString))
{
using (var cmd = new SqlCommand(sql, conn))
{
for (int i = 0; i < skuNumber.Count; i++)
{
cmd.Parameters.AddWithValue("@skuNumber" + i, skuNumber[i]);
}
cmd.Parameters.AddWithValue("@shipDateFilter", DateTime.Today.AddDays(timePeriodDay * -1));
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
return returnList;
}
while (reader.Read())
{
decimal price = reader.GetDecimal(1);
if (price > 0)
{
returnList.Add(reader.GetString(0), price);
}
}
}
}
}
return returnList;
}
public Dictionary<string, int> GetSaleCount(List<string> skuNumber, DateTime periodStart, DateTime periodEnd)
{
var returnList = new Dictionary<string, int>();
if (skuNumber == null || !skuNumber.Any())
{
return returnList;
}
string sql = @"
SELECT sku
,Count(1) AS CountOfSku
FROM tblImportFbaSaleShipment
WHERE (
(sku IN @skuNumber)
AND (
(tblImportFbaSaleShipment.[shipment-date] >= @periodStart)
AND tblImportFbaSaleShipment.[shipment-date] <= @periodEnd
)
)
GROUP BY sku;";
using (var conn = new SqlConnection(sqlConnectionString))
{
var param = new DynamicParameters();
param.Add("@skuNumber", skuNumber);
param.Add("@periodStart", periodStart.ToUniversalTime());
param.Add("@periodEnd", periodEnd.ToUniversalTime());
return conn.Query(sql, param).ToDictionary(
row => (string)row.sku,
row => (int)row.CountOfSku);
}
}
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Product
{
public class CreateCompetitivePrice : Connection
{
public CreateCompetitivePrice(string sqlConnectionString) : base(sqlConnectionString)
{
}
public int ProductCompetitivePriceSet(int productId, int conditionId, decimal price, bool isBuyBoxPrice, DateTime? priceDate = null)
{
DateTime dt = new DateTime();
if (priceDate == null || priceDate == default(DateTime))
{
dt = DateTime.Now;
}
else
{
dt = (DateTime)priceDate;
}
if (priceDate.Value.Kind == DateTimeKind.Unspecified)
{
throw new Exception("Unspecified DateTimeKind");
}
using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
{
sqlConn.Open();
using (SqlCommand cmd = new SqlCommand(@"
UPDATE Table1
SET (
CompetitivePrice = @price
,IsBuyBoxPrice = @isBuyBoxPrice
)
OUTPUT INSERTED.ProductPriceCompetitiveID
WHERE ProductID = @productId
AND SkuConditionID = @conditionId
AND PriceDate = @priceDate
IF @@ROWCOUNT = 0
INSERT INTO tblProductPriceCompetitive (
ProductID
,SkuConditionID
,CompetitivePrice
,PriceDate
,IsBuyBoxPrice
)
OUTPUT INSERTED.ProductPriceCompetitiveID
VALUES (
@productId
,@conditionId
,@price
,@priceDate
,@isBuyBoxPrice
);"
, sqlConn))
{
cmd.Parameters.AddWithValue("@productId", productId);
cmd.Parameters.AddWithValue("@conditionId", conditionId);
cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@priceDate", dt.ToUniversalTime());
cmd.Parameters.AddWithValue("@isBuyBoxPrice", isBuyBoxPrice);
return (int)cmd.ExecuteScalar();
}
}
}
}
}

View File

@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Product
{
public class ReadCompetitivePrice : Connection
{
public ReadCompetitivePrice(string sqlConnectionString) : base(sqlConnectionString)
{
}
public List<Model.Product.CompetitivePrice> Execute(List<(int productId, int conditionId)> productIdAndConditionId)
{
int maxParameterCount = 2100;
int parameterPerPrice = 2;
int maxQuery = (int)decimal.Round(maxParameterCount / parameterPerPrice) - 1;
var resultList = new List<Model.Product.CompetitivePrice>();
if (productIdAndConditionId == null)
{
return resultList;
}
if (productIdAndConditionId.Count == 0)
{
return resultList;
}
if (productIdAndConditionId.Count <= maxQuery)
{
return ExecuteSub(productIdAndConditionId);
}
else
{
var partialList = new List<(int productId, int conditionId)>();
int queryCount = 0;
for (int i= 0; i < productIdAndConditionId.Count; i++)
{
queryCount++;
partialList.Add(productIdAndConditionId[i]);
if (queryCount == maxQuery)
{
resultList.AddRange(ExecuteSub(partialList));
partialList = new List<(int productId, int conditionId)>();
queryCount = 0;
}
}
if (queryCount > 0)
{
resultList.AddRange(ExecuteSub(partialList));
}
return resultList;
}
}
private List<Model.Product.CompetitivePrice> ExecuteSub(List<(int productId, int conditionId)> productIdAndConditionId)
{
var resultList = new List<Model.Product.CompetitivePrice>();
// build the sql string
string sql = @"
SELECT t.CompetitivePrice, t.PriceDate, t.ProductID, t.SkuConditionID
FROM tblProductPriceCompetitive AS t INNER JOIN (SELECT ProductID, SkuConditionID, Max(PriceDate) AS MaxOfPriceDate
FROM tblProductPriceCompetitive ";
for(int i = 0; i < productIdAndConditionId.Count; i++)
{
if (i == 0)
{
sql += @"
WHERE (ProductID=@productId" + i + " AND SkuConditionID=@conditionId" + i + ")";
}
else
{
sql += @"
OR (ProductID=@productId" + i + " AND SkuConditionID=@conditionId" + i + ")";
}
}
sql += @"
GROUP BY ProductID , SkuConditionID) AS a
ON (t.PriceDate = a.MaxOfPriceDate)
AND (t.ProductID = a.ProductID)
AND (t.SkuConditionID = a.SkuConditionID)";
using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
{
sqlConn.Open();
using (SqlCommand cmd = new SqlCommand(sql, sqlConn))
{
for (int i = 0; i < productIdAndConditionId.Count; i++)
{
cmd.Parameters.AddWithValue("@productId" + i, productIdAndConditionId[i].productId);
cmd.Parameters.AddWithValue("@conditionId" + i, productIdAndConditionId[i].conditionId);
}
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
return resultList;
}
while (reader.Read())
{
var result = new Model.Product.CompetitivePrice();
result.ConditionId = reader.GetInt32(3);
result.Price = reader.GetDecimal(0);
result.PriceDatetime = DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
result.ProductId = reader.GetInt32(2);
result.PriceIsEstimated = false;
resultList.Add(result);
}
return resultList;
}
}
}
}
}
}

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Data.SqlClient;
namespace bnhtrade.Core.Data.Database.SKU
namespace bnhtrade.Core.Data.Database.Sku
{
public class GetSkuId
{

View File

@@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.SKU
namespace bnhtrade.Core.Data.Database.Sku
{
class GetSku : Connection
{

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Transactions;
namespace bnhtrade.Core.Data.Database.Sku.Price
{
public class CreatePricingDetail : Connection
{
public CreatePricingDetail(string sqlConnectionString) : base(sqlConnectionString)
{
}
public void Executue(List<Model.Sku.Price.PriceInfo> newInfo)
{
if (newInfo == null || !newInfo.Any())
{ return; }
using (var scope = new TransactionScope())
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
// write new item to table
for (int i = 0; i < newInfo.Count(); i++)
{
string sql = @"
INSERT INTO tblSkuPriceType (
SkuID
,[OrderChannelID]
,[PriceInfoTimeStamp]
,[OrderChannelQuantity]
,[UnitPurchaseCost]
,[UnitMinPriceProfit]
,[UnitMinPriceCost]
,[UnitMinPriceDestory]
,[InventoryAgeMin]
,[InventoryAgeMax]
,[SkuPriceTypeID]
,[CompetitivePrice]
,[MinPrice]
,[MaxPrice]
,[RepriceIncrement]
,[ReviewRequired]
)
VALUES (
(SELECT skuSkuID FROM tblSku WHERE skuSkuNumber=@skuNumber)
,(SELECT OrderChannelID FROM tblOrderChannel WHERE OrderChannel=@orderChannel)
,@priceInfoTimeStamp
,@orderChannelQuantity
,@unitPurchaseCost
,@unitMinPriceProfit
,@unitMinPriceCost
,@unitMinPriceDestory
,@inventoryAgeMin
,@inventoryAgeMax
,@skuPriceTypeID
,@competitivePrice
,@minPrice
,@maxPrice
,@repriceIncrement
,@reviewRequired
);";
using (var cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@skuNumber", newInfo[i].SkuNumber);
cmd.Parameters.AddWithValue("@orderChannel", newInfo[i].OrderChannel);
cmd.Parameters.AddWithValue("@priceInfoTimeStamp", newInfo[i].PriceInfoTimeStamp);
cmd.Parameters.AddWithValue("@orderChannelQuantity", newInfo[i].OrderChannelQuantity);
cmd.Parameters.AddWithValue("@unitPurchaseCost", newInfo[i].UnitPurchaseCost);
cmd.Parameters.AddWithValue("@unitMinPriceProfit", newInfo[i].UnitMinPriceProfit);
cmd.Parameters.AddWithValue("@unitMinPriceCost", newInfo[i].UnitMinPriceCost);
cmd.Parameters.AddWithValue("@unitMinPriceDestory", newInfo[i].UnitMinPriceDestory);
cmd.Parameters.AddWithValue("@inventoryAgeMin", newInfo[i].InventoryAgeMin);
cmd.Parameters.AddWithValue("@inventoryAgeMax", newInfo[i].InventoryAgeMax);
cmd.Parameters.AddWithValue("@skuPriceTypeID", newInfo[i].PriceTypeId);
cmd.Parameters.AddWithValue("@competitivePrice", newInfo[i].CompetitivePrice);
cmd.Parameters.AddWithValue("@minPrice", newInfo[i].MinPrice);
cmd.Parameters.AddWithValue("@maxPrice", newInfo[i].MaxPrice);
cmd.Parameters.AddWithValue("@repriceIncrement", newInfo[i].RepriceIncrement);
cmd.Parameters.AddWithValue("@reviewRequired", newInfo[i].ReviewRequired);
int j = cmd.ExecuteNonQuery();
if (j < 1)
{
throw new Exception("Failed database insert statement");
}
}
}
scope.Complete();
}
}
}
}

View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Sku.Price
{
public class ReadParameter : Connection
{
public ReadParameter(string sqlConnectionString) : base(sqlConnectionString)
{
}
public List<Model.Sku.Price.SkuPriceParameter> Execute()
{
string stringSql = @"
SELECT
b.SkuID AS SkuId
,b.SkuTotalQuantity AS TotalQuantity
,b.SkuTotalCost AS TotalCost
,b.SkuAvgUnitCost AS UnitCostAverage
,tblSku.skuSkuNumber AS SkuNumber
,tblSku.skuProductID AS ProductId
,tblSku.skuSkuConditionID AS ConditionId
,tblSku.AccountTaxCodeID AS TaxCodeId
,tblProductCategory.ProfitMinPercent AS ProfitMargin
,tblProductCategory.ProfitMinAmount AS PriceMinProfit
,(tblAmazonFeeEstimate.ReferralFee / tblAmazonFeeEstimate.PriceToEstimateFeeListingPrice) As AgentFeeMargin
,(tblAmazonFeeEstimate.VariableClosingFee + tblAmazonFeeEstimate.PerItemFee + tblAmazonFeeEstimate.FBAFee + tblAmazonFeeEstimate.OtherFee_Exception) AS AgentFeeFixed
,tblAccountTaxCode.TaxRateMultiplierGross AS VatMargin
,tblAccountTaxCode.TaxRateName AS TaxRateName
,tblSkuCondition.IsFixedPrice AS IsFixedPrice
,tblSkuCondition.CompetitivePriceMultiplierNew
FROM
(((((
SELECT
a.SkuID,
Sum(a.SumOfQuantity) AS SkuTotalQuantity,
Sum(a.QuanityTimesUnitCost) AS SkuTotalCost,
Sum(a.QuanityTimesUnitCost)/Sum(a.SumOfQuantity) AS SkuAvgUnitCost
FROM
(
SELECT
tblStock.SkuID,
Sum(tblStockJournalPost.Quantity) AS SumOfQuantity,
tblStockJournal.StockID, tblAccountStockCost.AmountUnit,
Sum([tblStockJournalPost].[Quantity])*[tblAccountStockCost].[AmountUnit] AS QuanityTimesUnitCost
FROM
(((tblStockJournalPost
INNER JOIN tblStockStatus
ON tblStockJournalPost.StockStatusID = tblStockStatus.StockStatusID)
INNER JOIN tblStockJournal ON tblStockJournalPost.StockJournalID = tblStockJournal.StockJournalID)
INNER JOIN tblAccountStockCost ON tblStockJournal.StockID = tblAccountStockCost.StockID)
INNER JOIN tblStock ON tblAccountStockCost.StockID = tblStock.StockID
WHERE
tblStockStatus.StockStatusTypeID=3
OR tblStockStatus.StockStatusTypeID=4
GROUP BY
tblStockJournal.StockID,
tblAccountStockCost.AmountUnit,
tblStock.SkuID
HAVING
Sum(tblStockJournalPost.Quantity)>0
) a
GROUP BY
a.SkuID
) b
INNER JOIN tblSku ON b.SkuID = tblSku.skuSkuID)
INNER JOIN tblProduct ON tblSku.skuProductID = tblProduct.prdProductID)
LEFT JOIN tblAmazonFeeEstimate ON tblProduct.prdProductID = tblAmazonFeeEstimate.ProductIdentifier )
INNER JOIN tblProductCategory ON tblProduct.ProductCategoryID = tblProductCategory.ProductCategoryID)
INNER JOIN tblAccountTaxCode ON tblSku.AccountTaxCodeID = tblAccountTaxCode.AccountTaxCodeID
INNER JOIN tblSkuCondition ON tblSku.skuSkuConditionID = tblSkuCondition.scnSkuConditionID
";
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
var invPricing = conn.Query<Model.Sku.Price.SkuPriceParameter>(stringSql).ToList();
if (invPricing != null || invPricing.Any())
{
return invPricing;
}
else
{
return null;
}
}
}
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Sku.Price
{
public class ReadPricingDetail : Connection
{
public ReadPricingDetail(string sqlConnectionString) : base(sqlConnectionString)
{
}
public Dictionary<string, Model.Sku.Price.PriceInfo> ReadDictionary(List<string> skuNumberList, string orderChannel)
{
var dic = new Dictionary<string, Model.Sku.Price.PriceInfo>();
var list = Read(skuNumberList, orderChannel);
for (int i = 0; i < list.Count; i++)
{
dic.Add(list[i].SkuNumber, list[i]);
}
return dic;
}
public List<Model.Sku.Price.PriceInfo> Read(List<string> skuNumberList, string orderChannel)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
string sql = @"
SELECT tblSku.skuSkuNumber AS SkuNumber
,tblOrderChannel.OrderChannel
,tblSkuPrice.PriceInfoTimeStamp
,tblSkuPrice.OrderChannelQuantity
,tblSkuPrice.UnitPurchaseCost
,tblSkuPrice.UnitMinPriceProfit
,tblSkuPrice.UnitMinPriceCost
,tblSkuPrice.UnitMinPriceDestory
,tblSkuPrice.InventoryAgeMin
,tblSkuPrice.InventoryAgeMax
,tblSkuPrice.CompetitivePrice
,tblSkuPrice.MinPrice
,tblSkuPrice.MaxPrice
,tblSkuPrice.RepriceIncrement
,tblSkuPrice.ReviewRequired
,tblSkuPriceType.SkuPriceTypeID
,tblSkuPriceType.TypeTitle
FROM tblSkuPrice
INNER JOIN tblSkuPriceType ON tblSkuPrice.SkuPriceTypeID = tblSkuPriceType.SkuPriceTypeID
INNER JOIN tblSku ON tblSkuPrice.SkuID = tblSku.skuSkuID
INNER JOIN tblOrderChannel ON tblSkuPrice.OrderChannelID = tblOrderChannel.OrderChannelID
WHERE tblSku.skuSkuNumber IN @skuNumber
AND (tblOrderChannel.OrderChannel = @orderChannel);";
var parameters = new DynamicParameters();
parameters.Add("@skuNumber", skuNumberList);
parameters.Add("@orderChannel", orderChannel);
return conn.Query<Model.Sku.Price.PriceInfo>(sql, parameters).ToList();
}
}
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Sku
{
public class ReadSkuConditionInfo : Connection
{
public ReadSkuConditionInfo(string sqlConnectionString): base(sqlConnectionString)
{
}
public List<Model.Sku.SkuConditionInfo> Read(List<int> conditionIdList)
{
string sql = @"
SELECT scnSkuConditionID AS SkuConditionId
,scnTitleShort AS TitleShort
,scnSkuNumberSuffix AS SkuConditionNumber
,BaseType AS AmazonBaseType
,IsFixedPrice
,CompetitivePriceMultiplierNew AS CompetitivePriceMultiplier
,scnRepricerStrategy AS RepricerStrategy
,scnAmazonIdentifier AS AmazonIdentifier
,scnConditionNoteDefault AS ConditionNoteDefault
,scnDescription AS Description
FROM tblSkuCondition";
if (conditionIdList != null || !conditionIdList.Any())
{
sql += @"
WHERE scnSkuConditionID IN @conditionIdList
";
}
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
var paramter = new DynamicParameters();
paramter.Add("@conditionIdList", conditionIdList);
return conn.Query<Model.Sku.SkuConditionInfo>(sql, paramter).ToList();
}
}
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Stock
{
public class CreateSkuTransaction : Connection
{
public CreateSkuTransaction(string sqlConnectionString) : base(sqlConnectionString)
{
}
public void Create(Model.Stock.SkuTransaction skuTransaction)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(@"
INSERT INTO tblStockSkuTransaction (
TransactionDate
,StockSkuTransactionTypeID
,ForeignKey
,Reference
,Detail
,SkuID
,Quantity
,IsProcessed
,StockJournalID
)
OUTPUT INSERTED.StockSkuTransactionID
VALUES (
@transactionDate
,@stockSkuTransactionTypeID
,@foreignKey
,@reference
,@Detail
,(
SELECT skuSkuID
FROM tblSku
WHERE skuSkuNumber = @skuNumber
)
,@quantity
,@isProcessed
,@stockJournalID
)
", conn))
{
cmd.Parameters.AddWithValue("@transactionDate", skuTransaction.TransactionDate.ToUniversalTime());
cmd.Parameters.AddWithValue("@stockSkuTransactionTypeID", skuTransaction.SkuTransactionTypeId);
if (!skuTransaction.IsSetForeignKey) { cmd.Parameters.AddWithValue("@foreignKey", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@foreignKey", skuTransaction.ForeignKey); }
if (!skuTransaction.IsSetReference) { cmd.Parameters.AddWithValue("@reference", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@reference", skuTransaction.Reference); }
if (!skuTransaction.IsSetDetail) { cmd.Parameters.AddWithValue("@detail", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@detail", skuTransaction.Detail); }
cmd.Parameters.AddWithValue("@skuNumber", skuTransaction.SkuNumber);
cmd.Parameters.AddWithValue("@quantity", skuTransaction.Quantity);
cmd.Parameters.AddWithValue("@isProcessed", skuTransaction.IsProcessed);
if (!skuTransaction.IsSetStockJournalId) { cmd.Parameters.AddWithValue("@stockJournalID", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@stockJournalID", skuTransaction.StockJournalId); }
object obj = cmd.ExecuteScalar();
if (obj == null || obj == DBNull.Value)
{
throw new Exception("Sku Reconcile Transaction insert failed");
}
skuTransaction.SkuTransactionId = (int)obj;
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Stock
{
public class DeleteSkuTransaction : Connection
{
public DeleteSkuTransaction (string sqlConnectionString): base(sqlConnectionString)
{
}
public void ByTransactionId(int skuReconcileId)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(@"
DELETE FROM tblStockSkuTransaction WHERE StockSkuTransactionID = @transactionId
", conn))
{
cmd.Parameters.AddWithValue("@transactionId", skuReconcileId);
if (cmd.ExecuteNonQuery() < 1)
{
throw new Exception("Delete sku transaction effected no records");
}
}
}
}
}
}

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Stock
{
public class ReadSkuTransaction : Connection
{
public ReadSkuTransaction(string sqlConnectionString) : base(sqlConnectionString)
{
}
public int? GetJournalId(int skuTransactionId)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (var cmd = new SqlCommand(@"
SELECT StockJournalID FROM tblStockSkuTransaction WHERE StockSkuTransactionID=@transactionId
", conn))
{
cmd.Parameters.AddWithValue("@transactionId", skuTransactionId);
object obj = cmd.ExecuteScalar();
if (obj == null || obj == DBNull.Value)
{
return null;
}
else
{
return (int)obj;
}
}
}
}
public List<Model.Stock.SkuTransaction> GetUnreconciled()
{
// order by stocktransId desc = Amazon reports are listed in datetime ASC order, some reports have date only,
// however I have reason to believe these are in time order.
// Adding this means they at least get processed in the correct order (maybe)!
string sqlWhere = @"
WHERE tblStockSkuTransaction.IsProcessed = 0
AND (
tblStockSkuTransactionType.StockJournalEntryEnabled = 1
OR tblStockSkuTransactionType.IsNewReviewRequired = 1
) ";
return Read(sqlWhere, new DynamicParameters());
}
private List<Model.Stock.SkuTransaction> Read(string sqlWhere, DynamicParameters parameters)
{
var resultList = new List<Model.Stock.SkuTransaction>();
string sql = @"
SELECT tblStockSkuTransaction.StockSkuTransactionID AS SkuTransactionId
,tblStockSkuTransaction.TransactionDate
,tblStockSkuTransaction.StockSkuTransactionTypeID AS SkuTransactionTypeId
,tblStockSkuTransaction.ForeignKey
,tblStockSkuTransaction.Reference
,tblStockSkuTransaction.Detail
,tblStockSkuTransaction.Quantity
,tblStockSkuTransaction.IsProcessed
,tblStockSkuTransaction.StockJournalID AS StockJournalId
,tblStockSkuTransactionType.TypeTitle AS SkuTransactionTypeName
,tblSku.skuSkuNumber AS SkuNumber
,tblStockSkuTransaction.SkuID
FROM tblStockSkuTransaction
INNER JOIN tblStockSkuTransactionType ON tblStockSkuTransaction.StockSkuTransactionTypeID = tblStockSkuTransactionType.StockSkuTransactionTypeID
INNER JOIN tblSku ON tblStockSkuTransaction.SkuID = tblSku.skuSkuID ";
sql += sqlWhere;
sql += @"
ORDER BY tblStockSkuTransaction.TransactionDate ASC, tblStockSkuTransaction.StockSkuTransactionID DESC;";
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
resultList = conn.Query<Model.Stock.SkuTransaction>(sql, parameters).ToList();
}
// set datetime kind
for (int i = 0; i < resultList.Count; i++)
{
if (resultList[i].IsSetTransactionDate)
{
resultList[i].TransactionDate = DateTime.SpecifyKind(resultList[i].TransactionDate, DateTimeKind.Utc);
}
}
return resultList;
}
}
}

View File

@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace bnhtrade.Core.Data.Database.Stock
{
public class ReadSkuTransactionType : Connection
{
public ReadSkuTransactionType(string sqlConnectionString) : base(sqlConnectionString)
{
}
/// <summary>
/// Depriciated, delete when not required by other code
/// </summary>
/// <param name="sqlConnectionString"></param>
/// <param name="typeCode"></param>
/// <returns></returns>
public int GetTypeId(string typeCode)
{
/* GetStockTransactionTypeId return meanings
* >0 use the as the TypeId when inserting transaction
* 0 Skip transpose, type doesn't exist or is new (not reviewed yet)
* -1 Type import/transpose is disabled, IsProcessed=TRUE StockTransactionID=NULL */
// old optional parameters
// , bool onNewReturnId = false, bool onNewDisableInsert = false
if (typeCode.Length == 0)
{
throw new Exception("Empty match string passed to method");
}
using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
{
sqlConn.Open();
using (SqlCommand cmd = new SqlCommand(@"
SELECT
StockSkuTransactionTypeID,
IsNewReviewRequired,
TransactionImportEnabled
FROM
tblStockSkuTransactionType
WHERE
TypeCode=@typeCode;
", sqlConn))
{
cmd.Parameters.AddWithValue("@typeCode", typeCode);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
int index01 = reader.GetOrdinal("StockSkuTransactionTypeID");
int index02 = reader.GetOrdinal("IsNewReviewRequired");
int index03 = reader.GetOrdinal("TransactionImportEnabled");
int transactionTypeId = reader.GetInt32(index01);
bool isNew = reader.GetBoolean(index02);
bool? importEnabled = reader[index03] as bool? ?? null; // column can be null
if (isNew == true || importEnabled == null)
{
// return 0 and 'skip' item
return 0;
}
else if (importEnabled == false)
{
// mark IsProcessed=true and leave transactionId=null
return -1;
}
else if (transactionTypeId > 0)
{
return transactionTypeId;
}
else
{
throw new Exception("Sku TransactionTypeId lookup method failed, is one of the 'enabled' boolean on table set to null?");
}
}
else
{
return 0;
}
}
}
}
}
private List<Model.Stock.SkuTransactionType> Execute(string sqlWhere, DynamicParameters param)
{
string sql = @"
SELECT tblStockSkuTransactionType.StockSkuTransactionTypeID AS TypeId
,tblStockSkuTransactionType.TypeName
,tblStockSkuTransactionType.TypeCode
,tblStockSkuTransactionType.TypeDescription
,tblStockSkuTransactionType.StockJournalTypeID
,tblStockSkuTransactionType.TransactionForeignKeyName
,tblStockSkuTransactionType.TransactionReferenceType
,tblStockSkuTransactionType.IsNewReviewRequired
,tblStockSkuTransactionType.TransactionImportEnabled
,tblStockSkuTransactionType.StockJournalEntryEnabled
,tblStockSkuTransactionType.DebitStockStatusID
,tblStockSkuTransactionType.CreditStockStatusID
,tblStockSkuTransactionType.StatusBalanceCheckRequired
,tblStockSkuTransactionType.FilterStockOnDateTime
,tblStockSkuTransactionType.FirstInFirstOut
,tblStockSkuTransactionType.RecordCreated
,CreditStatus.StockStatus AS CreditStockStatus
,DebitStatus.StockStatus AS DebitStockStatus
FROM tblStockStatus AS DebitStatus
RIGHT OUTER JOIN tblStockSkuTransactionType ON DebitStatus.StockStatusID = tblStockSkuTransactionType.DebitStockStatusID
LEFT OUTER JOIN tblStockStatus AS CreditStatus ON tblStockSkuTransactionType.CreditStockStatusID = CreditStatus.StockStatusID
";
sql += sqlWhere;
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
return conn.Query<Model.Stock.SkuTransactionType>(sql, param).ToList();
}
}
public List<Model.Stock.SkuTransactionType> ByTypeCode(List<string> typeCode)
{
string sqlWhere = @"
WHERE TypeCode IN @typeCode ";
var param = new DynamicParameters();
param.Add("@typeCode", typeCode);
return Execute(sqlWhere, param);
}
public List<Model.Stock.SkuTransactionType> ByTypeName(List<string> typeName)
{
string sqlWhere = @"
WHERE TypeName IN @typeName ";
var param = new DynamicParameters();
param.Add("@typeName", typeName);
return Execute(sqlWhere, param);
}
}
}

View File

@@ -0,0 +1,198 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database.Stock
{
public class UpdateSkuTransaction : Connection
{
private string err = "Database UpdateSkuTransaction: ";
public UpdateSkuTransaction(string sqlConnectionString) : base(sqlConnectionString)
{
}
public void Update(int skuTransactionId, bool isProcessed)
{
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(@"
UPDATE tblStockSkuTransaction
SET IsProcessed=@isProcessed
WHERE StockSkuTransactionID=@transactionId
", conn))
{
cmd.Parameters.AddWithValue("@isProcessed", isProcessed);
cmd.Parameters.AddWithValue("@transactionId", skuTransactionId);
int effected = cmd.ExecuteNonQuery();
if (effected < 1)
{
throw new Exception(err += "Sku Transaction IsProcessed update failed");
}
}
}
}
/// <summary>
/// Update the StockJournalID field. Will also set the IsProcessed value base on input.
/// </summary>
/// <param name="skuTransactionId">Sku Transaction Id</param>
/// <param name="stockJournalId">Stock Journal Id or null to unset</param>
public void Update(int skuTransactionId, int? stockJournalId)
{
string sql = @"
UPDATE tblStockSkuTransaction
SET IsProcessed = @isProcessed
,StockJournalID = @stockJournalID
WHERE StockSkuTransactionID = @transactionId;";
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
if (stockJournalId == null) { cmd.Parameters.AddWithValue("@stockJournalID", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@stockJournalID", (int)stockJournalId); }
if (stockJournalId == null) { cmd.Parameters.AddWithValue("@isProcessed", false); }
else { cmd.Parameters.AddWithValue("@isProcessed", true); }
cmd.Parameters.AddWithValue("@transactionId", skuTransactionId);
int effected = cmd.ExecuteNonQuery();
if (effected < 1)
{
throw new Exception(err += "Sku Transaction StockJournalID update failed");
}
}
}
}
public void Update(int skuTransactionId, int quantity, bool isProcessed)
{
string sql = @"
UPDATE tblStockSkuTransaction
SET IsProcessed = @isProcessed
,Quantity = @quantity
WHERE StockSkuTransactionID = @transactionId;";
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@isProcessed", isProcessed);
cmd.Parameters.AddWithValue("@quantity", quantity);
cmd.Parameters.AddWithValue("@transactionId", skuTransactionId);
int effected = cmd.ExecuteNonQuery();
if (effected < 1)
{
throw new Exception(err += "Sku Transaction quantity and isprocessed update failed");
}
}
}
}
/// <summary>
/// Update the StockJournalID field. Will also set the IsProcessed value base on input.
/// </summary>
/// <param name="skuTransactionId">Sku Transaction Id</param>
/// <param name="quantity">Sku Transaction quantity. Set to null to leave database value unchanged.</param>
/// <param name="stockJournalId">Stock Journal Id</param>
public void Update(int skuTransactionId, int? quantity, int stockJournalId)
{
string sql = @"
UPDATE tblStockSkuTransaction
SET IsProcessed = @isProcessed
,StockJournalID = @stockJournalID ";
if (quantity != null)
{
sql += @"
,Quantity = @quantity ";
}
sql += @"
WHERE StockSkuTransactionID = @transactionId;";
using (var conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
if (quantity != null) { cmd.Parameters.AddWithValue("@quantity", (int)quantity); }
cmd.Parameters.AddWithValue("@isProcessed", true);
cmd.Parameters.AddWithValue("@stockJournalID", stockJournalId);
cmd.Parameters.AddWithValue("@transactionId", skuTransactionId);
int effected = cmd.ExecuteNonQuery();
if (effected < 1)
{
throw new Exception(err += "Sku Transaction IsProcessed update failed");
}
}
}
}
public void Update(Model.Stock.SkuTransaction skuTransaction)
{
using (var conn = new SqlConnection())
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(@"
UPDATE tblStockSkuTransaction
SET TransactionDate = @transactionDate
,StockSkuTransactionTypeID = @stockSkuTransactionTypeID
,ForeignKey = @foreignKey
,Reference = @reference
,Detail = @Detail
,SkuID = (
SELECT skuSkuID
FROM tblSku
WHERE skuSkuNumber = @skuNumber
)
,Quantity = @quantity
,IsProcessed = @isProcessed
,StockJournalID = @stockJournalID
WHERE StockSkuTransactionID = @transactionId
", conn))
{
cmd.Parameters.AddWithValue("@transactionDate", skuTransaction.TransactionDate.ToUniversalTime());
cmd.Parameters.AddWithValue("@stockSkuTransactionTypeID", skuTransaction.SkuTransactionTypeId);
if (!skuTransaction.IsSetForeignKey) { cmd.Parameters.AddWithValue("@foreignKey", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@foreignKey", skuTransaction.ForeignKey); }
if (!skuTransaction.IsSetReference) { cmd.Parameters.AddWithValue("@reference", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@reference", skuTransaction.Reference); }
if (!skuTransaction.IsSetDetail) { cmd.Parameters.AddWithValue("@detail", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@detail", skuTransaction.Detail); }
cmd.Parameters.AddWithValue("@skuNumber", skuTransaction.SkuNumber);
cmd.Parameters.AddWithValue("@quantity", skuTransaction.Quantity);
cmd.Parameters.AddWithValue("@isProcessed", skuTransaction.IsProcessed);
if (!skuTransaction.IsSetStockJournalId) { cmd.Parameters.AddWithValue("@stockJournalID", DBNull.Value); }
else { cmd.Parameters.AddWithValue("@stockJournalID", skuTransaction.StockJournalId); }
cmd.Parameters.AddWithValue("@transactionId", skuTransaction.SkuTransactionId);
int effected = cmd.ExecuteNonQuery();
if (effected < 1)
{
throw new Exception(err += "stockSkuTransaction IsProcessed update failed");
}
}
}
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database
{
public class WhereBuilder
{
private int parameterCount;
public WhereBuilder()
{
Innit();
}
public string SqlWhereString { get; private set; }
public Dictionary<string, object> ParameterList { get; private set; }
public void Innit()
{
SqlWhereString = null;
ParameterList = new Dictionary<string, object>();
parameterCount = 0;
}
/// <summary>
/// Used to create a string for an SQL where condition 'In' statement
/// </summary>
/// <param name="columnReference">Name of the column to used to for the condition statement</param>
/// <param name="orValueList">List of values to test in condition statement</param>
/// <param name="wherePrefix">Optional string to prefix to the returned result</param>
public void In(string columnReference, List<string> orValueList, string wherePrefix = null)
{
Innit();
if (orValueList == null || !orValueList.Any())
{
return;
}
string sqlWhere = @"
";
if (wherePrefix != null)
{
sqlWhere += wherePrefix;
}
sqlWhere += " " + columnReference + " IN ( ";
var paramters = new Dictionary<string, object>();
int listCount = orValueList.Count();
for (int i = 0; i < listCount; i++, parameterCount++)
{
if (i > 0)
{
sqlWhere += ", ";
}
string param = "@parameter" + parameterCount;
sqlWhere += param;
paramters.Add(param, orValueList[i]);
}
sqlWhere += " )";
SqlWhereString = sqlWhere;
ParameterList = paramters;
}
/// <summary>
/// Used to create a string for an SQL where condition 'In' statement
/// </summary>
/// <param name="columnReference">Name of the column to used to for the condition statement</param>
/// <param name="orValueList">List of values to test in condition statement</param>
/// <param name="wherePrefix">Optional string to prefix to the returned result</param>
public void In(string columnReference, List<int> orValueList, string wherePrefix = null)
{
var stringList = new List<string>();
if (orValueList != null || !orValueList.Any())
{
foreach (int value in orValueList)
{
stringList.Add(value.ToString());
}
}
In(columnReference, stringList, wherePrefix);
}
}
}