示例#1
0
        /// <summary>
        /// Adds a new entry to the Ticket table
        /// </summary>
        public static Ticket Add(TicketType type, int partyId, int seatingId,
                                 int employeeId, int customerId)
        {
            Ticket   result = null;
            DateTime now    = DateTime.Now;
            short    year   = DayOfOperation.CurrentYear;

            SqlConnection cn = GetConnection();

            using (SqlCommand sqlCmd = new SqlCommand("AddTicket", cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@TicketYear", SqlDbType.SmallInt, year);
                BuildSqlParameter(sqlCmd, "@TicketType", SqlDbType.SmallInt, type);
                BuildSqlParameter(sqlCmd, "@TicketPartyId", SqlDbType.Int, partyId);
                BuildSqlParameter(sqlCmd, "@TicketSeatingId", SqlDbType.Int, seatingId);
                BuildSqlParameter(sqlCmd, "@TicketEmployeeId", SqlDbType.Int, employeeId);
                BuildSqlParameter(sqlCmd, "@TicketCustomerId", SqlDbType.Int, customerId);
                BuildSqlParameter(sqlCmd, "@TicketCreateTime", SqlDbType.DateTime, now);
                BuildSqlParameter(sqlCmd, "@TicketId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new Ticket(YearId.Create(year, Convert.ToInt32(sqlCmd.Parameters["@TicketId"].Value)),
                                        null, type, partyId, seatingId, employeeId, customerId, now, null)
                    {
                        IsBeingModified = true
                    };
                }
            }
            FinishedWithConnection(cn);

            return(result);
        }
示例#2
0
        /// <summary>
        /// Add a new entry to the TicketCoupon table, for a Ticket
        /// </summary>
        public static TicketCoupon AddForTicket(int couponId, YearId ticketPrimaryKey)
        {
            TicketCoupon result = null;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddTicketCoupon";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@TicketCouponYear", SqlDbType.SmallInt, ticketPrimaryKey.Year);
                BuildSqlParameter(sqlCmd, "@TicketCouponCouponId", SqlDbType.Int, couponId);
                BuildSqlParameter(sqlCmd, "@TicketCouponTicketId", SqlDbType.Int, ticketPrimaryKey.Id);
                BuildSqlParameter(sqlCmd, "@TicketCouponTicketItemId", SqlDbType.Int, null);
                BuildSqlParameter(sqlCmd, "@TicketCouponId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new TicketCoupon(
                        new YearId(ticketPrimaryKey.Year,
                                   Convert.ToInt32(sqlCmd.Parameters["@TicketCouponId"].Value)),
                        couponId, ticketPrimaryKey.Id, 0);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
示例#3
0
        /// <summary>
        /// Get an entry from the TicketItem table
        /// </summary>
        public static TicketItem Get(YearId primaryKey)
        {
            SqlConnection cn     = GetConnection();
            TicketItem    result = Get(cn, primaryKey);

            FinishedWithConnection(cn);
            return(result);
        }
示例#4
0
 private TicketCoupon(YearId primaryKey, int couponId, int ticketId,
                      int?ticketItemId)
 {
     PrimaryKey   = primaryKey;
     CouponId     = couponId;
     TicketId     = ticketId;
     TicketItemId = ticketItemId;
 }
示例#5
0
        public static void ClearTicketDiscounts(YearId ticketPrimaryKey)
        {
            IEnumerable <TicketDiscount> discounts = TicketDiscount.GetAll(ticketPrimaryKey);

            foreach (TicketDiscount discount in discounts)
            {
                TicketDiscount.Delete(discount.PrimaryKey);
            }
        }
示例#6
0
        public static void DeleteAll(YearId ticketPrimaryKey)
        {
            IEnumerable <TicketPayment> payments = TicketPayment.GetAll(ticketPrimaryKey);

            foreach (TicketPayment payment in payments)
            {
                TicketPayment.Delete(payment.PrimaryKey);
            }
        }
示例#7
0
 private TicketItemOption(YearId primaryKey, int itemOptionId, int ticketItemId,
                          TicketItemOptionType type, int changeCount)
 {
     PrimaryKey   = primaryKey;
     ItemOptionId = itemOptionId;
     TicketItemId = ticketItemId;
     Type         = type;
     ChangeCount  = changeCount;
 }
