protected void Page_Load(object sender, EventArgs e) { IncludeFileInfo includeFileInfoById = IncludeFile.GetIncludeFileInfoById(BasePage.RequestInt32("id")); if (!includeFileInfoById.IsNull) { this.LitName.Text = includeFileInfoById.Name; switch (includeFileInfoById.IncludeType) { case IncludeType.None: return; case IncludeType.JSWriteHtml: case IncludeType.JS: this.LitPreview.Text = "<script type=\"text/javascript\" src=\"" + base.BasePath + SiteConfig.SiteOption.IncludeFilePath + "/" + includeFileInfoById.FileName + "\"></script>"; return; case IncludeType.Html: this.LitPreview.Text = "<iframe frameborder=\"0\" width=\"100%\" height=\"400px\" src=\"" + base.BasePath + SiteConfig.SiteOption.IncludeFilePath + "/" + includeFileInfoById.FileName + "\" scrolling=\"auto\" id=\"includeFile\"></iframe>"; return; } } else { AdminPage.WriteErrMsg("您修改的内嵌代码不存在!", "IncludeFileManage.aspx"); } }
private static bool CreateIncludeFile(IncludeFileInfo includeFileInfo) { if (includeFileInfo.IsNull) { return(false); } string includeFilePath = SiteConfig.SiteOption.IncludeFilePath; includeFilePath = "~/" + includeFilePath + "/" + includeFileInfo.FileName; includeFilePath = HttpContext.Current.Request.MapPath(includeFilePath); TemplateInfo templateInfo = new TemplateInfo(); templateInfo.QueryList = new NameValueCollection(); templateInfo.PageName = ""; templateInfo.TemplateContent = includeFileInfo.Template; templateInfo.RootPath = HttpContext.Current.Request.PhysicalApplicationPath; templateInfo.CurrentPage = 1; string templateContent = TemplateTransform.GetHtml(templateInfo).TemplateContent; if (includeFileInfo.IncludeType == IncludeType.JSWriteHtml) { templateContent = "document.write(\"" + DataSecurity.ConvertToJavaScript(templateContent) + "\")"; } FileSystemObject.WriteFile(includeFilePath, templateContent); return(true); }
public bool Add(IncludeFileInfo includeFileInfo) { Parameters parms = new Parameters(); parms.AddInParameter("@ID", DbType.Int32, DBHelper.GetMaxId("PE_IncludeFile", "ID") + 1); InitParameters(includeFileInfo, parms); return(DBHelper.ExecuteSql("INSERT INTO PE_IncludeFile (ID, Name, Description, IncludeType, AssociateType, FileName, Template) VALUES (@ID, @Name, @Description, @IncludeType, @AssociateType, @FileName, @Template)", parms)); }
public bool Update(IncludeFileInfo includeFileInfo) { Parameters parms = new Parameters(); parms.AddInParameter("@ID", DbType.Int32, includeFileInfo.Id); InitParameters(includeFileInfo, parms); return(DBHelper.ExecuteSql("UPDATE PE_IncludeFile SET Name = @Name, Description = @Description, IncludeType = @IncludeType, AssociateType = @AssociateType, FileName = @FileName, Template = @Template WHERE ID = @ID", parms)); }
private static void InitParameters(IncludeFileInfo includeFileInfo, Parameters parms) { parms.AddInParameter("@Name", DbType.String, includeFileInfo.Name); parms.AddInParameter("@Description", DbType.String, includeFileInfo.Description); parms.AddInParameter("@IncludeType", DbType.Int32, includeFileInfo.IncludeType); parms.AddInParameter("@FileName", DbType.String, includeFileInfo.FileName); parms.AddInParameter("@Template", DbType.String, includeFileInfo.Template); parms.AddInParameter("@AssociateType", DbType.Int32, includeFileInfo.AssociateType); }
private static IncludeFileInfo GetIncludeFileInfoFromDataReader(NullableDataReader dr) { IncludeFileInfo info = new IncludeFileInfo(); info.Id = dr.GetInt32("ID"); info.Name = dr.GetString("Name"); info.Description = dr.GetString("Description"); info.IncludeType = (IncludeType)dr.GetInt32("IncludeType"); info.AssociateType = (AssociateType)dr.GetInt32("AssociateType"); info.FileName = dr.GetString("FileName"); info.Template = dr.GetString("Template"); return(info); }
private void BindDataToControls() { IncludeFileInfo includeFileInfoById = IncludeFile.GetIncludeFileInfoById(BasePage.RequestInt32("id")); if (!includeFileInfoById.IsNull) { this.TxtName.Text = includeFileInfoById.Name; this.ViewState["Name"] = includeFileInfoById.Name; this.TxtDescription.Text = includeFileInfoById.Description; this.TxtFileName.Text = includeFileInfoById.FileName; this.ViewState["FileName"] = includeFileInfoById.FileName; this.RadlIncludeType.SelectedValue = Enum.GetName(typeof(IncludeType), includeFileInfoById.IncludeType); this.RadlAssociateType.SelectedValue = Enum.GetName(typeof(AssociateType), includeFileInfoById.AssociateType); this.TxtTemplate.Text = includeFileInfoById.Template; } else { AdminPage.WriteErrMsg("您修改的内嵌代码不存在!", "IncludeFileManage.aspx"); } }
protected void EgvIncludeFileList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { IncludeFileInfo dataItem = (IncludeFileInfo)e.Row.DataItem; TextBox box = (TextBox)e.Row.FindControl("TxtIncludeCode"); ExtendedLiteral literal = (ExtendedLiteral)e.Row.FindControl("LitFileName"); HyperLink link = (HyperLink)e.Row.FindControl("HlnkPreview"); string includeFilePath = SiteConfig.SiteOption.IncludeFilePath; includeFilePath = "~/" + includeFilePath + "/" + dataItem.FileName; FileInfo info2 = new FileInfo(HttpContext.Current.Request.MapPath(includeFilePath)); if (!info2.Exists) { ((LinkButton)e.Row.FindControl("LnkCreateIncludeFile")).Text = "生成"; literal.BeginTag = "<span style='color:red'>"; literal.Text = dataItem.FileName; literal.EndTag = "</span>"; link.Enabled = false; } else { literal.Text = dataItem.FileName; } switch (dataItem.IncludeType) { case IncludeType.JSWriteHtml: case IncludeType.JS: box.Text = "<script type=\"text/javascript\" src=\"{PE.SiteConfig.ApplicationPath /}{PE.SiteConfig.includefilepath /}/" + dataItem.FileName + "\"></script>"; return; case IncludeType.Html: box.Text = "<!--#include File=\"{PE.SiteConfig.ApplicationPath /}{PE.SiteConfig.includefilepath /}/" + dataItem.FileName + "\"-->"; return; default: return; } } }
public static bool Delete(int id) { IncludeFileInfo includeFileInfoById = GetIncludeFileInfoById(id); if (!includeFileInfoById.IsNull && dal.Delete(id)) { try { string includeFilePath = SiteConfig.SiteOption.IncludeFilePath; includeFilePath = "~/" + includeFilePath + "/" + includeFileInfoById.FileName; FileInfo info2 = new FileInfo(HttpContext.Current.Request.MapPath(includeFilePath)); if (info2.Exists) { info2.Delete(); } return(true); } catch (IOException) { return(true); } } return(false); }
public static bool Add(IncludeFileInfo includeFileInfo) { return(dal.Add(includeFileInfo)); }
public static bool Update(IncludeFileInfo includeFileInfo) { return(dal.Update(includeFileInfo)); }
protected void BtnSaveIncludeFile_Click(object sender, EventArgs e) { IncludeFileInfo includeFileInfo = new IncludeFileInfo(); includeFileInfo.Id = BasePage.RequestInt32("id"); includeFileInfo.Name = this.TxtName.Text; includeFileInfo.FileName = this.TxtFileName.Text; includeFileInfo.Description = this.TxtDescription.Text; includeFileInfo.Template = this.TxtTemplate.Text; includeFileInfo.IncludeType = (IncludeType)Enum.Parse(typeof(IncludeType), this.RadlIncludeType.SelectedValue); includeFileInfo.AssociateType = (AssociateType)Enum.Parse(typeof(AssociateType), this.RadlAssociateType.SelectedValue); if (BasePage.RequestStringToLower("action") == "modify") { if ((includeFileInfo.Name != this.ViewState["Name"].ToString()) && IncludeFile.ExistsName(includeFileInfo.Name)) { AdminPage.WriteErrMsg("内嵌代码名称已经存在"); } bool flag = string.Compare(includeFileInfo.FileName, this.ViewState["FileName"].ToString(), StringComparison.OrdinalIgnoreCase) != 0; if (flag && IncludeFile.ExistsFileName(includeFileInfo.FileName)) { AdminPage.WriteErrMsg("内嵌代码文件名已经存在"); } if (IncludeFile.Update(includeFileInfo)) { if (flag) { string includeFilePath = SiteConfig.SiteOption.IncludeFilePath; includeFilePath = "~/" + includeFilePath + "/" + this.ViewState["FileName"].ToString(); FileInfo info2 = new FileInfo(HttpContext.Current.Request.MapPath(includeFilePath)); if (info2.Exists) { info2.Delete(); } } AdminPage.WriteSuccessMsg("修改成功", "IncludeFileManage.aspx"); } else { AdminPage.WriteErrMsg("修改失败", "IncludeFileManage.aspx"); } } else { if (IncludeFile.ExistsName(includeFileInfo.Name)) { AdminPage.WriteErrMsg("内嵌代码名称已经存在"); } if (IncludeFile.ExistsFileName(includeFileInfo.FileName)) { AdminPage.WriteErrMsg("内嵌代码文件名已经存在"); } if (IncludeFile.Add(includeFileInfo)) { AdminPage.WriteSuccessMsg("添加成功", "IncludeFileManage.aspx"); } else { AdminPage.WriteErrMsg("添加失败", "IncludeFileManage.aspx"); } } }