Exemple #1
0
        //method to populate datagrid
        private void PrimeListGrid()
        {
            BLLAccountManager bllAccMgnr     = new BLLAccountManager();
            List <Account>    AccDetailsList = bllAccMgnr.GetAccountDetailsAsList();

            //// set auto generate columns to false
            dgvAccounts.AutoGenerateColumns = false;
            dgvAccounts.ColumnCount         = 7;
            // fit everything to the size of the windows form
            dgvAccounts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //setting the headers
            dgvAccounts.Columns[0].HeaderText       = "Account Number"; // what will be displayed in dgv
            dgvAccounts.Columns[0].DataPropertyName = "AccountNo";      // from column names in SQL Server

            dgvAccounts.Columns[1].HeaderText       = "Account Type";
            dgvAccounts.Columns[1].DataPropertyName = "AccountType";

            dgvAccounts.Columns[2].HeaderText       = "Sort Code";
            dgvAccounts.Columns[2].DataPropertyName = "SortCode";

            dgvAccounts.Columns[3].HeaderText       = "Initial Balance";
            dgvAccounts.Columns[3].DataPropertyName = "InitBal";

            dgvAccounts.Columns[4].HeaderText       = "Current Balance";
            dgvAccounts.Columns[4].DataPropertyName = "CurtBal";

            dgvAccounts.Columns[5].HeaderText       = "Over Draft Limit";
            dgvAccounts.Columns[5].DataPropertyName = "OverDraft";

            dgvAccounts.Columns[6].HeaderText       = "Student ID";
            dgvAccounts.Columns[6].DataPropertyName = "StudentID";

            dgvAccounts.DataSource = AccDetailsList;
        }//end of primeGrid()
Exemple #2
0
        }//End of search button click

        //method to repopulate datagrid with all accounts
        private void btnDisplayAll_Click(object sender, EventArgs e)
        {
            BLLAccountManager manager = new BLLAccountManager();

            List <Account> accs = manager.GetAccountDetailsAsList();

            dgvDisplay.DataSource = accs;
        }//end of display all accs btn
Exemple #3
0
        }//end of GetSelectedStudent

        //method returns selected account from datagrid
        private Account GetSelectedAccount()
        {
            BLLAccountManager bllAccMngr = new BLLAccountManager();

            // inputting a list of Accounts into accList
            accList = bllAccMngr.GetAccountDetailsAsList();

            Account selAccount = null;

            int    studentID = 0;
            string accType   = "";
            // using enum instead of majic numbers
            int studentIDIndex = Convert.ToInt32(Convert.ToInt32(OOP2_SGetAccounts.SPGetAccounts_StudentID));
            int accTypeIndex   = Convert.ToInt32(Convert.ToInt32(OOP2_SGetAccounts.SPGetAccounts_AccountType));
            int rowIndex       = 0;

            if (dgvDisplay.SelectedRows.Count > 0)
            {
                // this ensures you select only 1 row, not multi-select
                rowIndex = dgvDisplay.SelectedRows[0].Index;

                // getting the studentID
                studentID = (int)dgvDisplay.Rows[rowIndex].Cells[studentIDIndex].Value;
                // getting the account type
                accType = dgvDisplay.Rows[rowIndex].Cells[accTypeIndex].Value.ToString();

                // circulating through the list to find the matching student number and account type
                for (int i = 0; i < accList.Count; i++)
                {
                    // checking student id
                    if (accList[i].StudentID == studentID)
                    {
                        // checking matching account type
                        if (accList[i].AccountType == accType)
                        {
                            selAccount = accList[i];
                            break;
                        }
                    }
                }
            }
            return(selAccount);
        }//end of GetSelectedAccount
Exemple #4
0
        }//end of primeGrid()

        //Method eill get details of selected account in the datagrid and will return an object
        private Account GetSelectedAccount()
        {
            BLLAccountManager bllAccMngr = new BLLAccountManager();

            // inputting a list of Accounts into accList
            accList = bllAccMngr.GetAccountDetailsAsList();

            Account selAccount = null;

            int    studentID = 0;
            string accType   = "";
            // as the StudentID is the last column in Main Display dgv - using enum
            int studentIDIndex = Convert.ToInt32(Convert.ToInt32(OOP2_SGetAccounts.SPGetAccounts_StudentID));
            int accTypeIndex   = Convert.ToInt32(Convert.ToInt32(OOP2_SGetAccounts.SPGetAccounts_AccountType));
            int rowIndex       = 0;

            if (dgvAccounts.SelectedRows.Count > 0)
            {
                // this ensures you select only 1 row, not multi-select
                rowIndex = dgvAccounts.SelectedRows[0].Index;

                // getting the studentID
                studentID = (int)dgvAccounts.Rows[rowIndex].Cells[studentIDIndex].Value;
                // getting the account type
                accType = dgvAccounts.Rows[rowIndex].Cells[accTypeIndex].Value.ToString();

                for (int i = 0; i < accList.Count; i++)
                {
                    if (accList[i].StudentID == studentID)
                    {
                        if (accList[i].AccountType == accType)
                        {
                            selAccount = accList[i];
                            break;
                        }
                    }
                }
            }
            return(selAccount);
        }//End of GetSelectedAccount