示例#8
0
 private TicketDelivery(YearId primaryKey, int ticketId, int employeeId,
                        DateTime departTime, DateTime?returnTime)
 {
     PrimaryKey       = primaryKey;
     DeliveryDriverId = employeeId;
     TicketId         = ticketId;
     DepartTime       = departTime;
     ReturnTime       = returnTime;
 }
示例#9
0
        public static void ClearTicketCoupons(YearId ticketPrimaryKey)
        {
            IEnumerable <TicketCoupon> coupons = TicketCoupon.GetAll(ticketPrimaryKey);

            foreach (TicketCoupon coupon in coupons)
            {
                TicketCoupon.Delete(coupon.PrimaryKey);
            }
        }
示例#10
0
 /// <summary>
 /// Delete a Ticket table entry
 /// </summary>
 public static bool Delete(YearId primaryKey)
 {
     // Scan existing
     if (Tickets.Keys.Contains(primaryKey))
     {
         Tickets.Remove(primaryKey);
     }
     return(Ticket.Delete(primaryKey));
 }
示例#11
0
        /// <summary>
        /// Gets all entries for the specified ticket key
        /// </summary>
        /// <param name="ticketPrimaryKey"></param>
        /// <param name="getCanceled"></param>
        /// <param name="getOnlyUnmade"></param>
        /// <returns></returns>
        public static IEnumerable <TicketItem> GetAll(YearId ticketPrimaryKey,
                                                      bool getCanceled = true, bool getOnlyUnmade = false)
        {
            SqlConnection cn  = GetConnection();
            SqlCommand    cmd = null;

            try
            {
                if (getOnlyUnmade)
                {
                    if (getCanceled)
                    {
                        cmd = new SqlCommand("SELECT * FROM TicketItem WHERE (" +
                                             "TicketItemYear=" + ticketPrimaryKey.Year + " AND " +
                                             "TicketItemTicketId=" + ticketPrimaryKey.Id + " AND " +
                                             "(TicketItemOrderTime IS NULL))", cn);
                    }
                    else
                    {
                        cmd = new SqlCommand("SELECT * FROM TicketItem WHERE (" +
                                             "TicketItemYear=" + ticketPrimaryKey.Year + " AND " +
                                             "TicketItemTicketId=" + ticketPrimaryKey.Id + " AND " +
                                             "(TicketItemWhenCanceled IS NULL) AND " +
                                             "(TicketItemOrderTime IS NULL))", cn);
                    }
                }
                else if (getCanceled)
                {
                    cmd = new SqlCommand("SELECT * FROM TicketItem WHERE (" +
                                         "TicketItemYear=" + ticketPrimaryKey.Year + " AND " +
                                         "TicketItemTicketId=" + ticketPrimaryKey.Id + ")", cn);
                }
                else
                {
                    cmd = new SqlCommand("SELECT * FROM TicketItem WHERE (" +
                                         "TicketItemYear=" + ticketPrimaryKey.Year + " AND " +
                                         "TicketItemTicketId=" + ticketPrimaryKey.Id + " AND " +
                                         "(TicketItemWhenCanceled IS NULL))", cn);
                }
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        yield return(BuildTicketItem(rdr));
                    }
                }
            }
            finally
            {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                FinishedWithConnection(cn);
            }
        }
示例#12
0
 private TicketVoid(YearId primaryKey, int employeeId, int ticketId,
                    int?ticketItemId, DateTime when, double amount)
 {
     PrimaryKey   = primaryKey;
     EmployeeId   = employeeId;
     TicketId     = ticketId;
     TicketItemId = ticketItemId;
     When         = when;
     Amount       = amount;
 }
示例#13
0
 private TicketDiscount(YearId primaryKey, int discountId, int ticketId,
                        int?ticketItemId, double?amount, int?pseudoEmployeeId)
 {
     PrimaryKey       = primaryKey;
     DiscountId       = discountId;
     TicketId         = ticketId;
     TicketItemId     = ticketItemId;
     Amount           = amount;
     PseudoEmployeeId = pseudoEmployeeId;
 }
示例#14
0
        /// <summary>
        /// Get an entry from the TicketRefund table
        /// </summary>
        public static TicketRefund Get(YearId primaryKey)
        {
            TicketRefund result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, primaryKey);
            FinishedWithConnection(cn);

            return(result);
        }
