コード例 #1
0
        protected internal void TransmitirClick(object sender, EventArgs e)
        {
            CloudData = new CloudDataStore();
            db        = new DataBase();
            TextView TVResult = FindViewById <TextView>(Resource.Id.TVResultado);

            ProgressDialog pbar = new ProgressDialog(this);

            pbar.SetCancelable(false);
            pbar.SetMessage("Sincronizando dados do sistema...");
            pbar.SetProgressStyle(ProgressDialogStyle.Horizontal);
            pbar.Progress = 0;
            pbar.Max      = 100;
            pbar.Show();

            new Thread(new ThreadStart(async delegate
            {
                // Envia do App para a Web;
                if (await CloudData.AddPlantio(null))
                {
                    pbar.Progress += 10;
                    //Plantio
                    if (await CloudData.BaixarPlantio(null))
                    {
                        pbar.Progress += 5;
                    }

                    //Instalacao
                    if (await CloudData.AddInstalacao(null))
                    {
                        pbar.Progress += 5;
                        if (await CloudData.BaixarInstalacao(null))
                        {
                            pbar.Progress += 5;
                        }


                        if (await CloudData.AddManutencao(null))
                        {
                            pbar.Progress += 5;
                            if (await CloudData.BaixarManutencao(null))
                            {
                                pbar.Progress += 5;
                            }
                        }

                        if (await CloudData.AddPlanejamentoAplic(null))
                        {
                            pbar.Progress += 10;
                            if (await CloudData.AddAplicacao(null))
                            {
                                pbar.Progress += 5;

                                if (await CloudData.BaixarPlanejamentoAplic(null) &&
                                    await CloudData.BaixarAplicacao(null))
                                {
                                    pbar.Progress += 10;
                                }
                            }
                        }

                        if (await CloudData.AddPlanejamentoAval(null))
                        {
                            pbar.Progress += 10;
                            if (await CloudData.BaixarPlanejamentoAval(null))
                            {
                                pbar.Progress += 10;
                                if (await CloudData.AddAvaliacao(null))
                                {
                                    pbar.Progress += 5;

                                    if (await CloudData.BaixarPlanejamentoAval(null) &&
                                        await CloudData.BaixarAvaliacao(null))
                                    {
                                        pbar.Progress += 10;
                                    }

                                    if (await CloudData.AddAvaliacaoImagem(null))
                                    {
                                        pbar.Progress += 5;
                                    }
                                }
                            }
                        }
                    }
                }

                ////Avaliacao_Imagem
                //if (await CloudData.AddAvaliacaoImagem(null))
                //{
                //    pbar.Progress += 5;
                //}


                if (pbar.Progress >= 100)
                {
                    Thread.Sleep(800);
                    RunOnUiThread(() => {
                        TVResult.Text = "Sincronização efetuada com sucesso!";
                        TVResult.SetTextColor(Android.Graphics.Color.DarkGreen);
                    });
                    RunOnUiThread(() => { Toast.MakeText(this, "Dados importados com sucesso.", ToastLength.Long).Show(); });

                    pbar.Dismiss();
                }
                else
                {
                    RunOnUiThread(() => {
                        TVResult.Text = "Erro ao baixar os dados do servidor!";
                        TVResult.SetTextColor(Android.Graphics.Color.Red);
                    });

                    pbar.Dismiss();
                }


                RunOnUiThread(() => { pbar.SetMessage("Dados importados..."); });
            })).Start();
        }