public CustomerDetailVM()
        {
            TicketTypes = TicketType.GetTicketTypes();
            Tickets = Ticket.GetTickets();

            SelectedCustomer = new Ticket();
            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
Example #2
0
        public static void UpdateTicket(Ticket ticket)
        {
            // If _Tickets is null, create the Observable Collection
            if (_Tickets == null) GetTickets();

            try
            {
                // Update db
                DbParameter param1 = Database.AddParameter("@id", ticket.ID);
                DbParameter param2 = Database.AddParameter("@ticketholder", ticket.TicketHolder);
                DbParameter param3 = Database.AddParameter("@ticketholderemail", ticket.TicketHolderEmail);
                DbParameter param4 = Database.AddParameter("@tickettype", ticket.TicketType);
                DbParameter param5 = Database.AddParameter("@amount", ticket.Amount);
                int affectedRows = Database.ModifyData("UPDATE ticket SET TicketHolder = @ticketholder, TicketHolderEmail = @ticketholderemail, TicketType = @tickettype, Amount = @amount WHERE id = @id", param1, param2, param3, param4, param5);
                if (affectedRows == 0) return;

                // Update _Tickets
                _Tickets[GetIndexByID(ticket.ID)] = ticket;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #3
0
        public static ObservableCollection<Ticket> GetTickets()
        {
            // If _Tickets is null, create the Observable Collection
            if (_Tickets == null)
            {
                try
                {
                    // Create _Tickets
                    _Tickets = new ObservableCollection<Ticket>();

                    // Get data
                    DbDataReader reader = Database.GetData("SELECT * FROM ticket");
                    foreach (DbDataRecord record in reader)
                    {
                        // Create new Ticket
                        Ticket ticket = new Ticket();

                        // Get ID
                        if (DBNull.Value.Equals(record["ID"])) ticket.ID = -1;
                        else ticket.ID = Convert.ToInt32(record["ID"]);

                        // Get TicketHolder
                        if (DBNull.Value.Equals(record["TicketHolder"])) ticket.TicketHolder = "";
                        else ticket.TicketHolder = record["TicketHolder"].ToString();

                        // Get TicketHolderEmail
                        if (DBNull.Value.Equals(record["TicketHolderEmail"])) ticket.TicketHolderEmail = "";
                        else ticket.TicketHolderEmail = record["TicketHolderEmail"].ToString();

                        // Get TicketType
                        if (DBNull.Value.Equals(record["TicketType"])) ticket.TicketType = -1;
                        else ticket.TicketType = Convert.ToInt32(record["TicketType"].ToString());

                        // Get Amount
                        if (DBNull.Value.Equals(record["Amount"])) ticket.Amount = -1;
                        else ticket.Amount = Convert.ToInt32(record["Amount"].ToString());

                        // Add _Tickets
                        _Tickets.Add(ticket);
                    }
                    if (reader != null)
                        reader.Close();
                }

                // Fail
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);

                    // Clear Contactpersons
                    _Tickets.Clear();
                    _Tickets = null;
                }

            }

            // Return _Tickets
            return _Tickets;
        }
Example #4
0
        public static void DeleteTicket(Ticket ticket)
        {
            // If _Tickets is null, create the Observable Collection
            if (_Tickets == null) GetTickets();

            try
            {
                // Add to db
                DbParameter param = Database.AddParameter("@id", ticket.ID);
                int affectedRows = Database.ModifyData("DELETE FROM ticket WHERE id = @id", param);
                if (affectedRows == 0) return;

                // Update _Tickets
                _Tickets.RemoveAt(GetIndexByID(ticket.ID));
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #5
0
        public static int AddTicket(Ticket ticket)
        {
            // If _Tickets is null, create the Observable Collection
            if (_Tickets == null) GetTickets();

            try
            {
                // Add to db
                DbParameter param1 = Database.AddParameter("@ticketholder", ticket.TicketHolder);
                DbParameter param2 = Database.AddParameter("@ticketholderemail", ticket.TicketHolderEmail);
                DbParameter param3 = Database.AddParameter("@tickettype", ticket.TicketType);
                DbParameter param4 = Database.AddParameter("@amount", ticket.Amount);
                DbDataReader reader = Database.GetData("INSERT INTO ticket(TicketHolder, TicketHolderEmail, TicketType, Amount) VALUES(@ticketholder, @ticketholderemail, @tickettype, @amount); SELECT LAST_INSERT_ID() AS ID;", param1, param2, param3, param4);
                foreach (DbDataRecord record in reader)
                {
                    // Get ID
                    if (DBNull.Value.Equals(record["ID"])) ticket.ID = -1;
                    else ticket.ID = Convert.ToInt32(record["ID"]);
                }
                if (reader != null)
                    reader.Close();

                _Tickets.Add(ticket);
                return ticket.ID;
            }

            // Fail
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return -1;
        }
        private void SelectionChanged(CustomerDetailVM customervm)
        {
            if (SelectedCustomer == null) return;
            if (ShowCancel == "Visible") CancelUpdateCustomer(this);

            _oldCustomer = SelectedCustomer.Copy();

            customervm.ShowEdit = "Visible";
            customervm.ShowCancel = "Hidden";
            customervm.ShowSave = "Hidden";
            Enabled = false;
        }
        private void DeleteCustomer(CustomerDetailVM customervm)
        {
            if (SelectedCustomer == null) return;

            // Add the removed tickets from the deleted order again
            int ticketIndex = TicketType.GetIndexByID(_oldCustomer.TicketType);
            TicketType updatedTicketType = TicketTypes[ticketIndex].Copy();
            updatedTicketType.TicketsLeft = TicketTypes[ticketIndex].TicketsLeft + SelectedCustomer.Amount;
            TicketType.UpdateTicketType(updatedTicketType);

            // Remove the order
            Ticket.DeleteTicket(SelectedCustomer);

            SelectedCustomer = new Ticket();
            Enabled = true;
            ShowEdit = "Hidden";
            ShowCancel = "Hidden";
            ShowSave = "Visible";
        }
 private void AddCustomer(CustomerDetailVM customervm)
 {
     SelectedCustomer = new Ticket();
     _oldCustomer = null;
     customervm.ShowEdit = "Hidden";
     customervm.ShowCancel = "Visible";
     customervm.ShowSave = "Visible";
     customervm.Enabled = true;
 }