示例#15
0
        /// <summary>
        /// Used for returns
        /// </summary>
        public double GetTax(double itemCost)
        {
            Item   item   = Item.Get(ItemId);
            Tax    tax    = Tax.Get(item.TaxId);
            Ticket ticket = Ticket.Get(YearId.Create(PrimaryKey.Year, TicketId));

            if (item.IsTaxExemptable && (ticket.TaxExemptId != null))
            {
                return(0);
            }
            return(itemCost * tax.Percentage);
        }
示例#16
0
 private TicketRefund(YearId primaryKey, int employeeId, int ticketId,
                      int registerDrawerId, DateTime when, double amount,
                      TicketRefundType refundType)
 {
     PrimaryKey       = primaryKey;
     EmployeeId       = employeeId;
     TicketId         = ticketId;
     RegisterDrawerId = registerDrawerId;
     When             = when;
     Amount           = amount;
     Type             = refundType;
 }
示例#17
0
 private TicketItemReturn(YearId primaryKey, int registerDrawerId, int employeeId,
                          int ticketId, int itemId, int itemQuantity, double amount, DateTime when)
 {
     PrimaryKey       = primaryKey;
     RegisterDrawerId = registerDrawerId;
     EmployeeId       = employeeId;
     TicketId         = ticketId;
     ItemId           = itemId;
     ItemQuantity     = itemQuantity;
     Amount           = amount;
     When             = when;
 }
示例#18
0
 private TicketPayment(YearId primaryKey, int ticketId, int registerDrawerId,
                       int employeeId, double amount, PaymentSource type, DateTime transactionTime,
                       byte[] serializedCardInfo)
 {
     PrimaryKey         = primaryKey;
     TicketId           = ticketId;
     RegisterDrawerId   = registerDrawerId;
     EmployeeId         = employeeId;
     Amount             = amount;
     PaymentType        = type;
     TransactionTime    = transactionTime;
     SerializedCardInfo = serializedCardInfo;
 }
示例#19
0
        public static bool HasOption(YearId primaryKey, int optionItemId)
        {
            bool found = false;

            foreach (TicketItemOption tio in GetAll(primaryKey))
            {
                if (tio.ItemOptionId == optionItemId)
                {
                    found = true;
                    break;
                }
            }
            return(found);
        }
示例#20
0
 private Ticket(YearId primaryKey, int?orderId, TicketType type, int partyId, int seatingId, int serverId,
                int customerId, DateTime createTime,
                DateTime?startTime, DateTime?prepareTime, DateTime?readyTime, DateTime?closeTime,
                string managerNote, bool isCanceled, string taxExemptId)
     : this(primaryKey, orderId, type, partyId, seatingId, serverId, customerId, createTime, taxExemptId)
 {
     ManagerNote     = managerNote;
     IsCanceled      = isCanceled;
     StartTime       = startTime;
     PrepareTime     = prepareTime;
     ReadyTime       = readyTime;
     CloseTime       = closeTime;
     IsBeingModified = false;
 }
示例#21
0
        /// <summary>
        /// Delete an entry from the TicketDelivery table, by ticket id
        /// </summary>
        public static void DeleteByTicket(YearId ticketPrimaryKey)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "DELETE FROM TicketDelivery WHERE (" +
                                     "TicketDeliveryYear=" + ticketPrimaryKey.Year + " AND " +
                                     "TicketDeliveryTicketId=" + ticketPrimaryKey.Id + ")";
                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            FinishedWithConnection(cn);
            return;
        }
        private void PopulateDestinationList()
        {
            listBoxDestinationTicket.Items.Clear();

            foreach (FormattedListBoxItem item in listboxSourceTicket.Items)
            {
                if (item.IsSelected)
                {
                    continue;
                }
                YearId primaryKey = (YearId)item.ReferenceObject;
                listBoxDestinationTicket.Items.Add(
                    new FormattedListBoxItem(primaryKey, item.Text));
            }
        }
示例#23
0
        /// <summary>
        /// Delete an entry from the TicketDiscount table for a specific ticketItem
        /// </summary>
        public static bool DeleteForTicketItem(YearId ticketItemPrimaryKey)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "DELETE FROM TicketDiscount WHERE (" +
                                     "TicketDiscountYear=" + ticketItemPrimaryKey.Year + " AND " +
                                     "TicketDiscountTicketItemId=" + ticketItemPrimaryKey.Id + ")";
                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
