123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- using comal.timesheets.CustomControls;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using InABox.Core;
- using Comal.Classes;
- using InABox.Clients;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- using comal.timesheets.QAForms;
- namespace comal.timesheets.SiteITPModule
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class JobITPDetails
- {
- private JobITPShell _itp = null;
- Guid itpID = Guid.Empty;
- DigitalFormLayout layout = new DigitalFormLayout();
- bool layoutLoaded;
- List<ITPFormShell> iTPFormShells = new List<ITPFormShell>();
- JobITP jobITP = new JobITP();
- public JobITPDetails(JobITPShell itp)
- {
- InitializeComponent();
- _itp = itp;
- layoutLoaded = false;
- ITPNameLbl.Text = "ITP Area: " + itp.Description;
- }
- protected override void OnAppearing()
- {
- LoadList();
- base.OnAppearing();
- }
- private async void LoadLayoutIDForITP()
- {
- try
- {
- await Task.Run(() =>
- {
- CoreTable table1 = new Client<JobITP>().Query
- (
- new Filter<JobITP>(x => x.ID).IsEqualTo(itpID),
- new Columns<JobITP>(x => x.DigitalForm.ID,
- x => x.ID,
- x => x.Code)
- );
- if (table1.Rows.Any())
- {
- List<object> list = table1.Rows.First().Values;
- if (list[0] == null) list[0] = Guid.Empty;
- jobITP.ID = Guid.Parse(list[1].ToString());
- jobITP.Code = list[2].ToString();
- if (Guid.Parse(list[0].ToString()) != Guid.Empty)
- {
- CoreTable table = new Client<DigitalFormLayout>().Query(
- new Filter<DigitalFormLayout>(x => x.Form.ID).IsEqualTo(Guid.Parse(list[0].ToString()))
- );
- if (table.Rows.Any())
- {
- layout = table.Rows.FirstOrDefault().ToObject<DigitalFormLayout>();
- layoutLoaded = true;
- Device.BeginInvokeOnMainThread(() =>
- {
- DFDescriptionLbl.Text = "Digital Form Template: " + layout.Description;
- });
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- DisplayAlert("Alert", "No form layouts found for ITP", "OK");
- });
- }
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- DisplayAlert("Alert", "No form layouts found for ITP", "OK");
- });
- }
- }
- else if (iTPFormShells.Count > 0)
- {
- CoreTable table = new Client<DigitalFormLayout>().Query(new Filter<DigitalFormLayout>(x => x.Form.ID).IsEqualTo(iTPFormShells.First().FormID));
- if (table.Rows.Any())
- {
- layout = table.Rows.FirstOrDefault().ToObject<DigitalFormLayout>();
- layoutLoaded = true;
- Device.BeginInvokeOnMainThread(() =>
- {
- DFDescriptionLbl.Text = "Digital Form Template: " + layout.Description;
- });
- }
- }
- else
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- DisplayAlert("Alert", "No form layouts found for ITP", "OK");
- });
- }
- });
- }
- catch { }
- }
- private async void LoadList()
- {
- try
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- iTPFormShells.Clear();
- CoreTable table = new Client<JobITPForm>().Query(
- new Filter<JobITPForm>(x => x.Parent.ID).IsEqualTo(itpID),
- new Columns<JobITPForm>(
- x => x.ID, //0
- x => x.Form.Description, //1
- x => x.FormCompleted, //2
- x => x.Form.ID, //3
- x => x.Description, //4
- x => x.FormData, //5
- x => x.LastUpdate, //6
- x => x.LastUpdateBy, //7
- x => x.Created //8
- ),
- new SortOrder<JobITPForm>(x => x.FormCompleted)
- );
- foreach (CoreRow row in table.Rows)
- {
- List<object> list = row.Values;
- if (list[0] == null) { list[0] = Guid.Empty; } //0
- if (list[1] == null) { list[1] = ""; } //1
- if (list[2] == null) { list[2] = DateTime.MinValue; } //2
- if (list[3] == null) { list[3] = Guid.Empty; } //3
- if (list[4] == null) { list[4] = ""; } //4
- if (list[5] == null) { list[5] = ""; } //5
- if (list[6] == null) { list[6] = DateTime.MinValue; } //6
- if (list[7] == null) { list[7] = ""; } //7
- if (list[8] == null) { list[8] = DateTime.MinValue; } //8
- ITPFormShell shell = new ITPFormShell
- {
- ID = Guid.Parse(list[0].ToString()),
- Description = list[4].ToString(),
- Completed = DateTime.Parse(list[2].ToString()),
- FormID = Guid.Parse(list[3].ToString())
- };
- if (string.IsNullOrWhiteSpace(shell.Description))
- {
- shell.Description = list[1].ToString();
- }
- if (shell.Completed != DateTime.MinValue)
- {
- shell.Color = Color.FromHex("#15C7C1"); //light blue
- shell.Status = "Completed (" + shell.Completed.ToString("dd-MMMM-yy") + ")";
- }
- else if (!string.IsNullOrWhiteSpace(list[5].ToString()))
- {
- shell.Color = Color.Orange;
- shell.Status = "In Progress (Updated: " + DateTime.Parse(list[6].ToString()).ToString("dd-MMMM-yy") + ")";
- }
- else
- {
- shell.Color = Color.FromHex("#f08080"); //light coral / red
- shell.Status = "To Do (Created " + DateTime.Parse(list[8].ToString()).ToString("dd-MMMM-yy") + ")";
- }
- iTPFormShells.Add(shell);
- }
- if (!layoutLoaded)
- LoadLayoutIDForITP();
- Device.BeginInvokeOnMainThread(() =>
- {
- ITPFormDisplayList.ItemsSource = null;
- ITPFormDisplayList.ItemsSource = iTPFormShells;
- countLbl.Text = "Number of Forms: " + iTPFormShells.Count;
- });
- }
- }
- catch { }
- }
- private async void Add_Clicked(object sender, EventArgs e)
- {
- try
- {
- if (!layoutLoaded)
- {
- DisplayAlert("No form layouts found for ITP", "Unable to add a form", "OK");
- return;
- }
- JobITPForm newForm = new JobITPForm();
- newForm.Parent.ID = itpID;
- string chosenOption = await DisplayPromptAsync("Enter Location", "", "OK", "Cancel");
- if (!string.IsNullOrEmpty(chosenOption))
- {
- if (chosenOption != "Cancel")
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- newForm.Form.ID = layout.Form.ID;
- newForm.Description = chosenOption;
- new Client<JobITPForm>().Save(newForm, "Added on mobile device");
- }
- LoadList();
- }
- }
- }
- catch { }
- }
- private async void ITPFormList_Tapped(object sender, EventArgs e)
- {
- try
- {
- if (!layoutLoaded)
- return;
- ITPFormShell shell = ITPFormDisplayList.SelectedItem as ITPFormShell;
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- bool readOnly = false;
- CoreTable table0 = new Client<JobITPForm>().Query(
- new Filter<JobITPForm>(x => x.ID).IsEqualTo(shell.ID),
- new Columns<JobITPForm>(
- x => x.ID, //0
- x => x.Form.Description, //1
- x => x.Form.AppliesTo, //2
- x => x.FormCompleted, //3
- x => x.FormCompletedBy.ID, //4
- x => x.FormData, //5
- x => x.Form.ID, //6
- x => x.Parent.ID, //7
- x => x.FormStarted, //8
- x => x.FormOpen, //9
- x => x.BlobData
- )
- );
- if (table0.Rows.Any())
- {
- JobITPForm existingForm = table0.Rows.First().ToObject<JobITPForm>();
- if (existingForm.FormCompleted != DateTime.MinValue)
- {
- readOnly = true;
- }
- DigitalFormHostModel<JobITP, JobITPLink, JobITPForm> model = new DigitalFormHostModel<JobITP, JobITPLink, JobITPForm>();
- model.LoadItems(jobITP, existingForm, layout);
- DigitalFormHost host = new DigitalFormHost(model);
-
- Navigation.PushAsync(host);
- }
- }
- }
- catch
- {
- DisplayAlert("Error opening form", "", "OK");
- }
- }
- }
- public class ITPFormShell
- {
- public Guid ID { get; set; }
- public string Description { get; set; }
- public string Status { get; set; }
- public string StatusDetails { get; set; }
- public Color Color { get; set; }
- public DateTime Completed { get; set; }
- public Guid FormID { get; set; }
- public ITPFormShell()
- {
- ID = Guid.Empty;
- Description = "";
- Status = "";
- StatusDetails = "";
- Color = Color.Default;
- Completed = DateTime.MinValue;
- FormID = Guid.Empty;
- }
- }
- }
|