public static void DeleteAll(YearId ticketPrimaryKey) { IEnumerable <TicketPayment> payments = TicketPayment.GetAll(ticketPrimaryKey); foreach (TicketPayment payment in payments) { TicketPayment.Delete(payment.PrimaryKey); } }
public static IEnumerable <TicketPayment> GetAllForTickets(IEnumerable <Ticket> tickets) { foreach (Ticket ticket in tickets) { foreach (TicketPayment ticketPayment in TicketPayment.GetAll(ticket.PrimaryKey)) { yield return(ticketPayment); } } }
/// <summary> /// Update an entry in the TicketPayment table /// </summary> public static bool Update(TicketPayment ticketPayment) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, ticketPayment); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the TicketPayment table /// </summary> public static TicketPayment Get(YearId primaryKey) { TicketPayment result = null; SqlConnection cn = GetConnection(); result = Get(cn, primaryKey); FinishedWithConnection(cn); return(result); }
private static TicketPayment Get(SqlConnection cn, YearId primaryKey) { TicketPayment result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketPayment WHERE (TicketPaymentId=" + primaryKey.Id + " AND TicketPaymentYear=" + primaryKey.Year + ")", cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildTicketPayment(rdr); } } } return(result); }
/// <summary> /// Delete an entry from the TicketPayment table /// </summary> public static bool Delete(YearId primaryKey) { Int32 rowsAffected = 0; SqlConnection cn = GetConnection(); TicketPayment ticketPayment = Get(cn, primaryKey); if (ticketPayment != null) { using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "DELETE FROM TicketPayment WHERE (TicketPaymentId=" + primaryKey.Id + " AND TicketPaymentYear=" + primaryKey.Year + ")"; rowsAffected = sqlCmd.ExecuteNonQuery(); } } FinishedWithConnection(cn); return(rowsAffected != 0); }
/// <summary> /// Add a new entry to the TicketPayment table /// </summary> public static TicketPayment Add(YearId ticketPrimaryKey, int registerDrawerId, int employeeId, double amount, PaymentSource type, CreditCardInfo cardInfo = null) { TicketPayment result = null; DateTime now = DateTime.Now; byte[] encryptedCardInfo = null; if (cardInfo != null) { #if !DEMO byte[] decryptedBytes = cardInfo.SerializeObject(); encryptedCardInfo = AESHelper.Encrypt(decryptedBytes, "ThePriceIsRight"); #else encryptedCardInfo = cardInfo.SerializeObject(); #endif } SqlConnection cn = GetConnection(); string cmd = "AddTicketPayment"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@TicketPaymentYear", SqlDbType.Int, ticketPrimaryKey.Year); BuildSqlParameter(sqlCmd, "@TicketPaymentTicketId", SqlDbType.Int, ticketPrimaryKey.Id); BuildSqlParameter(sqlCmd, "@TicketPaymentRegisterDrawerId", SqlDbType.Int, registerDrawerId); BuildSqlParameter(sqlCmd, "@TicketPaymentEmployeeId", SqlDbType.Int, employeeId); BuildSqlParameter(sqlCmd, "@TicketPaymentAmount", SqlDbType.Float, amount); BuildSqlParameter(sqlCmd, "@TicketPaymentType", SqlDbType.TinyInt, type); BuildSqlParameter(sqlCmd, "@TicketPaymentTime", SqlDbType.DateTime, now); BuildSqlParameter(sqlCmd, "@TicketPaymentCardInfo", SqlDbType.VarBinary, encryptedCardInfo); BuildSqlParameter(sqlCmd, "@TicketPaymentId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new TicketPayment( new YearId(ticketPrimaryKey.Year, Convert.ToInt32(sqlCmd.Parameters["@TicketPaymentId"].Value)), ticketPrimaryKey.Id, registerDrawerId, employeeId, amount, type, now, encryptedCardInfo); } } FinishedWithConnection(cn); return(result); }
private static bool Update(SqlConnection cn, TicketPayment ticketPayment) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE TicketPayment SET TicketPaymentTicketId=@TicketPaymentTicketId,TicketPaymentRegisterDrawerId=@TicketPaymentRegisterDrawerId,TicketPaymentEmployeeId=@TicketPaymentEmployeeId,TicketPaymentAmount=@TicketPaymentAmount,TicketPaymentType=@TicketPaymentType,TicketPaymentTime=@TicketPaymentTime,TicketPaymentCardInfo=@TicketPaymentCardInfo WHERE (TicketPaymentId=@TicketPaymentId AND TicketPaymentYear=@TicketPaymentYear)"; BuildSqlParameter(sqlCmd, "@TicketPaymentYear", SqlDbType.SmallInt, ticketPayment.PrimaryKey.Year); BuildSqlParameter(sqlCmd, "@TicketPaymentId", SqlDbType.Int, ticketPayment.PrimaryKey.Id); BuildSqlParameter(sqlCmd, "@TicketPaymentTicketId", SqlDbType.Int, ticketPayment.TicketId); BuildSqlParameter(sqlCmd, "@TicketPaymentRegisterDrawerId", SqlDbType.Int, ticketPayment.RegisterDrawerId); BuildSqlParameter(sqlCmd, "@TicketPaymentEmployeeId", SqlDbType.Int, ticketPayment.EmployeeId); BuildSqlParameter(sqlCmd, "@TicketPaymentAmount", SqlDbType.Float, ticketPayment.Amount); BuildSqlParameter(sqlCmd, "@TicketPaymentType", SqlDbType.TinyInt, ticketPayment.PaymentType); BuildSqlParameter(sqlCmd, "@TicketPaymentTime", SqlDbType.DateTime, ticketPayment.TransactionTime); BuildSqlParameter(sqlCmd, "@TicketPaymentCardInfo", SqlDbType.VarBinary, ticketPayment.SerializedCardInfo); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }