async private Task <bool> SaveRegistrationsAndSignatureDataToServer(Planning planning, int statusID)
        {
            try {
                SQLiteConnection db = App.dbHandler.db;
                StatusResult     statusResult;

                //lbStatus.Text = "Sending registrations"
                //activityIndicator.IsRunning = activityIndicator.IsVisible = true;
                UpdateUI(true);

                var regs = from r in db.Table <Registration> ()
                           where r.PlanningID == planning.ID
                           select r;
                List <rsRegistration> registrationList = new List <rsRegistration> (regs.Count() + 1);
                foreach (Registration r in regs)
                {
                    rsRegistration reg = new rsRegistration()
                    {
                        ID            = r.IDguid,
                        PlanningID    = r.PlanningIDguid,
                        OrderID       = r.OrderIDguid,
                        UserID        = r.UserIDguid,
                        Date          = r.Date,
                        RegTypeID     = r.RegTypeID,
                        Priority      = r.Priority,
                        IsDisplayed   = r.IsDisplayed,
                        IsOnReport    = r.IsOnReport,
                        IsRequired    = r.IsRequired,
                        IsReadingOnly = r.IsReadingOnly,
                        Caption       = r.Caption,
                        Result        = r.Result,
                        PathName      = r.PathName,
                        Input         = r.Input,
                        IsClientReg   = r.IsClientReg,
                        IsChanged     = r.IsChanged,
                        IsDeleted     = r.IsDeleted
                    };
                    registrationList.Add(reg);
                }

                //lbSendStatus.Text = text.SendingArticles;

                var artRegs = (from a in db.Table <ArticleReg> ()
                               where a.PlanningID == planning.ID
                               select new rsArticleReg()
                {
                    ArticleID = a.ArticleID, Article = "", OrderID = a.OrderIDguid, PlanningID = a.PlanningIDguid, Qty = a.Qty, IsChanged = a.IsChanged,
                    IsDeleted = a.IsDeleted, PriceIn = a.PriceIn, PriceOut = a.PriceOut
                }).ToList <rsArticleReg> ();

                // Save registrations and articleregistrations to server
                //
                SaveRegistrationInput input = new SaveRegistrationInput()
                {
                    userIDin       = App.appSettings.loginVars.userID.ToString(),
                    installationID = App.appSettings.installationID,
                    registrations  = registrationList,
                    articles       = artRegs
                };
                MobRegService service = new MobRegService(ProgramVars.URL);
                statusResult = await service.SaveRegistrationsAsync(input);

                if (statusResult.statusCode != 0)
                {
                    throw new Exception(statusResult.status);
                }


                //
                // SaveRegistrations completed OK, next SavePlanning
                //
                // input.dataIn, input.overWriteExecEndDateTime, input.includeSignatureData, input.sendReport, input.resources
                rsPlanning rsplanning        = planning.TOrsPlanning();
                var        planningResources = db.Table <Resource> ().Where(r => r.PlanningID == planning.ID);
                if (planningResources != null && planningResources.Count() > 0)
                {
                    rsplanning.Resources = new List <rsResource> (planningResources.Count());
                    foreach (Resource res in planningResources)
                    {
                        rsplanning.Resources.Add(res.TOrsResource());
                    }
                }

                SavePlanningInput saveInput = new SavePlanningInput()
                {
                    userIDin                 = App.appSettings.loginVars.userID.ToString(),
                    installationID           = App.appSettings.installationID,
                    dataIn                   = rsplanning,
                    overWriteExecEndDateTime = false,
                    includeSignatureData     = true,
                    sendReport               = false,
                    resources                = Common.GetResourcesForPlanningID(planning.ID)
                };
                statusResult = await service.SavePlanningAsync(saveInput);

                if (statusResult.statusCode != 0)
                {
                    throw new Exception(statusResult.status);
                }

                // Save all pictures with changes and not deleted to server
                //
                var regPics = from r in db.Table <Registration> ()
                              where r.PlanningID == planning.ID && r.RegTypeID == RegistrationTypes.Picture && r.IsChanged && !r.IsDeleted
                              select r;
                IFileSystem fileSystem = DependencyService.Get <IFileSystem>();
                string      handlerUrl, path;
                foreach (Registration r in regPics)
                {
                    path = fileSystem.GetDataPath($"{r.ID}.jpg");
                    if (fileSystem.ExistsFile(path).statusCode == 0)
                    {
                        handlerUrl = string.Format("{0}?regid={1}&userid={2}&instid={3:d}&mode=up", ProgramVars.ImageHandlerUrl,
                                                   r.ID, r.UserID, App.appSettings.installationID);
                        statusResult = await service.SaveBinaryAsync(handlerUrl, fileSystem.OpenFileStream(path));

                        if (statusResult.statusCode != 0)
                        {
                            throw new Exception(statusResult.status);
                        }
                    }
                }

                //statusPanel.Visible = false;

                // Save signature
                //
                handlerUrl = string.Format("{0}?regid={1}&userid={2}&instid={3:d}&mode=SIGNATURE", ProgramVars.ImageHandlerUrl,
                                           planning.ID, App.appSettings.loginVars.userID.ToString(), App.appSettings.installationID);
                path         = fileSystem.GetDataPath($"sig{planning.ID}.png");
                statusResult = await service.SaveBinaryAsync(handlerUrl, fileSystem.OpenFileStream(path));

                if (statusResult.statusCode != 0)
                {
                    throw new Exception(statusResult.status);
                }

                //activityIndicator.IsRunning = activityIndicator.IsVisible = false;
                UpdateUI(true);

                return(true);
            } catch (Exception ex) {
                //statusPanel.Visible = false;
                //activityIndicator.IsRunning = activityIndicator.IsVisible = false;
                UpdateUI(false);
                await DisplayAlert(AppResources.Error, ex.Message, AppResources.OK);

                return(false);
            }
        }
        }        //end method

        protected async Task PerformStatusChange(int selectedStatusID)
        {
            StatusResult result;

            try {
                //Update server
                //
                UpdateUI(true);
                MobRegService     service = new MobRegService(ProgramVars.URL);
                UpdateStatusInput input   = new UpdateStatusInput()
                {
                    newStatus      = selectedStatusID,
                    userID         = App.appSettings.loginVars.userID.ToString(),
                    installationID = App.appSettings.installationID,
                    planningID     = planning.ID,
                    resources      = Common.GetResourcesForPlanningID(planning.ID)
                };
                result = await service.UpdateStatusForGroupAsync(input);

                if (result.statusCode != 0)
                {
                    throw new Exception(result.status);
                }
                //Update client
                //
                Common.ChangeStatus(planning, selectedStatusID);


                // Do post status change processing
                //
                if (selectedStatusID == StatusTypes.FinishedOK || selectedStatusID == StatusTypes.FinishedNOK)
                {
                    planning.ExecEndDateTime = time;
                    // Send ExecXXXDateTimes to server
                    //
                    SavePlanningInput saveInput = new SavePlanningInput()
                    {
                        userIDin                 = App.appSettings.loginVars.userID.ToString(),
                        installationID           = App.appSettings.installationID,
                        dataIn                   = planning.TOrsPlanning(),
                        overWriteExecEndDateTime = true,
                        includeSignatureData     = false,
                        sendReport               = true,
                        resources                = Common.GetResourcesForPlanningID(planning.ID)
                    };
                    result = await service.SavePlanningAsync(saveInput);

                    if (result.statusCode != 0)
                    {
                        throw new Exception(result.status);
                    }

                    // Delete all planning related data from client
                    //
                    Common.DeletePlanningByPlanningID(planning.ID);
                }
                else
                {
                    // Update PlanningHistory table
                    //
                    planning.StatusID = selectedStatusID;
                    App.dbHandler.db.Update(planning);
                    PlanningHistory his = new PlanningHistory()
                    {
                        PlanningID = planning.ID,
                        StatusID   = planning.StatusID,
                        StartTime  = time,
                        EndTime    = time
                    };
                    App.dbHandler.db.Insert(his);
                }
                //activityIndicator.IsRunning = activityIndicator.IsVisible = false;
                UpdateUI(false);
                await App.Current.MainPage.Navigation.PopAsync(true);
            } catch (Exception ex) {
                UpdateUI(false);
                //activityIndicator.IsRunning = activityIndicator.IsVisible = false;
                await DisplayAlert(AppResources.Error, ex.Message, AppResources.Cancel);
            }
        }