123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets
- {
- public delegate void JobDocFiltersPicked(string discipline, string type, string category, string area);
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class JobDocsFilterPage : ContentPage
- {
- Guid JobID = Guid.Empty;
- List<string> Disciplines = new List<string>();
- List<string> Types = new List<string>();
- List<string> Categories = new List<string>();
- List<string> Areas = new List<string>();
- Dictionary<JobDocFilterType, string> Filters = new Dictionary<JobDocFilterType, string>();
- public event JobDocFiltersPicked OnJobDocFiltersPicked;
- public JobDocsFilterPage(Guid jobid, Dictionary<JobDocFilterType, string> filters)
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- JobID = jobid;
- Filters = filters;
- LoadFilters();
- }
- private void CancelBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- private void SaveBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- OnJobDocFiltersPicked?.Invoke(disciplinePicker.SelectedItem, typePicker.SelectedItem, categoryPicker.SelectedItem, areaPicker.SelectedItem);
- }
- private void LoadFilters()
- {
- LoadTags();
- LoadAreas();
- PopulateLists();
- }
- private void LoadTags()
- {
- CoreTable table = new Client<JobDocumentSetTag>().Query();
- foreach (CoreRow row in table.Rows)
- {
- var tag = row.ToObject<JobDocumentSetTag>();
- if (tag.Job.ID == Guid.Empty || tag.Job.ID == JobID)
- CategoriseTag(tag);
- }
- }
- private void LoadAreas()
- {
- CoreTable table = new Client<JobITP>().Query(
- new Filter<JobITP>(x => x.Job.ID).IsEqualTo(JobID),
- new Columns<JobITP>(x => x.Code));
- foreach (CoreRow row in table.Rows)
- Areas.Add(row.Get<JobITP, string>(x => x.Code));
- }
- private void PopulateLists()
- {
- disciplinePicker.AddItems(Disciplines, CheckNotBlank(JobDocFilterType.Discipline));
- typePicker.AddItems(Types, CheckNotBlank(JobDocFilterType.Type));
- categoryPicker.AddItems(Categories, CheckNotBlank(JobDocFilterType.Category));
- areaPicker.AddItems(Areas, CheckNotBlank(JobDocFilterType.Area));
- }
- private string CheckNotBlank(JobDocFilterType type)
- {
- return Filters.ContainsKey(type) ? Filters[type] : "";
- }
- private void CategoriseTag(JobDocumentSetTag tag)
- {
- if (tag.Type == JobDocumentSetTagType.Discipline)
- Disciplines.Add(tag.Description);
- else if (tag.Type == JobDocumentSetTagType.Type)
- Types.Add(tag.Description);
- else if (tag.Type == JobDocumentSetTagType.Category)
- Categories.Add(tag.Description);
- }
- }
- }
|