title: how can i simplify crud
body: <p>Hi i would like to simplify my code on the crud messagebox. I currently have almost 20 over pages of CRUD forms with 4 buttons of create, update delete and reset. How do i simplify this to become a user control? so that i don have to keep writting "Save successfully", "sorry, error",....</p>
  
  <p>my Code </p>
  
  <pre><code> protected override void btnSave_Click(object sender, EventArgs e)
      {
          if (!validateBeforeSave()) return;
  
          if (MessageBox.Show(MessageManager.SaveAsk, "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
          {
              try
              {                  
                  BindValueToObject();                   
  
                  if (Convert.ToInt32(lblEmpId.Text) == 0)
                  {
                      user.Add();
                      ResetAfterSave(true, user.Id);
                      base.Success = true;
                  }
                  else
                  {
                      user.Update();
                      ResetAfterSave(false, user.Id);
                      base.Success = true;
                  }
                  base.btnSave_Click(this, null);
              }
              catch (Exception ex)
              {
                  Logger.Error(typeof(UsersForm), ex.ToString());
                  base.Success = false;
                  base.btnSave_Click(this, null);
              }
          }
      }
      protected override void btnDelete_Click(object sender, EventArgs e)
      {
          if (null == dgUser.CurrentRow) return;
          user.Id = (int)dgUser.SelectedRows[0].Cells["empId"].Value;
  
          try
          {
              if ((MessageBox.Show(MessageManager.DeleteAsk, "Are you sure to delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
              {
                  user.Delete();
                  ResetAfterSave(false, 0);
                  base.Success = true;
                  base.btnDelete_Click(this, null);
              }
          }
          catch
          {
              base.Success = false;
              base.btnDelete_Click(this, null);
          }
      }
  </code></pre>
  
  <p>The base.btnSave_Click(this, null); is calling this below where i pass in the flag.</p>
  
  <pre><code> protected virtual void btnSave_Click(object sender, EventArgs e)
      {
          if (this.success)
              MessageBox.Show(MessageManager.SaveSuccess, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
          else
          {
              MessageBox.Show(MessageManager.SaveFailed, "Fail to save", MessageBoxButtons.OK, MessageBoxIcon.Stop);
              return;
          }
      }
  </code></pre>
  
  <p>I felt very annoying of rewriting this over and over again. </p>