//Ingresar Aportacion OE
        private void aportacionAgregar_btn_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult dlgResult = MessageBox.Show("Una vez ingresada, esta aportacion no se puede deshacer.\nEsta seguro que los campos estan correctos y desea continuar?", "Continue?", MessageBoxButton.OKCancel);
            if (dlgResult == MessageBoxResult.OK)
            {
                if (aportacionAno_txt.SelectedIndex == -1 || aportacionMes_txt.SelectedIndex == -1)
                {
                    MessageBox.Show("Debe especificar un año y mes");
                    return;
                }
                if (aportacionMotivo_txt.SelectedIndex == -1)
                {
                    MessageBox.Show("Ingrese un motivo");
                    return;
                }
                if (aportacionMonto_txt.Text == "")
                {
                    MessageBox.Show("Ingrese un monto");
                    return;
                }
                DateTime fecha = DateTime.Now;
                if (mesANumero(aportacionMes_txt.SelectedItem.ToString()) <= fecha.Month && Convert.ToInt32(aportacionAno_txt.SelectedItem.ToString()) == fecha.Year)
                {
                    MessageBox.Show("No puede ingresar una fecha en el pasado o del mes actual!");
                    return;
                }

                aportacionObligatoriaEspecial aportacionOE = new aportacionObligatoriaEspecial();
                aportacionOE.FechaRealizacion = mesANumero(aportacionMes_txt.SelectedItem.ToString()) + "/1/" + aportacionAno_txt.SelectedItem.ToString();
                aportacionOE.Monto = Convert.ToInt64(aportacionMonto_txt.Text);
                aportacionOE.Motivo = aportacionMotivo_txt.SelectedItem.ToString();
                aportacionOE.Descripcion = aportacionDescripcion_txt.Text;

                flags[0] = true;
                flags[1] = true;
                flags[2] = true;
                flags[3] = true;
                habilitarCampos(false, "aportacion");
                Wrapper.AgregarPeticionCompleted += new EventHandler<ServiceReference.AgregarPeticionCompletedEventArgs>(Wrapper_AgregarPeticionCompleted);
                Wrapper.AgregarPeticionAsync(ServiceReference.peticion.insertarAportacionOE, MainPage.tc.InsertarAportacionObligatoriaEspecial(aportacionOE, usuario));
            }
            else if (dlgResult == MessageBoxResult.Cancel)
            {
                // No, stop
            }
        }
        /********************************************************************************************************************************
        *****************************************************    Metodo PRINCIPAL  ******************************************************
        *********************************************************************************************************************************/

        //es el metodo que corre cuando se dispara el evento de recibir respuesta, aqui van todas las respuestas
        //con los codigos que le pertenecen, consultar TABLA DE PETICIONES.XLSX

        private void Wrapper_AgregarPeticionCompleted(object sender, ServiceReference.AgregarPeticionCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string temp = e.Result.Substring(0, 3);
                string recievedResponce = e.Result.Substring(3);
                if (recievedResponce == "False")
                {
                    if (flags[2])
                    {
                        flags[2] = false;
                        MessageBox.Show("Ha ocurrido un error.  Intente su consulta de nuevo.\nSi el problema persiste, refresque la pagina e intente de nuevo.");
                        habilitarSearch(true);
                        habilitarAportaciones(true);
                        habilitarBotones(true);
                    }
                }
                else
                {
                    switch (temp)
                    {
                        case "p14"://Get Limite Actual de la aportacion
                            if (flags[1])
                            {
                                descripcionAV_txt.IsEnabled = true;
                                montoAV_txt.IsEnabled = true;
                                agregarAV_btn.IsEnabled = true;

                                flags[1] = false;
                                limiteAportacionVoluntaria = Convert.ToInt32(recievedResponce);
                            }
                            break;

                        case "p28"://Get Afiliados (Para llenar el autocomplete y combobox del SEARCH)
                            if (flags[0])
                            {
                                flags[0] = false;
                                habilitarSearch(true);

                                if (recievedResponce == "")//Quiere decir que no existen afiliados registrados
                                {
                                    MessageBox.Show("No existen afiliados registrados");
                                    return;
                                }
                                listaGrandota = MainPage.tc.getListasPagos(recievedResponce);
                                numeroCertificados = (List<string>)listaGrandota[0];
                                nombresAfiliados = (List<string>)listaGrandota[1];

                                numeroCertificado_txt.ItemsSource = numeroCertificados;
                                nombreAuto_txt.ItemsSource = nombresAfiliados;
                            }
                            break;

                        case "p29"://buscar Afiliado PAGAR
                            if (flags[0])
                            {
                                flags[0] = false;
                                habilitarSearch(true);
                                habilitarAportaciones(true);
                                habilitarBotones(true);
                                aportacionObligatoriaEspecial tempInstance = new aportacionObligatoriaEspecial();

                                listaAportaciones = MainPage.tc.getAfiliadoAportaciones(recievedResponce);

                                if (listaAportaciones[6] == "NULL")//Si no hay aportaciones
                                {
                                    MessageBox.Show("El usuario no tiene aportaciones obligatorias pendientes");
                                    return;
                                }

                                //Los primeros 6 posiciones traen datos del afiliado
                                id_txt.Text = listaAportaciones[5].ToString();
                                nombreAuto_txt.Text = listaAportaciones[1].ToString() + " " + listaAportaciones[2].ToString() + " " +
                                                      listaAportaciones[3].ToString() + " " + listaAportaciones[4].ToString();
                                numeroCertificado_txt.SelectedItem = listaAportaciones[0].ToString();

                                //Del indice 6 en adelante son de tipo aportaciones obligatorias especiales

                                for (int i = 6; i < listaAportaciones.Count; i++)
                                {
                                    listaAportacionesAfiliado.Add((aportacionObligatoriaEspecial)listaAportaciones[i]);
                                    tempInstance = (aportacionObligatoriaEspecial)listaAportaciones[i];
                                    controlDePagoGrid1.Add(new controlDePagoGrid()
                                    {
                                        ID = tempInstance.IDAportacion,
                                        Fecha_A_Pagar = tempInstance.fechaPlazo,
                                        Monto = tempInstance.Monto,
                                        Motivo = tempInstance.Motivo,
                                        Descripcion = tempInstance.Descripcion,
                                        TipoAportacion = "Obligatoria"
                                    });
                                    if (tempInstance.Motivo == "")
                                    {
                                        listaIDAportaciones.Add(tempInstance.IDAportacion);
                                    }
                                }


                                //Grid culero de las aportaciones obligatorias
                                gridMesesPorPagar.ItemsSource = controlDePagoGrid1;

                            }
                            break;

                        case "p30":
                            if (flags[0])
                            {
                                flags[0] = false;
                                habilitarSearch(true);
                                habilitarAportaciones(true);
                                habilitarBotones(true);

                                while (controlDePagoGrid2.Count != 0)
                                    controlDePagoGrid2.RemoveAt(0);

                                MessageBox.Show("Se han registrado las aportaciones exitosamente!");
                                NavigationService.Refresh();
                            }
                            break;
                        default:
                            if (flags[2])
                            {
                                flags[2] = false;
                                MessageBox.Show("Ha ocurrido un error.  Intente su consulta de nuevo.\nSi el problema persiste, refresque la pagina e intente de nuevo.");
                                habilitarSearch(true);
                                habilitarAportaciones(true);
                                habilitarBotones(true);
                            }
                            break;
                    }
                }
            }
            else
            {
                if (flags[2])
                {
                    flags[2] = false;
                    MessageBox.Show("Ha ocurrido un error.  Intente su consulta de nuevo.\nSi el problema persiste, refresque la pagina e intente de nuevo.");
                    habilitarSearch(true);
                    habilitarAportaciones(true);
                    habilitarBotones(true);
                }
                //habilitarCampos(true);
            }
        }