Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- 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 System.Windows.Threading;
- using MahApps.Metro.Controls;
- namespace Outlook_Add_In_Test
- {
- /// <summary>
- /// Interaction logic for WPFDistroList.xaml
- /// </summary>
- public partial class WPFDistroList : MetroWindow
- {
- DispatcherTimer dispatcherTimer = new DispatcherTimer();
- public static Dictionary<string, userInits> returnedResults { get; set; }
- public bool selectionchanged { get; set; }
- WPFNewEventv2 mainWindow;
- private ObservableCollection<SelectableItem> Items { get; set; }
- public WPFDistroList(WPFNewEventv2 oldWindow)
- {
- InitializeComponent();
- selectionchanged = false;
- mainWindow = oldWindow;
- //Set the Tick Method
- dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
- //Set timer interval in seconds ( (0, 0, 1) = 1 second)
- dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
- LoadingRing.IsActive = true;
- BtnOk.Background = Brushes.DarkGray;
- BtnOk.IsEnabled = false;
- Thread th = new Thread(searchThread);
- th.Start();
- }
- private void searchThread()
- {
- //Connect to database and get a List of all the users Initials
- Database connect = new Database();
- returnedResults = connect.ExecGetUserInits();
- //Stop the previous search/Timer before starting it again
- dispatcherTimer.Stop();
- //Start search timer
- dispatcherTimer.Start();
- }
- private void dispatcherTimer_Tick(object sender, EventArgs e)
- {
- int counter = 0;
- LstDistro.Items.Clear();
- foreach (var eventReturned in returnedResults)
- {
- userInits er = new userInits();
- er = eventReturned.Value;
- string LstBackground;
- //Set background to green for every even index in list
- if ((counter % 2) == 0)
- LstBackground = "#99FFFFFF";
- else
- LstBackground = "#99E8E8E8";
- var listVar = new
- {
- LBackground = LstBackground,
- LInits = er.userInit,
- LFullName = er.userFullName
- };
- ComboBoxItem newItem = new ComboBoxItem();
- newItem.Content = er.userInit;
- LstDistro.Items.Add(listVar);
- counter = counter + 1;
- }
- var bc = new BrushConverter();
- BtnOk.Background = (Brush)bc.ConvertFrom("#FF333333");
- BtnOk.IsEnabled = true;
- LoadingRing.IsActive = false;
- if (mainWindow.LblDistro.Content != "")
- {
- string searchValue = mainWindow.LblDistro.Content as string;
- string[] searchArray = searchValue.Split(',');
- foreach (var searchItem in searchArray)
- {
- foreach (var item in LstDistro.Items)
- {
- if (item.ToString().Contains(searchItem.Remove(searchItem.Length - 1)))
- {
- LstDistro.SelectedItems.Add(item);
- selectionchanged = false;
- }
- }
- }
- }
- dispatcherTimer.Stop();
- }
- private void BtnOk_Click(object sender, RoutedEventArgs e)
- {
- if (selectionchanged == true)
- {
- foreach (var item in LstDistro.SelectedItems)
- {
- var curItem = item.ToString();
- //Trim selected value string to give just the event and subject string
- int evNameIndex = curItem.IndexOf("LFullName = ");
- string evNameString = curItem.Substring(evNameIndex + 12);
- int commaIndex = evNameString.IndexOf('}');
- evNameString = evNameString.Substring(0, commaIndex);
- //Check to see if a comma should be added before the string addition
- if (mainWindow.LblDistro.Content == "")
- {
- mainWindow.LblDistro.Content = evNameString;
- }
- else
- {
- //Check to see if Name is already on label. If so dont re add it.
- if ((mainWindow.LblDistro.Content as string).Contains(evNameString))
- {
- //Do nothing
- }
- else
- {
- mainWindow.LblDistro.Content = mainWindow.LblDistro.Content + " , " + evNameString;
- }
- }
- }
- }
- this.Close();
- }
- private void CheckBox_Checked(object sender, RoutedEventArgs e)
- {
- ////Select the Item using the DataContext of the Button
- //object clicked = (e.OriginalSource as FrameworkElement).DataContext;
- //var lbi = LstDistro.ItemContainerGenerator.ContainerFromItem(clicked) as ListBoxItem;
- //lbi.IsSelected = true;
- }
- private void LstDistro_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- selectionchanged = true;
- }
- public class SelectableItem : INotifyPropertyChanged
- {
- private bool _isSelected;
- public bool IsSelected
- {
- get { return _isSelected; }
- set
- {
- _isSelected = value;
- OnPropertyChanged("IsSelected");
- }
- }
- public string DisplayName { get; set; }
- public event PropertyChangedEventHandler PropertyChanged;
- protected virtual void OnPropertyChanged(string propertyName)
- {
- PropertyChangedEventHandler handler = PropertyChanged;
- if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement