///
 #endregion
 /// ------------------------------------------------------------------------------------------------
 #region Public Constructors
 /// ------------------------------------------------------------------------------------------------
 ///
 /// ------------------------------------------------------------------------------------------------
 /// Name		SRiResolution
 ///
 /// <summary>	Creates a new instance of the SRiResolution class.
 /// </summary>
 /// <param name="sent">			The visit that was sent to the API.</param>
 /// <param name="returned">		The visit that was returned from the API in conflict.</param>
 ///
 /// <remarks>
 /// </remarks>
 /// ------------------------------------------------------------------------------------------------
 ///
 public SRiResolution(SRiVisitMeta sent, SRiVisitMeta returned)
 {
     Title       = sent.VisitTypeDescription;
     Description = sent.Visit.DateVisit.ToString("dd/MM/yy HH:mm", "Completed ", "Not complete");
     Type        = "VISIT";
     Selected    = false;
     CaseID      = AppData.PropertyModel.GetRefVal(sent) ?? "No Case ID";
     TradeName   = AppData.PropertyModel.GetTradeName(sent) ?? "No Trading Name";
     //
     // There is only a resolve action required for a conflict.
     if (returned.QueryState.ToUpper().Equals("C"))
     {
         Issue            = SRiResolutionIssue.Conflict;
         m_oResolveAction = () =>
         {
             // Make sure the visit stays as changed and update the version to match the returned.
             sent.Status  = SyncStatus.Changed;
             sent.Version = returned.Version;
             sent.Visit.UpdateVersions(returned.Visit);
             AppData.PropertyModel.Update(sent, sent);
         };
     }
     else if (returned.QueryState.ToUpper().Equals("D"))
     {
         Issue            = SRiResolutionIssue.Deletion;
         m_oResolveAction = () =>
         {
             AppData.PropertyModel.Delete(sent);
         };
     }
 }
        ///
        /// ------------------------------------------------------------------------------------------------
        /// Name        AddActionClick
        /// ------------------------------------------------------------------------------------------------
        ///
        /// <summary> Handles a click on add action
        /// </summary>
        /// ------------------------------------------------------------------------------------------------
        ///
        private void AddActionClick(object sender, EventArgs e)
        {
            try
            {
                SRiVisitMeta visit = AppData.PropertyModel.SelectedVisit.Visit;
                if (!AppData.ConfigModel.Actions(visit.Organisation, visit.Visit.VisitType).Any())
                {
                    LockScreen.ToDisplayAlert(this, "Cannot add Action", "No action types set up in Uniform for this visit type. Please contact your Uniform administrator for assistance.", "OK");
                }
                else
                {
                    Task.Delay(250);
                    PopupContent.ShowPopupRelative(new AddActionView(this, PopupContent), BX_AddActions, Width * 0.40, GetHeight(GroupedListViewModel.Count), true, "");
                    if (Device.OS != TargetPlatform.iOS)
                    {
                        PopupContent._triangleImage.Source = "";
                    }

                    AppData.PropertyModel.SelectedAction = new SelectedAction(new SRiAction()
                    {
                        DueDate     = DateTime.Now,
                        VisitKeyVal = visit.Visit.KeyVal,
                        MDKeyVal    = visit.Visit.MDKeyVal,
                        MDSubSys    = visit.Visit.MDSubSys,
                        Paragraphs  = new List <SRiActionParagraph>()
                    }, AppData.PropertyModel.SelectedVisit.NewActionMapping, true);
                }
            }
            catch (Exception ex)
            {
                LogTracking.LogTrace(ex.ToString());
            }
        }
        /// ------------------------------------------------------------------------------------------------
        #region Public Constructor
        /// ------------------------------------------------------------------------------------------------
        ///
        /// ------------------------------------------------------------------------------------------------
        /// Name		SelectedVisit
        ///
        /// <summary>	Creates a new instance of the SelectedVisit class.
        /// </summary>
        /// <param name="visit">		The visit being selected.</param>
        /// <param name="iMap">			The index mapping of the visit selection.</param>
        /// <param name="isNew">		Whether the entity is a new creation.</param>
        ///
        /// <remarks>
        /// </remarks>
        /// ------------------------------------------------------------------------------------------------
        ///
        public SelectedVisit(SRiVisitMeta visit, IndexMapping iMap, bool isNew)
            : base(iMap, isNew)
        {
            Exception error;

            //
            OnSiteSettings.ShouldSerialize = ShouldSerializeRule.Full;
            Visit        = SRiVisitMeta.FromJson(visit.ToJson(), out error);
            Visit.Status = Visit.Status.SetNewOrChanged(isNew ? SyncStatus.New : SyncStatus.Changed);
            if (error != null)
            {
                throw error;
            }
            SetGroupMod();
        }
        ///
        /// ------------------------------------------------------------------------------------------------
        /// Name        AddActionClick
        /// ------------------------------------------------------------------------------------------------
        ///
        /// <summary> Handles a click on add action
        /// </summary>
        /// ------------------------------------------------------------------------------------------------
        ///
        private void AddActionClick(object sender, EventArgs e)
        {
            SRiVisitMeta visit = AppData.PropertyModel.SelectedVisit.Visit;

            if (!AppData.ConfigModel.Actions(visit.Organisation, visit.Visit.VisitType).Any())
            {
                DisplayAlert("Cannot add Action", "No action types set up in Uniform for this visit type. Please contact your Uniform administrator for assistance.", "Ok");
            }
            else
            {
                PopupContent.ShowPopupRelative(new AddActionView(this, PopupContent), Lbl_AddActions, Width * 0.40, GetHeight(GroupedListViewModel.Count), true, "");
                PopupContent._triangleImage.Source = "";

                AppData.PropertyModel.SelectedAction = new SelectedAction(new SRiAction()
                {
                    DueDate     = DateTime.Now,
                    VisitKeyVal = visit.Visit.KeyVal,
                    MDKeyVal    = visit.Visit.MDKeyVal,
                    MDSubSys    = visit.Visit.MDSubSys,
                    Paragraphs  = new List <SRiActionParagraph>()
                }, AppData.PropertyModel.SelectedVisit.NewActionMapping, true);
            }
        }
Beispiel #5
0
 public static void SetSavedStatus(this SRiVisitMeta v, SRiVisitMeta v2)
 {
     v.Visit.Status = v2.Visit.Status;
 }
        /// ------------------------------------------------------------------------------------------------
        /// Name        OnLoad
        /// ------------------------------------------------------------------------------------------------
        /// <summary>
        /// Load data when the page is loaded.
        /// </summary>
        /// <param name="visitMeta">SRiVisit</param>
        /// ------------------------------------------------------------------------------------------------
        private void OnLoad(SRiVisitMeta visitMeta)
        {
            try
            {
                var visit = visitMeta.Visit;
                Lbl_TitleName.Text = visitMeta.VisitTypeDescription;

                if (visit.DateScheduled != null)
                {
                    if (AppData.PropertyModel.SelectedVisit.Visit.Visit.Status == SyncStatus.New)
                    {
                        var completeDate = visit.DateScheduled.ToString("ddd dd MMM yyyy", "", "");
                        // var completedDateTime = Details.DateScheduled.ToString("h:mm tt", "", "");
                        Dtp_ScheduledDate.Date      = Convert.ToDateTime(completeDate.Replace("\"", ""));
                        Tmp_ScheduledDate.Time      = visit.DateScheduled.Value.TimeOfDay;
                        Dtp_ScheduledDate.IsVisible = true;
                        Tmp_ScheduledDate.IsVisible = true;
                    }
                    else
                    {
                        Lbl_ScheduledDate.Text = visit.DateScheduled != null?visit.DateScheduled.LongishDateTimeFormat() : "No Value Set";
                    }
                }
                else
                {
                    Dtp_ScheduledDate.IsVisible = true;
                    Tmp_ScheduledDate.IsVisible = true;
                    Tmp_ScheduledDate.Time      = DateTime.Now.TimeOfDay;
                    Dtp_ScheduledDate.Date      = DateTime.Now.Date;
                }


                if (visit.DateVisit != null)
                {
                    Pkr_Status.IsVisible        = true;
                    Pkr_Status.SelectedIndex    = Pkr_Status.Items.IndexOf("Completed");
                    Dtp_CompletedDate.Date      = Convert.ToDateTime(visit.DateVisit.ToString("ddd dd MMM yyyy", "", "").Replace("\"", ""));
                    Tmp_CompletedDate.Time      = visit.DateVisit.Value.TimeOfDay;
                    Tmp_CompletedDate.IsVisible = true;
                    Dtp_CompletedDate.IsVisible = true;
                }
                else
                {
                    Pkr_Status.IsVisible        = true;
                    Pkr_Status.SelectedIndex    = Pkr_Status.Items.IndexOf("Outstanding");
                    Dtp_CompletedDate.IsVisible = false;
                    Tmp_CompletedDate.IsVisible = false;
                }

                if (visit.Hours != null)
                {
                    Pkr_TimeTakenHours.SelectedIndex   = Pkr_TimeTakenHours.Items.IndexOf(visit.Hours.ToConvertHt().Item1);
                    Pkr_TimeTakenMinutes.SelectedIndex = Pkr_TimeTakenMinutes.Items.IndexOf(visit.Hours.ToConvertHt().Item2);
                }
                if (visit.Miles != null)
                {
                    Pkr_Miles.SelectedIndex        = Pkr_Miles.Items.IndexOf(visit.Miles.ToConvertMt().Item1);
                    Pkr_DecimalMiles.SelectedIndex = Pkr_DecimalMiles.Items.IndexOf(visit.Miles.ToConvertMt().Item2 ?? Pkr_DecimalMiles.Items[0]);
                }
                if (!string.IsNullOrEmpty(visit.Notes))
                {
                    Ed_Notes.Text = visit.Notes;
                }

                // Added to get the officer Name
                int index;

                var orderedOfficers = AppData.ConfigModel.OfficerList(AppData.PropertyModel.SelectedVisit.Visit.Organisation,
                                                                      AppData.PropertyModel.SelectedVisit.GroupMod).OrderBy(o => o.OfficerCode + o.Name).ToList();

                _groupedOffice = new GroupedListView(orderedOfficers.Select(a => new KeyValuePair <string, string>(a.OfficerCode, a.Name)).ToList(), Lbl_Officer);
                //
                var selectedvisit = AppData.PropertyModel.SelectedVisit.Visit.Visit;
                index = 0;
                if (!string.IsNullOrEmpty(selectedvisit.Officer) && orderedOfficers.Count > 0)
                {
                    for (int i = 0; i < orderedOfficers.Count; i++)
                    {
                        if (orderedOfficers[i].OfficerCode.Equals(selectedvisit.Officer))
                        {
                            index = i;
                            break;
                        }
                    }
                    Lbl_Officer.Text = $"{orderedOfficers[index].OfficerCode} - {orderedOfficers[index].Name}";
                }
                else if (string.IsNullOrEmpty(AppData.PropertyModel.SelectedVisit.GroupMod))
                {
                    var officerCode = AppData.MainModel.CurrentUser.OfficerCode(AppData.PropertyModel.SelectedVisit.Visit.Organisation);
                    var officers    = AppData.ConfigModel.OfficerList(AppData.PropertyModel.SelectedVisit.Visit.Organisation).Where(x => x.OfficerCode == officerCode).OrderBy(o => o.OfficerCode + o.Name).ToList();

                    for (int i = 0; i < officers.Count; i++)
                    {
                        if (officers[i].OfficerCode.Equals(selectedvisit.Officer))
                        {
                            index = i;
                            break;
                        }
                    }
                    Lbl_Officer.Text      = $"{officers[index].OfficerCode} - {officers[index].Name}";
                    Lbl_Officer.TextColor = Color.Black;
                }
                else
                {
                    Lbl_Officer.Text = "Value";
                }
                //
            }
            catch (Exception ex)
            {
                LogTracking.LogTrace(ex.ToString());
            }
        }