123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using comal.timesheets.Tasks;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI;
- using XF.Material.Forms.UI.Dialogs;
- namespace comal.timesheets.QAForms
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class EmployeeFormPicker : ContentPage
- {
- List<EmployeeFormShell> employeeFormShells = new List<EmployeeFormShell>();
- Guid empID = Guid.Empty;
- List<string> roles = new List<string>();
- bool firstLoad = true;
- Employee employee = new Employee();
- public EmployeeFormPicker()
- {
- InitializeComponent();
- empID = GlobalVariables.EmpID;
- filterOptionsControl.OnFilterOptionChanged += FilterOptionsControl_OnFilterOptionChanged;
- roles.Add("All");
- LoadEmployee();
- NavigationPage.SetHasBackButton(this, false);
- }
- private void LoadEmployee()
- {
- Task.Run(() =>
- {
- employee = new Client<Employee>().Query(new Filter<Employee>(x => x.ID).IsEqualTo(empID)).Rows.FirstOrDefault().ToObject<Employee>();
- });
- }
- private void FilterOptionsControl_OnFilterOptionChanged(string filterOption)
- {
- if (filterOption == filterOptionsControl.CurrentOption)
- return;
- filterOptionsControl.CurrentOption = filterOption;
- if (filterOption == "All")
- {
- employeeFormDisplayList.ItemsSource = employeeFormShells;
- }
- else
- {
- employeeFormDisplayList.ItemsSource = employeeFormShells.Where(x => x.Role.Equals(filterOption));
- }
- }
- void ExitBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- protected async override void OnAppearing()
- {
- LoadData();
- base.OnAppearing();
- }
- async void LoadData()
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Refreshing"))
- {
- Title = "Loading";
- await Task.Run(() =>
- {
- employeeFormShells.Clear();
- string emptyString = "";
- CoreTable table = new Client<EmployeeForm>().Query(
- new Filter<EmployeeForm>(x => x.Parent.ID).IsEqualTo(empID),
- new Columns<EmployeeForm>(
- x => x.ID, //0
- x => x.Form.Description, //1
- x => x.FormCompleted, //2
- x => x.FormData, //3
- x => x.Created, //4
- x => x.Form.ID //5
- ),
- new SortOrder<EmployeeForm>(x => x.Created, SortDirection.Descending)
- );
- 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] = emptyString; } //1
- if (list[2] == null) { list[2] = DateTime.MinValue; } //2
- if (list[3] == null) { list[3] = emptyString; } //3
- if (list[4] == null) { list[4] = DateTime.MinValue; } //4
- if (list[5] == null) { list[5] = Guid.Empty; } //5
- EmployeeFormShell shell = new EmployeeFormShell();
- shell.ID = Guid.Parse(list[0].ToString());
- shell.Description = list[1].ToString();
- shell.Completed = DateTime.Parse(list[2].ToString());
- shell.Created = "Created: " + DateTime.Parse(list[4].ToString()).ToString("dd MMM yy");
- if (shell.Completed != DateTime.MinValue)
- {
- shell.Color = Color.FromHex("#15C7C1"); //light blue
- shell.Status = "Status: Completed " + shell.Completed.ToString("dd-MMMM-yy");
- }
- else if (!string.IsNullOrWhiteSpace(list[3].ToString()))
- {
- shell.Color = Color.Orange;
- shell.Status = "Status: In Progress";
- }
- else
- {
- shell.Color = Color.FromHex("#f08080"); //light coral / red
- shell.Status = "Status: Not started";
- }
- CoreTable table2 = new Client<RoleForm>().Query(new Filter<RoleForm>(x => x.Form.ID).IsEqualTo(Guid.Parse(list[5].ToString())),
- new Columns<RoleForm>(x => x.Role.Name));
- if (table2.Rows.Any())
- {
- List<object> list2 = table2.Rows.FirstOrDefault().Values;
- if (list2[0] == null) { list2[0] = ""; } //0
- string role = list2[0].ToString();
- shell.Role = role;
- if (!roles.Contains(role))
- {
- roles.Add(role);
- }
- }
- employeeFormShells.Add(shell);
- }
- Device.BeginInvokeOnMainThread(() =>
- {
- if (firstLoad)
- {
- filterOptionsControl.Options = roles;
- filterOptionsControl.CreateRadioButtonsAndSetDefault(roles.First());
- firstLoad = false;
- }
- employeeFormDisplayList.ItemsSource = null;
- employeeFormDisplayList.ItemsSource = employeeFormShells;
- Title = "My Employee Forms";
- });
- });
- }
- }
- async void LayoutsList_Tapped(object sender, EventArgs e)
- {
- try
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- bool readOnly = false;
- EmployeeForm empForm = new EmployeeForm();
- EmployeeFormShell shell = employeeFormDisplayList.SelectedItem as EmployeeFormShell;
- CoreTable table0 = new Client<EmployeeForm>().Query(
- new Filter<EmployeeForm>(x => x.ID).IsEqualTo(shell.ID),
- new Columns<EmployeeForm>(
- 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.FormStarted, //7
- x => x.FormOpen, //8
- x => x.Parent.ID,
- x => x.BlobData
- )
- );
- if (table0.Rows.Any())
- {
- empForm = table0.Rows.First().ToObject<EmployeeForm>();
- if (empForm.FormCompleted != DateTime.MinValue)
- {
- readOnly = true;
- }
- DigitalFormLayout layout = new DigitalFormLayout();
- CoreTable table = new Client<DigitalFormLayout>().Query(
- new Filter<DigitalFormLayout>(x => x.Form.ID).IsEqualTo(empForm.Form.ID)
- );
- if (table.Rows.Any())
- {
- layout = table.Rows.FirstOrDefault().ToObject<DigitalFormLayout>();
- }
- var model = new DigitalFormHostModel<Employee, EmployeeLink, EmployeeForm>();
- model.LoadItems(employee, empForm, layout);
- DigitalFormHost host = new DigitalFormHost(model);
- Navigation.PushAsync(host);
- }
- }
- }
- catch { }
- }
- }
- public class EmployeeFormShell
- {
- public Guid ID { get; set; }
- public string Description { get; set; }
- public Color Color { get; set; }
- public DateTime Completed { get; set; }
- public string Status { get; set; }
- public string Created { get; set; }
- public string Role { get; set; }
- public EmployeeFormShell()
- {
- ID = Guid.Empty;
- Description = "";
- Color = Color.Default;
- Completed = DateTime.MinValue;
- Status = "";
- Created = "";
- Role = "";
- }
- }
- }
|