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

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

            // Show the dialog
            Keyword_dialog.Title        = row.Keyword;
            Keyword_dialog.TitleTooltip = "GK #" + row.GK.ToString();

            // Disable editing keyword value
            _keywordValueField.IsEnabled = false;

            Keyword_dialog.BeginEdit(
                Dialog_MakeEditVersion <Oltp.KeywordDataTable, Oltp.KeywordRow>(_keywords, row),
                row
                );

            TabControl tabs = Visual.GetDescendant <TabControl>(Keyword_dialog);

            if (tabs.SelectedIndex == 1)
            {
                AssociationsTabItem_GotFocus(null, null);
            }

            // 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;
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        private void AssociationsTabItem_GotFocus(object sender, RoutedEventArgs e)
        {
            if (!(Keyword_dialog.TargetContent is Oltp.KeywordRow))
            {
                return;
            }

            // Show
            if (_assoc_Campaigns == null)
            {
                _assoc_Campaigns = Visual.GetDescendant <ItemsControl>(Keyword_dialog, "_assoc_Campaigns");
            }

            if (_assoc_Campaigns.ItemsSource != null)
            {
                return;
            }

            Oltp.KeywordRow keyword = (Keyword_dialog.TargetContent as Oltp.KeywordRow);
            List <CampaignAdgroupCombination> duos = null;

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    duos = new List <CampaignAdgroupCombination>();
                    Oltp.AdgroupDataTable adgroups = proxy.Service.Adgroup_GetByKeyword(keyword.GK);

                    if (adgroups.Rows.Count > 0)
                    {
                        // Get all parent campaign IDs
                        List <long> campaignGKs = new List <long>();
                        foreach (Oltp.AdgroupRow ag in adgroups.Rows)
                        {
                            if (!campaignGKs.Contains(ag.CampaignGK))
                            {
                                campaignGKs.Add(ag.CampaignGK);
                            }
                        }

                        // Now get the campaigns themselves
                        Oltp.CampaignDataTable campaigns = proxy.Service.Campaign_GetIndividualCampaigns(campaignGKs.ToArray());
                        foreach (Oltp.AdgroupRow ag in adgroups.Rows)
                        {
                            DataRow[] rs = campaigns.Select(String.Format("GK = {0}", ag.CampaignGK));
                            if (rs.Length > 0)
                            {
                                duos.Add(new CampaignAdgroupCombination(rs[0] as Oltp.CampaignRow, ag));
                            }
                        }
                    }
                }
            },
                                  delegate()
            {
                _assoc_Campaigns.ItemsSource = duos;
            });
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        private void Keyword_ChangeMonitoring(object sender, RoutedEventArgs e)
        {
            bool monitor = sender == _buttonMonitor;

            // First mark the correct monitoring state
            foreach (Oltp.KeywordRow kw in _listTable._listView.SelectedItems)
            {
                kw.IsMonitored = monitor;
            }


            try
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    proxy.Service.Keyword_Save(Oltp.Prepare <Oltp.KeywordDataTable>(_keywords));
                }
            }
            catch (Exception ex)
            {
                // Failed, so cancel and display a message
                MessageBoxError("Keywords could not be updated.", ex);
                _keywords.RejectChanges();
                return;
            }

            Oltp.KeywordRow[] rowsToIterate = new Oltp.KeywordRow[_listTable._listView.SelectedItems.Count];
            _listTable._listView.SelectedItems.CopyTo(rowsToIterate, 0);

            foreach (Oltp.KeywordRow kw in rowsToIterate)
            {
                if (_filterCheckbox.IsChecked == false && !monitor)
                {
                    // Remove keywords that have been unmonitored
                    kw.Delete();
                    _items.Remove(kw);
                }
                else
                {
                    ListViewItem item = _listTable._listView.ItemContainerGenerator.ContainerFromItem(kw) as ListViewItem;

                    // Apply the correcy template
                    (this.Resources["NameTemplateSelector"] as MasterKeywordsLocal.NameTemplateSelector)
                    .ApplyTemplate(kw, item);
                }
            }

            _keywords.AcceptChanges();
        }
Beispiel #4
0
        /*=========================*/
        #endregion

        #region Keywords
        /*=========================*/

        /// <summary>
        /// Add a gateway to an dataItem
        /// </summary>
        private void Keyword_AddClick(object sender, RoutedEventArgs e)
        {
            // Create an editable new row
            Oltp.KeywordRow editVersion = Dialog_MakeEditVersion <Oltp.KeywordDataTable, Oltp.KeywordRow>(_keywords, null);
            editVersion.AccountID   = this.Window.CurrentAccount.ID;
            editVersion.IsMonitored = true;

            // Show the dialog
            Keyword_dialog.Title = "New Keyword";

            // Enable editing keyword value
            _keywordValueField.IsEnabled = true;

            Keyword_dialog.BeginEdit(editVersion, _keywords);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        private void Keyword_dialog_AppliedChanges(object sender, CancelRoutedEventArgs e)
        {
            Oltp.KeywordRow dataItem = Keyword_dialog.TargetContent as Oltp.KeywordRow;

            // Call the univeral applied change handler
            Dialog_AppliedChanges <Oltp.KeywordRow>(Keyword_dialog, dataItem.Keyword, _listTable._listView, e);

            // Disable editing keyword value
            _keywordValueField.IsEnabled = false;

            // Set correct data template
            ListViewItem item = _listTable._listView.ItemContainerGenerator.ContainerFromItem(dataItem) as ListViewItem;

            (this.Resources["NameTemplateSelector"] as MasterKeywordsLocal.NameTemplateSelector)
            .ApplyTemplate(dataItem, item);
        }
Beispiel #6
0
        public void ApplyTemplate(Oltp.KeywordRow dataItem, ListViewItem item)
        {
            if (item == null)
            {
                return;
            }

            Button nameButton = Visual.GetDescendant <Button>(item, "_itemName");

            if (nameButton == null)
            {
                return;
            }

            ContentPresenter cp = VisualTreeHelper.GetParent(nameButton) as ContentPresenter;

            cp.ContentTemplate = SelectTemplate(dataItem, item);
        }
Beispiel #7
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            Oltp.KeywordRow kw = item as Oltp.KeywordRow;

            if (kw == null)
            {
                return(new DataTemplate());
            }
            else if (kw.IsMonitored)
            {
                return(App.CurrentPage
                       .FindResource("MonitoredNameTemplate") as DataTemplate);
            }
            else
            {
                return(App.CurrentPage
                       .FindResource("UnmonitoredNameTemplate") as DataTemplate);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Open the dialog
        /// </summary>
        private void Keyword_dialog_Open(object sender, RoutedEventArgs e)
        {
            // Set dataItem as current item
            ListViewItem currentItem = _listTable.GetParentListViewItem(e.OriginalSource as FrameworkElement);

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

            // Show the dialog
            Keyword_dialog.Title        = row.Keyword;
            Keyword_dialog.TitleTooltip = "GK #" + row.GK.ToString();

            // Disable editing keyword value
            if (_keywordValueField != null)
            {
                _keywordValueField.IsEnabled = false;
            }

            Keyword_dialog.BeginEdit(
                Dialog_MakeEditVersion <Oltp.KeywordDataTable, Oltp.KeywordRow>(row),
                row
                );
        }