Cesar Systems

Herramientas Informaticas

Creando texto para vista PHP8 en base a la tabla usando Visual Basic 2022

Ahora solo queda hacer la función para generar automáticamente el código HTML/PHP para la vista del catalogo en base a la nueva tabla.

La lógica es igual solo que es otro texto

Insertamos el siguiente código

'IMPORTAMOS LAS LIBRERIAS NECESARIAS PARA LA CONEXIÓN A MYSQL/MARIADB
Imports MySqlConnector.MySqlConnection

'EMPIEZA EL MODULO
Module crearVista

    ' CON PUBLIC SUB CREAMOS PROCEDIMIENTOS
    Public Function generarVista() As String

        ' VARIABLES PARA LA CONEXIÓN
        Dim strServidor As String
        Dim strBaseDeDatos As String
        Dim strUsuario As String
        Dim strContra As String

        'Variables de uso
        Dim contador As Integer
        Dim strEncabezadosTabla As String
        Dim strCampos As String
        Dim strControlesNuevos As String
        Dim strControlesEditar As String
        Dim strEditarJS As String
        Dim strBloquear As String
        Dim strEditarTraeDatos As String
        Dim strDatos As String
        Dim strLLavePrimaria As String
        Dim strVista As String
        Dim strSegundoCampo As String

        contador = 0
        strEncabezadosTabla = ""
        strCampos = ""
        strControlesNuevos = ""
        strEditarJS = ""
        strDatos = ""

        'OBTENEMOS LOS DATOS DE CONFIGURACIÖN DEL REGISTRO DE WINDOWS PREVIAMENTE GUARDADAS
        If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing) Is Nothing Then
            strServidor = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing).ToString()
            strBaseDeDatos = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "baseDeDatos", Nothing).ToString()
            strUsuario = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "usuario", Nothing).ToString()
            strContra = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "contra", Nothing).ToString()
        Else

            MsgBox("No se han capturado la conexión a la base de datos")
            Exit Function


        End If


        ' METEMOS LA CADENA DE CONEXIÓN EN UNA VARIABLE
        Dim cadenaConexion = "Server=" & strServidor & ";User ID=" & strUsuario & ";Password=" & strContra & ";Database=" & strBaseDeDatos

        ' CREAMOS LA CONEXIÓN CON LA CADENA DE CONEXIÓN
        Dim connection = New MySqlConnector.MySqlConnection(cadenaConexion)

        Try


            connection.Open()
            Dim comando = New MySqlConnector.MySqlCommand("delete from clases where clase= 'controladores/" & frmCreaCatalogo.txtTabla.Text & ".controlador.php'", connection)
            Dim resultado = comando.ExecuteReader()
            comando = Nothing
            resultado = Nothing
            connection.Close()



            connection.Open()
            comando = New MySqlConnector.MySqlCommand("delete from clases where clase= 'modelos/" & frmCreaCatalogo.txtTabla.Text & ".modelo.php'", connection)
            resultado = comando.ExecuteReader()
            comando = Nothing
            resultado = Nothing
            connection.Close()

            connection.Open()
            comando = New MySqlConnector.MySqlCommand("insert into clases(clase) values('controladores/" & frmCreaCatalogo.txtTabla.Text & ".controlador.php')", connection)
            resultado = comando.ExecuteReader()
            comando = Nothing
            resultado = Nothing
            connection.Close()

            connection.Open()
            comando = New MySqlConnector.MySqlCommand("insert into clases(clase) values( 'modelos/" & frmCreaCatalogo.txtTabla.Text & ".modelo.php')", connection)
            resultado = comando.ExecuteReader()
            comando = Nothing
            resultado = Nothing
            connection.Close()

            ' SI SE ABRE LA CONEXIÓN MANDAMOS MENSAJE
            connection.Open()




            comando = New MySqlConnector.MySqlCommand("SHOW KEYS FROM  " & frmCreaCatalogo.txtTabla.Text & " WHERE Key_name = 'PRIMARY'", connection)

            resultado = comando.ExecuteReader

            resultado.Read()


            'ASIGNAMOS EL CAMPO LLAVE

            strLLavePrimaria = resultado.GetString("Column_name")


            'OBTENEMOS LOS CAMPOS DE LA TABLA
            connection.Close()
            connection.Open()
            comando = Nothing
            comando = New MySqlConnector.MySqlCommand("describe  " & frmCreaCatalogo.txtTabla.Text & "", connection)
            resultado = Nothing
            resultado = comando.ExecuteReader



            contador = 0


            While (resultado.Read)
                strEncabezadosTabla &= "<th>" & utilerias.strPrimeraMayuscula(resultado("Field")) & "</th>" & vbCrLf

                strCampos &= "<td>'.$value[""" & resultado("Field") & """].'</td>" & vbCrLf

                If contador > 0 Then

                    strControlesNuevos &= "" & "            <!-- ENTRADA PARA " & UCase(resultado("Field")) & " --> " & vbCrLf
                    strControlesNuevos &= "" & " " & vbCrLf
                    strControlesNuevos &= "" & "            <div class=""form-group""> " & vbCrLf
                    strControlesNuevos &= "" & " " & vbCrLf
                    strControlesNuevos &= "" & "              <div class=""input-group""> " & vbCrLf
                    strControlesNuevos &= "" & " " & vbCrLf
                    strControlesNuevos &= "" & "                <span class=""input-group-addon"">" & utilerias.strPrimeraMayuscula(resultado("Field")) & ": </span>  " & vbCrLf
                    strControlesNuevos &= "" & " " & vbCrLf
                    strControlesNuevos &= "" & "                <input type=""text"" class=""form-control input-lg"" name=""nuevo" & utilerias.strPrimeraMayuscula(resultado("Field")) & """ placeholder=""Ingresar " & utilerias.strPrimeraMayuscula(resultado("Field")) & """ required> " & vbCrLf
                    strControlesNuevos &= "" & " " & vbCrLf
                    strControlesNuevos &= "" & "              </div> " & vbCrLf
                    strControlesNuevos &= "" & " " & vbCrLf
                    strControlesNuevos &= "" & "            </div> " & vbCrLf

                    strEditarJS &= "" & "            $(""#editarDescripcion"").val(respuesta[""descripcion""]);" & vbCrLf

                End If


                If resultado("Key") = "PRI" Then
                    strBloquear = "readonly"
                Else
                    strBloquear = ""
                End If



                strControlesEditar &= "" & "            <!-- ENTRADA PARA " & UCase(resultado("Field")) & " --> " & vbCrLf
                strControlesEditar &= "" & " " & vbCrLf
                strControlesEditar &= "" & "            <div class=""form-group""> " & vbCrLf
                strControlesEditar &= "" & " " & vbCrLf
                strControlesEditar &= "" & "              <div class=""input-group""> " & vbCrLf
                strControlesEditar &= "" & " " & vbCrLf
                strControlesEditar &= "" & "                <span class=""input-group-addon"">" & utilerias.strPrimeraMayuscula(resultado("Field")) & ": </span>  " & vbCrLf
                strControlesEditar &= "" & " " & vbCrLf
                strControlesEditar &= "" & "                <input " & strBloquear & "  type=""text"" class=""form-control input-lg"" id=""editar" & utilerias.strPrimeraMayuscula(resultado("Field")) & """ name=""editar" & utilerias.strPrimeraMayuscula(resultado("Field")) & """ placeholder=""Ingresar " & utilerias.strPrimeraMayuscula(resultado("Field")) & """ required> " & vbCrLf
                strControlesEditar &= "" & " " & vbCrLf
                strControlesEditar &= "" & "              </div> " & vbCrLf
                strControlesEditar &= "" & " " & vbCrLf
                strControlesEditar &= "" & "            </div> " & vbCrLf

                strEditarTraeDatos &= "" & "            $(""#editar" & utilerias.strPrimeraMayuscula(resultado("Field")) & """).val(respuesta[""" & resultado("Field") & """]); " & vbCrLf

                contador = contador + 1

            End While


            strControlesEditar &= "" & " <input type=""hidden"" id=""editar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """  name = ""editar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """ > " & vbCrLf
            strEncabezadosTabla &= "<th>Acciones</th>"
            strCampos &= "<td> " & vbCrLf
            strCampos &= "<div class = ""btn-group""> " & vbCrLf



            strCampos &= "                    <button class= ""btn btn-warning btnEditar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """ id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & " = ""'.$value[""id""].'"" data-toggle = ""modal"" data-target = ""#modalEditar" & Trim(utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text)) & """> <i class = ""fa fa-pencil""> </i> </button> " & vbCrLf

            strCampos &= "<button class = ""btn btn-danger btnEliminar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """ id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "= ""'.$value[""id""].'""><i class= ""fa fa-times""></i></button>" & vbCrLf

            strCampos &= "</div>" & vbCrLf

            strCampos &= "</td> " & vbCrLf

            strVista &= "" & "<?php" & vbCrLf
            strVista &= "" & vbCrLf
            strVista &= "" & "if(""off"" == ""offf""){" & vbCrLf
            strVista &= "" & vbCrLf
            strVista &= "" & "  echo '<script>" & vbCrLf
            strVista &= "" & vbCrLf
            strVista &= "" & "    window.location = ""inicio""; " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  </script>'; " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  return; " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "} " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "?> " & vbCrLf
            strVista &= "" & "<div class=""content-wrapper"">" & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  <section class=""content-header"">" & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    <h1> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      Administrar <?php echo  mb_strtolower(preg_replace('/(?<=\\w)(\\p{Lu})/u', ' $1', ' " & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & " ')); ?> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    </h1> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    <ol class=""breadcrumb""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      <li><a href=""inicio""><i class=""fa fa-dashboard""></i> Inicio</a></li> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      <li class=""active"">Administrar <?php echo  mb_strtolower(preg_replace('/(?<=\\w)(\\p{Lu})/u', ' $1', '" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & " ')); ?></li> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    </ol> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  </section> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  <section class=""content""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    <div class=""box""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      <div class=""box-header With-border""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <button class=""btn btn-primary"" data-toggle=""modal"" data-target=""#modalAgregar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          Agregar <?php echo  mb_strtolower(preg_replace('/(?<=\\w)(\\p{Lu})/u', ' $1', '" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & " ')); ?> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      <div class=""box-body""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "       <table class=""table table-bordered table-striped dt-responsive tablas"" width=""100%""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <thead> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "         <tr> " & vbCrLf
            strVista &= "" & " " & strEncabezadosTabla
            strVista &= "" & "         </tr>  " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </thead> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <tbody> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <?php " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        $item = null; " & vbCrLf
            strVista &= "" & "        $valor = null; " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        $" & frmCreaCatalogo.txtTabla.Text & "= Controlador" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "::ctrMostrar($item, $valor); " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "       foreach ($" & frmCreaCatalogo.txtTabla.Text & " as $key => $value){ " & vbCrLf
            strVista &= "" & " " & vbCrLf



            strVista &= "" & "          echo ' <tr> " & vbCrLf

            strVista &= "" & strCampos & vbCrLf

            strVista &= "" & " " & vbCrLf
            strVista &= "" & "                </tr>'; " & vbCrLf
            strVista &= "" & "        } " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        ?>  " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </tbody> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "       </table> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  </section> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "</div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "<!--===================================== " & vbCrLf
            strVista &= "" & "MODAL <?php echo  mb_strtolower(preg_replace('/(?<=\\w)(\\p{Lu})/u', ' $1', ' " & (frmCreaCatalogo.txtTabla.Text) & " ')); ?> " & vbCrLf
            strVista &= "" & " ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "<div id=""modalAgregar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """ class=""modal fade"" role=""dialog""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  <div class=""modal-dialog""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    <div class=""modal-content""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      <form role=""form"" method=""post"" enctype=""multipart/form-data""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <!--===================================== " & vbCrLf
            strVista &= "" & "        CABEZA DEL MODAL " & vbCrLf
            strVista &= "" & "        ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <div class=""modal-header"" style=""background:#3c8dbc; color:white"" > " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <button type=""button"" class=""close"" data-dismiss=""modal"">&times;</button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <h4 class=""modal-title"">Agregar <?php echo  mb_strtolower(preg_replace('/(?<=\\w)(\\p{Lu})/u', ' $1', ' " & (frmCreaCatalogo.txtTabla.Text) & " ')); ?> </h4> " & vbCrLf
            strVista &= "" & " " & vbCrLf

            strVista &= "" & "        </div> " & vbCrLf

            strVista &= "" & "        <!--===================================== " & vbCrLf
            strVista &= "" & "        CUERPO DEL MODAL " & vbCrLf
            strVista &= "" & "        ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <div class=""modal-body""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <div class=""box-body""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "            <!-- ENTRADA PARA DESCRIPCION --> " & vbCrLf

            strVista &= "" & " " & strControlesNuevos & vbCrLf


            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <!--===================================== " & vbCrLf
            strVista &= "" & "        PIE DEL MODAL " & vbCrLf
            strVista &= "" & "        ====================================== --> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <div class=""modal-footer""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <button type=""button"" class=""btn btn-Default pull-left"" data-dismiss=""modal"">Salir</button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <button type=""submit"" class=""btn btn-primary"">Guardar</button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <?php " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "           $crear = new Controlador" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "(); " & vbCrLf
            strVista &= "" & "           $crear ->ctrIngresar(); " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        ?> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      </form> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "</div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "<!--===================================== " & vbCrLf
            strVista &= "" & "MODAL EDITAR USUARIO " & vbCrLf
            strVista &= "" & " ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "<div id=""modalEditar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """ class=""modal fade"" role=""dialog"">" & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  <div class=""modal-dialog""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    <div class=""modal-content""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      <form role=""form"" method=""post"" enctype=""multipart/form-data""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <!--===================================== " & vbCrLf
            strVista &= "" & "        CABEZA DEL MODAL " & vbCrLf
            strVista &= "" & "        ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <div class=""modal-header"" style=""background:#3c8dbc; color:white"" > " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <button type=""button"" class=""close"" data-dismiss=""modal"">&times;</button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <h4 class=""modal-title"">Agregar <?php echo  mb_strtolower(preg_replace('/(?<=\\w)(\\p{Lu})/u', ' $1', ' " & (frmCreaCatalogo.txtTabla.Text) & " ')); ?> </h4> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <!--===================================== " & vbCrLf
            strVista &= "" & "        CUERPO DEL MODAL " & vbCrLf
            strVista &= "" & "        ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <div class=""modal-body""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <div class=""box-body""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "            <!-- ENTRADA PARA DESCRIPCION --> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & strControlesEditar
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <!--===================================== " & vbCrLf
            strVista &= "" & "        PIE DEL MODAL " & vbCrLf
            strVista &= "" & "        ======================================--> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        <div class=""modal-footer""> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <button type=""button"" class=""btn btn-Default pull-left"" data-dismiss=""modal"">Salir</button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "          <button type=""submit"" class=""btn btn-primary"">Modificar</button> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "     <?php " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "           $editar = new Controlador" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "(); " & vbCrLf
            strVista &= "" & "           $editar ->ctrEditar(); " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "        ?>  " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "      </form> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "    </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "  </div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "</div> " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "<?php " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "   $borrar = new Controlador" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "(); " & vbCrLf
            strVista &= "" & "   $borrar ->ctrBorrar(); " & vbCrLf
            strVista &= "" & " " & vbCrLf
            strVista &= "" & "?>  " & vbCrLf

            'JAVASCRIPT FUNCIONES
            strVista &= "" & "<script type=""text/javascript"">" & vbCrLf

            'ELIMINAR


            strVista &= "" & "/*= == == == == == == == == == == == == == == == == == == == == == ==" & vbCrLf
            strVista &= "" & " ELIMINAR " & UCase(frmCreaCatalogo.txtTabla.Text) & vbCrLf
            strVista &= "" & " == == == == == == == == == == == == == == == == == == == == == == = */" & vbCrLf
            strVista &= "" & "$("".tablas "").on(""click"", "".btnEliminar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """, function() {" & vbCrLf

            strVista &= "" & "    var id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & " = $(this).attr(""id" & frmCreaCatalogo.txtTabla.Text & """);" & vbCrLf

            strVista &= "" & "    swal( {" & vbCrLf
            strVista &= "" & "        title: '¿Está seguro de borrar?'," & vbCrLf
            strVista &= "" & "        text: ""¡Si no lo está puede cancelar la accíón!""," & vbCrLf
            strVista &= "" & "        type: 'warning'," & vbCrLf
            strVista &= "" & "        showCancelButton: true," & vbCrLf
            strVista &= "" & "        confirmButtonColor: '#3085d6'," & vbCrLf
            strVista &= "" & "        cancelButtonColor: '#d33'," & vbCrLf
            strVista &= "" & "        cancelButtonText: 'Cancelar'," & vbCrLf
            strVista &= "" & "       confirmButtonText: 'Si, borrar!'" & vbCrLf
            strVista &= "" & "    }).then(function(result) {" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "        if (result.value) {" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "            window.location = ""index.php?ruta=" & (frmCreaCatalogo.txtTabla.Text) & "&id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "=""+id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "+""&borrar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "=borrar"";" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "        }" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "    })" & vbCrLf

            strVista &= "" & "})" & vbCrLf


            'editar

            strVista &= "" & "/* = == == == == == == == == == == == == == == == == == == == == == ==" & vbCrLf
            strVista &= "" & " EDITAR " & vbCrLf
            strVista &= "" & " == == == == == == == == == == == == == == == == == == == == == == = */" & vbCrLf
            strVista &= "" & "$("".tablas "").on(""click"", "".btnEditar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """, function() {" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "    var id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & " = $(this).attr(""id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """);" & vbCrLf
            strVista &= "" & "  console.log(id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & ");"
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "    var datos = new FormData();" & vbCrLf
            strVista &= "" & "    datos.append(""id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """, id" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & "); " & vbCrLf
            strVista &= "" & "    datos.append(""buscar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """, ""buscar" & utilerias.strPrimeraMayuscula(frmCreaCatalogo.txtTabla.Text) & """);" & vbCrLf
            strVista &= "" & "   " & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "    $.ajax( {" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "        url:""controladores/" & frmCreaCatalogo.txtTabla.Text & ".controlador.php""," & vbCrLf
            strVista &= "" & "        method:""POST""," & vbCrLf
            strVista &= "" & "        data: datos," & vbCrLf
            strVista &= "" & "        cache: false," & vbCrLf
            strVista &= "" & "        contentType: false," & vbCrLf
            strVista &= "" & "        processData: false," & vbCrLf
            strVista &= "" & "       dataType:""json""," & vbCrLf
            strVista &= "" & "       success: function(respuesta) {" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & strEditarTraeDatos & vbCrLf
            strVista &= "" & "            " & vbCrLf
            strVista &= "" & "        }" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "    });" & vbCrLf
            strVista &= "" & "" & vbCrLf
            strVista &= "" & "})" & vbCrLf


            strVista &= "" & "</script>" & vbCrLf
            Return strVista
        Catch ex As Exception
            ' SI NO SE ABRE LA CONEXIÓN MANDAMOS MENSAJE DE ERROR
            MsgBox("ERROR " & ex.Message)

            Exit Function
        End Try

    End Function

