private void AutocompleteTextBox_Closed(object sender, RoutedEventArgs e) { AutocompleteTextBox autoComplete = (AutocompleteTextBox)sender; OrderDetailsEntity orderDetails = (OrderDetailsEntity)autoComplete.DataContext; Lite <ProductEntity> product = (Lite <ProductEntity>)autoComplete.SelectedItem; orderDetails.Discount = 0; if (product == null) { orderDetails.UnitPrice = 0; } else { orderDetails.UnitPrice = product.Retrieve().UnitPrice; } dgDetails.CommitEdit(DataGridEditingUnit.Cell, true); }
// Given a quickPasteItem (essential the information representing a single data control and its value), // - add a row to the grid with controls that display that information, // - add a checkbox that can be selected to indicate whether that information should be included in a paste operation private void BuildRow(QuickPasteItem quickPasteItem, int gridRowIndex) { // USE Column: A checkbox to indicate whether the current search row should be used as part of the search Thickness thickness = new Thickness(0, 2, 0, 2); CheckBox useCurrentRow = new CheckBox() { Margin = thickness, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, IsChecked = quickPasteItem.Use, Tag = quickPasteItem }; useCurrentRow.Checked += this.UseCurrentRow_CheckChanged; useCurrentRow.Unchecked += this.UseCurrentRow_CheckChanged; this.UseCheckboxes.Add(useCurrentRow); Grid.SetRow(useCurrentRow, gridRowIndex); Grid.SetColumn(useCurrentRow, GridColumnUse); this.QuickPasteGridRows.Children.Add(useCurrentRow); // LABEL column: The label associated with the control (Note: not the data label) TextBlock controlLabel = new TextBlock() { Margin = new Thickness(5), Text = quickPasteItem.Label, Foreground = quickPasteItem.Use ? Brushes.Black : Brushes.Gray, }; Grid.SetRow(controlLabel, gridRowIndex); Grid.SetColumn(controlLabel, GridColumnLabel); this.QuickPasteGridRows.Children.Add(controlLabel); // Value column: The value is presented as an editable field particular to its control type if (quickPasteItem.ControlType == Constant.Control.Note || quickPasteItem.ControlType == Constant.Control.Counter) { // Notes and Counters both uses a text field, so they can be constructed as a textbox AutocompleteTextBox textBoxValue = new AutocompleteTextBox() { Autocompletions = null, Text = quickPasteItem.Value, Height = ValuesHeight, Width = ValuesWidth, TextWrapping = TextWrapping.NoWrap, VerticalAlignment = VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, IsEnabled = quickPasteItem.Use, Tag = quickPasteItem }; if (quickPasteItem.ControlType == Constant.Control.Note) { textBoxValue.Autocompletions = this.dataEntryControls.AutocompletionGetForNote(quickPasteItem.DataLabel); } // Counter text fields are modified to only allow numeric input if (quickPasteItem.ControlType == Constant.Control.Counter) { textBoxValue.PreviewTextInput += this.Counter_PreviewTextInput; DataObject.AddPastingHandler(textBoxValue, this.Counter_Paste); } textBoxValue.TextChanged += this.NoteOrCounter_TextChanged; Grid.SetRow(textBoxValue, gridRowIndex); Grid.SetColumn(textBoxValue, GridColumnValue); this.QuickPasteGridRows.Children.Add(textBoxValue); } else if (quickPasteItem.ControlType == Constant.Control.FixedChoice) { // Choices use choiceboxes ControlRow controlRow = this.fileDatabase.GetControlFromTemplateTable(quickPasteItem.DataLabel); ComboBox comboBoxValue = new ComboBox() { Height = ValuesHeight, Width = ValuesWidth, // Create the dropdown menu ItemsSource = controlRow.GetChoicesForQuickPasteMenu(), SelectedItem = quickPasteItem.Value, IsEnabled = quickPasteItem.Use, Tag = quickPasteItem }; Grid.SetRow(comboBoxValue, gridRowIndex); Grid.SetColumn(comboBoxValue, GridColumnValue); this.QuickPasteGridRows.Children.Add(comboBoxValue); comboBoxValue.SelectionChanged += this.FixedChoice_SelectionChanged; } else if (quickPasteItem.ControlType == Constant.Control.Flag) { // Flags present checkable checkboxes CheckBox flagCheckBox = new CheckBox() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, IsChecked = !string.Equals(quickPasteItem.Value, Constant.BooleanValue.False, StringComparison.OrdinalIgnoreCase), IsEnabled = quickPasteItem.Use, Tag = quickPasteItem }; flagCheckBox.Checked += this.Flag_CheckedOrUnchecked; flagCheckBox.Unchecked += this.Flag_CheckedOrUnchecked; Grid.SetRow(flagCheckBox, gridRowIndex); Grid.SetColumn(flagCheckBox, GridColumnValue); this.QuickPasteGridRows.Children.Add(flagCheckBox); } else { // We should never get here throw new NotSupportedException(String.Format("Unhandled control type in QuickPasteEditor '{0}'.", quickPasteItem.ControlType)); } this.Note.Visibility = this.QuickPasteEntry.IsAtLeastOneItemPastable() ? Visibility.Collapsed : Visibility.Visible; }