Example #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (m_IsAdd)
         {
             m_BookTitlesObject = new CBookTitlesDTO(txtBookTitlesId.Text, lkBookGenreName.EditValue.ToString(), txtBookTitlesName.Text);
             m_BookTitlesExecute.AddBookTitlesToDatabase(m_BookTitlesObject);
             foreach (CheckedListBoxItem _authorName in chkCmbAuthorName.Properties.Items)
             {
                 if (_authorName.CheckState == CheckState.Checked)
                 {
                     m_AuthorDetailObject = new CAuthorDetailDTO(m_BookTitlesExecute.getBookTitlesMaxIdFromDatabase(), _authorName.Value.ToString());
                     m_AuthorDetailExecute.AddAuthorDetailToDatabase(m_AuthorDetailObject);
                 }
             }
         }
         else
         {
             m_BookTitlesObject = new CBookTitlesDTO(txtBookTitlesId.Text, lkBookGenreName.EditValue.ToString(), txtBookTitlesName.Text);
             m_BookTitlesExecute.UpdateBookTitlesToDatabase(m_BookTitlesObject);
             _listAuthorNameSecond = new ArrayList(chkCmbAuthorName.EditValue.ToString().Split(new string[] { ", " }, StringSplitOptions.None));
             foreach (object item in _listAuthorNameFirst)
             {
                 if (!_listAuthorNameSecond.Contains(item))
                 {
                     m_AuthorDetailExecute.DeleteAuthorDetailToDatabase(new CAuthorDetailDTO(txtBookTitlesId.Text, item.ToString()));
                 }
             }
             foreach (object item in _listAuthorNameSecond)
             {
                 if (!_listAuthorNameFirst.Contains(item))
                 {
                     m_AuthorDetailExecute.AddAuthorDetailToDatabase(new CAuthorDetailDTO(txtBookTitlesId.Text, item.ToString()));
                 }
             }
         }
         //m_AuthorDetailObject = new CAuthorDetailDTO(m_BookTitlesExecute.getBookTitlesMaxIdFromDatabase(),chkCmbAuthorName.)
     }
     catch (System.Exception ex)
     {
         XtraMessageBox.Show(ex.ToString(), "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
     }
     finally
     {
         updateEnableButtonAndResetValueOfControl(ref btnSave);
     }
 }
Example #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (!checkData())
     {
         return;
     }
     try
     {
         if (m_IsAdd)
         {
             m_BookTitlesObject = new CBookTitlesDTO("DS0000000", lkBookGenreName.EditValue.ToString(), txtBookTitlesName.Text);
             if (m_BookTitlesExecute.AddBookTitlesToDatabase(m_BookTitlesObject))
             {
                 XtraCustomMessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", true);
             }
             else
             {
                 XtraCustomMessageBox.Show("Thêm dữ liệu thất bại!", "Lỗi", true);
             }
             foreach (CheckedListBoxItem _authorName in chkCmbAuthorName.Properties.Items)
             {
                 if (_authorName.CheckState == CheckState.Checked)
                 {
                     m_AuthorDetailObject = new CAuthorDetailDTO(m_BookTitlesExecute.getBookTitlesMaxIdFromDatabase(),
                                                                 _authorName.Value.ToString());
                     m_AuthorDetailExecute.AddAuthorDetailToDatabase(m_AuthorDetailObject);
                 }
             }
         }
         else
         {
             m_BookTitlesObject = new CBookTitlesDTO(txtBookTitlesId.Text,
                                                     lkBookGenreName.EditValue.ToString(), txtBookTitlesName.Text);
             if (m_BookTitlesExecute.UpdateBookTitlesToDatabase(m_BookTitlesObject))
             {
                 XtraCustomMessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", true);
             }
             else
             {
                 XtraCustomMessageBox.Show("Cập nhật dữ liệu thất bại!", "Lỗi", true);
             }
             _listAuthorNameSecond = new ArrayList(chkCmbAuthorName.EditValue.ToString().Split(new string[] { ", " }, StringSplitOptions.None));
             foreach (object item in _listAuthorNameFirst)
             {
                 if (!_listAuthorNameSecond.Contains(item))
                 {
                     m_AuthorDetailExecute.DeleteAuthorDetailToDatabase(new CAuthorDetailDTO(txtBookTitlesId.Text, item.ToString()));
                 }
             }
             foreach (object item in _listAuthorNameSecond)
             {
                 if (!_listAuthorNameFirst.Contains(item))
                 {
                     m_AuthorDetailExecute.AddAuthorDetailToDatabase(new CAuthorDetailDTO(txtBookTitlesId.Text, item.ToString()));
                 }
             }
         }
         //m_AuthorDetailObject = new CAuthorDetailDTO(m_BookTitlesExecute.getBookTitlesMaxIdFromDatabase(),chkCmbAuthorName.)
     }
     catch (System.Exception)
     {
         XtraCustomMessageBox.Show("Lưu dữ liệu thất bại", "Thông báo", true);
     }
     finally
     {
         updateEnableButtonAndResetValueOfControl(ref btnSave);
     }
 }