/// <summary>
        ///     Gets rows from the datasource based on the PK_tblModePayment index.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="_pmtMode"></param>
        /// <param name="_forex"></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="LibraryManagement.Domain.ModePayment"/> 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 LibraryManagement.Domain.ModePayment GetByPmtModeForex(TransactionManager transactionManager, System.String _pmtMode, System.String _forex, int start, int pageLength, out int count)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.tblModePayment_GetByPmtModeForex", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@PmtMode", DbType.StringFixedLength, _pmtMode);
            database.AddInParameter(commandWrapper, "@Forex", DbType.StringFixedLength, _forex);

            IDataReader         reader = null;
            TList <ModePayment> tmp    = new TList <ModePayment>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetByPmtModeForex", tmp));

                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);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetByPmtModeForex", tmp));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }

            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;
        }
        }        //end getall

        #endregion

        #region GetPaged Methods

        /// <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 LibraryManagement.Domain.ModePayment objects.</returns>
        public override TList <ModePayment> 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.tblModePayment_GetPaged", _useStoredProcedure);


            if (commandWrapper.CommandType == CommandType.Text &&
                commandWrapper.CommandText != null)
            {
                commandWrapper.CommandText = commandWrapper.CommandText.Replace(SqlUtil.PAGE_INDEX, string.Concat(SqlUtil.PAGE_INDEX, Guid.NewGuid().ToString("N").Substring(0, 8)));
            }

            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
            TList <ModePayment> rows = new TList <ModePayment>();

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "GetPaged", rows));

                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);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "GetPaged", rows));
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }

            return(rows);
        }
        /// <summary>
        ///     Returns rows from the DataSource that meet the parameter conditions.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="parameters">A collection of <see cref="SqlFilterParameter"/> objects.</param>
        /// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</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>
        /// <returns>Returns a typed collection of LibraryManagement.Domain.ModePayment objects.</returns>
        public override TList <ModePayment> Find(TransactionManager transactionManager, IFilterParameterCollection parameters, string orderBy, int start, int pageLength, out int count)
        {
            SqlFilterParameterCollection filter = null;

            if (parameters == null)
            {
                filter = new SqlFilterParameterCollection();
            }
            else
            {
                filter = parameters.GetParameters();
            }

            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.tblModePayment_Find_Dynamic", typeof(ModePaymentColumn), filter, orderBy, start, pageLength);

            SqlFilterParameter param;

            for (int i = 0; i < filter.Count; i++)
            {
                param = filter[i];
                database.AddInParameter(commandWrapper, param.Name, param.DbType, param.GetValue());
            }

            TList <ModePayment> rows   = new TList <ModePayment>();
            IDataReader         reader = null;

            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                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);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }

            return(rows);
        }
        }        //end Delete

        #endregion

        #region Find Functions

        #region Parsed Find Methods
        /// <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 LibraryManagement.Domain.ModePayment objects.</returns>
        public override TList <ModePayment> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
        {
            count = -1;
            if (whereClause.IndexOf(";") > -1)
            {
                return(new TList <ModePayment>());
            }

            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.tblModePayment_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, "@PmtMode", DbType.StringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Description", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Forex", DbType.StringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@ForexRate", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Iscard", DbType.StringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Status", DbType.Boolean, 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("pmt_mode ") || clause.Trim().StartsWith("pmt_mode="))
                {
                    database.SetParameterValue(commandWrapper, "@PmtMode",
                                               clause.Trim().Remove(0, 8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("description ") || clause.Trim().StartsWith("description="))
                {
                    database.SetParameterValue(commandWrapper, "@Description",
                                               clause.Trim().Remove(0, 11).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("forex ") || clause.Trim().StartsWith("forex="))
                {
                    database.SetParameterValue(commandWrapper, "@Forex",
                                               clause.Trim().Remove(0, 5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("forex_rate ") || clause.Trim().StartsWith("forex_rate="))
                {
                    database.SetParameterValue(commandWrapper, "@ForexRate",
                                               clause.Trim().Remove(0, 10).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("iscard ") || clause.Trim().StartsWith("iscard="))
                {
                    database.SetParameterValue(commandWrapper, "@Iscard",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("status ") || clause.Trim().StartsWith("status="))
                {
                    database.SetParameterValue(commandWrapper, "@Status",
                                               clause.Trim().Remove(0, 6).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
            TList <ModePayment> rows = new TList <ModePayment>();


            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                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);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }
            return(rows);
        }
Example #5
0
        }        //end Delete

        #endregion

        #region Find Functions

        #region Parsed Find Methods
        /// <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 LibraryManagement.Domain.OnOrder objects.</returns>
        public override TList <OnOrder> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
        {
            count = -1;
            if (whereClause.IndexOf(";") > -1)
            {
                return(new TList <OnOrder>());
            }

            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.tblOn_order_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, "@TranDate", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@TranTime", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@DeliverDt", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@TransNum", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@TransCode", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@ExpId", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@GoodsId", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Qty", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@UnitSymb", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Price", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@MercType", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@UserId", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Remark", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Recnum", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Status", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@EndQty", DbType.Decimal, 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("tran_date ") || clause.Trim().StartsWith("tran_date="))
                {
                    database.SetParameterValue(commandWrapper, "@TranDate",
                                               clause.Trim().Remove(0, 9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("tran_time ") || clause.Trim().StartsWith("tran_time="))
                {
                    database.SetParameterValue(commandWrapper, "@TranTime",
                                               clause.Trim().Remove(0, 9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("deliver_dt ") || clause.Trim().StartsWith("deliver_dt="))
                {
                    database.SetParameterValue(commandWrapper, "@DeliverDt",
                                               clause.Trim().Remove(0, 10).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("trans_num ") || clause.Trim().StartsWith("trans_num="))
                {
                    database.SetParameterValue(commandWrapper, "@TransNum",
                                               clause.Trim().Remove(0, 9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("trans_code ") || clause.Trim().StartsWith("trans_code="))
                {
                    database.SetParameterValue(commandWrapper, "@TransCode",
                                               clause.Trim().Remove(0, 10).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("exp_id ") || clause.Trim().StartsWith("exp_id="))
                {
                    database.SetParameterValue(commandWrapper, "@ExpId",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("goods_id ") || clause.Trim().StartsWith("goods_id="))
                {
                    database.SetParameterValue(commandWrapper, "@GoodsId",
                                               clause.Trim().Remove(0, 8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("qty ") || clause.Trim().StartsWith("qty="))
                {
                    database.SetParameterValue(commandWrapper, "@Qty",
                                               clause.Trim().Remove(0, 3).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("unit_symb ") || clause.Trim().StartsWith("unit_symb="))
                {
                    database.SetParameterValue(commandWrapper, "@UnitSymb",
                                               clause.Trim().Remove(0, 9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("price ") || clause.Trim().StartsWith("price="))
                {
                    database.SetParameterValue(commandWrapper, "@Price",
                                               clause.Trim().Remove(0, 5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("merc_type ") || clause.Trim().StartsWith("merc_type="))
                {
                    database.SetParameterValue(commandWrapper, "@MercType",
                                               clause.Trim().Remove(0, 9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("user_id ") || clause.Trim().StartsWith("user_id="))
                {
                    database.SetParameterValue(commandWrapper, "@UserId",
                                               clause.Trim().Remove(0, 7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("remark ") || clause.Trim().StartsWith("remark="))
                {
                    database.SetParameterValue(commandWrapper, "@Remark",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("recnum ") || clause.Trim().StartsWith("recnum="))
                {
                    database.SetParameterValue(commandWrapper, "@Recnum",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("status ") || clause.Trim().StartsWith("status="))
                {
                    database.SetParameterValue(commandWrapper, "@Status",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("end_qty ") || clause.Trim().StartsWith("end_qty="))
                {
                    database.SetParameterValue(commandWrapper, "@EndQty",
                                               clause.Trim().Remove(0, 7).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
            TList <OnOrder> rows = new TList <OnOrder>();


            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                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);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }
            return(rows);
        }
        }        //end Delete

        #endregion

        #region Find Functions

        #region Parsed Find Methods
        /// <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 LibraryManagement.Domain.CsCard objects.</returns>
        public override TList <CsCard> Find(TransactionManager transactionManager, string whereClause, int start, int pageLength, out int count)
        {
            count = -1;
            if (whereClause.IndexOf(";") > -1)
            {
                return(new TList <CsCard>());
            }

            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.tblCsCard_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, "@CardId", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@IsVip", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@CsSex", DbType.Boolean, DBNull.Value);
            database.AddInParameter(commandWrapper, "@PersonId", DbType.AnsiStringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Birthday", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@PsIssuedate", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@PsPlaceissuse", DbType.StringFixedLength, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Fullname", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Address", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Phone", DbType.AnsiString, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Email", DbType.AnsiString, DBNull.Value);
            database.AddInParameter(commandWrapper, "@DiscPc", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@IssDate", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@DueDate", DbType.DateTime, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Image", DbType.Binary, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Remark", DbType.String, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Begmark", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Endmark", DbType.Decimal, DBNull.Value);
            database.AddInParameter(commandWrapper, "@Status", DbType.Boolean, 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("card_id ") || clause.Trim().StartsWith("card_id="))
                {
                    database.SetParameterValue(commandWrapper, "@CardId",
                                               clause.Trim().Remove(0, 7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("is_vip ") || clause.Trim().StartsWith("is_vip="))
                {
                    database.SetParameterValue(commandWrapper, "@IsVip",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("cs_sex ") || clause.Trim().StartsWith("cs_sex="))
                {
                    database.SetParameterValue(commandWrapper, "@CsSex",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("person_id ") || clause.Trim().StartsWith("person_id="))
                {
                    database.SetParameterValue(commandWrapper, "@PersonId",
                                               clause.Trim().Remove(0, 9).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("birthday ") || clause.Trim().StartsWith("birthday="))
                {
                    database.SetParameterValue(commandWrapper, "@Birthday",
                                               clause.Trim().Remove(0, 8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("ps_issuedate ") || clause.Trim().StartsWith("ps_issuedate="))
                {
                    database.SetParameterValue(commandWrapper, "@PsIssuedate",
                                               clause.Trim().Remove(0, 12).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("ps_placeissuse ") || clause.Trim().StartsWith("ps_placeissuse="))
                {
                    database.SetParameterValue(commandWrapper, "@PsPlaceissuse",
                                               clause.Trim().Remove(0, 14).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("fullname ") || clause.Trim().StartsWith("fullname="))
                {
                    database.SetParameterValue(commandWrapper, "@Fullname",
                                               clause.Trim().Remove(0, 8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("address ") || clause.Trim().StartsWith("address="))
                {
                    database.SetParameterValue(commandWrapper, "@Address",
                                               clause.Trim().Remove(0, 7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("phone ") || clause.Trim().StartsWith("phone="))
                {
                    database.SetParameterValue(commandWrapper, "@Phone",
                                               clause.Trim().Remove(0, 5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("email ") || clause.Trim().StartsWith("email="))
                {
                    database.SetParameterValue(commandWrapper, "@Email",
                                               clause.Trim().Remove(0, 5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("disc_pc ") || clause.Trim().StartsWith("disc_pc="))
                {
                    database.SetParameterValue(commandWrapper, "@DiscPc",
                                               clause.Trim().Remove(0, 7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("iss_date ") || clause.Trim().StartsWith("iss_date="))
                {
                    database.SetParameterValue(commandWrapper, "@IssDate",
                                               clause.Trim().Remove(0, 8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("due_date ") || clause.Trim().StartsWith("due_date="))
                {
                    database.SetParameterValue(commandWrapper, "@DueDate",
                                               clause.Trim().Remove(0, 8).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("image ") || clause.Trim().StartsWith("image="))
                {
                    database.SetParameterValue(commandWrapper, "@Image",
                                               clause.Trim().Remove(0, 5).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("remark ") || clause.Trim().StartsWith("remark="))
                {
                    database.SetParameterValue(commandWrapper, "@Remark",
                                               clause.Trim().Remove(0, 6).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("begmark ") || clause.Trim().StartsWith("begmark="))
                {
                    database.SetParameterValue(commandWrapper, "@Begmark",
                                               clause.Trim().Remove(0, 7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("endmark ") || clause.Trim().StartsWith("endmark="))
                {
                    database.SetParameterValue(commandWrapper, "@Endmark",
                                               clause.Trim().Remove(0, 7).Trim().TrimStart(equalSign).Trim().Trim(singleQuote));
                    continue;
                }
                if (clause.Trim().StartsWith("status ") || clause.Trim().StartsWith("status="))
                {
                    database.SetParameterValue(commandWrapper, "@Status",
                                               clause.Trim().Remove(0, 6).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
            TList <CsCard> rows = new TList <CsCard>();


            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));

                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);
                    }
                }

                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                commandWrapper = null;
            }
            return(rows);
        }