控件绑定
Imports System.Data.SqlClient
Imports System.Configuration
Module MM_MB
'勾选DataGrid中指定列中的CheckBox
Public Sub SelectDataGridItem(ByVal Dg As DataGrid, ByVal ColNum As Int16, ByVal CkbID As String, ByVal SelectMode As Int16)
Dim ckb As CheckBox
Dim i As Int16
If Dg Is Nothing Then
Exit Sub
End If
If Dg.Columns.Count - 1 < ColNum Then
Exit Sub
End If
For i = 0 To Dg.Items.Count - 1
ckb = CType(Dg.Items(i).Cells(ColNum).FindControl(CkbID), CheckBox)
If Not ckb Is Nothing Then
Select Case SelectMode
Case 0
ckb.Checked = False
Case 1
ckb.Checked = True
Case 2
ckb.Checked = Not ckb.Checked
End Select
End If
Next
End Sub
'''****************************************************************************
''' 绑定dpdnlst
'''****************************************************************************
' Dim str As String
' str = "select distinct VIP_GROUP_NAME,VIP_GROUP_ID from " & ModeName & ".dim_vip_group_query"
' Init_Dpdnlst(DBConnStr, Me.dpdnlst_HuiYuanZu, str, "VIP_GROUP_ID", "vip_group_name")
'Public Sub Init_Dpdnlst(ByVal dd As DropDownList, ByVal SQL As String) ' If Conn.myconn1.State = ConnectionState.Open Then
' myconn1.Close()
' End If
' dd.Items.Clear()
' dd.Items.Add("请选择")
' ''连接数据库
' myconn1.Open()
' mycomm.Parameters.Clear()
' mycomm = New SqlCommand(SQL, myconn4)
' Dim Reader As SqlDataReader '= New SqlDataReader
' Reader = mycomm.ExecuteReader
' While Reader.Read()
' Dim item As New ListItem
' If Not IsDBNull(Reader.GetValue(0)) Then
' If Trim(Reader.GetValue(0)) <> "" Then
' item.Value = Reader.GetValue(0)
' Else
' item.Value = ""
' End If
' Else
' item.Value = ""
' End If
' If Not IsDBNull(Reader.GetValue(1)) Then
' If Trim(Reader.GetValue(1)) <> "" Then
' item.Text = Reader.GetValue(1)
' Else
' item.Text = ""
' End If
' Else
' item.Text = ""
' End If
' dd.Items.Add(item)
' End While
' Reader.Close()
' Reader = Nothing
'End Sub
'绑定部门
Public Sub dr1bind(ByVal dr As DropDownList)
Try
myconn1.Open() '打开数据库
mysql = " SELECT DISTINCT * FROM Depart ORDER BY DeptID "
mycomm = New SqlCommand(mysql, myconn1)
' mycomm.Parameters.Add("@DataSort", "G")
MyDr = mycomm.ExecuteReader
dr.Items.Clear()
dr.Items.Add("请选择")
If MyDr.HasRows Then
Do While MyDr.Read()
Dim item As ListItem = New ListItem
If Not IsDBNull(MyDr.GetValue(0)) Then
If Trim(MyDr.GetValue(0)) <> "" Then
item.Value = MyDr.GetValue(0)
Else
item.Value = ""
End If
Else
item.Value = ""
End If
If Not IsDBNull(MyDr.GetValue(1)) Then
If Trim(MyDr.GetValue(1)) <> "" Then
item.Text = MyDr.GetValue(1)
Else
item.Text = ""
End If
Else
item.Text = ""
End If
dr.Items.Add(item)
Loop
End If
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
Catch ex As Exception
'Me.Label1.Text = "出错了:<br>d1在读取会议室时出现异常,数据读取失败!<br>原因事:" + ex.Message
Exit Sub
End Try
End Sub
'绑定员工
Public Sub dr3bind(ByVal dr2 As String, ByVal dr As DropDownList)
Try
myconn1.Open() '打开数据库
mysql = " SELECT DISTINCT EID, Name FROM Employee "
If dr2.Trim = "" Then
mysql = mysql + " ORDER BY EID "
mycomm = New SqlCommand(mysql, myconn1)
Else
mysql = mysql + " WHERE (DeptID =@DeptID) ORDER BY EID "
mycomm = New SqlCommand(mysql, myconn1)
mycomm.Parameters.Add("@DeptID", dr2.Trim)
End If
MyDr = mycomm.ExecuteReader
dr.Items.Clear()
dr.Items.Add("请选择")
If MyDr.HasRows Then
Do While MyDr.Read()
Dim item As ListItem = New ListItem
If Not IsDBNull(MyDr.GetValue(0)) Then
If Trim(MyDr.GetValue(0)) <> "" Then
item.Value = MyDr.GetValue(0)
Else
item.Value = ""
End If
Else
item.Value = ""
End If
If Not IsDBNull(MyDr.GetValue(1)) Then
If Trim(MyDr.GetValue(1)) <> "" Then
item.Text = MyDr.GetValue(1)
Else
item.Text = ""
End If
Else
item.Text = ""
End If
dr.Items.Add(item)
Loop
End If
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
Catch ex As Exception
'Me.Label1.Text = "出错了:<br>d1在读取会议室时出现异常,数据读取失败!<br>原因事:" + ex.Message
Exit Sub
End Try
If Conn.myconn1.State = ConnectionState.Open Then
myconn1.Close()
End If
End Sub
'绑定身份
'绑定级别
'Public Sub drjbbind(ByVal dr As DropDownList, ByVal lb As String)
' Try
' myconn1.Open() '打开数据库
' mysql = " SELECT DISTINCT BDCode, BDName FROM BasicData WHERE (DataSort =@DataSort) ORDER BY BDCode "
' mycomm = New SqlCommand(mysql, myconn1)
' mycomm.Parameters.Add("@DataSort", lb.Trim)
' MyDr = mycomm.ExecuteReader
' dr.Items.Clear()
' dr.Items.Add("请选择")
' If MyDr.HasRows Then
' Do While MyDr.Read()
' Dim item As ListItem = New ListItem
' If Not IsDBNull(MyDr.GetValue(0)) Then
' If Trim(MyDr.GetValue(0)) <> "" Then
' item.Value = MyDr.GetValue(0)
' Else
' item.Value = ""
' End If
' Else
' item.Value = ""
' End If
' If Not IsDBNull(MyDr.GetValue(1)) Then
' If Trim(MyDr.GetValue(1)) <> "" Then
' item.Text = MyDr.GetValue(1)
' Else
' item.Text = ""
' End If
' Else
' item.Text = ""
' End If
' dr.Items.Add(item)
' Loop
' End If
' MyDr.Close()
' myconn1.Close()
' mycomm.Parameters.Clear()
' Catch ex As Exception
' 'Me.Label1.Text = "出错了:<br>d1在读取会议室时出现异常,数据读取失败!<br>原因事:" + ex.Message
' Exit Sub
' End Try
'End Sub
Public Sub DrBind(ByVal dr As DropDownList, ByVal lb As String)
Try
myconn1.Open() '打开数据库
mysql = " SELECT DISTINCT BDCode, BDName FROM BasicData WHERE (DataSort =@DataSort) ORDER BY BDCode "
mycomm = New SqlCommand(mysql, myconn1)
mycomm.Parameters.Add("@DataSort", lb.Trim)
MyDr = mycomm.ExecuteReader
dr.Items.Clear()
dr.Items.Add("请选择")
If MyDr.HasRows Then
Do While MyDr.Read()
Dim item As ListItem = New ListItem
If Not IsDBNull(MyDr.GetValue(0)) Then
If Trim(MyDr.GetValue(0)) <> "" Then
item.Value = MyDr.GetValue(0)
Else
item.Value = ""
End If
Else
item.Value = ""
End If
If Not IsDBNull(MyDr.GetValue(1)) Then
If Trim(MyDr.GetValue(1)) <> "" Then
item.Text = MyDr.GetValue(1)
Else
item.Text = ""
End If
Else
item.Text = ""
End If
dr.Items.Add(item)
Loop
End If
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
Catch ex As Exception
'Me.Label1.Text = "出错了:<br>d1在读取会议室时出现异常,数据读取失败!<br>原因事:" + ex.Message
Exit Sub
End Try
End Sub
'找到身份
Public Function sfBind(ByVal lb As String, ByVal bh As String) As String
If Conn.myconn1.State = ConnectionState.Open Then
myconn1.Close()
End If
Dim sf As String = ""
myconn1.Open()
mysql = "SELECT DISTINCT BDCode, BDName FROM BasicData WHERE (DataSort =@DataSort) AND (BDCode =@BDCode)"
mycomm = New SqlCommand(mysql, myconn1)
mycomm.Parameters.Add("@DataSort", lb.Trim)
mycomm.Parameters.Add("@BDCode", bh.Trim)
MyDr = mycomm.ExecuteReader
If MyDr.HasRows Then '存在更新
MyDr.Read()
If Not IsDBNull(MyDr.GetValue(1)) Then
sf = MyDr.GetString(1)
End If
End If
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
sfBind = sf.Trim
End Function
'找到签名图片路径
Public Function TP(ByVal bh As String) As String
If Conn.myconn1.State = ConnectionState.Open Then
myconn1.Close()
End If
mysql = "SELECT PicName FROM Sign WHERE (ECode =@ECode) "
mycomm = New SqlCommand(mysql, myconn1)
mycomm.Parameters.Add("@ECode", bh.Trim)
Dim epicn As String = ""
myconn1.Open()
MyDr = mycomm.ExecuteReader
If MyDr.HasRows Then '存在更新
MyDr.Read()
If Not IsDBNull(MyDr.GetValue(0)) Then
If MyDr.GetValue(0) <> "" Then
epicn = MyDr.GetValue(0)
End If
End If
End If
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
Return epicn
End Function
'权限的判定
Public Function QX(ByVal bh As String) As String
If Conn.myconn1.State = ConnectionState.Open Then
myconn1.Close()
End If
Dim Ucode As String = ""
mysql = "SELECT UPCode FROM Employee WHERE (EID =@EID) "
mycomm = New SqlCommand(mysql, myconn1)
mycomm.Parameters.Add("@EID", bh.Trim)
myconn1.Open()
MyDr = mycomm.ExecuteReader
If MyDr.HasRows Then '存在更新
MyDr.Read()
If Not IsDBNull(MyDr.GetValue(0)) Then
If MyDr.GetValue(0) <> "" Then
Ucode = MyDr.GetValue(0)
End If
End If
End If
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
Return Ucode
End Function
'检查密码
Public Function spass(ByVal shr As String, ByVal mm As String) As String
If Conn.myconn1.State = ConnectionState.Open Then
myconn1.Close()
End If
Dim bz As String = ""
mysql = "SELECT SPass FROM Sign WHERE (ECode =@ECode) AND (PState = '启用')"
mycomm = New SqlCommand(mysql, myconn1)
mycomm.Parameters.Add("@ECode", shr.Trim) '
Try
myconn1.Open()
MyDr = mycomm.ExecuteReader
If MyDr.HasRows Then
MyDr.Read()
If Not IsDBNull(MyDr.GetValue(0)) Then
If Trim(MyDr.GetValue(0)) <> "" Then
If MyDr.GetString(0).Trim = MD5.Encrypt(mm.Trim, 32) Then
bz = "A"
MyDr.Close()
myconn1.Close()
Else
bz = "B"
' Page.RegisterStartupScript("用户登录", "<script>alert('" + "您输入的签名密码有误,请重新输入!" + "');</script>")
Exit Try
End If
End If
End If
Else
bz = "C"
'Page.RegisterStartupScript("用户登录", "<script>alert('" + "您还没有上传签名图片或者是已经禁用,请联系管理员!" + "');</script>")
MyDr.Close()
myconn1.Close()
mycomm.Parameters.Clear()
Exit Try
End If
Catch ex As Exception
bz = ex.Message
End Try
Return bz
End Function
End Module