Пример #1
0
        ///<Summary>
        ///Select all rows by foreign key
        ///This method returns all data rows in the table Order Details based on a foreign key
        ///</Summary>
        ///<returns>
        ///IList-IDAOOrderDetails.
        ///</returns>
        ///<parameters>
        ///Int32? productID
        ///</parameters>
        public static IList <IDAOOrderDetails> SelectAllByProductID(Int32?productID)
        {
            Doing(null);
            SqlCommand command = new SqlCommand();

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

            command.Connection = staticConnection;

            DataTable      dt         = new DataTable("Order Details");
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);

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

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

                List <IDAOOrderDetails> objList = new List <IDAOOrderDetails>();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        DAOOrderDetails retObj = new DAOOrderDetails();
                        retObj._orderID    = Convert.IsDBNull(row["OrderID"]) ? (Int32?)null : (Int32?)row["OrderID"];
                        retObj._productID  = Convert.IsDBNull(row["ProductID"]) ? (Int32?)null : (Int32?)row["ProductID"];
                        retObj._unitPrice  = Convert.IsDBNull(row["UnitPrice"]) ? (decimal?)null : (decimal?)row["UnitPrice"];
                        retObj._quantity   = Convert.IsDBNull(row["Quantity"]) ? (Int16?)null : (Int16?)row["Quantity"];
                        retObj._discount   = Convert.IsDBNull(row["Discount"]) ? (float?)null : (float?)row["Discount"];
                        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 all rows by filter criteria
        ///This method returns all data rows in the table using criteriaquery api Order Details
        ///</Summary>
        ///<returns>
        ///IList-IDAOOrderDetails.
        ///</returns>
        ///<parameters>
        ///IList<IDataCriterion> listCriterion, IList<IDataOrderBy> listOrder, IDataSkip dataSkip, IDataTake dataTake
        ///</parameters>
        public static IList <IDAOOrderDetails> SelectAllByCriteria(IList <IDataCriterion> listCriterion, IList <IDataOrderBy> listOrder, IDataSkip dataSkip, IDataTake dataTake)
        {
            Doing(null);
            SqlCommand command = new SqlCommand();

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

            command.Connection = staticConnection;

            DataTable      dt         = new DataTable("Order Details");
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);

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

                List <IDAOOrderDetails> objList = new List <IDAOOrderDetails>();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        DAOOrderDetails retObj = new DAOOrderDetails();
                        retObj._orderID    = Convert.IsDBNull(row["OrderID"]) ? (Int32?)null : (Int32?)row["OrderID"];
                        retObj._productID  = Convert.IsDBNull(row["ProductID"]) ? (Int32?)null : (Int32?)row["ProductID"];
                        retObj._unitPrice  = Convert.IsDBNull(row["UnitPrice"]) ? (decimal?)null : (decimal?)row["UnitPrice"];
                        retObj._quantity   = Convert.IsDBNull(row["Quantity"]) ? (Int16?)null : (Int16?)row["Quantity"];
                        retObj._discount   = Convert.IsDBNull(row["Discount"]) ? (float?)null : (float?)row["Discount"];
                        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();
            }
        }