Exemple #5
0
        }//end of prime

        //method that populates the datagrid and configures the way data is displayd in it
        private void PrimeListGrid(bool clearDataSource)
        {
            if (clearDataSource)
            {
                dgvDisplay.DataSource = null;
            }

            BLLAccountManager bllAccMgnr     = new BLLAccountManager();
            List <Account>    AccDetailsList = bllAccMgnr.GetAccountDetailsAsList();

            dgvDisplay.AutoGenerateColumns = false;
            dgvDisplay.ColumnCount         = 7;
            dgvDisplay.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //setting the headers
            dgvDisplay.Columns[0].HeaderText       = "Account Number"; // what will be displayed in dgv
            dgvDisplay.Columns[0].DataPropertyName = "AccountNo";

            dgvDisplay.Columns[1].HeaderText       = "Account Type";
            dgvDisplay.Columns[1].DataPropertyName = "AccountType";

            dgvDisplay.Columns[2].HeaderText       = "Sort Code";
            dgvDisplay.Columns[2].DataPropertyName = "SortCode";

            dgvDisplay.Columns[3].HeaderText       = "Initial Balance";
            dgvDisplay.Columns[3].DataPropertyName = "InitBal";

            dgvDisplay.Columns[4].HeaderText       = "Current Balance";
            dgvDisplay.Columns[4].DataPropertyName = "CurtBal";

            dgvDisplay.Columns[5].HeaderText       = "Over Draft Limit";
            dgvDisplay.Columns[5].DataPropertyName = "OverDraft";

            dgvDisplay.Columns[6].HeaderText       = "Student ID";
            dgvDisplay.Columns[6].DataPropertyName = "StudentID";

            dgvDisplay.DataSource = AccDetailsList;
        }//end of primeGrid()
        }//end of back

        // Method to to create new account
        // If a student exists it will create a new acount that will be linked to existing student
        // If there is no student it will create a student and a new account
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //variable to control display of succesfull record insetion
            bool success = false;

            BLLAccountManager manager = new BLLAccountManager();

            List <Account> accList = new List <Account>();

            //following two lines are here to chech if we have account type allready created
            List <Account> currentExist = new List <Account>(1);
            List <Account> savingtExist = new List <Account>(1);

            accList = manager.GetAccountDetailsAsList();

            //Creating empty account
            Account acc = new Account();

            int accNo;
            int studIdFromDb = 0;

            if (!ExistingStud)
            {
                if (ValidateChildren(ValidationConstraints.Enabled))
                {
                    PopulateStudent();
                    manager.AddStudent(Student, out studIdFromDb);
                    success = true;
                }
                else
                {
                    success = false;
                }
                //PopulateStudent();
                //manager.AddStudent(Student, out studIdFromDb);

                //manager.AddStudent(Student, out studIdFromDb);
                acc.StudentID = studIdFromDb;
            }
            else if (ExistingStud)
            {
                acc.StudentID = int.Parse(txtStudentId.Text);
            }

            string accType = "";

            //getting all accs for a given student that are current or saving
            currentExist = accList.Where(Account => Account.AccountType == "current" && Account.StudentID == acc.StudentID).ToList();
            savingtExist = accList.Where(Account => Account.AccountType == "saving" && Account.StudentID == acc.StudentID).ToList();

            acc.SortCode = int.Parse(txtSortCode.Text);

            string initBal  = txtInitialBalance.Text;
            int    initBal2 = MoneyTransformer.TransformMoney(initBal);

            acc.InitialBalance = initBal2;
            // setting the current Balance to the same value as the inital balance
            acc.CurrentBalance = initBal2;
            string ovaDraft  = txtOverdraft.Text;
            int    ovaDraft2 = MoneyTransformer.TransformMoney(ovaDraft);

            acc.OverDraftLimit = ovaDraft2;

            if (rdoCurrentAcc.Checked)
            {
                //checking if student has a current account allready
                if (currentExist.Any())
                {
                    MessageBox.Show("Student allready has a current account");
                }
                else
                {
                    accType         = "current";
                    acc.AccountType = accType;

                    if (ValidateChildren(ValidationConstraints.Enabled))
                    {
                        manager.AddAccount(acc, out accNo);
                        success = true;
                    }
                    else
                    {
                        success = false;
                    }
                }
            }
            else if (rdoSavingsAcc.Checked)
            {
                //checking if student has saving account allready.
                if (savingtExist.Any())
                {
                    MessageBox.Show("Student allready has saving account");
                }
                else
                {
                    accType         = "saving";
                    acc.AccountType = accType;
                    if (ValidateChildren(ValidationConstraints.Enabled))
                    {
                        manager.AddAccount(acc, out accNo);
                        success = true;
                    }
                    else
                    {
                        success = false;
                    }
                }
            }

            if (success)
            {
                MessageBox.Show("New Account Created");
            }
            else
            {
                MessageBox.Show("No account created try again with correct details");
            }
        }//end of add acc button click