Wednesday, June 15, 2011

dbconn

Imports System.Data.Odbc
Imports System.Data
Imports System.IO

Public Class dbconn
    Public gs_ConnDB As OdbcConnection
    Public objCnf As ConfigurationManager
    Dim objOdbcDataReader As OdbcDataReader
    Dim lsobjDR As OdbcDataReader
    Public trans As OdbcTransaction

    Public Sub OpenConn()
        gs_ConnDB = New OdbcConnection(ConfigurationManager.AppSettings("ConnectionString").ToString)
        If gs_ConnDB.State = ConnectionState.Closed Then
            gs_ConnDB.Open()
        End If
    End Sub
    Public Sub OpenConnRCS()
        gs_ConnDB = New OdbcConnection(ConfigurationManager.AppSettings("ConnectionStringRCS").ToString)
        If gs_ConnDB.State = ConnectionState.Closed Then
            gs_ConnDB.Open()
        End If
    End Sub
    Public Function BeginTransaction()
        trans = gs_ConnDB.BeginTransaction
        Return trans
    End Function
    Public Sub CommitTransaction()
        trans.Commit()
    End Sub
    Public Sub RollBackTransaction()
        trans.Rollback()
    End Sub
    Public Function GetDataReader(ByVal SQL As String) As OdbcDataReader
        Dim cmdQuery As New OdbcCommand
        'Dim lsobjDR As OdbcDataReader
        cmdQuery.Connection = gs_ConnDB
        cmdQuery.CommandText = SQL
        cmdQuery.CommandType = CommandType.Text
        lsobjDR = cmdQuery.ExecuteReader
        Return lsobjDR
    End Function
    Public Function GetDataSet(ByVal SQL As String, ByVal tblName As String) As DataSet
        'This function will Retrieve Data and Return as Dataset together with table name
        Dim lobjDataAdapter As New OdbcDataAdapter(SQL, gs_ConnDB)
        Dim lobjDataSet As New DataSet
        lobjDataAdapter.Fill(lobjDataSet, tblName)
        Return lobjDataSet
    End Function

    Public Function ExecuteNonQuerySQL(ByVal SQL As String) As Integer
        Dim cmdQuery As New OdbcCommand
        Dim mnResult As Integer
        cmdQuery.Connection = gs_ConnDB
        cmdQuery.CommandText = SQL
        cmdQuery.CommandType = CommandType.Text
        Try
            mnResult = cmdQuery.ExecuteNonQuery
            mnResult = 1
        Catch ex As OdbcException
            mnResult = 0
        End Try
        cmdQuery.Dispose()
        Return mnResult
    End Function

    Public Function ExecuteNonQuerySP(ByVal pSPName As String, ByVal pVal As String) As Integer
        Dim cmdQuery As New OdbcCommand
        Dim parmReturnValue As OdbcParameter
        Dim arrValue As String()
        Dim lstValue As String
        Dim arrNameValue As String()
        Dim mnResult As Integer

        arrValue = Split(pVal, ",")

        cmdQuery = New OdbcCommand(pSPName, gs_ConnDB)
        cmdQuery.CommandType = CommandType.StoredProcedure

        For Each lstValue In arrValue
            arrNameValue = Split(lstValue, "|")
            cmdQuery.Parameters.AddWithValue("@" & arrNameValue(0), arrNameValue(1))
        Next

        parmReturnValue = cmdQuery.Parameters.AddWithValue("ReturnValue", SqlDbType.Int)
        parmReturnValue.Direction = ParameterDirection.ReturnValue

        cmdQuery.ExecuteNonQuery()
        mnResult = cmdQuery.Parameters("ReturnValue").Value

        cmdQuery.Dispose()
        Return mnResult
    End Function
    Public Sub CloseConn()
        gs_ConnDB.Close()
    End Sub
    Public Sub popdata(ByVal sql As String, ByVal TableName As String, ByVal Grid As DataGrid, ByVal lblErrMsg As Label)
        Dim ds_tuser As New DataSet
        Dim objcmnfunctions As New cmnfunctions
        ds_tuser = GetDataSet(sql, TableName)
        If ds_tuser.Tables(TableName).Rows.Count > 0 Then
            Grid.Visible = True
            Grid.DataSource = ds_tuser
            Grid.DataBind()
        Else
            Grid.Visible = False
            lblErrMsg.Text = objcmnfunctions.GetErrMsg("ET_010")
        End If
        ds_tuser.Dispose()
    End Sub
    Public Function GetExecuteScalar(ByVal SQL As String) As String
        GetExecuteScalar = ""
        Dim lobjCommand As New OdbcCommand
        Try
            lobjCommand.Connection = gs_ConnDB
            lobjCommand.CommandText = SQL
            lobjCommand.CommandType = CommandType.Text
            GetExecuteScalar = lobjCommand.ExecuteScalar
            Return GetExecuteScalar
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        lobjCommand.Dispose()
        lobjCommand = Nothing
    End Function
