mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 22:47:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user