/// <summary> /// Update an entry in the DirectDeposit table /// </summary> public static bool Update(DirectDeposit directDeposit) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, directDeposit); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the DirectDeposit table /// </summary> public static DirectDeposit Get(int id) { DirectDeposit result = null; SqlConnection cn = GetConnection(); result = Get(cn, id); FinishedWithConnection(cn); return(result); }
private static DirectDeposit Get(SqlConnection cn, int id) { DirectDeposit result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM DirectDeposit WHERE DirectDepositEmployeeId=" + id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildDirectDeposit(rdr); } } } return(result); }
private static bool Update(SqlConnection cn, DirectDeposit directDeposit) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE DirectDeposit SET DirectDepositAccountNumber=@DirectDepositAccountNumber,DirectDepositRoutingNumber=@DirectDepositRoutingNumber,DirectDepositAccountType=@DirectDepositAccountType WHERE DirectDepositEmployeeId=@DirectDepositEmployeeId"; BuildSqlParameter(sqlCmd, "@DirectDepositEmployeeId", SqlDbType.Int, directDeposit.EmployeeId); BuildSqlParameter(sqlCmd, "@DirectDepositAccountNumber", SqlDbType.Text, directDeposit.AccountNumber); BuildSqlParameter(sqlCmd, "@DirectDepositRoutingNumber", SqlDbType.Text, directDeposit.RoutingNumber); BuildSqlParameter(sqlCmd, "@DirectDepositAccountType", SqlDbType.TinyInt, directDeposit.AccountType); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }
/// <summary> /// Delete an entry from the DirectDeposit table /// </summary> public static bool Delete(int id) { Int32 rowsAffected = 0; SqlConnection cn = GetConnection(); DirectDeposit directDeposit = Get(cn, id); if (directDeposit != null) { using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "DELETE FROM DirectDeposit WHERE DirectDepositEmployeeId=" + id; rowsAffected = sqlCmd.ExecuteNonQuery(); } } FinishedWithConnection(cn); return(rowsAffected != 0); }
/// <summary> /// Add a new entry to the DirectDeposit table /// </summary> public static DirectDeposit Add(int employeeId, string accountNumber, string routingNumber, BankAccountType accountType) { DirectDeposit result = null; SqlConnection cn = GetConnection(); string cmd = "AddDirectDeposit"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@DirectDepositEmployeeId", SqlDbType.Int, employeeId); BuildSqlParameter(sqlCmd, "@DirectDepositAccountNumber", SqlDbType.Text, accountNumber); BuildSqlParameter(sqlCmd, "@DirectDepositRoutingNumber", SqlDbType.Text, routingNumber); BuildSqlParameter(sqlCmd, "@DirectDepositAccountType", SqlDbType.TinyInt, accountType); if (sqlCmd.ExecuteNonQuery() > 0) { result = new DirectDeposit(employeeId, accountNumber, routingNumber, accountType); } } FinishedWithConnection(cn); return(result); }
public bool Update() { return(DirectDeposit.Update(this)); }