# TickerManagement [C#]

     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
     using System.Windows;
     using System.Windows.Controls;
     using System.Windows.Data;
     using System.Windows.Documents;
     using System.Windows.Input;
     using System.Windows.Media;
     using System.Windows.Media.Imaging;
     using System.Windows.Navigation;
     using System.Windows.Shapes;
     using WpfApplication1.ServiceReference1;
     using System.Collections.ObjectModel;
     using System.Globalization;

     namespace WpfApplication1
     {

         // Interaction logic for TickerManagement.xaml
         public partial class TickerManagement : UserControl
         {
             ServiceSample sample = new ServiceSample();

             public TickerManagement()
             {
                 InitializeComponent();
             }

             //Initialize the XAML object and retrieve group from server by login
             public TickerManagement(string login, string password)
             {
                 InitializeComponent();

                 //Login and retrive group
                 List<View_Group> listResult;
                 sample.GetGroup(out listResult, login, password);

                 //Bind group to TreeList
                 treeGroup.ItemsSource = TreeNode.GetTreeNode(listResult);
             }

             //Select group and retrive coresponding ticker
             private void treeGroup_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
             {
                 //Retrive tickers from selected group
                 List<View_Banner> listResult;
                 sample.GetTicker(out listResult, (treeGroup.SelectedItem as TreeNode).Id ?? 0);

                 //Bind ticker to List
                 gridTicker.ItemsSource = new ObservableCollection<View_Banner>(listResult);
             }

             //Select ticker and display this status
             private void gridTicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
             {
                 if (gridTicker.SelectedItem == null) return;

                 //Display if the ticker as 'Published' or 'Unpublished'
                 btnPublish.Content = (gridTicker.SelectedItem as View_Banner).FolderId == -1 ? "Unpublished" : "Published";
             }

             //Published / Unpublished a tcker
             private void btnPublish_Click(object sender, RoutedEventArgs e)
             {
                 //Keep the ticker to publish
                 View_Banner ticker = gridTicker.SelectedItem as View_Banner;

                 //Change this folder id
                 ticker.FolderId = ticker.FolderId == -1 ? -2 : -1;

                 //Update the ticker
                 sample.UpdateTicker(ref ticker);

                 //Refresh the ticker collection
                 gridTicker_SelectionChanged(null, null);
             }
         }

         public class PublishConvert : IValueConverter
         {
             public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
             {
                 return System.Convert.ToInt32(value) == -1 ? "Published" : "Not Published";
             }

             public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
             {
                 throw new NotImplementedException();
             }
         }
     }