wy_jj.aspx
来自「ASP.NET开发实战详解」· ASPX 代码 · 共 279 行
ASPX
279 行
<%@ 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 Sql as string
dim dataR as sqldatareader
If Not IsPostBack Then
If Session("curruser").value = "" Then
Response.Redirect("../index.aspx")
End If
cnn=new sqlconnection(configurationsettings.appsettings("connection"))
sql="select * from wy_info"
cmd=new sqlcommand(sql,cnn)
cnn.open()
datar=cmd.executereader()
if datar.read() then
name.text=Iif(IsDbNull(datar("name")),"",datar("name"))
addr.text=Iif(IsDbNull(datar("addr")),"",datar("addr"))
ssqy.text=Iif(IsDbNull(datar("area")),"",datar("area"))
jgrq.text=Iif(IsDbNull(datar("jgdate")),"",datar("jgdate"))
yjrq.text=Iif(IsDbNull(datar("yjdate")),"",datar("yjdate"))
memo.text=Iif(IsDbNull(datar("memo")),"",datar("memo"))
zdmj.text=Iif(IsDbNull(datar("zdarea")),"",datar("zdarea"))
lhmj.text=Iif(IsDbNull(datar("lharea")),"",datar("lharea"))
dlmj.text=Iif(IsDbNull(datar("dlarea")),"",datar("dlarea"))
jzmj.text=Iif(IsDbNull(datar("jzarea")),"",datar("jzarea"))
zzs.text=Iif(IsDbNull(datar("znum")),"",datar("znum"))
zhs.text=Iif(IsDbNull(datar("hnum")),"",datar("hnum"))
zrs.text=Iif(IsDbNull(datar("pnum")),"",datar("pnum"))
End If
datar.close()
cnn.close()
end if
End Sub
Sub save_click(Sender As Object, E As EventArgs)
dim sql as string
dim Str1 as string
dim Str2 as string
dim theTag as integer
dim datar as sqldatareader
thetag=0
thetag=testdata(jgrq.text,"竣工日期",1)+testdata(yjrq.text,"移交日期",1)+testdata(jzmj.text,"建筑面积",2)+testdata(zdmj.text,"占地面积",2)+testdata(lhmj.text,"绿化面积",2)+testdata(dlmj.text,"道路面积",2)+testdata(zzs.text,"总幢数",2)+testdata(zhs.text,"总户数",2)+testdata(zrs.text,"总人数",2)
if thetag=0 then
cnn=new sqlconnection(configurationsettings.appsettings("connection"))
sql="select * from wy_info"
cmd=new sqlcommand(sql,cnn)
cnn.open
datar=cmd.executereader()
if datar.read() then
str1="name='" & name.text & "',addr='" & addr.text & "',area='" & ssqy.text & "',memo='" & memo.text & "'"
if trim(jgrq.text)="" then
str1=str1 & ",jgdate=null"
else
str1=str1 & ",jgdate='" & cdate(jgrq.text) & "'"
end if
if trim(yjrq.text)="" then
str1=str1 & ",yjdate=null"
else
str1=str1 & ",yjdate='" & cdate(yjrq.text) & "'"
end if
if trim(jzmj.text)="" then
str1=str1 & ",jzarea=null"
else
str1=str1 & ",jzarea=" & cdec(jzmj.text)
end if
if trim(zdmj.text)="" then
str1=str1 & ",zdarea=null"
else
str1=str1 & ",zdarea=" & cdec(zdmj.text)
end if
if trim(lhmj.text)="" then
str1=str1 & ",lharea=null"
else
str1=str1 & ",lharea=" & cdec(lhmj.text)
end if
if trim(dlmj.text)="" then
str1=str1 & ",dlarea=null"
else
str1=str1 & ",dlarea=" & cdec(dlmj.text)
end if
if trim(zzs.text)="" then
str1=str1 & ",znum=null"
else
str1=str1 & ",znum=" & cint(zzs.text)
end if
if trim(zhs.text)="" then
str1=str1 & ",hnum=null"
else
str1=str1 & ",hnum=" & cint(zhs.text)
end if
if trim(zrs.text)="" then
str1=str1 & ",pnum=null"
else
str1=str1 & ",pnum=" & cint(zrs.text)
end if
sql="update wy_info set " & str1
else
str1="name,addr,area,memo"
str2="'" & name.text & "','" & addr.text & "','" & ssqy.text & "','" & memo.text & "'"
if trim(jgrq.text)<>"" then
str1=str1 & ",jgdate"
str2=str2 & ",'" & cdate(jgrq.text) & "'"
end if
if trim(yjrq.text)<>"" then
str1=str1 & ",yjdate='"
str2=str2 & ",'" & cdate(yjrq.text) & "'"
end if
if trim(jzmj.text)<>"" then
str1=str1 & ",jzarea"
str2=str2 & "," & cdec(jzmj.text)
end if
if trim(zdmj.text)<>"" then
str1=str1 & ",zdarea"
str2=str2 & "," & cdec(zdmj.text)
end if
if trim(lhmj.text)<>"" then
str1=str1 & ",lharea"
str2=str2 & "," & cdec(lhmj.text)
end if
if trim(dlmj.text)<>"" then
str1=str1 & ",dlarea"
str2=str2 & "," & cdec(dlmj.text)
end if
if trim(zzs.text)<>"" then
str1=str1 & ",znum"
str2=str2 & "," & cint(zzs.text)
end if
if trim(zhs.text)<>"" then
str1=str1 & ",hnum"
str2=str2 & "," & cint(zhs.text)
end if
if trim(zrs.text)<>"" then
str1=str1 & ",pnum"
str2=str2 & "," & cint(zrs.text)
end if
sql="insert into wy_info(" & str1 & ") values(" & str2 & ")"
end if
datar.close()
cmd=new sqlcommand(sql,cnn)
cmd.executenonquery
page.registerstartupscript("",getalertinfo("数据保存成功!"))
end if
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
Function TestData(byval str1 as string,byval Str2 as string,byval ttype as integer) as integer
'str1表示要判断的字符串
'str2表示该字符串所代表的内容
'str3表示该字符串的类型,1表示日期型,2表示数值型
if trim(str1)<>"" then
select case ttype
case "1"
if not isdate(trim(str1)) then
page.registerstartupscript("",getalertinfo("错误的" & trim(str2) & "!"))
return 1
else
return 0
end if
case "2"
if not isnumeric(trim(str1)) then
page.registerstartupscript("",getalertinfo("错误的" & trim(str2) & "!"))
return 1
else
return 0
end if
end select
end if
End Function
</script>
<html>
<head>
<title>公司信息</title>
<link href="../Main.css" type="text/css" rel="stylesheet" />
</head>
<body background="../images/1.jpg">
<form runat="server">
<table id="search" cellspacing="1" cellpadding="0" width="80%" align="center" border="0">
<tbody>
<tr class="tr4">
<td colspan="3" height="30">
小区名称
<asp:TextBox class="input_text" id="name" runat="server" width="600"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td colspan="3" height="30">
小区地址
<asp:TextBox class="input_text" id="addr" runat="server" width="600"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td colspan="3" height="30">
所属区域
<asp:TextBox class="input_text" id="ssqy" runat="server" width="600"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td width="34%" height="30">
竣工日期
<asp:TextBox class="input_text" id="jgrq" runat="server" width="140"></asp:TextBox>
</td>
<td colspan="2">
移交日期
<asp:TextBox class="input_text" id="yjrq" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td width="34%" height="30">
建筑面积
<asp:TextBox class="input_text" id="jzmj" runat="server" width="140"></asp:TextBox>
</td>
<td colspan="2" rowspan="7">
小区简介<br />
<asp:TextBox id="memo" runat="server" width="380" Rows="13" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td height="30">
占地面积
<asp:TextBox class="input_text" id="zdmj" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td height="30">
绿化面积
<asp:TextBox class="input_text" id="lhmj" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td height="30">
道路面积
<asp:TextBox class="input_text" id="dlmj" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td height="30">
总 幢 数
<asp:TextBox class="input_text" id="zzs" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td height="30">
总 户 数
<asp:TextBox class="input_text" id="zhs" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td height="30">
总 人 数
<asp:TextBox class="input_text" id="zrs" runat="server" width="140"></asp:TextBox>
</td>
</tr>
<tr class="tr4">
<td valign="bottom" align="middle" colspan="3" height="80">
<asp:button class="input_button" id="SaveBtn" onclick="Save_Click" runat="server" text="保 存"></asp:button>
<br />
<asp:RequiredFieldValidator id="Requiredfieldvalidator1" runat="server" ControlToValidate="name" ErrorMessage="*">小区名称不可为空</asp:RequiredFieldValidator>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?