| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- using System;
- using System.Collections.Generic;
- using Xamarin.Forms;
- using InABox.Core;
- using Comal.Classes;
- using InABox.Clients;
- using System.Linq;
- using System.Threading.Tasks;
- using Syncfusion.XForms.PopupLayout;
- using Xamarin.Essentials;
- using System.Windows.Input;
- using PRSSecurity = InABox.Core.Security;
- namespace comal.timesheets
- {
- class StaffStatus
- {
- public Guid ID { get; set; }
- public String StaffName { get; set; }
- public String In { get; set; }
- public String Out { get; set; }
- public string Mobile { get; set; }
- public string StaffLocation { get; set; }
- public bool InTimeVisible { get; set; }
- public bool OutTimeVisible { get; set; }
- public bool InImageVisible { get; set; }
- public bool OutImageVisible { get; set; }
- public bool HiddenRowVisible { get; set; }
- public int HiddenRowHeight { get; set; }
- public StaffStatus()
- {
- ID = Guid.Empty;
- StaffName = "";
- In = "";
- Out = "";
- StaffLocation = "";
- InTimeVisible = true;
- OutTimeVisible = true;
- InImageVisible = false;
- OutImageVisible = false;
- HiddenRowVisible = false;
- HiddenRowHeight = 0;
- Mobile = "";
- }
- }
- public partial class StaffStatusPage : ContentPage
- {
- CoreTable employees = null;
- CoreTable timesheets = null;
- bool bManager = false;
- public StaffStatusPage()
- {
- InitializeComponent();
- if (PRSSecurity.IsAllowed<CanViewMobileInOutBoardDetails>())
- bManager = true;
- ConfigurePage();
- }
- private void ConfigurePage()
- {
- NavigationPage.SetHasBackButton(this, false);
- ToolbarItems.Clear();
- ToolbarItems.Add(new ToolbarItem("Back", "", () =>
- {
- Navigation.PopAsync();
- }));
- popupLayout.PopupView.AppearanceMode = AppearanceMode.OneButton;
- popupLayout.PopupView.HeaderTitle = "Contact Details";
- Title = "In/Out Board";
- }
- protected override void OnAppearing()
- {
- base.OnAppearing();
- LoadData();
- }
- private void StaffList_Tapped(object sender, EventArgs e)
- {
- CreatePopup((StaffList.SelectedItem as StaffStatus).Mobile);
- popupLayout.Show();
- }
- private void CreatePopup(string mobile)
- {
- popupLayout.PopupView.FooterTemplate = new DataTemplate(() =>
- {
- return CreateFrame(mobile);
- });
- popupLayout.PopupView.ContentTemplate = new DataTemplate(() =>
- {
- return CreatePopupContent(mobile);
- });
- }
- private Label CreatePopupContent(string mobile)
- {
- return new Label
- {
- Text = "Mobile: " + mobile,
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Center,
- HorizontalTextAlignment = TextAlignment.Center,
- VerticalTextAlignment = TextAlignment.Center,
- FontAttributes = FontAttributes.Bold,
- FontSize = 24
- };
- }
- private Grid CreateGrid(Image img, Label label)
- {
- var grid = new Grid { BackgroundColor = Color.FromHex("#15C7C1"), RowSpacing = 0, ColumnSpacing = 0, Padding = 0, Margin = 0 };
- grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
- grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
- Grid.SetColumn(img, 0);
- Grid.SetColumn(label, 1);
- grid.Children.Add(img);
- grid.Children.Add(label);
- return grid;
- }
- private Image CreateImage(string mobile)
- {
- Image img = new Image
- {
- Source = "call.png",
- HeightRequest = 40,
- WidthRequest = 40,
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Center,
- Margin = 0,
- };
- img.GestureRecognizers.Add(new TapGestureRecognizer
- {
- Command = CallPerson(mobile)
- });
- return img;
- }
- private Label CreateCallLabel(string mobile)
- {
- Label label = new Label
- {
- Text = "Call",
- FontAttributes = FontAttributes.Bold,
- FontSize = 24,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- VerticalOptions = LayoutOptions.FillAndExpand,
- HorizontalTextAlignment = TextAlignment.Start,
- VerticalTextAlignment = TextAlignment.Center,
- BackgroundColor = Color.FromHex("#15C7C1"),
- TextColor = Color.White,
- Margin = 0
- };
- label.GestureRecognizers.Add(new TapGestureRecognizer
- {
- Command = CallPerson(mobile)
- });
- return label;
- }
- private Frame CreateFrame(string mobile)
- {
- var img = CreateImage(mobile);
- var label = CreateCallLabel(mobile);
- var grid = CreateGrid(img, label);
- Frame frame = new Frame
- {
- Content = grid,
- Padding = 0,
- Margin = 0,
- BackgroundColor = Color.FromHex("#15C7C1")
- };
- frame.GestureRecognizers.Add(new TapGestureRecognizer
- {
- Command = CallPerson(mobile)
- });
- return frame;
- }
- private ICommand CallPerson(string mobile)
- {
- return new Command(() =>
- {
- try
- {
- PhoneDialer.Open(mobile);
- }
- catch (Exception e2)
- {
- string s = e2.Message;
- }
- });
- }
- private void LoadData()
- {
- Task.Run(() =>
- {
- ShowLoading();
- CoreTable employees = QueryEmployees();
- CoreTable timesheets = QueryTimeSheets();
- List<StaffStatus> staff = new List<StaffStatus>();
- foreach (CoreRow row in employees.Rows)
- staff.Add(CreateStatus(row, timesheets));
- ShowList(staff);
- });
- }
- private void ShowList(List<StaffStatus> staff)
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- loadingColumn.Width = 0;
- listViewColumn.Width = new GridLength(1, GridUnitType.Star);
- loadingLayout.IsVisible = false;
- StaffList.IsVisible = true;
- StaffList.ItemsSource = staff;
- });
- }
- private StaffStatus CreateStatus(CoreRow row, CoreTable timesheets)
- {
- Guid empid = row.Get<Employee, Guid>(x => x.ID);
- String name = row.Get<Employee, String>(x => x.Name);
- CoreRow startrow = timesheets.Rows.FirstOrDefault(r => r.Get<TimeSheet, Guid>(c => c.EmployeeLink.ID).Equals(empid));
- CoreRow finishrow = timesheets.Rows.LastOrDefault(r => r.Get<TimeSheet, Guid>(c => c.EmployeeLink.ID).Equals(empid));
- String sIn = "";
- String sOut = "";
- if (startrow != null)
- {
- TimeSpan start = startrow.Get<TimeSheet, TimeSpan>(c => c.Start);
- TimeSpan finish = finishrow.Get<TimeSheet, TimeSpan>(c => c.Finish);
- sIn = String.Format("{0:hh\\:mm} ", start);
- if (finish.Ticks > 0)
- sOut = String.Format("{0:hh\\:mm}", finish);
- }
- var status = new StaffStatus()
- {
- StaffName = row.Get<Employee, String>(x => x.Name),
- ID = empid,
- In = sIn,
- Out = sOut
- };
- if (!string.IsNullOrWhiteSpace(row.Get<Employee, string>(x => x.Mobile)))
- status.Mobile = row.Get<Employee, String>(x => x.Mobile);
- if (!bManager)
- status = ShowDots(status);
- else if (startrow != null)
- status = ShowManagerOptions(status, startrow);
- return status;
- }
- private StaffStatus ShowManagerOptions(StaffStatus status, CoreRow startrow)
- {
- status.StaffLocation = startrow.Get<string>("Address");
- if (!string.IsNullOrWhiteSpace(status.StaffLocation))
- {
- status.HiddenRowVisible = true;
- status.HiddenRowHeight = 30;
- }
- return status;
- }
- private StaffStatus ShowDots(StaffStatus status)
- {
- status.InTimeVisible = false;
- status.OutTimeVisible = false;
- if (!string.IsNullOrWhiteSpace(status.In))
- status.InImageVisible = true;
- if (!string.IsNullOrWhiteSpace(status.Out))
- status.OutImageVisible = true;
- return status;
- }
- private void ShowLoading()
- {
- Device.BeginInvokeOnMainThread(async () =>
- {
- for (int i = 0; i < 10; i++)
- {
- Random random = new Random();
- uint number = (uint)random.Next(500, 3000);
- await loadingLbl.TranslateTo(0, 15, 500);
- await loadingLbl.TranslateTo(0, 0, 500);
- loadingLbl.RotateTo(360, number);
- await loadingLbl.TranslateTo(0, 15, 500);
- await loadingLbl.TranslateTo(0, 0, 500);
- await loadingLbl.TranslateTo(0, 15, 500);
- await loadingLbl.TranslateTo(0, 0, 500);
- await loadingLbl.TranslateTo(0, 15, 500);
- number = (uint)random.Next(500, 3000);
- await loadingLbl.TranslateTo(0, 0, 500);
- loadingLbl.RotateTo(360, number);
- }
- });
- }
- private CoreTable QueryEmployees()
- {
- return new Client<Employee>().Query(
- LookupFactory.DefineFilter<Employee>().And
- (x => x.Name).IsNotEqualTo("Administrator"),
- new Columns<Employee>(x => x.ID, x => x.Name, x => x.Mobile),
- new SortOrder<Employee>(x => x.Name)
- );
- }
- private CoreTable QueryTimeSheets()
- {
- return new Client<TimeSheet>().Query(
- new Filter<TimeSheet>(x => x.Date).IsEqualTo(DateTime.Today),
- new Columns<TimeSheet>(x => x.EmployeeLink.ID, x => x.Start, x => x.Finish, x => x.Address),
- new SortOrder<TimeSheet>(x => x.EmployeeLink.ID).ThenBy(x => x.Start)
- );
- }
- }
- }
|