尝试根据担保权验证信息

时间:2019-10-15 16:28:11

标签: sql vb.net record

根据用户从我拥有的用户权限表中获得的权限,尝试使网页上的某些文本框可见

这是我的存储过程称为

ALTER PROCEDURE [dbo].[uc_OneAPortalUserAccess]
    @intUserID as INT
    ,@intInvoiceShipmentID as INT

AS

BEGIN

SELECT TOP 1
    i.InvoiceShipmentID, p.ProjectID, OneA.UserID, OneA.ViewAccess, OneA.EditAccess, OneA.ApproveAccess

FROM 
    KitUnit ku
    JOIN ProjectAccount pa on pa.ProjectAccountID = ku.ProjectAccountID
    JOIN Project p on p.ProjectID = pa.ProjectID
    JOIN InvoiceShipment i on i.InvoiceShipmentID = ku.InvoiceShipmentID
    JOIN OneAPortalAccess OneA on P.ProjectID = OneA.ProjectID
    JOIN Users U on U.UserID = OneA.UserID
WHERE 
    i.InvoiceShipmentID = @intInvoiceShipmentID
    and OneA.UserID = @intUserID

END

这是我的vb.net代码

Dim blnView As Boolean
Dim blnEdit As Boolean
Dim blnApprove As Boolean
Dim sqlp(1) As SqlParameter

sqlp(0) = DataBase.CreateSQLParam("@intInvoiceShipmentID", SqlDbType.Int, intInvoiceShipmentId)
sqlp(1) = DataBase.CreateSQLParam("@intUserID", SqlDbType.Int, intUserID)

DataBase.ExecuteNonQueryParam( _
       "uc_OneAPortalUserAccess", _
       CommandType.StoredProcedure, _
       sqlp)

'If user has view only access
If blnView = True Then
    btnSaveTop.Visible = False
    btnSaveBottom.Visible = False
    btnApproveBottom.Visible = False
    btnApproveTop.Visible = False
End If

我不知道如何撤回访问字段并显示它们

1 个答案:

答案 0 :(得分:0)

我使用了我更熟悉的模式。将数据库对象保留在本地可使您控制它们是否已关闭和处置。 Using...End Using块会处理这些琐事。

我创建了DataTableConnectionCommand。然后执行DataReader以Load DataTable。 Select语句中显示的值将在DataTable中。

我不喜欢将用户界面代码与数据访问代码混合使用。这个Sub可以是Function,返回一个Approval类或结构的实例。我怀疑您为简洁起见包含了UI代码。

Private Sub OPCode(intInvoiceShipmentId As Integer, intUserID As Integer)
    Dim blnView As Boolean
    Dim blnEdit As Boolean
    Dim blnApprove As Boolean
    Using dt As New DataTable
        Using cn As New SqlConnection("Your connection string"),
        cmd As New SqlCommand("uc_OneAPortalUserAccess", cn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.Add("@intInvoiceShipmentID", SqlDbType.Int).Value = intInvoiceShipmentId
            cmd.Parameters.Add("@intUserID", SqlDbType.Int).Value = intUserID
            cn.Open()
            dt.Load(cmd.ExecuteReader)
        End Using
        If dt.Rows.Count > 0 Then
            blnView = CBool(dt.Rows(0)("ViewAccess"))
            blnEdit = CBool(dt.Rows(0)("EditAccess"))
            blnApprove = CBool(dt.Rows(0)("ApproveAccess"))
        Else
            blnView = False
            blnEdit = False
            blnApprove = False
        End If
    End Using
    'If user has view only access
    If blnView = True Then
        btnSaveTop.Visible = False
        btnSaveBottom.Visible = False
        btnApproveBottom.Visible = False
        btnApproveTop.Visible = False
    End If
End Sub