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 resultList; public ReadAccountCode() { } public List All() { Innit(); return Execute(null, null); } public List ByAccountCode(List accountCodeList) { Innit(); if (accountCodeList == null || !accountCodeList.Any()) { return resultList; } sqlWhere.In("tblAccountChartOf.AccountCode", accountCodeList, " WHERE "); return Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList); } private List Execute(string sqlWhere, Dictionary 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(); } } }