Private Sub BuidSub(OneSource As String, OneRef As String, OneExt As String, OneSub As String, OneClass As String)
Dim strSourceCode As String = OneSource
Dim objCSharpCodePrivoder As New CSharpCodeProvider()
Dim objVBCodePrivoder As New VBCodeProvider()
Dim OnePara As New CompilerParameters()
For Each OneStr In OneRef.Split(vbCrLf)
If Not OneStr.Trim.Equals(String.Empty) Then
OnePara.ReferencedAssemblies.Add(OneStr.Trim)
End If
Next
OnePara.GenerateInMemory = True
Dim cr As CompilerResults
If OneExt.ToLower = ".cs" Then
cr = objCSharpCodePrivoder.CompileAssemblyFromSource(OnePara, OneSource)
Else
cr = objVBCodePrivoder.CompileAssemblyFromSource(OnePara, OneSource)
End If
If cr.Errors.HasErrors Then
Dim strErrorMsg As String = cr.Errors.Count.ToString() + " Errors:"
For x As Integer = 0 To cr.Errors.Count - 1
strErrorMsg += vbCrLf & "Line: " & cr.Errors(x).Line.ToString() & " - " & cr.Errors(x).ErrorText
Next
MyPage.ShowException(strErrorMsg)
Else
Try
Dim objAssembly As Assembly = cr.CompiledAssembly
Dim FullName As String = "MyERP.{0}"
FullName = String.Format(FullName, OneClass)
Dim objClass As Object = objAssembly.CreateInstance(FullName)
If objClass Is Nothing Then
MyPage.ShowException(GetMessage("LOAD_CLASS_ERROR", MyParameter.LoginLan))
Else
If ChkProperty(objClass, "Owner") Then
objClass.Owner = Me
End If
CallByName(objClass, OneSub, vbMethod)
End If
Catch ex As Exception
MyPage.ShowException(ex)
End Try
End If
End Sub