コード例 #1
0
        /// <summary>
        /// Open the dialog
        /// </summary>
        private void Segment_dialog_Open(object sender, RoutedEventArgs e)
        {
            // Set dataItem as current item
            ListViewItem currentItem = _listTable.GetParentListViewItem(e.OriginalSource as FrameworkElement);

            Oltp.SegmentRow row = currentItem.Content as Oltp.SegmentRow;

            // Show the dialog
            Segment_dialog.Title        = row.Name;
            Segment_dialog.TitleTooltip = row.SegmentID.ToString();

            Segment_dialog.BeginEdit(
                Dialog_MakeEditVersion <Oltp.SegmentDataTable, Oltp.SegmentRow>(row),
                row
                );

            TabControl tabs    = VisualTree.GetChild <TabControl>(Segment_dialog);
            TabItem    tabItem = (TabItem)tabs.ItemContainerGenerator.ContainerFromIndex(tabs.SelectedIndex);

            if (tabItem != null)
            {
                tabItem.RaiseEvent(new RoutedEventArgs(TabItem.GotFocusEvent, tabItem));
            }

            // When opening, select it only if no more than one is already selected
            if (_listTable.ListView.SelectedItems.Count < 2)
            {
                _listTable.ListView.SelectedItems.Clear();
                currentItem.IsSelected = true;
            }
        }
コード例 #2
0
        /*=========================*/
        #endregion

        #region Profiles
        /*=========================*/

        /// <summary>
        ///
        /// </summary>
        private void Segment_Add(object sender, RoutedEventArgs e)
        {
            // Create an editable new ro
            Oltp.SegmentRow editVersion = Dialog_MakeEditVersion <Oltp.SegmentDataTable, Oltp.SegmentRow>(null);
            editVersion.AccountID = this.Window.CurrentAccount.ID;

            // Show the dialog
            Segment_dialog.Title = "New Segment";
            Segment_dialog.BeginEdit(editVersion, _segments);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        private void Segment_dialog_ApplyingChanges(object sender, CancelRoutedEventArgs e)
        {
            Oltp.SegmentRow editVersion = Segment_dialog.Content as Oltp.SegmentRow;
            bool            isNew       = editVersion.RowState == DataRowState.Added;

            if (IsMissingData(isNew, _segmentValuesTable))
            {
                MainWindow.MessageBoxError("At least one value is required for a segment.", null);
                e.Cancel = true;
                return;
            }

            List <TextBox> textboxes = VisualTree.GetChildren <TextBox>(_segmentValuesListTable);

            foreach (TextBox textbox in textboxes)
            {
                if (Validation.GetHasError(textbox))
                {
                    MainWindow.MessageBoxError("You have one or more errors. Please correct them before continuing.", null);
                    e.Cancel = true;
                    return;
                }
            }

            Dialog_ApplyingChanges <Oltp.SegmentDataTable, Oltp.SegmentRow>(
                _segments,
                Segment_dialog,
                typeof(IOltpLogic).GetMethod("Segment_Save"),
                e,
                null,
                true,
                delegate()
            {
                if (e.Cancel)
                {
                    return;
                }

                if (_segmentValuesTable == null || _segmentValuesTable.GetChanges() == null)
                {
                    Segment_dialog.EndApplyChanges(e);
                    return;
                }

                ObservableCollection <DataRow> source =
                    _segmentValuesListTable.ListView.ItemsSource as ObservableCollection <DataRow>;

                for (int i = 0; i < source.Count; i++)
                {
                    if (source[i].RowState != DataRowState.Added)
                    {
                        continue;
                    }

                    (source[i] as Oltp.SegmentValueRow).AccountID = Window.CurrentAccount.ID;
                    (source[i] as Oltp.SegmentValueRow).SegmentID = (Segment_dialog.TargetContent as Oltp.SegmentRow).SegmentID;
                }

                // Save -- async
                Window.AsyncOperation(delegate()
                {
                    using (OltpProxy proxy = new OltpProxy())
                    {
                        Oltp.SegmentValueDataTable returnedTable = proxy.Service.SegmentValue_Save(_segmentValuesTable);
                        if (returnedTable != null)
                        {
                            _segmentValuesTable = returnedTable;
                        }
                        else
                        {
                            _segmentValuesTable.AcceptChanges();
                        }
                    }
                },
                                      delegate(Exception ex)
                {
                    MainWindow.MessageBoxError("Failed to save segment values.", ex);
                    e.Cancel = true;
                    return(false);
                },
                                      delegate()
                {
                    SetListSource <DataRow>(_segmentValuesTable, _segmentValuesListTable.ListView);

                    // Complete the apply process
                    Segment_dialog.EndApplyChanges(e);
                });
            });
        }