Files
bnhtrade/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs
2024-04-11 12:26:13 +01:00

97 lines
3.3 KiB
C#

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 ReadAccountCode : Connection
{
private Data.Database.SqlWhereBuilder sqlWhere = new SqlWhereBuilder();
private List<Model.Account.AccountCode> resultList;
public ReadAccountCode()
{
}
public List<Model.Account.AccountCode> All()
{
Innit();
return Execute(null, null);
}
public List<Model.Account.AccountCode> ByAccountCode(List<int> accountCodeList)
{
Innit();
if (accountCodeList == null || !accountCodeList.Any())
{
return resultList;
}
sqlWhere.In("tblAccountChartOf.AccountCode", accountCodeList, " WHERE ");
return Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList);
}
private List<Model.Account.AccountCode> Execute(string sqlWhere, Dictionary<string, object> parameters)
{
//build sql query
string sqlString = @"
SELECT tblAccountChartOf.AccountChartOfID
,tblAccountChartOf.AccountCode
,tblAccountChartOf.AccountName
,tblAccountChartOf.Description
,tblAccountChartOfType.AccountChartOfType
,tblAccountChartOfType.BasicType
FROM tblAccountChartOf
INNER JOIN tblAccountChartOfType ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID
" + sqlWhere;
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
if (parameters != null)
{
foreach (var parameter in parameters)
{
cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
}
}
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
var result = new Model.Account.AccountCode();
int tablePk = reader.GetInt32(0);
result.AccountCodeId = reader.GetInt32(1);
result.Title = reader.GetString(2);
if (!reader.IsDBNull(3)) { result.Description = reader.GetString(3); }
result.Type = reader.GetString(4);
result.BasicType = reader.GetString(5);
resultList.Add(result);
}
}
return resultList;
}
}
}
}
private void Innit()
{
resultList = new List<Model.Account.AccountCode>();
}
}
}