Beispiel #1
0
        public ActionResult Index()
        {
            var booksRepo = new Books();
            var books = booksRepo.GetByPage(0);//REFACTORING model should be DTO

            return View(books);
        }
 public static async Task SaveImageAsync(Books.IBook book)
 {
     if(book is Books.IBookFixed && (book as Books.IBookFixed).PageCount>0)
     {
         if (await GetImageFileAsync(book.ID) == null)
         {
             await (book as Books.IBookFixed).GetPage(0).SaveImageAsync(await CreateImageFileAsync(book.ID), 300);
         }
     }
 }
Beispiel #3
0
 public BookForm( Books b )
 {
     InitializeComponent();
       bookID = b.BooksID;
       txtPatronID.ReadOnly = false;
       txtPatronID.Text = b.PatronID.ToString(); // todo
       cmbType.SelectedIndex = (b.Type == "adult") ? 0 : 1; // todo
       txtTitle.Text = b.Title;
       txtDescription.Text = b.Description;
       //dtpCheckedOut.Value = new DateTime(); // todo
 }
Beispiel #4
0
        public ActionResult Delete(Book model)
        {
            var booksRepo = new Books();
            var success = booksRepo.Delete(model);
            if (success)
            {
                return RedirectToAction("index");
            }

            return View(model);
        }
public ActionResult EditBooks(string oper)
{
    // 데이터베이스에서 데이터를 가져옵니다.
    DataClassesDB db = new DataClassesDB();

    // 각각에 맞게 처리합니다.
    if (oper == "add")
    {
        // 책을 추가합니다.
        Books books = new Books();
        
        books.Name = Request["Name"];
        books.Author = Request["Author"];
        books.Publisher = Request["Publisher"];
        books.Isbn = Request["Isbn"];
        books.Page = Request["Page"];
        books.PublishDate = DateTime.Now;

        db.Books.InsertOnSubmit(books);
        db.SubmitChanges();
    }
    else if (oper == "edit")
    {
        // 책을 변경합니다.
        var id = int.Parse(Request["Id"]);
        var willUpdate = db.Books.Single(x => x.Id == id);
        willUpdate.Name = Request["Name"];
        willUpdate.Author = Request["Author"];
        willUpdate.Publisher = Request["Publisher"];
        willUpdate.Isbn = Request["Isbn"];
        willUpdate.Page = Request["Page"];
        willUpdate.PublishDate = DateTime.Now;

        db.SubmitChanges();
    }
    else if (oper == "del")
    {
        // 책을 삭제합니다.
        var id = int.Parse(Request["Id"]);
        var willDelete = db.Books.Single(x => x.Id == id);
        db.Books.DeleteOnSubmit(willDelete);
    }
    return Content("SUCCESS");
}
Beispiel #6
0
    public static void Main(string[] args)
    {
        Books Book1 = new Books(); /* 声明 Book1,类型为 Book */
          Books Book2 = new Books(); /* 声明 Book2,类型为 Book */

          /* book 1 详述 */
          Book1.getValues("C Programming",
          "Nuha Ali", "C Programming Tutorial",6495407);

          /* book 2 详述 */
          Book2.getValues("Telecom Billing",
          "Zara Ali", "Telecom Billing Tutorial", 6495700);

          /* 打印 Book1 信息 */
          Book1.display();

          /* 打印 Book2 信息 */
          Book2.display();

          Console.ReadKey();
    }
        public async void Initialize(Books.IBookFixed value, Control target=null)
        {
            if (BookInfo != null) SaveInfo();
            this.Title = "";

            var pages = new ObservableCollection<PageViewModel>();
            var option = OptionCache = target == null ? OptionCache : new Books.PageOptionsControl(target);
            for (uint i = 0; i < value.PageCount; i++)
            {
                uint page = i;
                pages.Add(new PageViewModel(new Books.VirtualPage(() => { var p = value.GetPage(page); p.Option = option; return p; })));
            }
            this._Reversed = false;
            this._PageSelected = 0;
            ID = value.ID;
            this.Pages = pages;
            BookInfo = await BookInfoStorage.GetBookInfoByIDOrCreateAsync(value.ID);
            var tempPageSelected = (bool)SettingStorage.GetValue("SaveLastReadPage") ? (int)(BookInfo?.GetLastReadPage()?.Page ?? 1):1;
            this.PageSelected = tempPageSelected == this.PagesCount ? 1 : tempPageSelected;
            this.Reversed = BookInfo?.PageReversed ?? false;
            OnPropertyChanged(nameof(Reversed));
            this.AsBookShelfBook = null;

            this.Bookmarks = new ObservableCollection<BookmarkViewModel>();
            {
                var rl = new Windows.ApplicationModel.Resources.ResourceLoader();
                var bm = new BookmarkViewModel() { Page = 1, AutoGenerated = true, Title = rl.GetString("BookmarkTop/Title") };
                this.Bookmarks.Add(bm);
            }
            foreach (var bm in BookInfo.Bookmarks)
            {
                this.Bookmarks.Add(new BookmarkViewModel(bm) );
            }
            {
                var rl = new Windows.ApplicationModel.Resources.ResourceLoader();
                var bm = new BookmarkViewModel() { Page = this.PagesCount, AutoGenerated = true, Title = rl.GetString("BookmarkLast/Title") };
                this.Bookmarks.Add(bm);
            }
        }
 private void Open(Books.IBook book)
 {
     if (book != null && book is Books.IBookFixed) (this.DataContext as BookFixed2ViewModels.BookViewModel).Initialize(book as Books.IBookFixed, this.flipView);
 }
        public static void Initialize(LibraryContext context)
        {
            context.Database.EnsureCreated();
            if (context.Books.Any())
            {
                return; // BD a fost creata anterior
            }
            var books = new Books[]
            {
                new Books {
                    Title = "Baltagul", Author = "Mihail Sadoveanu", Price = Decimal.Parse("22")
                },
                new Books {
                    Title = "Enigma Otiliei", Author = "George Calinescu", Price = Decimal.Parse("18")
                },
                new Books {
                    Title = "Maytrei", Author = "Mircea Eliade", Price = Decimal.Parse("27")
                },
                new Books {
                    Title = "Panza de paianjen", Author = "Cella Serghi", Price = Decimal.Parse("45")
                },
                new Books {
                    Title = "Fata de hartie", Author = "Guillame Musso", Price = Decimal.Parse("38")
                },
                new Books {
                    Title = "De veghe in lanul de secara", Author = "J.D. Salinger", Price = Decimal.Parse("28")
                },
            };

            foreach (Books s in books)
            {
                context.Books.Add(s);
            }
            context.SaveChanges();
            var customers = new Customer[]
            {
                new Customer {
                    CustomerID = 1050, Name = "Popescu Marcela", BirthDate = DateTime.Parse("1979-09-01")
                },
                new Customer {
                    CustomerID = 1045, Name = "Mihailescu Cornel", BirthDate = DateTime.Parse("1969-07-08")
                },
            };

            foreach (Customer c in customers)
            {
                context.Customers.Add(c);
            }
            context.SaveChanges();
            var orders = new Order[]
            {
                new Order {
                    BookID = 1, CustomerID = 1050, OrderDate = DateTime.Parse("02-25-2020")
                },
                new Order {
                    BookID = 3, CustomerID = 1045, OrderDate = DateTime.Parse("09-28-2020")
                },
                new Order {
                    BookID = 1, CustomerID = 1045, OrderDate = DateTime.Parse("10-28-2020")
                },
                new Order {
                    BookID = 2, CustomerID = 1050, OrderDate = DateTime.Parse("09-28-2020")
                },
                new Order {
                    BookID = 4, CustomerID = 1050, OrderDate = DateTime.Parse("09-28-2020")
                },
                new Order {
                    BookID = 4, CustomerID = 1050, OrderDate = DateTime.Parse("10-28-2020")
                },
            };

            foreach (Order e in orders)
            {
                context.Orders.Add(e);
            }
            context.SaveChanges();
            var publisher = new Publishers[]
            {
                new Publishers {
                    PublisherName = "Humanitas", Adress = "Str. Aviatorilor, nr. 40, Bucuresti"
                },
                new Publishers {
                    PublisherName = "Nemira", Adress = "Str. Plopilor, nr. 35, Ploiesti"
                },
                new Publishers {
                    PublisherName = "Paralela 45", Adress = "Str. Cascadelor, nr. 22, Cluj-Napoca"
                },
            };

            foreach (Publishers p in publisher)
            {
                context.Publishers.Add(p);
            }
            context.SaveChanges();
            var publishedbooks = new Views.Books.PublishedBooks[]
            {
                new Views.Books.PublishedBooks {
                    BookID = books.Single(c => c.Title == "Maytrei").ID, PublisherID = publisher.Single(i => i.PublisherName == "Humanitas").ID
                },
                new Views.Books.PublishedBooks {
                    BookID = books.Single(c => c.Title == "Enigma Otiliei").ID, PublisherID = publisher.Single(i => i.PublisherName == "Humanitas").ID
                },
                new Views.Books.PublishedBooks {
                    BookID = books.Single(c => c.Title == "Baltagul").ID, PublisherID = publisher.Single(i => i.PublisherName == "Nemira").ID
                },
                new Views.Books.PublishedBooks {
                    BookID = books.Single(c => c.Title == "Fata de hartie").ID, PublisherID = publisher.Single(i => i.PublisherName == "Paralela 45").ID
                },
                new Views.Books.PublishedBooks {
                    BookID = books.Single(c => c.Title == "Panza de paianjen").ID, PublisherID = publisher.Single(i => i.PublisherName == "Paralela 45").ID
                },
                new Views.Books.PublishedBooks {
                    BookID = books.Single(c => c.Title == "De veghe in lanul desecara").ID, PublisherID = publisher.Single(i => i.PublisherName == "Paralela45").ID
                },
            };

            foreach (Views.Books.PublishedBooks pb in publishedbooks)
            {
                //var entityEntry = context.PublishedBooks.Add(pb);
            }
            context.SaveChanges();
        }
