// Get all accounts for a single customer public Acct[] GetAllAccounts() { // To allow server to work until client header authentication/encryption added if (authInfo == null) { authInfo = tempAuthInfo; } System.Data.SqlClient.SqlDataAdapter adapter; System.Data.SqlClient.SqlCommand cmd; System.Data.SqlClient.SqlConnection conn; string connString = (string)ConfigurationSettings.AppSettings["connectStringWoodgrove"]; conn = new System.Data.SqlClient.SqlConnection(); adapter = new System.Data.SqlClient.SqlDataAdapter(); cmd = new System.Data.SqlClient.SqlCommand(); // // conn // conn.ConnectionString = connString; // // adapter // adapter.SelectCommand = cmd; adapter.TableMappings.AddRange( new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping( "Table", "_GetAccount", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("AccountID", "AccountID"), new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), new System.Data.Common.DataColumnMapping("Description", "Description"), new System.Data.Common.DataColumnMapping("Balance", "Balance"), new System.Data.Common.DataColumnMapping("LastTransactionDate", "LastTransactionDate"), new System.Data.Common.DataColumnMapping("Type", "Type"), new System.Data.Common.DataColumnMapping("InterestRate", "InterestRate"), new System.Data.Common.DataColumnMapping("MinimumBalance", "MinimumBalance") }) } ); // // cmd // cmd.CommandText = "_GetAllAccounts"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, true, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null)); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@userID", System.Data.SqlDbType.NVarChar, 16, System.Data.ParameterDirection.Input, true, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, authInfo.Username)); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.NVarChar, 16, System.Data.ParameterDirection.Input, true, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, authInfo.Password)); // Open connection, fill dataset, close connection conn.Open(); AccountDataSet ds = new AccountDataSet(); int nRecords = adapter.Fill(ds); conn.Close(); // Check that records exists if (nRecords == 0) { return(null); } // Allocate one per account Acct[] a = new Acct[ds._GetAccount.Count]; for (int i = 0; i < ds._GetAccount.Count; i++) { // Set account information to return if (ds._GetAccount[i].Type == "SV") { SavingsAcct sa = new SavingsAcct(); sa.InterestRate = ds._GetAccount[i].InterestRate; a[i] = sa; } else if (ds._GetAccount[i].Type == "CK") { CheckingAcct ca = new CheckingAcct(); ca.MinimumBalance = ds._GetAccount[i].MinimumBalance; a[i] = ca; } a[i].AccountID = ds._GetAccount[i].AccountID; a[i].Description = ds._GetAccount[i].Description; a[i].Type = ds._GetAccount[i].Type; a[i].Balance = ds._GetAccount[i].Balance; a[i].lastTransaction = (ds._GetAccount[i].IsLastTransactionDateNull() ? new DateTime(0) : ds._GetAccount[i].LastTransactionDate); } return(a); }
// Get all accounts for a single customer public Acct[] GetAllAccounts() { // To allow server to work until client header authentication/encryption added if (authInfo == null) authInfo = tempAuthInfo; System.Data.SqlClient.SqlDataAdapter adapter; System.Data.SqlClient.SqlCommand cmd; System.Data.SqlClient.SqlConnection conn; string connString = (string)ConfigurationSettings.AppSettings["connectStringWoodgrove"]; conn = new System.Data.SqlClient.SqlConnection(); adapter = new System.Data.SqlClient.SqlDataAdapter(); cmd = new System.Data.SqlClient.SqlCommand(); // // conn // conn.ConnectionString = connString; // // adapter // adapter.SelectCommand = cmd; adapter.TableMappings.AddRange( new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping( "Table", "_GetAccount", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("AccountID", "AccountID"), new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), new System.Data.Common.DataColumnMapping("Description", "Description"), new System.Data.Common.DataColumnMapping("Balance", "Balance"), new System.Data.Common.DataColumnMapping("LastTransactionDate", "LastTransactionDate"), new System.Data.Common.DataColumnMapping("Type", "Type"), new System.Data.Common.DataColumnMapping("InterestRate", "InterestRate"), new System.Data.Common.DataColumnMapping("MinimumBalance", "MinimumBalance") }) } ); // // cmd // cmd.CommandText = "_GetAllAccounts"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, true, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null)); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@userID", System.Data.SqlDbType.NVarChar, 16, System.Data.ParameterDirection.Input, true, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, authInfo.Username)); cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.NVarChar, 16, System.Data.ParameterDirection.Input, true, ((System.Byte)(10)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, authInfo.Password)); // Open connection, fill dataset, close connection conn.Open(); AccountDataSet ds = new AccountDataSet(); int nRecords = adapter.Fill(ds); conn.Close(); // Check that records exists if (nRecords == 0) return null; // Allocate one per account Acct[] a = new Acct[ds._GetAccount.Count]; for (int i = 0; i < ds._GetAccount.Count; i++) { // Set account information to return if (ds._GetAccount[i].Type == "SV") { SavingsAcct sa = new SavingsAcct(); sa.InterestRate = ds._GetAccount[i].InterestRate; a[i] = sa; } else if (ds._GetAccount[i].Type == "CK") { CheckingAcct ca = new CheckingAcct(); ca.MinimumBalance = ds._GetAccount[i].MinimumBalance; a[i] = ca; } a[i].AccountID = ds._GetAccount[i].AccountID; a[i].Description = ds._GetAccount[i].Description; a[i].Type = ds._GetAccount[i].Type; a[i].Balance = ds._GetAccount[i].Balance; a[i].lastTransaction = (ds._GetAccount[i].IsLastTransactionDateNull() ? new DateTime(0) : ds._GetAccount[i].LastTransactionDate); } return a; }