public NuevaTarjeta(TipoAnadidor tipo, TarjetasViewModel _t, RecargasViewModel _r) { try { InitializeComponent(); Title = "Nueva tarjeta"; ToolbarItems.Add(new ToolbarItem("Ayuda", "ayuda2.png", () => { var page = new InfoAyuda("nuevat.html"); Navigation.PushPopupAsync(page); })); #if __IOS__ grdScanner.IsVisible = false; #endif tvm = _t; rvm = _r; this.BindingContext = tvm; Refresh(); tvm.Idusuario = App.usr.idusuario; if (App.usr.idpais != 0) { tvm.idpais = App.usr.idpais; } txtNum.Completed += (s, e) => txtMes.Focus(); txtMes.Completed += (s, e) => txtAno.Focus(); txtAno.Completed += (s, e) => txtCvc.Focus(); txtCvc.Completed += (s, e) => txtTitularFN.Focus(); txtTitularFN.Completed += (s, e) => txtTitularLN.Focus(); txtTitularLN.Completed += (s, e) => txtCalleNum.Focus(); txtCalleNum.Completed += (s, e) => txtCP.Focus(); tvm.TarjetaIncompleta += (s, e) => { if (e.estaincompleta) { if (tvm.idpais == 0 || tvm.IdEstado == 0 || tvm.IdCiudad == 0) { lblvalGeo.IsVisible = true; } else { lblvalGeo.IsVisible = false; } btnGuardar.IsEnabled = false; } else { lblvalGeo.IsVisible = false; btnGuardar.IsEnabled = true; } }; txtNum.TextChanged += (sender, e) => { if (!String.IsNullOrEmpty(txtNum.Text)) { if (cardval.IsValid) { CreditCardDetector det = new CreditCardDetector(txtNum.Text); tvm.idemisor = SetEmisor(det.Brand); tvm.NumeroTarjeta = txtNum.Text; lblvalCard.IsVisible = false; //.Text = ""; } else { CreditCardDetector det = new CreditCardDetector(txtNum.Text); tvm.idemisor = SetEmisor(det.Brand); tvm.NumeroTarjeta = ""; lblvalCard.IsVisible = true; //.Text = "El numero de tarjeta es obligatorio, y tal cual aparece en la tarjeta"; } } }; txtMes.TextChanged += Valfecha; txtAno.TextChanged += Valfecha; txtCvc.TextChanged += Valfecha; txtTitularFN.TextChanged += (s, e) => { if (valTitulFN.IsValid) { lblvalTitular.IsVisible = false; //.Text = ""; tvm.TitularFN = CleanString.UseRegex(txtTitularFN.Text); } else { lblvalTitular.IsVisible = true; //.Text = "El nombre del titular es obligatorio y tal cual aparece en la tarjeta"; tvm.TitularFN = ""; } }; txtTitularLN.TextChanged += (s, e) => { if (valTitulLN.IsValid) { lblvalTitular.IsVisible = false; //.Text = ""; tvm.TitularLN = CleanString.UseRegex(txtTitularLN.Text); } else { lblvalTitular.IsVisible = true; //.Text = "El nombre del titular es obligatorio y tal cual aparece en la tarjeta"; tvm.TitularLN = ""; } }; txtCalleNum.TextChanged += (s, e) => { if (valCalle.IsValid) { lblvalCalle.IsVisible = false; //.Text = ""; tvm.CalleyNum = CleanString.UseRegex(txtCalleNum.Text); } else { lblvalCalle.IsVisible = true; //.Text = "El nombre del titular es obligatorio y tal cual aparece en la tarjeta"; tvm.CalleyNum = ""; } }; txtCP.TextChanged += (s, e) => { if (cpval.IsValid) { lblvalCP.IsVisible = false; //.Text = ""; tvm.CP = check.SafeSqlLiteral(txtCP.Text); } else { lblvalCP.IsVisible = true; //.Text = "El nombre del titular es obligatorio y tal cual aparece en la tarjeta"; tvm.CP = ""; } }; string title = ""; ListaOpciones lo; //grdPais.Tapped += async (object sender, EventArgs e) => TapGestureRecognizer tapgrdPais = new TapGestureRecognizer(); tapgrdPais.Tapped += async(s, e) => { grdPais.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdPais.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Seleccione un país"; ls = tvm.lsPais().Select(x => new Opcion { idopc = x.idpais, opc = x.pais, imgopc = x.img }).ToObservableCollection(); lo = new ListaOpciones(ls, title, 2); lo.IdOpc = 1; await App.Nav.PushAsync(lo, Constantes.animated); }; grdPais.GestureRecognizers.Add(tapgrdPais); TapGestureRecognizer tapgrdTipo = new TapGestureRecognizer(); tapgrdTipo.Tapped += async(s, e) => //grdTipo.Tapped += async (object sender, EventArgs e) => { grdTipo.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdTipo.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Seleccione emisor"; ls = tvm.LsEmisores().Select(x => new Opcion { idopc = x.idemisor, opc = x.emisor, imgopc = x.img }).ToObservableCollection(); lo = new ListaOpciones(ls, title, 2); lo.IdOpc = 2; await App.Nav.PushAsync(lo, Constantes.animated); }; grdTipo.GestureRecognizers.Add(tapgrdTipo); TapGestureRecognizer tapgrdScanner = new TapGestureRecognizer(); tapgrdScanner.Tapped += async(s, e) => //vclScanner.Tapped += (s, e) => { grdScanner.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdScanner.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; #if __ANDROID__ var plataforma = DependencyService.Get <ICardReader>(); if (plataforma != null) { plataforma.CardFound = delegate(string FormattedCardNumber, int ExpiryMonth, int ExpiryYear, string CardholderName, Card.IO.CardType CardType) { txtNum.Text = FormattedCardNumber; //txtTitular.Text = CardholderName; txtMes.Text = (ExpiryMonth > 0 ? ExpiryMonth.ToString() : ""); if (ExpiryYear > 0) { if (ExpiryYear.ToString().Length > 2) { txtAno.Text = ExpiryYear.ToString().Substring(2, 2); } else { txtAno.Text = ExpiryYear.ToString(); } } else { txtAno.Text = ""; } }; plataforma.ReadCard(); } #endif #if __IOS__ //var plataforma = DependencyService.Get<ICardReader>(); //if (plataforma != null) //{ // plataforma.CardFound = delegate (string FormattedCardNumber, int ExpiryMonth, int ExpiryYear, string CardholderName, Card.IO.CreditCardType CardType) // { // txtNum.Text = FormattedCardNumber; // //txtTitular.Text = CardholderName; // txtMes.Text = (ExpiryMonth > 0 ? ExpiryMonth.ToString() : ""); // if (ExpiryYear > 0) // { // if (ExpiryYear.ToString().Length > 2) // txtAno.Text = ExpiryYear.ToString().Substring(2, 2); // else // txtAno.Text = ExpiryYear.ToString(); // } // else // txtAno.Text = ""; // }; // plataforma.ReadCard(); //} #endif }; grdScanner.GestureRecognizers.Add(tapgrdScanner); TapGestureRecognizer tapgrdEstado = new TapGestureRecognizer(); tapgrdEstado.Tapped += async(s, e) => //grdEstado.Tapped += async (object sender, EventArgs e) => { grdEstado.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdEstado.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Seleccione estado"; ls = tvm.lsEstados(tvm.idpais).Select(x => new Opcion { idopc = x.idestado, opc = x.estado, }).ToObservableCollection(); lo = new ListaOpciones(ls, title, 2); lo.IdOpc = 3; await App.Nav.PushAsync(lo, Constantes.animated); }; grdEstado.GestureRecognizers.Add(tapgrdEstado); TapGestureRecognizer tapgrdCiudad = new TapGestureRecognizer(); tapgrdCiudad.Tapped += async(s, e) => //btnCiudad.Clicked += async (s,e) => //vclCiudad.Tapped += async (s, e) => { grdCiudad.BackgroundColor = Color.FromHex("#e5e5e5"); await Task.Delay(100); grdCiudad.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Seleccione ciudad"; ls = tvm.lsMunicipios(tvm.IdEstado).OrderBy(x => x.municipio).Select(x => new Opcion { idopc = x.idmunicipio, opc = x.municipio, }).ToObservableCollection(); lo = new ListaOpciones(ls, title, 2); lo.IdOpc = 4; await App.Nav.PushAsync(lo, Constantes.animated); }; grdCiudad.GestureRecognizers.Add(tapgrdCiudad); btnGuardar.Clicked += async(sender, e) => { if (tvm.EsIncompleta()) { await DisplayAlert("Error", "Faltan capturar o seleccionar algunos campos", "OK"); } else { if (txtAno.Text.Trim().Length < 2 || txtMes.Text.Trim().Length < 2) { await DisplayAlert("Error", "Revise mes y año de expiración", "OK"); } else { int mm = int.Parse(txtMes.Text.Trim()); int yy = int.Parse(txtAno.Text.Trim()); if (mm < 1 || mm > 12 || yy < DateTime.Now.Year - 2000) { await DisplayAlert("Error", "Revise mes y año de expiración", "OK"); } else { if (App.usr == null || (App.usr != null && (App.usr.email == null || App.usr.idusuario == 0))) { var login = new Login(App.Current); await App.Nav.PushAsync(login, Constantes.animated); } else { btnGuardar.IsEnabled = false; //tvm.TarjetaAlta += async (s, ea) => //{ // UserDialogs.Instance.HideLoading(); // if (ea.Error != null || ea.Cancelled) // await DisplayAlert("Error", "Ocurrio un error, vuelva a intentar", "OK"); // else // await App.Nav.PopAsync(Constantes.animated); //}; //UserDialogs.Instance.ShowLoading("Guardando..."); //tvm.Alta(); rvm.idFormaPago = 2; //tarjeta rvm.TipoTrans = TipoTransaccion.PrimeraVez; rvm.IdTarjeta = 0; Procesar pro = App.Nav.NavigationStack.OfType <Procesar>().FirstOrDefault(); if (pro == null) { await App.Nav.PushAsync(new Procesar(rvm, tvm, TipoTransaccion.PrimeraVez), Constantes.animated); } else { pro.Refresh(rvm, tvm, TipoTransaccion.PrimeraVez); await App.Nav.PopAsync(Constantes.animated); //boto nueva tarjeta (this) await App.Nav.PopAsync(Constantes.animated); //boto medios pago } } } } } }; tvm.ChecaIncompleta(); } catch (Exception e) { } }
public void CargarInicia(Recarga rec) { InitializeComponent(); Title = "Cargar Saldo"; rvm = new RecargasViewModel(); this.BindingContext = rvm; rvm.Tiporecarga = TipoRecarga.RecargaTA; NavigationPage.SetBackButtonTitle(this, ""); if (rec != null) { if (rec is RecargaProg) { rvm.EdicionOnly = true; } if (App.usr.idpais != 0) { rvm.idpais = App.usr.idpais; } else { rvm.idpais = 1; //default Mexico } rvm.IdUsuario = App.usr.idusuario; mirec = new Recarga(); mirec = rec; } else { Refresh(); if (App.usr.idpais != 0) { rvm.idpais = App.usr.idpais; } else { rvm.idpais = 1; //default Mexico } } ToolbarItems.Add(new ToolbarItem("Ayuda", "ayuda2.png", () => { var page = new InfoAyuda("cargarsaldo.html"); Navigation.PushPopupAsync(page); })); lsC.Clear(); rvm.RecargaIncompleta += (s, e) => { if (e.estaincompleta) { if (rvm.idoperadora == 0 || rvm.idpaquete == 0) { lblvalOpePaq.IsVisible = true; } else { lblvalOpePaq.IsVisible = false; } btnAplicar.IsEnabled = false; } else { btnAplicar.IsEnabled = true; } }; if (mirec != null) { rvm.idpais = mirec.idpais; rvm.idoperadora = mirec.idoperadora; rvm.idpaquete = mirec.idpaquete; rvm.NumeroRecarga = mirec.numerorecarga; rvm.ContactoRecarga = (!String.IsNullOrEmpty(mirec.contactorecarga) ? CleanString.UseRegex(mirec.contactorecarga) : ""); rvm.idFormaPago = mirec.idformapago; rvm.IdTarjeta = mirec.idtarjeta; if (rvm.idFormaPago == 2 && rvm.IdTarjeta > 0) { rvm.TipoTrans = TipoTransaccion.SegundaVez; } } if (rvm.EdicionOnly) { btnAplicar.Text = "Comprar"; } else { if (rvm.idFormaPago == 2 && rvm.IdTarjeta > 0 && App.db.SelTarjetas(rvm.IdTarjeta) != null) { btnAplicar.Text = "Confirmar"; } else { btnAplicar.Text = "Comprar"; } } string title = ""; ListaOpciones lo; TapGestureRecognizer tapgrdPais = new TapGestureRecognizer(); tapgrdPais.Tapped += async(s, e) => //vclPais.Tapped += async (object sender, EventArgs e) => { grdPais.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdPais.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Selecciona un pais"; ls = rvm.lsPais().Select(x => new Opcion { idopc = x.idpais, opc = x.pais, imgopc = x.img }).ToObservableCollection(); lo = new ListaOpciones(ls, title, 1); lo.IdOpc = 1; await App.Nav.PushAsync(lo, Constantes.animated); }; grdPais.GestureRecognizers.Add(tapgrdPais); TapGestureRecognizer tapgrdOperadora = new TapGestureRecognizer(); tapgrdOperadora.Tapped += async(s, e) => //vclOperadora.Tapped += async (object sender, EventArgs e) => { grdOperadora.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdOperadora.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Selecciona una compañía"; ls = rvm.LsOperadoras(rvm.idpais).Select(x => new Opcion { idopc = x.idoperadora, opc = x.operadora, imgopc = x.img }).ToObservableCollection(); lo = new ListaOpciones(ls, title, 1); lo.IdOpc = 2; await App.Nav.PushAsync(lo, Constantes.animated); }; grdOperadora.GestureRecognizers.Add(tapgrdOperadora); if (mirec != null) { txtNum.Text = mirec.numerorecarga; lblContacto.Text = (!String.IsNullOrEmpty(mirec.contactorecarga) ? CleanString.UseRegex(mirec.contactorecarga) : ""); } TapGestureRecognizer tapgrdSaldo = new TapGestureRecognizer(); tapgrdSaldo.Tapped += async(s, e) => //vclSaldo.Tapped += async (object sender, EventArgs e) => { grdSaldo.BackgroundColor = Color.FromHex("#e5e5e5"); //Color.FromHex((App.Current.Resources["ButtonRojo"] as Style).Setters.Where(x => x.Property == BackgroundColorProperty).FirstOrDefault().Value.ToString()); //.Opacity = .5; await Task.Delay(100); grdSaldo.BackgroundColor = Color.Transparent; //grdEstado.Opacity = 1; ls.Clear(); title = "Selecciona monto"; ObservableCollection <catPaquete> lpq = rvm.LsPaquetes(rvm.idoperadora); ls = lpq.OrderBy(x => x.tipo).Select(x => new Opcion { idopc = x.idpaquete, opc = x.monto.ToString("c", new System.Globalization.CultureInfo("es-MX")) + " " + x.paquete, idagrupador = x.tipo, agrupador = (x.tipo == 0 ? "Tiempo aire" : "Paquetes de datos") }).ToObservableCollection(); if (ls.Select(x => x.idagrupador).Distinct().Count() > 1) { lo = new ListaOpciones(ls, title, 1, true); //hay TA y datos } else { lo = new ListaOpciones(ls, title, 1); //solo TA } lo.IdOpc = 4; await App.Nav.PushAsync(lo, Constantes.animated); }; grdSaldo.GestureRecognizers.Add(tapgrdSaldo); TapGestureRecognizer tapgrdLimpiar = new TapGestureRecognizer(); tapgrdLimpiar.Tapped += async(s, e) => { grdLimpiar.BackgroundColor = Color.FromHex("#e5e5e5"); await Task.Delay(100); grdLimpiar.BackgroundColor = Color.Transparent; rvm.Refresh(); txtNum.Text = ""; lblContacto.Text = ""; }; grdLimpiar.GestureRecognizers.Add(tapgrdLimpiar); btnAplicar.Clicked += async(sender, ea) => { if (rvm.EsIncompleta()) { await DisplayAlert("Error", "Faltan capturar o seleccionar algunos campos", "OK"); } else { btnAplicar.IsEnabled = false; rvm.NumeroRecarga = check.SafeSqlLiteral(txtNum.Text.Trim()); if (rvm.EdicionOnly) { await App.Nav.PushAsync(new RegPago(rvm), Constantes.animated); } else { if (rvm.idFormaPago == 2 && rvm.IdTarjeta > 0 && App.db.SelTarjetas(rvm.IdTarjeta) != null) { //vamos a cargar el tvm desde una tarjeta (no se como?) TarjetasViewModel tvm = new TarjetasViewModel(); await App.Nav.PushAsync(new Procesar(rvm, tvm, TipoTransaccion.SegundaVez), Constantes.animated); } else { await App.Nav.PushAsync(new RegPago(rvm), Constantes.animated); } } } }; phvalNum.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { if (phvalNum.IsValid) { rvm.NumeroRecarga = check.SafeSqlLiteral(txtNum.Text); } else { rvm.NumeroRecarga = ""; } }; btnContactos.Clicked += async(sender, e) => { vwContactos = new Contactos(); await App.Nav.PushAsync(vwContactos); lsC = vwContactos.GetLista(); }; txtNum.TextChanged += (s, e) => { if (lsC.Count > 0) { IEnumerable <Contacto> tmp = lsC.Where(x => Regex.Replace(x.Number, @"\s+", "").Contains(e.NewTextValue)); if (tmp.Count() > 0) { lblContacto.Text = CleanString.UseRegex(tmp.FirstOrDefault().Name); rvm.ContactoRecarga = lblContacto.Text; } else { lblContacto.Text = ""; rvm.ContactoRecarga = ""; } } }; }