Exemplo n.º 1
0
        /// <summary>
        ///     Executes the save command.
        /// </summary>
        /// <returns>The save command.</returns>
        private async Task ExecuteSaveCommand()
        {
            var saved = false;

            if (IsBusy)
            {
                return;
            }

            if (ServerAddress.Trim() == null || ServerAddress.Trim().Length < 1)
            {
                Page.DisplayAlertMessage("", HACCPUtil.GetResourceString("EnterServerIPAddressorDomainName"));
                return;
            }
            var isDataExists = false;

            Page.EndEditing();
            IsBusy = true;
            SaveCommand.ChangeCanExecute();
            Page.ShowProgressIndicator();
            var currentServerAddressStatus = IsServerAddressExist;

            try
            {
                var isConnected = await TestConnection(false);

                if (isConnected)
                {
                    if (currentServerAddressStatus)
                    {
                        isDataExists = dataStore.CheckTemperaturesExists() || dataStore.CheckCheckListsExists();
                    }

                    if (isDataExists == false)
                    {
                        HaccpAppSettings.SharedInstance.SiteSettings.ServerAddress   = ServerAddress.Trim();
                        HaccpAppSettings.SharedInstance.SiteSettings.ServerPort      = Port.Trim();
                        HaccpAppSettings.SharedInstance.SiteSettings.ServerDirectory = ServerDirectory.Trim();

                        dataStore.SaveSiteSettings(HaccpAppSettings.SharedInstance.SiteSettings);

                        saved = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Ooops! Something went wrong while save connection. Exception: {0}", ex);
            }
            finally
            {
                IsBusy = false;
                SaveCommand.ChangeCanExecute();
                Page.DismissPopup();
            }
            if (saved)
            {
                await Page.ShowAlert("", HACCPUtil.GetResourceString("ServerSettingsupdatedsuccessfully"));

                if (currentServerAddressStatus)
                {
                    await Page.PopPage();
                }
                else
                {
                    //if (HaccpAppSettings.SharedInstance.IsWindows)
                    //{
                    //    var style = Application.Current.Resources["WindowsListScrollHelpGridStyle"] as Style;
                    //    if (style != null)
                    //    {
                    //        style.Setters.RemoveAt(0);
                    //        style.Setters.Insert(0, new Setter {Property = VisualElement.HeightRequestProperty, Value = 90});
                    //    }

                    //    var recordstyle = Application.Current.Resources["WindowsScrollHelpGridStyle"] as Style;
                    //    if (recordstyle != null)
                    //    {
                    //        recordstyle.Setters.RemoveAt(0);
                    //        recordstyle.Setters.Insert(0,
                    //            new Setter {Property = VisualElement.HeightRequestProperty, Value = 85});
                    //    }
                    //    // related to scroll issue fix after changing language
                    //}
                    Page.LoadHomePage();
                }
            }
            else if (isDataExists)
            {
                var siteSettings = new SiteSettings
                {
                    ServerAddress   = ServerAddress.Trim(),
                    ServerPort      = Port.Trim(),
                    ServerDirectory = ServerDirectory.Trim()
                };
                await Page.NavigateToWithSelectedObject(PageEnum.ServerSettingsConfirmation, true, siteSettings);
            }
        }