End Module

Creando texto para el archivo del catalogo controlador PHP Visual Basic 2022 en base a una tabla creada

Ya vimos como crear el modelo, dijimos que mostraremos como crear el archivo de modelo, pero mejor mostraremos como generar el texto del controlador en base a los campos de la tabla, es un poco mas fácil

a continuación les dejo el código fuente

Imports System.Windows.Forms

Public Class frmCreaCatalogo

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        Dim strModelo As String
        Dim strControlador As String

        My.Computer.Registry.SetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "txtTabla", Me.txtTabla.Text)

        strModelo = crearModelo.generaModelo()
        strControlador = crearControlador.generaControlador()


        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub btnRuta_Click(sender As Object, e As EventArgs) Handles btnRuta.Click

        dlgRuta.ShowDialog()

        txtRuta.Text = dlgRuta.SelectedPath


    End Sub

    Private Sub frmCreaCatalogo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "txtTabla", Nothing) Is Nothing Then

            Me.txtTabla.Text = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "txtTabla", Nothing).ToString()

        End If
    End Sub
End Class

Saludos y espero que les sirva

Creando el texto para el modelo del catalogo en PHP en Visual Basic 2022

Hasta ahora ya nos pudimos conectar a la base de datos, hicimos consultas SQL a través de la conexión creada hicimos r creamos funciones para facilitar la programación, ahora nos toca simplemente maniobrar para crear todo el texto completo.

