Exemplo n.º 1
0
        /// <summary>
        /// AddNewItemForm constructor.
        /// </summary>
        /// <param name="booksManager">Business logic command pattern instance</param>
        /// <param name="bookMetaDataType">The type of book meta data</param>
        public AddNewItemForm(BooksManager booksManager, Type bookMetaDataType)
        {
            this.booksManager     = booksManager;
            this.bookMetaDataType = bookMetaDataType;

            InitializeComponent();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the application settings from the Windows Registry.
        /// </summary>
        private void LoadSettings()
        {
            try
            {
                RegistryHandler.ExtractRegistrySettings(out dbFolder, out tempFolder);

                Properties.Settings.Default.DatabaseFolderPath = dbFolder;
                Properties.Settings.Default.TempFolderPath     = tempFolder;
            }

            catch (Exception ex)
            {
                RegistryHandler.DeleteRegistrySettings();
                throw new RegistryAccessException("Could not access the registry settings.", ex);
            }

            try
            {
                booksManager = BooksManager.Instance;
            }

            catch (BookEntitiesException)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// RenameItemForm constructor.
        /// </summary>
        /// <param name="booksManager">Business logic command pattern instance</param>
        /// <param name="bookMetaDataObject">The book meta data object to be renamed</param>
        public RenameItemForm(BooksManager booksManager, IBookMetaData bookMetaDataObject)
        {
            this.booksManager       = booksManager;
            this.bookMetaDataObject = bookMetaDataObject;

            InitializeComponent();
        }
Exemplo n.º 4
0
        private void BindHotBook()
        {
            BooksManager bm = new BooksManager();

            Repeater1.DataSource = bm.GetList(5, "1=1 ", " Clicks desc").Tables[0].DefaultView;
            Repeater1.DataBind();
        }
Exemplo n.º 5
0
        /// <summary>
        /// BookDetails constructor.
        /// </summary>
        /// <param name="booksManager">Business logic command pattern instance</param>
        /// <param name="booksListOperations">Object defining operations to be performed on a list of books</param>
        public BookDetails(BooksManager booksManager, BooksListOperations booksListOperations)
        {
            this.booksManager        = booksManager;
            this.booksListOperations = booksListOperations;

            InitializeComponent();
        }
Exemplo n.º 6
0
        public ActionResult AddCategory(string name)
        {
            BooksManager manager = new BooksManager(Properties.Settings.Default.ConStr);

            manager.AddCategory(name);
            return(Redirect("/books/index"));
        }
Exemplo n.º 7
0
        //临时数据代替表单提交
        private void InsertToIndex()
        {
            //创建一条临时数据
            Books book = new Books();

            book.Author             = "痞子一毛";
            book.Title              = "piziyimao";
            book.CategoryId         = 1;
            book.ContentDescription = "不是所有痞子都叫一毛不是所有痞子都叫一毛不是所有痞子都叫一毛不是所有痞子都叫一毛";
            book.PublisherId        = 1;
            book.ISBN        = "124365";
            book.WordsCount  = 1000000;
            book.UnitPrice   = 88;
            book.CategoryId  = 1;
            book.Clicks      = 10;
            book.PublishDate = DateTime.Now;
            BooksManager bm = new BooksManager();

            //IndexManager.bookIndex.Add()数据新增 索引库更新测试

            //int insertId;
            //if((insertId = bm.Add(book)) > 0) {
            //    book.Id = insertId;
            //    IndexManager.bookIndex.Add(book);
            //}

            //IndexManager.bookIndex.Mod()数据修改 索引库更新测试
            book.Id = 10001;//数据库生成主键ID
            book.ContentDescription = "侬好哇, 记住不是所有痞子都叫一毛哟";
            bm.Update(book);
            IndexManager.bookIndex.Mod(book);
        }
Exemplo n.º 8
0
        public ActionResult NewBook()
        {
            BooksManager     manager   = new BooksManager(Properties.Settings.Default.ConStr);
            NewBookViewModel viewModel = new NewBookViewModel();

            viewModel.Categories = manager.GetCategories();
            return(View(viewModel));
        }
        public void BookManager_GetOldestBook_no_books_results_null()
        {
            var bm = new BooksManager(new testRepo());

            var result = bm.GetOldestBook();

            Assert.IsNull(result);
        }
Exemplo n.º 10
0
        public void Initialize()
        {
            booksManager     = new BooksManager();
            publisherManager = new PublisherManager();
            books            = new List <IBooks>();

            bookshopAPI = new BookshopAPI(booksManager, publisherManager, books);
        }
Exemplo n.º 11
0
 private void OnRemoveBook()
 {
     if (null != this._currentBook)
     {
         BooksManager.RemoveBook(this._currentBook);
         this._currentBook = null;
         OnViewBookInfo(null);
     }
 }
Exemplo n.º 12
0
        private void OnDelBook(object sender, MouseEventArgs arg)
        {
            BooksManager.RemoveBook(this.BookItem);

            RoutedPropertyChangedEventArgs <BookItemView> args = new RoutedPropertyChangedEventArgs <BookItemView>(this, this);

            args.RoutedEvent = BookItemView.ItemRemovedEvent;

            this.RaiseEvent(args);
        }
Exemplo n.º 13
0
        /// <summary>
        /// BookSelectForm constructor.
        /// </summary>
        /// <param name="selectedItemType">The selected item string</param>
        /// <param name="booksManager">Business logic command pattern instance</param>
        /// <param name="book">The meta-data corresponding to the currently selected book</param>
        public BookSelectForm(Type selectedItemType, BooksManager booksManager, Book book)
        {
            this.selectedItemType = selectedItemType;

            this.booksManager = booksManager;
            this.book         = book;

            this.selectedItems = new List <object>();

            InitializeComponent();
        }
Exemplo n.º 14
0
        public void Initialize()
        {
            booksManager     = new BooksManager();
            publisherManager = new PublisherManager();

            BookTemp       = new List <IBooks>();
            BookList       = new List <IBooks>();
            BookListSecond = new List <IBooks>();

            bookshopAPI = new BookshopAPI(booksManager, publisherManager, BookTemp);
        }
Exemplo n.º 15
0
        public ActionResult NewCategory()
        {
            BooksManager         manager   = new BooksManager(Properties.Settings.Default.ConStr);
            NewCategoryViewModel viewModel = new NewCategoryViewModel();

            viewModel.CategoriesString = String.Join(",", manager.GetCategories().Select(c => c.Name));

            //NewBookViewModel viewModel = new NewBookViewModel();
            //viewModel.Categories = manager.GetCategories();
            return(View(viewModel));
        }
Exemplo n.º 16
0
        public async Task <ActionResult <BooksObj> > Delete(string id)
        {
            BooksObj book = await BooksManager.DeleteBook(_booksRepository, id);

            if (book == null)
            {
                return(NotFound());
            }

            return(book);
        }
Exemplo n.º 17
0
        protected async override Task AddItems()
        {
            IEnumerable <Book> booksCollection = null;

            booksCollection = await BooksManager.GetBooksManager().GetBooks(this.CurrentPosition, this.PageSize, this.category);

            foreach (Book book in booksCollection)
            {
                this.MyItems.Add(book);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// BookQueryControl constructor.
        /// </summary>
        /// <param name="booksManager">Business logic command pattern instance</param>
        /// <param name="bookMetaDataType">The type of book meta data</param>
        /// <param name="queryType">The type of the query</param>
        public BookQueryControl(BooksManager booksManager, Type bookMetaDataType, QueryType queryType)
        {
            this.booksManager     = booksManager;
            this.bookMetaDataType = bookMetaDataType;

            this.queryType = queryType;

            this.checkedItems = new List <IBookMetaData>();

            InitializeComponent();
            this.cbQueryType.SelectedIndex = 0;
        }
 public void GetBookList_Test()
 {
     var database = new BooksManager();
     try
     {
         TransactionHelper.Begin(() => database.GetList2().ForEach(book => Console.WriteLine(book.Name)));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 20
0
        async void OnPickerSelectedItem(object sender, EventArgs e)
        {
            BooksIncrementalView booksListIncrementalView = null;

            string selectedCategory = listPicker.Items[listPicker.SelectedIndex];
            string listName         = BooksManager.GetListNameByCategory(selectedCategory);

            booksListIncrementalView = new BooksIncrementalView(listName);

            BindingContext = booksListIncrementalView;

            booksListIncrementalView.LoadMoreItemsCommand.Execute(null);
        }
Exemplo n.º 21
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            listDataType = 1;

            if (BooksManager.Books.Count() != 0)
            {
                listBox1.DataSource = null;
                listBox1.Items.Clear();
                booksList.Clear();

                for (int i = 0; i < BooksManager.Books.Count(); i++)
                {
                    booksList.Add(new Book(BooksManager.Books[i], BooksManager.Books[i].Title));
                    //listBox1.Items.Add(BooksManager.Books[i].Title);
                }

                listBox1.DataSource    = booksList;
                listBox1.DisplayMember = "Title";
                listBox1.ValueMember   = "BookFromList";
            }
            else
            {
                if (DataBase.GetStateConnection())
                {
                    listBox1.DataSource = null;
                    listBox1.Items.Clear();
                    booksList.Clear();

                    string query = "select * from Books";
                    //SqlConnection connection = DataBase.GetSqlConnection();
                    SqlCommand    command = new SqlCommand(query, DataBase.Sql);
                    SqlDataReader reader  = command.ExecuteReader();
                    //BooksManager booksMng = new BooksManager();
                    BooksManager.LoadBook(reader);

                    //List<Books> bks = booksMng.Books;
                    for (int i = 0; i < BooksManager.Books.Count(); i++)
                    {
                        booksList.Add(new Book(BooksManager.Books[i], BooksManager.Books[i].Title));
                        //listBox1.Items.Add(BooksManager.Books[i].Title);
                    }

                    listBox1.DataSource    = booksList;
                    listBox1.DisplayMember = "Title";
                    listBox1.ValueMember   = "BookFromList";

                    reader.Close();
                }
            }
        }
Exemplo n.º 22
0
        public ActionResult Index(int?categoryId)
        {
            BooksManager   manager   = new BooksManager(Properties.Settings.Default.ConStr);
            IndexViewModel viewModel = new IndexViewModel();

            viewModel.Books             = manager.GetBooks(categoryId);
            viewModel.Categories        = manager.GetCategories();
            viewModel.CurrentCategoryId = categoryId;
            if (TempData["message"] != null)
            {
                viewModel.Message = (string)TempData["message"];
            }
            return(View(viewModel));
        }
Exemplo n.º 23
0
        public ActionResult AddBook(string title, string author, int yearPublished, int pageCount,
                                    int categoryId)
        {
            BooksManager manager = new BooksManager(Properties.Settings.Default.ConStr);
            int          newId   = manager.AddBook(new Book
            {
                Title         = title,
                Author        = author,
                YearPublished = yearPublished,
                PageCount     = pageCount
            }, categoryId);

            TempData["message"] = "Book added successfully, new book id: " + newId;
            return(Redirect("/books/index"));
        }
Exemplo n.º 24
0
        private void OnAddNewBook(object bookview)
        {
            AddBookNotification notification = new AddBookNotification();

            notification.Title = "Add Book Item";
            this.AddBookRequest.Raise(notification,
                                      returned =>
            {
                if (returned != null && returned.Confirmed && returned.AddedBook != null)
                {
                    BooksManager.AddBookLibrary(returned.AddedBook);
                    ReloadBookRows();
                }
            });
        }
Exemplo n.º 25
0
        /// <summary>
        /// 创建索引
        /// </summary>
        private void CreateIndexByData()
        {
            string      indexPath = Context.Server.MapPath("~/IndexData");//索引文档保存位置         
            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NativeFSLockFactory());
            //IndexReader:对索引库进行读取的类
            bool isExist = IndexReader.IndexExists(directory);  //是否存在索引库文件夹以及索引库特征文件

            if (isExist)
            {
                //如果索引目录被锁定(比如索引过程中程序异常退出或另一进程在操作索引库),则解锁
                //Q:存在问题 如果一个用户正在对索引库写操作 此时是上锁的 而另一个用户过来操作时 将锁解开了 于是产生冲突 --解决方法后续
                if (IndexWriter.IsLocked(directory))
                {
                    IndexWriter.Unlock(directory);
                }
            }

            //创建向索引库写操作对象  IndexWriter(索引目录,指定使用盘古分词进行切词,最大写入长度限制)
            //补充:使用IndexWriter打开directory时会自动对索引库文件上锁
            IndexWriter  writer      = new IndexWriter(directory, new PanGuAnalyzer(), !isExist, IndexWriter.MaxFieldLength.UNLIMITED);
            BooksManager bookManager = new BooksManager();
            List <PZYM.Shop.Model.Books> bookList = bookManager.GetModelList("");

            //--------------------------------遍历数据源 将数据转换成为文档对象 存入索引库
            foreach (var book in bookList)
            {
                Document document = new Document();  //new一篇文档对象 --一条记录对应索引库中的一个文档

                //向文档中添加字段  Add(字段,值,是否保存字段原始值,是否针对该列创建索引)
                document.Add(new Field("Id", book.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));//--所有字段的值都将以字符串类型保存 因为索引库只存储字符串类型数据

                //Field.Store:表示是否保存字段原值。指定Field.Store.YES的字段在检索时才能用document.Get取出原值 
                //Field.Index.NOT_ANALYZED:指定不按照分词后的结果保存--是否按分词后结果保存取决于是否对该列内容进行模糊查询


                document.Add(new Field("Description", book.Description, Field.Store.YES, Field.Index.ANALYZED));

                //Field.Index.ANALYZED:指定文章内容按照分词后结果保存 否则无法实现后续的模糊查询
                //WITH_POSITIONS_OFFSETS:指示不仅保存分割后的词 还保存词之间的距离

                document.Add(new Field("MenuId", book.MenuId.ToString(), Field.Store.YES, Field.Index.ANALYZED));

                document.Add(new Field("CreativeHTML", string.IsNullOrWhiteSpace(book.CreativeHTML) ? "" : book.CreativeHTML, Field.Store.YES, Field.Index.ANALYZED));
                writer.AddDocument(document);   //文档写入索引库
            }
            writer.Close();                     //会自动解锁
            directory.Close();                  //不要忘了Close,否则索引结果搜不到
        }
Exemplo n.º 26
0
        public void ApplicationStarted()
        {
            this.userOut = new SpyUserOut();
            this.userIn  = new SpyUserIn(userOut);

            this.application = new Application(userIn, userOut);

            var booksDao = CreateBooksDao();

            this.booksManager = new BooksManager(booksDao);
            this.application.Setup(this.booksManager);

            this.userDao          = CreateUserDao();
            this.borrowingManager = new BorrowingManager(this.userDao, booksDao, CreateBorrowingDao());
            this.application.Setup(this.borrowingManager);
        }
Exemplo n.º 27
0
        public void QueryStringTest()
        {
            BooksManager manager = new BooksManager();

            List <Book> Cbooks = manager.GetAll(title: "C");

            Assert.AreEqual(2, Cbooks.Count);

            List <Book> noBooks = manager.GetAll(title: "None");

            Assert.AreEqual(0, noBooks.Count);

            List <Book> sortTitle = manager.GetAll(sortBy: "title");

            Assert.AreEqual("ABC for beginners", sortTitle[0].Title);

            List <Book> sortPrice = manager.GetAll(sortBy: "Price");

            Assert.AreEqual("C# is nice", sortPrice[0].Title);
        }
Exemplo n.º 28
0
        public void TestItAll()
        // We cannot control the execution order of test methods.
        // unless we have only one test method ...
        {
            BooksManager manager = new BooksManager();

            List <Book> allBooks = manager.GetAll();

            Assert.AreEqual(3, allBooks.Count);

            Book book = manager.GetById(1);

            Assert.AreEqual("C# is nice", book.Title);

            Assert.IsNull(manager.GetById(100));

            Book newBook = new Book {
                Title = "Android Programing", Price = 17.85
            };
            Book addedBook = manager.Add(newBook);

            Assert.AreEqual(4, addedBook.Id);
            Assert.AreEqual(4, manager.GetAll().Count);

            Book updates = new Book {
                Title = "Android Programming", Price = 18.1
            };
            Book updatedBook = manager.Update(3, updates);

            Assert.AreEqual("Android Programming", updatedBook.Title);

            Assert.IsNull(manager.Update(100, updates));

            Book deletedBook = manager.Delete(3);

            Assert.AreEqual("Android Programming", deletedBook.Title);
            Assert.AreEqual(3, manager.GetAll().Count);

            Assert.IsNull(manager.Delete(100));
        }
        public void BookManager_GetOldestBook_two_books_second_is_oldest()
        {
            var mock = new Mock <IBookRepository>();

            mock.Setup(x => x.GetAllBooks()).Returns(() =>
            {
                var b1 = new Book()
                {
                    Title = "EINS", Jahr = DateTime.Now
                };
                var b2 = new Book()
                {
                    Title = "ZWEI", Jahr = DateTime.Now.AddDays(-1)
                };
                return(new[] { b1, b2 });
            });
            var bm = new BooksManager(mock.Object);

            var result = bm.GetOldestBook();

            Assert.AreEqual("ZWEI", result.Title);
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            var bm = new BooksManager(new GoogleBookApIRepo());

            int zahl = 1;

            Console.WriteLine($"{zahl}");
            zahl += 1;
            Console.WriteLine($"{zahl}");
            zahl *= 1;
            Console.WriteLine($"{zahl}");
            zahl -= 1;

            foreach (var b in bm.GetAllBookTitles())
            {
                Console.WriteLine($"[{b.Id:00}] {b.Title} - {b.Jahr}");
            }

            Console.WriteLine($"OldBook: {bm.GetOldestBook().Title}");

            Console.WriteLine("Ende");
            Console.ReadLine();
        }
 public BooksController(BooksManager booksManager)
 {
     this.booksManager = booksManager;
 }