Ejemplo n.º 1
0
        async void ButtonSendData_Clicked(object sender, EventArgs e)
        {
            //IHud hud = DependencyService.Get<IHud>();
            hud.Show("Syncing data...");
            int iSyncSuccess = 0;
            int iSyncFailed  = 0;
            await Task.Run(() => _vm.syncWithServer(ref iSyncSuccess, ref iSyncFailed));

            string syncMessage = "";

            if (iSyncFailed > 0 && iSyncSuccess > 0)
            {
                syncMessage = string.Format("{0} transactions synced successfully; {1} transactions failed during sync.", iSyncSuccess, iSyncFailed);
            }
            else if (iSyncSuccess > 0 && iSyncFailed == 0)
            {
                syncMessage = string.Format("{0} transactions synced successfully.", iSyncSuccess);
            }
            else if (iSyncSuccess == 0 && iSyncFailed > 0)
            {
                syncMessage = string.Format("{0} transactions failed during sync.", iSyncFailed);
            }
            else
            {
                syncMessage = "Sync completed successfully.";
            }

            await DisplayAlert("Synchronization", syncMessage, "OK");

            hud.Dismiss();
        }
Ejemplo n.º 2
0
        void ButtonSendData_Clicked(object sender, EventArgs e)
        {
            Button buttonSendData = (Button)sender;

            buttonSendData.IsEnabled = false;
            buttonSendData.Content   = "SENDING DATA...";

            // dch rkl 11/02/2016 add try/catch to catch and display message if the sync fails
            try
            {
                if (!App.Database.HasDataConnection())
                {
                    MessageBoxResult result = System.Windows.MessageBox.Show("No data connection presently, please check and try again.", "Connectivity Issue", MessageBoxButton.OK);
                    if (result == MessageBoxResult.OK)
                    {
                        return;
                    }
                }
                else
                {
                    // dch rkl 12/09/2016 return number failed and number successful
                    int iSyncSuccess = 0;
                    int iSyncFailed  = 0;
                    //_vm.syncWithServer();
                    _vm.syncWithServer(ref iSyncSuccess, ref iSyncFailed);
                    string syncMessage = "";
                    if (iSyncFailed > 0 && iSyncSuccess > 0)
                    {
                        syncMessage = string.Format("{0} transactions synced successfully; {1} transactions failed during sync.", iSyncSuccess, iSyncFailed);
                    }
                    else if (iSyncSuccess > 0 && iSyncFailed == 0)
                    {
                        syncMessage = string.Format("{0} transactions synced successfully.", iSyncSuccess);
                    }
                    else if (iSyncSuccess == 0 && iSyncFailed > 0)
                    {
                        syncMessage = string.Format("{0} transactions failed during sync.", iSyncFailed);
                    }
                    else
                    {
                        syncMessage = "Sync completed successfully.";
                    }

                    // dch rkl 11/02/2016 display message when sync has completed
                    //MessageBoxResult result = System.Windows.MessageBox.Show("Sync has completed successfully.", "Sync Completed", MessageBoxButton.OK);
                    MessageBoxResult result = System.Windows.MessageBox.Show(syncMessage, "Sync Completed", MessageBoxButton.OK);
                }
            }
            catch (Exception ex)
            {
                MessageBoxResult result = System.Windows.MessageBox.Show(String.Format("Sync failed with the following error: {0}", ex.ToString()),
                                                                         "Sync Failed", MessageBoxButton.OK);
            }

            buttonSendData.IsEnabled = true;
            buttonSendData.Content   = "SYNC DATA";
        }