mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-25 09:07:15 +00:00
116 lines
4.0 KiB
C#
116 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static bnhtrade.Core.Data.Database.Constants;
|
|
|
|
namespace bnhtrade.Core.Data.Database.Stock
|
|
{
|
|
internal class Status : Connection
|
|
{
|
|
private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder;
|
|
|
|
public List<int> StatusIds { get; set; }
|
|
|
|
public List<int> StatusTypeIds { get; set; }
|
|
|
|
public Status ()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
sqlBuilder = new SqlWhereBuilder();
|
|
StatusIds = new List<int>();
|
|
StatusTypeIds = new List<int>();
|
|
}
|
|
|
|
public List<Model.Stock.Status> Read()
|
|
{
|
|
var returnList = new List<Model.Stock.Status>();
|
|
sqlBuilder.Init();
|
|
|
|
//build sql query
|
|
string sql = @"
|
|
SELECT [StockStatusID]
|
|
,[StatusCode]
|
|
,[StockStatus]
|
|
,[StockStatusTypeID]
|
|
,[Reference]
|
|
,[ForeignKeyID]
|
|
,[IsCreditOnly]
|
|
,[IsClosed]
|
|
,[RecordCreated]
|
|
FROM [e2A].[dbo].[tblStockStatus]
|
|
WHERE 1=1 ";
|
|
|
|
// build the where statments
|
|
if (StatusIds.Any())
|
|
{
|
|
sqlBuilder.In("StockStatusID", StatusIds, "AND");
|
|
}
|
|
if (StatusTypeIds.Any())
|
|
{
|
|
sqlBuilder.In("StockStatusTypeID", StatusTypeIds, "AND");
|
|
}
|
|
|
|
// append where string to the sql
|
|
if (sqlBuilder.IsSetSqlWhereString)
|
|
{
|
|
sql = sql + sqlBuilder.SqlWhereString;
|
|
}
|
|
|
|
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
|
{
|
|
sqlBuilder.AddParametersToSqlCommand(cmd);
|
|
|
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
if (reader.HasRows)
|
|
{
|
|
var typeDict = new Data.Database.Stock.StatusType().Read();
|
|
|
|
while (reader.Read())
|
|
{
|
|
int statusId = reader.GetInt32(0);
|
|
int? statusCode = null;
|
|
if (!reader.IsDBNull(1)) { statusCode = reader.GetInt32(1); }
|
|
string stockStatus = reader.GetString(2);
|
|
int typeId = reader.GetInt32(3);
|
|
string reference = null;
|
|
if (!reader.IsDBNull(4)) { reference = reader.GetString(4); }
|
|
int? foreignKeyId = null;
|
|
if (!reader.IsDBNull(5)) { foreignKeyId = reader.GetInt32(5); }
|
|
bool isCreditOnly = reader.GetBoolean(6);
|
|
bool isClosed = reader.GetBoolean(7);
|
|
DateTime recordCreated = DateTime.SpecifyKind(reader.GetDateTime(8), DateTimeKind.Utc);
|
|
|
|
var newItem = new Model.Stock.Status(statusId
|
|
, statusCode
|
|
, stockStatus
|
|
, typeDict[typeId]
|
|
, reference
|
|
, foreignKeyId
|
|
, isCreditOnly
|
|
, isClosed
|
|
, recordCreated
|
|
);
|
|
|
|
returnList.Add(newItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return returnList;
|
|
}
|
|
}
|
|
}
|