Пример #1
0
        ///<Summary>
        ///Select all rows by filter criteria
        ///This method returns all data rows in the table using criteriaquery api Categories
        ///</Summary>
        ///<returns>
        ///IList-IDAOCategories.
        ///</returns>
        ///<parameters>
        ///IList<IDataCriterion> listCriterion, IList<IDataOrderBy> listOrder, IDataSkip dataSkip, IDataTake dataTake
        ///</parameters>
        public static IList <IDAOCategories> SelectAllByCriteria(IList <IDataCriterion> listCriterion, IList <IDataOrderBy> listOrder, IDataSkip dataSkip, IDataTake dataTake)
        {
            Doing(null);
            SqlCommand command = new SqlCommand();

            command.CommandText = GetSelectionCriteria(InlineProcs.ctprCategories_SelectAllByCriteria, null, listCriterion, listOrder, dataSkip, dataTake);
            command.CommandType = CommandType.Text;
            SqlConnection staticConnection = StaticSqlConnection;

            command.Connection = staticConnection;

            DataTable      dt         = new DataTable("Categories");
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);

            try
            {
                staticConnection.Open();
                sqlAdapter.Fill(dt);
                Done(null);

                List <IDAOCategories> objList = new List <IDAOCategories>();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        DAOCategories retObj = new DAOCategories();
                        retObj._categoryID   = Convert.IsDBNull(row["CategoryID"]) ? (Int32?)null : (Int32?)row["CategoryID"];
                        retObj._categoryName = Convert.IsDBNull(row["CategoryName"]) ? null : (string)row["CategoryName"];
                        retObj._description  = Convert.IsDBNull(row["Description"]) ? null : (string)row["Description"];
                        retObj._picture      = Convert.IsDBNull(row["Picture"]) ? null : (byte[])row["Picture"];
                        retObj._ctrVersion   = Convert.IsDBNull(row["ctr_version"]) ? (Int32?)null : (Int32?)row["ctr_version"];
                        objList.Add(retObj);
                    }
                }
                return(objList);
            }
            catch (Exception ex)
            {
                Failed(null, ex);
                Handle(null, ex);
                return(null);
            }
            finally
            {
                staticConnection.Close();
                command.Dispose();
            }
        }
Пример #2
0
        ///<Summary>
        ///Select one row by primary key(s)
        ///This method returns one row from the table Categories based on the primary key(s)
        ///</Summary>
        ///<returns>
        ///IDAOCategories
        ///</returns>
        ///<parameters>
        ///Int32? categoryID
        ///</parameters>
        public static IDAOCategories SelectOne(Int32?categoryID)
        {
            Doing(null);
            SqlCommand command = new SqlCommand();

            command.CommandText = InlineProcs.ctprCategories_SelectOne;
            command.CommandType = CommandType.Text;
            SqlConnection staticConnection = StaticSqlConnection;

            command.Connection = staticConnection;

            DataTable      dt         = new DataTable("Categories");
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);

            try
            {
                command.Parameters.Add(CtSqlParameter.Get("@CategoryID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, (object)categoryID ?? (object)DBNull.Value));

                staticConnection.Open();
                sqlAdapter.Fill(dt);
                Done(null);

                DAOCategories retObj = null;
                if (dt.Rows.Count > 0)
                {
                    retObj               = new DAOCategories();
                    retObj._categoryID   = Convert.IsDBNull(dt.Rows[0]["CategoryID"]) ? (Int32?)null : (Int32?)dt.Rows[0]["CategoryID"];
                    retObj._categoryName = Convert.IsDBNull(dt.Rows[0]["CategoryName"]) ? null : (string)dt.Rows[0]["CategoryName"];
                    retObj._description  = Convert.IsDBNull(dt.Rows[0]["Description"]) ? null : (string)dt.Rows[0]["Description"];
                    retObj._picture      = Convert.IsDBNull(dt.Rows[0]["Picture"]) ? null : (byte[])dt.Rows[0]["Picture"];
                    retObj._ctrVersion   = Convert.IsDBNull(dt.Rows[0]["ctr_version"]) ? (Int32?)null : (Int32?)dt.Rows[0]["ctr_version"];
                }
                return(retObj);
            }
            catch (Exception ex)
            {
                Failed(null, ex);
                Handle(null, ex);
                return(null);
            }
            finally
            {
                staticConnection.Close();
                command.Dispose();
            }
        }