public string Save(Account anAccount) { int value; if (anAccount.AccountNumber.Length > 7) { value = gateway.Save(anAccount); if (value > 0) { return "Saved Successfully"; } else { return "Save Failed"; } } else { return "Account Number must be 8 characters long"; } }
public List<Account>Search(List< Account> accounts ,string accountno) { accounts=new List<Account>(); SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT cu_accountno,cu_name,cu_openingDate,balance FROM customer WHERE (cu_accountno LIKE'" + accountno + "%')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Account account1 = new Account(); account1.AccountNumber = reader["cu_accountno"].ToString(); account1.CustomerName= reader["cu_name"].ToString(); account1.OpeningDate = reader["cu_openingDate"].ToString(); account1.Balance = decimal.Parse(reader["balance"].ToString()); accounts.Add(account1); } reader.Close(); connection.Close(); return accounts; }
private void saveAccountButton_Click(object sender, EventArgs e) { Account anAccount=new Account(); anAccount.CustomerName = customerNameTextBox.Text; anAccount.Email = emailTextBox.Text; anAccount.AccountNumber = accountNumberTextBox.Text; anAccount.OpeningDate = openingDateTextBox.Text; anAccount.Balance = 0; MessageBox.Show(manager.Save(anAccount)); }
public List<Account> GetData(List<Account>AccountList) { AccountList=new List<Account>(); string query = "SELECT cu_accountno,cu_name,cu_openingdate,balance FROM customer "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Account account=new Account(); account.AccountNumber = reader["cu_accountno"].ToString(); account.CustomerName = reader["cu_name"].ToString(); account.OpeningDate = reader["cu_openingdate"].ToString(); account.Balance = decimal.Parse(reader["balance"].ToString()); AccountList.Add(account); } connection.Close(); return AccountList; }
public int Save(Account anAccount) { string query = "INSERT INTO customer VALUES('"+anAccount.CustomerName+"','"+anAccount.Email+"','"+anAccount.AccountNumber+"','"+anAccount.OpeningDate+"','"+anAccount.Balance+"')"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return rowAffected; }