⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csharp.bas

📁 CodeWizardRC2.zip for Rainbow Souce Code
💻 BAS
字号:
Attribute VB_Name = "CSharp"
Function GetCSharpGet(oTable As SQLDMO.Table) As String
    Dim s As String
    Dim i As Integer
    Dim TableName As String
    Dim ProcName As String
    Dim NameLen As Integer
    Dim col As SQLDMO.Column
    Dim Key As String
    Dim ParameterKey As String
    
    Key = GetIdentityKey(oTable)
    ParameterKey = "@" & Key
    
    Call GetTableProcNames(oTable.name, "Get", TableName, ProcName)
    NameLen = Len(oTable.name)
    If InStr(NameLen - 1, oTable.name, "es") > 0 Then
        TableName = TableName & "es"
    ElseIf InStr(NameLen, oTable.name, "s") > 0 Then
        TableName = TableName & "s"
    End If
    
    'Comment
    s = s & GetCSXMLDoc(ProcName & TableName)
    s = s & "/// <param name=""" & Key & """>" & Key & "</param>" & vbCrLf
    s = s & "/// <returns>A DataSet</returns>" & vbCrLf
    
    'Head
    If ColumnExists(oTable, "ModuleID") Then
        s = s & "public DataSet " & ProcName & TableName & "(" & GetCSharpDataType(oTable.Columns("ModuleID").DataType) & " " & "ModuleID" & ")" & vbCrLf
    Else
        s = s & "public DataSet " & ProcName & TableName & "()" & vbCrLf
    End If
    
    s = s & "{" & vbCrLf
    s = s & vbTab & "// Create Instance of Connection and Command Object" & vbCrLf
    s = s & vbTab & "SqlConnection myConnection = PortalSettings.SqlConnectionString;" & vbCrLf
    s = s & vbTab & "SqlDataAdapter myCommand = new SqlDataAdapter(""" & ProcName & TableName & """, myConnection);" & vbCrLf
    s = s & vbTab & "myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;" & vbCrLf
    s = s & vbCrLf
    
    If ColumnExists(oTable, "ModuleID") Then
        s = s & vbTab & "// Add Parameters to SPROC" & vbCrLf
        s = s & vbTab & "SqlParameter parameter" & oTable.Columns("ModuleID").name & " = new SqlParameter(""@" & oTable.Columns("ModuleID").name & """, " & GetCSharpSQLFullDataType(oTable.Columns("ModuleID")) & ");" & vbCrLf
        s = s & vbTab & "parameter" & oTable.Columns("ModuleID").name & ".Value = " & oTable.Columns("ModuleID").name & ";" & vbCrLf
        s = s & vbTab & "myCommand.SelectCommand.Parameters.Add(parameter" & oTable.Columns("ModuleID").name & ");" & vbCrLf
        s = s & vbCrLf
    End If
    
    s = s & vbTab & "// Create and Fill the DataSet" & vbCrLf
    s = s & vbTab & "DataSet myDataSet = new DataSet();" & vbCrLf
    s = s & vbTab & "myCommand.Fill(myDataSet);" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Return the dataset" & vbCrLf
    s = s & vbTab & "return myDataSet;" & vbCrLf
    s = s & "}" & vbCrLf
    
    GetCSharpGet = s
End Function

