123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Threading;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.DynamicGrid.Spreadsheet;
- using InABox.WPF;
- using Microsoft.Office.Interop.Outlook;
- using System.ComponentModel;
- using Selection = InABox.Core.Selection;
- namespace PRSDesktop
- {
-
- public class JobPanelSettings : BaseObject, IGlobalConfigurationSettings
- {
- [Caption("Milestone Task",IncludePath = false)]
- public KanbanTypeLink DocumentMilestoneKanbanType { get; set; }
- }
- /// <summary>
- /// Interaction logic for JobPanel.xaml
- /// </summary>
- public partial class JobPanel : UserControl, IPanel<Job>
- {
-
-
- private enum PageIndex
- {
- Details = 00,
- Scopes,
- Documents,
- Stages,
- ITPs,
- BOM,
- Requisitions,
- Orders,
- Designs,
- Manufacturing,
- Dispatch,
- Delivery,
- Onsite,
- Kanban,
- Equipment,
- Employee,
- Tracker,
- Assignment,
- Timesheet,
- Form,
- Invoice,
- Spreadsheets,
- Summary
- }
-
- private int CurrentPage = -1;
-
- private JobDetails? JobDetailsPage;
- private JobScopePanel? _jobScopePage;
- private JobDocumentSetPanel? JobDocumentsPage;
- private JobStagesPanel? JobPlanningPage;
- private JobITPGrid? JobITPPage;
- private JobBillOfMaterialsPanel? JobBillOfMaterialsPage;
- private JobRequisitionPanel? JobRequisitionsPage;
- private JobDesignList? JobDesignsPage;
- private JobOrderGrid? JobOrderPage;
- private ManufacturingGrid? JobManufacturingPage;
- private ReadyToGoGrid? JobReadyToGoPage;
- private DeliveryPanel? JobDeliveriesPage;
- private DeliveredOnSiteGrid? JobOnSitePage;
- private TaskPanel? JobTasksPage;
- private JobEquipmentGrid? JobEquipmentPage;
- private JobEmployeePanel? JobEmployeePage;
- private JobTrackerGrid? JobTrackerPage;
- private JobAssignmentPanel? JobActivitiesPage;
- private JobTimesheetGrid? JobTimeSheetsPage;
- private JobFormGrid? JobFormsPage;
- private InvoicePanel? JobInvoicePage;
- private JobSpreadsheetGrid? JobSpreadsheetPage;
- private JobSummaryPanel? JobSummaryPage;
-
- private DateTime lastselection = DateTime.MaxValue;
-
- private IDataModelSource modelsource;
- // User Settings
- private JobScreenSettings settings;
-
- // Global Settings
- private JobPanelSettings _settings = null;
-
- private DispatcherTimer timer;
-
- public JobPanel()
- {
- InitializeComponent();
- }
- public bool IsReady { get; set; }
- public Dictionary<string, object[]> Selected()
- {
-
- return (PageIndex)JobPages.SelectedIndex switch
- {
- PageIndex.Details => JobDetailsPage?.Selected(),
-
- PageIndex.Scopes => _jobScopePage?.Selected(),
-
- PageIndex.Documents => JobDocumentsPage?.Selected(),
- PageIndex.Stages => JobPlanningPage?.Selected(),
-
- PageIndex.ITPs => new Dictionary<string, object[]> { { typeof(JobITP).EntityName(), JobITPPage.SelectedRows } },
-
- PageIndex.BOM => new Dictionary<string, object[]>
- { { typeof(JobBillOfMaterials).EntityName(), JobBillOfMaterialsPage.SelectedRows } },
-
- PageIndex.Designs => JobDesignsPage?.Selected(),
-
- PageIndex.Orders => new Dictionary<string, object[]> { { typeof(PurchaseOrderItem).EntityName(), JobOrderPage?.SelectedRows } },
-
- PageIndex.Requisitions => new Dictionary<string, object[]>
- { { typeof(JobRequisition).EntityName(), JobRequisitionsPage?.Requisitions?.SelectedRows } },
-
- PageIndex.Manufacturing => new Dictionary<string, object[]>
- { { typeof(ManufacturingPacket).EntityName(), JobManufacturingPage.SelectedRows } },
-
- PageIndex.Dispatch => new Dictionary<string, object[]> { { typeof(DeliveryItem).EntityName(), JobReadyToGoPage.SelectedRows } },
-
- PageIndex.Delivery => new Dictionary<string, object[]>
- { { typeof(Delivery).EntityName(), JobDeliveriesPage.Deliveries.SelectedRows } },
-
- PageIndex.Onsite => new Dictionary<string, object[]> { { typeof(DeliveryItem).EntityName(), JobOnSitePage.SelectedRows } },
- PageIndex.Kanban => JobTasksPage.Selected(),
-
- PageIndex.Equipment => new Dictionary<string, object[]> { { typeof(Equipment).EntityName(), JobEquipmentPage.SelectedRows } },
-
- PageIndex.Employee => new Dictionary<string, object[]>
- { { typeof(Employee).EntityName(), JobEmployeePage.Employees.SelectedRows } },
-
- PageIndex.Tracker => new Dictionary<string, object[]> { { typeof(GPSTracker).EntityName(), JobTrackerPage.SelectedRows } },
- PageIndex.Assignment => new Dictionary<string, object[]>
- { { typeof(Assignment).EntityName(), JobActivitiesPage.Assignments.SelectedRows } },
-
- PageIndex.Timesheet => new Dictionary<string, object[]> { { typeof(TimeSheet).EntityName(), JobTimeSheetsPage.SelectedRows } },
-
- PageIndex.Form => new Dictionary<string, object[]> { { typeof(JobForm).EntityName(), JobFormsPage.SelectedRows } },
-
- PageIndex.Invoice => new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), JobInvoicePage.Invoices.SelectedRows } },
-
- PageIndex.Spreadsheets => new Dictionary<string, object[]> { { typeof(JobSpreadsheet).EntityName(), JobSpreadsheetPage.SelectedRows } },
-
- PageIndex.Summary => new Dictionary<string, object[]> { { typeof(JobMaterial).EntityName(), JobSummaryPage.Summary.SelectedRows } },
-
- _ => new Dictionary<string,object[]> {{ typeof(Job).EntityName(), JobGrid.SelectedRows}}
-
- };
-
- }
- public void Setup()
- {
- Task[] settingstasks = new Task[]
- {
- Task.Run(() =>
- {
- _settings = new GlobalConfiguration<JobPanelSettings>().Load();
- }),
- Task.Run(() =>
- {
- settings = new UserConfiguration<JobScreenSettings>().Load();
- })
- };
- Task.WaitAll(settingstasks);
-
- SplitPanel.View = settings.ViewType == ScreenViewType.Register ? DynamicSplitPanelView.Master :
- settings.ViewType == ScreenViewType.Details ? DynamicSplitPanelView.Detail : DynamicSplitPanelView.Combined;
- SplitPanel.AnchorWidth = settings.AnchorWidth;
- var sc = new Dictionary<Guid, string> { { Guid.Empty, "All Jobs" } };
- var statuses = new Client<JobStatus>().Query();
- foreach (var row in statuses.Rows)
- sc[row.Get<JobStatus, Guid>(x => x.ID)] = row.Get<JobStatus, string>(x => x.Description);
- JobStatus.ItemsSource = sc;
- if (sc.ContainsKey(settings.JobStatus))
- JobStatus.SelectedValue = settings.JobStatus;
- else
- JobStatus.SelectedValue = sc.Keys.First();
- JobGrid.OnSelectItem += JobGrid_OnSelectItem;
- JobGrid.BeforeRefresh += JobGrid_BeforeRefresh;
- JobGrid.AfterRefresh += JobGrid_AfterRefresh;
- Scopes.Visibility = Security.CanView<JobScope>() ? Visibility.Visible : Visibility.Collapsed;
- Documents.Visibility = Security.CanView<JobDocumentSet>() ? Visibility.Visible : Visibility.Collapsed;
- Stages.Visibility = ClientFactory.IsSupported<JobStage>() ? Visibility.Visible : Visibility.Collapsed;
- ITPs.Visibility = ClientFactory.IsSupported<JobITP>() ? Visibility.Visible : Visibility.Collapsed;
- BOM.Visibility = ClientFactory.IsSupported<JobBillOfMaterials>() ? Visibility.Visible : Visibility.Collapsed;
- Requisitions.Visibility = ClientFactory.IsSupported<JobRequisition>() ? Visibility.Visible : Visibility.Collapsed;
- Orders.Visibility = ClientFactory.IsSupported<PurchaseOrderItem>() ? Visibility.Visible : Visibility.Collapsed;
- Setouts.Visibility = ClientFactory.IsSupported<Setout>() ? Visibility.Visible : Visibility.Collapsed;
- Manufacturing.Visibility = ClientFactory.IsSupported<ManufacturingPacket>() ? Visibility.Visible : Visibility.Collapsed;
- Dispatch.Visibility = ClientFactory.IsSupported<DeliveryItem>() ? Visibility.Visible : Visibility.Collapsed;
- Deliveries.Visibility = ClientFactory.IsSupported<Delivery>() ? Visibility.Visible : Visibility.Collapsed;
- OnSite.Visibility = ClientFactory.IsSupported<DeliveryItem>() ? Visibility.Visible : Visibility.Collapsed;
- Tasks.Visibility = ClientFactory.IsSupported<Kanban>() ? Visibility.Visible : Visibility.Collapsed;
- EquipmentTab.Visibility = ClientFactory.IsSupported<Equipment>() ? Visibility.Visible : Visibility.Collapsed;
- Employees.Visibility = ClientFactory.IsSupported<Employee>() ? Visibility.Visible : Visibility.Collapsed;
- Trackers.Visibility = ClientFactory.IsSupported<GPSTracker>() ? Visibility.Visible : Visibility.Collapsed;
- Assignments.Visibility = ClientFactory.IsSupported<Assignment>() ? Visibility.Visible : Visibility.Collapsed;
- Timesheets.Visibility = ClientFactory.IsSupported<TimeSheet>() ? Visibility.Visible : Visibility.Collapsed;
- Forms.Visibility = Security.CanView<JobForm>() ? Visibility.Visible : Visibility.Collapsed;
- Invoices.Visibility = Security.CanView<Invoice>() ? Visibility.Visible : Visibility.Collapsed;
- Spreadsheets.Visibility = Security.CanView<JobSpreadsheet>() ? Visibility.Visible : Visibility.Collapsed;
- Summary.Visibility = ClientFactory.IsSupported<JobMaterial>() ? Visibility.Visible : Visibility.Collapsed;
- JobGrid.ColumnsTag = settings.ViewType == ScreenViewType.Register ? settings.ViewType.ToString() : "";
- JobGrid.Refresh(true, false);
- timer = new DispatcherTimer();
- timer.Tick += Timer_Tick;
- timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
- timer.IsEnabled = true;
- }
- private bool _jobGridRefreshing;
- private void JobGrid_BeforeRefresh(object sender, BeforeRefreshEventArgs args)
- {
- _jobGridRefreshing = true;
- }
- private void JobGrid_AfterRefresh(object sender, AfterRefreshEventArgs args)
- {
- if (settings.CurrentJob == Guid.Empty)
- {
- JobGrid.SelectedRows = Array.Empty<CoreRow>();
- }
- else
- {
- JobGrid.SelectedRows = JobGrid.Data.Rows.Where(x => x.Get<Job, Guid>(x => x.ID) == settings.CurrentJob).ToArray();
- }
- _jobGridRefreshing = false;
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- timer.IsEnabled = false;
- timer = null;
- Details.Content = null;
- JobDetailsPage = null;
- Scopes.Content = null;
- _jobScopePage = null;
- Documents.Content = null;
- JobDocumentsPage = null;
- Stages.Content = null;
- JobPlanningPage = null;
- //Levels.Content = null;
- //LevelGrid = null;
- //Zones.Content = null;
- //ZoneGrid = null;
- ITPs.Content = null;
- JobITPPage = null;
- BOM.Content = null;
- JobBillOfMaterialsPage = null;
- Setouts.Content = null;
- JobDesignsPage = null;
- Requisitions.Content = null;
- JobRequisitionsPage = null;
- Orders.Content = null;
- JobOrderPage = null;
- Manufacturing.Content = null;
- JobManufacturingPage = null;
- Dispatch.Content = null;
- JobReadyToGoPage = null;
- Deliveries.Content = null;
- JobDeliveriesPage = null;
- OnSite.Content = null;
- JobOnSitePage = null;
- Tasks.Content = null;
- JobTasksPage = null;
- EquipmentTab.Content = null;
- JobEquipmentPage = null;
- Employees.Content = null;
- JobEmployeePage = null;
- Trackers.Content = null;
- JobTrackerPage = null;
- Assignments.Content = null;
- JobActivitiesPage = null;
- Timesheets.Content = null;
- JobTimeSheetsPage = null;
- Forms.Content = null;
- JobFormsPage = null;
- Invoices.Content = null;
- JobInvoicePage = null;
- Spreadsheets.Content = null;
- JobSpreadsheetPage = null;
- Summary.Content = null;
- JobSummaryPage = null;
- }
- public void Refresh()
- {
- JobGrid.StatusID = (Guid)JobStatus.SelectedValue;
- JobGrid.Refresh(false, true);
- lastselection = DateTime.MinValue;
- }
- public void CreateToolbarButtons(IPanelHost host)
- {
- host.CreateSetupAction(new PanelAction() { Caption = "Job Settings", Image = PRSDesktop.Resources.specifications, OnExecute = JobSettingsClick });
- }
- private void JobSettingsClick(PanelAction obj)
- {
- var pages = new DynamicEditorPages();
- var buttons = new DynamicEditorButtons();
- buttons.Add(
- "",
- PRSDesktop.Resources.help.AsBitmapImage(),
- _settings,
- (f, i) =>
- {
- Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + typeof(Equipment).Name.SplitCamelCase().Replace(" ", "_"))
- { UseShellExecute = true });
- }
- );
- var propertyEditor = new DynamicEditorForm(typeof(JobPanelSettings), pages, buttons);
- propertyEditor.OnDefineLookups += sender =>
- {
- var editor = sender.EditorDefinition as ILookupEditor;
- var colname = sender.ColumnName;
- var values = editor.Values(colname, new [] { _settings });
- sender.LoadLookups(values);
- };
- propertyEditor.OnEditorValueChanged += (sender, name, value) =>
- {
- CoreUtils.SetPropertyValue(_settings, name, value);
- return new Dictionary<string, object?>();
- };
-
- propertyEditor.Items = new BaseObject[] { _settings };
- if (propertyEditor.ShowDialog() == true)
- {
- new GlobalConfiguration<JobPanelSettings>().Save(_settings);
- }
- }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public string SectionName => modelsource?.SectionName ?? "Job Details";
- public DataModel DataModel(Selection selection)
- {
- if (modelsource == null)
- {
- var row = JobGrid.SelectedRows.FirstOrDefault();
- var jobid = row != null ? row.Get<Job, Guid>(x => x.ID) : CoreUtils.FullGuid;
- return new JobDetailsDataModel(new Filter<Job>(x => x.ID).IsEqualTo(jobid));
- }
- return modelsource.DataModel(selection);
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (lastselection < DateTime.Now.AddMilliseconds(-500))
- {
- lastselection = DateTime.MaxValue;
-
- var job = JobGrid.SelectedRows.FirstOrDefault()?.ToObject<Job>() ?? new Job();
-
- //var jobid = row != null ? row.Get<Job, Guid>(x => x.ID) : CoreUtils.FullGuid;
- //Guid customerid = row != null ? row.Get<Job, Guid>(x => x.Customer.ID) : Guid.Empty;
- var page = (PageIndex)JobPages.SelectedIndex;
-
- switch (page)
- {
- case PageIndex.Details :
- RefreshPanel(Details, ref JobDetailsPage, job);
- break;
- case PageIndex.Scopes : RefreshPanel(Scopes, ref _jobScopePage, job);
- break;
- case PageIndex.Documents : RefreshPanel(Documents, ref JobDocumentsPage, job);
- break;
- case PageIndex.Stages : RefreshPanel(Stages, ref JobPlanningPage, job);
- break;
- case PageIndex.ITPs : RefreshGrid(ITPs, ref JobITPPage, job);
- break;
- case PageIndex.BOM : RefreshPanel(BOM, ref JobBillOfMaterialsPage, job);
- break;
- case PageIndex.Requisitions : RefreshPanel(Requisitions, ref JobRequisitionsPage, job);
- break;
- case PageIndex.Orders : RefreshGrid(Orders, ref JobOrderPage, job);
- break;
- case PageIndex.Designs : RefreshPanel(Setouts, ref JobDesignsPage, job);
- break;
- case PageIndex.Manufacturing : RefreshGrid(Manufacturing, ref JobManufacturingPage, job);
- break;
- case PageIndex.Dispatch :
- RefreshGrid(Dispatch, ref JobReadyToGoPage, job);
- break;
- case PageIndex.Delivery :
- RefreshPanel(Deliveries, ref JobDeliveriesPage, job);
- break;
- case PageIndex.Onsite :
- RefreshGrid(OnSite, ref JobOnSitePage, job);
- break;
- case PageIndex.Kanban :
- RefreshPanel(Tasks, ref JobTasksPage, job);
- break;
- case PageIndex.Equipment :
- RefreshGrid(EquipmentTab, ref JobEquipmentPage, job);
- break;
- case PageIndex.Employee :
- RefreshPanel(Employees, ref JobEmployeePage, job);
- break;
- case PageIndex.Tracker :
- RefreshGrid(Trackers, ref JobTrackerPage, job);
- break;
- case PageIndex.Assignment :
- RefreshPanel(Assignments, ref JobActivitiesPage, job);
- break;
- case PageIndex.Timesheet :
- RefreshGrid(Timesheets, ref JobTimeSheetsPage, job);
- break;
- case PageIndex.Form :
- RefreshGrid(Forms, ref JobFormsPage, job);
- break;
- case PageIndex.Invoice :
- RefreshPanel(Invoices, ref JobInvoicePage, job);
- break;
- case PageIndex.Spreadsheets :
- RefreshGrid(Spreadsheets, ref JobSpreadsheetPage, job);
- break;
- case PageIndex.Summary :
- RefreshPanel(Summary, ref JobSummaryPage, job);
- break;
- }
- }
- }
- private void RefreshPanel<T>(TabItem container, ref T panel, Job job) where T : IBasePanel, IJobControl, new()
- {
- if (panel == null)
- {
- panel = new T();
- panel.IsReady = false;
- //panel.ParentID = CoreUtils.FullGuid;
- panel.Job = new Job();
- panel.Settings = _settings;
- panel.Setup();
- panel.IsReady = true;
- container.Content = panel;
- }
- if (JobPages.SelectedIndex != CurrentPage)
- {
- modelsource = panel;
- OnUpdateDataModel?.Invoke(panel.SectionName, panel.DataModel(Selection.None));
- CurrentPage = JobPages.SelectedIndex;
- }
- //panel.ParentID = jobid;
- panel.Job = job;
- panel.Settings = _settings;
- panel.Refresh();
- }
- private void RefreshGrid<T>(TabItem container, ref T grid, Job job) where T : IDynamicGrid, IJobControl, IDataModelSource, new()
- {
- var bInitialised = false;
- if (grid == null)
- {
- grid = new T();
- container.Content = grid;
- }
- else
- {
- bInitialised = true;
- }
- if (JobPages.SelectedIndex != CurrentPage)
- {
- modelsource = grid;
- OnUpdateDataModel?.Invoke(grid.SectionName, grid.DataModel(Selection.None));
- CurrentPage = JobPages.SelectedIndex;
- }
- //grid.ParentID = jobid;
- grid.Job = job;
- grid.Settings = _settings;
- grid.Refresh(!bInitialised, true);
- }
- private void JobGrid_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- lastselection = DateTime.Now;
- if (IsReady && !_jobGridRefreshing)
- {
- settings.CurrentJob = e.Rows?.FirstOrDefault()?.Get<Job, Guid>(x => x.ID) ?? Guid.Empty;
- new UserConfiguration<JobScreenSettings>().Save(settings);
- }
- }
- private void ShowEmailInterface(PanelAction obj)
- {
- var form = new EmailInterfaceForm();
- form.ShowDialog();
- }
- private MAPIFolder? FindFolder(NameSpace oNS, string foldername)
- {
- var folder = oNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
- if (string.IsNullOrEmpty(foldername))
- return folder;
- var comps = foldername.Split('/');
- foreach (var comp in comps)
- {
- var curfolder = folder;
- var bFound = false;
- foreach (MAPIFolder subfolder in folder.Folders)
- if (subfolder.Name.Equals(comp))
- {
- curfolder = subfolder;
- bFound = true;
- break;
- }
- if (bFound)
- folder = curfolder;
- else
- return null;
- }
- return folder;
- }
- private string ConstructReply(string job, string name, string body, bool html)
- {
- var emp = new Client<Employee>().Load(new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid)).FirstOrDefault();
- var template = html
- ? "<p>Dear {0}</p>Thankyou for your email.</p><p>It has been allocated Job #{1}, and will be attended to as soon as possible.</p><p><b><u>Job Description:</u></b><br>{2}</p><p>Regards,</p><p>{3}"
- : "Dear {0}\n\nThankyou for your email.\n\nIt has been allocated Job #{1}, and will be attended to as soon as possible.\n\nJob Description:\n================\n{2}\n\nRegards,\n\n{3}";
- return string.Format(template, name.Split(' ').First(), job, body, emp != null ? emp.Name : "Frog Software");
- }
- private void CheckMailbox(PanelAction obj)
- {
- Progress.SetMessage("Connecting to Mail Service");
- var mailer = ClientFactory.CreateMailer();
- if (!mailer.Connect())
- {
- Progress.Close();
- MessageBox.Show("Unable to Connect to Mail System!");
- return;
- }
- Progress.SetMessage("Locating PRS Folder");
- var prs = mailer.FindFolder(null, "PRS");
- if (prs == null)
- {
- Progress.Close();
- MessageBox.Show("Unable to Find PRS Folder");
- return;
- }
- Progress.SetMessage("Locating Archive Folder");
- var archive = mailer.FindFolder(prs, "Archive");
- if (archive == null)
- {
- Progress.Close();
- MessageBox.Show("Unable to Find PRS/Archive Folder");
- return;
- }
- var me = new Client<Employee>().Load(new Filter<Employee>(x => x.UserLink.ID).IsEqualTo(ClientFactory.UserGuid)).FirstOrDefault();
- if (me == null)
- {
- Progress.Close();
- MessageBox.Show(string.Format("Employee [{0}] does not have a valid email address", me.Name));
- return;
- }
- //Outlook.Application app = new Outlook.Application();
- //Outlook.NameSpace ns = app.GetNamespace("mapi");
- //ns.Logon(Missing.Value, Missing.Value, false, true);
- //Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
- //Outlook.MAPIFolder folder = FindFolder(ns,"PRS");
- //if (folder == null)
- // folder = (Outlook.Folder)inbox.Folders.Add("PRS",Outlook.OlDefaultFolders.olFolderInbox);
- //Outlook.MAPIFolder archive = FindFolder(ns, "PRS/Archive");
- //if (archive == null)
- // archive = (Outlook.Folder)folder.Folders.Add("Archive", Outlook.OlDefaultFolders.olFolderInbox);
- JobGrid jg = null;
- Customer[] customers = null;
- Progress.SetMessage("Scanning PRS Folder");
- var items = mailer.GetMessages(prs);
- foreach (var item in items)
- {
- if (customers == null)
- {
- Progress.SetMessage("Loading Customer Details");
- customers = new Client<Customer>().Load();
- }
- var cust = customers.FirstOrDefault(x => x.Email.Equals(item.From));
- if (cust != null)
- {
- if (jg == null)
- jg = new JobGrid();
- var job = new Job();
- jg.OnCustomiseEditor += Jg_OnCustomiseEditor;
- job.Name = item.Subject;
- job.Notes = new[] { item.Body };
- job.Customer.ID = cust.ID;
- job.Customer.Synchronise(cust);
- job.Account.ID = !cust.Account.IsValid() ? cust.ID : cust.Account.ID;
- var defstatus = new Client<JobStatus>().Query(new Filter<JobStatus>(x => x.Default).IsEqualTo(true));
- if (defstatus.Rows.Any())
- job.JobStatus.ID = defstatus.Rows.First().Get<JobStatus, Guid>(x => x.ID);
- Progress.Close();
- if (jg.EditItems(new[] { job }))
- {
- item.Subject = string.Format("{0} (PRS #{1})", job.Name, job.JobNumber);
- item.Save();
- mailer.MoveMessage(item, archive);
- //item.Move(archive);
- var message = mailer.CreateMessage();
- message.From = me.Email;
- message.Subject = string.Format("RE: {0}", item.Subject);
- message.Body = ConstructReply(job.JobNumber, cust.Name, string.Join("\n\n", job.Notes), false);
- message.To = new[] { cust.Email };
- mailer.SendMessage(message);
- //Outlook.MailItem replyMail = item.ReplyAll();
- //replyMail.To = cust.Email;
- //replyMail.Body = ConstructReply(job.JobNumber, cust.Name, String.Join("\n\n",job.Notes), false);
- //replyMail.Send();
- }
- Progress.Show("Scanning PRS Folder");
- }
- }
- items = null;
- Progress.SetMessage("Refreshing");
- Refresh();
- Progress.Close();
- MessageBox.Show("All Done");
- //ns.Logoff();
- //folder = null;
- //ns = null;
- //app = null;
- }
- private void Jg_OnCustomiseEditor(IDynamicEditorForm sender, Job[]? items, DynamicGridColumn column, BaseEditor editor)
- {
- if (column.ColumnName.Equals("Notes"))
- {
- if (editor is NotesEditor notes)
- notes.AlwaysEnabled = true;
- }
- }
- public Dictionary<Type, CoreTable> DataEnvironment()
- {
- var env = new Dictionary<Type, CoreTable>();
- env[typeof(Job)] = JobGrid.Data;
- return env;
- }
- private void JobPages_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (e.Source == JobPages)
- lastselection = DateTime.MinValue;
- }
- private void JobStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (IsReady)
- {
- settings.JobStatus = (Guid)JobStatus.SelectedValue;
- new UserConfiguration<JobScreenSettings>().Save(settings);
- JobGrid.StatusID = (Guid)JobStatus.SelectedValue;
- JobGrid.Refresh(false, true);
- }
- }
- private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
- {
- settings.ViewType = SplitPanel.View == DynamicSplitPanelView.Master ? ScreenViewType.Register :
- SplitPanel.View == DynamicSplitPanelView.Detail ? ScreenViewType.Details : ScreenViewType.Combined;
- settings.AnchorWidth = SplitPanel.AnchorWidth;
- new UserConfiguration<JobScreenSettings>().Save(settings);
- var newTag = settings.ViewType == ScreenViewType.Register ? settings.ViewType.ToString() : "";
- if (JobGrid.ColumnsTag != newTag)
- {
- JobGrid.ColumnsTag = newTag;
- JobGrid.Refresh(true, true);
- }
- }
- }
- }
|