private void ButtonAddCategory_Click(object sender, EventArgs e)
        {
            if (!ReadyToAdd())
            {
                return;
            }
            string   categoryName = textBoxCategoryName.Text.Trim();
            string   description  = textBoxDescription.Text.Trim();
            Category category     = new Category()
            {
                CategoryName = categoryName,
                Description  = description
            };
            int categoryID = CategoryDAO.AddNewCategory(category);

            MessageBox.Show("Category Added Successful!");
            if (containerForm is AddBookForm addBookForm)
            {
                addBookForm.UpdateCheckedListBoxCategories(categoryID);
                addBookForm.ClearAddNewPanel();
            }
            else if (containerForm is EditBookForm editBookForm)
            {
                editBookForm.UpdateCheckedListBoxCategories(categoryID);
                editBookForm.ClearAddNewPanel();
            }
        }
Ejemplo n.º 2
0
        private void EditBookForm_Load(object sender, System.EventArgs e)
        {
            UpdateComboBoxAuthors(0);
            UpdateComboBoxPublishers(0);
            UpdateCheckedListBoxCategories(0);
            Book book = BookDAO.SelectBookByBookID(bookID);

            textBoxTitle.Text                   = book.Title;
            comboBoxAuthors.SelectedItem        = book.AuthorName;
            comboBoxPublishers.SelectedItem     = book.PublisherName;
            dateTimePickerPublicationDate.Value = book.PublicationDate;
            for (int index = 0; index < checkedListBoxCategories.Items.Count; index++)
            {
                checkedListBoxCategories.SetItemChecked(index, false);
            }
            List <Category> categories = CategoryDAO.SelectCategoriesByBookID(bookID);

            for (int index = 0; index < checkedListBoxCategories.Items.Count; index++)
            {
                string categoryName = checkedListBoxCategories.Items[index].ToString();
                foreach (Category category in categories)
                {
                    if (category.CategoryName.Equals(categoryName))
                    {
                        checkedListBoxCategories.SetItemChecked(index, true);
                        break;
                    }
                }
            }
            textBoxUnitPrice.Text   = ((int)book.UnitPrice).ToString();
            textBoxDescription.Text = book.Description;
        }
Ejemplo n.º 3
0
 public AddBookForm(Employee e, FrmMenu menuForm)
 {
     this.EMPLOYEE = e;
     this.menuForm = menuForm;
     InitializeComponent();
     publishers = PublisherDAO.SelectAllPublishers();
     categories = CategoryDAO.SelectAllCategories();
 }
Ejemplo n.º 4
0
 public EditBookForm(int bookID, FrmMenu frmMenu, Employee e)
 {
     InitializeComponent();
     this.bookID  = bookID;
     this.frmMenu = frmMenu;
     EMPLOYEE     = e;
     authors      = AuthorDAO.SelectAllAuthors();
     publishers   = PublisherDAO.SelectAllPublishers();
     categories   = CategoryDAO.SelectAllCategories();
 }
Ejemplo n.º 5
0
 public void UpdateCheckedListBoxCategories(int categoryID)
 {
     checkedListBoxCategories.Items.Clear();
     categories = CategoryDAO.SelectAllCategories();
     for (int index = 0; index < categories.Count; index++)
     {
         Category category = categories[index];
         checkedListBoxCategories.Items.Add(category.CategoryName);
         if (category.CategoryID == categoryID)
         {
             checkedListBoxCategories.SetItemChecked(index, true);
         }
     }
 }
        private void TextBoxCategoryName_TextChanged(object sender, EventArgs e)
        {
            string categoryName = textBoxCategoryName.Text.Trim();

            if (categoryName.Length == 0)
            {
                labelCategoryNameMessage.ForeColor = Color.Red;
                labelCategoryNameMessage.Text      = "Category Name is required";
                return;
            }
            List <Category> categories = CategoryDAO.SelectAllCategories();

            foreach (Category category in categories)
            {
                if (category.CategoryName.Equals(categoryName))
                {
                    labelCategoryNameMessage.ForeColor = Color.Red;
                    labelCategoryNameMessage.Text      = "Category Name already existed";
                    return;
                }
            }
            labelCategoryNameMessage.ForeColor = Color.Green;
            labelCategoryNameMessage.Text      = "Category Name is OK";
        }
