private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (lblName.Content == "?" || lblDesc.Content == "?"
                    || String.IsNullOrWhiteSpace(txtName.Text))
                {
                    System.Windows.MessageBox.Show("Please input correct format and/or fill all required fields", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                if (status == "Add")
                {
                    using (var ctx = new finalContext())
                    {
                        var num = ctx.Banks.Where(x => x.BankName == txtName.Text).Count();
                        if (num > 0)
                        {
                            return;
                        }

                        Bank bank = new Bank { BankName = txtName.Text, Description = txtDesc.Text, Active = true };


                        var add = from ad in ctx.TempAdresses
                                  select ad;
                        int ctr = 1;
                        foreach (var item in add)
                        {
                            BankAddress bAd = new BankAddress { BankNum = ctr, City = item.City, Province = item.Province, Street = item.Street };
                            ctx.BankAdresses.Add(bAd);
                            ctr++;
                        }

                        AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Added new Bank " + txtName.Text };
                        ctx.AuditTrails.Add(at);

                        ctx.Banks.Add(bank);
                        ctx.SaveChanges();
                        System.Windows.MessageBox.Show("New Bank Added", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                        this.Close();
                    }
                }
                else
                {
                    using (var ctx = new finalContext())
                    {
                        var bank = ctx.Banks.Find(bId);
                        bank.BankName = txtName.Text;
                        bank.Description = txtDesc.Text;
                        AuditTrail at = new AuditTrail { EmployeeID = UserID, DateAndTime = DateTime.Now, Action = "Updated Bank " + txtName.Text };
                        ctx.AuditTrails.Add(at);
                        ctx.SaveChanges();
                        System.Windows.MessageBox.Show("Bank Successfully Updated", "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 btnAddAddress_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (btnAddAddress.Content.ToString() != "Add")
                {
                    if (lblStreet.Content == "?" || lblProvince.Content == "?" || lblCity.Content == "?"
                    || String.IsNullOrWhiteSpace(txtStreet.Text) || String.IsNullOrWhiteSpace(txtProvince.Text) || String.IsNullOrWhiteSpace(txtCity.Text))
                    {
                        System.Windows.MessageBox.Show("Please input correct format and/or fill all required fields");
                        return;
                    }
                }

                if (btnAddAddress.Content.ToString() == "Add")
                {
                    grpAddress.Visibility = Visibility.Visible;
                    btnAddAddress.Content = "Save";
                    btnEdtAddress.Content = "Cancel";
                    btnEdtAddress.IsEnabled = true;
                    btnDelAddress.Visibility = Visibility.Hidden;

                    tbAddress.IsEnabled = false;
                    tbInfo.IsEnabled = false;

                }
                else if (btnAddAddress.Content.ToString() == "Save")
                {
                    if (txtCity.Text == "" || txtProvince.Text == "" || txtStreet.Text == "")
                    {
                        System.Windows.MessageBox.Show("Please complete the required information", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    //for view
                    if (status == "View")
                    {
                        using (var ctx = new finalContext())
                        {
                            var add = ctx.BankAdresses.Where(x => x.BankID == bId).Count();
                            int ctr = add + 1;
                            BankAddress adds = new BankAddress { BankID = bId, BankNum = ctr, Street = txtStreet.Text, Province = txtProvince.Text, City = txtCity.Text };
                            ctx.BankAdresses.Add(adds);
                            ctx.SaveChanges();
                            var adds1 = from ad in ctx.BankAdresses
                                        where ad.BankID == bId
                                        select new { BankNumber = ad.BankNum, Street = ad.Street, Province = ad.Province, City = ad.City };
                            dgAddress.ItemsSource = adds1.ToList();
                        }


                        reset();
                        return;
                    }

                    using (var ctx = new finalContext())
                    {
                        TempAddress add = new TempAddress { Street = txtStreet.Text, Province = txtProvince.Text, City = txtCity.Text };
                        ctx.TempAdresses.Add(add);
                        ctx.SaveChanges();
                        dgAddress.ItemsSource = ctx.TempAdresses.ToList();
                    }

                    reset();
                }
                else
                {
                    //for view
                    if (status == "View")
                    {
                        using (var ctx = new finalContext())
                        {
                            int bankNum = Convert.ToInt32(getRow(dgAddress, 0));
                            var add = ctx.BankAdresses.Where(x => x.BankID == bId && x.BankNum == bankNum).First();
                            add.City = txtCity.Text;
                            add.Province = txtProvince.Text;
                            add.Street = txtStreet.Text;
                            ctx.SaveChanges();
                            var adds = from ad in ctx.BankAdresses
                                       where ad.BankID == bId
                                       select new { BankNumber = ad.BankNum, Street = ad.Street, Province = ad.Province, City = ad.City };
                            dgAddress.ItemsSource = adds.ToList();
                        }
                        reset();
                        return;
                    }


                    using (var ctx = new finalContext())
                    {
                        var add = ctx.TempAdresses.Find(Convert.ToInt32(getRow(dgAddress, 0)));
                        add.City = txtCity.Text;
                        add.Province = txtProvince.Text;
                        add.Street = txtStreet.Text;
                        ctx.SaveChanges();
                        dgAddress.ItemsSource = ctx.TempAdresses.ToList();
                        reset();

                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Runtime Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }