private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (MyStorage.ReadXML <ObservableCollection <Book> >("books.xml") == null)
            {
                books = new ObservableCollection <Book>();
            }
            else
            {
                books = MyStorage.ReadXML <ObservableCollection <Book> >("books.xml");
            }

            if (MyStorage.ReadXML <ObservableCollection <Friend> >("friends.xml") == null)
            {
                friends = new ObservableCollection <Friend>();
            }
            else
            {
                friends = MyStorage.ReadXML <ObservableCollection <Friend> >("friends.xml");
            }

            LBx_book.ItemsSource      = books;
            LBx_friend.ItemsSource    = friends;
            TBk_bookCount.DataContext = this;

            foreach (Book element in books)
            {
                if (element.isAvailable == "Yes")
                {
                    availableCount++;
                }
            }
        }
示例#2
0
        private void Btn_save_friend_Click(object sender, RoutedEventArgs e)
        {
            if (friend.phone == null)
            {
                MessageBox.Show("Please enter phone number.");
                return;
            }

            Friend fList = (from f in MainWindow.friends where f.phone.Contains(friend.phone) select f).FirstOrDefault <Friend>();

            if (fList != null)
            {
                MessageBox.Show("A friend with this phone number exists in database. Please try another.");
                return;
            }

            MainWindow.friends.Add(friend);
            MyStorage.WriteXML <ObservableCollection <Friend> >("friends.xml", MainWindow.friends);
            MessageBox.Show("New friend has been added");
            this.Close();
        }
        private void Btn_save_book_Click(object sender, RoutedEventArgs e)
        {
            if (book.isbn == null)
            {
                MessageBox.Show("Please enter ISBN.");
                return;
            }

            Book bList = (from b in MainWindow.books where b.isbn.Contains(book.isbn) select b).FirstOrDefault <Book>();

            if (bList != null)
            {
                MessageBox.Show("The book already exists in database. Please try another.");
                return;
            }

            MainWindow main = (MainWindow)Application.Current.MainWindow;

            MainWindow.books.Add(book);
            main.availableCount++;
            MyStorage.WriteXML <ObservableCollection <Book> >("books.xml", MainWindow.books);
            MessageBox.Show("New book has been added");
            this.Close();
        }
示例#4
0
        private void Btn_save_Click(object sender, RoutedEventArgs e)
        {
            MainWindow main = (MainWindow)Application.Current.MainWindow;

            if (CBx_friend.SelectedItem == null)
            {
                MessageBox.Show("Please select a friend ...");
                return;
            }

            selectedFriend = CBx_friend.SelectedItem as Friend;
            Friend friend = (from f in MainWindow.friends where f.phone.Contains(selectedFriend.phone) select f).FirstOrDefault <Friend>();

            selectedBook.isAvailable = "No";
            selectedBook.friend      = friend.firstName + " " + friend.lastName;
            selectedBook.contact     = friend.phone;
            selectedBook.borrowDate  = date;
            selectedBook.returnDate  = date.AddDays(days);
            friend.bookList.Add(selectedBook.isbn);
            main.availableCount--;
            MyStorage.WriteXML <ObservableCollection <Friend> >("friends.xml", MainWindow.friends);
            MessageBox.Show("The book has been borrowed");
            this.Close();
        }
 private void Window_Closed(object sender, EventArgs e)
 {
     MyStorage.WriteXML <ObservableCollection <Book> >("books.xml", books);
     MyStorage.WriteXML <ObservableCollection <Friend> >("friends.xml", friends);
 }