Ejemplo n.º 7
0
 public SearchBookPanel(Form containerForm)
 {
     this.containerForm = containerForm;
     authors            = AuthorDAO.SelectAllAuthors();
     publishers         = PublisherDAO.SelectAllPublishers();
     categories         = CategoryDAO.SelectAllCategories();
     Size     = new Size(1205, 265);
     groupBox = new GroupBox()
     {
         Text     = "Search Book",
         Location = new Point(12, 12),
         Size     = new Size(1190, 250)
     };
     labelTitle = new Label()
     {
         Text     = "Title",
         AutoSize = true,
         Location = new Point(6, 23),
         Size     = new Size(27, 13)
     };
     textBoxTitle = new TextBox()
     {
         Location = new Point(69, 19),
         Size     = new Size(175, 20)
     };
     labelAuthor = new Label()
     {
         Text     = "Author",
         AutoSize = true,
         Location = new Point(6, 49),
         Size     = new Size(38, 13)
     };
     comboBoxAuthors = new ComboBox()
     {
         Location = new Point(69, 46),
         Size     = new Size(175, 21)
     };
     labelPublisher = new Label()
     {
         Text     = "Publisher",
         AutoSize = true,
         Location = new Point(6, 76),
         Size     = new Size(30, 13)
     };
     comboBoxPublishers = new ComboBox()
     {
         Location = new Point(69, 73),
         Size     = new Size(175, 21)
     };
     labelCategories = new Label()
     {
         Text     = "Categories",
         AutoSize = true,
         Location = new Point(6, 103),
         Size     = new Size(57, 13)
     };
     checkedListBoxCategories = new CheckedListBox()
     {
         ScrollAlwaysVisible = true,
         Location            = new Point(69, 103),
         Size = new Size(175, 94)
     };
     labelPublicationDate = new Label()
     {
         Text     = "Publication Date",
         AutoSize = true,
         Location = new Point(6, 204),
         Size     = new Size(85, 13)
     };
     comboBoxPublicationDate = new ComboBox()
     {
         Location = new Point(9, 221),
         Size     = new Size(82, 21)
     };
     labelMonth = new Label()
     {
         Text     = "Month",
         AutoSize = true,
         Location = new Point(97, 204),
         Size     = new Size(37, 13)
     };
     comboBoxMonth = new ComboBox()
     {
         Location = new Point(97, 221),
         Size     = new Size(72, 21)
     };
     labelYear = new Label()
     {
         Text     = "Year",
         AutoSize = true,
         Location = new Point(172, 204),
         Size     = new Size(29, 13)
     };
     numericUpDownYear = new NumericUpDown()
     {
         Location = new Point(175, 222),
         Size     = new Size(69, 20)
     };
     labelSearchResult = new Label()
     {
         Text     = "Search Result",
         AutoSize = true,
         Location = new Point(250, 16),
         Size     = new Size(74, 13)
     };
     dataGridViewSearchResult = new DataGridView()
     {
         AllowUserToAddRows    = false,
         AllowUserToDeleteRows = false,
         AutoSizeColumnsMode   = DataGridViewAutoSizeColumnsMode.AllCells,
         Location = new Point(253, 32),
         Size     = new Size(600, 210)
     };
     AddControls();
     AddItemsToComboBoxAuthors();
     AddItemsToComboBoxPublishers();
     AddItemsToCheckedListBoxCategories();
     AddItemsToComboBoxPublicationDate();
     AddItemsToComboBoxMonth();
     AddItemsToNumericUpDownYear();
     AddEventsToControls();
     UpdateDataGridViewSearchResult();
 }