using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Communications; namespace Swarmops.Database { public partial class SwarmDb { #region Field reading code private const string communicationTurnaroundFieldSequence = " OrganizationId,CommunicationTypeId,CommunicationId,DateTimeOpened,DateTimeFirstResponse," + // 0-4 "PersonIdFirstResponse,DateTimeClosed,PersonIdClosed,Open,Responded " + // 5-9 "FROM CommunicationTurnarounds "; private static BasicCommunicationTurnaround ReadCommunicationTurnaroundFromDataReader (IDataRecord reader) { int organizationId = reader.GetInt32 (0); int communicationTypeId = reader.GetInt32 (1); int communicationId = reader.GetInt32 (2); DateTime dateTimeOpened = reader.GetDateTime (3); DateTime dateTimeFirstResponse = reader.GetDateTime (4); int personIdFirstResponse = reader.GetInt32 (5); DateTime dateTimeClosed = reader.GetDateTime (6); int personIdClosed = reader.GetInt32 (7); bool open = reader.GetBoolean (8); bool awaitingResponse = reader.GetBoolean (9); return new BasicCommunicationTurnaround (organizationId, communicationTypeId, communicationId, dateTimeOpened, dateTimeFirstResponse, personIdFirstResponse, dateTimeClosed, personIdClosed, open, awaitingResponse); } #endregion #region Record reading - SELECT statements public BasicCommunicationTurnaround GetCommunicationTurnaround (int organizationId, int communicationTypeId, int communicationId) { using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); DbCommand command = GetDbCommand ( "SELECT" + communicationTurnaroundFieldSequence + "WHERE OrganizationId=" + organizationId + " AND CommunicationTypeId=" + communicationTypeId + " AND CommunicationId=" + communicationId + ";", connection); using (DbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { return ReadCommunicationTurnaroundFromDataReader (reader); } throw new ArgumentException ("Unknown Communication Id: " + communicationId); } } } public BasicCommunicationTurnaround[] GetCommunicationTurnarounds (params object[] conditions) { List result = new List(); using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); DbCommand command = GetDbCommand ( "SELECT" + communicationTurnaroundFieldSequence + ConstructWhereClause ("CommunicationTurnarounds", conditions) + " ORDER BY DateTimeOpened", connection); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) {