public static void InsertMysqlAutorization()
        {
            ConectarEpslog();
            string          query         = "select * from datosgenerales where flag = '0' and cautocode <> '0000'";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            while (reader.Read())
            {
                if (!CompanyExists(reader))
                {
                    ConnectionMySQL.Connect();
                    ConnectionMySQL.InsertCompany(reader.GetString(24), reader.GetString(17), reader.GetString(16), reader.GetString(18));
                    ConnectionMySQL.Disconnect();
                }
                if (!InsuredExists(reader))
                {
                    string clinic_history_code = GetClinicHistoryCode();
                    ConnectionMySQL.Connect();
                    ConnectionMySQL.InsertInsured(reader.GetString(27), reader.GetString(17), reader.GetString(0), reader.GetString(22), reader.GetString(1), reader.GetString(23), reader.GetString(6), reader.GetString(7), reader.GetString(8), reader.GetString(9), reader.GetString(10), reader.GetString(11), Helper.GetDate(reader.GetString(12)), reader.GetInt16(13).ToString(), reader.GetString(14).ToString(), Helper.GetDate(reader.GetString(19)), Helper.GetDate(reader.GetString(20)), Helper.GetDate(reader.GetString(21)), reader.GetString(29), "", clinic_history_code);
                    ConnectionMySQL.Disconnect();
                }
                string intern_code = GetInternCode();
                ConnectionMySQL.Connect();
                ConnectionMySQL.InsertAuthorization(reader.GetString(1), reader.GetString(25), reader.GetString(5), reader.GetString(2), Helper.GetDateTime(reader.GetString(3)), reader.GetString(8), reader.GetString(6), reader.GetString(7), Helper.GetDate(reader.GetString(12)), reader.GetValue(35).ToString(), intern_code, null);
                ConnectionMySQL.Disconnect();
                ConnectionMySQL.Connect();
                ConnectionMySQL.UpdateCompany(reader.GetValue(3).ToString(), reader.GetValue(17).ToString());
                ConnectionMySQL.Disconnect();
                UpdateAfterInsert("DatosGenerales", "cAutoCode", 2, reader);
            }
            Desconectar();
        }
        public static void InsertMysqlInsuredAutorization()
        {
            ConectarEpslog();
            string          query         = "select * from seguros_datosgenerales where flag = '0' and cautocode <> '0000'";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            while (reader.Read())
            {
                if (!CompanyInsuredExists(reader))
                {
                    ConnectionMySQL.Connect();
                    //CAMBIAR EL COMPANY_RUC POR COMPANY_CODE
                    ConnectionMySQL.InsertCompanyInsured(reader.GetValue(24).ToString(), reader.GetValue(23).ToString(), reader.GetString(16), reader.GetString(25));
                    ConnectionMySQL.Disconnect();
                }
                if (!InsuredExists(reader))
                {
                    string clinic_history_code = GetClinicHistoryCode();
                    ConnectionMySQL.Connect();
                    ConnectionMySQL.InsertInsuredInsured("5", reader.GetString(24), reader.GetString(0), reader.GetString(32), reader.GetString(1), reader.GetString(35), reader.GetString(6), reader.GetString(7), reader.GetString(8), reader.GetString(9), reader.GetString(10), reader.GetString(11), Helper.GetDate(reader.GetString(12)), reader.GetInt16(13).ToString(), reader.GetString(14).ToString(), Helper.GetDate("19900101"), Helper.GetDate("19900101"), Helper.GetDate("19900101"), reader.GetString(41), "", clinic_history_code);
                    ConnectionMySQL.Disconnect();
                }
                string intern_code = GetInternCode();
                ConnectionMySQL.Connect();
                ConnectionMySQL.InsertAuthorization(reader.GetString(1), "2", reader.GetString(5), reader.GetString(2), Helper.GetDateTime(reader.GetString(3)), reader.GetString(8), reader.GetString(6), reader.GetString(7), Helper.GetDate(reader.GetString(12)), "99999", intern_code, reader.GetValue(20).ToString());
                ConnectionMySQL.Disconnect();
                UpdateAfterInsert("seguros_datosgenerales", "cAutoCode", 2, reader);
            }
            Desconectar();
        }
        public static void InsertMysqlService()
        {
            ConectarTedef();
            string          query         = "select * from ts_nomenclador where ruc = '20494306043' and flag = '0' order by codigo";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            while (reader.Read())
            {
                if (!CategoryServiceExists(reader))
                {
                    ConnectionMySQL.Connect();
                    ConnectionMySQL.InsertCategoryService(Helper.SplitPoints(reader.GetString(1)));
                    ConnectionMySQL.Disconnect();
                }
                if (!SubCategoryServiceExists(reader))
                {
                    ConnectionMySQL.Connect();
                    ConnectionMySQL.InsertSubCategoryService(Helper.SplitPoints(reader.GetString(1)));
                    ConnectionMySQL.Disconnect();
                }
                ConnectionMySQL.Connect();
                ConnectionMySQL.InsertService(Helper.SplitPoints(reader.GetString(1)), reader.GetString(2), reader.GetString(3), reader.GetString(4));
                ConnectionMySQL.Disconnect();
                UpdateAfterInsert("ts_nomenclador", "CODIGO", 1, reader);
            }
            Desconectar();
            FinalMessage();
        }
        public static bool Evalue(string query)
        {
            ConnectionMySQL.Connect();
            MySqlCommand    command = new MySqlCommand(query, ConnectionMySQL.GetConnection());
            MySqlDataReader readerm = command.ExecuteReader();
            bool            flag    = false;

            while (readerm.Read())
            {
                flag = true;
            }
            ConnectionMySQL.Disconnect();
            return(flag);
        }
        public static void InsertMysqlProductPacific()
        {
            ConectarEpslog();
            string          query         = "select * from seguros_datosgenerales order by cAutoCode";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertProductPacific(reader.GetValue(20).ToString(), reader.GetValue(2).ToString());
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlInsuredCoverage()
        {
            ConectarEpslog();
            string          query         = "select * from seguros_coberturas where flag = '0' and cautocode <> '0000' order by cautocode";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertCoverageInsured(reader.GetValue(2).ToString(), reader.GetValue(4).ToString(), reader.GetValue(5).ToString(), reader.GetValue(9).ToString(), reader.GetValue(10).ToString(), "");
                UpdateAfterInsert("seguros_coberturas", "cautocode", 2, reader);
            }
            Desconectar();
            ConnectionMySQL.Disconnect();
        }
        public static void InsertMysqlProduct()
        {
            ConectarTarifario();
            string          query         = "select * from productos where flag = '0' order by cod_prod";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertProduct(reader.GetValue(0).ToString(), reader.GetString(1));
                UpdateAfterInsert("productos", "cod_prod", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlCoverageType()
        {
            ConectarTedef();
            string          query         = "select * from  ts_tipocobertvinctipprest where flag = '0' order by codigotipocoberturaprest";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertCoverageType(reader.GetString(0), reader.GetString(1));
                UpdateAfterInsert("ts_tipocobertvinctipprest", "codigotipocoberturaprest", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlDiagnostic()
        {
            ConectarTedef();
            string          query         = "select * from TS_CIE10 where flag = '0' order by codigocie10";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertDiagnostic(reader.GetString(0), reader.GetString(1));
                UpdateAfterInsert("TS_CIE10", "codigocie10", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlDiagnosticCategory()
        {
            ConectarSiteds();
            string          query         = "select cCateCode,sCateDesc from CateDiagnostico where flag = '0' order by cCateCode";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertDiagnosticCategory(reader.GetString(0), reader.GetString(1));
                UpdateAfterInsert("CateDiagnostico", "cCateCode", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlSubMechanismType()
        {
            ConectarTedef();
            string          query         = "select * from ts_submecanismopago where flag = '0' order by codigosubmecanismopago";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertSubMechanismType(reader.GetString(0), reader.GetString(1), reader.GetString(2));
                UpdateAfterInsert("ts_submecanismopago", "codigosubmecanismopago", 1, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlClasificationServiceType()
        {
            ConectarTedef();
            string          query         = "select * from ts_tipoclasificaciongasto where flag = '0' order by codigoclasificaciongasto;";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertClasificationServiceType(reader.GetString(0), reader.GetString(1));
                UpdateAfterInsert("ts_rubro", "codigoclasificaciongasto", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlSector()
        {
            ConectarTedef();
            string          query         = "select * from ts_rubro where flag = '0'";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertSector(reader.GetString(0), reader.GetString(1));
                UpdateAfterInsert("ts_rubro", "codigorubro", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlCumSunasaProduct()
        {
            ConectarTedef();
            string          query         = "select * from ts_producto where flag = '0' order by codigoproducto";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertCumSunasaProduct(reader.GetValue(0).ToString(), reader.GetValue(1).ToString(), reader.GetValue(3).ToString(), reader.GetValue(10).ToString(), reader.GetValue(9).ToString(), reader.GetValue(8).ToString(), reader.GetValue(4).ToString(), reader.GetValue(5).ToString(), reader.GetValue(6).ToString(), reader.GetValue(11).ToString(), reader.GetValue(12).ToString());
                UpdateAfterInsert("ts_producto", "codigoproducto", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlDigemid()
        {
            ConectarTedef();
            string          query         = "select * from ts_catalogodigemid where flag = '0' order by cod_prod";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertDigemid(reader.GetString(0), reader.GetString(1), reader.GetValue(2).ToString(), reader.GetString(3), reader.GetString(4), reader.GetString(5), reader.GetValue(6).ToString(), reader.GetValue(7).ToString(), reader.GetString(8), reader.GetString(9));
                UpdateAfterInsert("ts_catalogodigemid", "cod_prod", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlSubCoverageType()
        {
            ConectarTarifario();
            string          query         = "select * from sub_coverage_types where flag = '0' order by id";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertSubCoverageType(reader.GetValue(1).ToString(), reader.GetValue(2).ToString(), reader.GetValue(3).ToString(), reader.GetValue(4).ToString(), reader.GetValue(5).ToString());
                UpdateAfterInsert("sub_coverage_types", "id", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlDoctor()
        {
            ConectarTarifario();
            string          query         = "select * from medicos where flag = '0' and dni <> '0' order by dni";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertDoctor(reader.GetValue(0).ToString(), reader.GetString(1), reader.GetString(2), reader.GetString(3));
                UpdateAfterInsert("medicos", "dni", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlAfiliationType()
        {
            ConectarSiteds();
            string          query         = "select * from TipoAfiliacion where flag = '0' order by cAfilType";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertAfiliationType(reader.GetString(0).ToString(), reader.GetString(1).ToString());
                UpdateAfterInsert("TipoAfiliacion", "cAfilType", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlInsurance()
        {
            ConectarSiteds();
            string          query         = "select * from Entidad where flag = '0'";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertInsurance(reader.GetString(1).ToString(), reader.GetString(2).ToString());
                UpdateAfterInsert("Entidad", "cEntiCode", 1, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlRelationShip()
        {
            ConectarSiteds();
            string          query         = "select * from Parentesco where flag = '0'";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertRelationShip(reader.GetString(0).ToString(), reader.GetString(1).ToString());
                UpdateAfterInsert("Parentesco", "cParnCode", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlMoney()
        {
            ConectarSiteds();
            string          query         = "select * from Moneda where flag = '0'";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                ConnectionMySQL.InsertMoney(reader.GetString(0).ToString(), reader.GetString(2).ToString());
                UpdateAfterInsert("Moneda", "cMoneCode", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static void InsertMysqlProcedureType()
        {
            ConectarSiteds();
            string          query         = "select Entidad.cEntiCode, TipoProcedimientosEspeciales.cProcCode, TipoProcedimientosEspeciales.sProcName from TipoProcedimientosEspeciales inner join Entidad  on TipoProcedimientosEspeciales.cEntiIden = Entidad.cEntiIden where TipoProcedimientosEspeciales.flag = '0' order by TipoProcedimientosEspeciales.cEntiIden";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            while (reader.Read())
            {
                ConnectionMySQL.Connect();
                ConnectionMySQL.InsertProcedureType(reader.GetString(1).ToString(), reader.GetString(2).ToString(), reader.GetString(0).ToString());
                UpdateAfterInsert("TipoProcedimientosEspeciales", "cProcCode", 1, reader);
                ConnectionMySQL.Disconnect();
            }
            Desconectar();
            FinalMessage();
        }
        public static void InsertMysqlPatientOther()
        {
            ConectarHC();
            string          query         = "SELECT * FROM histories WHERE flag = '0' ORDER BY hc asc";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            while (reader.Read())
            {
                ConnectionMySQL.Connect();
                ConnectionMySQL.InsertPatientOther(reader.GetValue(0).ToString(), reader.GetValue(1).ToString(), reader.GetValue(2).ToString());
                ConnectionMySQL.Disconnect();
                UpdateAfterInsert("histories", "hc", 0, reader);
                //MessageBox.Show(Helper.GetComplexName(reader.GetValue(1).ToString())[0] + " -- " + Helper.GetComplexName(reader.GetValue(1).ToString())[1]);
            }
            FinalMessage();
        }
        public static void InsertMysqlPrice()
        {
            ConectarTarifario();
            string          query         = "select * from tarifario where codigo <> 0 and flag = '0' order by codigo";
            OleDbCommand    commandselect = new OleDbCommand(query, Conex);
            OleDbDataReader reader        = commandselect.ExecuteReader();

            ConnectionMySQL.Connect();
            while (reader.Read())
            {
                if (!ServiceExists(reader))
                {
                    ConnectionMySQL.Connect();
                    ConnectionMySQL.InsertService(Helper.SuavizatingCode(reader.GetValue(0).ToString()), reader.GetString(1), "", "");
                    ConnectionMySQL.Disconnect();
                }
                ConnectionMySQL.IncludePrice(reader.GetValue(0).ToString(), reader.GetValue(2).ToString(), Convert.ToInt16(reader.GetValue(3).ToString()));
                UpdateAfterInsert("tarifario", "codigo", 0, reader);
            }
            ConnectionMySQL.Disconnect();
            FinalMessage();
        }
        public static string GetInternCode()
        {
            ConnectionMySQL.Connect();
            string          query       = "select max(abs(intern_code)) from authorizations";
            MySqlCommand    command     = new MySqlCommand(query, ConnectionMySQL.GetConnection());
            MySqlDataReader readerm     = command.ExecuteReader();
            string          intern_code = "0";

            while (readerm.Read())
            {
                string valor = readerm.GetValue(0).ToString();
                if (valor == "0" || valor == null || valor == "" || Convert.ToInt32(valor) <= 15000)
                {
                    intern_code = "15001";
                }
                else
                {
                    intern_code = (Convert.ToInt32(valor) + 1).ToString();
                }
            }
            ConnectionMySQL.Disconnect();
            return(intern_code);
        }
        public static string GetClinicHistoryCode()
        {
            ConnectionMySQL.Connect();
            string          query               = "select max(abs(clinic_history_code)) from patients";
            MySqlCommand    command             = new MySqlCommand(query, ConnectionMySQL.GetConnection());
            MySqlDataReader readerm             = command.ExecuteReader();
            string          clinic_history_code = "0";

            while (readerm.Read())
            {
                string valor = readerm.GetValue(0).ToString();
                if (valor == "0" || valor == null || valor == "" || Convert.ToInt32(valor) <= 5000)
                {
                    clinic_history_code = "5001";
                }
                else
                {
                    clinic_history_code = (Convert.ToInt32(valor) + 1).ToString();
                }
            }
            ConnectionMySQL.Disconnect();
            return(clinic_history_code);
        }