Ejemplo n.º 1
0
 //[ValidateAntiForgeryToken]特性用来防止伪造的跨站请求,配合表单中的@Html.AntiForgeryToken()使用
 //对数据进行增删改时要防止csrf攻击!
 //该特性表示检测服务器请求是否被篡改。注意:该特性只能用于post请求,get请求无效。
 public ActionResult Create([Bind(Include = "BookId,CategoryId,Title,Price,BookCoverUrl,Authors")] Books book)
 {
     if (ModelState.IsValid)
     {
         bookmanager.AddBook(book);
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", book.CategoryId);
     return(View("Create", book));
 }
Ejemplo n.º 2
0
        public ActionResult AddBook(Book book)
        {
            if (ModelState.IsValid)
            {
                _manager.AddBook(book);

                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 3
0
        protected void BtnOk_Click(object sender, EventArgs e)
        {
            //图书图片是否上传
            bool fileOK = false;
            //定义上传图书图片路径
            string BookPath = Server.MapPath("~/Images/");
            //实例化图书/出版社实体类
            BookInfo      book       = new BookInfo();
            PublisherInfo Publishers = new PublisherInfo();

            //是否已经上传图书(HasFile  布尔类型 获取一个布尔值,用于表示FileUpload控件是否已经包含一个文件)
            if (FileUpload1.HasFile)
            {
                string   fileExtension     = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                string[] AllowedExtensions = { ".gif", ".png", ".bmp", ".jpg" };
                for (int i = 0; i < AllowedExtensions.Length; i++)
                {
                    if (fileExtension == AllowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }
            if (fileOK)
            {
                try
                {
                    FileUpload1.SaveAs(BookPath + FileUpload1.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("图片上传不成功!");
                }
            }
            else
            {
                MessageBox.Show("只能够上传图片文件!");
            }

            book.Title              = txtTitle.Text;
            book.Author             = txtAuthor.Text;
            book.Category           = PbId.Text;
            book.Publisher          = PublisherName.Text;
            book.ISBN               = TxtISBN.Text;
            book.PublishDate        = DateTime.Parse(TxtTime.Text);
            book.UnitPrice          = Convert.ToInt32(TxtUnitPrice.Text);
            book.WordsCount         = Convert.ToInt32(TxtWordsCount.Text);
            book.ContentDescription = TxtContentDescription.Text;
            book.ImgUrl             = BookPath.ToString();

            BookManager.AddBook(book);
        }
        static void Main(string[] args)
        {
            ICustomerManager customerManager = new CustomerManager();

            customerManager.AddCustomer("Lars", "19930503", 0);

            IBookshelfAisleManager BookshelfAisleManager1 = new BookshelfAisleManager();

            BookshelfAisleManager1.AddBookshelfAisle(1);

            IBookshelfAisleManager BookshelfAisleManager2 = new BookshelfAisleManager();

            BookshelfAisleManager2.AddBookshelfAisle(2);

            IBookshelfAisleManager BookshelfAisleManager3 = new BookshelfAisleManager();

            BookshelfAisleManager3.AddBookshelfAisle(3);

            IShelfManager shelfManager1 = new ShelfManager();

            shelfManager1.AddShelf(1, 1);

            IShelfManager shelfManager2 = new ShelfManager();

            shelfManager2.AddShelf(2, 2);

            IShelfManager shelfManager3 = new ShelfManager();

            shelfManager3.AddShelf(3, 3);

            IBookManager bookManager1 = new BookManager();

            bookManager1.AddBook("Sagan om ringen", 199);

            IBookManager bookManager2 = new BookManager();

            bookManager2.AddBook("Clean Code", 159);

            IBookManager bookManager3 = new BookManager();

            bookManager3.AddBook("Harry Potter", 179);

            IBookManager bookManager4 = new BookManager();

            bookManager4.AddBook("Nalles stora blåa hus", 200);

            IBookManager bookManager5 = new BookManager();

            bookManager5.AddBook("Bamse", 99);
        }
Ejemplo n.º 5
0
    public void AddBook()
    {
        var id = bookManager.GetId();

        Console.WriteLine("Id nowej książki wynosi : " + id);
        Console.WriteLine("Podaj nazwę książki: ");
        var name = Console.ReadLine();

        Console.WriteLine("Podaj autora: ");
        var author = Console.ReadLine();

        Console.WriteLine("Podaj cenę książki: ");
        var price = Helpers.JustDecimals();

        bookManager.AddBook(id, name, author, price);
    }
Ejemplo n.º 6
0
 public IHttpActionResult Post([FromBody] BookModel value)
 {
     if (ModelState.IsValid)
     {
         bool success = bookBll.AddBook(value);
         if (success)
         {
             return(Ok());
         }
         return(BadRequest());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Ejemplo n.º 7
0
    public static void Main(string[] args)
    {
        string name  = "西游记";
        double price = 199.9;

        string authorName   = "吴承恩";
        int    authorAge    = 20;
        int    authorGender = 1;

        Book book01    = new Book(name, authorName, authorAge, authorGender, price);
        bool addResult = BookManager.AddBook(book01);

        Book[] result = BookManager.FindByName("西游记", Findflags.ByBookName);
        foreach (Book book in result)
        {
            Console.WriteLine(book);
        }
    }
 public HttpResponseMessage Post([FromBody] BookModel model)
 {
     try
     {
         BookDTO bookdto = modelfactory.Parse(model);
         string  bookID  = bookmanager.AddBook(bookdto);
         if (bookID == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "SOMETHING WENT WRONG"));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.Created, "BOOK CREATED SUCCESSFULLY WITH ID : " + bookID));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Ejemplo n.º 9
0
        public HttpResponseMessage AddBook([FromBody] BookModel newBook)
        {
            if (ModelState.IsValid)
            {
                BookManager BookManager = new BookManager();

                if (BookManager.AddBook(newBook))
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, newBook));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
            }

            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Ejemplo n.º 10
0
        public void handleAddBook()
        {
            int    BookID    = int.Parse(librarianFormView.BookID);
            string BookName  = librarianFormView.BookName;
            int    Quantity  = int.Parse(librarianFormView.Quantity);
            float  BookPrice = float.Parse(librarianFormView.BookPrice);
            string Author    = librarianFormView.Author;

            try {
                bool result = bookManager.AddBook(new Book(BookID, BookName, Quantity, BookPrice, Author));
                if (!result)
                {
                    librarianFormView.showMessage("Add Book Fail");
                    return;
                }

                librarianFormView.showMessage("Add Book Success!");
                handleLoadBooksForLibrarian();
            } catch (Exception ex) {
                librarianFormView.showMessage(ex.Message);
            }
        }
Ejemplo n.º 11
0
    /// <summary>
    /// 单击“保存”按钮事件方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void bntSave_Click(object sender, EventArgs e)
    {
        string FileName = this.fulBook.FileName;

        if (FileName.Trim().Trim().Length != 0)
        {
            string strpath = Server.MapPath("~/images/BookCovers/" + txtISBN.Text.Trim() + ".jpg");
            fulBook.PostedFile.SaveAs(strpath);//把图片保存在此路径中
        }
        BookManager manger = new BookManager();
        Book        book   = new Book();

        book.Author             = txtAuthor.Text;
        book.Category           = new Category(int.Parse(ddlCategory.SelectedValue), ddlCategory.SelectedItem.Text);
        book.ContentDescription = txtDesc.Text;
        book.ISBN        = txtISBN.Text;
        book.PublishDate = DateTime.Parse(txtPublishDate.Text);
        book.Publisher   = new Publisher(int.Parse(ddlPublisher.SelectedValue), ddlPublisher.SelectedItem.Text);
        book.Title       = txtTitle.Text;
        book.TOC         = ftbToc.Text;
        book.UnitPrice   = decimal.Parse(txtPrice.Text);
        if (Request.QueryString["id"] != null)
        {
            book.Id = Convert.ToInt32(Request.QueryString["id"]);
            if (manger.ModifyBook(book))
            {
                Page.RegisterClientScriptBlock("", "<script>alert('书籍修改成功!')</script>");
            }
        }
        else
        {
            manger.AddBook(book);
            Response.Redirect("~/admin/BookList.aspx");
            //Page.RegisterClientScriptBlock("", "<script>alert('书籍添加成功!')</script>");
        }
    }
Ejemplo n.º 12
0
 public ActionResult AddBook(string bookName, string bookType, string bookState)
 {
     _bookManager.AddBook(bookName, bookType, bookState);
     return(View("Index", _bookManager));
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            BookManager lib    = new BookManager();
            char        option = '1';

            while (option != '5')
            {
                Console.WriteLine("Wellcome to my library");
                Console.WriteLine("1. Add new book");
                Console.WriteLine("2.Update a book");
                Console.WriteLine("3.Delete a book");
                Console.WriteLine("4.List all book");
                Console.WriteLine("5.Quit");
                Console.Write("Choose an option (from 1-5): ");
                option = new DataInput().CheckOption();

                switch (option)
                {
                case '1':
                    if (lib.AddNewBook(lib.AddBook()))
                    {
                        Console.WriteLine("Saved!!!");
                    }
                    else
                    {
                        Console.WriteLine("Can not add to the book!!!");
                    }
                    break;

                case '2':
                    if (lib.UpdateBookInfor())
                    {
                        Console.WriteLine("Done!!!");
                    }
                    else
                    {
                        Console.WriteLine("Can not update the book, double-check book's id " +
                                          "or amount of book in the list");
                    }
                    break;

                case '3':
                    bool result4 = lib.DeleteBook();
                    if (result4)
                    {
                        Console.WriteLine("Done!!!");
                    }
                    else
                    {
                        Console.WriteLine("Can not delete the requested book, double-check book's id " +
                                          "or amount of book in the list");
                    }
                    break;

                case '4':
                    if (lib.GetListBook().Count == 0)
                    {
                        Console.WriteLine("No book to show");
                        break;
                    }

                    lib.DisplayAllBooks();
                    break;

                case '5':
                    break;
                }
            }
        }
Ejemplo n.º 14
0
 //确认添加
 private void btnAdd_Click(object sender, EventArgs e)
 {
     #region 数据验证
     if (this.txtBookName.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入图书名称", "提示信息");
         this.txtBookName.Focus();
         return;
     }
     if (this.cboBookCategory.SelectedIndex == -1)
     {
         MessageBox.Show("请选择图书分类", "提示信息");
         return;
     }
     if (this.cboPublisher.SelectedIndex == -1)
     {
         MessageBox.Show("请选择图书出版社", "提示信息");
         return;
     }
     if (this.txtAuthor.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入主编人", "提示信息");
         this.txtAuthor.Focus();
         return;
     }
     if (!Common.DataValidate.IsDecimal(this.txtUnitPrice.Text.Trim()))
     {
         MessageBox.Show("请输入正确的单价", "提示信息");
         this.txtUnitPrice.Focus();
         return;
     }
     if (this.txtBarCode.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入图书条码", "提示信息");
         this.txtBarCode.Focus();
         return;
     }
     if (!Common.DataValidate.IsInteger(this.txtBookCount.Text.Trim()))
     {
         MessageBox.Show("请输入正确的收藏总数", "提示信息");
         this.txtBookCount.Focus();
         return;
     }
     if (this.txtBookPosition.Text.Trim().Length == 0)
     {
         MessageBox.Show("请输入书架位置", "提示信息");
         this.txtBookPosition.Focus();
         return;
     }
     if (this.pbCurrentImage.Image == null)
     {
         MessageBox.Show("请选择图书封面", "提示信息");
         return;
     }
     #endregion
     #region 封装数据
     Book objBook = new Book()
     {
         BookName      = this.txtBookName.Text.Trim(),
         BookCategory  = Convert.ToInt32(this.cboBookCategory.SelectedValue),
         PublisherId   = Convert.ToInt32(this.cboPublisher.SelectedValue),
         PublisherName = this.cboPublisher.Text,
         PublishDate   = Convert.ToDateTime(this.dtpPublishDate.Text),
         Author        = this.txtAuthor.Text.Trim(),
         UnitPrice     = Convert.ToDecimal(this.txtUnitPrice.Text.Trim()),
         BarCode       = this.txtBarCode.Text.Trim(),
         BookCount     = Convert.ToInt32(this.txtBookCount.Text.Trim()),
         Remainder     = Convert.ToInt32(this.txtBookCount.Text.Trim()),
         BookPosition  = this.txtBookPosition.Text.Trim(),
         BookImage     = new Common.SerializeObjectToString().SerializeObject(this.pbCurrentImage.Image)
     };
     #endregion
     #region 调用后台方法保存数据
     try
     {
         if (objBookManager.AddBook(objBook))
         {
             this.books.Add(objBook);
             this.dgvBookList.DataSource = null;
             this.dgvBookList.DataSource = this.books;
             foreach (Control item in this.gbBook.Controls)
             {
                 if (item is TextBox)
                 {
                     item.Text = "";
                 }
                 else if (item is ComboBox)
                 {
                     ((ComboBox)item).SelectedIndex = -1;
                 }
             }
             this.pbCurrentImage.Image = null;
             MessageBox.Show("添加成功", "提示信息");
         }
         else
         {
             MessageBox.Show("添加失败,请重试", "提示信息");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("添加失败,请重试。具体信息:" + ex.Message, "提示信息");
     }
     #endregion
 }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            IAisleManager aisleManager = new AisleManager();

            aisleManager.AddAisle(1);
            aisleManager.AddAisle(2);
            aisleManager.AddAisle(3);
            aisleManager.AddAisle(4);

            IShelfManager shelfManager = new ShelfManager();
            var           shelf1       = shelfManager.AddShelf(101, 1);
            var           shelf2       = shelfManager.AddShelf(102, 1);
            var           shelf3       = shelfManager.AddShelf(101, 2);
            var           shelf4       = shelfManager.AddShelf(101, 3);
            var           shelf5       = shelfManager.AddShelf(102, 3);
            var           shelf6       = shelfManager.AddShelf(103, 3);

            IBookManager bookManager = new BookManager();

            bookManager.AddBook("Clean Code", "Robert C. Martin", "9780132350884", 452, 2019, 5, shelf1, false);
            bookManager.AddBook("Peter Pan", "Barrie, J. M.", "9781405279574", 258, 2003, 3, shelf1, true);
            bookManager.AddBook("Harry Potter och frången från Azkaban", "J.K. Rowling", "9789129704211", 243, 2017, 4, shelf1, false);
            bookManager.AddBook("Harrp Potter och den vises sten", "J.K. Rowling", "9789129697704", 243, 2015, 3, shelf1, false);
            bookManager.AddBook("Bränn alla mina brev", "Alex Schulman", "9789188745583", 58, 2019, 5, shelf2, false);
            bookManager.AddBook("1984", "George Orwell", "9780451524935", 92, 1950, 1, shelf2, false);
            bookManager.AddBook("Oliver Twist", "Charles Dickens", "9789163802225", 28, 1994, 1, shelf2, false);
            bookManager.AddBook("Lord of the rings box set", "J.R.R. Tolkien", "9780007581146", 937, 2014, 2, shelf2, false);
            bookManager.AddBook("Moby Dick", "Herman Melville", "9789187193170", 89, 2016, 3, shelf3, false);
            bookManager.AddBook("Lord of the flies", "William Goldberg", "9780571200535", 85, 1999, 2, shelf3, false);
            bookManager.AddBook("To Kill a Mockingbird", "Harper Lee", "9781784752637", 98, 2015, 4, shelf4, false);
            bookManager.AddBook("Hjärnstark", "Anders Hansen", "9789175038452", 58, 2018, 5, shelf4, true);
            bookManager.AddBook("Gone Girl", "Gillian Flynn", "9780753827666", 76, 2013, 4, shelf4, false);
            bookManager.AddBook("Middagstipset", "Jenny Warsén", "9789174247947", 180, 2018, 5, shelf5, true);
            bookManager.AddBook("Omgiven av idioter", "Thomas Erikson", "9789175038407", 58, 2018, 5, shelf5, true);
            bookManager.AddBook("Hon som måste dö", "David Lagercrantz", "9789113073743", 189, 2019, 5, shelf5, false);

            ICustomerManager customerManager = new CustomerManager();

            customerManager.AddCustomer("Erika Axelsson", "Restalundsvägen 2", "1996-4-4", 0, null);
            var guardian1 = customerManager.AddCustomer("Knut Knutsson", "Rudbecksgatan 10", "1974-10-10", 0, null);
            var guardian2 = customerManager.AddCustomer("Johan Johansson", "Kungsgatan 1", "1982-1-1", 0, null);
            var guardian3 = customerManager.AddCustomer("Isak Isaksson", "Trädgårdsgatan 6", "1976-10-23", 0, null);

            customerManager.AddCustomer("Anders Andersson", "Drottninggatan 1", "1965-5-10", 0, null);
            customerManager.AddCustomer("Lovisa Lund", "Peppargatan 13", "1992-4-11", 0, null);
            customerManager.AddCustomer("Rebecca Rudolfsson", "Sörbyvägen 3", "1970-1-10", 75, null);
            customerManager.AddCustomer("Britta Bo", "Oskarsvägen 7", "1950-7-17", 0, null);

            customerManager.AddCustomer("Kasper Knutsson", "RudbecksGatan 10", "2007-1-15", 0, guardian1);
            customerManager.AddCustomer("Maja Johansson", "Kungsgatan 1", "2010-4-24", 0, guardian2);
            customerManager.AddCustomer("Lisa Isaksson", "Bolundstigen 11", "2006-8-8", 0, guardian3);

            ILoanManager loanManager = new LoanManager();

            loanManager.AddLoan(DateTime.Parse("2019-10-21"), DateTime.Parse("2019-11-21"), "Erika Axelsson", "Peter Pan");
            loanManager.AddLoan(DateTime.Parse("2019-9-24"), DateTime.Parse("2019-10-24"), "Anders Andersson", "Omgiven av idioter");
            loanManager.AddLoan(DateTime.Parse("2019-8-30"), DateTime.Parse("2019-9-30"), "Lovisa Lund", "Middagstipset");
            loanManager.AddLoan(DateTime.Parse("2019-10-5"), DateTime.Parse("2019-11-5"), "Lovisa Lund", "Hjärnstark");
            loanManager.AddLoan(DateTime.Parse("2019-11-1"), DateTime.Parse("2019-12-1"), "Kapser Knutsson", "Lord of the flies");

            Console.WriteLine("Press enter:");
            Console.ReadLine();
        }
Ejemplo n.º 16
0
        //添加图书
        private void btnAdd_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.txtBookName.Text.Trim().Length == 0)//图书名不能为空
            {
                MessageBox.Show("书名不能为空!");
                this.txtBookName.Focus();
                return;
            }
            if (this.txtBarCode.Text.Trim().Length == 0)//条码不能为空
            {
                MessageBox.Show("条码不能为空!");
                this.txtBarCode.Focus();
                return;
            }
            if (this.txtAuthor.Text.Trim().Length == 0)//主编人不能为空
            {
                MessageBox.Show("主编人不能为空!");
                this.txtAuthor.Focus();
                return;
            }
            if (this.cboBookCategory.Text.Trim().Length == 0)//图书分类不能为空
            {
                MessageBox.Show("图书分类不能为空!");
                this.cboBookCategory.Focus();
                return;
            }
            if (this.cboPublisher.Text.Trim().Length == 0)//出版社不能为空
            {
                MessageBox.Show("出版社不能为空!");
                this.cboPublisher.Focus();
                return;
            }
            if (this.txtUnitPrice.Text.Trim().Length == 0)//价格不能为空
            {
                MessageBox.Show("价格不能为空!");
                this.txtUnitPrice.Focus();
                return;
            }
            if (!Common.DataValidate.IsInteger(this.txtUnitPrice.Text.Trim()))//价格为整数
            {
                MessageBox.Show("价格不正确!");
                this.txtUnitPrice.Focus();
                return;
            }
            #endregion
            #region 数据封装
            Book objBook = new Book()
            {
                BookName      = this.txtBookName.Text.Trim(),
                BarCode       = this.txtBarCode.Text.Trim(),
                Author        = this.txtAuthor.Text.Trim(),
                PublisherId   = Convert.ToInt32(this.cboPublisher.SelectedValue),
                PublishDate   = Convert.ToDateTime(this.dtpPublishDate.Text),
                BookCategory  = Convert.ToInt32(this.cboBookCategory.SelectedValue),
                UnitPrice     = Convert.ToDouble(this.txtUnitPrice.Text.Trim()),
                BookImage     = this.pbCurrentImage.Image != null ? new SerializeObjectToString().SerializeObject(this.pbCurrentImage.Image) : "",
                BookCount     = this.txtBookCount.Text.Trim().Length != 0 ? Convert.ToInt32(this.txtBookCount.Text.Trim()) : 0,
                Remainder     = this.txtBookCount.Text.Trim().Length != 0 ? Convert.ToInt32(this.txtBookCount.Text.Trim()) : 0,
                BookPosition  = this.txtBookPosition.Text.Trim(),
                PublisherName = this.cboPublisher.Text
            };
            #endregion
            #region 添加图书
            try
            {
                objBookManager.AddBook(objBook);
                //在列表中更新图书
                bookList.Add(objBook);
                this.dgvBookList.DataSource = null;
                this.dgvBookList.DataSource = bookList;
                //清空输入文本框,等用户输入新的内容
                foreach (Control item in this.gbBook.Controls)
                {
                    if (item is TextBox)
                    {
                        item.Text = "";
                    }
                    else if (item is ComboBox)
                    {
                        ((ComboBox)item).SelectedIndex = -1;
                    }
                }
                pbCurrentImage.Image = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加图书失败,错误信息:" + ex.Message);
            }

            #endregion
        }