Beispiel #10
0
 public void Add(Books Books)
 {
     _dbContext.Books.Add(Books);
     _dbContext.SaveChanges();
 }
Beispiel #11
0
 partial void InsertBooks(Books instance);
Beispiel #12
0
 partial void DeleteBooks(Books instance);
 public PageViewModel(Books.IPageFixed page) {
     this.Page = page;
 }
Beispiel #14
0
        void CreateEnvyXml(FictionBook book, ref ISXMLElement pXML)
        {
            EnvyBook sbook  = new EnvyBook(book);
            Books    sBooks = new Books();

            sBooks.books[0] = sbook;

            MemoryStream ms       = null;
            XmlWriter    writer   = null;
            string       finalXml = String.Empty;

            try {
                XmlSerializer s = new XmlSerializer(typeof(Books));
                s.UnknownNode      += new XmlNodeEventHandler(OnUnknownNode);
                s.UnknownAttribute += new XmlAttributeEventHandler(OnUnknownAttribute);

                ms = new MemoryStream();

                UTF8Encoding utf8 = new UTF8Encoding(false, false);
                writer = new XmlTextWriter(ms, utf8);

                XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
                // Don't add any prefixes
                xsn.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                s.Serialize(writer, sBooks, xsn);

                // Start modifying the resulting XML
                XmlDocument doc = new XmlDocument();
                ms.Position = 0;
                doc.Load(ms);
                XmlAttribute schema = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation",
                                                          "http://www.w3.org/2001/XMLSchema-instance");
                schema.Value = Books.URI;
                doc.DocumentElement.SetAttributeNode(schema);
                // Truncate the serialization result and overwrite it with our modified XML
                ms.SetLength(0);
                ms.Position = 0;
                writer      = new XmlTextWriter(ms, utf8);
                doc.Save(writer);

                char[] buffer = Encoding.UTF8.GetChars(ms.ToArray());
                finalXml = new string(buffer);
            } catch (Exception e) {
                Trace.WriteLine(e.Message);
                Exception inner = e.InnerException;
                while (inner != null)
                {
                    Trace.WriteLine(inner.Message);
                    inner = inner.InnerException;
                }
            } finally {
                if (writer != null)
                {
                    writer.Close();
                }
                if (ms != null)
                {
                    ms.Close();
                }
            }
            if (!String.IsNullOrEmpty(finalXml))
            {
                Trace.WriteLine(finalXml);
                ISXMLElement newXML = pXML.FromString(finalXml);
                if (newXML != null)
                {
                    pXML.Elements.Attach(newXML);
                }
            }
        }
Beispiel #15
0
 private Books(Books next, string book, Books previous)
 {
     Next     = next;
     Book     = book;
     Previous = previous;
 }
 public ViewResult AddNewBook(Books BookModel)
 {
     return(View());
 }
Beispiel #17
0
 public void Update(Books book)
 {
     _context.Update(book);
 }
Beispiel #18
0
 public static Books Previous(this Books previous, string book)
 {
     return(new Books(this, book, previous));
 }
Beispiel #19
0
 public void Remove(Books book)
 {
     _context.Remove(book);
 }
Beispiel #20
0
        // public IEnumerable<Books> Books => throw new NotImplementedException();

        // public IEnumerable<Books> BooksOfTheWeek => throw new NotImplementedException();

        public void Add(Books book)
        {
            _context.Add(book);
        }
Beispiel #21
0
 public void Awake()
 {
     books = (Books)target;
 }
