set_user.aspx

来自「ASP.NET开发实战详解」· ASPX 代码 · 共 272 行

ASPX
272
字号
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.sqlclient" %>
<script runat="server">
    dim Cnn as sqlconnection
    Shared DTable as new datatable
    dim cmd as sqlcommand
    Shared TitleStr as string
    Shared DispStr as string
    Sub Page_Load(Sender As Object, E As EventArgs)
       dim theNode as TreeNode
      Dim theNode1 As TreeNode
      Dim theNode2 As TreeNode
      Dim theNode3 As TreeNode
       dim sql as string
       dim datar as sqldatareader
       dim datar1 as sqldatareader
       dim datar2 as sqldatareader
       dim datar3 as sqldatareader
      Dim Cnn1 As SqlConnection
       dim Cnn2 as sqlconnection
       dim Cnn3 as sqlconnection

       select case request.querystring("type")
       case "sfsz"
          titlestr="将收费项目对应到用户"
          dispstr="当前收费项目:" 
       case "biao"
          titlestr="将表安装到用户"
          dispstr="当前表编号:" 
       end select

       if dtable.columns.count=0 then
          dtable.columns.add("code",System.Type.GetType("System.String"))
          dtable.columns.add("name",system.type.gettype("System.String"))
          dtable.columns.add("hzname",system.type.gettype("System.String"))
          dim thekey() as datacolumn={dtable.columns("code")}
          dtable.primarykey=thekey
          bindgrid()
       end if

       If Not IsPostBack Then 

       cnn=new sqlconnection(configurationsettings.appsettings("connection"))
       cnn1=new sqlconnection(configurationsettings.appsettings("connection"))
       cnn2=new sqlconnection(configurationsettings.appsettings("connection"))
       cnn3=new sqlconnection(configurationsettings.appsettings("connection"))
       cnn.open()
       cnn1.open()
       cnn2.open()
       cnn3.open()

       sql="select * from fc_lp order by code"
       cmd=new sqlcommand(sql,cnn)
       datar=cmd.executereader()
       do while datar.read()
          thenode=new treenode()
            theNode.Text = datar("name")
            theNode.Value = datar("code")
            TreeView1.Nodes.Add(theNode)
            sql = "select * from fc_lg where lpcode='" & datar("code") & "' order by code"
          cmd=new sqlcommand(sql,cnn1)
          datar1=cmd.executereader()
          do while datar1.read()
               theNode1 = New TreeNode()
               theNode1.Text = datar1("name")
               theNode1.Value = datar1("code")
               theNode.ChildNodes.Add(theNode1)
               sql = "select code,name from fw_para where type='LT' and code in (select ltcode from fc_cell where lgcode='" & datar1("code") & "') order by code"
             cmd=new sqlcommand(sql,cnn2)
             datar2=cmd.executereader()
             do while datar2.read()
                  theNode2 = New TreeNode()
                  theNode2.Text = datar2("name")
                  theNode2.Value = Trim(datar1("code")) & Trim(datar2("code"))
                  theNode1.ChildNodes.Add(theNode2)
                  sql = "select code,a.name,isnull(b.name,'') as zhname from fc_cell a left outer join zh_master b on a.code=b.cellcode where ltcode='" & datar2("code") & "' and lgcode='" & datar1("code") & "' order by a.code"
                cmd=new sqlcommand(sql,cnn3)
                datar3=cmd.executereader()
                do while datar3.read()
                     theNode3 = New TreeNode()
                   if datar3("zhname")="" then
                        theNode3.Text = datar3("name")
                   else
                        theNode3.Text = datar3("name") & "(" & datar3("zhname") & ")"
                     End If
                     theNode3.Value = datar3("code")
                     theNode2.ChildNodes.Add(theNode3)
                loop
                datar3.close()
             loop
             datar2.close()
          loop
          datar1.close()
       loop  
       
       end if
   End Sub

    Sub BindGrid()
        datagrid1.datasource=dtable
        datagrid1.databind()
    End Sub

    Sub Add_Click(Sender As Object, E As EventArgs)
      Dim i As Integer
      If TreeView1.Nodes.Count > 0 Then
         For i = 0 To TreeView1.Nodes.Count - 1
            getNode(TreeView1.Nodes(i))
         Next
         BindGrid()
      End If
   End Sub

   Private Sub getNode(ByVal theNodes As TreeNode)
      Dim str1 As String
      Dim dycode As String
      Dim dyname As String
      Dim zhname As String
      Dim i, j, k As Integer
      Dim DRow As DataRow
      Dim myDataRowCollection As DataRowCollection
      If theNodes.ChildNodes.Count <> 0 Then
         For i = 0 To theNodes.ChildNodes.Count - 1
            getNode(theNodes.ChildNodes(i))
         Next
      Else
         If theNodes.Checked = True Then
            str1 = theNodes.Text
            dycode = theNodes.Value
            i = InStr(Trim(str1), "(")
            If i > 0 Then
               dyname = Left(Trim(str1), i - 1)
               zhname = Mid(Trim(str1), i + 1, Len(Trim(str1)) - i - 1)
            Else
               dyname = Trim(str1)
               zhname = ""
            End If
            myDataRowCollection = DTable.Rows
            If Not (myDataRowCollection.Contains(dycode)) Then
               DRow = DTable.NewRow()
               DRow(0) = dycode
               DRow(1) = dyname
               DRow(2) = zhname
               DTable.Rows.Add(DRow)
            End If
         End If
      End If
   End Sub

    Sub Del_Click(Sender As Object, E As EventArgs)
        dtable.rows.clear()
        bindgrid()   
    end sub

    Sub Save_Click(Sender As Object, E As EventArgs)
        dim myDataRowCollection as datarowcollection
        dim theRow as datarow
        dim theid as string=request.querystring("id")
        dim Sql as String
        dim Str1 as string
        mydatarowcollection=dtable.rows
        if mydatarowcollection.count=0 then
           select case request.querystring("type")
           case "sfsz"
               Page.RegisterStartupScript("", GetAlertInfo("没有添加与该收费项目相关联的单元,数据无法保存!"))
           case "biao"
              Page.RegisterStartupScript("",getalertinfo("没有添加安装该表的单元,数据无法保存!"))
           case "zbiao"
              Page.RegisterStartupScript("",getalertinfo("没有添加与该总表相关联的单元,数据无法保存!"))
           end select           
        else
           for each theRow In mydatarowcollection
              str1=str1 & "c" & therow(0).tostring
           next
           select case request.querystring("type")
           case "sfsz"
              sql="insert into cw_sf_user(cellcode,itemcode) select code," & theid & " from fc_cell where charindex('c'+code,'" & str1 & "')>0 and code not in (select cellcode from cw_sf_user where itemcode=" & theid & ")" 
           case "biao"
              sql="insert into cw_biao_user(cellcode,biaocode) select code," & theid & " from fc_cell where charindex('c'+code,'" & str1 & "')>0 and code not in (select cellcode from cw_biao_user where biaocode=" & theid & ")" 
           end select           
           cnn=new sqlconnection(configurationsettings.appsettings("connection"))
           cnn.open           
           cmd=new sqlcommand(sql,cnn)
           cmd.executenonquery 
           page.registerstartupscript("",getalertinfo("数据保存成功!"))
        end if
    end sub


    Sub Grid1_Mod(Sender as object,E as DataGridCommandEventArgs)
        dim codestr as string=E.Item.Cells(0).Text
        dim DRow as datarow
        dim myDataRowCollection as datarowcollection
        if CType(e.CommandSource,LinkButton).CommandName="Delete" then 
           mydatarowcollection=dtable.rows
           DRow=mydatarowcollection.find(codestr)
           mydatarowcollection.remove(DRow)
           bindgrid()
        end if
    End Sub

    Sub Grid1_PageIndexChanged(Sender As Object, E As DataGridPageChangedEventArgs)
        datagrid1.CurrentPageIndex = e.NewPageIndex
        BindGrid()
    End Sub

    Function GetAlertInfo(byval str1 as string) as String
       dim Str2 as String
       str2="<script language='javascript'>alert('" & str1 & "')<"
       str2+="/"
       str2+="script>"
       return trim(str2)
   End Function

