biaoinfo.aspx

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

ASPX
261 行
字号
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.sqlclient" %>
<script runat="server">

    dim Cnn as sqlconnection
              dim cmd as sqlcommand
              Sub Page_Load(Sender As Object, E As EventArgs)
                  dim datar as sqldatareader
                  dim sql as string
                  If Not IsPostBack Then
                    If session("curruser")="" then
                       response.redirect ("../index.aspx")
                    end if
                    BindGrid()
                  End If
              End Sub
    
              Sub Save_Click(Sender As Object, E As EventArgs)
                  dim codestr as string=code.text
                  dim lcstr as string=lc.text
                  dim blstr as string=bl.text
                  dim typestr as string=ttype.selecteditem.value
                  dim unitstr as string=unit.selecteditem.value
                  dim pricestr as string=price.text
                  dim memostr as string=memo.text
                  dim sql as string
                  if trim(lcstr)="" then
                     lcstr="0"
                  end if
                  if trim(blstr)="" then
                     blstr="0"
                  end if
 
                  cnn=new sqlconnection(configurationsettings.appsettings("connection"))
                  cnn.open()
                  sql="insert into cw_biao_info(code,type,lc,bl,price,unit,memo) values('" & codestr & "','" & typestr & "'," & lcstr & "," & blstr & "," & pricestr & ",'" & unitstr & "','" & memostr & "')"
                  cmd=new sqlcommand(sql,cnn)
                  cmd.executeNonQuery
                  cnn.close()
                  bindgrid()
		  call cleardata()	
                  page.registerstartupscript("",getalertinfo("数据保存成功!"))
              End Sub

	      sub cleardata()
		  code.text=""
                  price.text=""
                  bl.text=""
                  lc.text=""
                  memo.text=""
              end sub
	    
		    
                   Sub BindGrid()
                      dim dataR as sqldatareader
                      dim dtcmd as sqldataadapter
                      dim dt as new datatable
                      dim MaxPage as integer  '计算最大页数
                      dim str2 as string
                      dim Str1 as string
                      dim i as integer
                      dim sumrecord as integer
                      cnn=new sqlconnection(configurationsettings.appsettings("connection"))
                      str2="select count(*) as nums from cw_biao_info"
                      cnn.open()
                      cmd=new sqlcommand(str2,cnn)
                      datar=cmd.executereader()
                      if datar.read() then
                         if datar("nums").tostring()="0" then
                            msg.text=""
                         else
                            msg.text="合计:记录数 " & datar("nums").tostring()
                         end if
                      end if
                      datar.close()
                      str1="select * from cw_biao_info order by type,id"
                      dtcmd=new sqldataadapter(str1,cnn)
                      dtcmd.fill(dt)
                      if (dt.defaultview.count mod datagrid1.pagesize)>0 then
                         maxpage=dt.defaultview.count \datagrid1.pagesize+1
                      else
                         maxpage=dt.defaultview.count \datagrid1.pagesize
                      end if
                      do while datagrid1.currentpageindex>0
                         if maxpage<datagrid1.currentpageindex+1 then
                           datagrid1.currentpageindex=datagrid1.currentpageindex-1
                         else
                           exit do
                        end if
                      loop
                      datagrid1.datasource=dt
                      datagrid1.databind()
                 sumrecord=datagrid1.Items.count
                 for i=0 to sumrecord-1
                   dim LinkButton=Datagrid1.Items(i).Cells(8).Controls(0)
                   LinkButton.Attributes.Add("onclick","javascript:openwin('set_user.aspx?id=" & Datagrid1.Items(i).Cells(0).text & "&type=biao&name=" & datagrid1.items(i).cells(1).text & "')")
                   dim LinkButton1=Datagrid1.Items(i).Cells(9).Controls(0)
                   LinkButton1.Attributes.Add("onclick","javascript:openwin('view_user.aspx?id=" & Datagrid1.Items(i).Cells(0).text & "&type=biao&name=" & datagrid1.items(i).cells(1).text & "')")
                   dim LinkButton2=Datagrid1.Items(i).Cells(10).Controls(0)
                   LinkButton2.Attributes.Add("onclick","javascript:openwin('biao_mod.aspx?id=" & Datagrid1.Items(i).Cells(0).text & "')")
                 next
                 cnn.close()
              End Sub
    
    
   Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      MultiView1.ActiveViewIndex = 0
   End Sub
   
   Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      MultiView1.ActiveViewIndex = 1
   End Sub
    
                   Sub Grid1_Mod(Sender as object,E as DataGridCommandEventArgs)
                       dim codestr as string=E.Item.Cells(0).Text
                       dim sql as string
                       dim url as string
                       if CType(e.CommandSource,LinkButton).CommandName="Delete" then
                          cnn=new sqlconnection(configurationsettings.appsettings("connection"))
                          cnn.open()
                          sql="delete from cw_biao_info where id=" & codestr
                          cmd=new sqlcommand(sql,cnn)
                          cmd.executeNonQuery
                          cnn.close()
                          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>收费设置</title>
    <link href="../Main.css" type="text/css" rel="stylesheet" />
    <script language="javascript">
       function openwin(src)
       {
          var vDialog=null;
          vDialog=showModalDialog(src,window,"status:no;resizable:off;dialogHeight:500px;dialogWidth:750px;unadorne:yes;help:no");
          location.reload();
       }

    </script>
</head>
<body leftmargin="0" topmargin="0" background="../images/1.jpg">
    <form runat="server">
       <asp:Image ID="Image2" runat="server" ImageUrl="../images/pic1.gif" />
       <asp:LinkButton ID="LinkButton1" Font-Bold="True" Font-Size="X-Small" runat="server" OnClick="LinkButton1_Click" CausesValidation="False">表信息查询</asp:LinkButton>&nbsp;&nbsp;
       <asp:Image ID="Image1" runat="server" ImageUrl="../images/pic1.gif" />
       <asp:LinkButton ID="LinkButton2" runat="server" Font-Bold="True" Font-Size="X-Small" OnClick="LinkButton2_Click" CausesValidation="False">表信息增加</asp:LinkButton>
       <hr />
       <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
         <asp:View ID="View1" runat="server">    
                <table class="" id="search" cellspacing="1" cellpadding="0" width="95%" align="center" border="0">
                    <tbody>
                        <tr class="tr2">
                            <td style="PADDING-LEFT: 5px" height="25">
                                <asp:Label id="Msg" runat="server" forecolor="red"></asp:Label></td>
                        </tr>
                        <tr>
                            <td style="PADDING-LEFT: 5px" height="25">
                                <asp:DataGrid id="DataGrid1" runat="server" width="100%" OnPageIndexChanged="Grid1_PageIndexChanged" AllowSorting="True" AllowPaging="True" Font-Names="verdana" bordercolor="Black" cellpadding="2" font-name="verdana" font-size="8pt" headerstyle-backcolor="#F8FAFC" OnItemCommand="Grid1_Mod" AutoGenerateColumns="False" PageSize="10">
                                    <HeaderStyle font-bold="True" horizontalalign="Center" verticalalign="Middle" backcolor="#F8FAFC"></HeaderStyle>
                                    <PagerStyle nextpagetext="下一页" font-names="宋体" font-bold="True" prevpagetext="上一页" horizontalalign="Right" forecolor="Blue" mode="NumericPages"></PagerStyle>
                                    <EditItemStyle backcolor="#E9F0F8"></EditItemStyle>
                                    <Columns>
                                        <asp:BoundColumn DataField="id" visible="false" HeaderText="序号"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="code" HeaderText="编号"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="type" HeaderText="类型"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="lc" HeaderText="量程"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="bl" HeaderText="倍率"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="price" HeaderText="单价"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="unit" HeaderText="单位"></asp:BoundColumn>
                                        <asp:BoundColumn DataField="memo" HeaderText="备注"></asp:BoundColumn>
                                        <asp:ButtonColumn Text="安装到用户" HeaderText="安装到用户" CommandName="gnyh"></asp:ButtonColumn>
                                        <asp:ButtonColumn Text="查看用户" HeaderText="查看用户" CommandName="ckyh"></asp:ButtonColumn>
                                        <asp:ButtonColumn Text="修改" HeaderText="修改" CommandName="modi"></asp:ButtonColumn>
                                        <asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
                                    </Columns>
                                </asp:DataGrid>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </asp:View>
            <asp:View ID="View2" runat="server">
                <br />
                <table id="search" cellspacing="1" cellpadding="0" width="80%" align="center" border="0">
                    <tbody>
                        <tr>
                            <td height="50" width="34%">
                                编&nbsp;&nbsp;&nbsp;&nbsp;号
                                <asp:TextBox class="input_text" id="code" runat="server" width="110"></asp:TextBox>
			    </td>
                            <td width="33%">
                                类&nbsp;&nbsp;&nbsp;&nbsp;型
                                <asp:DropDownList class="input_text" id="ttype" runat="server" width="110">
				   <asp:ListItem Value="电表" selected="true">电表</asp:ListItem>
				   <asp:ListItem Value="水表">水表</asp:ListItem>
				   <asp:ListItem Value="气表">气表</asp:ListItem>
				</asp:DropDownList>
                            </td>
                            <td>
                                单&nbsp;&nbsp;&nbsp;&nbsp;位
                                <asp:DropDownList class="input_text" id="unit" runat="server" width="110">
				   <asp:ListItem Value="度" selected="true">度</asp:ListItem>
				   <asp:ListItem Value="吨">吨</asp:ListItem>
				   <asp:ListItem Value="立方米">立方米</asp:ListItem>
				</asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td height="50">
                                量&nbsp;&nbsp;&nbsp;&nbsp;程
                                <asp:TextBox class="input_text" id="lc" runat="server" width="110"></asp:TextBox>
                            </td>
                            <td>
                                倍&nbsp;&nbsp;&nbsp;&nbsp;率
                                <asp:TextBox class="input_text" id="bl" runat="server" width="110"></asp:TextBox>
                            </td>
                            <td>
                                单&nbsp;&nbsp;&nbsp;&nbsp;价
                                <asp:TextBox class="input_text" id="price" runat="server" width="110"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan=3 height="50">
                                备&nbsp;&nbsp;&nbsp;&nbsp;注
                                <asp:TextBox class="input_text" id="memo" runat="server" width="540"></asp:TextBox>
                            </td>
                        </tr>
                        <tr class="tr4">
                            <td valign="bottom" align="middle" colspan="3" height="100">
                                <asp:button class="input_button" id="SaveBtn" onclick="Save_Click" runat="server" text="保  存"></asp:button>
                                <br />
                                <asp:RequiredFieldValidator id="Requiredfieldvalidator1" runat="server" ErrorMessage="*" ControlToValidate="code">表编号不可为空</asp:RequiredFieldValidator><br>
                                <asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server" ErrorMessage="*" ControlToValidate="price">单价不可为空</asp:RequiredFieldValidator>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </asp:View>
        </asp:MultiView>
    </form>
</body>
</html>

⌨️ 快捷键说明

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