コード例 #1
0
 public AuthorManagementForm()
 {
     InitializeComponent();
     AuthorBUS bus=new AuthorBUS();
     lst = bus.GetAllAuthor();
     grdAuthor.DataSource = lst;
 }
コード例 #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     AuthorBUS authorBus = new AuthorBUS();
     if(String.IsNullOrEmpty(txtAuthorId.Text))
     {
         if (String.IsNullOrEmpty(txtAuthorName.Text))
         {
             MessageBox.Show("Vui lòng nhập vào tên tác giả !!!");
             txtAuthorName.Focus();
         }
         else
         {
             if (authorBus.InsertAuthor(new AuthorDTO(){AuthorName = txtAuthorName.Text,CreatedDate = DateTime.Now,UpdatedDate = DateTime.Now}) == 1)
             {
                 MessageBox.Show("Tạo mới Tác giả thành công !!!");
                 lst.Clear();
                 lst.AddRange(authorBus.GetAllAuthor());
                 grdAuthor.RefreshDataSource();
                 txtAuthorId.Text = "";
                 txtAuthorName.Text = "";
             }
             else
             {
                 MessageBox.Show("Tạo mới tác giả thất bại !!!");
             }
         }
     }
     else
     {
         if (String.IsNullOrEmpty(txtAuthorName.Text))
         {
             MessageBox.Show("Vui lòng nhập vào tên tác giả !!!");
             txtAuthorName.Focus();
         }
         else
         {
             AuthorDTO author = (AuthorDTO) grvAuthor.GetFocusedRow();
             author.AuthorName = txtAuthorName.Text;
             if (authorBus.UpdateAuthor(author) == 1)
             {
                 MessageBox.Show("Cập nhật thông tin Tác giả thành công !!!");
                 grdAuthor.RefreshDataSource();
             }
             else
             {
                 MessageBox.Show("Cập nhật thông tin Tác giả thất bại !!!");
             }
         }
     }
 }