明天回家过春节了。要些日子才过来吧。
这两天头晕得厉害。不知是KFC不能多吃,还是晚上的风太凉了。
家那边虽然感觉比昆山冷一些,可是身子就是不太容易出毛病。
虽然很想带些东西回去,却有心无力。
嗯,过年再不似儿时那般盼望了。
又是一个难过的年
浏览模式: 标准 | 列表2007年02月的文章
回家过春节了
Submitted by on 2007, February 16, 5:34 AM
实例(Smarty+FCKeditor新闻系统)
Submitted by on 2007, February 10, 6:07 PM
实例(Smarty+FCKeditor新闻系统)
——一牛人学习php一个月的作业——
以下是主文件index.php的内容:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
require("./global.php");
require("./smarty/libs/Smarty.class.php");
require("./mysql.php");
require("./FCKeditor/fckeditor.php");
$action=$_REQUEST["action"];
//定义一个函数用于调用FCK
function editor($input_name, $input_value)
{
global $smarty;
$editor = new FCKeditor($input_name) ;
$editor->BasePath = "./FCKeditor/";//指定编辑器路径
$editor->ToolbarSet = "Default";//编辑器工具栏有Basic(基本工具),Default(所有工具)选择
$editor->Width = "100%";
$editor->Height = "320";
$editor->Value = $input_value;
$editor->Config["AutoDetectLanguage"] = true ;
$editor->Config["DefaultLanguage"] = "en" ;//语言
$FCKeditor = $editor->CreateHtml();
$smarty->assign("editor", $FCKeditor);//指定区域
}
switch ($action){
case "addnewsview":
$smarty= new Smarty();
$smarty->template_dir = "./template";
$smarty->compile_dir = "./smarty/templates_c";
$smarty->assign("page_title","新建新闻");
$smarty->assign("actionvalue","addnews");
editor("content","");//调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST["content"]对应
$smarty->display("addnews.htm");
break;
case "addnews":
$title=$_REQUEST["title"];
$content=$_REQUEST["content"];
$db=new mysql();
$button=$_REQUEST["Submit"];
if(empty($title) || empty($content)){
echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}else{
$sql="insert into news values(id,"admin","$title","$content",NOW())";
$db->query_exec($sql);
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
break;
case "editnewsview":
$smarty= new Smarty();
$smarty->template_dir = "./template";
$smarty->compile_dir = "./smarty/templates_c";
$smarty->assign("page_title","修改新闻");
$smarty->assign("actionvalue","addnews");
$id=$_REQUEST["id"];
$query="select * from news where id=$id";
$db=new mysql();
$result = $db->query_exec($query);
$rs = $result-> fetch_assoc();
$smarty->assign("title",$rs["title"]);
//$smarty->assign("content",$rs["content"]);
$smarty->assign("actionvalue","editnews");
$smarty->assign("id",$rs["id"]);
editor("content",$rs["content"]);
$smarty->display("addnews.htm");
break;
case "editnews":
$title=$_REQUEST["title"];
$content=$_REQUEST["content"];
$id=$_REQUEST["id"];
$button=$_REQUEST["Submit"];
$db=new mysql();
if ($button=="提交"){
$sql="update news set title="$title",content="$content",date=NOW() where id=$id";
$db->query_exec($sql);
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
break;
case "delnews":
$db=new mysql();
if ($checkbox!="" or count($checkbox)!=0) {
for ($i=0;$i<count($checkbox);$i++){
$db->query_exec("delete from news where id="$checkbox[$i]"");
}
}
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
break;
default:
$smarty= new Smarty();
$smarty->template_dir = "./template";
$smarty->compile_dir = "./smarty/templates_c";
$smarty->assign("page_title","新闻管理");
$smarty->assign("actionvalue","delnews");
$query="select * from news";
$db=new mysql();
$result = $db->query_exec($query);
while ($rs = $result-> fetch_assoc()) {
$array[]= array("id"=>$rs["id"], "title"=>$rs["title"],"date"=>$rs["date"]);
$smarty->assign("news",$array);
}
$smarty->display("index.htm");
}
?>
以下是模板文件index.htm的内容
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$page_title}</title>
</head>
<body>
<p class="style1">新闻管理</p>
<hr>
<table width="771" height="115" border="0">
<tr>
<td height="62"><div align="center">系统管理</div></td>
<td width="666" rowspan="2"><form name="form1" method="post" action="">
<table width="543" border="0">
<tr>
<td width="253">标题</td>
<td width="230">日期</td>
<td width="46">选择</td>
</tr>
{section name=news loop=$news}
<tr>
<td><a href="./index.php?action=editnewsview&id={$news[news].id}">{$news[news].title}</a></td>
<td>{$news[news].date}</td>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="{$news[news].id}"></td>
</tr>
{/section}
</table>
<p>
<input type="submit" name="Submit" value="删除">
<input name="action" type="hidden" id="action" value="{$actionvalue}">
</p>
</form> </td>
</tr>
<tr>
<td width="95" height="47"><div align="center"><a href="./index.php?action=addnewsview">添加新闻</a></div></td>
</tr>
</table>
<p class="style1"> </p>
</body>
</html>
以下是添加新闻的模板文件addnews.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="./css/a.css" rel="stylesheet" type="text/css">
<title>{$page_title}</title>
</head>
<body>
<p class="style1">新闻管理登陆 </p>
<hr>
<table width="771" height="501" border="0">
<tr>
<td height="62"><div align="center">系统管理</div></td>
<td width="666" rowspan="2"><form name="form1" method="post" action="index.php">
<p>标题
<input name="title" type="text" id="title" value="{$title}">
</p>
<p>内容:</p>
<p>{$editor}</p>
<p>
<input type="submit" name="Submit" value="提交">
<input type="hidden" name="action" value={$actionvalue}>
<input name="id" type="hidden" value="{$id}">
</p>
</form>
</td>
</tr>
<tr>
<td width="95" height="433"><div align="center">添加新闻</div></td>
</tr>
</table>
</body>
</html>
注:数据库已经在附件里面,先新建一个名为new的数据库,再把表导入
本系统用户名:admin 密码:admin
——一牛人学习php一个月的作业——
以下是主文件index.php的内容:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
require("./global.php");
require("./smarty/libs/Smarty.class.php");
require("./mysql.php");
require("./FCKeditor/fckeditor.php");
$action=$_REQUEST["action"];
//定义一个函数用于调用FCK
function editor($input_name, $input_value)
{
global $smarty;
$editor = new FCKeditor($input_name) ;
$editor->BasePath = "./FCKeditor/";//指定编辑器路径
$editor->ToolbarSet = "Default";//编辑器工具栏有Basic(基本工具),Default(所有工具)选择
$editor->Width = "100%";
$editor->Height = "320";
$editor->Value = $input_value;
$editor->Config["AutoDetectLanguage"] = true ;
$editor->Config["DefaultLanguage"] = "en" ;//语言
$FCKeditor = $editor->CreateHtml();
$smarty->assign("editor", $FCKeditor);//指定区域
}
switch ($action){
case "addnewsview":
$smarty= new Smarty();
$smarty->template_dir = "./template";
$smarty->compile_dir = "./smarty/templates_c";
$smarty->assign("page_title","新建新闻");
$smarty->assign("actionvalue","addnews");
editor("content","");//调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST["content"]对应
$smarty->display("addnews.htm");
break;
case "addnews":
$title=$_REQUEST["title"];
$content=$_REQUEST["content"];
$db=new mysql();
$button=$_REQUEST["Submit"];
if(empty($title) || empty($content)){
echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}else{
$sql="insert into news values(id,"admin","$title","$content",NOW())";
$db->query_exec($sql);
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
break;
case "editnewsview":
$smarty= new Smarty();
$smarty->template_dir = "./template";
$smarty->compile_dir = "./smarty/templates_c";
$smarty->assign("page_title","修改新闻");
$smarty->assign("actionvalue","addnews");
$id=$_REQUEST["id"];
$query="select * from news where id=$id";
$db=new mysql();
$result = $db->query_exec($query);
$rs = $result-> fetch_assoc();
$smarty->assign("title",$rs["title"]);
//$smarty->assign("content",$rs["content"]);
$smarty->assign("actionvalue","editnews");
$smarty->assign("id",$rs["id"]);
editor("content",$rs["content"]);
$smarty->display("addnews.htm");
break;
case "editnews":
$title=$_REQUEST["title"];
$content=$_REQUEST["content"];
$id=$_REQUEST["id"];
$button=$_REQUEST["Submit"];
$db=new mysql();
if ($button=="提交"){
$sql="update news set title="$title",content="$content",date=NOW() where id=$id";
$db->query_exec($sql);
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
break;
case "delnews":
$db=new mysql();
if ($checkbox!="" or count($checkbox)!=0) {
for ($i=0;$i<count($checkbox);$i++){
$db->query_exec("delete from news where id="$checkbox[$i]"");
}
}
echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
break;
default:
$smarty= new Smarty();
$smarty->template_dir = "./template";
$smarty->compile_dir = "./smarty/templates_c";
$smarty->assign("page_title","新闻管理");
$smarty->assign("actionvalue","delnews");
$query="select * from news";
$db=new mysql();
$result = $db->query_exec($query);
while ($rs = $result-> fetch_assoc()) {
$array[]= array("id"=>$rs["id"], "title"=>$rs["title"],"date"=>$rs["date"]);
$smarty->assign("news",$array);
}
$smarty->display("index.htm");
}
?>
以下是模板文件index.htm的内容
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$page_title}</title>
</head>
<body>
<p class="style1">新闻管理</p>
<hr>
<table width="771" height="115" border="0">
<tr>
<td height="62"><div align="center">系统管理</div></td>
<td width="666" rowspan="2"><form name="form1" method="post" action="">
<table width="543" border="0">
<tr>
<td width="253">标题</td>
<td width="230">日期</td>
<td width="46">选择</td>
</tr>
{section name=news loop=$news}
<tr>
<td><a href="./index.php?action=editnewsview&id={$news[news].id}">{$news[news].title}</a></td>
<td>{$news[news].date}</td>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="{$news[news].id}"></td>
</tr>
{/section}
</table>
<p>
<input type="submit" name="Submit" value="删除">
<input name="action" type="hidden" id="action" value="{$actionvalue}">
</p>
</form> </td>
</tr>
<tr>
<td width="95" height="47"><div align="center"><a href="./index.php?action=addnewsview">添加新闻</a></div></td>
</tr>
</table>
<p class="style1"> </p>
</body>
</html>
以下是添加新闻的模板文件addnews.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="./css/a.css" rel="stylesheet" type="text/css">
<title>{$page_title}</title>
</head>
<body>
<p class="style1">新闻管理登陆 </p>
<hr>
<table width="771" height="501" border="0">
<tr>
<td height="62"><div align="center">系统管理</div></td>
<td width="666" rowspan="2"><form name="form1" method="post" action="index.php">
<p>标题
<input name="title" type="text" id="title" value="{$title}">
</p>
<p>内容:</p>
<p>{$editor}</p>
<p>
<input type="submit" name="Submit" value="提交">
<input type="hidden" name="action" value={$actionvalue}>
<input name="id" type="hidden" value="{$id}">
</p>
</form>
</td>
</tr>
<tr>
<td width="95" height="433"><div align="center">添加新闻</div></td>
</tr>
</table>
</body>
</html>
注:数据库已经在附件里面,先新建一个名为new的数据库,再把表导入
本系统用户名:admin 密码:admin
下载文件
年终聚餐了
Submitted by on 2007, February 10, 5:37 PM
VBS中使用Try——Catch
Submitted by on 2007, February 9, 5:17 PM
值得一看
[html]<script language="vbscript">
function Test(a,b)
Test = a/b
end function
</script>
<script language="javascript">
try
{
alert(Test(6,0));
}
catch(e)
{
alert(e.message);
}
</script> [/html]
[html]<script language="vbscript">
function Test(a,b)
Test = a/b
end function
</script>
<script language="javascript">
try
{
alert(Test(6,0));
}
catch(e)
{
alert(e.message);
}
</script> [/html]
VBScript实现的ASP模板类(未测试)
Submitted by on 2007, February 3, 7:22 PM
<%
" 档案名称:cls_MyTemplate.asp
" 原创作者:胡传照
Class MyTemplate
Private m_strError " 出错信息
Private m_strVersion " 版本号
Private m_strVersionName " 版本名称
Private m_strClassName " 类的名称
Private mvarTplPath "As Variant "local copy
Private objDic "As Scripting.Dictionary "local copy
" 类初始化
Private Sub Class_Initialize()
m_strError = ""
m_strVersion = "0.1"
m_strVersionName = "Alpha 0.1版"
m_strClassName = ""
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = vbTextCompare
End Sub
" 类释放
Private Sub Class_Terminate()
Set Dic = Nothing
m_strError = ""
m_strVersion = ""
m_strVersionName = ""
m_strName = ""
End Sub
"-----读写各个属性---------------------------
Public Property Get ClassName()
ClassName = m_strClassName
End Property
Public Property Let ClassName(strName)
m_strClassName = strName
End Property
"-----------------------------------------------
" 获取错误信息
Public Function GetLastError()
GetLastError = m_strError
End Function
" 私有方法,添加错误信息
Private Sub AddErr(strEcho)
m_strError = m_strError + "<Div CLASS=""alert"">" & strEcho & "</Div>"
End Sub
" 清除错误信息
Public Function ClearError()
m_strError = ""
End Function
Public Function Parse(varName) " As String) As String
Dim mc "As MatchCollection
Dim m "As Match
"Dim sms "As SubMatches
Dim i
If Dic.Item(varName) = Empty Then
Parse = ""
Else
Dim reg "As RegExp
Set reg = New RegExp
reg.Global = True
reg.MultiLine = True
reg.IgnoreCase = True
reg.Pattern = "{(\w*)}"
Dim strResult "As String
strResult = Dic.Item(varName)
Set mc = reg.Execute(strResult)
If mc.Count >= 1 Then
For i = 0 To mc.Count - 1
Set m = mc.Item(i)
Key = Mid(m.Value, 2, Len(m.Value) - 2)
reg.Pattern = m.Value
If Not IsEmpty(Dic.Item(Key)) Then
strResult = reg.Replace(strResult, Dic.Item(Key))
End If
Set m = Nothing
Next
End If
Set mc = Nothing
Set reg = Nothing
Parse = strResult
End If
End Function
Public Sub SplitVars(varName) "As String)
Dim lenth "As Integer
Dim mc "As MatchCollection
Dim m "As Match
Dim sms "As SubMatches
"Response.Write "test " & varname &"<br>"
If Dic.Item(varName) = Empty Then
Response.Write varname &" is empty"
Exit Sub
End If
Dim Template_Exp "As RegExp
Set Template_Exp = New RegExp
"Template_Exp.Global = True
Template_Exp.IgnoreCase = True
"<!--#TPLDEF +(\w*) *-->((.|\n)*)<!--#TPLEND+\1 *-->
"<!--#TPLDEF +(\w*) *-->((.|\n)*)<!--#TPLEND +\1 *-->
Template_Exp.Pattern = "<!--#TPLDEF +(\w*) *-->((.|\n)*)<!--#TPLEND +\1 *-->"
While Template_Exp.Test(Dic.Item(varName)) <> False
Set mc = Template_Exp.Execute(Dic.Item(varName))
If mc.Count >= 1 Then
"mc.Item(0) = mc.Item(1)
For Each m In mc
"r = r & m.Value & vbNewLine
Set sms = m.SubMatches
" For j = 0 To sms.Count - 1
" r = r & sms.Item(j) & vbNewLine
" Next j
Dic.Item(sms.Item(0)) = sms.Item(1)
Next " m
"MsgBox r
End If
s = "{" & sms.Item(0) & "}"
"MsgBox s
Dic.Item(varName) = Template_Exp.Replace(Dic.Item(varName), s)
" MsgBox Dic.Item(varName), , "Dic.Item(varName)"
s = sms.Item(0)
Set sms = Nothing
Set mc = Nothing
SplitVars (s)
"Set Template_Exp = Nothing
Wend
End Sub
Public Sub LoadFile(varName, filename) "(varName As String, filename As String)
Dim fso "As Scripting.FileSystemObject
Set fso = Server.CreateObject("Scripting.FileSystemObject") "New FileSystemObject
Dim Pathfile "As String
Pathfile = fso.BuildPath(TplPath, filename)
Response.Write Server.MapPath(Pathfile) & "<br>"
If fso.FileExists(Server.MapPath(Pathfile)) Then
Set f = fso.OpenTextFile(Server.MapPath(Pathfile), 1)
Dic.RemoveAll
Dic.Item(varName) = f.ReadAll()
Response.Write "Dic.Item("& varName&")="
Response.Write "laod file success "
Set f = Nothing
else
Response.Write Pathfile & " ----Do not Exist<br>"
Response.Write "load file faild"
End If
Pathfile = ""
Set fso = Nothing
End Sub
Public Sub LoadAccess(varName, TemplateName) "(varName As String, TemplateName As String)
sqlTemplate = "Select * From Template Where TemplateName="" & TemplateName & """
"Response.Write sqlTemplate
If Not IsObject(Conn) Then
DBPath = "./"
DBFile = "data/BlogData.mdb"
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""& DbPath & "" & DbFile & "")
"Response.Write ConnStr
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.open ConnStr
If Err Then
Err.Clear
Set Conn = Nothing
AddErr "数据库连接出错,请检查连接字串。"
Response.Write GetLastError
"Response.Write Err
Dic.Item(varName) = "加载数据失败,请检查数据库连接是否正确"
"Response.End
End If
End If
Set rsTemplate = Server.CreateObject("Adodb.Recordset")
rsTemplate.Open sqlTemplate, Conn, 1, 1
Dic.Item(varName) = rsTemplate("TemplateHtml")
rsTemplate.Close
Set rsTemplate = Nothing
End Sub
Public Property Let TplPath(vData) "(ByVal vData) "As Variant)
mvarTplPath = vData
End Property
"Public Property Set TplPath(vData)"(ByVal vData) "As Variant)
" Set mvarTplPath = vData
"End Property
Public Property Get TplPath() "As Variant
"If IsObject(mvarTplPath) Then
" Set TplPath = mvarTplPath
"Else
TplPath = mvarTplPath
"End If
End Property
"Public Property Let Dic(vData)"(ByVal vData) "As Variant)
" objDic = vData
"End Property
Public Property Set Dic(vData) "(ByVal vData) "As Variant)
Set objDic = vData
End Property
Public Property Get Dic() "As Variant
If IsObject(objDic) Then
"a=objDic.Keys
"response.Write "In Dic there are " &cstr(objDic.count) & "Items<br>"
"for i=objDic.count-1 to 0 step -1
"response.Write "Index "&CStr(i)&"-" & a(i) & ":" & objDic.Item(a(i))& "<br>--------------------------------------<br>"
"response.Write a(i) & vbNewline
"
"next
Set Dic = objDic
Else
Dic = objDic
End If
End Property
End Class
%>
调试的时候使用了VB来调试,所以里面有很多VB的代码,但是都注释掉了,不影响使用。
使用和沐风的那个差不多。
例子:
<!--#include file="cls_MyTemplate.asp"-->
Dim tpl "As MyTemplate
Set tpl = New MyTemplate
tpl.TplPath = "E:\Webs\hublog\template"
"tpl.LoadFile "Main", "blogview.htm"
tpl.LoadAccess "Main","default"
TplLoadTimes=TplLoadTimes+1
tpl.SplitVars ("Main")
"a=tpl.Dic.Keys
"response.Write "ssssssssssssssssssssssssssssssssssssssssssssss"
"for i=tpl.Dic.count-1 to 0 step -1
"response.Write a(i)
"response.Write "::::--->>><br>" & tpl.dic.Item(a(i))& "<br>--------------------------------------<br>"
"response.Write a(i) & vbNewline
"tpl.Dic.Item(a(i))=tpl.Parse(a(i))
"next
Dim ss
"tpl.Dic.Item("TITLE") =tpl.Parse("TITLE")
ss = objMyBlogArticle.Title
tpl.Dic.Item("TITLE") =CheckEmptyStr(ss,"标题未设置")
"tpl.Dic.Item("AUTHOR") =tpl.Parse("AUTHOR")
ss = objMyBlogArticle.Author
tpl.Dic.Item("AUTHOR") = CheckEmptyStr(ss,"作者不详")
"tpl.Dic.Item("CONTENT") = tpl.Parse("CONTENT")
ss = objMyBlogArticle.Content
tpl.Dic.Item("CONTENT") = CheckEmptyStr(ss,"请更新数据")
"tpl.Dic.Item("POSTTIME") = tpl.Parse("POSTTIME")
ss = objMyBlogArticle.PostTime
tpl.Dic.Item("POSTTIME") =CheckEmptyStr(ss,"请更新数据")
tpl.Dic.Item("ARTICLE") = tpl.Parse("ARTICLE")
"response.Write tpl.Parse("TITLE")
"response.Write tpl.Parse("ARTICLE")
response.Write tpl.Parse("Main")
Set tpl = Nothing
else
Response.Write "文章不存在!"
End if
Set objMyBlogArticle = Nothing%>
----------------------------
blogview.htm自己去填,有时间的话我再贴上来,没时间就算了
loadaccess中的tpl.LoadAccess "Main","default",default是一个模版的名字,内容是blogview.htm
" 档案名称:cls_MyTemplate.asp
" 原创作者:胡传照
Class MyTemplate
Private m_strError " 出错信息
Private m_strVersion " 版本号
Private m_strVersionName " 版本名称
Private m_strClassName " 类的名称
Private mvarTplPath "As Variant "local copy
Private objDic "As Scripting.Dictionary "local copy
" 类初始化
Private Sub Class_Initialize()
m_strError = ""
m_strVersion = "0.1"
m_strVersionName = "Alpha 0.1版"
m_strClassName = ""
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = vbTextCompare
End Sub
" 类释放
Private Sub Class_Terminate()
Set Dic = Nothing
m_strError = ""
m_strVersion = ""
m_strVersionName = ""
m_strName = ""
End Sub
"-----读写各个属性---------------------------
Public Property Get ClassName()
ClassName = m_strClassName
End Property
Public Property Let ClassName(strName)
m_strClassName = strName
End Property
"-----------------------------------------------
" 获取错误信息
Public Function GetLastError()
GetLastError = m_strError
End Function
" 私有方法,添加错误信息
Private Sub AddErr(strEcho)
m_strError = m_strError + "<Div CLASS=""alert"">" & strEcho & "</Div>"
End Sub
" 清除错误信息
Public Function ClearError()
m_strError = ""
End Function
Public Function Parse(varName) " As String) As String
Dim mc "As MatchCollection
Dim m "As Match
"Dim sms "As SubMatches
Dim i
If Dic.Item(varName) = Empty Then
Parse = ""
Else
Dim reg "As RegExp
Set reg = New RegExp
reg.Global = True
reg.MultiLine = True
reg.IgnoreCase = True
reg.Pattern = "{(\w*)}"
Dim strResult "As String
strResult = Dic.Item(varName)
Set mc = reg.Execute(strResult)
If mc.Count >= 1 Then
For i = 0 To mc.Count - 1
Set m = mc.Item(i)
Key = Mid(m.Value, 2, Len(m.Value) - 2)
reg.Pattern = m.Value
If Not IsEmpty(Dic.Item(Key)) Then
strResult = reg.Replace(strResult, Dic.Item(Key))
End If
Set m = Nothing
Next
End If
Set mc = Nothing
Set reg = Nothing
Parse = strResult
End If
End Function
Public Sub SplitVars(varName) "As String)
Dim lenth "As Integer
Dim mc "As MatchCollection
Dim m "As Match
Dim sms "As SubMatches
"Response.Write "test " & varname &"<br>"
If Dic.Item(varName) = Empty Then
Response.Write varname &" is empty"
Exit Sub
End If
Dim Template_Exp "As RegExp
Set Template_Exp = New RegExp
"Template_Exp.Global = True
Template_Exp.IgnoreCase = True
"<!--#TPLDEF +(\w*) *-->((.|\n)*)<!--#TPLEND+\1 *-->
"<!--#TPLDEF +(\w*) *-->((.|\n)*)<!--#TPLEND +\1 *-->
Template_Exp.Pattern = "<!--#TPLDEF +(\w*) *-->((.|\n)*)<!--#TPLEND +\1 *-->"
While Template_Exp.Test(Dic.Item(varName)) <> False
Set mc = Template_Exp.Execute(Dic.Item(varName))
If mc.Count >= 1 Then
"mc.Item(0) = mc.Item(1)
For Each m In mc
"r = r & m.Value & vbNewLine
Set sms = m.SubMatches
" For j = 0 To sms.Count - 1
" r = r & sms.Item(j) & vbNewLine
" Next j
Dic.Item(sms.Item(0)) = sms.Item(1)
Next " m
"MsgBox r
End If
s = "{" & sms.Item(0) & "}"
"MsgBox s
Dic.Item(varName) = Template_Exp.Replace(Dic.Item(varName), s)
" MsgBox Dic.Item(varName), , "Dic.Item(varName)"
s = sms.Item(0)
Set sms = Nothing
Set mc = Nothing
SplitVars (s)
"Set Template_Exp = Nothing
Wend
End Sub
Public Sub LoadFile(varName, filename) "(varName As String, filename As String)
Dim fso "As Scripting.FileSystemObject
Set fso = Server.CreateObject("Scripting.FileSystemObject") "New FileSystemObject
Dim Pathfile "As String
Pathfile = fso.BuildPath(TplPath, filename)
Response.Write Server.MapPath(Pathfile) & "<br>"
If fso.FileExists(Server.MapPath(Pathfile)) Then
Set f = fso.OpenTextFile(Server.MapPath(Pathfile), 1)
Dic.RemoveAll
Dic.Item(varName) = f.ReadAll()
Response.Write "Dic.Item("& varName&")="
Response.Write "laod file success "
Set f = Nothing
else
Response.Write Pathfile & " ----Do not Exist<br>"
Response.Write "load file faild"
End If
Pathfile = ""
Set fso = Nothing
End Sub
Public Sub LoadAccess(varName, TemplateName) "(varName As String, TemplateName As String)
sqlTemplate = "Select * From Template Where TemplateName="" & TemplateName & """
"Response.Write sqlTemplate
If Not IsObject(Conn) Then
DBPath = "./"
DBFile = "data/BlogData.mdb"
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""& DbPath & "" & DbFile & "")
"Response.Write ConnStr
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.open ConnStr
If Err Then
Err.Clear
Set Conn = Nothing
AddErr "数据库连接出错,请检查连接字串。"
Response.Write GetLastError
"Response.Write Err
Dic.Item(varName) = "加载数据失败,请检查数据库连接是否正确"
"Response.End
End If
End If
Set rsTemplate = Server.CreateObject("Adodb.Recordset")
rsTemplate.Open sqlTemplate, Conn, 1, 1
Dic.Item(varName) = rsTemplate("TemplateHtml")
rsTemplate.Close
Set rsTemplate = Nothing
End Sub
Public Property Let TplPath(vData) "(ByVal vData) "As Variant)
mvarTplPath = vData
End Property
"Public Property Set TplPath(vData)"(ByVal vData) "As Variant)
" Set mvarTplPath = vData
"End Property
Public Property Get TplPath() "As Variant
"If IsObject(mvarTplPath) Then
" Set TplPath = mvarTplPath
"Else
TplPath = mvarTplPath
"End If
End Property
"Public Property Let Dic(vData)"(ByVal vData) "As Variant)
" objDic = vData
"End Property
Public Property Set Dic(vData) "(ByVal vData) "As Variant)
Set objDic = vData
End Property
Public Property Get Dic() "As Variant
If IsObject(objDic) Then
"a=objDic.Keys
"response.Write "In Dic there are " &cstr(objDic.count) & "Items<br>"
"for i=objDic.count-1 to 0 step -1
"response.Write "Index "&CStr(i)&"-" & a(i) & ":" & objDic.Item(a(i))& "<br>--------------------------------------<br>"
"response.Write a(i) & vbNewline
"
"next
Set Dic = objDic
Else
Dic = objDic
End If
End Property
End Class
%>
调试的时候使用了VB来调试,所以里面有很多VB的代码,但是都注释掉了,不影响使用。
使用和沐风的那个差不多。
例子:
<!--#include file="cls_MyTemplate.asp"-->
Dim tpl "As MyTemplate
Set tpl = New MyTemplate
tpl.TplPath = "E:\Webs\hublog\template"
"tpl.LoadFile "Main", "blogview.htm"
tpl.LoadAccess "Main","default"
TplLoadTimes=TplLoadTimes+1
tpl.SplitVars ("Main")
"a=tpl.Dic.Keys
"response.Write "ssssssssssssssssssssssssssssssssssssssssssssss"
"for i=tpl.Dic.count-1 to 0 step -1
"response.Write a(i)
"response.Write "::::--->>><br>" & tpl.dic.Item(a(i))& "<br>--------------------------------------<br>"
"response.Write a(i) & vbNewline
"tpl.Dic.Item(a(i))=tpl.Parse(a(i))
"next
Dim ss
"tpl.Dic.Item("TITLE") =tpl.Parse("TITLE")
ss = objMyBlogArticle.Title
tpl.Dic.Item("TITLE") =CheckEmptyStr(ss,"标题未设置")
"tpl.Dic.Item("AUTHOR") =tpl.Parse("AUTHOR")
ss = objMyBlogArticle.Author
tpl.Dic.Item("AUTHOR") = CheckEmptyStr(ss,"作者不详")
"tpl.Dic.Item("CONTENT") = tpl.Parse("CONTENT")
ss = objMyBlogArticle.Content
tpl.Dic.Item("CONTENT") = CheckEmptyStr(ss,"请更新数据")
"tpl.Dic.Item("POSTTIME") = tpl.Parse("POSTTIME")
ss = objMyBlogArticle.PostTime
tpl.Dic.Item("POSTTIME") =CheckEmptyStr(ss,"请更新数据")
tpl.Dic.Item("ARTICLE") = tpl.Parse("ARTICLE")
"response.Write tpl.Parse("TITLE")
"response.Write tpl.Parse("ARTICLE")
response.Write tpl.Parse("Main")
Set tpl = Nothing
else
Response.Write "文章不存在!"
End if
Set objMyBlogArticle = Nothing%>
----------------------------
blogview.htm自己去填,有时间的话我再贴上来,没时间就算了
loadaccess中的tpl.LoadAccess "Main","default",default是一个模版的名字,内容是blogview.htm
实现只下载的asp代码
Submitted by on 2007, February 3, 7:04 PM
贴代码啰:
| 代码: |
| if Request("Filename")="" then
response.write "<h1>Error:</h1>Filename is empty!<p>" else call downloadFile(replace(replace(Request("Filename"),"\",""),"/","")) end if Function downloadFile(strFile) strFilename = server.MapPath(strFile) Response.Buffer = True Response.Clear Set s = Server.CreateObject("ADODB.Stream") s.Open "Set as binary s.Type = 1 "load in the file on error resume next "check the file exists Set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.FileExists(strFilename) then Response.Write("<h1>Error:</h1>"&strFilename&" does not exists!<p>") Response.End end if "get length of file Set f = fso.GetFile(strFilename) intFilelength = f.size s.LoadFromFile(strFilename) if err then Response.Write("<h1>Error: </h1>Unknown Error!<p>") Response.End end if "send the headers to the users Browse Response.AddHeader "Content-Disposition","attachment; filename="&f.name Response.AddHeader "Content-Length",intFilelength Response.CharSet = "UTF-8" Response.ContentType = "application/octet-stream" "output the file to the browser Response.BinaryWrite s.Read Response.Flush "tidy up s.Close Set s = Nothing End Function |
PHP+ACCESS写的客户回访系统收尾总结
Submitted by on 2007, February 2, 1:23 AM
功能预期:
客户列表
客户的添加、修改
客户回访列表
添加回访
伪删除
修改密码
帐号管理
技术攻关:
php访问ACCESS
php+access的分页
心得体会:
句末的分号易忘
变量的$易忘
属性,方法用"->"操作
用"."连接字串
{}要配对.
php和ACCESS搭配,在刚接触的时候,真的很是别扭。不过很快就会慢慢习惯。习惯了就和ASP+ACCESS,差不多了。在分页时比较麻烦一些,没有PHP+MYSQL方便。还是和ASP一样用ado的recordcount,pagesize,absolutepage……
php出错时的提示,没有asp可靠。因为asp是一句一行,故而比较可信。而php因为是一分号结束一句,所以在我们因为丢失分号的时候出错,往往提示就不准确。偶曾盯着一行没有问题的句子好半天,没有找到问题。汗死!下次碰到这样的问题时,直接慢慢的从头往下看。
客户列表
客户的添加、修改
客户回访列表
添加回访
伪删除
修改密码
帐号管理
技术攻关:
php访问ACCESS
php+access的分页
心得体会:
句末的分号易忘
变量的$易忘
属性,方法用"->"操作
用"."连接字串
{}要配对.
php和ACCESS搭配,在刚接触的时候,真的很是别扭。不过很快就会慢慢习惯。习惯了就和ASP+ACCESS,差不多了。在分页时比较麻烦一些,没有PHP+MYSQL方便。还是和ASP一样用ado的recordcount,pagesize,absolutepage……
php出错时的提示,没有asp可靠。因为asp是一句一行,故而比较可信。而php因为是一分号结束一句,所以在我们因为丢失分号的时候出错,往往提示就不准确。偶曾盯着一行没有问题的句子好半天,没有找到问题。汗死!下次碰到这样的问题时,直接慢慢的从头往下看。






