コード例 #1
0
        public void LoadCategoryById(int categoryId)
        {
            CategoryTDG        categoryTDG  = new CategoryTDG();
            List <CategoryDto> categoryDtos = categoryTDG.FindCategoryById(categoryId).ToList();

            DataTable categoryTable = new DataTable();

            categoryTable.TableName = "Category";

            Type categoryType = typeof(CategoryDto);

            PropertyInfo[] propertyInfos = categoryType.GetProperties();
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                DataColumn dataColumn = new DataColumn();
                dataColumn.ColumnName = propertyInfo.Name;
                dataColumn.DataType   = propertyInfo.PropertyType;
                categoryTable.Columns.Add(dataColumn);
            }

            foreach (CategoryDto categoryDto in categoryDtos)
            {
                DataRow newRow = categoryTable.NewRow();

                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    newRow[propertyInfo.Name] = propertyInfo.GetValue(categoryDto);
                }

                categoryTable.Rows.Add(newRow);
            }

            Holder.AddTable(categoryTable);
        }
コード例 #2
0
        public void LoadOrderDetailById(int orderId)
        {
            OrderDetailTDG         orderDetailTDG  = new OrderDetailTDG();
            IList <OrderDetailDto> orderDetailDtos = orderDetailTDG.FindOrderDetailById(orderId).ToList();

            DataTable orderDetailTable = new DataTable();

            orderDetailTable.TableName = "OrderDetail";

            Type orderDetailType = typeof(OrderDetailDto);

            PropertyInfo[] propertyInfos = orderDetailType.GetProperties();
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                DataColumn dataColumn = new DataColumn();
                dataColumn.ColumnName = propertyInfo.Name;
                dataColumn.DataType   = propertyInfo.PropertyType;
                orderDetailTable.Columns.Add(dataColumn);
            }

            foreach (OrderDetailDto orderDetailDto in orderDetailDtos)
            {
                DataRow newRow = orderDetailTable.NewRow();

                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    newRow[propertyInfo.Name] = propertyInfo.GetValue(orderDetailDto);
                }

                orderDetailTable.Rows.Add(newRow);
            }

            Holder.AddTable(orderDetailTable);
        }
コード例 #3
0
        public void LoadProductById(int productId)
        {
            ProductTDG        productTDG  = new ProductTDG();
            List <ProductDto> productDtos = productTDG.FindProductById(productId).ToList();

            DataTable producTable = new DataTable();

            producTable.TableName = "Product";

            Type producType = typeof(ProductDto);

            PropertyInfo[] propertyInfos = producType.GetProperties();
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                DataColumn dataColumn = new DataColumn();
                dataColumn.ColumnName = propertyInfo.Name;
                dataColumn.DataType   = propertyInfo.PropertyType;
                producTable.Columns.Add(dataColumn);
            }

            foreach (ProductDto productDto in productDtos)
            {
                DataRow newRow = producTable.NewRow();

                foreach (PropertyInfo propertyInfo in propertyInfos)
                {
                    newRow[propertyInfo.Name] = propertyInfo.GetValue(productDto);
                }

                producTable.Rows.Add(newRow);
            }

            Holder.AddTable(producTable);
        }