public static int Consultar(ActualizaciondePAModel[] models, SessionDB sesion)
        {
            EliminaDetallesConflicto(sesion.pkUser.ToString());

            int           agregados = 0;
            List <string> listIDSIU = new List <string>();

            if (models.Length > 0)
            {
                bool TMP = true;
                foreach (ActualizaciondePAModel model in models)
                {
                    if (model.IDSIU == "00260600")
                    {
                        model.IDSIU = model.IDSIU;
                    }
                    model.sesion = sesion;

                    //  ActualizarIPersona persona = model as ActualizarIPersona;
                    //  persona.findPersona();
                    //   model.PERSONA_REGISTRADA = model.PK_PERSONA != -1 ? "1" : "0";

                    //if (listIDSIU.Contains(model.IDSIU) || persona.addPersona(TMP))
                    // {
                    ActualizarIPA pa = model as ActualizarIPA;
                    pa.findPA();
                    model.PA_REGISTRADA = model.PK_PA != -1 ? "1" : "0";

                    if (pa.addPA(TMP))
                    {
                        agregados++;
                        listIDSIU.Add(model.IDSIU);
                        continue;
                    }
                    else
                    {
                        InsertaDetallesConflicto("PA_TMP_UPDATE", model.IDSIU, model.NOMBRES + " " + model.APELLIDOS, model.xQuery, model.xErrMsg, sesion.pkUser.ToString(), sesion.nickName);
                        Console.WriteLine("Este pinche IDSIU es el del problema: " + model.IDSIU + " (puto)");
                    }

                    /* }
                     * else
                     * {
                     *   InsertaDetallesConflicto("PERSONAS_TMP", model.IDSIU, model.NOMBRES + " " + model.APELLIDOS, model.xQuery, model.xErrMsg, sesion.pkUser.ToString(), sesion.nickName);
                     *   Console.WriteLine("Este pinche IDSIU es el del problema: " + model.IDSIU + " (puto)");
                     * }*/
                    //break;
                }
            }
            return(agregados);
        }
        public bool Comparar(string Periodo, string TipoDeContrato, string TipoPago, string Escuela, string Campus, string CampusPA, string TipoDocente, string PartePeriodo, ActualizaciondePAModel model, SessionDB sesion)
        {
            model.sesion = sesion;
            string usuario = Convert.ToString(sesion.pkUser);

            bool all_result    = true;
            int  registradosPA = 0;
            bool TMP           = true;//PA_TMP_UPDATE
            int  NOT_FOUND     = -1;

            List <string> listIDSIU = new List <string>();

            //sedes?

            sql = " SELECT * "
                  + "   FROM PA_TMP_UPDATE "
                  + "  WHERE USUARIO = " + usuario; // AND INDICADOR <> 1 ?
            ResultSet res = db.getTable(sql);

            ActualizarIPA PA = this as ActualizarIPA;

            while (res.Next())
            {
                bool ok;
                long.TryParse(res.Get("ID_PA"), out PK_PA);

                if (PA.editPA_TMP_UPDATE(TMP))
                {
                    if (PA.find_PA() == NOT_FOUND)  //no encontro
                    {
                        ok = PA.add_PA_UPDATE('N'); //NUEVO
                    }
                    else //si encontro
                         //comparar

                    {
                        Dictionary <string, int> col = new Dictionary <string, int>();

                        if (!CompareTo(col))             // si entra agregar  son iguales (true)
                        {                                //ACTUALIZAR
                            PA.add_PA_UPDATE('A');       //agrego el registro de PA_TMP_UPDATE en PA_UPDATE
                            PA.add_PA_UPDATE2('A', col); //agrego el registro de PA en PA_UPDATE
                        }

                        col.Clear();
                    }


                    continue;
                }

                all_result = false;
                break;
            }



            //  string Escuela, string Campus, string CampusPA, string TipoDocente, string PartePeriodo



            List <string> filtros = new List <string>();

            //	if (filter != "") filtros.Add("CVE_SEDE = '" + filter + "'");

            if (Periodo != "")
            {
                filtros.Add("PERIODO = '" + Periodo + "'");
            }
            if (Campus != "")
            {
                filtros.Add("CVE_SEDE = '" + Campus + "'");
            }

            if (CampusPA != "")
            {
                filtros.Add("CAMPUS_INB = '" + CampusPA + "'");
            }

            if (Escuela != "")
            {
                filtros.Add("CVE_ESCUELA = '" + Campus + "'");
            }

            if (PartePeriodo != "")
            {
                filtros.Add("PARTEDELPERIODO = '" + PartePeriodo + "'");
            }

            /* if (Periodo != "")
             * {
             *   filtros.Add("PERIODO = '" + Periodo + "'");
             * }*/

            string filter = "";
            string union  = "";

            if (filtros.Count > 0)
            {
                union  = " WHERE ";
                filter = "" + union + "" + string.Join <string>(" AND ", filtros.ToArray());
            }


            //BAJA compara tabla de PA Con PA_TMP_UPDATE agregar filtros
            sql = " SELECT * "
                  + "   FROM PA "
                  + filter;

            res = db.getTable(sql);


            while (res.Next())
            {
                long.TryParse(res.Get("ID_PA"), out PK_PA2);
                if (PA.editPA())
                {
                    if (!PA.find_PA2())        //si entra no esta
                    {
                        PA.add_PA_UPDATE('B'); //agrego el registro de PA en PA_UPDATE
                    }
                }
            }


            return(all_result);
        }
        public bool Generar(string data, out int totalPA, out int registradosPA, out int registradosPersonas)
        {
            string[] arrChecked = data.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            totalPA             = arrChecked.Length;
            registradosPA       = 0;
            registradosPersonas = 0;
            bool all_result = true;

            bool TMP       = true;
            int  NOT_FOUND = -1;

            List <string> listIDSIU = new List <string>();

            foreach (string itemChecked in arrChecked)
            {
                long.TryParse(itemChecked, out PK_PA);

                bool ok;
                bool personaActualizada;

                ActualizarIPersona persona = this as ActualizarIPersona;
                ActualizarIPA      PA      = this as ActualizarIPA;

                if (PA.editPA(TMP))
                {
                    personaActualizada = listIDSIU.Contains(IDSIU);

                    if (personaActualizada || persona.editPersona(TMP))
                    {
                        if (personaActualizada)
                        {
                            ok = true;
                        }
                        else
                        {
                            if (persona.findPersona() == NOT_FOUND)
                            {
                                ok = persona.addPersona();
                            }
                            else
                            {
                                ok = persona.savePersona();
                            }
                            registradosPersonas++;
                        }

                        if (ok)
                        {
                            if (PA.findPA() == NOT_FOUND)
                            {
                                ok = PA.addPA();
                            }
                            else
                            {
                                ok = PA.savePA();
                            }

                            if (ok)
                            {
                                markPersona();
                                markPA();
                                registradosPA++;

                                if (personaActualizada == false)
                                {
                                    listIDSIU.Add(IDSIU);
                                }
                                continue;
                            }
                        }
                    }
                }
                all_result = false;
                break;
            }

            return(all_result);
        }