コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override void OnAccountChanged()
        {
            Oltp.AccountRow value = Window.CurrentAccount;

            //..............................
            // Segments
            _tabSegmentsInitialized = false;
            _segmentValueTables     = new Dictionary <Oltp.SegmentRow, Oltp.SegmentValueDataTable>();

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    _segmentTable = proxy.Service.Segment_Get(value.ID, false);
                    foreach (Oltp.SegmentRow segment in _segmentTable.Rows)
                    {
                        Oltp.SegmentValueDataTable values = proxy.Service.SegmentValue_Get(value.ID, segment.SegmentID);
                        Oltp.SegmentValueRow defaultRow   = values.NewSegmentValueRow();
                        defaultRow.AccountID = value.ID;
                        defaultRow.SegmentID = segment.SegmentID;
                        defaultRow.ValueID   = -1;
                        defaultRow.Value     = "(none)";
                        values.Rows.InsertAt(defaultRow, 0);
                        values.AcceptChanges();
                        _segmentValueTables.Add(segment, values);
                    }
                }
            },
                                  delegate()
            {
                GetCreatives(value, null, false);
            });
        }
コード例 #2
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);
                });
            });
        }