private void SaveWord(CustomerDetailVM customervm)
        {
            if (!SelectedCustomer.IsValid())
                return;
            // Create Save Dialog
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.DefaultExt = ".docx";
            dlg.Filter = "Word files (*.docx)|*.docx";
            dlg.ShowDialog();

            // Get path
            if (dlg.FileName != "")
            {
                try
                {
                    SelectedCustomer.CreateWord(dlg.FileName);
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    MessageBox.Show("Error:\nCould not save the ticket.", "Error: Save");
                }
            }
        }
        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 SaveUpdateCustomer(CustomerDetailVM customervm)
        {
            if (!SelectedCustomer.IsValid())
                return;
            // Save Changes
            if (_oldCustomer == null)
            {
                // Check if there are enough tickets left
                int ticketIndex = TicketType.GetIndexByID(SelectedCustomer.TicketType);
                if (TicketTypes[ticketIndex].TicketsLeft >= SelectedCustomer.Amount)
                {
                    // Reduce tickets left by the ordered amount
                    TicketType updatedTicketType = TicketTypes[ticketIndex].Copy();
                    updatedTicketType.TicketsLeft = TicketTypes[ticketIndex].TicketsLeft - SelectedCustomer.Amount;
                    TicketType.UpdateTicketType(updatedTicketType);

                    // Insert new order into ticket db
                    SelectedCustomer.ID = Ticket.AddTicket(SelectedCustomer);
                }
            }
            else
            {
                // Check if there is a difference in the ordered tickets or types
                if (_oldCustomer.Amount == SelectedCustomer.Amount && _oldCustomer.TicketType == SelectedCustomer.TicketType)
                {
                    // Nothing special to do, just update the ticket
                    Ticket.UpdateTicket(SelectedCustomer);
                }
                else
                {
                    // Check if there are enough tickets left
                    int newticketIndex = TicketType.GetIndexByID(SelectedCustomer.TicketType);
                    if (TicketTypes[newticketIndex].TicketsLeft >= SelectedCustomer.Amount)
                    {
                        // Reduce tickets left by the ordered amount
                        TicketType updatedTicketType = TicketTypes[newticketIndex].Copy();
                        updatedTicketType.TicketsLeft = TicketTypes[newticketIndex].TicketsLeft - SelectedCustomer.Amount;
                        TicketType.UpdateTicketType(updatedTicketType);

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

                        // Insert update the order in ticket db
                        Ticket.UpdateTicket(SelectedCustomer);
                    }
                }
            }

            // Update GUI
            customervm.ShowEdit = "Visible";
            customervm.ShowCancel = "Hidden";
            customervm.ShowSave = "Hidden";
            Enabled = false;
        }
 private void EditCustomer(CustomerDetailVM customervm)
 {
     customervm.ShowEdit = "Hidden";
     customervm.ShowCancel = "Visible";
     customervm.ShowSave = "Visible";
     customervm.Enabled = true;
 }
        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 CancelUpdateCustomer(CustomerDetailVM customervm)
        {
            // Reset person
            _changeNotify = false;
            SelectedCustomer = _oldCustomer;

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