private void UpdateGroupBoxImportDetails(int bookID) { int unitsInStock = BookDAO.SelectUnitsInStock(bookID); textBoxUnitsInStock.Text = unitsInStock.ToString(); groupBoxImportDetails.Visible = true; }
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; }
private void ButtonEdit_Click(object sender, EventArgs e) { if (!IsReadyToEdit()) { return; } string title = textBoxTitle.Text.Trim(); int authorID = authors[comboBoxAuthors.SelectedIndex].AuthorID; int publisherID = publishers[comboBoxPublishers.SelectedIndex].PublisherID; DateTime publicationDate = dateTimePickerPublicationDate.Value; List <int> categoriesID = new List <int>(0); foreach (string categoryName in checkedListBoxCategories.CheckedItems) { int selectedCategoryID = categories[checkedListBoxCategories.Items.IndexOf(categoryName)].CategoryID; categoriesID.Add(selectedCategoryID); } decimal unitPrice = Convert.ToDecimal(textBoxUnitPrice.Text.Trim().ToString()); string description = textBoxDescription.Text.ToString(); int numRows = BookDAO.EditBook(title, authorID, publisherID, publicationDate, categoriesID, unitPrice, description, bookID); if (numRows == categoriesID.Count) { MessageBox.Show("Book Edited Successful!"); frmMenu.LoadNewForm(new ViewBookForm(EMPLOYEE, frmMenu)); } }
private void AddItemsToNumericUpDownYear() { numericUpDownYear.Minimum = BookDAO.SelectMinPublicationYear(); numericUpDownYear.Maximum = BookDAO.SelectMaxPublicationYear(); numericUpDownYear.Value = numericUpDownYear.Maximum; numericUpDownYear.ReadOnly = true; }
private void TextBoxTitle_TextChanged(object sender, EventArgs e) { string title = textBoxTitle.Text.Trim(); if (title.Length == 0) { labelTitleMessage.ForeColor = Color.Red; labelTitleMessage.Text = "Title is required"; UpdateAddButton(); return; } List <string> booksTitle = BookDAO.SelectAllTitle(); foreach (string titles in booksTitle) { if (titles.Equals(title)) { labelTitleMessage.ForeColor = Color.Red; labelTitleMessage.Text = "Title already existed"; UpdateAddButton(); return; } } labelTitleMessage.ForeColor = Color.Green; labelTitleMessage.Text = "Title is OK"; UpdateAddButton(); }
private void ButtonAdd_Click(object sender, EventArgs e) { string title = textBoxTitle.Text.Trim(); int authorID = authors[comboBoxAuthors.SelectedIndex].AuthorID; int publisherID = publishers[comboBoxPublishers.SelectedIndex].PublisherID; DateTime publicationDate = dateTimePickerPublicationDate.Value; List <int> categoriesID = new List <int>(0); foreach (string categoryName in checkedListBoxCategories.CheckedItems) { int selectedCategoryID = categories[checkedListBoxCategories.Items.IndexOf(categoryName)].CategoryID; categoriesID.Add(selectedCategoryID); } decimal unitPrice = Convert.ToDecimal(textBoxUnitPrice.Text.Trim().ToString()); string description = textBoxDescription.Text.Trim(); int bookID = BookDAO.AddNewBook(title, authorID, publisherID, publicationDate, categoriesID, unitPrice, description); if (bookID > 0) { MessageBox.Show("Book Added Successful!"); if (MessageBox.Show("Do you want to import it now?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { menuForm.LoadNewForm(new ImportBookForm(bookID)); } else { ResetForm(); } } }
private void ButtonImport_Click(object sender, EventArgs e) { int bookID = Convert.ToInt32(textBoxBookID.Text.Trim()); int importUnits = Convert.ToInt32(textBoxImportUnits.Text.Trim()); int numRows = BookDAO.ImportBook(bookID, importUnits); if (numRows == 1) { MessageBox.Show("Book Imported Successful!"); } textBoxImportUnits.Text = ""; UpdateGroupBoxImportDetails(bookID); }
private void UpdateGroupBoxBookDetails(int bookID) { Book book = BookDAO.SelectBookByBookID(bookID); textBoxBookID.Text = book.BookID.ToString(); textBoxTitle.Text = book.Title; textBoxAuthor.Text = book.AuthorName; textBoxPublisher.Text = book.PublisherName; dateTimePickerPublicationDate.Value = book.PublicationDate; textBoxCategoriesName.Text = book.CategoriesName; textBoxUnitPrice.Text = Utility.FormatMoney(book.UnitPrice); textBoxDescription.Text = book.Description; groupBoxBookDetails.Visible = true; }
private void UpdateDataGridViewSearchResult() { dataGridViewSearchResult.DataSource = null; dataGridViewSearchResult.Rows.Clear(); dataGridViewSearchResult.Columns.Clear(); dataGridViewSearchResult.AutoGenerateColumns = false; AddColumnsToDataGridViewSearchResult(); string title = textBoxTitle.Text.Trim(); int authorID = GetSelectedAuthorID(); int publisherID = GetSelectedPublisherID(); List <int> categoriesID = GetSelectedCategoriesID(); PublicationDateCondition pdc = GetPublicationDateCondition(); List <Book> books = BookDAO.SearchBooks(title, authorID, publisherID, categoriesID, pdc); dataGridViewSearchResult.DataSource = books; }
public void DataGridViewSearchResult_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } var source = ((DataGridView)sender).Columns[e.ColumnIndex]; if (source.Name.Equals("Add")) { int bookID = Convert.ToInt32(searchBookPanel.dataGridViewSearchResult.Rows[e.RowIndex].Cells["BookID"].Value); Book book = BookDAO.SelectBookByBookID(bookID); if (book.UnitsInStock == 0) { MessageBox.Show("UnitsInStock == 0"); return; } UpdateDataGridViewBillDetails(bookID); UpdateLabelTotalPrice(); UpdateButtonCreateBill(); } }
private void UpdateDataGridViewBillDetails(int bookID) { Book book = BookDAO.SelectBookByBookID(bookID); for (int index = 0; index < dataGridViewBillDetails.Rows.Count; index++) { int existedBookID = Convert.ToInt32(dataGridViewBillDetails.Rows[index].Cells["BookID"].Value.ToString()); if (bookID == existedBookID) { DataGridViewCell quantityCell = dataGridViewBillDetails.Rows[index].Cells["Quantity"]; int oldQuantity = Convert.ToInt32(quantityCell.Value.ToString()); int unitsInStock = BookDAO.SelectUnitsInStock(bookID); if (oldQuantity == unitsInStock) { MessageBox.Show("Quantity <= UnitsInStock"); return; } quantityCell.Value = oldQuantity + 1; return; } } dataGridViewBillDetails.Rows.Add(book.BookID, book.Title, Utility.FormatMoney(book.UnitPrice), 1, 0); }
private void DrawSaleChart() { string[] monthsName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; lstTotalByDate.Clear(); string month = (cbxMonthsSale.SelectedIndex + 1).ToString(); dgvTopBook.DataSource = BookDAO.GetTopBookByMonth(month); dgvTopEmployee.DataSource = AccountDAO.GetTopEmployeeByMonth(month); for (int i = 0; i < DateTime.DaysInMonth(DateTime.Now.Year, Convert.ToInt32(month)); i++) { string year = "2020"; string date = (i + 1).ToString(); string conDate = year + "-" + month + "-" + date; try { DateTime dt = Convert.ToDateTime(conDate); double value = BillDAO.getTotalByDate(conDate); lstTotalByDate.Add(value); } catch (FormatException) { lstTotalByDate.Add(0); } } int basehei = 200; double maxVal = 0; double minVal = 0; foreach (double d in lstTotalByDate) { if (d > maxVal) { maxVal = d; } } minVal = maxVal; foreach (double d in lstTotalByDate) { if (d < minVal) { minVal = d; } } flpDisplaySale.Controls.Clear(); for (int i = 0; i < lstTotalByDate.Count; i++) { int height = CalToCol(basehei, maxVal, lstTotalByDate[i]); MyLabel l = new MyLabel(); l.Height = height; l.BackColor = Color.Gray; l.Months = i; l.MouseHover += L_MouseHover; l.MouseLeave += L_MouseLeave; MyLabel l2 = new MyLabel(); l2.Text = (i + 1).ToString(); l2.Height = 25; FlowLayoutPanel fl1 = new FlowLayoutPanel(); fl1.Width = 30; fl1.Height = 300; fl1.FlowDirection = FlowDirection.BottomUp; fl1.Controls.Add(l2); fl1.Controls.Add(l); flpDisplaySale.Controls.Add(fl1); } lblSaleHighest.Text = String.Format("Heightest Of" + monthsName[Convert.ToInt32(month) - 1] + ": {0:n0} VND ", maxVal); lblLowest.Text = String.Format("Lowest Of" + monthsName[Convert.ToInt32(month) - 1] + ": {0:n0} VND ", minVal); double aver = 0; foreach (double d in lstTotalByDate) { aver += d; } lblSaleAver.Text = String.Format("Average : {0:n0} VND / Day", (aver / lstTotalByDate.Count)); }