Пример #1
0
        //Retrieving all items under a single order
        public List <ItemsDO> ItemsByOrderID(int orderID)
        {
            List <ItemsDO> items = new List <ItemsDO>();

            try
            {
                //Defining some commands again
                using (SqlConnection sqlConnection = new SqlConnection(_ConnectionString))
                    using (SqlCommand viewByOrder = new SqlCommand("ITEMS_SELECT_BY_ORDER_ID", sqlConnection))
                    {
                        //after 60 seconds, it stops trying to complete
                        viewByOrder.CommandType    = CommandType.StoredProcedure;
                        viewByOrder.CommandTimeout = 60;

                        //Sorting the table by OrderID, so only items in an order are returned
                        viewByOrder.Parameters.AddWithValue("OrderID", orderID);

                        sqlConnection.Open();

                        //gathering and storing data
                        using (SqlDataReader reader = viewByOrder.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                //creating a new item object for each entry and adding them all to a list
                                ItemsDO item = MapperDAL.ReaderToItem(reader);
                                items.Add(item);
                            }
                        }
                    }
            }
            //keeping a log of any errors
            catch (SqlException sqlEx)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.SqlErrorLog(sqlEx);
                throw sqlEx;
            }
            catch (Exception ex)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.ErrorLog(ex);
                throw ex;
            }
            //returning list of items under that order
            return(items);
        }
Пример #2
0
        //Viewing a single item entry
        public ItemsDO ViewItemByID(int ItemID)
        {
            ItemsDO singleItem = new ItemsDO();

            try
            {
                //defining commands to access the database
                using (SqlConnection sqlConnection = new SqlConnection(_ConnectionString))
                    using (SqlCommand viewItemByID = new SqlCommand("ITEMS_SELECT_BY_ID", sqlConnection))
                    {
                        //telling it to time out after 60 seconds
                        viewItemByID.CommandType    = CommandType.StoredProcedure;
                        viewItemByID.CommandTimeout = 60;

                        //using the ItemID to return only that item
                        viewItemByID.Parameters.AddWithValue("ItemID", ItemID);

                        sqlConnection.Open();

                        //collecting and storing the data
                        using (SqlDataReader reader = viewItemByID.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                singleItem = MapperDAL.ReaderToItem(reader);
                            }
                        }
                    }
            }
            //Logging any errors
            catch (SqlException sqlEx)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.SqlErrorLog(sqlEx);
                throw sqlEx;
            }
            catch (Exception ex)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.ErrorLog(ex);
                throw ex;
            }

            //returning data
            return(singleItem);
        }