コード例 #1
0
        public static async Task <List <OrderItem> > RetrieveItemsByOrderId(string orderId)
        {
            List <OrderItem> orderItemsList = new List <OrderItem>();
            string           sqlCmdString   = "Select * From dbo.order_items Where order_id = @order_id";
            Database         myDb           = new Database();
            SqlCommand       sqlCmd         = new SqlCommand(sqlCmdString, myDb.Connection);
            //SqlDataReader reader = null;
            SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlCmd);
            DataTable      table    = new DataTable();
            OrderItem      orderItem;

            await Task.Run(async() =>
            {
                try
                {
                    myDb.OpenConnection();
                    sqlCmd.Parameters.Add(new SqlParameter("@order_id", orderId));
                    sqlAdapt.Fill(table);

                    foreach (DataRow row in table.Rows)
                    {
                        orderItem = new OrderItem()
                        {
                            Qty            = Convert.ToInt16(row["item_qty"]),
                            RateAdjustment = Convert.ToInt32(row["rate_adjustment"]),
                            IsPersist      = true
                        };
                        orderItem.Item = await StockItem.RetrieveBySkuCode((string)row["item_sku_code"]);
                        orderItemsList.Add(orderItem);
                    }
                }
                finally
                {
                    sqlAdapt.Dispose();
                    table.Dispose();
                    myDb.CloseConnection();
                }
            });

            return(orderItemsList);
        }