コード例 #1
0
ファイル: BookRepositary.cs プロジェクト: Bathri021/Aspireksr
        public void addbBookIntoList()
        {
            string sqlQuery = "Select * From Book";

            using (SqlCommand selectCommand = new SqlCommand(sqlQuery, dbConnection))
            {
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = selectCommand;
                DataSet BookDataset = new DataSet();
                adapter.Fill(BookDataset, "Book");
                DataTable BookDataTable = BookDataset.Tables["Book"];
                foreach (DataRow row in BookDataTable.Rows)
                {
                    Book book = new Book
                    {
                        BookID    = int.Parse(row[0].ToString()),
                        Title     = row[2].ToString(),
                        Author    = row[3].ToString(),
                        Genere    = row[4].ToString(),
                        Price     = int.Parse(row[5].ToString()),
                        NoOfPages = int.Parse(row[6].ToString())
                    };
                    BookList.Add(book.BookID, book);
                }
            };
        }
コード例 #2
0
        public void Call()
        {
            #region older versions without generics, code redundancy
            var numbers = new List();
            numbers.Add(2);

            var booksList = new BookList();
            booksList.Add(new Book());
            #endregion

            var numbersList = new GenericList <int>();
            numbers.Add(10);

            var books = new GenericList <Book>();
            books.Add(new Book());

            var dictionary = new GenericDictionary <string, Book>();
            dictionary.Add("1234", new Book());

            var number = new Nullable <int>(5);
            Console.WriteLine("Has value? " + number.HasValue);
            Console.WriteLine("Value: " + number.GetValueOrDefault());

            var numberTwo = new Nullable <int>();
            Console.WriteLine("Has value? " + numberTwo.HasValue);
            Console.WriteLine("Value: " + numberTwo.GetValueOrDefault());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: AdinaGh/7Tema1
        private static BookList BookMaxYear(SqlConnection connection, int maxYear)
        {
            const string query = "select * from Book where Year<=@MaxYear";

            using (var command = new SqlCommand(query, connection))
            {
                command.Parameters.Add(new SqlParameter("@MaxYear", maxYear));
                Console.WriteLine($"Books with max {maxYear}:");
                using (var dataReader = command.ExecuteReader())
                {
                    var list = new BookList();
                    while (dataReader.Read())
                    {
                        var currentRow = dataReader;

                        var bookId = currentRow["BookId"];
                        var title  = currentRow["Title"];
                        var year   = currentRow["Year"];
                        var price  = currentRow["Price"];

                        list.Add(int.Parse(currentRow["BookId"].ToString()), currentRow["Title"].ToString(),
                                 int.Parse(currentRow["Year"].ToString()), decimal.Parse(currentRow["Price"].ToString()));
                    }
                    return(list);
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: AdinaGh/7Tema1
        private static BookList Top10Books(SqlConnection connection)
        {
            const string query = "select top 10 * from Book";

            using (var command = new SqlCommand(query, connection))
            {
                Console.WriteLine("Top 10 Books:");
                using (var dataReader = command.ExecuteReader())
                {
                    var list = new BookList();
                    while (dataReader.Read())
                    {
                        var currentRow = dataReader;

                        var title = currentRow["Title"];
                        var year  = currentRow["Year"];
                        var price = currentRow["Price"];

                        list.Add(int.Parse(currentRow["BookId"].ToString()), currentRow["Title"].ToString(),
                                 int.Parse(currentRow["Year"].ToString()), decimal.Parse(currentRow["Price"].ToString()));
                    }
                    return(list);
                }
            }
        }
コード例 #5
0
ファイル: Generics.cs プロジェクト: Lakhwinder/HandsOn
        static void Main(string[] args)
        {
            var book = new Book {
                Isbn = "1111", Title = "C# Advanced"
            };

            //Classic way
            var numbers = new List();

            numbers.Add(10);

            var books = new BookList();

            books.Add(book);
            //Generic
            var numberList = new GenericList <int>();

            numberList.Add(10);

            var bookList = new GenericList <Book>();

            bookList.Add(book);

            var dictionary = new GenericDictionary <string, Book>();

            dictionary.Add("1234", new Book());
        }
コード例 #6
0
 private void ExecuteHttpCommand()
 {
     NavigationService.NavigateTo(typeof(HttpPage).FullName);
     Messenger.Default.Send(new NotificationMessageAction <Book>(null, null, item =>
     {
         BookList.Add(item);
     }), "http");
 }
コード例 #7
0
        /// <summary>
        /// 追加コマンドを実行する
        /// </summary>
        private void AddCommandExecute()
        {
            Book addBook = new Book(books.GetList().Count + 1, Book.Title, Book.Author, Book.Price);

            books.Add(addBook);

            CollectionList.Add(addBook);
        }
コード例 #8
0
        /// <summary> Add book to the list.</summary>
        /// <param name="book"> The book to add. </param>
        public void AddBook(Book book)
        {
            if (IfBookExists(book))
            {
                throw new ArgumentException("The book already exists!");
            }

            BookList.Add(book);
        }
コード例 #9
0
        /// <summary>
        /// 追加コマンドを実行する
        /// </summary>
        private void AddCommandExecute()
        {
            Book addBook = new Book(DataBaseManager.GetIDNextData(), Book.Title, Book.Author, Book.Price);

            books.Add(addBook);
            DataBaseManager.AddDataBase(addBook);


            CollectionList.Add(addBook);
        }
コード例 #10
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainViewModel()
        {
            Book = new Book();

            books = new BookList();

            DataBaseManager = new DataBaseManager();

            if (!DataBaseManager.IsExistDataBaseFile())
            {
                DataBaseManager.CreateDataBase();

                books.Add(new Book()
                {
                    ID = 1, Title = "簡単すぎる本", Author = "アンドロイド1号", Price = 100
                });
                books.Add(new Book()
                {
                    ID = 2, Title = "普通すぎる本", Author = "アンドロイド2号", Price = 200
                });
                books.Add(new Book()
                {
                    ID = 3, Title = "難しすぎる本", Author = "アンドロイド3号", Price = 300
                });

                foreach (var book in books.GetList())
                {
                    DataBaseManager.AddDataBase(book);
                }
            }
            else
            {
                foreach (var book in DataBaseManager.GetDataBase())
                {
                    books.Add(book);
                }
            }



            CollectionList = new ObservableCollection <Book>(books.GetList());
        }
コード例 #11
0
        void InitData()
        {
            var ser = new BookService2(new BookRepository());
            var lst = ser.GetBooks();

            BookList.Clear();
            foreach (var article in lst)
            {
                BookList.Add(article);
            }
        }
コード例 #12
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainViewModel()
        {
            Book = new Book();

            books = new BookList();

            books.Add(new Book()
            {
                ID = 1, Title = "簡単すぎる本", Author = "アンドロイド1号", Price = 100
            });
            books.Add(new Book()
            {
                ID = 2, Title = "普通すぎる本", Author = "アンドロイド2号", Price = 200
            });
            books.Add(new Book()
            {
                ID = 3, Title = "難しすぎる本", Author = "アンドロイド3号", Price = 300
            });

            CollectionList = new ObservableCollection <Book>(books.GetList());
        }
コード例 #13
0
        private void sortByName()
        {
            List <BOOK> sortedList = BookList.OrderBy(x => x.NAME.ToUpper().Contains(SortByName.ToUpper())).ToList();

            sortedList.Reverse();
            BookList.Clear();
            foreach (var sortedItem in sortedList)
            {
                BookList.Add(sortedItem);
            }
            SelectedBook = BookList.First();
            OnPropertyChanged("BookList");
        }
コード例 #14
0
        private void sortByBookId()
        {
            List <BOOK> sortedList = BookList.OrderBy(x => x.ID.ToString() == Convert.ToString(SearchByBookId)).ToList();

            sortedList.Reverse();
            BookList.Clear();
            foreach (var sortedItem in sortedList)
            {
                BookList.Add(sortedItem);
            }
            SelectedBook = BookList.First();
            OnPropertyChanged("BookList");
        }
コード例 #15
0
 public bool AddBook(string Title, string Author)
 {
     try
     {
         BookList.Add(new Book(this.NextBookId, Title, Author));
         Console.WriteLine("SUCCESS: Added book to library: " + this.Name);
         this.NextBookId++;
         return(true);
     }
     catch
     {
         Console.WriteLine("ERROR: Faild to add book to library: " + this.Name);
         return(false);
     }
 }
コード例 #16
0
        private async Task _addBookAsync()
        {
            var books = await BookHelper.OpenAsync();

            if (books == null)
            {
                return;
            }

            books.ForEach(book =>
            {
                BookList.Add(book);
            });
            NavigationService.NavigateTo(typeof(BookReadPage).FullName, books[0]);
        }
コード例 #17
0
 private void _refresh()
 {
     BookList.Clear();
     SqlHelper.Conn.Open();
     using (var reader = SqlHelper.Select <Book>("ORDER BY ReadTime DESC"))
     {
         while (reader.Read())
         {
             if (reader.HasRows)
             {
                 BookList.Add(new Book(reader));
             }
         }
     }
     SqlHelper.Conn.Close();
 }
コード例 #18
0
        /// <summary>
        /// Adds the book.
        /// </summary>
        /// <param name="book">The book.</param>
        /// <exception cref="ArgumentNullException">book</exception>
        /// <exception cref="ArgumentException">book</exception>
        public void AddBook(Book book)
        {
            if (ReferenceEquals(book, null))
            {
                Logger.Error($"{nameof(book)} is null");
                throw new ArgumentNullException($"{nameof(book)} is null");
            }

            if (BookList.Contains(book))
            {
                Logger.Error($"{nameof(book)} is already exist!");
                throw new ArgumentException($"{nameof(book)} is already exist!");
            }

            BookList.Add(book);
            Logger.Info($"{nameof(book)} added!");
        }
コード例 #19
0
        void UpdateBookList(bool setActive = true)
        {
            lock (_updateBookLock)
            {
                BookList.Clear();
                foreach (var book in _localBookList.Books)
                {
                    _books[book] = null;
                    BookList.Add(book);
                }

                if (setActive && BookList.Count > 0)
                {
                    ActiveBook = BookList[0];
                }
            }
        }
コード例 #20
0
 /// <summary>
 /// add book for the booklist and with the important entities to the resultList
 /// </summary>
 /// <param name="result">the api calls result object</param>
 private void AddItemToList(BookList result)
 {
     foreach (var d in result.Docs)
     {
         ImageSource img  = _searchService.GetImg(d.Cover_edition_key, "M");
         var         temp = new BookEntity
         {
             Title = d.Title_suggest,
             Img   = img,
             Isbn  = d.Isbn,
             Oclc  = d.Oclc,
             Lccn  = d.Lccn
         };
         ResultList.Add(temp);
         BookList.Add(d);
     }
 }
コード例 #21
0
        static void Main(string[] args)
        {
            var book = new Book {
                Isbn = "12133", Title = "CSharp"
            };

            var number = new List();

            number.Add(10);

            var books = new BookList();

            books.Add(book);

            var letters = new GenericList <string>();

            letters.Add("teste");
        }
コード例 #22
0
ファイル: Menu.cs プロジェクト: josephharburg/MidTermLibrary
        //Method that lets a user add a book to the library
        public static void AddBook()
        {
            Console.WriteLine("Would you like to donate a book? (Yes or No)");
            string reply = Validator.inputCheck(Console.ReadLine());

            if (reply == "yes" || reply == "y")
            {
                Console.WriteLine("What is the title?");
                string title = Validator.ValidateTitle();
                Console.WriteLine("Who is the author?");
                string author = Validator.ValidateAuthor();
                BookList.Add(new Book(title, author, 0));
            }
            else if (reply == "no" || reply == "n")
            {
            }

            BookToTxtFile(BookList);
        }
コード例 #23
0
        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnpreviewpage_Click(object sender, RoutedEventArgs e)
        {
            PageIndex = (Convert.ToInt32(PageIndex) - 1).ToString();

            int pagecount = Convert.ToInt32(PageCount);

            Books book = new Books()
            {
                BookCategory = BookCategoryId,
                BookName     = BookName,
                BarCode      = Barcode,
                PageIndex    = Convert.ToInt32(PageIndex),
                PageSize     = Convert.ToInt32(PageSize)
            };

            List <Books> bookslist = new List <Books>();

            bookmaintainb.SearchBookinfoList <Books>(DAL.SQLID.BookMaintain.BookMaintain.selelct_book_bycontation, book, bookslist);
            BookList.Clear();
            if (bookslist.Count != 0)
            {
                foreach (var item in bookslist)
                {
                    BookList.Add(item);
                }
            }
            if (Convert.ToInt32(PageIndex) == 1)
            {
                //上一页,首页不可用,其他可以用
                ButtonFistpage     = "0";
                ButtonNexpage      = "1";
                ButtonPreviewpage  = "0";
                ButtonLastpage     = "1";
                ButtonRedirttopage = "1";

                //btnfistpage.IsEnabled = false;
                //btnnextpage.IsEnabled = true;
                //btnpreviewpage.IsEnabled = false;
                //btnlastpage.IsEnabled = true;
                //btnredirettopage.IsEnabled = true;
            }
        }
コード例 #24
0
        public void PrepareData(List <Book> books, Author author)
        {
            Id          = author.Id;
            Name        = author.Name;
            Surname     = author.Surname;
            DateOfBirth = author.DateBorned.ToString("dd.MM.yyyy.");

            foreach (var book in books)
            {
                BookDetailsViewModel viewModel = new BookDetailsViewModel();

                viewModel.Id       = book.Id;
                viewModel.Title    = book.Title;
                viewModel.Subtitle = book.Subtitle;
                viewModel.Isbn     = book.Isbn;
                BookList.Add(viewModel);
            }

            NumberOfBooks = BookList.Count;
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: AdinaGh/7Tema1
        private static BookList Books2010(SqlConnection connection, int year)
        {
            const string query = "select * from Book where Year=@Year";

            using (var command = new SqlCommand(query, connection))
            {
                command.Parameters.Add(new SqlParameter("@Year", year));
                using (var dataReader = command.ExecuteReader())
                {
                    var list = new BookList();
                    while (dataReader.Read())
                    {
                        var currentRow = dataReader;

                        list.Add(int.Parse(currentRow["BookId"].ToString()), currentRow["Title"].ToString(), int.Parse(currentRow["Year"].ToString()), decimal.Parse(currentRow["Price"].ToString()));
                    }
                    return(list);
                }
            }
        }
コード例 #26
0
ファイル: TestBookCollection.cs プロジェクト: ya1aalexx/pi19
 private void h_TestFill()
 {
     BookList.Add(
         new Book()
     {
         Title  = "имя 1",
         Author = "й1 ц у"
     });
     BookList.Add(
         new Book()
     {
         Title  = "имя 2",
         Author = "й2 ц у"
     });
     BookList.Add(
         new Book()
     {
         Title  = "имя 3",
         Author = "й3 ц у"
     });
 }
コード例 #27
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            string author = AuthorTextBox.Text;
            string title = TitleTextBox.Text;
            string releaseDate, nISBN;

            Categories category = (Categories)Enum.Parse(typeof(Categories), CategoryComboBox.Text);
            Types      type     = (Types)Enum.Parse(typeof(Types), TypeComboBox.Text);

            int numberOfPages, length, numberOfActors;
            int selectedCategory = CategoryComboBox.SelectedIndex;

            switch (selectedCategory)
            {
            case 0:
                try
                {
                    nISBN         = FirstAdditionalInformationInfoTextBox.Text;
                    numberOfPages = int.Parse(SecondAdditionalInformationInfoTextBox.Text);

                    Book book = new Book(title, author, category, type, nISBN, numberOfPages);
                    BookList.Add(book);

                    totalToRead = book.News(totalToRead, "add");
                }
                catch
                {
                    MessageBox.Show("Ilość stron powinna być podana jako liczba", "Zła wartość");
                }
                break;

            case 1:
                try
                {
                    length         = int.Parse(SecondAdditionalInformationInfoTextBox.Text);
                    numberOfActors = int.Parse(FirstAdditionalInformationInfoTextBox.Text);

                    Audiobook audiobook = new Audiobook(title, author, category, type, length, numberOfActors);
                    AudiobookList.Add(audiobook);

                    totalToListen = audiobook.News(totalToListen, "add");
                }
                catch
                {
                    MessageBox.Show("Czas trwania oraz liczba aktorów powinny być podane jako liczby", "Zła wartość");
                }
                break;

            case 2:
                try
                {
                    releaseDate = FirstAdditionalInformationInfoTextBox.Text;
                    length      = int.Parse(SecondAdditionalInformationInfoTextBox.Text);

                    Movie movie = new Movie(title, author, category, type, length, releaseDate);
                    MovieList.Add(movie);

                    totalToWatch = movie.News(totalToWatch, "add");
                }
                catch
                {
                    MessageBox.Show("Czas trwania powinien być podany jako liczba", "Zła wartość");
                }
                break;
            }
            SetNewsTextBlocks(selectedCategory);
        }
コード例 #28
0
        private void ReadTXTFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string fileName = TXTfilePath.Text + TXTfileName.Text + ".txt";

                FileStream fileStream = new FileStream(fileName,
                                                       FileMode.Open, FileAccess.Read);

                try
                {
                    StreamReader streamReader = new StreamReader(fileStream);

                    while (streamReader.EndOfStream == false)
                    {
                        string   line  = streamReader.ReadLine();
                        string[] table = line.Split('_');

                        if (table[0] == "Książka")
                        {
                            Categories category      = (Categories)Enum.Parse(typeof(Categories), "Książka");
                            string     title         = table[1];
                            string     author        = table[2];
                            string     nISBN         = table[3];
                            int        numberOfPages = int.Parse(table[4]);
                            Types      type          = (Types)Enum.Parse(typeof(Types), table[5]);
                            Book       book          = new Book(title, author, category, type, nISBN, numberOfPages);
                            BookList.Add(book);
                            totalToRead = book.News(totalToRead, "add");
                        }
                        else if (table[0] == "Audiobook")
                        {
                            Categories category       = (Categories)Enum.Parse(typeof(Categories), "Audiobook");
                            string     title          = table[1];
                            string     author         = table[2];
                            int        length         = int.Parse(table[3]);
                            int        numberOfActors = int.Parse(table[4]);
                            Types      type           = (Types)Enum.Parse(typeof(Types), table[5]);
                            Audiobook  audiobook      = new Audiobook(title, author, category, type, length, numberOfActors);
                            AudiobookList.Add(audiobook);
                            totalToListen = audiobook.News(totalToListen, "add");
                        }
                        else if (table[0] == "Film")
                        {
                            Categories category    = (Categories)Enum.Parse(typeof(Categories), "Film");
                            string     title       = table[1];
                            string     author      = table[2];
                            int        length      = int.Parse(table[3]);
                            string     releaseDate = table[4];
                            Types      type        = (Types)Enum.Parse(typeof(Types), table[5]);
                            Movie      movie       = new Movie(title, author, category, type, length, releaseDate);
                            MovieList.Add(movie);
                            totalToWatch = movie.News(totalToWatch, "add");
                        }
                        else
                        {
                            MessageBox.Show("Wystąpił błąd podczas odczytywana danych z pliku");
                        }
                    }

                    streamReader.Close();

                    MessageBox.Show("Wczytano pomyslnie");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Nie można wczytać pliku.");
                }
                int selectedCategory = CategoryComboBox.SelectedIndex;
                SetNewsTextBlocks(selectedCategory);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Nie można otworzyć pliku.");
            }
        }
コード例 #29
0
 public void AddBook(Book _book)
 {
     BookList.Add(_book);
 }
コード例 #30
0
 /// <summary>
 ///
 /// </summary>
 public static void addBookItem(String EPC, String timeStamp, String RSSI, string Title, string Autor, string Genre, Byte[] Image)
 {
     BookList.Add(new Itembook(EPC = EPC, timeStamp = timeStamp.ToString(), RSSI = RSSI, Title = Title, Autor = Autor, Genre = Genre, Image = Image));
 }