Function GetCSharpGetSingle(oTable As SQLDMO.Table) As String
    Dim s As String
    Dim i As Integer
    Dim TableName As String
    Dim ProcName As String
    Dim col As SQLDMO.Column
    Dim Key As String
    Dim ParameterKey As String
    
    Key = GetIdentityKey(oTable)
    ParameterKey = "@" & Key
    
    Call GetTableProcNames(oTable.name, "GetSingle", TableName, ProcName)
    
    'Comment
    s = s & GetCSXMLDoc(ProcName & TableName)
    s = s & "/// <param name=""" & Key & """>" & Key & "</param>" & vbCrLf
    s = s & "/// <returns>A SqlDataReader</returns>" & vbCrLf
    'Head
    s = s & "public SqlDataReader " & ProcName & TableName & "(" & GetCSharpDataType(oTable.Columns(Key).DataType) & " " & Key & ")" & vbCrLf
    s = s & "{" & vbCrLf
    s = s & vbTab & "// Create Instance of Connection and Command Object" & vbCrLf
    s = s & vbTab & "SqlConnection myConnection = PortalSettings.SqlConnectionString;" & vbCrLf
    s = s & vbTab & "SqlCommand myCommand = new SqlCommand(""" & ProcName & TableName & """, myConnection);" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Mark the Command as a SPROC" & vbCrLf
    s = s & vbTab & "myCommand.CommandType = CommandType.StoredProcedure;" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Add Parameters to SPROC" & vbCrLf
    s = s & GetCSParamDef(oTable.Columns(Key))
    s = s & vbCrLf
    s = s & vbTab & "// Execute the command" & vbCrLf
    s = s & vbTab & "myConnection.Open();" & vbCrLf
    s = s & vbTab & "SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Return the datareader" & vbCrLf
    s = s & vbTab & "return result;" & vbCrLf
    s = s & "}" & vbCrLf
    
    GetCSharpGetSingle = s
End Function

Function GetCSharpDelete(oTable As SQLDMO.Table) As String
    Dim s As String
    Dim i As Integer
    Dim TableName As String
    Dim ProcName As String
    Dim col As SQLDMO.Column
    Dim Key As String
    Dim ParameterKey As String
    
    Key = GetIdentityKey(oTable)
    ParameterKey = "@" & Key
    
    Call GetTableProcNames(oTable.name, "Delete", TableName, ProcName)
    
    'Comment
    s = s & GetCSXMLDoc(ProcName & TableName)
    s = s & "/// <param name=""" & Key & """>" & Key & "</param>" & vbCrLf
    s = s & "/// <returns>Void</returns>" & vbCrLf
    'Head
    s = s & "public void " & ProcName & TableName & "(" & GetCSharpDataType(oTable.Columns(Key).DataType) & " " & Key & ")" & vbCrLf
    s = s & "{" & vbCrLf
    s = s & vbTab & "// Create Instance of Connection and Command Object" & vbCrLf
    s = s & vbTab & "SqlConnection myConnection = PortalSettings.SqlConnectionString;" & vbCrLf
    s = s & vbTab & "SqlCommand myCommand = new SqlCommand(""" & ProcName & TableName & """, myConnection);" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Mark the Command as a SPROC" & vbCrLf
    s = s & vbTab & "myCommand.CommandType = CommandType.StoredProcedure;" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Add Parameters to SPROC" & vbCrLf
    s = s & GetCSParamDef(oTable.Columns(Key))
    s = s & vbCrLf
    s = s & vbTab & "// Execute the command" & vbCrLf
    s = s & vbTab & "myConnection.Open();" & vbCrLf
    s = s & vbTab & "myCommand.ExecuteNonQuery();" & vbCrLf
    s = s & vbTab & "myConnection.Close();" & vbCrLf
    s = s & "}" & vbCrLf
    
    GetCSharpDelete = s
End Function

Function GetCSharpAdd(oTable As SQLDMO.Table) As String
    Dim s As String
    Dim i As Integer
    Dim TableName As String
    Dim ProcName As String
    Dim col As SQLDMO.Column
    Dim Key As String
    Dim ParameterKey As String
    
    Key = GetIdentityKey(oTable)
    ParameterKey = "@" & Key
    
    Call GetTableProcNames(oTable.name, "Add", TableName, ProcName)
    
    'Comment
    s = s & GetCSXMLDoc(ProcName & TableName)
    s = s & "/// <param name=""" & Key & """>" & Key & "</param>" & vbCrLf
    s = s & "/// <returns>The newly created ID</returns>" & vbCrLf
    'Head
    s = s & "public " & GetCSharpDataType(oTable.Columns(Key).DataType) & " " & ProcName & TableName & "("
    i = 1
    For Each col In oTable.Columns
        s = s & GetCSharpDataType(col.DataType) & " " & col.name
        If i < oTable.Columns.Count Then
            s = s & ", "
            i = i + 1
        End If
    Next
    s = s & ")" & vbCrLf
    s = s & "{" & vbCrLf
    s = s & vbTab & "// Create Instance of Connection and Command Object" & vbCrLf
    s = s & vbTab & "SqlConnection myConnection = PortalSettings.SqlConnectionString;" & vbCrLf
    s = s & vbTab & "SqlCommand myCommand = new SqlCommand(""" & ProcName & TableName & """, myConnection);" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Mark the Command as a SPROC" & vbCrLf
    s = s & vbTab & "myCommand.CommandType = CommandType.StoredProcedure;" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Add Parameters to SPROC" & vbCrLf
    
    s = s & GetCSParamDef(oTable.Columns(Key), True) & vbCrLf
   
    For Each col In oTable.Columns
        If Not col.Identity Then
            s = s & GetCSParamDef(col) & vbCrLf
        End If
    Next

    s = s & vbCrLf
    s = s & vbTab & "// Open the database connection and execute the command" & vbCrLf
    s = s & vbTab & "myConnection.Open();" & vbCrLf
    s = s & vbTab & "myCommand.ExecuteNonQuery();" & vbCrLf
    s = s & vbTab & "myConnection.Close();" & vbCrLf
    s = s & vbCrLf
    
    s = s & vbTab & "// Return the newly created ID" & vbCrLf
    
    
    If (oTable.Columns(Key).IsRowGuidCol) Then
        s = s & vbTab & "return new Guid(parameter" + Key + ".Value.ToString());" & vbCrLf
    Else
        s = s & vbTab & "return (int)parameter" + Key + ".Value;" & vbCrLf
    End If
    
    s = s & "}" & vbCrLf
    
    GetCSharpAdd = s
End Function

Function GetCSharpUpdate(oTable As SQLDMO.Table) As String
    Dim s As String
    Dim i As Integer
    Dim TableName As String
    Dim ProcName As String
    Dim col As SQLDMO.Column
    Dim Key As String
    Dim ParameterKey As String
    
    Key = GetIdentityKey(oTable)
    ParameterKey = "@" & Key
    
    Call GetTableProcNames(oTable.name, "Update", TableName, ProcName)
    
    'Comment
    s = s & GetCSXMLDoc(ProcName & TableName)
    s = s & "/// <param name=""" & Key & """>" & Key & "</param>" & vbCrLf
    s = s & "/// <returns>Void</returns>" & vbCrLf
    'Head
    s = s & "public void " & ProcName & TableName & "("
    i = 1
    For Each col In oTable.Columns
        s = s & GetCSharpDataType(col.DataType) & " " & col.name
        If i < oTable.Columns.Count Then
            s = s & ", "
            i = i + 1
        End If
    Next
    s = s & ")" & vbCrLf
    s = s & "{" & vbCrLf
    s = s & vbTab & "// Create Instance of Connection and Command Object" & vbCrLf
    s = s & vbTab & "SqlConnection myConnection = PortalSettings.SqlConnectionString;" & vbCrLf
    s = s & vbTab & "SqlCommand myCommand = new SqlCommand(""" & ProcName & TableName & """, myConnection);" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Mark the Command as a SPROC" & vbCrLf
    s = s & vbTab & "myCommand.CommandType = CommandType.StoredProcedure;" & vbCrLf
    s = s & vbCrLf
    s = s & vbTab & "// Update Parameters to SPROC" & vbCrLf
    
    For Each col In oTable.Columns
        s = s & GetCSParamDef(col) & vbCrLf
    Next

    s = s & vbCrLf
    s = s & vbTab & "// Execute the command" & vbCrLf
    s = s & vbTab & "myConnection.Open();" & vbCrLf
    s = s & vbTab & "myCommand.ExecuteNonQuery();" & vbCrLf
    s = s & vbTab & "myConnection.Close();" & vbCrLf
    s = s & "}" & vbCrLf
    
    GetCSharpUpdate = s
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -