Esempio n. 1
0
        private void Load()
        {
            if (!string.IsNullOrEmpty(action))
            {
                switch (action)
                {
                case "new":
                    var progressDialog = ProgressDialog.Show(this, "Carregando", "Buscando informações do produto.", true);

                    var t = new Thread(new ThreadStart(delegate
                    {
                        var c        = this.Intent.GetStringExtra("productCode");
                        var shopCode = this.Intent.GetStringExtra("shopCode");
                        var res      = Request.GetInstance().Post <Produto>("product", "get", user.Token, new HttpParam("product_code", c), new HttpParam("company_id", shopCode), new HttpParam("get_product_unit", "1"), new HttpParam("get_product_stock", "1"), new HttpParam("get_product_price", "1"));


                        if (res.status == null)
                        {
#if DEBUG
                            AlertDialog.Builder alerta = new AlertDialog.Builder(this);
                            alerta.SetTitle("Debug");
                            alerta.SetMessage(res.debug);
                            alerta.SetPositiveButton("Fechar", (sender, e) => { });
                            alerta.Show();
                            return;
#else
                            Toast.MakeText(this, "Erro no servidor!", ToastLength.Long).Show();
                            return;
#endif
                        }

                        item.SetProduto(res.data);

                        RunOnUiThread(() =>
                        {
                            progressDialog.Hide();

                            if (item.GetTabelaDePreco().Valor == 0)
                            {
                                Toast.MakeText(this, "O produto não possui preço cadastrado", ToastLength.Long).Show();
                                Finish();
                                return;
                            }

                            UpdateScreen();
                        });
                    }));
                    t.Start();
                    break;

                case "update":
                    item = Serializador.LoadFromXMLString <ItemPedido>(this.Intent.GetStringExtra("item"));
                    UpdateScreen();
                    break;
                }
            }
            else
            {
                Finish();
            }
        }