public static void EditAccount(Account acc) { myConnection.Open(); string commandString = string.Format ("UPDATE Accounts Set AccountType=@AccountType, AccountBalance=@AccountBalance, IsAccountOpen=@IsAccountOpen WHERE AccountID = {0}", acc.AccountID); OleDbCommand myCommand = new OleDbCommand(commandString, myConnection); myCommand.Parameters.AddWithValue("@AccountType", acc.AccountType); myCommand.Parameters.AddWithValue("@AccountBalance", acc.AccountBalance); myCommand.Parameters.AddWithValue("@IsAccountOpen", acc.IsAccountOpen); myCommand.ExecuteNonQuery(); myConnection.Close(); }
public static void AddAccount(Account acc, Customer cust) { myConnection.Open(); string commandString = string.Format ("INSERT INTO Accounts (CustomerID, AccountType, AccountBalance, IsAccountOpen) VALUES (@CustomerID, @AccountType, @AccountBalance, @IsAccountOpen)"); OleDbCommand myCommand = new OleDbCommand(commandString, myConnection); myCommand.Parameters.AddWithValue("@CustomerID", cust.CustomerID); myCommand.Parameters.AddWithValue("@AccountType", acc.AccountType); myCommand.Parameters.AddWithValue("@AccountBalance", acc.AccountBalance); myCommand.Parameters.AddWithValue("@IsAccountOpen", acc.IsAccountOpen); myCommand.ExecuteNonQuery(); myConnection.Close(); }
public static void RemoveAccount(Account acc) { myConnection.Open(); string commandString = string.Format ("DELETE FROM Accounts WHERE AccountID = {0}", acc.AccountID); OleDbCommand myCommand = new OleDbCommand(commandString, myConnection); myCommand.ExecuteNonQuery(); myConnection.Close(); }
public static List<Account> RetrieveAccounts(Customer cust) { myConnection.Open(); string commandString = string.Format ("SELECT * FROM Accounts WHERE CustomerID = {0}", cust.CustomerID); OleDbCommand myCommand = new OleDbCommand(commandString, myConnection); OleDbDataReader myReader = myCommand.ExecuteReader(); while (myReader.Read()) { Account acc = new Account(); acc.AccountID = myReader.GetInt32(0); acc.CustomerID = myReader.GetInt32(1); acc.AccountType = myReader.GetString(2); acc.AccountBalance = myReader.GetDecimal(3); acc.IsAccountOpen = myReader.GetBoolean(4); cust.AccountList.Add(acc); } myReader.Close(); myConnection.Close(); return cust.AccountList; }
private void btnSaveAccount_Click(object sender, EventArgs e) { Account acc; if (ProgramState == State.EditAccount) acc = (Account)lstCustomerAccounts.SelectedItem; else acc = new Account(); try { acc.AccountBalance = Convert.ToDecimal(txtAccountDeposit.Text); acc.IsAccountOpen = true; if (checkChecking.Checked) { acc.AccountType = "Checking"; } else acc.AccountType = "Savings"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Warning!"); return; } if (ProgramState == State.EditAccount) DatabaseService.EditAccount(acc); else DatabaseService.AddAccount(acc, currentCustomer); DisplayAccounts(); ProgramState = State.ViewAccount; }