예제 #1
0
        /// <summary>
        /// Lấy danh sách BookCategory từ thư mục Data
        /// </summary>
        /// <returns></returns>
        public static ObservableCollection <BookCategory> BookCategories()
        {
            string path = GetDataPath() + "BookCategoryData.xml";
            ObservableCollection <BookCategory> bookCategories = new ObservableCollection <BookCategory>();

            try
            {
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(path);
                DataTable dt = new DataTable();
                dt = dataSet.Tables["BookCategory"];

                foreach (DataRow dr in dt.Rows)
                {
                    BookCategory bookCategory = new BookCategory(dr);
                    bookCategories.Add(bookCategory);
                }
            }
            catch (Exception) { }

            return(bookCategories);
        }
예제 #2
0
        /// <summary>
        /// Lấy danh sách BookItem từ thư mục Data theo chuyên mục sách
        /// </summary>
        /// <param name="bookCategoryFilter"></param>
        /// <returns></returns>
        public static ObservableCollection <BookItem> BookItems(BookCategory bookCategoryFilter)
        {
            string path = GetDataPath() + "BookItemData.xml";
            ObservableCollection <BookItem> bookItems = new ObservableCollection <BookItem>();

            try
            {
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(path);
                DataTable dt = new DataTable();
                dt = dataSet.Tables["BookItem"];

                if (bookCategoryFilter.Id == "0" || bookCategoryFilter == null)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        BookItem bookItem = new BookItem(dr);
                        bookItems.Add(bookItem);
                    }
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        BookItem bookItem = new BookItem(dr);
                        if (bookItem.Book.BookCategory == bookCategoryFilter.Name)
                        {
                            bookItems.Add(bookItem);
                        }
                    }
                }
            }
            catch (Exception) { }

            return(bookItems);
        }