/// <summary> /// clear all controls and change text in the update button when user click add button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { try { ((mdiForm)this.MdiParent).StatusStipLabel.Text = "Adding a new record"; ((mdiForm)this.MdiParent).StatusStipLabe2.Text = ""; cmbBook.SelectedIndex = 0; cmbAuthor.SelectedIndex = 0; LoadCategory(); btnUpdate.Text = "Create"; btnAdd.Enabled = false; btnDelete.Enabled = false; createNewRecord = true; NavigationState(false); UT.ClearControls(grpBook.Controls); UT.ClearControls(grpAuthor.Controls); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
/// <summary> /// clear all controls and change text in the update button when user click add button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { try { ((mdiForm)this.MdiParent).StatusStipLabel.Text = "Adding a new author"; ((mdiForm)this.MdiParent).StatusStipLabe2.Text = ""; UT.ClearControls(grpAuthorInfo.Controls); UT.ClearControls(grpCareer.Controls); UT.ClearControls(grpPublishedWork.Controls); rdoMale.Checked = true; LoadCategory(); btnUpdate.Text = "Create"; btnAdd.Enabled = false; btnDelete.Enabled = false; createNewRecord = true; NavigationState(false); grpPublishedWork.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
/// <summary> /// load author according to user selection /// </summary> private void LoadAuthor() { string sqlAuthor = "SELECT AuthorId, FirstName + ISNULL(' '+ MiddleName, '') + ' ' + LastName AS FullName FROM Author"; if (lstCategory.SelectedIndex > 0) { sqlAuthor += $" WHERE MainCategory = {lstCategory.SelectedValue}"; } sqlAuthor += " ORDER BY FirstName, MiddleName, LastName"; DataTable dtAuthor = DataAccess.GetData(sqlAuthor); if (dtAuthor.Rows.Count > 0) { UT.FillListControl(cmbAuthor, "FullName", "AuthorId", dtAuthor); numberOfAuthors = dtAuthor.Rows.Count; LoadAuthorDetail(); } else { dgvBooks.Visible = false; lbFullName.Text = string.Empty; lbContactNumber.Text = string.Empty; lbAward.Text = string.Empty; lbNumOfBook.Text = string.Empty; cmbAuthor.DataSource = null; ((mdiForm)this.MdiParent).StatusStipLabel.Text = "No records"; MessageBox.Show("There is no author in the category"); } }
/// <summary> /// Load books according to user selection /// if the user selects the filter option, filter the result based on criteria /// </summary> private void LoadBook() { string sqlLoadBook = "SELECT BookId, Title + ' - ' + Edition AS Title FROM Book WHERE 0=0"; if (lstCategory.SelectedIndex > 0) { sqlLoadBook += $" AND CategoryId = {lstCategory.SelectedValue}"; } if (cmbYear.SelectedIndex > 0) { sqlLoadBook += $" AND (PublicateDate BETWEEN '{cmbYear.SelectedItem}-01-01' AND '{cmbYear.SelectedItem}-12-31')"; } if (chkAvailable.Checked) { sqlLoadBook += $" AND Available = 1"; } sqlLoadBook += " ORDER BY Title"; DataTable dtBook = DataAccess.GetData(sqlLoadBook); if (dtBook.Rows.Count > 0) { UT.FillListControl(cmbTitle, "Title", "BookId", dtBook); numberOfBooks = dtBook.Rows.Count; LoadBookDetail(); } else { dgvAuthors.Visible = false; lbTitle.Text = string.Empty; lbISBN.Text = string.Empty; lbCategory.Text = string.Empty; lbPublisher.Text = string.Empty; lbPrice.Text = string.Empty; lbNumOfAuthor.Text = string.Empty; cmbTitle.DataSource = null; ((mdiForm)this.MdiParent).StatusStipLabel.Text = "No records"; MessageBox.Show("There is no book in the category"); } }
/// <summary> /// fill the category list /// </summary> private void LoadCategory() { DataTable dtCategory = DataAccess.GetData("SELECT CategoryId, CategoryName FROM Category"); UT.FillListControl(lstCategory, "CategoryName", "CategoryId", dtCategory, true, "All"); }
/// <summary> /// fill the category combobox /// </summary> private void LoadCategory() { DataTable dtCategory = DataAccess.GetData("SELECT CategoryId, CategoryName FROM Category"); UT.BindComboBox(cmbCategory, dtCategory, "CategoryName", "CategoryId"); }
/// <summary> /// fill the authors combobox /// </summary> private void LoadAuthor() { DataTable dtAuthor = DataAccess.GetData("SELECT AuthorId, FirstName + ISNULL(' '+ MiddleName, '') + ' ' + LastName AS WholeName FROM Author ORDER BY LastName, FirstName"); UT.BindComboBox(cmbAuthor, dtAuthor, "WholeName", "AuthorId"); }
/// <summary> /// fill the books combobox /// </summary> private void LoadBook() { DataTable dtBook = DataAccess.GetData("SELECT BookId, Title FROM Book"); UT.BindComboBox(cmbBook, dtBook, "Title", "BookId"); }