| Current Path : G:/PleskVhosts/mpcdp.in/cmamp.mpcdp.in/cdpp3/App_Code/Utiles/ |
Windows NT SG2NWVPWEB022 10.0 build 17763 (Windows Server 2016) i586 |
| Current File : G:/PleskVhosts/mpcdp.in/cmamp.mpcdp.in/cdpp3/App_Code/Utiles/General.vb |
'Imports Microsoft.VisualBasic
'Public Class General
'End Class
Imports System.Collections.Generic
Imports System.Web
Imports System.Drawing
Imports System.IO
Imports System.Data
Imports System.Drawing.Drawing2D
Imports System.Data.SqlClient
''' <summary>
''' Summary description for General
''' </summary>
Public Class General
'
' TODO: Add constructor logic here
'
Public Sub New()
End Sub
Public Shared ReadOnly Property appPath() As String
Get
#If RELEASE Then
' for online web server environment
Return "http://ULBWEB.com/"
#Elif DEBUG Then
Return "http://localhost/ULBWEB/"
#Else
#End If
Return "http://ULBWEB/ULBWEB/"
End Get
End Property
' Public Shared ReadOnly Property ApplicationPath() As String
' Get
'Return HttpContext.Current.Request.ApplicationPath & (If(HttpContext.Current.Request.ApplicationPath.EndsWith("/"), String.Empty, "/"))
' End Get
' End Property
Public Shared Function GetAppSetting(ByVal name As String) As String
Dim Result As String = String.Empty
If HttpContext.Current.Cache("appSetting_" & name) Is Nothing Then
Dim b As [Byte]() = Convert.FromBase64String(System.Configuration.ConfigurationManager.AppSettings(name))
Result = System.Text.ASCIIEncoding.ASCII.GetString(b)
HttpContext.Current.Cache.Insert("appSetting_" & name, Result)
Else
Result = HttpContext.Current.Cache("appSetting_" & name).ToString()
End If
Return Result
End Function
Public Shared Function GetAdminID() As String
Dim Result As String = ""
Dim cookieMember As HttpCookie = HttpContext.Current.Request.Cookies("admin")
If cookieMember IsNot Nothing Then
Result = cookieMember.Values("adminID")
End If
Return Result
End Function
'Get Random Number
Public Shared Function GetRandomNumber(ByVal minValue As Integer, ByVal maxValue As Integer) As Integer
Dim RandomNumberGenerator As Random
RandomNumberGenerator = New Random(CInt(DateTime.Now.Ticks))
Return RandomNumberGenerator.[Next](minValue, maxValue)
End Function
Public Shared Function GetSubString(ByVal str As String, ByVal start As Integer, ByVal [end] As Integer) As String
Dim Result As String = String.Empty
If str <> "" Then
str = str.Replace("!#$", "%")
If str.Length > (start + [end]) Then
Result = str.Substring(start, [end]) & "..."
Else
Result = str
End If
End If
Return Result
End Function
Public Shared Function GetReplace(ByVal data As String) As String
Dim Result As String = String.Empty
data = data.Replace("!#$", "%")
Result = data
Return Result
End Function
' To generalize substring function to use inside Controls (ie. gridview, list on Run time)
Public Shared Function GetSubStringNew(ByVal str As String, ByVal start As Integer, ByVal [end] As Integer) As String
Dim Result As String = String.Empty
If str <> "" Then
If str.Length > (start + [end]) Then
Result = str.Substring(start, [end]) & "..."
Else
Dim val As Boolean = System.Text.RegularExpressions.Regex.IsMatch(str, "\d")
If val = True Then
Dim id As Integer = Convert.ToInt32(str)
Result = loadSchool(id)
Else
Result = str
End If
End If
End If
Return Result
End Function
Private Shared Function loadSchool(ByVal paraId As Integer) As String
Dim SchoolName As String = String.Empty
Dim dsList As New DataSet()
Command.CreateSqlConnection()
Dim da As New SqlDataAdapter("SELECT ItemDesc FROM Lists WHERE ItemID = " & paraId & " and Name='School'", Command.CreateSqlConnection())
da.Fill(dsList, "List")
Dim myDataTable As DataTable = dsList.Tables(0)
For Each dRow As DataRow In myDataTable.Rows
SchoolName = dRow("ItemDesc").ToString()
Next
da.Dispose()
myDataTable.Dispose()
Return SchoolName
End Function
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
End Class