Como algo nuevo aprendido en este código es que no se pueden usar las comillas ” como escape por ejemplo \” en su lugar simplemente pones dos veces la doble comilla ejemplo “”

También el salto de linea que en gambas3 era gb.CrLf en Visual Basic 2022 es vbCrLf

Bien sin mas reparos les dejo como quedo finalmente el código para crear el código del modelo en PHP

'IMPORTAMOS LAS LIBRERIAS NECESARIAS PARA LA CONEXIÓN A MYSQL/MARIADB
Imports MySqlConnector.MySqlConnection

'EMPIEZA EL MODULO
Module crearModelo

    ' CON PUBLIC SUB CREAMOS PROCEDIMIENTOS
    Public Function generaModelo() As String

        ' VARIABLES PARA LA CONEXIÓN
        Dim strServidor As String
        Dim strBaseDeDatos As String
        Dim strUsuario As String
        Dim strContra As String

        'Variables de uso
        Dim strCampos As String
        Dim strCamposNoLLave As String
        Dim strLLavePrimaria As String
        Dim strCamposValue As String
        Dim strBindingInsert As String
        Dim strBindingUpdate As String
        Dim strCamposUpdate As String
        Dim strModelo As String

        'OBTENEMOS LOS DATOS DE CONFIGURACIÖN DEL REGISTRO DE WINDOWS PREVIAMENTE GUARDADAS
        If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing) Is Nothing Then
            strServidor = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing).ToString()
            strBaseDeDatos = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "baseDeDatos", Nothing).ToString()
            strUsuario = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "usuario", Nothing).ToString()
            strContra = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "contra", Nothing).ToString()
        Else

            MsgBox("No se han capturado la conexión a la base de datos")
            Exit Function


        End If


        ' METEMOS LA CADENA DE CONEXIÓN EN UNA VARIABLE
        Dim cadenaConexion = "Server=" & strServidor & ";User ID=" & strUsuario & ";Password=" & strContra & ";Database=" & strBaseDeDatos

        ' CREAMOS LA CONEXIÓN CON LA CADENA DE CONEXIÓN
        Dim connection = New MySqlConnector.MySqlConnection(cadenaConexion)

        Try

            ' SI SE ABRE LA CONEXIÓN MANDAMOS MENSAJE
            connection.Open()



            Dim comando = New MySqlConnector.MySqlCommand("SHOW KEYS FROM  " & frmCreaCatalogo.txtTabla.Text & " WHERE Key_name = 'PRIMARY'", connection)

            Dim resultado = comando.ExecuteReader

            resultado.Read()


            'ASIGNAMOS EL CAMPO LLAVE

            strLLavePrimaria = resultado.GetString("Column_name")


            'OBTENEMOS LOS CAMPOS DE LA TABLA
            connection.Close()
            connection.Open()
            comando = Nothing
            comando = New MySqlConnector.MySqlCommand("describe  " & frmCreaCatalogo.txtTabla.Text & "", connection)
            resultado = Nothing
            resultado = comando.ExecuteReader



            Dim contador As Integer
            contador = 0


            While (resultado.Read)


                ' CAMPOS PARA EL Select
                If contador = 0 Then
                    strCampos = resultado.GetString("Field") & vbCrLf
                Else
                    strCampos = strCampos & "," & resultado("Field") & vbCrLf
                End If

                'CAMPOS PARA EL INSERT

                If resultado("Key") <> "PRI" Then
                    If contador = 1 Then
                        strCamposNoLLave = resultado("Field") & vbCrLf
                    Else
                        strCamposNoLLave = strCamposNoLLave & "," & resultado("Field") & vbCrLf
                    End If

                End If

                ' CAMPOS PARA EL VALUE

                If resultado("Key") <> "PRI" Then
                    If contador = 1 Then
                        strCamposValue = ":" & resultado("Field") & vbCrLf
                    Else
                        strCamposValue = strCamposValue & "," & ":" & resultado("Field") & vbCrLf
                    End If
                End If

                If resultado("Key") & vbCrLf <> "PRI" Then
                    strBindingInsert = strBindingInsert & "     $stmt -> bindParam("":" & resultado("Field") & """, $datos[""nuevo" & UCase(Mid$(resultado("Field"), 1, 1)) & Mid$(resultado("Field"), 2, 100) & """], PDO::PARAM_STR);" & vbCrLf
                End If

                ' CAMPOS UPDATE
                If resultado("Key") <> "PRI" Then

                    If contador = 1 Then

                        strCamposUpdate = strCamposUpdate & resultado("Field") & "= :" & resultado("Field")

                    Else

                        strCamposUpdate = strCamposUpdate & "," & resultado("Field") & "= :" & resultado("Field")

                    End If

                End If

                strBindingUpdate = strBindingUpdate & "     $stmt -> bindParam("":" & resultado("Field") & """, $datos[""editar" & utilerias.strPrimeraMayuscula(resultado("Field")) & """], PDO::PARAM_STR);" & vbCrLf

                contador = contador + 1



            End While


            strModelo = ""
            strModelo &= "<?php" & vbCrLf
            strModelo &= "require_once ""conexion.php"";" & vbCrLf
            strModelo &= "" & "" & vbCrLf



            strModelo &= "" & "Class Modelo" & UCase(Mid$(frmCreaCatalogo.txtTabla.Text, 1, 1)) & Mid$(frmCreaCatalogo.txtTabla.Text, 2, 25) & " {" & vbCrLf
            strModelo &= "" & "   /* =============================================" & vbCrLf
            strModelo &= "" & "     MOSTRAR " & UCase(frmCreaCatalogo.txtTabla.Text) & vbCrLf
            strModelo &= "" & "      ============================================= */" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "    Static Public Function mdlMostrar($tabla, $item, $valor) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "       If ($item != Null) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           $stmt = Conexion:: conectar() -> prepare( ""Select " & strCampos

            strModelo &= "" & "           From " & frmCreaCatalogo.txtTabla.Text & " a WHERE $item =$item"");" & vbCrLf
            strModelo &= "" & "" & vbCrLf


            strModelo &= "" & "           $stmt -> bindParam( "":"" .$item, $valor, PDO::PARAM_STR);" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           Try {" & vbCrLf
            strModelo &= "" & "               $stmt -> execute();" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "                Return $stmt -> fetch();" & vbCrLf
            strModelo &= "" & "           } Catch (PDOException $e) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "               $arr = $stmt -> errorInfo();" & vbCrLf
            strModelo &= "" & "                $arr[3] = ""Error"";" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "               If ($e -> getMessage() == 23000) {" & vbCrLf
            strModelo &= "" & "                   $mensaje = "" El registro esta duplicado, Favor de checar el numero de nomina "";" & vbCrLf
            strModelo &= "" & "                   Return $mensaje;" & vbCrLf
            strModelo &= "" & "               } Else {" & vbCrLf
            strModelo &= "" & "                  Return $arr[2];" & vbCrLf
            strModelo &= "" & "              }" & vbCrLf
            strModelo &= "" & "           }" & vbCrLf
            strModelo &= "" & "           " & vbCrLf
            strModelo &= "" & "           " & vbCrLf
            strModelo &= "" & "       } Else {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           $stmt = Conexion:: conectar() -> prepare(""Select * """ & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           " & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           From " & frmCreaCatalogo.txtTabla.Text & " a ""); """ & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           $stmt -> execute();" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           Return $stmt -> fetchAll();" & vbCrLf
            strModelo &= "" & "       }" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "       $stmt -> close();" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "        $stmt = Null;" & vbCrLf
            strModelo &= "" & "   }" & vbCrLf
            strModelo &= "" & "" & vbCrLf

            ' REGISTRO

            strModelo &= "" & "   /* ==================================================================" & vbCrLf
            strModelo &= "" & "     REGISTRO" & vbCrLf
            strModelo &= "" & "    ==================================================================== */" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "   Static Public Function mdlIngresar($tabla, $datos) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "      $stmt = Conexion:: conectar() -> prepare(""INSERT INTO " & frmCreaCatalogo.txtTabla.Text & "(" & strCamposNoLLave & "" & vbCrLf
            strModelo &= "" & "        " & vbCrLf
            strModelo &= "" & "                                                                       )" & vbCrLf
            strModelo &= "" & "                                                                       VALUES(" & strCamposValue & ")" & vbCrLf
            strModelo &= "" & "                          " & vbCrLf
            strModelo &= "" & "                                                                              ""); " & vbCrLf
            strModelo &= "" & ""

            strModelo &= "" & strBindingInsert & vbCrLf

            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "       If ($stmt -> execute()) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           Return ""ok"";" & vbCrLf
            strModelo &= "" & "       } Else {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           $arr = $stmt -> errorInfo();" & vbCrLf
            strModelo &= "" & "           $arr[3] = "" Error "";" & vbCrLf
            strModelo &= "" & "          Return $arr[2];" & vbCrLf
            strModelo &= "" & "      }" & vbCrLf

            strModelo &= "" & "      $stmt -> close();" & vbCrLf

            strModelo &= "" & "      $stmt = Null;" & vbCrLf
            strModelo &= "" & "  }" & vbCrLf



            'EDITAR ACTUALIZAR
            strModelo &= "" & "  /* ==================================================================" & vbCrLf
            strModelo &= "" & "   EDITAR " & vbCrLf
            strModelo &= "" & "     ================================================================== */" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "   Static Public Function mdlEditar($tabla, $datos) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "       $stmt = Conexion:: conectar() -> prepare("" UPDATE $tabla Set " & strCamposUpdate & "" & vbCrLf
            strModelo &= "" & ""
            strModelo &= "" & "                                                                   WHERE id =" & strLLavePrimaria & "  ""); " & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & strBindingUpdate
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "       If ($stmt -> execute()) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "           Return ""ok"";" & vbCrLf
            strModelo &= "" & "     } Else {" & vbCrLf
            strModelo &= "" & ""
            strModelo &= "" & "          Return ""Error"";" & vbCrLf
            strModelo &= "" & "      }" & vbCrLf
            strModelo &= "" & ""
            strModelo &= "" & "     $stmt -> close();" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "      $stmt = Null;" & vbCrLf
            strModelo &= "" & "   }" & vbCrLf
            strModelo &= "" & "   " & vbCrLf
            strModelo &= "" & " " & vbCrLf & vbCrLf
            strModelo &= "" & "  /* ===================================================================" & vbCrLf
            strModelo &= "" & "     BORRAR USUARIO" & vbCrLf
            strModelo &= "" & "     =================================================================== */" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "  Static Public Function mdlBorrar($tabla, $datos) {" & vbCrLf

            strModelo &= "" & "       $stmt = Conexion:: conectar() -> prepare( "" DELETE From " & frmCreaCatalogo.txtTabla.Text & " WHERE id =:id"");" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "       $stmt -> bindParam("":id"", $datos, PDO::PARAM_INT);" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "      If ($stmt -> execute()) {" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "Return ""ok"";" & vbCrLf
            strModelo &= "" & "      } Else {" & vbCrLf

            strModelo &= "" & "          Return ""Error"";" & vbCrLf
            strModelo &= "" & "      }" & vbCrLf

            strModelo &= "" & "        $stmt -> close();" & vbCrLf

            strModelo &= "" & "       $stmt = Null;" & vbCrLf
            strModelo &= "" & "    }" & vbCrLf
            strModelo &= "" & "" & vbCrLf
            strModelo &= "" & "}" & vbCrLf


            generaModelo = strModelo
        Catch ex As Exception
            ' SI NO SE ABRE LA CONEXIÓN MANDAMOS MENSAJE DE ERROR
            MsgBox("ERROR " & ex.Message)

            Exit Function
        End Try

    End Function

End Module

Funciones UCase y Mid$ y concatenado de Strings en Visual Basic 2022

De aquí en adelante trabajaremos manejando texto para crear el código del modelo vista controlador, así que la primera función que necesitamos crear es la de convertir la primera letra una cadena “Palabra” en mayúscula, para ello usaremos las funciones UCase, la cual sirve para convertir todo el texto le le mandemos en mayuscula por ejemplo si ponemos UCase(“kakaroto”) el resultado sera “KAKAROTO”. En cambio la función Mid$ nos servirá para obtener una parte del texto por ejemplo si ponemos mid$(“kakaroto”,1,1) el resultado sera “k” o si ponen mid$(“kakaroto”,1,2) el resultado sera “ka”.

Para el concatenado de dos variables con texto simplemente se contatena con amperson &

Por ejemplo en la variable strTexto1 tiene asignado el siguiente texto “Texto de prueba” y la variable strTexto2 tiene asignado el texto “17 de agosto de 2022” si concatenamos strTexto1 & strTexto2 el resultado sera “Texto de prueba 17 de agosto de 2022”

Entonces para solo ponerle la primera letra mayúscula a la cadena “kakaroto” seria de la siguiente forma UCase(Mid$(“kakaroto”, 1, 1)) & Mid$(“kakaroto”, 2, 100) y el resultado seria “Kakaroto”

El código fuente para usar la función seria la siguiente

Module utilerias


    Public Function strPrimeraMayuscula(strCadena As String) As String

        Return UCase(Mid$(strCadena, 1, 1)) & Mid$(strCadena, 2, 100)

    End Function


End Module

Como ejecutar una consulta MySQL y ciclo While en Visual Basic 2022

Ya hemos visto como realizar la conexión a la base de datos MySQL / MariaDB además de conectarnos con una cadena de conexión dinámica ahora veremos como realizar una consulta a una table y leer los datos con el ciclo While.

Estamos en en el archivo modulo crearModelo.vb justo despues de abrir la conexión declaramos la variable comando de tipo mysqlcommand, y ejecutaremos la siguiente consulta “describe proveedores;” la cual nos regresa los campos de la tabla, quedaría de la siguiente forma.

 Dim comando = New MySqlConnector.MySqlCommand("describe proveedores;", connection)

Posteriormente guardamos el resultado usando la función executeReader

Dim resultado = comando.ExecuteReader

En resultado tenemos guardado todos los renglones y columnas que nos regreso la consulta “describe proveedores;” para leerlos y mostrarlos en un MessageBox necesitaremos recorrerlos mediante un ciclo while y lo hacemos de la siguiente forma.

   While (resultado.Read)

      MessageBox.Show(resultado.GetString(0))

   End While
Vemos como el messageBox se muestra dependiendo del numero de columnas que tenga la tabla a la cual le hicimos el describe

Al final el código quedaría de la siguiente forma

'IMPORTAMOS LAS LIBRERIAS NECESARIAS PARA LA CONEXIÓN A MYSQL/MARIADB
Imports MySqlConnector.MySqlConnection

'EMPIEZA EL MODULO
Module crearModelo

    ' CON PUBLIC SUB CREAMOS PROCEDIMIENTOS
    Public Sub generaModelo()

        ' VARIABLES PARA LA CONEXIÓN
        Dim strServidor As String
        Dim strBaseDeDatos As String
        Dim strUsuario As String
        Dim strContra As String


        'OBTENEMOS LOS DATOS DE CONFIGURACIÖN DEL REGISTRO DE WINDOWS PREVIAMENTE GUARDADAS
        If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing) Is Nothing Then
            strServidor = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing).ToString()
            strBaseDeDatos = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "baseDeDatos", Nothing).ToString()
            strUsuario = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "usuario", Nothing).ToString()
            strContra = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "contra", Nothing).ToString()
        Else

            MsgBox("No se han capturado la conexión a la base de datos")
            Return

        End If


        ' METEMOS LA CADENA DE CONEXIÓN EN UNA VARIABLE
        Dim cadenaConexion = "Server=" & strServidor & ";User ID=" & strUsuario & ";Password=" & strContra & ";Database=" & strBaseDeDatos

        ' CREAMOS LA CONEXIÓN CON LA CADENA DE CONEXIÓN
        Dim connection = New MySqlConnector.MySqlConnection(cadenaConexion)

        Try

            ' SI SE ABRE LA CONEXIÓN MANDAMOS MENSAJE
            connection.Open()


            Dim comando = New MySqlConnector.MySqlCommand("describe proveedores;", connection)

            Dim resultado = comando.ExecuteReader

            While (resultado.Read)

                MessageBox.Show(resultado.GetString(0))


            End While


            MsgBox("Conexion Correcta")

        Catch ex As Exception
            ' SI NO SE ABRE LA CONEXIÓN MANDAMOS MENSAJE DE ERROR
            MsgBox("ERROR " & ex.Message)

            Exit Sub
        End Try

    End Sub

End Module

Creando Cadena de Conexión dinámica con Variables de Configuración #8

Hasta este punto ya hemos creado la conexión con una cadena de conexión directa en la cual nosotros ponemos los datos de conexión a la base de de datos directamente, pero sabemos que la conexión del servidor, la base de datos, el usuario y la contraseña pueden estar cambiando, entonces mostraremos como tener una conexión dinámica basada en nuestras variables de configuración guardadas en el registro de Windows.

Nuestro código en el modulo crearModelo quedaría de la siguiente forma.

'IMPORTAMOS LAS LIBRERIAS NECESARIAS PARA LA CONEXIÓN A MYSQL/MARIADB
Imports MySqlConnector.MySqlConnection

'EMPIEZA EL MODULO
Module crearModelo

    ' CON PUBLIC SUB CREAMOS PROCEDIMIENTOS
    Public Sub generaModelo()

        ' VARIABLES PARA LA CONEXIÓN
        Dim strServidor As String
        Dim strBaseDeDatos As String
        Dim strUsuario As String
        Dim strContra As String


        'OBTENEMOS LOS DATOS DE CONFIGURACIÖN DEL REGISTRO DE WINDOWS PREVIAMENTE GUARDADAS
        If Not My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing) Is Nothing Then
            strServidor = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "servidor", Nothing).ToString()
            strBaseDeDatos = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "baseDeDatos", Nothing).ToString()
            strUsuario = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "usuario", Nothing).ToString()
            strContra = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\CREADORMVCPHP", "contra", Nothing).ToString()
        Else

            MsgBox("No se han capturado la conexión a la base de datos")
            Return

        End If


        ' METEMOS LA CADENA DE CONEXIÓN EN UNA VARIABLE
        Dim cadenaConexion = "Server=" & strServidor & ";User ID=" & strUsuario & ";Password=" & strContra & ";Database=" & strBaseDeDatos

        ' CREAMOS LA CONEXIÓN CON LA CADENA DE CONEXIÓN
        Dim connection = New MySqlConnector.MySqlConnection(cadenaConexion)

        Try

            ' SI SE ABRE LA CONEXIÓN MANDAMOS MENSAJE
            connection.Open()
            MsgBox("Conexion Correcta")

        Catch ex As Exception
            ' SI NO SE ABRE LA CONEXIÓN MANDAMOS MENSAJE DE ERROR
            MsgBox("ERROR " & ex.Message)

            Exit Sub
        End Try

    End Sub

