private void TicketForm_Load(object sender, EventArgs e)
        {
            //Create a database context to access the database
            CustomerPurchaseContext db = new CustomerPurchaseContext();

            //Set the amount of minuted to be added based on the user input in the OptionsForm
            minutes = OptionsForm.input.MinutesPerWindow;

            //Set next entry time based on minutes per window that the user input in the options form
            nextEntryTime = DateTime.Now.AddMinutes(minutes).AddSeconds(-DateTime.Now.Second);

            //Set the next entry time display (only used for the list box)
            nextEntryTimeDisplay = nextEntryTime;

            //Set the ticket to be issued
            Ticket = 0;

            //Set the next entry ticket
            nextEntryTicket = 0;

            //Display the guests with following tickets that can enter
            GuestsEnterLabel.Text = Ticket.ToString();

            //Display next available entry
            NextEntryLabel.Text = DateTime.Now.AddMinutes(OptionsForm.input.MinutesPerWindow).ToShortTimeString().ToString();
        }
Пример #2
0
 /// <summary>
 /// If customer id is 0, they will be added. Otherwise, it will update based on the customer id
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static CustomerPurchase AddOrUpdate(CustomerPurchase p)
 {
     using (var context = new CustomerPurchaseContext())
     {
         context.Entry(p).State = (p.CustomerId == 0) ? EntityState.Added : EntityState.Modified;
         context.SaveChanges();
         return(p);
     }
 }
Пример #3
0
 public static CustomerPurchase Add(CustomerPurchase p)
 {
     using (var context = new CustomerPurchaseContext())
     {
         context.CustomerPurchases.Add(p);
         context.SaveChanges();
     }
     return(p);
 }
Пример #4
0
 /// <summary>
 /// Updates all customer purchase data (Except for customer id, which is the primary key)
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static CustomerPurchase Update(CustomerPurchase p)
 {
     using (var context = new CustomerPurchaseContext())
     {
         context.CustomerPurchases.Attach(p);
         context.Entry(p).State = EntityState.Modified;
         context.SaveChanges();
         return(p);
     }
 }
Пример #5
0
        /// <summary>
        /// Deletes a customer purchase from the database by their customer id
        /// </summary>
        /// <param name="p"></param>
        public static void Delete(CustomerPurchase p)
        {
            using (var context = new CustomerPurchaseContext())
            {
                context.CustomerPurchases.Add(p);

                context.Entry(p).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
Пример #6
0
 /// <summary>
 /// Returns a list of all the customer purchases sorted by customer id in ascending order
 /// </summary>
 public static List <CustomerPurchase> GetAllCustomerPurchases()
 {
     using (var context = new CustomerPurchaseContext())
     {
         List <CustomerPurchase> purchases = context.CustomerPurchases
                                             .OrderBy(p => p.CustomerId)
                                             .ToList();
         return(purchases);
     }
 }