Export amazon settlement report fix

This commit is contained in:
2020-02-06 21:20:15 +00:00
committed by GitHub
parent bed529e1c8
commit 7e50da21e7
52 changed files with 4827 additions and 819 deletions
@@ -4,12 +4,12 @@ using System.Data.SqlClient;
namespace bnhtrade.Core.Data.Database.SKU
{
public class GetSKUId
public class GetSkuId
{
private Dictionary<string, int> SKUIdBySKUNumber { get; set; }
private Dictionary<int, string> SKUNumberBySKUId { get; set; }
private string SqlConnectionString { get; set; }
public GetSKUId(string sqlConnectionString)
public GetSkuId(string sqlConnectionString)
{
// setup sql parameters
if (sqlConnectionString.Length == 0)
@@ -0,0 +1,158 @@
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.SKU
{
class GetSku : Connection
{
private Dictionary<string, Model.Sku.Sku> cache;
protected GetSku (string sqlConnection) : base(sqlConnection)
{
Default();
}
protected List<Model.Sku.Sku> BySkuNumberList(List<string> skuNumberList, bool forceRequery = false)
{
if (skuNumberList == null || !skuNumberList.Any())
{
return null;
}
var getList = new List<string>();
foreach(string item in skuNumberList)
{
if (forceRequery || !cache.ContainsKey(item))
{
getList.Add(item);
}
}
// update the cache
CacheUpdate(getList);
// build the return list
var returnList = new List<Model.Sku.Sku>();
foreach (string item in skuNumberList)
{
if (cache.ContainsKey(item))
{
returnList.Add(cache[item]);
}
}
//return the list
if (returnList.Any())
{
return returnList;
}
else
{
return null;
}
}
protected void CacheClear()
{
cache.Clear();
}
private void CacheUpdate(List<string> skuNumberList)
{
// build the sql string
string sqlString = @"
SELECT
skuSkuID
,skuSkuNumber
,skuAmazonFNSKU
,skuActive
FROM tblSku
WHERE 1 = 1";
// build dictionary of parameters and skunumbers
var dicSkuNumberByParameterString = new Dictionary<string, string>();
int count = 0;
foreach (string item in skuNumberList)
{
if (!string.IsNullOrWhiteSpace(item))
{
count = count + 1;
string parameterString = "@skuNumber" + count;
dicSkuNumberByParameterString.Add(parameterString, item);
}
}
if (dicSkuNumberByParameterString.Any())
{
count = 0;
foreach (var item in dicSkuNumberByParameterString)
{
count = count + 1;
if (count == 1)
{
sqlString = sqlString + @"
AND ( skuSkuNumber = " + item.Key;
}
else
{
sqlString = sqlString + @"
OR skuSkuNumber = " + item.Key;
}
}
sqlString = sqlString + " )";
}
else
{
return;
}
sqlString = sqlString + @"
ORDER BY skuSkuNumber";
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
if (dicSkuNumberByParameterString.Any())
{
foreach (var item in dicSkuNumberByParameterString)
{
cmd.Parameters.AddWithValue(item.Key, item.Value);
}
}
using (var reader = cmd.ExecuteReader())
{
if (!reader.HasRows)
{
return;
}
while (reader.Read())
{
var sku = new Model.Sku.Sku();
int tablePk = reader.GetInt32(0);
sku.SkuNumber = reader.GetString(1);
if (!reader.IsDBNull(2)) { sku.AmazonFNSKU = reader.GetString(2); }
sku.IsActive = reader.GetBoolean(3);
// update cache
if (cache.ContainsKey(sku.SkuNumber))
{
cache.Remove(sku.SkuNumber);
}
cache.Add(sku.SkuNumber, sku);
}
}
}
}
}
protected void Default()
{
cache = new Dictionary<string, Model.Sku.Sku>();
}
}
}