private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                List <VoucherItemsModel> voucherList  = new List <VoucherItemsModel>();
                ImusCityHallEntities     db           = new ImusCityHallEntities();
                Disbursement             disbursement = db.Disbursements.Find(DisbursementID);
                vouchernotb.Text = disbursement.VoucherNo;
                payeetb.Text     = disbursement.Payee == null ? disbursement.PayeeName : disbursement.Payee.CompanyName;

                paymenttypetb.Text = disbursement.PaymentType;
                decimal totalAmount = disbursement.DisbursementItems.Sum(m => m.Amount);
                voucheramounttb.Text = String.Format("{0:n}", totalAmount);

                foreach (var item in disbursement.DisbursementItems)
                {
                    var voucherItem = new VoucherItemsModel()
                    {
                        Explanation = item.Explanation,
                        Amount      = String.Format("{0:n}", item.Amount)
                    };
                    voucherList.Add(voucherItem);
                }
                voucheritemsdg.ItemsSource = voucherList;
                checkdesctb.Text           = voucherList.FirstOrDefault().Explanation;

                LoadFund();
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void voucherlistdg_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                db = new ImusCityHallEntities();
                if (voucherlistdg.SelectedValue == null)
                {
                    return;
                }
                else
                {
                    List <VoucherItemsModel> voucherItemsList = new List <VoucherItemsModel>();
                    int          DisbursementID = (int)voucherlistdg.SelectedValue;
                    Disbursement disbursement   = db.Disbursements.Find(DisbursementID);
                    foreach (var voucherItem in disbursement.DisbursementItems)
                    {
                        var item = new VoucherItemsModel()
                        {
                            Explanation = voucherItem.Explanation,
                            Amount      = String.Format("{0:n}", voucherItem.Amount)
                        };
                        voucherItemsList.Add(item);
                    }
                    vouchernotb.Text      = disbursement.VoucherNo;
                    datetb.Text           = disbursement.DateCreated.HasValue ? disbursement.DateCreated.Value.ToShortDateString() : null;
                    paymenttypetb.Text    = disbursement.PaymentType;
                    payeetb.Text          = disbursement.Payee == null ? disbursement.PayeeName : disbursement.Payee.CompanyName;
                    projectnametb.Text    = disbursement.ProjectName;
                    departmenttb.Text     = disbursement.Department == null ? null : disbursement.Department.DepartmentName;
                    obligatedcb.IsChecked = disbursement.Obligated;
                    documentcb.IsChecked  = disbursement.DocCompleted;
                    decimal totalAmount = disbursement.DisbursementItems.Sum(m => m.Amount);
                    amounttb.Text = String.Format("{0:n}", totalAmount);
                    voucheritemsdg.ItemsSource = voucherItemsList;
                    Mouse.OverrideCursor       = null;
                }
            }
            else
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }

            Mouse.OverrideCursor = null;
        }