End Module
Nos aseguramos de que tenemos los datos de conexión a la base de datos bien capturados
Hacemos la prueba y si sale el siguiente mensaje significa que la conexión se realizo correctamente

CONEXIÓN VISUAL BASIC 2022 CON MYSQL

En la publicación anterior vimos como hacer el diseño de la ventana para generar el catalogo ahora nos toca leer la tabla para ver que campos contiene y así crear todos los archivos necesarios para crear el catalogo. Antes de leer los datos es necesario conectarnos a la base de datos de MySQL o MariaDB, así que en esta publicación veremos como conectarnos a a MySQL con Visual Basic 2022

Primero nos vamos a administrar paquetes Nutgets para solución e instalamos MySQLConector por Bradley Grainger
Creamos la carpeta módulos que nos servirá para guardar funciones y procedimientos necesarios para el proyecto que en nuestro caso será las conexiones
Creamos un modulo con nombre creaModelo

'IMPORTAMOS LAS LIBRERIAS NECESARIAS PARA LA CONEXIÓN A MYSQL/MARIADB
Imports MySqlConnector.MySqlConnection

'EMPIEZA EL MODULO
Module creaModelo
' CON PUBLIC SUB CREAMOS PROCEDIMIENTOS
Public Sub generaModelo()

    ' METEMOS LA CADENA DE CONEXIÓN EN UNA VARIABLE
    Dim cadenaConexion = "Server=127.0.0.1;User ID=root;Password=;Database=pos"

    ' CREAMOS LA CONEXIÓN CON LA CADENA DE CONEXIÓN
    Dim connection = New MySqlConnector.MySqlConnection(cadenaConexion)

    Try

        ' SI SE ABRE LA CONEXIÓN MANDAMOS MENSAJE
        connection.Open()
        MsgBox("Conexion Correcta")

    Catch ex As Exception
        ' SI NO SE ABRE LA CONEXIÓN MANDAMOS MENSAJE DE ERROR
        MsgBox("ERROR " & ex.Message)

        Exit Sub
    End Try