</script>
<html>
<head>
    <title><%=titlestr%></title>
    <link href="../Main.css" type="text/css" rel="stylesheet" />
    <base target="_self" />
    <script language="javascript">

    </script>
</head>
<body leftmargin="0" background="../images/1.jpg">
    <form runat="server">

        <br><p align="center"><font style="color:blue" face="隶书" size="6"><strong><%=titlestr%></strong></font><br>
        <font style="color:blue"><%=dispstr%></font><font style="color:red"><%=request.querystring("name")%></font>
        <hr></p>

<asp:Panel id="Panel1" runat="server" BorderStyle="Solid" BorderWidth="1px" style="Z-INDEX: 101; LEFT: 30px; OVERFLOW: auto; POSITION: absolute; TOP: 90px " Width="292px" Height="370px">
    <asp:TreeView  ID="TreeView1" runat="server" ExpandDepth="1" Font-Size="X-Small"  ShowCheckBoxes="All" BorderStyle="None" ForeColor="Black" NodeWrap="True" ShowLines="True" style="Z-INDEX: 114; LEFT: 4px; POSITION: absolute; TOP: 4px" Width="280px" Height="358px">
      </asp:TreeView>
<%--
        <iewc:TreeView id="TreeView1" runat="server" SystemImagesPath="../images/" style="Z-INDEX: 114; LEFT: 4px; POSITION: absolute; TOP: 4px" Width="280px" Height="358px">
        </iewc:TreeView>--%>