End Class

sql conn

Imports System.Data.Odbc
Imports System.IO
Imports System.Web

Public Class cmnfunctions
    Dim objdbconn As New dbconn
    Dim objOdbcDataReader As OdbcDataReader
    Dim msSQL As String
    Dim mnResult As Integer

    Public Const DEFAULT_OPTION_ALL = "ALL"
    Public Const DEFAULT_OPTION = "-- Select One --"
    Public Const DEFAULT_OPTION_SHORT = "--"
    Public Const DEFAULT_VALUE = "-1"
    Public Const DEFAULT_ZERO = "0"
    Public Const DEFAULT_EMPTY_STRING = ""

  
    Dim mspassword_suspend As String
    Dim msEncryptedPassword As String
    Dim lnChangeDuration As Integer

    Dim lstLeftDate As String
    Dim mstemp As String()
    Dim msDate As String

    Dim lsTempGid As String
    Dim mserrormessage As String

    Public gsUser_GID As String
    Public gsUser As String
   
    Public Function InitializeTable(ByVal colNames As ArrayList, ByRef xTable As DataTable) As String

        xTable = New DataTable("ddlMultiColumn")

        For iCnt As Integer = 0 To (colNames.Count - 1)
            xTable.Columns.Add(CStr(colNames.Item(iCnt)), Type.GetType("System.String"))
        Next

        Return xTable.TableName

    End Function

    Public Function GetErrMsg(ByVal ErrMsgCode As String) As String
        objdbconn.OpenConn()
        msSQL = "select error_gid,error_code,error_message,error_type from " & _
                " adm_mst_terror where error_code = '" & ErrMsgCode & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = True Then
            While objOdbcDataReader.Read
                mserrormessage = objOdbcDataReader.Item("error_message")
            End While
        Else
            mserrormessage = "General Error Occurred"
        End If
        Return mserrormessage
        objOdbcDataReader.Close()
        objdbconn.CloseConn()
    End Function
    Public Function GetRandomString(ByVal length As Integer) As String
        Dim guidResult As String = System.Guid.NewGuid().ToString()
        guidResult = guidResult.Replace("-", String.Empty)
        guidResult = UCase(guidResult)
        If length <= 0 OrElse length > guidResult.Length Then
            Throw New ArgumentException("Length must be between 1 and " & guidResult.Length)
        End If
        Return guidResult.Substring(0, length)
    End Function
    ''//-------------------------------------------------------------------
    ''  Author  : Pavithra
    ''  Date    :
    ''  Purpose : To generate biometric gid
    ''-------------------------------------------------------------------//
    Public Function GetBiometricGID() As String
        Dim lsSeqNo As String
        objdbconn.OpenConn()
        msSQL = "Select max(biometric_gid) as maxgid from hrm_mst_tbiometric"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = True Then
            lsSeqNo = objOdbcDataReader.Item("maxgid").ToString
            If lsSeqNo = "" Then
                lsSeqNo = "1000"
            Else
                lsSeqNo = Val(lsSeqNo) + 1
            End If
        End If
        objOdbcDataReader.Close()
        objdbconn.CloseConn()
        Return lsSeqNo
    End Function


    Public Function getMasterGID(ByVal pModule_Code As String) As String
        Dim lsSeqNo As Integer
        objdbconn.OpenConn()
        msSQL = " select sequence_curval, sequence_format, " & _
                " sequence_code from adm_mst_tsequence " & _
                " where sequence_code = '" & pModule_Code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = True Then
            While objOdbcDataReader.Read
                lsSeqNo = objOdbcDataReader.Item("sequence_curval") + 1
                lsTempGid = pModule_Code & Format(Now(), "yyMMdd") & Format(lsSeqNo, "0000")
            End While
        End If
        objOdbcDataReader.Close()

        msSQL = " update adm_mst_tsequence set " & _
                " sequence_curval = '" & lsSeqNo & "' where " & _
                " sequence_code = '" & pModule_Code & "'"
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
        objdbconn.CloseConn()

        If mnResult = 1 Then
            Return lsTempGid
        Else
            Return "E"
        End If
    End Function
    Public Function getlastGID(ByVal pModule_Code As String) As String
        Dim lsSeqNo As Integer
        objdbconn.OpenConn()
        msSQL = " select sequence_curval, sequence_format, " & _
                " sequence_code from adm_mst_tsequence " & _
                " where sequence_code = '" & pModule_Code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = True Then
            While objOdbcDataReader.Read
                lsSeqNo = objOdbcDataReader.Item("sequence_curval") + 1
                lsTempGid = pModule_Code & Format(Now(), "yyMMdd") & Format(lsSeqNo, "0000")
            End While
        End If
        objOdbcDataReader.Close()
        objdbconn.CloseConn()
        Return lsTempGid
    End Function

    Public Sub getMaxColumnLengths(ByVal colNames As ArrayList, ByVal refTableName As String, ByRef colMaxLengths As ArrayList)

        Dim dr_tdatareader As OdbcDataReader = Nothing

        '' Append query Prefix
        msSQL = "SELECT "

        '' Append Query field sets to get maxlengths
        For iCnt As Integer = 0 To (colNames.Count - 1)
            If (iCnt > 0) Then
                msSQL = msSQL + ", "
            End If
            msSQL = msSQL + "MAX(LENGTH(" + CStr(colNames.Item(iCnt)) + ")) as column" + iCnt.ToString
        Next

        '' Append query suffix tablename
        msSQL = msSQL + " FROM " + refTableName

        ''//------ Fetch the max length of the sepecified columns from database-------->
        objdbconn.OpenConn()

        dr_tdatareader = objdbconn.GetDataReader(msSQL)

        If dr_tdatareader.HasRows Then

            If dr_tdatareader.Read() Then

                For iCnt As Integer = 0 To (colNames.Count - 1)
                    colMaxLengths.Add(CStr(dr_tdatareader.Item("column" + iCnt.ToString)))
                Next

            End If

        End If

        dr_tdatareader.Close()

        objdbconn.CloseConn()
        ''<---------------------------------------------------------------------------//

    End Sub
    ''//-------------------------------------------------------------------
    ''  Author  : Hariharan
    ''  Date    : 16.11.2010
    ''  Purpose : For DropDown Multi Column Purpose
    ''-------------------------------------------------------------------//
    Public Function popMultiColumnDropdown(ByVal keyFieldName As String, ByVal fieldNames As ArrayList, ByVal colMaxLengths As ArrayList, ByRef sqlResults As DataTable) As DataTable

        Dim ddlTable As DataTable
        Dim colNames As New ArrayList

        colNames.AddRange(New String() {"dataTextField", "dataValueField"})

        InitializeTable(colNames, ddlTable)

        '' Iterate through query result table to concatenate columns
        For iCnt As Integer = 0 To (sqlResults.Rows.Count - 1)

            Dim columnString As String = Nothing

            For jCnt As Integer = 0 To colMaxLengths.Count - 1

                If jCnt > 0 Then
                    columnString = columnString + "|"
                End If

                Dim columnValue As String = CStr(sqlResults.Rows(iCnt)(CStr(fieldNames.Item(jCnt))))

                columnString = columnString + String.Format("{0}", concatSpaces(columnValue, CInt(colMaxLengths(jCnt))))

            Next

            ddlTable.Rows.Add(ddlTable.NewRow)

            ddlTable.Rows(ddlTable.Rows.Count - 1)(CStr(colNames.Item(0))) = columnString
            ddlTable.Rows(ddlTable.Rows.Count - 1)(CStr(colNames.Item(1))) = sqlResults.Rows(iCnt)(keyFieldName).ToString

        Next

        Return ddlTable

    End Function
    Public Shared Function concatSpaces(ByVal inputStr As String, ByVal totalLength As Integer) As String
        Dim spaceCount As Integer = totalLength - inputStr.Length
        Dim spaces As String = inputStr
        For i As Integer = 0 To spaceCount - 1
            spaces &= " "
        Next
        Return HttpUtility.HtmlDecode(spaces)
    End Function
    Public Function getCODEGID(ByVal pModule_Code As String) As String
        Dim lsSeqNo As Integer
        objdbconn.OpenConn()
        msSQL = " select sequence_curval, sequence_format, " & _
                " sequence_code from adm_mst_tsequence " & _
                " where sequence_code = '" & pModule_Code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = True Then
            While objOdbcDataReader.Read
                lsSeqNo = objOdbcDataReader.Item("sequence_curval") + 1
                lsTempGid = pModule_Code & Format(lsSeqNo, "0000")
            End While
        End If
        objOdbcDataReader.Close()

        msSQL = " update adm_mst_tsequence set " & _
                " sequence_curval = '" & lsSeqNo & "' where " & _
                " sequence_code = '" & pModule_Code & "'"
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
        objdbconn.CloseConn()

        If mnResult = 1 Then
            Return lsTempGid
        Else
            Return "E"
        End If
    End Function
    Public Function getassetCODEGID(ByVal pModule_Code As String) As String
        Dim lsSeqNo As Integer
        objdbconn.OpenConn()
        msSQL = " select sequence_curval, sequence_format, " & _
                " sequence_code from ams_mst_tassetsequence " & _
                " where sequence_code = '" & pModule_Code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = True Then
            While objOdbcDataReader.Read
                lsSeqNo = objOdbcDataReader.Item("sequence_curval") + 1
                lsTempGid = pModule_Code & Format(lsSeqNo, "0000")
            End While
        End If
        objOdbcDataReader.Close()

        msSQL = " update ams_mst_tassetsequence set " & _
                " sequence_curval = '" & lsSeqNo & "' where " & _
                " sequence_code = '" & pModule_Code & "'"
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
        objdbconn.CloseConn()

        If mnResult = 1 Then
            Return lsTempGid
        Else
            Return "E"
        End If
    End Function
    Public Sub LogForAudit(ByVal strVal As String)
        Try
            Dim sw As StreamWriter = File.AppendText(ConfigurationManager.AppSettings("LOG_FILENAME").ToString)
            sw.WriteLine(Now() & " : " & strVal)
            sw.Close()
        Catch ex As Exception
        End Try
    End Sub
    Public Function getTransGID(ByVal pModule_Code As String, ByVal pTable_Name As String, ByVal pPrimaryKey As String) As String
        Dim lsSeqNo As Integer
        Dim lsTempGid As String

        objdbconn.OpenConn()
        msSQL = " select * from  " & pTable_Name & " where " & pPrimaryKey & " like '%" & Format(Now(), "yyMMdd") & "%'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = False Then
            objOdbcDataReader.Close()
            msSQL = " update adm_mst_tsequence set " & _
                    " sequence_curval = '1' where " & _
                    " sequence_code = '" & pModule_Code & "'"
            mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
            Return pModule_Code & Format(Now(), "yyMMdd") & "0001"
        End If
        objOdbcDataReader.Close()

        msSQL = " select sequence_curval, sequence_format, " & _
                " sequence_code from adm_mst_tsequence " & _
                " where sequence_code = '" & pModule_Code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = True Then
            objOdbcDataReader.Read()
            lsSeqNo = objOdbcDataReader.Item("sequence_curval") + 1
            lsTempGid = pModule_Code & Format(Now(), "yyMMdd") & Format(lsSeqNo, "0000")
            objOdbcDataReader.Close()
        Else
            objOdbcDataReader.Close()
            Return "E"
        End If

        msSQL = " update adm_mst_tsequence set " & _
                " sequence_curval = '" & lsSeqNo & "' where " & _
                " sequence_code = '" & pModule_Code & "'"
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)

        If mnResult = 1 Then
            Return lsTempGid
        Else
            Return "E"
        End If
    End Function

    Protected Friend Function GetDateFormat(ByVal pDate As String) As String
        If Len(pDate) = 0 Then
            Return "0000-00-00"
        End If
        lstLeftDate = Microsoft.VisualBasic.Left(pDate, 3)
        lstLeftDate = Microsoft.VisualBasic.Right(lstLeftDate, 1)
        Select Case lstLeftDate
            Case "-"
                mstemp = Split(pDate, "-")
            Case "/"
                mstemp = Split(pDate, "/")
        End Select

        If mstemp.Length < 3 Then
            Return "E"
        End If

        If Len(mstemp(2)) = 2 Then
            mstemp(2) = "20" & mstemp(2)
        ElseIf Len(mstemp(2)) = 1 Then
            mstemp(2) = "200" & mstemp(2)
        ElseIf Len(mstemp(2)) <> 4 Then
            Return "E"
        End If
        msDate = mstemp(2) & "-" & mstemp(1) & "-" & mstemp(0)
        Return msDate
    End Function
    'Encrypt the password
    Public Function ConvertToAscii(ByVal userText As String) As String
        Dim iIndex As Integer
        Dim lenOfUserString As Integer
        Dim newUserPass As String
        Dim tmp As String
        lenOfUserString = Len(userText)
        newUserPass = ""
        For iIndex = 1 To lenOfUserString
            tmp = Mid(userText, iIndex, 1)
            tmp = Asc(tmp) - lenOfUserString
            newUserPass = newUserPass & IIf(tmp.Length < 3, "0", "") & tmp
        Next
        ConvertToAscii = newUserPass
    End Function
    Public Function ValidatePwd(ByVal pwd As String) As String
        ValidatePwd = ""
        If Len(pwd) < 6 Then
            'ValidatePwd = "LengthError"
            'Exit Function
            Return "ERR_PC006"
        End If
    End Function
    Private Function SearchChar(ByVal SrcStr As String, ByVal SearchStartChar As String, ByVal SearchEndChar As String) As Boolean
        Dim i As Integer, l As Integer
        Dim CharAsc As Integer
        Dim StartCharAsc As Integer
        Dim EndCharAsc As Integer
        l = Len(SrcStr)
        SearchChar = False
        For i = 1 To l
            CharAsc = Asc(Mid(SrcStr, i, 1))
            StartCharAsc = Asc(SearchStartChar)
            EndCharAsc = Asc(SearchEndChar)

            If CharAsc >= StartCharAsc And CharAsc <= EndCharAsc Then
                SearchChar = True
                Exit Function
            End If
        Next i
    End Function

    Private Function SearchStr(ByVal SrcStr As String, ByVal SearchChar As String) As Boolean
        Dim l As Integer
        Const SpecialChar As String = "!#@$+^"

        l = Len(SpecialChar)
        SearchStr = False

        Select Case True
            Case CBool(InStr(1, SrcStr, "!")), _
                 CBool(InStr(1, SrcStr, "#")), _
                 CBool(InStr(1, SrcStr, "@")), _
                 CBool(InStr(1, SrcStr, "$")), _
                 CBool(InStr(1, SrcStr, "+")), _
                 CBool(InStr(1, SrcStr, "^"))
                SearchStr = True
        End Select
    End Function

    Public Function QuoteFilter(ByVal txt As String) As String
        QuoteFilter = Trim(Replace(Replace(Replace(txt, "'", "''"), """", """"""), "\", "/"))
    End Function
    Public Function LoginValidate(ByVal PassUserCode As String, ByVal PassPassword As String) As String
        msEncryptedPassword = ConvertToAscii(PassPassword)

        objdbconn.OpenConn()
        msSQL = "select password_suspend from adm_mst_tuser where user_code='" & PassUserCode & "' "
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = False Then
            objOdbcDataReader.Close()
            objdbconn.CloseConn()
            Return "ERR_LG001"
        End If

        While objOdbcDataReader.Read
            mspassword_suspend = objOdbcDataReader.Item("password_suspend") & ""
        End While
        objOdbcDataReader.Close()

        If mspassword_suspend = "Y" Then
            objdbconn.CloseConn()
            Return "ERR_LG002"
        End If

        msSQL = "select user_code, password_changedate, " & _
                " user_password, password_suspend from " & _
                " adm_mst_tuser where " & _
                " user_code='" & PassUserCode & "' and  " & _
                " user_password = '" & msEncryptedPassword & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = False Then
            objOdbcDataReader.Close()
            objdbconn.CloseConn()
            Return "ERR_LG003"
        End If
        objOdbcDataReader.Close()
        objdbconn.CloseConn()
        Return "SUC_LG001"
    End Function

    Public Function ChangePassword(ByVal PassUserCode As String, ByVal PassOldPassword As String, ByVal PassNewPassword As String, ByVal PassConfirmPassword As String) As String
        Dim msEncryptedOldPassword As String
        Dim msEncryptedNewPassword As String

        If Not PassConfirmPassword = PassNewPassword Then
            'ChangePassword = "Confirm Password Mismatch"
            Return "ERR_CP008"
        End If

        msEncryptedOldPassword = ConvertToAscii(PassOldPassword)
        msEncryptedNewPassword = ConvertToAscii(PassNewPassword)

        objdbconn.OpenConn()

        msSQL = " select user_gid from adm_mst_tuser where  " & _
                " user_code = '" & PassUserCode & "' and " & _
                " user_password ='" & msEncryptedOldPassword & "' "
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = False Then
            objOdbcDataReader.Close()
            objdbconn.CloseConn()
            Return "ERR_CP006"
        End If
        objOdbcDataReader.Close()

        msSQL = " select user_gid from adm_mst_tuser where  " & _
                " user_code = '" & PassUserCode & "' and (" & _
                " user_password1 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password2 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password3 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password4 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password5 = '" & msEncryptedNewPassword & "' )"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = True Then
            objOdbcDataReader.Close()
            objdbconn.CloseConn()
            Return "ERR_CP007"
        End If
        objOdbcDataReader.Close()

        msSQL = " update adm_mst_tuser set " & _
                " user_password1 = user_password2, " & _
                " user_password2 = user_password3, " & _
                " user_password3 = user_password4, " & _
                " user_password4 = user_password5, " & _
                " user_password5 = user_password, " & _
                " user_password = '" & msEncryptedNewPassword & "'," & _
                " password_changedate = '" & Format(DateAndTime.Now, "yyyy-MM-dd hh:mm:ss") & "'" & _
                " where user_code='" & PassUserCode & "' "
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
        objdbconn.CloseConn()
        Return "SUC_CP001"
    End Function

    Public Function ResetPassword(ByVal PassUserGID As String, ByVal PassNewPassword As String, ByVal PassConfirmPassword As String)

        Dim msEncryptedNewPassword As String

        If Not PassConfirmPassword = PassNewPassword Then
            'ChangePassword = "Confirm Password Mismatch"
            Return "ERR_CP008"
        End If

        msEncryptedNewPassword = ConvertToAscii(PassNewPassword)

        objdbconn.OpenConn()
        msSQL = " select user_gid from adm_mst_tuser where  " & _
                " user_gid = '" & PassUserGID & "' and (" & _
                " user_password1 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password2 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password3 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password4 = '" & msEncryptedNewPassword & "' OR " & _
                " user_password5 = '" & msEncryptedNewPassword & "' )"

        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = True Then
            objOdbcDataReader.Close()
            objdbconn.CloseConn()
            Return "ERR_CP007"
        End If
        objOdbcDataReader.Close()

        msSQL = " update adm_mst_tuser set" & _
                " user_password1 = user_password2, " & _
                " user_password2 = user_password3, " & _
                " user_password3 = user_password4, " & _
                " user_password4 = user_password5, " & _
                " user_password5 = user_password, " & _
                " user_password = '" & msEncryptedNewPassword & "'," & _
                " password_changedate = '" & Format(DateAndTime.Now, "yyyy-MM-dd hh:mm:ss") & "'" & _
                " where user_gid = '" & PassUserGID & "' "
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
        objdbconn.CloseConn()
        Return "SUC_CP001"
    End Function
  

  
    Public Function getBatchGID(ByVal pModule_Code As String) As String
        Dim lsSeqNo As Integer
        objdbconn.OpenConn()
        msSQL = " select sequence_curval, sequence_format, " & _
                " sequence_code from adm_mst_tsequence " & _
                " where sequence_code = '" & pModule_Code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)

        If objOdbcDataReader.HasRows = True Then
            While objOdbcDataReader.Read
                lsSeqNo = objOdbcDataReader.Item("sequence_curval") + 1
                lsTempGid = pModule_Code & Format(lsSeqNo, "0000")
            End While
        End If
        objOdbcDataReader.Close()

        msSQL = " update adm_mst_tsequence set " & _
                " sequence_curval = '" & lsSeqNo & "' where " & _
                " sequence_code = '" & pModule_Code & "'"
        mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
        objdbconn.CloseConn()

        If mnResult = 1 Then
            Return lsTempGid
        Else
            Return "E"
        End If
    End Function
    Public Shared Function StrToByteArray(ByVal str As String) As Byte()
        'create our encoder
        Dim encoding As New System.Text.ASCIIEncoding()
        'the byte[] containing our string
        Return encoding.GetBytes(str)
    End Function
    Public Shared Function ByteToStringArray(ByVal byteStr As Byte()) As String
        'Create our encoder
        Dim enc As New System.Text.ASCIIEncoding()
        'return our decoded string
        Return enc.GetString(byteStr)
    End Function
    Public Function HttpEncodeFilePath(ByVal ValueToEncode As Object) As String
        'variable to hold our path
        Dim fp As String = TryCast(ValueToEncode, String)
        'variable to olde our byte array
        Dim To64 As String = Convert.ToBase64String(StrToByteArray(fp))
        'return the formatted base64 string
        Return String.Format(To64, HttpUtility.UrlEncode(To64))
    End Function
    Public Function HttpDecodeFilePath(ByVal ValueToDecode As Object) As String
        'Get the value of our filepath and URL Decode it
        Dim fp As String = HttpUtility.UrlDecode(TryCast(ValueToDecode, String))
        'Convert our string back to Base64
        Dim From64 As Byte() = Convert.FromBase64String(fp)
        'return a Base64 string
        Dim Base64 As String = ByteToStringArray(From64)
        Return String.Format(Base64, ByteToStringArray(From64))
    End Function
    Public Function isEmail(ByVal inputEmail As String) As Boolean
        'inputEmail = NulltoString(inputEmail)
        Dim strRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & "\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" & ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
        Dim re As New Regex(strRegex)
        If re.IsMatch(inputEmail) Then
            Return (True)
        Else
            Return (False)
        End If

    End Function
    Public Function Menus(ByVal module_code As String, ByVal usergid As String)
        Dim strStringBuilder1 As New StringBuilder("")
        Dim grouptype, grouptype2 As String
        Dim i As Integer = 0
        objdbconn.OpenConn()
        msSQL = "select * from adm_mst_tmodule where module_code='" & module_code & "'"
        objOdbcDataReader = objdbconn.GetDataReader(msSQL)
        If objOdbcDataReader.HasRows = True Then
            msSQL = " select a.* from adm_mst_tmodule a,adm_mst_tprivilege b,adm_mst_tuser c where a.module_gid_parent='" & objOdbcDataReader.Item("module_gid").ToString & "'" & _
                " and a.module_gid=b.module_gid and c.user_gid='" & usergid & "' and b.usergroup_gid=c.usergroup_gid order by display_order"
            objOdbcDataReader = objdbconn.GetDataReader(msSQL)
            If objOdbcDataReader.HasRows = True Then
                'panelsubmenus.Controls.Add(New LiteralControl(strStringBuilder1.ToString))
                strStringBuilder1.Remove(0, strStringBuilder1.Length)
                strStringBuilder1.Append("
")
                strStringBuilder1.Append("")
                While objOdbcDataReader.Read
                    If i = 0 Then
                        strStringBuilder1.Append("
")
                        strStringBuilder1.Append("")
                    Else
                        If grouptype = objOdbcDataReader.Item("group_type") Then
                            strStringBuilder1.Append("")
                            strStringBuilder1.Append("")
                strStringBuilder1.Append("")
                strStringBuilder1.Append("
" & objOdbcDataReader.Item("module_name") & "
")
                        strStringBuilder1.Append("")
                        strStringBuilder1.Append("
")
                        strStringBuilder1.Append("
")
                            strStringBuilder1.Append("")
                        Else
                            strStringBuilder1.Append("
" & objOdbcDataReader.Item("module_name") & "
")
                            strStringBuilder1.Append("")
                            strStringBuilder1.Append("
")
                            strStringBuilder1.Append("
")
                            strStringBuilder1.Append("")
                            strStringBuilder1.Append("
")
                            strStringBuilder1.Append("")

                        End If
                    End If
                    i = i + 1
                    grouptype = objOdbcDataReader.Item("group_type")
                End While
                strStringBuilder1.Append("
" & objOdbcDataReader.Item("module_name") & "
")
                            strStringBuilder1.Append("")
                            strStringBuilder1.Append("
")
                            strStringBuilder1.Append("
")
                strStringBuilder1.Append("")
                strStringBuilder1.Append("
")
                'panelsubmenus.Controls.Add(New LiteralControl(strStringBuilder1.ToString))
                'strStringBuilder1.Remove(0, strStringBuilder1.Length)
            End If

        End If
        objdbconn.CloseConn()
        Return strStringBuilder1
    End Function
End Class




Friday, August 21, 2009

killer plants






Hi friends this is one of the dangerous plants i have heard about. Scientists have discovered a flesh-eating plant so big that it can swallow and devour a whole rat! This new species is called Nepenthes attenboroughii, it can grow more than 4-foot long.Those plants produce big pitchers which are filled with water and they also secrete nectar that attracts insects and rodents. Once those poor creatures fall in, they cannot escape and end up drowning, and then, the acids and enzymes do their job. Generally, only the bones of the prey remain... Really amazing...

Wednesday, August 19, 2009

after a long time

hi friends,
Nice to see you all after a long long time. I'm back. Do stay in touch and have fun.... have a good day guys....

Thursday, October 30, 2008

Two Two-Tons

Hi friends, today Gautham Gambhir and V.V.S. Laxman made double hundreds in first innings of third test match against Australia. This was the first ever double hundreds hit by two Indians against Aussies. They both stunned the Australians by big partnerships too. Both were aggressive as the game progresses. They made the Indians to dominate the Aussies again. It's a good sign for Indian cricket.

Laxman's knock

Hi friends, today V.V.S. Laxman did a splendid performance and made his second double hundred against Australia. He was unbeaten on 200. Many criticized him for his batting performance. And he has knocked everyone of it. He was aggressive as the game progresses. He has a massive average against the Aussies. He got passed 2000 runs against Australia in test cricket. He is really Very Very Special.

Gambhir first double

Hi friends, today Gautham Gambhir made his first ever double hundred against Australia. He made it with the best wishes from dare devil Sehwag scribbled at bottom of his bat. He stunned everyone by passing century with a six. Gauthy was aggressive as the game progresses. Aussies tried to distract him, but he did it with confidence till the end. He has performed well in twenty twenty cricket and in one day cricket and his passion continues in test cricket too. It's a good sign for Indian cricket.