End Sub
End Module
Quedaría de esta forma
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        creaModelo.generaModelo()

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

Así quedaría el evento Click

El evento CLICK lo dejamos de esta manera y hacemos la prueba
A la hora de hacer la prueba nos debe arrojar el siguiente mensaje

Y bien en la próxima publicación veremos como usar la variables que guardamos en el registro de Windows para integrarla en la cadena de conexión

Creando ventana “Crear Catálogo”

Ya vimos como usar las funciones registry para guardar las configuraciones de la base de de datos, ahora vamos a crear otra ventana para hacer el generador de catalogos.

Los componentes que vamos a utilizar son los siguientes

  1. textBox
  2. Button
  3. FolderBrowserDialog

Son 3 controles muy simples, de he hecho el componente que no se ha usado anteriormente en es este proyecto es FolderBrowserDialog, este nos permitira elegir la ruta del proyecto JCPOS2021

Creamos el formulario, para ello elegimos cuadro de dialogo y en el nombre le ponemos crearCatalogo.vb
Agregamos los controles de label para poner la etiqueta tabla, agregamos el campo de texto tabla para capturar la tabla, agregamos el boton btnRuta para mandar llamar el folderBrowserDialog y agregamos bdlRuta que será el folderBrowser dialog
Ahora en el evento Click del boton btnRuta agregamos para que se ejecute el dialogo para escoger la carpeta, posteriormente asignaremos la ruta seleccionada al campo de texto txtRuta
Al darle Click nos arrojara el dialogo para buscar la carpeta del proyecto
Al seleccionar la carpeta vemos como se pone la ruta en el campo de texto txtRuta

