Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            if (VariablesGlobales.Idvendedor == 0)
            {
                Intent i = new Intent(this.ApplicationContext, typeof(MainActivity));
                i.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop);
                StartActivity(i);
                this.Finish();
            }
            SetContentView(Resource.Layout.ListViewProductos);
            lstDatosProductos = FindViewById <ListView>(Resource.Id.lstProductosLista);
            dbUser            = new ConsultasTablas();

            LoadData();
            var btnVolverAlPedido = FindViewById <Button>(Resource.Id.btnProductosPedidoActual);

            SeleccCategoria = (Spinner)FindViewById(Resource.Id.spnProductosCategoria);
            string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            CategoriasProd          = dbUser.verCategoriaProductos();
            adapter                 = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, CategoriasProd);
            SeleccCategoria.Adapter = adapter;
            //SeleccCategoria.SetSelection(adapter.GetPosition("PRODUCTOS REVENDEDORES"));
            SeleccCategoria.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(ListaCategorias_ItemSelected);


            var btnVolver = FindViewById <Button>(Resource.Id.btnProductosVolver);

            BusquedaProducto = (SearchView)FindViewById(Resource.Id.srcProductosBusqueda);
            BusquedaProducto.QueryTextSubmit += BusquedaProducto_QuerySubmit;
            BusquedaProducto.QueryTextChange += BusquedaProducto_TextChange;

            btnVolver.Click += delegate
            {
                StartActivity(typeof(PaginaPrincipal));
            };
            if (VariablesGlobales.PedidoEnCurso == true)
            {
                lstDatosProductos.ItemClick += (s, e) =>
                {
                    LayoutInflater layoutInflater = LayoutInflater.From(Application.Context);

                    View dialogo = layoutInflater.Inflate(Resource.Layout.inputBoxCantProd, null);

                    AlertDialog.Builder builder      = new AlertDialog.Builder(this);
                    EditText            cantProd     = dialogo.FindViewById <EditText>(Resource.Id.txtInputCantProd);
                    EditText            PrecioProd   = dialogo.FindViewById <EditText>(Resource.Id.txtInputPrecioProd);
                    TextView            mensajeInput = dialogo.FindViewById <TextView>(Resource.Id.txtInputCantMensaje);

                    builder.SetView(dialogo);
                    AlertDialog alertDialog = builder.Create();

                    alertDialog.SetCanceledOnTouchOutside(true);
                    alertDialog.SetTitle("Agregar producto");

                    alertDialog.SetButton("Agregar", (ss, ee) =>

                    {
                        if (cantProd.Text == "" || cantProd.Text == "0")
                        {
                            mensajeInput.Text = "La cantidad debes ser un numero mayor que 0";
                        }
                        else
                        {
                            //agregamos el producto
                            List <Productos> agregaProd = new List <Productos>();
                            agregaProd = dbUser.VerListaProductosBusquedaID(IdPoductoSel);

                            string cant  = cantProd.Text;
                            string pUnit = funcionesGlobales.CalcularPrecioLista(agregaProd[0].precio, agregaProd[0].ganancia, agregaProd[0].utilidad1,
                                                                                 agregaProd[0].utilidad2, agregaProd[0].utilidad3, agregaProd[0].utilidad4, agregaProd[0].utilidad5, agregaProd[0].iva,
                                                                                 VariablesGlobales.ListaPrecioCliente, agregaProd[0].calcular_precio);

                            if (PrecioProd.Text != "" & PrecioProd.Text != "0")
                            {
                                string bonificacion   = agregaProd[0].bonif;
                                string PrecioSugerido = pUnit;
                                double PrecioMinimo   = Math.Round(double.Parse(pUnit) / ((double.Parse(bonificacion) + 100) / 100), 2);
                                if (bonificacion != "0")
                                {
                                    if (double.Parse(PrecioProd.Text) < PrecioMinimo)
                                    {
                                        Toast.MakeText(this, "El precio ingresado es inferior al minimo permitido, " +
                                                       "se modificara el precio al valor correspondiente ", ToastLength.Short).Show();
                                        pUnit = PrecioMinimo.ToString();
                                    }

                                    else
                                    {
                                        pUnit = PrecioProd.Text;
                                    }
                                }
                                else
                                {
                                    pUnit = PrecioProd.Text;
                                }
                            }
                            string pTotal = (double.Parse(pUnit) * double.Parse(cantProd.Text)).ToString();
                            PedidosDetalle productoDetalle = new PedidosDetalle()
                            {
                                id_master   = VariablesGlobales.IdPedidoenCurso,
                                cod         = agregaProd[0].codigo,
                                plu         = agregaProd[0].codigo,
                                codProdMain = agregaProd[0].codProdMain,
                                descripcion = agregaProd[0].descripcion,
                                iva         = agregaProd[0].iva,
                                cantidad    = cantProd.Text,
                                punit       = pUnit,
                                ptotal      = pTotal
                            };
                            dbUser.InsertarProductoPedido(productoDetalle);
                            Toast.MakeText(this, "Producto agregado!", ToastLength.Short).Show();
                        }
                    });
                    alertDialog.SetButton2("Cancelar", (sss, eee) =>
                    {
                        Toast.MakeText(this, "No se agrego el producto!", ToastLength.Short).Show();
                    });

                    IdPoductoSel = int.Parse(e.Id.ToString());
                    List <Productos> selectPrecio = new List <Productos>();
                    selectPrecio  = dbUser.VerListaProductosBusquedaID(IdPoductoSel);
                    PrecioProdSel = funcionesGlobales.CalcularPrecioLista(selectPrecio[0].precio, selectPrecio[0].ganancia, selectPrecio[0].utilidad1,
                                                                          selectPrecio[0].utilidad2, selectPrecio[0].utilidad3, selectPrecio[0].utilidad4, selectPrecio[0].utilidad5, selectPrecio[0].iva,
                                                                          VariablesGlobales.ListaPrecioCliente, selectPrecio[0].calcular_precio);

                    PrecioProd.Hint = "Precio: $" + PrecioProdSel;
                    alertDialog.Show();
                };
            }
            if (VariablesGlobales.PedidoEnCurso == false)
            {
                btnVolverAlPedido.Enabled = false;
            }
            else
            {
                btnVolverAlPedido.Enabled = true;
            }

            btnVolverAlPedido.Click += delegate
            {
                StartActivity(typeof(PedidoActual));
            };
        }