Beispiel #22
0
 internal void LoadBookDetails(int bookID)
 {
     DataSet bookDS;
       Books b;
       try
       {
     bookDS = data.RetrieveBook(bookID, null);
     if ((bookDS.Tables.Count > 0) && (bookDS.Tables["Books"].Rows.Count > 0))
     {
       DataRow bookDR = bookDS.Tables["Books"].Rows[0];
       b = new Books(bookDR);
       LaunchBookDialog(b);
     }
       }
       catch (Exception ex)
       {
     MessageBox.Show(ex.Message);
       }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (edit)
            {
                AddOrEdit.Text          = "Edit Book Copy";
                Cancel.Visible          = true;
                CheckedOutLabel.Visible = true;
                CheckedOut.Visible      = true;
                AvailableLabel.Visible  = true;
                Available.Visible       = true;
                if (!int.TryParse(Request.QueryString["ID"], out bookCopyId))
                {
                    Response.Redirect(BookCopyList);
                }
                if (!IsPostBack)
                {
                    DataTable dt = DatabaseHelper.Retrieve(@"
                    select Book.Id as BookId, BookCopy.LibraryId  as LibraryId, Out, Available
                    from BookCopy join Book on (BookCopy.BookId = Book.Id)
                    where BookCopy.Id = @BookCopyId
                ", new SqlParameter("@BookCopyId", bookCopyId));

                    if (dt.Rows.Count == 1)
                    {
                        int  selectedBookId    = dt.Rows[0].Field <int>("BookId");
                        int  selectedLibraryId = dt.Rows[0].Field <int>("LibraryId");
                        bool selectedOut       = dt.Rows[0].Field <bool>("Out");
                        bool selectedAvailable = dt.Rows[0].Field <bool>("Available");
                        Books.SelectedValue     = selectedBookId.ToString();
                        Libraries.SelectedValue = selectedLibraryId.ToString();
                        CheckedOut.Checked      = selectedOut;
                        Available.Checked       = selectedAvailable;
                    }
                    else
                    {
                        Response.Redirect(BookCopyList);
                    }
                }
            }
            else
            {
                AddOrEdit.Text = "Add Book Copy";
            }
            if (!IsPostBack)
            {
                DataTable dt = DatabaseHelper.Retrieve(@"
                    select Book.Id as BookId, Title + '    By: ' + FirstName + ' ' + LastName as BookName
                    from Book join Author on Book.AuthorId = Author.Id
                ");

                Books.DataValueField       = "BookId";
                Books.DataTextField        = "BookName";
                Books.AppendDataBoundItems = true;
                Books.Items.Add(new ListItem("Select Value...", string.Empty));
                Books.DataSource = dt;
                Books.DataBind();


                DataTable dt2 = DatabaseHelper.Retrieve(@"
                    select BranchName, Id
                    from Library
                ");

                Libraries.DataValueField = "Id";
                Libraries.DataTextField  = "BranchName";

                Libraries.AppendDataBoundItems = true;
                Libraries.Items.Add(new ListItem("Select Value...", string.Empty));
                Libraries.DataSource = dt2;
                Libraries.DataBind();
            }
        }
Beispiel #24
0
        private void Lending_Load(object sender, EventArgs e)
        {
            string commString = "SELECT * FROM BooksInfo;";
            SqlCommand comm = new SqlCommand(commString, SQLConnection.Connection);
            comm.Connection.Open();
            SqlDataReader listreader = comm.ExecuteReader();
            while (listreader.Read())
            {
                Books b = new Books();

                b.ISBN = listreader.GetInt32(0);
                b.BookName = listreader.GetString(1);
                b.Author = listreader.GetString(2);
                b.PublishedYear = listreader.GetInt32(3);

                listBName.Items.Add(b);
            }
            SQLConnection.Connection.Close();

            dtDueDate.MinDate = DateTime.Now;
            dtDueDate.MaxDate = DateTime.Now.AddDays(31);
        }
 public void Post([FromBody] Books value)
 {
     Book.Add(value);
 }
Beispiel #26
0
        public async Task <IActionResult> Import(IFormFile fileExcel)
        {
            if (ModelState.IsValid)
            {
                if (fileExcel != null)
                {
                    using (var stream = new FileStream(fileExcel.FileName, FileMode.Create))
                        if (Path.GetExtension(stream.Name) == ".xlsx" || Path.GetExtension(stream.Name) == ".xls")
                        {
                            await fileExcel.CopyToAsync(stream);

                            using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled))
                            {
                                foreach (IXLWorksheet worksheet in workBook.Worksheets)
                                {
                                    //worksheet.Name - назва категорії. Пробуємо знайти в БД, якщо відсутня, то створюємо нову
                                    Categories newcat;
                                    var        c = (from cat in _context.Categories
                                                    where cat.CategoryName.Contains(worksheet.Name)
                                                    select cat).ToList();
                                    if (c.Count > 0)
                                    {
                                        newcat = c[0];
                                    }
                                    else
                                    {
                                        newcat = new Categories();
                                        newcat.CategoryName = worksheet.Name;
                                        _context.Categories.Add(newcat);
                                    }
                                    //перегляд усіх рядків
                                    foreach (IXLRow row in worksheet.RowsUsed().Skip(1))
                                    {
                                        try
                                        {
                                            Books book = new Books();
                                            book.Name = row.Cell("1").Value.ToString();
                                            if (Int16.Parse(row.Cell("2").Value.ToString()) < 1 || Int16.Parse(row.Cell("2").Value.ToString()) > 25000)
                                            {
                                                throw new Exception();
                                            }
                                            book.NumberOfPages = Int16.Parse(row.Cell("2").Value.ToString());

                                            if (Int16.Parse(row.Cell("3").Value.ToString()) < 1300 || Int16.Parse(row.Cell("3").Value.ToString()) > 2020)
                                            {
                                                throw new Exception();
                                            }

                                            book.YearOfPublication = Int16.Parse(row.Cell("3").Value.ToString());
                                            BookCategory bookCategory = new BookCategory();
                                            bookCategory.Category = newcat;
                                            bookCategory.Book     = book;
                                            _context.Books.Add(book);
                                            _context.BookCategory.Add(bookCategory);
                                            for (int i = 4; i <= 6; i++)
                                            {
                                                /* if(!Regex.IsMatch(row.Cell(i).Value.ToString(), @"^([A-Z][a-z]+)\ ([A-Z][a-z]+)(\ ?([A-Z][a-z]+)?)|([А-ЯІЇЄЩ][а-яіїщє]+)\ ([А-ЯІЇЄЩ][а-яіїщє]+)(\ ?([А-ЯІЇЄЩ][а-яіїщє]+)?)$")) {
                                                 *   throw new Exception();
                                                 * }                     */
                                                if (row.Cell(i).Value.ToString().Length > 0)
                                                {
                                                    Authors author;
                                                    var     a = (from aut in _context.Authors
                                                                 where aut.FullName.Contains(row.Cell(i).Value.ToString())
                                                                 select aut).ToList();
                                                    if (a.Count > 0)
                                                    {
                                                        author = a[0];
                                                    }
                                                    else
                                                    {
                                                        author          = new Authors();
                                                        author.FullName = row.Cell(i).Value.ToString();
                                                        _context.Add(author);
                                                    }
                                                    Authorship ab = new Authorship();
                                                    ab.Book   = book;
                                                    ab.Author = author;
                                                    _context.Authorship.Add(ab);
                                                }
                                            }
                                        }

                                        catch (Exception e)
                                        {
                                            TempData["msgDATA"] = "<script>alert('Некоректний зміст файлу');</script>";
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            TempData["msgDATA"] = "<script>alert('Некоректний формат файлу');</script>";
                        }
                }

                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
        public void Delete(string isbn13)
        {
            Books book = Get(isbn13);

            Book.Remove(book);
        }
        private void grdmain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left)
            {
                //check # of chapters in book
                //if last chapter get next book
                //back one chapter

                var prevChapter = (CurrentVerseSelection.curr.chapter - 1);
                if (prevChapter >= 1)
                {
                    GoTo(CurrentVerseSelection.curr.book, prevChapter, 1);
                }
                else
                {
                    var bookIndex = Books.FindIndex(x => x.abbrev == CurrentVerseSelection.curr.book) - 1;
                    if (bookIndex >= 0)
                    {
                        var prevBook = Books[bookIndex];
                        GoTo(prevBook.abbrev, 1, 1);
                    }
                }
            }
            if (e.Key == Key.Right)
            {
                var nextChapter = (CurrentVerseSelection.curr.chapter + 1);
                if (nextChapter <= Chapters.Count())
                {
                    GoTo(CurrentVerseSelection.curr.book, nextChapter, 1);
                }
                else
                {
                    var bookIndex = Books.FindIndex(x => x.abbrev == CurrentVerseSelection.curr.book) + 1;
                    if (bookIndex <= Books.Count())
                    {
                        var nextBook = Books[bookIndex];
                        GoTo(nextBook.abbrev, 1, 1);
                    }
                }
            }
            if (e.Key == Key.Up)
            {
                // back one verse
                if (CurrentVerseSelection.prev == null)
                {
                    return;
                }
                GoTo(CurrentVerseSelection.curr.book, CurrentVerseSelection.curr.chapter, CurrentVerseSelection.prev.verse);
                SelectedChapter = CurrentVerseSelection.curr.chapter;
                SelectedVerse   = CurrentVerseSelection.curr.verse;
            }
            if (e.Key == Key.Down)
            {
                if (CurrentVerseSelection.next == null)
                {
                    return;
                }
                GoTo(CurrentVerseSelection.curr.book, CurrentVerseSelection.curr.chapter, CurrentVerseSelection.next.verse);

                SelectedChapter = CurrentVerseSelection.curr.chapter;
                SelectedVerse   = CurrentVerseSelection.curr.verse;
            }
        }
Beispiel #29
0
 public AddQuantity(Books k)
 {
     InitializeComponent();
     cb1.ItemsSource = bs.Provider.Select(x => x.NameCompany).ToList();
     MZ = k;
 }
Beispiel #30
0
 partial void UpdateBooks(Books instance);
Beispiel #31
0
        public IActionResult AddBook(Books book)
        {
            var result = bookContext.addBook(book);

            return(Ok(result));
        }
        static void Main(string[] args)
        {
            // int noBooks =1000;(total Books)
            int noBooks = 3;

            Books[] book    = new Books[noBooks];
            int     booksIn = 0;

            // ADD DATA FOR  BOOK

            /* for (int i = 0; i < noBooks; i++)
             * {
             *   Console.WriteLine("Enter data for book {0}", booksIn + 1);
             *   Console.Write("Enter the name of the book :");
             *   book[booksIn].Title = Console.ReadLine();
             *   Console.Write("Enter the author of the book :");
             *   book[booksIn].Author = Console.ReadLine();
             *   booksIn++;
             *  Console.WriteLine();
             * }*/


            //Display all the books

            /*for (int i = 0; i < booksIn ; i++)
             * {
             *   Console.WriteLine("{0}: Title = {1},Author = {2}", i+1 , book[i].Title, book[i].Author);
             *   Console.WriteLine();
             *
             * }*/
            //Adding data for 1 book
            if (booksIn < noBooks)
            {
                for (int i = booksIn; i < noBooks; i++)
                {
                    Console.WriteLine("Enter data for book {0}", booksIn + 1);
                    Console.WriteLine(booksIn);
                    Console.Write("Enter the name of the book :  ");
                    book[booksIn].Title = Console.ReadLine();
                    Console.Write("Enter the author of the book :  ");
                    book[booksIn].Author = Console.ReadLine();
                    booksIn++;
                    Console.WriteLine(booksIn);
                    Console.WriteLine(i);
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Sorry ! No space to enter more books");
                //break;
            }
            if (booksIn == 0)
            {
                Console.WriteLine("No books to be added");
            }
            else
            {
                for (int i = 0; i < booksIn; i++)
                {
                    Console.WriteLine("{0} : Title = {1}, Author = {2}", i + 1, book[i].Title, book[i].Author);

                    Console.WriteLine();
                }
            }
            //Search for book with a given title
            Console.WriteLine("Enter the name of the book to be searched : ");

            String findBook = Console.ReadLine();

            //Console.WriteLine("findBook" + findBook);

            Boolean found = false;

            Console.WriteLine("booksIn" + booksIn);

            for (int i = 1; i < booksIn; i++)
            {
                Console.WriteLine("book[i].Title" + book[i].Title);

                if (book[i].Title == findBook)
                {
                    Console.WriteLine("Book {0} found .", book[i].Title);

                    found = true;
                    break;
                }
                if (!found)
                {
                    Console.WriteLine("Sorry the book {0} is not found .", findBook);
                    Console.WriteLine();
                    break;
                }
            }
            //Delete a Book according to number

            if (booksIn == 0)
            {
                Console.WriteLine("No books to delete");
            }
            else
            {
                Console.WriteLine("Enter the book number to be deleted from 1 to {0}", booksIn);

                int numDelete = Convert.ToInt32(Console.ReadLine()) - 1;

                // Console.WriteLine("numDelete" + numDelete);

                // Console.WriteLine("booksIn " + booksIn);

                for (int i = numDelete; i < booksIn - 1; i++)

                {
                    Console.WriteLine("Delete book : " + book[i].Title);

                    book[i] = book[i + 1];
                    // Console.WriteLine("Delete book   : " + book[i].Title);
                    booksIn--;

                    //Console.WriteLine("Deleted book");
                }
            }


            Console.ReadLine();
        }
Beispiel #33
0
 public void Add(IEnumerable <Book> books)
 {
     Books.AddRange(books);
 }
 public ActionResult CreateBook([FromBody] Books book)
 {
     _bookService.CreateBook(book);
     return(Json(book));
 }
Beispiel #35
0
 public ActionResult Insert(Books book)
 {
     if (ModelState.IsValid)
     {
         try {
             _repository.Add(book);
         }
         catch(Exception) {
             return RedirectToAction("Index", new { alertMsg = "Erro: Não foi possível Incluir o Registro", alertType = "error" });
         }
         return RedirectToAction("Index", new { alertMsg = "Incluído", alertType = "success" });
     }
     return View(book);
 }
Beispiel #36
0
 public virtual IQueryable <Book> BooksInInventory()
 {
     return(Books.Where(b => b.IsInInventory == true));
 }
Beispiel #37
0
 private void deleteBookMediaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Really delete?", "Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
       {
     try
     {
       _selectedBook = new Books(MC.GetBook((lsv_AllBooksMedia.SelectedItems[0] as BooksListViewItem).BooksID));
       MC.BookDelete(_selectedBook.BooksID);
     }
     catch (Exception)
     {
       // somethign went wrong
     }
       }
 }
Beispiel #38
0
 internal void LaunchBookDialog(Books b)
 {
     BookForm bf = new BookForm(b);
       if (bf.ShowDialog() == DialogResult.OK)
       {
     //Update Patrons View
     RefreshPatrons();
       }
 }
Beispiel #39
0
        // Get entities of the books.
        private void LoadBooks()
        {
            _books = new Books();
            _localPath = Directory.GetCurrentDirectory();
            _localEntityPath = _localPath + "/Datas";
            _localImagePath = _localPath + "/Datas/Images/";
            DirectoryInfo info = new DirectoryInfo(_localEntityPath);

            // Check Dir info.
            if (!info.Exists)
            {
                info.Create();
            }

            String entityPath = info.FullName + "/books.xml";

            // If the entity file exist, get entity from xml file.
            if (File.Exists(entityPath))
            {
                using (FileStream stream = File.Open(entityPath, FileMode.Open))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Books));
                    _books = serializer.Deserialize(stream) as Books;
                }
            }
            else
            {
                _books = new Books();
                _books.Add(new Book
                {
                    Title = "<New Book>",
                    ISBN = "0-000-00000-0"
                });
            }

            // Set correct image path for each book.
            foreach (Book book in _books)
            {
                if (!String.IsNullOrEmpty(book.Image))
                {
                    book.Image = book.Image.Replace("$(Booklist)", _localImagePath);
                }
            }
        }
Beispiel #40
0
        public static void What(string choose1, string choose2, string type)
        {
            //結構陣列
            Books[] book = new Books[] {
                //科技0~2
                new Books(){ISBN="9789863206927",Name="10種物質改變世界",Author="米奧多尼克",Publisher="天下文化",Type="科技",Price="300"},
                new Books(){ISBN="9789869181945",Name="趨勢未來新策略",Author="歐崇敬",Publisher="秀威經典",Type="科技",Price="340"},
                new Books(){ISBN="9789570528343",Name="科學大家談",Author="張之傑",Publisher="臺灣商務",Type="科技",Price="250"},
                //小說3~5
                new Books(){ISBN="9789865706654",Name="白雪公主:惡童書",Author="笭菁",Publisher="春天",Type="小說",Price="240"},
                new Books(){ISBN="9789865706807",Name="鬼都",Author="笭菁",Publisher="春天",Type="小說",Price="160"},
                new Books(){ISBN="9789861439396",Name="河神的媳婦",Author="梓意",Publisher="邀月文化",Type="小說",Price="200"},
                //商管6~8
                new Books(){ISBN="9789867330666", Name="如何打造企業贏利模式",Author= "劉文智",Publisher= "憲業企管", Type="商管", Price="360"},
                new Books(){ISBN="9789867622570", Name="從管理中創造利潤", Author="孫曉東", Publisher="讀品", Type="商管", Price="280"},
                new Books(){ISBN="9789867600660", Name="IT有什麼明天?",Author= "尼可拉斯.卡爾", Publisher="杜默", Type="商管", Price="250"},
                //歷史10~12
                new Books(){ISBN="9789861204819", Name="神話與意義",Author= "李維史陀", Publisher="麥田", Type="歷史", Price="220"},
                new Books(){ISBN="9789570843590", Name="文明的故事",Author= "潘蜜拉.托勒", Publisher="讀品", Type="歷史",Price= "280"},
                new Books(){ISBN="9789862751879", Name="世界文化遺產",Author= "席梅爾", Publisher="明天國際", Type="歷史", Price="690"},
                //文學13~15
                new Books(){ISBN="9789861894041", Name="走路去巴黎", Author="克雷恩,索爾巴斯", Publisher="格林", Type="文學", Price="399"},
                new Books(){ISBN="9789578246430",Name= "失落的一角",Author= "謝爾.希爾弗斯坦",Publisher= "玉山社", Type="文學", Price="280"},
                new Books(){ISBN="9789861895345",Name= "界線",Author= "許育榮", Publisher="格林",Type= "文學", Price="280"},
                //其他16~18
                new Books(){ISBN="9789861850696", Name="魔術方塊破解密笈",Author= "陸嘉宏", Publisher="高寶", Type="其他", Price="149"},
                new Books(){ISBN="9789860010749", Name="街頭美學:設施公共藝術", Author="林熹俊", Publisher="典藏", Type="其他",Price= "220"},
                new Books(){ISBN="9789864340057", Name="Python程式設計入門",Author= "葉難",Publisher= "博碩文化", Type="其他", Price="620"}
            };
            string tmp_ReChoice = "";
            if (type == "0")
            {
            switch (choose1)
            {
                case "1"://ISBN
                    for (int i = 0; i < 18; i++)
                    {
                        tmp_ReChoice += "(" + i + ") " + book[i].ISBN + "\n";
                    };
                    Console.WriteLine(tmp_ReChoice);
                    break;
                case "2"://Name
                    for (int i = 0; i < 18; i++)
                    {
                        tmp_ReChoice += "(" + i + ") " + book[i].Name + "\n";
                    };
                    Console.WriteLine(tmp_ReChoice);
                    break;
                case "3"://Author
                    int countA = 0;
                    for (int i = 0; i < 18; i++)
                    {
                        string tf = "t";//初始t,代表沒有重複
                        if (i > 0)//從第二項後開始判斷
                        {
                            for (int j = i + 1; j < 18; j++)
                            {
                                if (book[i].Author == book[j].Author)//判斷後面有沒有重複
                                    tf = "f";//有則改為f
                            };
                        };
                        if (tf == "t")
                        {
                            tmp_ReChoice += "(" + countA + ") " + book[i].Author + "\n";
                            countA++;
                        }

                    };
                    Console.WriteLine(tmp_ReChoice);
                    break;
                case "4"://Publisher
                    int count = 0;
                    for (int i = 0; i < 18; i++)
                    {
                        string tf = "t";//初始t,代表沒有重複
                        if (i > 0)//從第二項後開始判斷
                        {
                            for (int j = i + 1; j < 18; j++)
                            {
                                if (book[i].Publisher == book[j].Publisher)//判斷後面有沒有重複
                                    tf = "f";//有則改為f
                            };
                        };
                        if (tf == "t")
                        {
                            tmp_ReChoice += "(" + count + ") " + book[i].Publisher + "\n";
                            count++;
                        }
                    }
                    Console.WriteLine(tmp_ReChoice);
                    break;
                case "5"://Type
                    tmp_ReChoice += "(0) " + book[0].Type + " (1) " + book[3].Type + " (2) " + book[6].Type + " (3) " + book[9].Type + " (4) " + book[12].Type + " (5) " + book[15].Type;
                    Console.WriteLine(tmp_ReChoice);
                    break;
                case "6"://Price
                    int countP = 0;
                    for (int i = 0; i < 18; i++)
                    {
                        string tf = "t";//初始t,代表沒有重複
                        if (i > 0)//從第二項後開始判斷
                        {
                            for (int j = i + 1; j < 18; j++)
                            {
                                if (book[i].Price == book[j].Price)//判斷後面有沒有重複
                                    tf = "f";//有則改為f
                            };
                        };
                        if (tf == "t")
                        {
                            tmp_ReChoice += "(" + countP + ") " + book[i].Price + "\n";
                            countP++;
                        }
                    } Console.WriteLine(tmp_ReChoice);
                    break;
            }
            }//type=0
            if (type == "1")
            {
            int tmp = Int32.Parse(choose2);//轉數字
            switch (choose1)
            {
                case "1"://ISBN
                    Console.WriteLine("\nISBN:" + book[tmp].ISBN + "\n書名:" + book[tmp].Name + "\n作者:" + book[tmp].Author + "\n出版社:" + book[tmp].Publisher + "\n類型:" + book[tmp].Type + "\n價格:" + book[tmp].Price);
                    break;
                case "2"://Name
                   Console.WriteLine("\nISBN:" + book[tmp].ISBN + "\n書名:" + book[tmp].Name + "\n作者:" + book[tmp].Author + "\n出版社:" + book[tmp].Publisher + "\n類型:" + book[tmp].Type + "\n價格:" + book[tmp].Price);
                    break;
                case "3"://Author
                    int countA = 0;
                    int countAA=0;
                    string tmpA = "";
                    for (int i = 0; i < 18; i++)
                    {
                        string tf = "t";//初始t,代表沒有重複
                        if(tmp==0 && i==0)
                            Console.WriteLine("\nISBN:" + book[i].ISBN + "\n書名:" + book[i].Name + "\n作者:" + book[i].Author + "\n出版社:" + book[i].Publisher + "\n類型:" + book[i].Type + "\n價格:" + book[i].Price);
                        if (i > 0)//從第二項後開始判斷
                        {
                            for (int j = i + 1; j < 18; j++)
                            {
                                if (book[i].Author == book[j].Author)//判斷後面有沒有重複
                                    tf = "f";//有則改為f
                            };
                            if (tf == "t")
                            {
                                countA++;
                                if (countA == tmp)
                                    tmpA = book[countAA].Author;
                            }
                        };
                        countAA++;
                    };
                    for (int k = 0; k < 18; k++) {
                        if (tmpA == book[k].Author) {
                            Console.WriteLine("\nISBN:" + book[k].ISBN + "\n書名:" + book[k].Name + "\n作者:" + book[k].Author + "\n出版社:" + book[k].Publisher + "\n類型:" + book[k].Type + "\n價格:" + book[k].Price);
                        }
                    }
                    break;
                case "4"://Publisher
                   int countP = 0;
                    int countPP=0;
                    string tmpP = "";
                    for (int i = 0; i < 18; i++)
                    {
                        string tf = "t";//初始t,代表沒有重複
                        if(tmp==0 && i==0)
                            Console.WriteLine("\nISBN:" + book[i].ISBN + "\n書名:" + book[i].Name + "\n作者:" + book[i].Author + "\n出版社:" + book[i].Publisher + "\n類型:" + book[i].Type + "\n價格:" + book[i].Price);
                        if (i > 0)//從第二項後開始判斷
                        {
                            for (int j = i + 1; j < 18; j++)
                            {
                                if (book[i].Publisher == book[j].Publisher)//判斷後面有沒有重複
                                    tf = "f";//有則改為f
                            };
                            if (tf == "t")
                            {
                                countP++;
                                if (countP == tmp)
                                    tmpP = book[countPP].Publisher;
                            }
                        };
                        countPP++;
                    };
                    for (int k = 0; k < 18; k++) {
                        if (tmpP == book[k].Publisher) {
                            Console.WriteLine("\nISBN:" + book[k].ISBN + "\n書名:" + book[k].Name + "\n作者:" + book[k].Author + "\n出版社:" + book[k].Publisher + "\n類型:" + book[k].Type + "\n價格:" + book[k].Price);
                        }
                    }
                    break;
                case "5"://Type
                    if (tmp == 0){
                    Console.WriteLine("\nISBN:" + book[0].ISBN + "\n書名:" + book[0].Name + "\n作者:" + book[0].Author + "\n出版社:" + book[0].Publisher + "\n類型:" + book[0].Type + "\n價格:" + book[0].Price);
                    Console.WriteLine("\nISBN:" + book[1].ISBN + "\n書名:" + book[1].Name + "\n作者:" + book[1].Author + "\n出版社:" + book[1].Publisher + "\n類型:" + book[1].Type + "\n價格:" + book[1].Price);
                    Console.WriteLine("\nISBN:" + book[2].ISBN + "\n書名:" + book[2].Name + "\n作者:" + book[2].Author + "\n出版社:" + book[2].Publisher + "\n類型:" + book[2].Type + "\n價格:" + book[2].Price);
                    }
                    if (tmp == 1)
                    {
                        Console.WriteLine("\nISBN:" + book[3].ISBN + "\n書名:" + book[3].Name + "\n作者:" + book[3].Author + "\n出版社:" + book[3].Publisher + "\n類型:" + book[3].Type + "\n價格:" + book[3].Price);
                        Console.WriteLine("\nISBN:" + book[4].ISBN + "\n書名:" + book[4].Name + "\n作者:" + book[4].Author + "\n出版社:" + book[4].Publisher + "\n類型:" + book[4].Type + "\n價格:" + book[4].Price);
                        Console.WriteLine("\nISBN:" + book[5].ISBN + "\n書名:" + book[5].Name + "\n作者:" + book[5].Author + "\n出版社:" + book[5].Publisher + "\n類型:" + book[5].Type + "\n價格:" + book[5].Price);
                    }
                    if (tmp == 2)
                    {
                        Console.WriteLine("\nISBN:" + book[6].ISBN + "\n書名:" + book[6].Name + "\n作者:" + book[6].Author + "\n出版社:" + book[6].Publisher + "\n類型:" + book[6].Type + "\n價格:" + book[0].Price);
                        Console.WriteLine("\nISBN:" + book[7].ISBN + "\n書名:" + book[7].Name + "\n作者:" + book[7].Author + "\n出版社:" + book[7].Publisher + "\n類型:" + book[7].Type + "\n價格:" + book[1].Price);
                        Console.WriteLine("\nISBN:" + book[8].ISBN + "\n書名:" + book[8].Name + "\n作者:" + book[8].Author + "\n出版社:" + book[8].Publisher + "\n類型:" + book[8].Type + "\n價格:" + book[2].Price);
                    }
                    if (tmp == 3)
                    {
                        Console.WriteLine("\nISBN:" + book[9].ISBN + "\n書名:" + book[9].Name + "\n作者:" + book[9].Author + "\n出版社:" + book[9].Publisher + "\n類型:" + book[9].Type + "\n價格:" + book[9].Price);
                        Console.WriteLine("\nISBN:" + book[10].ISBN + "\n書名:" + book[10].Name + "\n作者:" + book[10].Author + "\n出版社:" + book[10].Publisher + "\n類型:" + book[10].Type + "\n價格:" + book[10].Price);
                        Console.WriteLine("\nISBN:" + book[11].ISBN + "\n書名:" + book[11].Name + "\n作者:" + book[11].Author + "\n出版社:" + book[11].Publisher + "\n類型:" + book[11].Type + "\n價格:" + book[11].Price);
                    }
                    if (tmp == 4)
                    {
                        Console.WriteLine("\nISBN:" + book[12].ISBN + "\n書名:" + book[12].Name + "\n作者:" + book[12].Author + "\n出版社:" + book[12].Publisher + "\n類型:" + book[12].Type + "\n價格:" + book[12].Price);
                        Console.WriteLine("\nISBN:" + book[13].ISBN + "\n書名:" + book[13].Name + "\n作者:" + book[13].Author + "\n出版社:" + book[13].Publisher + "\n類型:" + book[13].Type + "\n價格:" + book[13].Price);
                        Console.WriteLine("\nISBN:" + book[14].ISBN + "\n書名:" + book[14].Name + "\n作者:" + book[14].Author + "\n出版社:" + book[14].Publisher + "\n類型:" + book[14].Type + "\n價格:" + book[14].Price);
                    }
                    if (tmp == 5)
                    {
                        Console.WriteLine("\nISBN:" + book[15].ISBN + "\n書名:" + book[15].Name + "\n作者:" + book[15].Author + "\n出版社:" + book[15].Publisher + "\n類型:" + book[15].Type + "\n價格:" + book[15].Price);
                        Console.WriteLine("\nISBN:" + book[16].ISBN + "\n書名:" + book[16].Name + "\n作者:" + book[16].Author + "\n出版社:" + book[16].Publisher + "\n類型:" + book[16].Type + "\n價格:" + book[16].Price);
                        Console.WriteLine("\nISBN:" + book[17].ISBN + "\n書名:" + book[17].Name + "\n作者:" + book[17].Author + "\n出版社:" + book[17].Publisher + "\n類型:" + book[17].Type + "\n價格:" + book[17].Price);
                    }
                    break;
                case "6"://Price
                    int cP = 0;
                    int cPP=0;
                    string tpP = "";
                    for (int i = 0; i < 18; i++)
                    {
                        string tf = "t";//初始t,代表沒有重複
                        if(tmp==0 && i==0)
                            Console.WriteLine("\nISBN:" + book[i].ISBN + "\n書名:" + book[i].Name + "\n作者:" + book[i].Author + "\n出版社:" + book[i].Publisher + "\n類型:" + book[i].Type + "\n價格:" + book[i].Price);
                        if (i > 0)//從第二項後開始判斷
                        {
                            for (int j = i + 1; j < 18; j++)
                            {
                                if (book[i].Price == book[j].Price)//判斷後面有沒有重複
                                    tf = "f";//有則改為f
                            };
                            if (tf == "t")
                            {
                                cP++;
                                if (cP == tmp)
                                    tpP = book[cPP].Price;
                            }
                        };
                        cPP++;
                    };
                    for (int k = 0; k < 18; k++) {
                        if (tpP == book[k].Price) {
                            Console.WriteLine("\nISBN:" + book[k].ISBN + "\n書名:" + book[k].Name + "\n作者:" + book[k].Author + "\n出版社:" + book[k].Publisher + "\n類型:" + book[k].Type + "\n價格:" + book[k].Price);
                        }
                    }
                    break;
            }
            }//type=0
        }
 public void CreateBook([FromBody] Books book)
 {
     book.b_id = journal.Books.Count() + 1;
     journal.Books.Add(book);
     journal.SaveChanges();
 }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                string komut = "SELECT * FROM BooksInfo Where bookISBN = @ID;";
                SqlCommand kom = new SqlCommand(komut, SQLConnection.Connection);
                kom.Parameters.AddWithValue("@ID", srchBook.Text);
                kom.Connection.Open();
                SqlDataReader re = kom.ExecuteReader();
                if (srchBook.Text == "")
                {
                    shwBook.Text = "The book could not be found.";
                }
                else
                {
                    while (re.Read())
                    {

                        Books b = new Books();
                        shwBook.Text = re.GetString(2);
                    }

                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally { SQLConnection.Connection.Close(); }
        }
 public void AddBook(Book book)
 {
     Books.Add(book);
 }
Beispiel #44
0
        public async Task <IActionResult> Import(IFormFile fileExcel)
        {
            if (ModelState.IsValid)
            {
                if (fileExcel != null)
                {
                    using (var stream = new FileStream(fileExcel.FileName, FileMode.Create))
                    {
                        await fileExcel.CopyToAsync(stream);

                        using (XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled))
                        {
                            var lang = _context.BookGenres.Include(b => b.Book).Include(b => b.Book.Language).ToList();
                            //перегляд усіх листів (в даному випадку категорій)
                            foreach (IXLWorksheet worksheet in workBook.Worksheets)
                            {
                                //worksheet.Name - назва категорії. Пробуємо знайти в БД, якщо відсутня, то створюємо нову
                                Genres newgen;
                                var    c = (from gen in _context.Genres
                                            where gen.Name.Contains(worksheet.Name)
                                            select gen).ToList();
                                if (c.Count > 0)
                                {
                                    newgen = c[0];
                                }
                                else
                                {
                                    newgen      = new Genres();
                                    newgen.Name = worksheet.Name;
                                    _context.Genres.Add(newgen);
                                }
                                //перегляд усіх рядків
                                foreach (IXLRow row in worksheet.RowsUsed().Skip(1))
                                {
                                    Books book    = new Books();
                                    int   counter = 0;
                                    foreach (var bo in _context.Books)
                                    {
                                        if (bo.Name == row.Cell(1).Value.ToString())
                                        {
                                            counter++; book = bo; break;
                                        }
                                    }
                                    if (counter > 0)
                                    {
                                        int count = 0;
                                        foreach (var gen in _context.BookGenres)
                                        {
                                            if ((book.Id == gen.BookId) && (newgen.Id == gen.GenreId))
                                            {
                                                count++; break;
                                            }
                                        }
                                        if (count > 0)
                                        {
                                            goto link1;// якщо такий книжко-жанр вже існує, переходимо до наступного рядка
                                        }
                                        else
                                        {
                                            BookGenres bookg = new BookGenres();
                                            bookg.Book  = book;
                                            bookg.Genre = newgen;
                                            _context.BookGenres.Add(bookg);
                                            goto link1;// переходимо до наступного рядка, бо вже маємо інформацію про цю книжку
                                        }
                                    }
                                    else
                                    {
                                        book      = new Books();
                                        book.Name = row.Cell(1).Value.ToString();
                                        _context.Books.Add(book);
                                    }

                                    book.PagesNum = Convert.ToInt32(row.Cell(3).Value);

                                    Language newlang; int?Lid = 1;
                                    counter = 0;
                                    foreach (var la in _context.Language)
                                    {
                                        if (la.Lname == row.Cell(2).Value.ToString())
                                        {
                                            counter++; Lid = la.Id; break;
                                        }
                                    }
                                    if (counter > 0)
                                    {
                                        book.LanguageId = Lid;
                                    }
                                    else
                                    {
                                        newlang       = new Language();
                                        newlang.Lname = row.Cell(2).Value.ToString();
                                        _context.Language.Add(newlang);
                                        book.LanguageId = newlang.Id;
                                    }

                                    BookGenres bg = new BookGenres();
                                    bg.Book  = book;
                                    bg.Genre = newgen;
                                    _context.BookGenres.Add(bg);

                                    int i = 4;
                                    while (row.Cell(i).Value.ToString().Length > 0)
                                    {
                                        BookAuthors ba = new BookAuthors();
                                        Authors     author; Authors auth = new Authors();
                                        counter = 0;
                                        foreach (var au in _context.Authors)
                                        {
                                            if (au.AuthorName == row.Cell(i).Value.ToString())
                                            {
                                                counter++; auth = au; break;
                                            }
                                        }

                                        if (counter > 0)
                                        {
                                            ba.Author = auth;
                                        }
                                        else
                                        {
                                            author            = new Authors();
                                            author.AuthorName = row.Cell(i).Value.ToString();
                                            ba.Author         = author;
                                            _context.Add(author);
                                        }
                                        ba.Book = book;
                                        _context.BookAuthors.Add(ba);
                                        i++;
                                    }

                                    link1 :;
                                    await _context.SaveChangesAsync();
                                }
                            }
                        }
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #45
0
        /// <summary> REVIEW
        /// This is where I would need to call my loops to read the book information from the text file so that it loads as the form is loaded.
        /// </summary>
        public Main_Menu()
        {
            InitializeComponent();

            updateCustomers(); //Populate the Customer Combo Box Upon Form startup

            DataGridSetup();
            quantityUserInputTextBox.Text = "1";

            //Preset the subtotal, tax, and total boxes
            subtotalTextBox.Text = subTotal.ToString("C");
            taxTextBox.Text      = tax.ToString("C");
            totalTextBox.Text    = totalPrice.ToString("C");


            //Testing FileStream Write capabilities
            //FileStream test = new FileStream("testtext.txt", FileMode.Create, FileAccess.Write);
            //StreamWriter testWriter = new StreamWriter(test);
            //string text = "test";
            //testWriter.WriteLine(text);
            //testWriter.Close();
            //test.Close();

            var dbCon = DBConnection.Instance();

            dbCon.DatabaseName = "bookstore";


            if (dbCon.IsConnect())
            {
                string query = "SELECT * FROM books";
                var    cmd   = new MySqlCommand(query, dbCon.Connection);



                var reader = cmd.ExecuteReader();
                //Go through the query to grab the books and insert them into our own book objects
                while (reader.Read())
                {
                    string bookTitle  = reader.GetString(0);
                    string bookAuthor = reader.GetString(1);
                    string bookISBN   = reader.GetString(2);
                    string bookPrice  = reader.GetString(3);
                    //Only used for visual representation of successful database connection
                    Console.WriteLine($"{bookTitle} {bookAuthor} {bookISBN} {bookPrice}\n");

                    //Procedurally add our retrieved book information
                    Books bk = new Books();
                    bk.Title  = bookTitle;
                    bk.Author = bookAuthor;
                    bk.ISBN   = bookISBN;
                    bk.Price  = bookPrice;

                    myArrayList.Add(bk);
                }

                //Simple check to see if we successfully retreived our book information prior to sending it to our form
                if (myArrayList.Count > 0)
                {
                    foreach (Books bk_data in myArrayList)
                    {
                        bookSelectComboBox.Items.Add(bk_data.Title);
                    }
                }
                else
                {
                    Console.WriteLine($"Could not retrieve book information from database.");
                }


                dbCon.Close();
            }
            else
            {
                Console.WriteLine("Database Connection Error.");
            }

            customerSelectComboBox.Focus();
        }
Beispiel #46
0
        private static void ProcessBook(Int32 size)
        {
            String str = String.Intern(ASCII.GetString(s_bookBuff, 0, size));
            Int32 i;

            if (s_curBook != Books.None
                && s_books[(Int32) s_curBook] == str)
            {
                if (s_bookPost) throw new Exception("There was verse data after post data.");
                // NO-OP
                return;
            }
            s_bookPost = false;

            for (i = 0; i < s_books.Length; ++i)
            {
                if (s_books[i] == str)
                {
                    var newBook = (Books) i;
                    if (newBook == s_curBook) return;
                    s_curBook = newBook;
                    str = newBook.ToString();
                    var buff = new Byte[32];
                    Int32 len = ASCII.GetBytes(str, 0, str.Length, buff, 0);
                    if (newBook != Books.Genesis)
                        WriteEOL();
                    s_out.WriteByte(66);
                    s_out.WriteByte(58);
                    for (Int32 j = 0; j < len; ++j)
                        s_out.WriteByte(buff[j]);
                    s_bookCount++;
                    return;
                }
            }

            throw new Exception("Book not found: " + str);
        }
Beispiel #47
0
        public async Task GetBookInCartForBorrow_Test()
        {
            var bookCart = new BookCarts
            {
                Id           = 1,
                UserId       = 1,
                BookId       = 1,
                Status       = (int)BookStatus.InOrder,
                ModifiedDate = DateTime.Now
            };

            _dbContext.Set <BookCarts>().Add(bookCart);

            var book = new Books
            {
                Id                = 1,
                BookName          = "Book",
                BookCode          = "ABC",
                LibraryId         = 1,
                CategoryId        = 1,
                SupplierId        = 1,
                PublisherId       = 1,
                Author            = "Author",
                AmountAvailable   = 10,
                Amount            = 20,
                Enabled           = true,
                MaximumDateBorrow = 30
            };

            _dbContext.Set <Books>().Add(book);

            var library = new Libraries
            {
                Id      = 1,
                Name    = "library",
                Enabled = true
            };

            _dbContext.Set <Libraries>().Add(library);

            await _dbContext.SaveChangesAsync();

            var bookCartRepository = new EfRepository <BookCarts>(_dbContext);
            var bookRepository     = new EfRepository <Books>(_dbContext);
            var libraryRepository  = new EfRepository <Libraries>(_dbContext);

            var getBookInCartForBorrowQuery = new GetBookInCartForBorrowQuery(bookCartRepository, bookRepository, libraryRepository, _httpContextAccessor);
            var bookInCartBorrow            = await getBookInCartForBorrowQuery.ExecuteAsync();

            Assert.NotNull(bookInCartBorrow);
            Assert.Single(bookInCartBorrow);
            BookInCartDetailViewModel bookInCart = bookInCartBorrow.FirstOrDefault();

            Assert.Equal(book.Id, bookInCart.BookId);
            Assert.Equal(book.BookCode, bookInCart.BookCode);
            Assert.Equal(book.BookCode, bookInCart.BookCode);
            Assert.Equal(book.BookName, bookInCart.BookName);
            Assert.Equal(book.Author, bookInCart.Author);
            Assert.Equal(book.Amount, bookInCart.Amoun);
            Assert.Equal(book.AmountAvailable, bookInCart.AmountAvailable);
            Assert.Equal(book.MaximumDateBorrow, bookInCart.MaximumDateBorrow);
            Assert.Equal(bookCart.ModifiedDate, bookInCart.ModifiedDate);
            Assert.Equal(bookCart.Status, bookInCart.Status);
            Assert.Equal(library.Name, bookInCart.LibraryName);
            Assert.Equal(DateTime.Now.Date.AddDays(book.MaximumDateBorrow + 1), bookInCart.ReturnDate);
        }
Beispiel #48
0
 private void editBookMediaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
       {
     _selectedBook = new Books(MC.GetBook((lsv_AllBooksMedia.SelectedItems[0] as BooksListViewItem).BooksID));
     MC.LoadBookDetails(_selectedBook.BooksID);
       }
       catch (Exception)
       {
       }
 }
        public ActionResult details(int id)
        {
            Books entry = db.bll.books.getBooks(id);

            return(View(entry));
        }