private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var ctx = new finalContext())
                {
                    FPaymentInfo fp = ctx.FPaymentInfo.Find(fId);
                    DepositedCheque dp = ctx.DepositedCheques.Find(fId);
                    MessageBoxResult mr = MessageBox.Show("Are you sure you want to process this transaction?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (mr == MessageBoxResult.Yes)
                    {

                        if (status == "Full")
                        {
                            var fp2 = from f in ctx.FPaymentInfo
                                     where f.LoanID == lID && f.PaymentStatus != "Cleared"
                                     select f;
                            double tot = 0;
                            foreach (var itm in fp2)
                            {
                                itm.PaymentStatus = "Cleared";
                                ClearedCheque cc = new ClearedCheque { FPaymentInfoID = itm.FPaymentInfoID, DateCleared = DateTime.Now };
                            }

                            FPaymentInfo f2 = new FPaymentInfo { Amount = double.Parse(txtAmt.Text), ChequeDueDate = DateTime.Now.Date, ChequeInfo = txtId.Text, LoanID = lID, PaymentNumber = fp2.Count() + 1, PaymentStatus = "Cleared", PaymentDate = DateTime.Now, RemainingBalance = 0 };
                            ctx.FPaymentInfo.Add(f2);
                            var lon = ctx.Loans.Find(lID);
                            lon.Status = "Paid";
                            PaidLoan pl = new PaidLoan { DateFinished = DateTime.Now, LoanID = lID };
                            ctx.PaidLoans.Add(pl);
                            ctx.SaveChanges();
                            ClearedCheque cc2 = new ClearedCheque { DateCleared = DateTime.Now, FPaymentInfoID = f2.FPaymentInfoID };
                            MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                            this.Close();
                            return;
                        }


                        if (chDaif.IsChecked == false)
                        {
                            wpfCheckout frm = new wpfCheckout();
                            frm.status = "Daif";
                            frm.fId = fId;
                            frm.ShowDialog();

                            if (cont == false)
                            {
                                System.Windows.MessageBox.Show("Please pay the DAIF fee first", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }
                        }

                        AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Changed Cheque " + fp.ChequeInfo + " to " + txtId.Text + "" };
                        ctx.AuditTrails.Add(at);
                        fp.PaymentStatus = "Deposited";
                        fp.ChequeInfo = txtId.Text;
                        dp.DepositDate = DateTime.Today.Date;
                        

                        fp.ReturnedCheque.isPaid = true;


                        if (chDaif.IsChecked == true)
                        {
                            fp.Amount = fp.Amount + fp.ReturnedCheque.Fee;
                        }
                        ctx.SaveChanges();
                        MessageBox.Show("Transaction has been successfully processed", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            try
            {
            MessageBoxResult mr = MessageBox.Show("Are you sure you want to clear the selected cheque(s)?","Question",MessageBoxButton.YesNo);
            if (mr == MessageBoxResult.Yes)
            {
                using (var ctx = new finalContext())
                {
                    var chq = from ch in ctx.TempClearings
                              select ch;
                    foreach (var item in chq)
                    {
                        var ch = ctx.FPaymentInfo.Find(item.FPaymentInfoID);
                        ch.PaymentStatus = "Cleared";
                        var ctr = ctx.FPaymentInfo.Where(x=> x.LoanID==item.FPaymentInfo.LoanID && x.PaymentStatus=="Due/Pending").Count();
                        if (ctr > 0)
                        {
                            var ch2 = ctx.FPaymentInfo.Where(x => x.LoanID == item.FPaymentInfo.LoanID && x.PaymentStatus == "Due/Pending").First();
                            ch2.PaymentStatus = "Due";
                        }
                        ClearedCheque cc = new ClearedCheque { FPaymentInfoID = item.FPaymentInfoID, DateCleared = DateTime.Today.Date };
                        ctx.ClearedCheques.Add(cc);
                    }
                    AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Cleared Cheques" };
                    ctx.AuditTrails.Add(at);

                    ctx.SaveChanges();
                    MessageBox.Show("Cheque(s) has/have been successfully cleared", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    this.Close();
                }
            }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }