Exemplo n.º 1
0
        private void EditClient(object sender, RoutedEventArgs e)
        {
            Client          editClient       = currentRoute.Clients.Find(x => x.Name == (string)((Button)sender).Tag);
            NewClientWindow editClientWindow = new NewClientWindow();

            editClientWindow.ClientNameTextBox.Text          = editClient.Name;
            editClientWindow.ClientAddressTextBox.Text       = editClient.Address;
            editClientWindow.SpecialInstructionsTextBox.Text = editClient.SpecialInstructions;
            editClientWindow.HotMealsTextBox.Text            = Convert.ToString(editClient.HotMeals);
            editClientWindow.ColdMealsTextBox.Text           = Convert.ToString(editClient.ColdMeals);
            editClientWindow.PhoneNumberTextBox.Text         = editClient.PhoneNumber;
            editClientWindow.ShowDialog();
            editClient.Name                = editClientWindow.ClientNameTextBox.Text;
            editClient.Address             = editClientWindow.ClientAddressTextBox.Text;
            editClient.SpecialInstructions = editClientWindow.SpecialInstructionsTextBox.Text;
            editClient.HotMeals            = Convert.ToInt32(editClientWindow.HotMealsTextBox.Text);
            editClient.ColdMeals           = Convert.ToInt32(editClientWindow.ColdMealsTextBox.Text);
            editClient.PhoneNumber         = editClientWindow.PhoneNumberTextBox.Text;

            ClientList.ColumnDefinitions.Clear();
            ClientList.RowDefinitions.Clear();
            ClientList.Children.Clear();

            ColumnDefinition ClientNameColumn = new ColumnDefinition {
                Name = "ClientName", Width = new GridLength(360)
            };
            ColumnDefinition ClientAddressColumn = new ColumnDefinition {
                Name = "ClientAddress", Width = new GridLength(360)
            };
            ColumnDefinition ClientEditColumn = new ColumnDefinition {
                Name = "ClientEdit", Width = new GridLength(90)
            };
            ColumnDefinition ClientDeleteColumn = new ColumnDefinition {
                Name = "ClientDelete", Width = new GridLength(90)
            };
            RowDefinition ClientRow = new RowDefinition {
                Name = "ClientRow1", Height = new GridLength(40)
            };

            ClientList.ColumnDefinitions.Add(ClientNameColumn);
            ClientList.ColumnDefinitions.Add(ClientAddressColumn);
            ClientList.ColumnDefinitions.Add(ClientEditColumn);
            ClientList.ColumnDefinitions.Add(ClientDeleteColumn);
            ClientList.RowDefinitions.Add(ClientRow);

            int position = 0;

            foreach (Client client in currentRoute.Clients)
            {
                AppendListExistingClient(client, position++);
            }
            AddCreateNewClientButton();
            SerializeRoutes();
        }
Exemplo n.º 2
0
        public static Client NewClient()
        {
            NewClientWindow win = new NewClientWindow();

            win.ShowDialog();
            try
            {
                Client newClient = new Client {
                    Name = win.ClientNameTextBox.Text, Address = win.ClientAddressTextBox.Text, ColdMeals = Convert.ToInt32(win.ColdMealsTextBox.Text), HotMeals = Convert.ToInt32(win.HotMealsTextBox.Text), SpecialInstructions = win.SpecialInstructionsTextBox.Text, PhoneNumber = win.PhoneNumberTextBox.Text
                };
                return(newClient);
            }
            catch
            {
                System.Windows.MessageBox.Show("Error entering client. Please confirm you are entering valid data and try again");
                return(null);
            }
        }