Feature: stock replenishment

This commit is contained in:
Bobbie Hodgetts
2024-05-09 13:23:33 +01:00
committed by GitHub
parent 91ef9acc78
commit 270eebca9a
30 changed files with 721 additions and 249 deletions

View File

@@ -7,44 +7,71 @@ using System.Threading.Tasks;
namespace bnhtrade.Core.Data.Database
{
/// <summary>
/// Step 1: Call the methods for each where clause you want to create. This can be done multiple times to create an sql where string. Pay attention
/// to the prefixes that you'll require between each where clause, as each time a method is called the sql statement will be appended to the previous sql
/// string.
/// Step 2: Appened the created sql string to your sql statement, NB the WHERE statemet is not included by default.
/// Step 3: Once you've created your sql command object, add the parameters to it using the method contained within this class.
/// STep 4: exceute your sql commend.
/// </summary>
public class SqlWhereBuilder
{
private int parameterCount;
private int parameterCount = 0;
public SqlWhereBuilder()
{
Innit();
Init();
}
public string SqlWhereString { get; private set; }
public bool IsSetSqlWhereString
{
get
{
if (SqlWhereString == null || string.IsNullOrEmpty(SqlWhereString))
{
return false;
}
else
{
return true;
}
}
}
public Dictionary<string, object> ParameterList { get; private set; }
public void Innit()
/// <summary>
/// Initialises the class
/// </summary>
public void Init()
{
SqlWhereString = null;
ParameterList = new Dictionary<string, object>();
parameterCount = 0;
SqlWhereString = "";
ParameterList = new Dictionary<string, object>();
}
public void AddParametersToSqlCommand(SqlCommand cmd)
{
foreach (var item in ParameterList)
if (ParameterList != null)
{
cmd.Parameters.AddWithValue(item.Key, item.Value);
foreach (var item in ParameterList)
{
cmd.Parameters.AddWithValue(item.Key, item.Value);
}
}
}
/// <summary>
/// Used to create a string for an SQL where condition 'In' statement
/// Append an 'In' statement and parameter list to the class properties
/// </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>
/// <param name="wherePrefix">Optional prefix that gets added to the sql string result</param>
public void In(string columnReference, List<string> orValueList, string wherePrefix = null)
{
Innit();
if (orValueList == null || !orValueList.Any())
{
return;
@@ -62,7 +89,6 @@ namespace bnhtrade.Core.Data.Database
sqlWhere += " " + columnReference + " IN ( ";
var paramters = new Dictionary<string, object>();
int listCount = distinctList.Count();
for (int i = 0; i < listCount; i++, parameterCount++)
{
@@ -73,20 +99,19 @@ namespace bnhtrade.Core.Data.Database
string param = "@parameter" + parameterCount;
sqlWhere += param;
paramters.Add(param, distinctList[i]);
ParameterList.Add(param, distinctList[i]);
}
sqlWhere += " )";
sqlWhere += " ) ";
SqlWhereString = sqlWhere;
ParameterList = paramters;
SqlWhereString = SqlWhereString + sqlWhere;
}
/// <summary>
/// Used to create a string for an SQL where condition 'In' statement
/// Append an 'In' statement and parameter list to the class properties
/// </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>
/// <param name="wherePrefix">Optional prefix that gets added to the sql string result</param>
public void In(string columnReference, List<int> orValueList, string wherePrefix = null)
{
var stringList = new List<string>();