Exemplo n.º 1
0
        private void bunifuTileButton_Execute_Click(object sender, EventArgs e)
        {
            if (IsViewMode())
            {
                this.Close();
                return;
            }
            ThreadManager.DisplayLoadingScreen();
            Book newBook = new Book();

            try
            {
                newBook.BookID        = bunifuCustomTextbox_BookCode.Text;
                newBook.BookName      = bunifuCustomTextbox_Title.Text;
                newBook.Location      = bunifuCustomTextbox_Location.Text;
                newBook.Status        = bunifuDropdown_Status.selectedValue;
                newBook.Price         = double.Parse(bunifuCustomTextbox_Price.Text);
                newBook.PublishDate   = Convert.ToDateTime(bunifuCustomTextbox_PulishDate.Text).Date;
                newBook.AuthorName    = bunifuCustomTextbox_Author.Text;
                newBook.PublisherName = bunifuCustomTextbox_Publisher.Text;
            }
            catch (Exception ex)
            {
                ErrorManager.MessageDisplay(ex.Message, "", "Error: Can't get data from fields");
                ThreadManager.CloseLoadingScreen();
                return;
            }

            string err = "";

            if (mode != "delete")
            {
                err = newBook.ValidateField();
            }
            if (err != "")
            {
                ThreadManager.CloseLoadingScreen();
                ErrorManager.MessageDisplay(err, "", "Data input error");
                return;
            }


            err = "";
            if (IsAddOrUpdateMode())
            {
                err = manager.AddOrUpdateBookToDatabase(newBook);
                ThreadManager.CloseLoadingScreen();
                ErrorManager.MessageDisplay(err, "Add/Update a book successfully", "Failed to add/update a book");
            }
            else if (IsDeleteMode())
            {
                err = manager.DeleteBookFromDatabase(bunifuCustomTextbox_BookCode.Text);
                ThreadManager.CloseLoadingScreen();
                ErrorManager.MessageDisplay(err, "Delete a book successfully", "Failed to delete a book");
            }
            if (err == "")
            {
                this.Close();
            }
        }