123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.Wpf;
- using InABox.WPF;
- using Syncfusion.Windows.Tools.Controls;
- namespace PRSDesktop
- {
- /// <summary>
- /// Interaction logic for NotificationForm.xaml
- /// </summary>
- public partial class NotificationForm : ThemableWindow
- {
- private CoreTable Employees;
- private CoreTable Jobs;
- private CoreTable Teams;
- public NotificationForm()
- {
- InitializeComponent();
- ContentEdit.SetColor(Colors.LightYellow);
- }
- public string Subject
- {
- get => TitleEdit.Text;
- set => TitleEdit.Text = value;
- }
- public string Description
- {
- get => ContentEdit.Text;
- set => ContentEdit.Text = value;
- }
- public Guid Recipient { get; set; }
- public Guid JobID { get; set; }
- public void OnLoaded(object sender, RoutedEventArgs e)
- {
- new Client<Employee>().Query(
- LookupFactory.DefineFilter<Employee>(),
- LookupFactory.DefineColumns<Employee>(),
- LookupFactory.DefineSort<Employee>(),
- (table, exception) =>
- {
- Employees = table;
- Dispatcher.Invoke(() => { ReloadEmployees(Guid.Empty); });
- }
- );
- new Client<EmployeeTeam>().Query(
- null,
- null,
- new SortOrder<EmployeeTeam>(x => x.TeamLink.Name),
- (table, exception) =>
- {
- Teams = table;
- Dispatcher.Invoke(() => { ReloadTeams(); });
- }
- );
- new Client<Job>().Query(
- LookupFactory.DefineFilter<Job>(),
- LookupFactory.DefineColumns<Job>(),
- LookupFactory.DefineSort<Job>(),
- (table, exception) =>
- {
- Jobs = table;
- Dispatcher.Invoke(() => { ReloadJobs(); });
- }
- );
- }
- private void ReloadTeams()
- {
- var lookups = new Dictionary<Guid, string>
- {
- { Guid.Empty, "" }
- };
- foreach (var row in Teams.Rows)
- lookups[row.Get<EmployeeTeam, Guid>(x => x.TeamLink.ID)] = row.Get<EmployeeTeam, string>(x => x.TeamLink.Name);
- TeamCombo.ItemsSource = null;
- TeamCombo.ItemsSource = lookups;
- }
- private void ReloadEmployees(Guid teamid)
- {
- var lookups = new Dictionary<Guid, string>();
- foreach (var row in Employees.Rows)
- {
- var bInTeam = Teams == null || teamid == Guid.Empty || Teams.Rows.Any(r =>
- r.Get<EmployeeTeam, Guid>(x => x.TeamLink.ID).Equals(teamid) &&
- r.Get<EmployeeTeam, Guid>(x => x.EmployeeLink.ID).Equals(row.Get<Employee, Guid>(x => x.ID)));
- if (bInTeam)
- lookups[row.Get<Employee, Guid>(x => x.ID)] = row.Get<Employee, string>(x => x.Name);
- }
- EmployeeChecks.ItemsSource = null;
- EmployeeChecks.ItemsSource = lookups;
- if (Recipient != Guid.Empty)
- foreach (KeyValuePair<Guid, string> pair in EmployeeChecks.Items)
- if (pair.Key == Recipient)
- {
- EmployeeChecks.SelectedItem = pair;
- EmployeeChecks.SelectedItems.Add(pair);
- ReloadNames();
- break;
- }
- }
- private void ReloadJobs()
- {
- var lookups = new Dictionary<Guid, string> { { Guid.Empty, "(No Job Selected)" } };
- foreach (var row in Jobs.Rows)
- lookups[row.Get<Job, Guid>(x => x.ID)] =
- string.Format("{0}: {1}", row.Get<Job, string>(x => x.JobNumber), row.Get<Job, string>(x => x.Name));
- JobDetails.ItemsSource = null;
- JobDetails.ItemsSource = lookups;
- foreach (KeyValuePair<Guid, string> pair in JobDetails.Items)
- if (pair.Key == JobID)
- {
- JobDetails.SelectedItem = pair;
- break;
- }
- }
- // private void CheckOKButton(object sender, EventArgs e)
- // {
- // OK.IsEnabled = (EmployeeChecks.SelectedItems.Count > 0) && !String.IsNullOrWhiteSpace(TitleEdit.Text) && !String.IsNullOrWhiteSpace(ContentEdit.Text);
- // }
- private void CheckOKButton(object sender, SelectionChangedEventArgs e)
- {
- CheckOK(sender);
- ReloadNames();
- }
- // private void CheckOKButton(object sender, TextChangedEventArgs e)
- // {
- // OK.IsEnabled = (EmployeeChecks.SelectedItems.Count > 0) && !String.IsNullOrWhiteSpace(TitleEdit.Text) && !String.IsNullOrWhiteSpace(ContentEdit.Text);
- // }
- private void CheckOK(object sender)
- {
- OK.IsEnabled = EmployeeChecks.SelectedItems.Count > 0 && !string.IsNullOrWhiteSpace(TitleEdit.Text) &&
- !string.IsNullOrWhiteSpace(ContentEdit.Text);
- }
- private void EmployeeChecks_ItemChecked(object sender, ItemCheckedEventArgs e)
- {
- OK.IsEnabled = EmployeeChecks.SelectedItems.Count > 0 && !string.IsNullOrWhiteSpace(TitleEdit.Text) &&
- !string.IsNullOrWhiteSpace(ContentEdit.Text);
- ReloadNames();
- }
- private void ReloadNames()
- {
- var names = new List<string>();
- foreach (KeyValuePair<Guid, string> pair in EmployeeChecks.SelectedItems)
- names.Add(pair.Value);
- Recipients.Text = string.Join("; ", names);
- }
- private void OK_Click(object sender, RoutedEventArgs e)
- {
- using (new WaitCursor())
- {
- var me = new Client<Employee>().Load(new Filter<Employee>(x => x.UserID).IsEqualTo(ClientFactory.UserGuid)).FirstOrDefault();
- var updates = new List<Notification>();
- foreach (KeyValuePair<Guid, string> item in EmployeeChecks.SelectedItems)
- {
- var notification = new Notification { Title = TitleEdit.Text, Description = ContentEdit.Text };
- notification.Sender.ID = me != null ? me.ID : Guid.Empty;
- notification.Employee.ID = item.Key;
- if (JobDetails.SelectedItem != null)
- {
- var job = (KeyValuePair<Guid, string>)JobDetails.SelectedItem;
- notification.Job.ID = job.Key;
- }
- updates.Add(notification);
- }
- new Client<Notification>().Save(updates, "Sent Notification");
- }
- DialogResult = true;
- Close();
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- private void TeamCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var pair = (KeyValuePair<Guid, string>)TeamCombo.SelectedItem;
- ReloadEmployees(pair.Key);
- }
- private void SelectAll_Checked(object sender, RoutedEventArgs e)
- {
- EmployeeChecks.SelectedItems.Clear();
- foreach (var item in EmployeeChecks.Items)
- EmployeeChecks.SelectedItems.Add(item);
- }
- private void SelectAll_Unchecked(object sender, RoutedEventArgs e)
- {
- EmployeeChecks.SelectedItems.Clear();
- }
- private void TitleEdit_LostFocus(object sender, RoutedEventArgs e)
- {
- }
- private void LostFocus(object sender, RoutedEventArgs e)
- {
- CheckOK(sender);
- }
- }
- }
|