mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
106 lines
4.0 KiB
C#
106 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bnhtrade.Core.Data.Database.Account
|
|
{
|
|
internal class ReadContact : Connection
|
|
{
|
|
private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder;
|
|
|
|
public List<int> ContactIdList { get; set; }
|
|
|
|
public ReadContact()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
sqlBuilder = new SqlWhereBuilder();
|
|
ContactIdList = new List<int>();
|
|
}
|
|
|
|
public Dictionary<int, Model.Account.Contact> Read()
|
|
{
|
|
var returnList = new Dictionary<int, Model.Account.Contact>();
|
|
sqlBuilder.Init();
|
|
|
|
//build sql query
|
|
string sql = @"
|
|
SELECT [ContactID]
|
|
,[ContactName]
|
|
,[PaypalName]
|
|
,[PaypalEmail]
|
|
,[EbayUsername]
|
|
,[EbayEmail]
|
|
,[RecordCreated]
|
|
,[RecordModified]
|
|
FROM [e2A].[dbo].[tblContact]
|
|
WHERE 1=1 ";
|
|
|
|
// build the where statments
|
|
if (ContactIdList.Any())
|
|
{
|
|
sqlBuilder.In("[ContactID]", ContactIdList, "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)
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
int contactId = reader.GetInt32(0);
|
|
string contactName = null;
|
|
if (!reader.IsDBNull(1)) { contactName = reader.GetString(1); }
|
|
string paypalName = null;
|
|
if (!reader.IsDBNull(2)) { paypalName = reader.GetString(2); }
|
|
string paypalEmail = null;
|
|
if (!reader.IsDBNull(3)) { paypalEmail = reader.GetString(3); }
|
|
string ebayUsername = null;
|
|
if (!reader.IsDBNull(4)) { ebayUsername = reader.GetString(4); }
|
|
string ebayEmail = null;
|
|
if (!reader.IsDBNull(5)) { ebayEmail = reader.GetString(5); }
|
|
DateTime recordCreated = DateTime.SpecifyKind(reader.GetDateTime(6), DateTimeKind.Utc);
|
|
DateTime? recordModified = null;
|
|
if (!reader.IsDBNull(7)) { recordModified = DateTime.SpecifyKind(reader.GetDateTime(7), DateTimeKind.Utc); }
|
|
|
|
var contact = new Model.Account.Contact();
|
|
contact.ContactId = contactId;
|
|
contact.ContantName = contactName;
|
|
contact.ContactPaypalName = paypalName;
|
|
contact.ContactPaypalEmail = paypalEmail;
|
|
contact.ContactEbayName = ebayUsername;
|
|
contact.ContactEbayEmail = ebayEmail;
|
|
contact.Created = recordCreated;
|
|
contact.Modified = recordModified;
|
|
|
|
returnList.Add(contactId, contact);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return returnList;
|
|
}
|
|
}
|
|
}
|