</asp:Panel>


<asp:button id="AddBtn" onclick="Add_Click" runat="server" text=">>" style="Z-INDEX: 101; LEFT: 349px; OVERFLOW: auto; POSITION: absolute; TOP: 150px "></asp:button>

<asp:button id="DelBtn" onclick="Del_Click" runat="server" text="<<" style="Z-INDEX: 101; LEFT: 349px; OVERFLOW: auto; POSITION: absolute; TOP: 230px "></asp:button>

<asp:button id="SaveBtn" onclick="Save_Click" runat="server" text="保 存" style="Z-INDEX: 101; LEFT: 345px; OVERFLOW: auto; POSITION: absolute; TOP: 310px "></asp:button>

<asp:Panel id="Panel3" runat="server" BorderStyle="Solid" BorderWidth="1px" style="Z-INDEX: 101; LEFT: 420px; OVERFLOW: auto; POSITION: absolute; TOP: 90px " Width="292px" Height="370px">
                        <asp:DataGrid id="DataGrid1" runat="server" width="100%" PageSize="11" AutoGenerateColumns="False" headerstyle-backcolor="#F8FAFC" font-size="8pt" font-name="verdana" cellpadding="2" bordercolor="Black" Font-Names="verdana" AllowPaging="True" AllowSorting="True" OnPageIndexChanged="Grid1_PageIndexChanged" OnItemCommand="Grid1_Mod" BorderStyle="None">
                            <HeaderStyle font-bold="True" horizontalalign="Center" verticalalign="Middle" backcolor="#F8FAFC"></HeaderStyle>
                            <PagerStyle nextpagetext="下一页" font-names="宋体" font-bold="True" prevpagetext="上一页" horizontalalign="Right" forecolor="Blue" position="bottom" mode="NumericPages"></PagerStyle>
                            <EditItemStyle backcolor="#E9F0F8"></EditItemStyle>
                            <Columns>
                                <asp:BoundColumn visible="false" DataField="Code" HeaderText="单元编号">
                                </asp:BoundColumn>
                                <asp:BoundColumn DataField="Name" HeaderText="单元名称">
                                   <HeaderStyle width="100px"></HeaderStyle>
                                </asp:BoundColumn>
                                <asp:BoundColumn DataField="hzname" HeaderText="户  主">
                                   <HeaderStyle width="100px"></HeaderStyle>
                                </asp:BoundColumn>
                                <asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete">
                                   <HeaderStyle width="70px"></HeaderStyle>
                                </asp:ButtonColumn>
                            </Columns>
                        </asp:DataGrid>
</asp:Panel>

    </form>
</body>
</html>

⌨️ 快捷键说明

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