globals.vb
来自「C#语言制作asp.net网上商店的」· VB 代码 · 共 173 行
VB
173 行
Imports Microsoft.VisualBasic
Imports NetShopForge.Common.Utilities
Imports System.Text
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Data
Imports System
Imports System.Configuration
Imports System.Net
Imports System.Text.RegularExpressions
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Web
Imports System.Threading
Imports Microsoft.VisualBasic.CompilerServices
Imports NetShopForge.Library.User
Imports System.IO
Namespace NetShopForge.Common
Public Module Globals
#Region "---Public Method---"
Public Function CloakText(ByVal PersonalInfo As String) As String
If Not PersonalInfo Is Nothing Then
Dim sb As New StringBuilder
' convert to ASCII character codes
sb.Remove(0, sb.Length)
Dim StringLength As Integer = PersonalInfo.Length - 1
For i As Integer = 0 To StringLength
sb.Append(Asc(PersonalInfo.Substring(i, 1)).ToString)
If i < StringLength Then
sb.Append(",")
End If
Next
' build script block
Dim sbScript As New StringBuilder
sbScript.Append(vbCrLf & "<script language=""javascript"">" & vbCrLf)
sbScript.Append("<!-- " & vbCrLf)
sbScript.Append(" document.write(String.fromCharCode(" & sb.ToString & "))" & vbCrLf)
sbScript.Append("// -->" & vbCrLf)
sbScript.Append("</script>" & vbCrLf)
Return sbScript.ToString
Else : Return Null.NullString
End If
End Function
Public Function GetKeys(ByVal KeyName As String, Optional ByVal Source As String = "") As Integer
Dim NewNum As Integer
Dim sFlage As String = "Flag"
Try
Dim sql As String
Dim time As DateTime = DateAndTime.Now.AddSeconds(1)
Dim db As Database = DatabaseFactory.CreateDatabase()
Do While (StringType.StrCmp(sFlage, "", False) <> 0)
sql = (("Update [nsf_SystemKey] Set [SourceID]='" & Source & "', [LockTime]=GetDate() Where [KeyName]='" & KeyName) & "' AND ((DATEADD(millisecond, 1000, LockTime) <GetDate() ) OR ( SourceID=''))")
Dim j As Integer = db.ExecuteNonQuery(CommandType.Text, sql)
If (j > 0) Then
sFlage = ""
Exit Do
End If
sFlage = "Err"
If (DateTime.Compare(time, DateAndTime.Now) < 0) Then
Return -1
End If
Thread.Sleep(10)
Loop
sql = "Select KeyValue From [nsf_SystemKey] Where [KeyName]='" & KeyName & "' AND SourceID='" & Source & "'"
Dim OldNum As Object = db.ExecuteScalar(CommandType.Text, sql)
Dim num As Integer = (IntegerType.FromObject(OldNum) + 1)
sql = "Update [nsf_SystemKey] Set [KeyValue]=" & StringType.FromInteger(num) & ", [SourceID]='' Where [KeyName]='" & KeyName & "'"
db.ExecuteNonQuery(CommandType.Text, sql)
NewNum = num
Catch exception As Exception
NewNum = -1
End Try
Return NewNum
End Function
Public Function GetCurrentUserInfo() As UserInfo
If (HttpContext.Current Is Nothing) Then
If Not (Thread.CurrentPrincipal.Identity.IsAuthenticated) Then
Return New UserInfo
Else
Dim objUserController As New UserController
Dim objUser As UserInfo
objUser = objUserController.GetUserByUsername(Thread.CurrentPrincipal.Identity.Name)
If Not objUser Is Nothing Then
Return objUser
Else
Return New UserInfo
End If
End If
Else
Dim objUser As UserInfo = CType(HttpContext.Current.Items("UserInfo"), UserInfo)
If Not objUser Is Nothing Then
Return objUser
Else
Return New UserInfo
End If
End If
End Function
Public Function DeleteDir(ByVal aimPath As String) As String
Try
If aimPath.Substring(aimPath.Length - 1) <> Path.DirectorySeparatorChar Then
aimPath += Path.DirectorySeparatorChar
End If
' string[] fileList = Directory.GetFiles(aimPath);
Dim fileList As String() = Directory.GetFileSystemEntries(aimPath)
Dim Files As String
For Each Files In fileList
If Directory.Exists(Files) Then
DeleteDir((aimPath + Path.GetFileName(Files)))
Else
File.Delete((aimPath + Path.GetFileName(Files)))
End If
Next
System.IO.Directory.Delete(aimPath, True)
Return ""
Catch e As Exception
Return e.ToString
End Try
End Function 'DeleteDir
Public Sub UserAuthenticated(ByVal page As Web.UI.Page, ByVal returnURL As String)
If Not page.User.Identity.IsAuthenticated Then
Dim URL As String = String.Format("~/Login.aspx?ReturnUrl={0}", returnURL)
page.Response.Redirect(URL)
End If
End Sub
Public Function GetModeListReader(ByVal modeType As String) As IDataReader
Dim db As Database = DatabaseFactory.CreateDatabase
Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Untitle_GetModuleList")
db.AddInParameter(dbCommand, "@Type", DbType.String, modeType)
Return db.ExecuteReader(dbCommand)
End Function
#End Region
End Module
End Namespace
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?