protected void Button1_Click(object sender, EventArgs e) { TemplateInfo info = new TemplateInfo(); info.title = title.Text.ToString(); info.filePath = filePath.Text.ToString(); info.activePath = activePath.Text.ToString(); info.templatePath = templatePath.Text.ToString(); info.content = contentDetail.Text.ToString(); info.typeId = templateid; TemplateDal te = new TemplateDal(); if (app == "edit") { te.Update(info, getId("id")); te.saveFile(info.templatePath, info.content); showMessage("修改成功", "templatefile_list.aspx?templateid="+templateid); } else { te.add(info); te.saveFile(info.templatePath, info.content); showMessage("添加成功","templatefile_list.aspx?templateid="+templateid); } }
//读取模板内容 public TemplateInfo read(int id) { DataSet ds = getData("select * from "+tableName+" where id=" + id); DataRow dr = ds.Tables[0].Rows[0]; TemplateInfo info = new TemplateInfo(); info.id = id; info.title = dr["title"].ToString(); info.content = dr["content"].ToString(); info.filePath = dr["filePath"].ToString(); info.activePath = dr["activePath"].ToString(); info.templatePath = dr["templatePath"].ToString(); return info; }
//修改模板文件 public void Update(TemplateInfo info,int id) { string sql = "update " + tableName + " set title = @title,filePath = @filePath,activePath=@activePath,templatePath = @templatePath,content=@content where id = @id"; ExecuteDataSet(sql, "@title",2,50,info.title, "@filePath", 2, 50, info.filePath, "@activePath",2,50,info.activePath, "@templatePath", 2, 50, info.templatePath, "@content", 2, info.content.Length, info.content, "@id",1,8,id ); //saveFile(info.templatePath, info.content); //同时保存 //saveFile(info.filePath, info.content); }
/// <summary> /// 添加新页面 /// </summary> /// <param name="info"></param> /// <returns></returns> public int add(TemplateInfo info) { int tid = add(tableName, "title", 2, 50, info.title, "filePath", 2, 50, info.filePath, "activePath", 2, 50, info.activePath, "templatePath", 2, 50, info.templatePath, "content", 2, info.content.Length, info.content, "typeId",1,8,info.typeId ); //保存模板文件 //saveFile(info.templatePath, info.content); //保存静态文件 //saveFile(info.filePath, info.content); return tid; }
protected void Page_Load(object sender, EventArgs e) { templateid = getId("templateid"); app = gform("do"); if (!IsPostBack) { if (app == "edit") { TemplateDal te = new TemplateDal(); TemplateInfo info = new TemplateInfo(); info = te.read(getId("id")); contentDetail.Text = info.content; title.Text = info.title; filePath.Text = info.filePath; activePath.Text = info.activePath; templatePath.Text = info.templatePath; } } }
private void init(TemplateInfo info) { templatestr = open(info.templatePath); info.content = templatestr; string filename = subfilename(info.activePath); Template tl = new Template(info); tl.do_include(); tl.do_var(); tl.do_if(); tl.do_loop(); tl.do_foreach(); tl.do_write(); tl.do_assign(); //... tl.do_display(filename); TemplateInfo value = tl.getvalue(); templatestr = value.content; fwrite(info.activePath, templatestr); }
//private TemplateInfo j_info; public do_template(TemplateInfo info):base(new TemplateInfo()) { j_info = info; }
public Template(TemplateInfo info) { j_info = info; }
public TemplateAdmin(TemplateInfo info) { new TemplateCompiled(info); }
public TemplateCompiled(TemplateInfo info) { init(info); }