示例#24
0
        private static TicketRefund Get(SqlConnection cn, YearId primaryKey)
        {
            TicketRefund result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketRefund WHERE (TicketRefundId=" + primaryKey.Id + " AND TicketRefundYear=" + primaryKey.Year + ")", cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildTicketRefund(rdr);
                    }
                }
            }
            return(result);
        }
示例#25
0
        private static TicketDiscount Get(SqlConnection cn, YearId primaryKey)
        {
            TicketDiscount result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketDiscount WHERE TicketDiscountId=" + primaryKey.Id + " AND TicketDiscountYear=" + primaryKey.Year, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildTicketDiscount(rdr);
                    }
                }
            }
            return(result);
        }
示例#26
0
        public static TicketItemOption Add(int ticketItemId, int itemOptionId,
                                           TicketItemOptionType type, int changeCount)
        {
            TicketItemOption result = null;
            short            year   = DayOfOperation.CurrentYear;
            YearId           ticketItemPrimaryKey = new YearId(year, ticketItemId);

            changeCount = changeCount.Clamp(0, 255);

            // Cache old before making a change
            TicketItem ticketItem = TicketItem.Get(ticketItemPrimaryKey);

            if (!ticketItem.IsTicketItemOptionsChanged)
            {
                TicketItem.CacheTicketItemOptions(ticketItem);
            }

            SqlConnection cn = GetConnection();

            using (SqlCommand sqlCmd = new SqlCommand("AddTicketItemOption", cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@TicketItemOptionItemOptionId", SqlDbType.Int, itemOptionId);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionTicketItemId", SqlDbType.Int, ticketItemId);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionType", SqlDbType.TinyInt, type);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionChangeCount", SqlDbType.TinyInt, changeCount);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionYear", SqlDbType.SmallInt, year);
                BuildSqlParameter(sqlCmd, "@TicketItemOptionId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new TicketItemOption(new YearId(year, Convert.ToInt32(sqlCmd.Parameters["@TicketItemOptionId"].Value)),
                                                  itemOptionId, ticketItemId, type, changeCount);
                }
            }
            FinishedWithConnection(cn);

            if (result != null)
            {
                SetTicketItemIsChanged(ticketItem);
            }

            // Reduce the inventory
            TicketItemOption.AdjustInventory(result, ticketItem.Quantity, false);

            return(result);
        }
示例#27
0
        /// <summary>
        /// Delete an entry from the TicketDiscount table
        /// </summary>
        public static bool Delete(YearId primaryKey)
        {
            Int32          rowsAffected   = 0;
            SqlConnection  cn             = GetConnection();
            TicketDiscount ticketDiscount = Get(cn, primaryKey);

            if (ticketDiscount != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM TicketDiscount WHERE (TicketDiscountId=" + primaryKey.Id + " AND TicketDiscountYear=" + primaryKey.Year + ")";
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
示例#28
0
        public static IEnumerable <TicketItemOption> GetAll(YearId ticketItemPrimaryKey)
        {
            SqlConnection cn = GetConnection();

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketItemOption WHERE (" +
                                                   "TicketItemOptionYear=" + ticketItemPrimaryKey.Year + " AND " +
                                                   "TicketItemOptionTicketItemId=" + ticketItemPrimaryKey.Id + ")", cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        yield return(BuildTicketItemOption(rdr));
                    }
                }
            }
            FinishedWithConnection(cn);
        }
示例#29
0
        /// <summary>
        /// Get a single ticket from the Ticket table
        /// </summary>
        public static Ticket GetTicket(YearId primaryKey)
        {
            // Scan existing
            if (Tickets.Keys.Contains(primaryKey))
            {
                Ticket.Refresh(Tickets[primaryKey]);
                return(Tickets[primaryKey]);
            }

            // Not found, let's check the database
            Ticket newTicket = Ticket.Get(primaryKey);

            if (newTicket != null)
            {
                Tickets.Add(newTicket.PrimaryKey, newTicket);
                return(newTicket);
            }
            return(null);
        }
示例#30
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);
        }