⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kqxt_jbxxwh.aspx.vb

📁 vb2005电子书籍——vb.net项目开发宝典源码
💻 VB
字号:
Namespace wsbgxt

Partial Class kqxt_jbxxwh_aspx
    Inherits System.Web.UI.Page
    Private Shared kqDV As DataView
    Private Shared lIndex As Integer
    Private Shared operateindex As Integer
    Private Shared iclskq As New clsDataSet
    Private Shared kqDS As DataSet
    Private Shared clsrow As New clsSingleRow
    Private Shared ryDS As DataSet
    Private Shared kqid As Integer

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub


    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not IsPostBack Then
            If Session("id") Is Nothing Then
                Response.Redirect("../NotLogin.aspx?FromPageName=kqxt/kqxt_jbxxwh")
            End If

            initpage()
            ddlYG1.DataSource = rydata()
            ddlYG1.DataTextField = "xm"
            ddlYG1.DataValueField = "id"
            ddlYG1.DataBind()
            ddlYG2.DataSource = rydata()
            ddlYG2.DataTextField = "xm"
            ddlYG2.DataValueField = "id"
            ddlYG2.DataBind()
            ddlYG3.DataSource = rydata()
            ddlYG3.DataTextField = "xm"
            ddlYG3.DataValueField = "id"
            ddlYG3.DataBind()
        End If
    End Sub
    Private Function rydata() As DataView
        Dim str As String
        Dim retable As DataView

        str = "select xm,id from n_yhjbxx_ent"
        ryDS = iclskq.CreateDataSet(str, "ry")

        retable = New DataView(ryDS.Tables(0))
        Return retable
    End Function

    Private Sub initpage()
        txtRQ.Text = ""
        txtJBSY.Text = ""
        'txtKQBZ.Text = ""
        txtJBSJ.Text = ""
    End Sub
    Private Sub LoadData(ByVal yfbz As Integer)
        Dim Sid As String
        Dim SQLstr As String
        Dim by As String
        Dim bn As String
        '控件初始化
        initpage()
        '转载数据

        by = Date.Today.Year.ToString + "-" + Date.Today.Month.ToString
        bn = Date.Today.Year.ToString
        If Date.Today.Month.ToString.Length = 1 Then
            by = Date.Today.Year.ToString + "-0" + Date.Today.Month.ToString
        End If
        If yfbz = 0 Then
            SQLstr = "select yhjbxx.xm as ygid,n_oa02_jbdjb_ent.id,n_oa02_jbdjb_ent.rq,n_oa02_jbdjb_ent.jbxz,n_oa02_jbdjb_ent.jbsy,n_oa02_jbdjb_ent.jbsj,n_yhjbxx_ent.xm as shr from n_oa02_jbdjb_ent  LEFT JOIN n_yhjbxx_ent ON (n_yhjbxx_ent.id = n_oa02_jbdjb_ent.shr) LEFT JOIN n_yhjbxx_ent yhjbxx ON (yhjbxx.id = n_oa02_jbdjb_ent.ygid) where ygid =" + ddlYG1.SelectedItem.Value
        ElseIf yfbz = 1 Then
            SQLstr = "select yhjbxx.xm as ygid,n_oa02_jbdjb_ent.id,n_oa02_jbdjb_ent.rq,n_oa02_jbdjb_ent.jbxz,n_oa02_jbdjb_ent.jbsy,n_oa02_jbdjb_ent.jbsj,n_yhjbxx_ent.xm as shr from n_oa02_jbdjb_ent  LEFT JOIN n_yhjbxx_ent ON (n_yhjbxx_ent.id = n_oa02_jbdjb_ent.shr) LEFT JOIN n_yhjbxx_ent yhjbxx ON (yhjbxx.id = n_oa02_jbdjb_ent.ygid) where ygid =" + ddlYG1.SelectedItem.Value + "and (CONVERT(varchar(7), rq,120)='" + by + "')"
        Else
            SQLstr = "select yhjbxx.xm as ygid,n_oa02_jbdjb_ent.id,n_oa02_jbdjb_ent.rq,n_oa02_jbdjb_ent.jbxz,n_oa02_jbdjb_ent.jbsy,n_oa02_jbdjb_ent.jbsj,n_yhjbxx_ent.xm as shr from n_oa02_jbdjb_ent  LEFT JOIN n_yhjbxx_ent ON (n_yhjbxx_ent.id = n_oa02_jbdjb_ent.shr) LEFT JOIN n_yhjbxx_ent yhjbxx ON (yhjbxx.id = n_oa02_jbdjb_ent.ygid) where ygid =" + ddlYG1.SelectedItem.Value + "and (CONVERT(varchar(4), rq,120)='" + bn + "')"
        End If
        kqDS = iclskq.CreateDataSet(SQLstr, "kq_kqwh")

        kqDV = New DataView(kqDS.Tables(0))
        grds.DataSource = kqDV
        grds.DataBind()
    End Sub
    Private Function AddRow() As Boolean
        Dim strCol() As String
        Dim strVal() As String
        ReDim strCol(8)
        ReDim strVal(8)

        strCol(1) = "ygid"
        strCol(2) = "rq"
        strCol(3) = "jbxz"
        strCol(4) = "jbsy"
        strCol(5) = "jbsj"
        strCol(6) = "shr"
        strCol(7) = "by1"
        strCol(8) = "by2"

        strVal(1) = ddlYG2.SelectedItem.Value
        strVal(2) = "'" + txtRQ.Text + "'"
        strVal(3) = "'" + ddlJBXZ.SelectedItem.Text + "'"
        strVal(4) = "'" + txtJBSY.Text + "'"
        strVal(5) = txtJBSJ.Text
        strVal(6) = ddlYG3.SelectedItem.Value
        strVal(7) = "''"
        strVal(8) = "''"
        If clsrow.AddRow("n_oa02_jbdjb_ent", strCol, strVal) Then
            Return True
        Else
            Return False
        End If
    End Function
    Private Function DeleteRow() As Boolean
        Dim strCol() As String
        Dim strVal() As String
        ReDim strCol(8)
        ReDim strVal(8)

        strCol(0) = "id"
        strCol(1) = "ygid"
        strCol(2) = "rq"
        strCol(3) = "jbxz"
        strCol(4) = "jbsy"
        strCol(5) = "jbsj"
        strCol(6) = "shr"
        strCol(7) = "by1"
        strCol(8) = "by2"

        strVal(0) = kqid
        strVal(1) = ddlYG2.SelectedItem.Value
        strVal(2) = "'" + txtRQ.Text + "'"
        strVal(3) = "'" + ddlJBXZ.SelectedItem.Text + "'"
        strVal(4) = "'" + txtJBSY.Text + "'"
        strVal(5) = txtJBSJ.Text
        strVal(6) = ddlYG3.SelectedItem.Value
        strVal(7) = "''"
        strVal(8) = "''"
        If clsrow.DeleteRow("n_oa02_jbdjb_ent", strCol, strVal) Then
            Return True
        Else
            Return False
        End If
    End Function
    Private Function UpdateRow() As Boolean
        Dim strCol() As String
        Dim strVal() As String
        ReDim strCol(8)
        ReDim strVal(8)

        strCol(0) = "id"
        strCol(1) = "ygid"
        strCol(2) = "rq"
        strCol(3) = "jbxz"
        strCol(4) = "jbsy"
        strCol(5) = "jbsj"
        strCol(6) = "shr"
        strCol(7) = "by1"
        strCol(8) = "by2"

        strVal(0) = kqid
        strVal(1) = ddlYG2.SelectedItem.Value
        strVal(2) = "'" + txtRQ.Text + "'"
        strVal(3) = "'" + ddlJBXZ.SelectedItem.Text + "'"
        strVal(4) = "'" + txtJBSY.Text + "'"
        strVal(5) = txtJBSJ.Text
        strVal(6) = ddlYG3.SelectedItem.Value
        strVal(7) = "''"
        strVal(8) = "''"
        If clsrow.UpdateRow("n_oa02_jbdjb_ent", strCol, strVal) Then
            Return True
        Else
            Return False
        End If
    End Function

    'datagrid 的分页处理
    Sub ChangeGridPage(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
        grds.EditItemIndex = -1
        grds.CurrentPageIndex = e.NewPageIndex
        grds.DataSource = kqDV
        grds.DataBind()
    End Sub

    Sub grds_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grds.ItemCommand

        Dim i As Integer

        lIndex = e.Item.ItemIndex
        lIndex = lIndex + grds.CurrentPageIndex * grds.PageSize

        kqid = CInt(e.Item.Cells(0).Text)


        btnADD.Visible = False
        btnOK.Visible = True


        If e.CommandSource.commandname = "kqUpdate" Or e.CommandSource.commandname = "kqDelete" Then

            For i = 0 To ddlYG2.Items.Count - 1
                If Trim(ddlYG2.Items(i).Text) = Trim(e.Item.Cells(1).Text) Then
                    ddlYG2.SelectedIndex = i
                    Exit For
                End If
            Next i
            txtRQ.Text = e.Item.Cells(2).Text

            txtJBSY.Text = e.Item.Cells(4).Text
            txtJBSJ.Text = e.Item.Cells(5).Text

            For i = 0 To ddlYG3.Items.Count - 1
                If Trim(ddlYG3.Items(i).Text) = Trim(e.Item.Cells(6).Text) Then
                    ddlYG3.SelectedIndex = i
                    Exit For
                End If
            Next i
            If ddlJBXZ.Items(0).Value = Trim(e.Item.Cells(3).Text) Then
                ddlJBXZ.SelectedIndex = 0
            ElseIf ddlJBXZ.Items(1).Value = Trim(e.Item.Cells(3).Text) Then
                ddlJBXZ.SelectedIndex = 1
            Else
                ddlJBXZ.SelectedIndex = 2
            End If
        End If


        If e.CommandSource.commandname = "kqUpdate" Then
            operateindex = 0
            '置员工为不可修改
        ElseIf e.CommandSource.commandname = "kqDelete" Then
            operateindex = 1
        End If
    End Sub

    Private Sub btnADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADD.Click
        If AddRow() Then
            statusbar.Text = "添加记录成功!"
         
            LoadData(DDLjbsx.SelectedIndex)
            initpage()
        Else
            statusbar.Text = "添加记录失败,请检查然后重新操作!"
        End If
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If operateindex = 0 Then
            If UpdateRow() Then
                statusbar.Text = "更新数据成功!"
                initpage()
                LoadData(DDLjbsx.SelectedIndex)
            Else
                statusbar.Text = "更新数据失败,请检查然后重新操作!"
            End If
        Else
            If DeleteRow() Then
                statusbar.Text = "删除数据成功!"
                initpage()
                LoadData(DDLjbsx.SelectedIndex)
            Else
                statusbar.Text = "删除数据失败,请检查然后重新操作!"
            End If
        End If
        grds.DataSource = kqDS
        grds.DataBind()
    End Sub

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        LoadData(DDLjbsx.SelectedIndex)
    End Sub
End Class

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -