Introduction
Imports System.Data.SqlClient
Imports System.Web.Mail
Imports System.IO
Imports Record.Key
Imports Constants.Database
Imports System.Data
Imports Microsoft.VisualBasic
Public Class commonFunctions
Inherits System.Web.UI.Page
#Region "variables"
Dim Sql_Con As New SqlConnection
Dim Sql As New SqlCommand
Dim sql_q As SqlCommand
Dim sql_chk As String
Dim dr As SqlDataReader
Dim adap As SqlDataAdapter
Dim i As Integer
Dim j As Integer
Dim ds As New DataSet
Public user_key As String
Public dating_key As String
Dim o_Key As New record.Key
Dim s_sql As String
Dim counter As Integer
Dim var1, var2
Dim match_date As DateTime
Dim listitem As ListItem
Dim strSql, NewFileName, strName, strMail As String
Dim intStartIndex, intEndIndex, intAutoId As Integer
Dim intAutoNumber, intIndex, intCount, intPos As Integer
#End Region
'*************************************************************************************************
'************To fill dropdown of numeric no. like year etc by giving some parameters**************
'*************************************************************************************************
Public Sub ddl_insert(ByRef ddlname As Object, ByRef value1 As Integer, ByRef value2 As Integer)
ddlname.Items.Clear()
ddlname.Items.Insert(0, "Select")
i = 1
For j = value1 To value2
ddlname.items.insert(i, j)
i = i + 1
Next
' ddlname.DataBind()
End Sub
'*************************************************************************************************
'******************To fill dropdown from database values by giving some parameters****************
'*************************************************************************************************
Public Sub ddl_fill(ByRef ddlname As Object, ByRef storedprocedurename As String, Optional ByRef parent As String = "")
Try
ddlname.Items.Clear()
Dim ds As DataSet = New DataSet
Sql_Con.ConnectionString = c_Sql_Connection
Sql_Con.Open()
With Sql
.Connection = Sql_Con
.Parameters.Clear()
.CommandText = storedprocedurename
.CommandType = CommandType.StoredProcedure
If parent <> "" Then
.Parameters.Add("@parent", SqlDbType.Int).Value = CInt(parent)
End If
End With
adap = New SqlDataAdapter(Sql)
adap.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
ddlname.DataSource = ds
ddlname.DataTextField = Convert.ToString(ds.Tables(0).Columns.Item(1))
ddlname.DataValueField = Convert.ToString(ds.Tables(0).Columns.Item(0))
ddlname.DataBind()
End If
listitem = New ListItem("Select", "0")
ddlname.Items.Insert(0, listitem)
adap.Dispose()
ds.Dispose()
Sql.Dispose()
Sql_Con.Dispose()
Catch ex As Exception
ds.Dispose()
Sql.Dispose()
Sql_Con.Dispose()
End Try
End Sub
Public Sub updateLastLoginDate(ByRef userId As String)
Try
Sql_Con.ConnectionString = c_Sql_Connection
Sql_Con.Open()
With Sql
.Connection = Sql_Con
.Parameters.Clear()
.CommandText = "tb_user_login_last_login_update"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@user_id", SqlDbType.VarChar, 50).Value = Convert.ToString(userId)
.ExecuteNonQuery()
End With
Sql.Dispose()
Sql_Con.Dispose()
Catch ex As Exception
Sql.Dispose()
Sql_Con.Dispose()
End Try
End Sub
'*************************************************************************************************
'***To upload the image in a given particular folder here I have used "uploads" as a folder name**
'*************************************************************************************************
Public Sub SaveAttachment(ByVal CategoryName As String, ByVal ImgControl As Object, ByVal lblName As Object)
Try
intStartIndex = ImgControl.PostedFile.FileName.IndexOf(".", 0) + 1
intEndIndex = ImgControl.PostedFile.FileName.Length
NewFileName = NewFileName & "." & ImgControl.PostedFile.FileName.Substring(intStartIndex, intEndIndex - intStartIndex)
Dim fn As String = System.IO.Path.GetFileName(ImgControl.PostedFile.FileName)
fn = CategoryName & "-" & fn
Dim SaveLocation As String = Server.MapPath("")
SaveLocation = SaveLocation.Substring(0, SaveLocation.Length - 6) & "\uploads\" & fn
ImgControl.PostedFile.SaveAs(SaveLocation)
NewFileName = fn
lblName.Visible = True
Catch ex As Exception
'txtErrMsg.Value = ex.Message
End Try
End Sub
'*************************************************************************************************
'********To search that whether the text you are entering is already in the table or not.*********
'*************************************************************************************************
Function search(ByRef obj_control As Object, ByRef StoredProceduerName As String, ByVal lblName As Object)
Try
' ddl_company_cat.Items.Clear()
Dim ds As DataSet = New DataSet
Sql_Con.ConnectionString = c_Sql_Connection
Sql_Con.Open()
With Sql
.Connection = Sql_Con
.Parameters.Clear()
.CommandText = StoredProceduerName
.CommandType = CommandType.StoredProcedure
End With
adap = New SqlDataAdapter(Sql)
adap.Fill(ds)
'dr = Sql.ExecuteReader
Dim i As Integer
i = 0
While ds.Tables(0).Rows.Count > i
If obj_control.text = ds.Tables(0).Rows(i)(1) Then
lblName.Visible = True
ds.Dispose()
Sql.Dispose()
Sql_Con.Dispose()
Return True
End If
i = i + 1
End While
ds.Dispose()
Sql.Dispose()
Sql_Con.Dispose()
Return False
Catch ex As Exception
Sql.Dispose()
Sql_Con.Dispose()
Return False
End Try
Return False
End Function
End Class