//CRUD for Disbursement
 public Disbursement CreateDisbursement(Disbursement disbursement)
 {
     bool isValid = false;
     Disbursement newDisbursement = new Disbursement();
     try
     {
         if (ValidateDisbursement(disbursement, DisbursementMethod.Create))
         {
             foreach (DisbursementItem item in disbursement.DisbursementItems)
             {
                 isValid = ValidateDisbursementItem(item, DisbursementMethod.Create);
                 if (!isValid)
                     break;
             }
             if (isValid)
             {
                 newDisbursement = disbursementDAO.CreateDisbursement(disbursement);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
     return newDisbursement;
 }
 protected void btnCreate_Click(object sender, EventArgs e)
 {
     int disbursementID = Convert.ToInt32(tbxDisbursementID.Text.ToString());
     Disbursement disbursement = disbursementDAO.GetDisbursementByID(disbursementID);
     Disbursement newDisbursement = new Disbursement();
     newDisbursement.DateCreated = disbursement.DateCreated;
     newDisbursement.CreatedBy = disbursement.CreatedBy;
     newDisbursement.StationeryRetrievalFormID = disbursement.StationeryRetrievalFormID;
     Disbursement createdDisbursement = disbursementDAO.CreateDisbursement(newDisbursement);
     List<Disbursement> Items = new List<Disbursement>();
     Items.Add(createdDisbursement);
     GridView1.DataSource = Items;
     GridView1.DataBind();
 }
        // validate disbursement
        private bool ValidateDisbursement(Disbursement disbursement, DisbursementMethod disbursementMethod)
        {
            string errMsg = "";
            try
            {
                if (disbursement != null)
                {
                    if (disbursementMethod == DisbursementMethod.Create)
                    {
                        errMsg = "Create Disbursement failed. Please try again later";
                        if ((disbursement.CreatedBy != 0 || disbursement.User != null) &&
                            (disbursement.DateCreated != null && disbursement.DateCreated.Date.ToShortDateString() == DateTime.Now.Date.ToShortDateString()))
                        {
                            return true;
                        }
                    }
                    if (disbursementMethod == DisbursementMethod.Update)
                    {
                        errMsg = "Update Disbursement failed. Please try again later";
                        if ((disbursement.CreatedBy != 0 || disbursement.User != null) &&
                            (disbursement.DateCreated != null))
                        {
                            return true;
                        }
                    }
                }
                return false;
            }

            catch (Exception)
            {
                throw new Exceptions.DisbursmentException(errMsg);
            }
        }
 public void DeleteDisbursement(Disbursement disbursement)
 {
     disbursementDAO.DeleteDisbursement(disbursement);
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Disbursements EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDisbursements(Disbursement disbursement)
 {
     base.AddObject("Disbursements", disbursement);
 }
 /// <summary>
 /// Create a new Disbursement object.
 /// </summary>
 /// <param name="disbursementID">Initial value of the DisbursementID property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 public static Disbursement CreateDisbursement(global::System.Int32 disbursementID, global::System.DateTime dateCreated, global::System.Int32 createdBy)
 {
     Disbursement disbursement = new Disbursement();
     disbursement.DisbursementID = disbursementID;
     disbursement.DateCreated = dateCreated;
     disbursement.CreatedBy = createdBy;
     return disbursement;
 }