Example #1
0
        private void EditLoan(Loan editLoan)
        {
            LoanForm loanForm = new LoanForm(editLoan);

            loanForm.ShowDialog();

            if (loanForm.DialogResult == DialogResult.OK)
            {
                Loan oldLoan = editLoan;
                Loan newLoan = loanForm.Loan;

                string loanProfileName = oldLoan.LoanProfileName;
                newLoan.LoanProfileName = loanProfileName;

                LoanProfile profile = data.LoanProfiles.SingleOrDefault(x => x.Name == loanProfileName);

                if (profile != null)
                {
                    if (profile.Loans != null)
                    {
                        List <Loan> targetLoans = profile.Loans.Where(x => x.Name == oldLoan.Name).ToList();

                        foreach (var item in targetLoans)
                        {
                            profile.Loans.Remove(item);
                        }

                        profile.Loans.Add(newLoan);
                    }
                    else
                    {
                        profile.Loans = new List <Loan>();
                        profile.Loans.Add(newLoan);
                    }
                }

                data.SelectedLoan = newLoan;
                BindTreeView();
                BindSelectedLoan();
                Program.UpdateDatabase(data);
            }
        }
Example #2
0
        private void CreateNewLoan()
        {
            LoanForm loanForm = new LoanForm();

            loanForm.ShowDialog();

            if (loanForm.DialogResult == DialogResult.OK)
            {
                LoanProfile profile = data.LoanProfiles.SingleOrDefault(x => x.Name == clickedNode.Split(':')[1]);

                if (profile != null)
                {
                    if (profile.Loans != null)
                    {
                        loanForm.Loan.LoanProfileName = profile.Name;

                        while (profile.Loans.Any(x => x.Name == loanForm.Loan.Name))
                        {
                            loanForm.Loan.Name += " - duplicate";
                        }
                        profile.Loans.Add(loanForm.Loan);
                    }
                    else
                    {
                        loanForm.Loan.LoanProfileName = profile.Name;
                        profile.Loans = new List <Loan>();
                        profile.Loans.Add(loanForm.Loan);
                    }
                }

                data.SelectedLoan = loanForm.Loan;
                BindTreeView();
                BindSelectedLoan();
                Program.UpdateDatabase(data);
            }
        }