/// <summary> /// Gets rows from the datasource based on the PK_EmailMessageDetail index. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="id"></param> /// <param name="start">Row number at which to start reading.</param> /// <param name="pageLength">Number of rows to return.</param> /// <param name="count">out parameter to get total records for query</param> /// <returns>Returns an instance of the <see cref="SmartMassEmail.Entities.EmailMessageDetail"/> class.</returns> /// <remarks></remarks> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override SmartMassEmail.Entities.EmailMessageDetail GetByID(TransactionManager transactionManager, System.Guid id, int start, int pageLength, out int count) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.EmailMessageDetail_GetByID", _useStoredProcedure); database.AddInParameter(commandWrapper, "@ID", DbType.Guid, id); IDataReader reader = null; SmartMassEmail.Entities.TList<EmailMessageDetail> tmp = new SmartMassEmail.Entities.TList<EmailMessageDetail>(); try { if (transactionManager != null) { reader = Utility.ExecuteReader(transactionManager, commandWrapper); } else { reader = Utility.ExecuteReader(database, commandWrapper); } //Create collection and fill Fill(reader, tmp, start, pageLength); count = -1; if(reader.NextResult()) { if(reader.Read()) { count = reader.GetInt32(0); } } } finally { if (reader != null) reader.Close(); } if (tmp.Count == 1) { return tmp[0]; } else if (tmp.Count == 0) { return null; } else { throw new DataException("Cannot find the unique instance of the class."); } //return rows; }
/// <summary> /// Gets rows from the datasource based on the FK_EmailMessageDetail_EmailMessage key. /// FK_EmailMessageDetail_EmailMessage Description: /// </summary> /// <param name="start">Row number at which to start reading.</param> /// <param name="pageLength">Number of rows to return.</param> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="emailMessageID"></param> /// <param name="count">out parameter to get total records for query</param> /// <remarks></remarks> /// <returns>Returns a typed collection of SmartMassEmail.Entities.EmailMessageDetail objects.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override SmartMassEmail.Entities.TList<EmailMessageDetail> GetByEmailMessageID(TransactionManager transactionManager, System.Guid emailMessageID, int start, int pageLength, out int count) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.EmailMessageDetail_GetByEmailMessageID", _useStoredProcedure); database.AddInParameter(commandWrapper, "@EmailMessageID", DbType.Guid, emailMessageID); IDataReader reader = null; SmartMassEmail.Entities.TList<EmailMessageDetail> rows = new SmartMassEmail.Entities.TList<EmailMessageDetail>(); try { if (transactionManager != null) { reader = Utility.ExecuteReader(transactionManager, commandWrapper); } else { reader = Utility.ExecuteReader(database, commandWrapper); } //Create Collection Fill(reader, rows, start, pageLength); count = -1; if(reader.NextResult()) { if(reader.Read()) { count = reader.GetInt32(0); } } } finally { if (reader != null) reader.Close(); } return rows; }
}//end getall #endregion #region Paged Recordset /// <summary> /// Gets a page of rows from the DataSource. /// </summary> /// <param name="start">Row number at which to start reading.</param> /// <param name="pageLength">Number of rows to return.</param> /// <param name="count">Number of rows in the DataSource.</param> /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param> /// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <remarks></remarks> /// <returns>Returns a typed collection of SmartMassEmail.Entities.EmailMessageDetail objects.</returns> public override SmartMassEmail.Entities.TList<EmailMessageDetail> GetPaged(TransactionManager transactionManager, string whereClause, string orderBy, int start, int pageLength, out int count) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.EmailMessageDetail_GetPaged", _useStoredProcedure); database.AddInParameter(commandWrapper, "@WhereClause", DbType.String, whereClause); database.AddInParameter(commandWrapper, "@OrderBy", DbType.String, orderBy); database.AddInParameter(commandWrapper, "@PageIndex", DbType.Int32, start); database.AddInParameter(commandWrapper, "@PageSize", DbType.Int32, pageLength); IDataReader reader = null; //Create Collection SmartMassEmail.Entities.TList<EmailMessageDetail> rows = new SmartMassEmail.Entities.TList<EmailMessageDetail>(); try { if (transactionManager != null) { reader = Utility.ExecuteReader(transactionManager, commandWrapper); } else { reader = Utility.ExecuteReader(database, commandWrapper); } Fill(reader, rows, 0, int.MaxValue); count = rows.Count; if(reader.NextResult()) { if(reader.Read()) { count = reader.GetInt32(0); } } } catch(Exception) { throw; } finally { if (reader != null) reader.Close(); } return rows; }
}//end Delete #endregion #region Find Functions /// <summary> /// Returns rows meeting the whereclause condition from the DataSource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param> /// <param name="start">Row number at which to start reading.</param> /// <param name="pageLength">Number of rows to return.</param> /// <param name="count">out. The number of rows that match this query.</param> /// <remarks>Operators must be capitalized (OR, AND)</remarks> /// <returns>Returns a typed collection of SmartMassEmail.Entities.EmailMessageDetail objects.</returns> public override SmartMassEmail.Entities.TList<EmailMessageDetail> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count) { count = -1; if (whereClause.IndexOf(";") > -1) return new SmartMassEmail.Entities.TList<EmailMessageDetail>(); SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.EmailMessageDetail_Find", _useStoredProcedure); bool searchUsingOR = false; if (whereClause.IndexOf("OR") > 0) // did they want to do "a=b OR c=d OR..."? searchUsingOR = true; database.AddInParameter(commandWrapper, "@SearchUsingOR", DbType.Boolean, searchUsingOR); database.AddInParameter(commandWrapper, "@ID", DbType.Guid, DBNull.Value); database.AddInParameter(commandWrapper, "@ChangeStamp", DbType.DateTime, DBNull.Value); database.AddInParameter(commandWrapper, "@IsBinary", DbType.Int32, DBNull.Value); database.AddInParameter(commandWrapper, "@Name", DbType.AnsiString, DBNull.Value); database.AddInParameter(commandWrapper, "@BinaryData", DbType.Binary, DBNull.Value); database.AddInParameter(commandWrapper, "@StringData", DbType.AnsiString, DBNull.Value); database.AddInParameter(commandWrapper, "@EmailMessageID", DbType.Guid, DBNull.Value); // replace all instances of 'AND' and 'OR' because we already set searchUsingOR whereClause = whereClause.Replace("AND", "|").Replace("OR", "|") ; string[] clauses = whereClause.ToLower().Split('|'); // Here's what's going on below: Find a field, then to get the value we // drop the field name from the front, trim spaces, drop the '=' sign, // trim more spaces, and drop any outer single quotes. // Now handles the case when two fields start off the same way - like "Friendly='Yes' AND Friend='john'" char[] equalSign = {'='}; char[] singleQuote = {'\''}; foreach (string clause in clauses) { if (clause.Trim().StartsWith("id ") || clause.Trim().StartsWith("id=")) { database.SetParameterValue(commandWrapper, "@ID", new Guid( clause.Replace("id","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote))); continue; } if (clause.Trim().StartsWith("changestamp ") || clause.Trim().StartsWith("changestamp=")) { database.SetParameterValue(commandWrapper, "@ChangeStamp", clause.Replace("changestamp","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote)); continue; } if (clause.Trim().StartsWith("isbinary ") || clause.Trim().StartsWith("isbinary=")) { database.SetParameterValue(commandWrapper, "@IsBinary", clause.Replace("isbinary","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote)); continue; } if (clause.Trim().StartsWith("name ") || clause.Trim().StartsWith("name=")) { database.SetParameterValue(commandWrapper, "@Name", clause.Replace("name","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote)); continue; } if (clause.Trim().StartsWith("binarydata ") || clause.Trim().StartsWith("binarydata=")) { database.SetParameterValue(commandWrapper, "@BinaryData", clause.Replace("binarydata","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote)); continue; } if (clause.Trim().StartsWith("stringdata ") || clause.Trim().StartsWith("stringdata=")) { database.SetParameterValue(commandWrapper, "@StringData", clause.Replace("stringdata","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote)); continue; } if (clause.Trim().StartsWith("emailmessageid ") || clause.Trim().StartsWith("emailmessageid=")) { database.SetParameterValue(commandWrapper, "@EmailMessageID", new Guid( clause.Replace("emailmessageid","").Trim().TrimStart(equalSign).Trim().Trim(singleQuote))); continue; } throw new ArgumentException("Unable to use this part of the where clause in this version of Find: " + clause); } IDataReader reader = null; //Create Collection SmartMassEmail.Entities.TList<EmailMessageDetail> rows = new SmartMassEmail.Entities.TList<EmailMessageDetail>(); try { if (transactionManager != null) { reader = Utility.ExecuteReader(transactionManager, commandWrapper); } else { reader = Utility.ExecuteReader(database, commandWrapper); } Fill(reader, rows, start, pageLength); if(reader.NextResult()) { if(reader.Read()) { count = reader.GetInt32(0); } } } finally { if (reader != null) reader.Close(); } return rows; }
/// <summary> /// This method wrap the '_EmailMessage_GetPendingEmailMessage' stored procedure. /// </summary> /// <param name="start">Row number at which to start reading.</param> /// <param name="pageLength">Number of rows to return.</param> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <remark>This method is generate from a stored procedure.</remark> /// <returns>A <see cref="SmartMassEmail.Entities.TList<EmailMessage>"/> instance.</returns> public override SmartMassEmail.Entities.TList<EmailMessage> GetPendingEmailMessage(TransactionManager transactionManager, int start, int pageLength ) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = database.GetStoredProcCommand("_EmailMessage_GetPendingEmailMessage"); IDataReader reader = null; if (transactionManager != null) { reader = Utility.ExecuteReader(transactionManager, commandWrapper); } else { reader = Utility.ExecuteReader(database, commandWrapper); } //Create Collection SmartMassEmail.Entities.TList<EmailMessage> rows = new SmartMassEmail.Entities.TList<EmailMessage>(); try { Fill(reader, rows, start, pageLength); } finally { if (reader != null) reader.Close(); } return rows; }
/// <summary> /// Gets All rows from the DataSource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="start">Row number at which to start reading.</param> /// <param name="pageLength">Number of rows to return.</param> /// <param name="count">out. The number of rows that match this query.</param> /// <remarks></remarks> /// <returns>Returns a typed collection of SmartMassEmail.Entities.EmailMessage objects.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override SmartMassEmail.Entities.TList<EmailMessage> GetAll(TransactionManager transactionManager, int start, int pageLength, out int count) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.EmailMessage_Get_List", _useStoredProcedure); IDataReader reader = null; //Create Collection SmartMassEmail.Entities.TList<EmailMessage> rows = new SmartMassEmail.Entities.TList<EmailMessage>(); try { if (transactionManager != null) { reader = Utility.ExecuteReader(transactionManager, commandWrapper); } else { reader = Utility.ExecuteReader(database, commandWrapper); } Fill(reader, rows, start, pageLength); count = -1; if(reader.NextResult()) { if(reader.Read()) { count = reader.GetInt32(0); } } } finally { if (reader != null) reader.Close(); } return rows; }//end getall