private void btnCont_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (status == "view")
         {
             using (var ctx = new finalContext())
             {
                 var ctr = ctx.Users.Where(x => x.EmployeeID == ID && x.Password == txtPassword.Password).Count();
                 if (ctr > 0)
                 {
                     wpfUserInfo frm = new wpfUserInfo();
                     frm.status = status;
                     frm.eId = ID;
                     this.Close();
                     frm.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Incorrect Password", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                     txtPassword.Password = "";
                     return;
                 }
             }
         }
         else if (status == "void")
         {
             using (var ctx = new finalContext())
             {
                 var ctr = ctx.Users.Where(x => x.EmployeeID == UserID && x.Password == txtPassword.Password).Count();
                 if (ctr > 0)
                 {
                     var ctr1 = Application.Current.Windows.Count;
                     var frm = Application.Current.Windows[ctr1 - 2] as wpfLoanSearch;
                     frm.cont = true;
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Incorrect Password", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                     txtPassword.Password = "";
                     return;
                 }
             }
         }
         else if (status == "scope")
         {
             using (var ctx = new finalContext())
             {
                 var ctr = ctx.Users.Where(x => x.EmployeeID == ID && x.Password == txtPassword.Password).Count();
                 if (ctr > 0)
                 {
                     wpfUserScopes frm = new wpfUserScopes();
                     frm.ID = eID;
                     this.Close();
                     frm.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Incorrect Password", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                     txtPassword.Password = "";
                     return;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
 }
        private void btnSelect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (status == "Client")
                {
                    var ctr = Application.Current.Windows.Count;
                    if (status2 == "LoanApplication")
                    {
                        int cbId = Convert.ToInt32(getRow(dgClient, 0));

                        using (var ctx = new finalContext())
                        {
                            var c = ctx.Loans.Where(x => (x.Status == "Applied" || x.Status == "Approved" ||
                                x.Status == "Released" || x.Status == "Under Collection" || x.Status == "Closed Account") && (x.ClientID == cbId || x.CoBorrower == cbId)).Count();
                            if (c > 0)
                            {
                                System.Windows.MessageBox.Show("Selected Client cannot become a co-borrower since it has an existing loan taht is not yet finished", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }
                        }

                        var frm = Application.Current.Windows[ctr - 2] as wpfLoanApplication;
                        frm.cbId = Convert.ToInt32(getRow(dgClient, 0));
                        frm.UserID = UserID;
                        using (var ctx = new finalContext())
                        {
                            var agt = ctx.Clients.Find(cbId);
                            String str = "(" + cbId + ")" + agt.FirstName + " " + agt.MiddleName + " " + agt.LastName;
                            frm.txtID.Text = str;
                        }
                    }
                    else if (status2 == "View1")
                    {
                        wpfViewClientInfo frm = new wpfViewClientInfo();
                        frm.status = status2;
                        int myCID = Convert.ToInt32(getRow(dgClient, 0));
                        frm.cID = myCID;
                        frm.UserID = UserID;
                        this.Close();
                        frm.ShowDialog();
                    }
                    else
                    {
                        var frm = Application.Current.Windows[ctr - 2] as wpfSelectClient;
                        frm.txtID.Text = getRow(dgClient, 0);
                        frm.UserID = UserID;
                        if (frm.txtID.Text == "")
                        {
                            return;
                        }
                    }
                    this.Close();
                }
                else if (status == "Agent")
                {
                    var ctr = Application.Current.Windows.Count;
                    var frm = Application.Current.Windows[ctr - 2] as wpfLoanApplication;
                    frm.UserID = UserID;
                    int num = Convert.ToInt32(getRow(dgClient, 0));
                    frm.agentId = num;
                    this.Close();
                }
                else if (status == "CI")
                {
                    var ctr = Application.Current.Windows.Count;
                    var frm = Application.Current.Windows[ctr - 2] as wpfLoanApplication;
                    frm.UserID = UserID;
                    int num = Convert.ToInt32(getRow(dgClient, 0));
                    frm.ciId = num;
                    using (var ctx = new finalContext())
                    {
                        var agt = ctx.Employees.Find(num);
                        String str = "(" + num + ")" + agt.FirstName + " " + agt.MI + " " + agt.LastName;
                        frm.txtCI.Text = str;
                    }
                    this.Close();
                }
                else if (status == "Collector")
                {
                    var ctr = Application.Current.Windows.Count;
                    var frm = Application.Current.Windows[ctr - 2] as wpfMReleasing;
                    frm.UserID = UserID;
                    int num = Convert.ToInt32(getRow(dgClient, 0));
                    frm.ciId = num;
                    using (var ctx = new finalContext())
                    {
                        var agt = ctx.Employees.Find(num);
                        String str = "(" + num + ")" + agt.FirstName + " " + agt.MI + " " + agt.LastName;
                        frm.txtCI.Text = str;
                    }
                    this.Close();
                }
                else if (status == "Collector1")
                {
                    var ctr = Application.Current.Windows.Count;
                    var frm = Application.Current.Windows[ctr - 2] as wpfPassToCollectors;
                    frm.UserID = UserID;
                    int num = Convert.ToInt32(getRow(dgClient, 0));
                    frm.cID = num;
                    using (var ctx = new finalContext())
                    {
                        var agt = ctx.Employees.Find(num);
                        String str = "(" + num + ")" + agt.FirstName + " " + agt.MI + " " + agt.LastName;
                        frm.txtCI.Text = str;
                    }
                    this.Close();
                }
                else if (status == "Employee")
                {
                    int num = Convert.ToInt32(getRow(dgClient, 0));
                    wpfUserInfo frm = new wpfUserInfo();
                    frm.UserID = UserID;
                    frm.eId = num;
                    this.Close();
                    frm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }