
根据代码,在一个目录中存在N个子目录,且每个目录下都有一个名为:住房信息.xls的文件,要将所以的文件合并到一个工作薄,并将工作表名称更改为子目录名称。将合并后的文件保存为:合并.xls,并保存到当前文件所在的目录。
Sub 遍历()Dim MyPath$, MyName$, m&, wb As Workbook '变量声明 $为文本型,&为整数型
Application.ScreenUpdating = False '禁止屏幕刷新
Application.DisplayAlerts = False '禁止出现任何错误提示
MyPath = ThisWorkbook.Path & "\" '获取当前工作薄路径
MyName = Dir(MyPath, vbDirectory) '开始查找第一项
Do While MyName <> "" '遍历
If MyName <> "." And MyName <> ".." Then '检查是否到末尾
'判断当前是否是目录
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
m = m + 1
'然后打开该目录里的:住房信息.xls
With GetObject(MyPath & MyName & "\住房信息.xls")
If m = 1 Then '如果第一次循环
.Sheets(1).Copy '则复制当前住户信息.xls的第一张工作表
Set wb = ActiveWorkbook '设定wb为活动工作薄
'并在当前路径存为:合并.xls
wb.SaveAs ThisWorkbook.Path & "\合并.xls"
Else '如果不是第一次循环
'则将 住户信息.xls的第一张工作表复制到 合并.xls的第一张工作表的最前面
.Sheets(1).Copy Before:=wb.Sheets(1)
wb.Save '保存wb
End If
wb.ActiveSheet.Name = MyName '当前工作表的名称命名为目录名称
.Close False '关闭wb
End With
End If
End If
MyName = Dir '下一个目录
Loop
wb.Close True '关闭wb
Application.ScreenUpdating = True '恢复屏幕更新
MsgBox "ok" 'd出对话框,表示完成。
End Sub
你把区分用户名的Username是放在NEWS里面的?这样 *** 作起来不太方便,建议你在用户表格〔比如User〕中添加一个字段AddedNum,当用户添加一条新闻后自动增加1个纪录:
<%
'插入新闻代码省略
……
Sql="insert into [news]()values()"
……
'加入一个纪录:
Conn.execute("Update [User] set AddedNum=AddedNum+1 where UserID="&session("UserID")&"")
Response.write"添加成功"
%>
然后在发布新闻页面前添加一个判断
<%
Dim chkRs
Set chkRs=conn.execute("select * from [User] where ID="&Session("id")&"")
if chkRs("AddedNum")>30 then
Response.write"<script language='javascript'>alert('你只能添加30条纪录')window.close()</script>"
else
插入新闻代码(即上面第一段代码)
end if
Set chkRs=nothing
%>
当然 如果你不愿意更改表结构,坚持把username放在news中来区分,也是可以的:
<%
Dim userAddNum
userAddNum=Conn.execute("select count(*) from [News] where username='"&Session("Username")&"'",0,1)(0)
if UserAddNum>30 then
Response.write"<script language='javascript'>alert('你只能添加30条纪录')window.close()</script>"
else
……
end if
%>
个人信息的修改( )
ST_UserAdd aspx cs的主要代码及其解释
在此主要是读取用户信息 显示到每个Web控件 主要代码如程序 所示
程序 ST_UserAdd aspx cs
protected void Page_Load(object sender System EventArgs e)
{
Response Cache SetCacheability(HttpCacheability NoCache)
//判断是否是第一次加载
if(!IsPostBack)
{
//初始化用户信息
ST_BookBiz ST_User st_user = new STGROUP ST_BookBiz ST_User()
//编辑 *** 作
if(Request[ Action ]== edit )
{
ST_BookBiz ST_Identity identity = new
ST_BookBiz ST_Identity(User Identity Name)
int userid = identity UserID
if (userid == )
Response Redirect( /ST_Login aspx )
st_entity = st_user GetUserInfo(userid)
txtNumber Text = userid ToString()
txtName Text = st_entity ST_Name
txtAddress Text = st_entity ST_Address
txtEmail Text = st_entity ST_Email
txtPhone Text = st_entity ST_Telephone
txtPostCode Text = st_entity ST_Postcode
txtTrueName Text = st_entity ST_TrueName
txtPass Text = st_entity ST_Pass
RadioButtonList SelectedIndex =
RadioButtonList Items IndexOf(RadioButtonList Items
FindByText(st_entity ST_Gender))
txtName ReadOnly = true
}
}
}
【代码说明】代码第 ~ 行根据用户ID读取用户信息 代码第 ~ 行显示这些信息 在此要提醒读者的是代码第 ~ 行 注意读取值如何与RadioButtonList控件进行绑定
说明 Items IndexOf()方法用来获取所选择项的索引
触发btnOK_Click事件后 即可进行个人信息的添加或修改 *** 作 主要代码如程序 所示
程序 ST_UserAdd aspx cs
protected void btnOK_Click(object sender System EventArgs e)
{
ST_BookBiz ST_User st_user = new STGROUP ST_BookBiz ST_User()
//判断条件 名称不允许为空
if(txtName Text== )
Response Write( <script defer>alert( 名称不允许为空! )
</script>)
else if(txtPass Text== )
Response Write( <script defer>alert( 密码不允许为空! )
</script>)
else if(txtPass Text != txtPass Text)
{
Response Write( <script defer>alert( 密码不一致! )
</script>)
}
else if (st_user ST_IsUserExist(txtName Text Trim()) &&
Request[ Action ] == add )
{
Response Write( <script defer>alert( 用户名已经存在! )
</script>)
}
else
{
ST_BookBiz ST_Identity identity = new
ST_BookBiz ST_Identity(User Identity Name)
int userid = identity UserID
//用户信息的添加或删除 *** 作
if (Request[ Action ] == add )
{
userid =
st_entity ST_Name = txtName Text
st_entity ST_Address = txtAddress Text
st_entity ST_Email = txtEmail Text
st_entity ST_Telephone = txtPhone Text
st_entity ST_Postcode = txtPostCode Text
st_entity ST_TrueName = txtTrueName Text
st_entity ST_Pass = txtPass Text
st_entity ST_Gender = RadioButtonList SelectedValue
userid = st_user InsertUser(st_entity)
identity = new ST_BookBiz ST_
Identity(txtName Text Trim()
userid)
Context User = new ST_BookBiz
ST_Principal(identity new
string[] { User })
identity Name = txtName Text
identity Roles = User
identity Save()
//身份验证票
FormsAuthentication SetAuthCookie(txtName Text false)
Response Redirect( /ST_Common/ST_Main aspx )
}
else if (Request[ Action ] == edit &&userid!= )
{
//修改信息
st_entity ST_Name = txtName Text
st_entity ST_Address = txtAddress Text
st_entity ST_Email = txtEmail Text
st_entity ST_Telephone = txtPhone Text
st_entity ST_Postcode = txtPostCode Text
st_entity ST_TrueName = txtTrueName Text
st_entity ST_Pass = txtPass Text
st_entity ST_Gender = RadioButtonList SelectedValue
st_entity ST_UserID = userid
st_user UpdateUser(st_entity)
string str = <script language=
javascript>alert( 更新成功! )
</script>
Response Write(str)
}
}
}
【代码说明】代码第 ~ 行首先判断用户的用户名和密码输入是否正确 代码第 ~ 行实现用户信息的添加 代码第 ~ 实现用户信息的修改
lishixinzhi/Article/program/net/201311/15818
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)