CONEXIÓN PHP 8.1 CON PDO SQL SERVER EN WINDOWS 10

En algunas ocasiones es necesario conectarnos por medio de PHP8.1 a la base de datos de SQL SERVER.

Aunque esta función no esta activada por default se puede activar, solo tenemos que descargar las siguientes librerías.

Descomprimimos y en mi caso son las que están en la carpeta x64
Ponemos las librerías en la carpeta EXT en donde están los archivos de PHP en mi caso la ruta es la que se ve en la imagen
En el archivo de configuracion que normalmente se llama php.ini agregamos las siguientes lineas extension=php_pdo_sqlsrv_81_nts
extension=php_sqlsrv_81_nts.dll
Renombramos la carpeta a PHP
Si corremos el PHPINFO debe salir activo el modulo de pdo_sqlsrv

Saludos y espero que les sirva

Novedades MX Linux 21 WILDFLOWER

Ha salido hace ya hace un poco de tiempo la versión 21 de MX LINUX, la distribución que se mantiene en el primer lugar en la top 100 de la WEB distrowatch así que vamos a dedicarle un post, sobre todo especificando la versión que viene con el entorno de escritorio XFCE

Para resumir rápidamente les dejo las novedades que tiene esta versión

Página 24 de 145

Creado con WordPress & Tema de Anders Norén