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

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

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

            Creative_dialog.BeginEdit(
                Dialog_MakeEditVersion <Oltp.CreativeDataTable, Oltp.CreativeRow>(_creatives, row),
                row
                );

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

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

            // Select the item
            currentItem.IsSelected = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        private void TabAssociations_GotFocus(object sender, RoutedEventArgs e)
        {
            if (!(Creative_dialog.TargetContent is Oltp.CreativeRow))
            {
                return;
            }

            // Show
            if (_assoc_Campaigns == null)
            {
                _assoc_Campaigns = VisualTree.GetChild <ItemsControl>(Creative_dialog, "_assoc_Campaigns");
            }

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

            Oltp.CreativeRow creative = (Creative_dialog.TargetContent as Oltp.CreativeRow);
            List <CampaignAdgroupCombination> duos = null;

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    duos = new List <CampaignAdgroupCombination>();
                    Oltp.AdgroupDataTable adgroups = proxy.Service.Adgroup_GetByCreative(creative.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;
            });
        }
        public ActionResult EditCreative(long creativeGK)
        {
            Models.CreativeModel m = new Models.CreativeModel();

            using (var client = new OltpLogicClient(session_id))
            {
                Oltp.CreativeRow creative = client.Service.Creative_GetSingle(creativeGK)[0];
                //client.Service.Creative_Get(
                m.Creative = creative;

                Oltp.SegmentDataTable segments = client.Service.Segment_Get(acc_id, false);

                foreach (Oltp.SegmentRow r in segments)
                {
                    bool is_creative_segment = ((Auxilary.SegmentAssociationFlags)r.Association).HasFlag(Auxilary.SegmentAssociationFlags.Creative);
                    if (is_creative_segment)
                    {
                        Oltp.SegmentValueDataTable values = client.Service.SegmentValue_Get(acc_id, r.SegmentID);
                        int value;
                        switch (r.SegmentID)
                        {
                        case 1: value = creative.Segment1; break;

                        case 2: value = creative.Segment2; break;

                        case 3: value = creative.Segment3; break;

                        case 4: value = creative.Segment4; break;

                        case 5: value = creative.Segment5; break;

                        default: value = creative.Segment1; break;
                        }


                        m.Segments.Add(new Models.SegmentRowModel()
                        {
                            SegmentRow = r, Values = values.ToList(), SelectedValue = value
                        });
                    }
                }

                Oltp.AdgroupDataTable creative_adgroups = client.Service.Adgroup_GetByCreative(creativeGK);
                Dictionary <int, Oltp.CampaignRow> campaings_dictionaty = client.Service.Campaign_GetIndividualCampaigns(creative_adgroups.Select(f => f.CampaignGK).ToArray()).ToDictionary(f => f.GK, f => f);

                foreach (Oltp.AdgroupRow r in creative_adgroups)
                {
                    m.Associations.Add(new Models.AssociationRowModel()
                    {
                        AdGroup = r, Campaign = campaings_dictionaty[(int)r.CampaignGK]
                    });
                }

                m.Creative = creative;
            }

            return(PartialView("~/Views/Creatives/CreativeDetails.cshtml", m));
        }
Ejemplo n.º 4
0
        private void Creative_ChangeMonitoring(object sender, RoutedEventArgs e)
        {
            bool monitor = sender == _buttonMonitor;

            // First mark the correct monitoring state
            foreach (Oltp.CreativeRow creative in _listTable.ListView.SelectedItems)
            {
                creative.IsMonitored = monitor;
            }

            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    proxy.Service.Creative_Save(Oltp.Prepare <Oltp.CreativeDataTable>(_creatives));
                }
            },
                                  delegate(Exception ex)
            {
                // Failed, so cancel and display a message
                MainWindow.MessageBoxError("Creatives could not be updated.", ex);
                _creatives.RejectChanges();
                return(false);
            },
                                  delegate()
            {
                Oltp.CreativeRow[] rowsToIterate = new Oltp.CreativeRow[_listTable.ListView.SelectedItems.Count];
                _listTable.ListView.SelectedItems.CopyTo(rowsToIterate, 0);

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

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

                _creatives.AcceptChanges();
            });
        }
Ejemplo n.º 5
0
        public void ApplyTemplate(Oltp.CreativeRow dataItem, ListViewItem item)
        {
            if (item == null)
            {
                return;
            }

            Button nameButton = VisualTree.GetChild <Button>(item, "_itemName");

            if (nameButton == null)
            {
                return;
            }

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

            cp.ContentTemplate = SelectTemplate(dataItem, item);
        }
Ejemplo n.º 6
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            Oltp.CreativeRow creative = item as Oltp.CreativeRow;

            if (creative == null)
            {
                return(new DataTemplate());
            }
            else if (creative.IsMonitored)
            {
                return(App.CurrentPage
                       .FindResource("MonitoredNameTemplate") as DataTemplate);
            }
            else
            {
                return(App.CurrentPage
                       .FindResource("UnmonitoredNameTemplate") as DataTemplate);
            }
        }