📄 managedocument.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Zeroone.FileSystem;
using Zeroone;
using Zeroone.Framework.Jobs;
using System.Xml;
using System.IO;
public partial class Admin_ManageDocument : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//get urlReferrer
if (Context.Request.UrlReferrer != null)
{
string strUrlReferrer = Context.Request.UrlReferrer.ToString();
ViewState["urlReferrer"] = strUrlReferrer;
}
//get queryString value
ViewState["path"] = Zeroone.FileSystem.Path.CheckRepairPath(Request.QueryString["path"]);
ViewState["dataProviderAction"] = Request.QueryString["action"];
ViewState["name"] = Request.QueryString["name"];
string path = ViewState["path"].ToString();
string dataProviderAction = ViewState["dataProviderAction"].ToString();
string name = ViewState["name"] == null ? null : ViewState["name"].ToString();
#region romove audit
//string removeAuditPath = path;
//if (path.StartsWith(CategoryController.SystemAuditPath))
//{
// if (path.Length > CategoryController.SystemAuditPath.Length)
// {
// int length = CategoryController.SystemAuditPath.Length;
// removeAuditPath = path.Substring(length - 1);
// }
// else
// {
// removeAuditPath = "/";
// }
//}
//ViewState["removeAuditPath"] = removeAuditPath;
#endregion
//实例化文档类型
cblTypes.DataSource = TypeController.GetTypes(path);
cblTypes.DataBind();
//Setting custom property
customPropertyValues.Path = path;
customPropertyValues.Name = name;
//初始化页
if (dataProviderAction.ToLower() == "update")
{
Document d = DocumentController.GetDocument(path, name);
tbSubject.Text = d.Subject;
tbName.Text = d.Name;
tbContent.Value = d.Content;
//cbApproved.Checked = d.Path.StartsWith(CategoryController.SystemAuditPath) ? false : true;
// select types
TypeCollection types = TypeController.GetTypesForDocument(d.DocumentID);
foreach (TypeInfo type in types)
{
foreach (ListItem item in cblTypes.Items)
{
if (type.Name == item.Value)
{
item.Selected = true;
}
}
}
//update button
this.btnManage.Text = "更新";
//分页
rptPages.DataSource = d.GetPages();
rptPages.DataBind();
}
else if (dataProviderAction.ToLower() == "insert")
{
this.btnManage.Text = "添加";
}
}
}
protected void btnManage_Click(object sender, EventArgs e)
{
//get queryString value
string path = ViewState["path"].ToString();
string dataProviderAction = ViewState["dataProviderAction"].ToString();
string name = ViewState["name"] == null ? null : ViewState["name"].ToString();
//string removeAuditPath = ViewState["removeAuditPath"].ToString();
//if (!cbApproved.Checked)
//{
// if (!path.StartsWith(CategoryController.SystemAuditPath))
// {
// path = CategoryController.SystemAuditPath + path.Substring(1);
// CategoryController.CreateDirectory(path);
// }
//}
//构造document类
Document d;
if (dataProviderAction.ToLower() == "insert")
{
d = new Document();
d.Subject = tbSubject.Text;
d.Name = tbName.Text.Trim().Replace(" ","-");
d.Content = tbContent.Value;
d.Path = path;
d.SetPropertyValues(customPropertyValues.Values);
d.Create();
}
//如果dataProviderAction为update则执行下面的语句
else
{
d = DocumentController.GetDocument(ViewState["path"].ToString(), name);
d.Subject = tbSubject.Text;
d.Name = tbName.Text.Trim().Replace(" ", "-");
d.Content = tbContent.Value;
//d.Path = cbApproved.Checked ? removeAuditPath : path;
d.SetPropertyValues(customPropertyValues.Values);
d.Update();
//----------更新该文档的评论栏目路径、分页栏目路径---------
//首先判断该文档的名称是否改变,如果没改变就不用更新文档的评论栏目路径、分页栏目路径
if ((d.Name != name) || (d.Path != path))
{
string oldPath = path + name + "/";
string updatePath = d.Path + d.Name + "/";
//判断是否是未审核文档
//if (updatePath.StartsWith(CategoryController.SystemAuditPath))
//{
// updatePath = updatePath.Substring(CategoryController.SystemAuditPath.Length - 1);
//}
//判断该文档是否有分页,如果有那么将该文档的分页栏目路径更新
oldPath = CategoryController.SystemPagesPath + oldPath.Substring(1);
updatePath = CategoryController.SystemPagesPath + updatePath.Substring(1);
if (CategoryController.Exists(oldPath))
{
Category c = CategoryController.GetCategory(oldPath);
c.Path = updatePath;
c.Update();
}
//判断该文档是否有评论信息
oldPath = CategoryController.SystemCommentPath + oldPath.Substring(CategoryController.SystemPagesPath.Length);
updatePath = CategoryController.SystemCommentPath + updatePath.Substring(CategoryController.SystemPagesPath.Length);
if (CategoryController.Exists(oldPath))
{
Category c = CategoryController.GetCategory(oldPath);
c.Path = updatePath;
c.Update();
}
//--------------------------------------------
}
//-----------维护索引---------------------
JobsConfiguration jobsConfig = JobsConfiguration.GetJobsConfiguration();
foreach (XmlNode jobNode in jobsConfig.JobsList)
{
if (jobNode.NodeType != XmlNodeType.Comment)
{
XmlAttribute pathAttribute = jobNode.Attributes["path"];
if (pathAttribute != null)
{
string indexFileDirectory = Context.Request.PhysicalApplicationPath + "zeroone_searchIndexFile" + pathAttribute.Value + "indexFiles";
if (File.Exists(indexFileDirectory + "\\segments"))
{
string indexCategoryPath = pathAttribute.Value;
if (path.StartsWith(indexCategoryPath))
Zeroone.Data.DocumentDataProvider.Instance().Indexer_AddDocument(d.DocumentID, indexCategoryPath);
}
}
}
}
//------------------------------------
}
//add document to type
TypeController.ClearDocumentTypes(d.DocumentID);
foreach (ListItem item in cblTypes.Items)
{
if (item.Selected)
{
TypeInfo type = TypeController.GetType(path, item.Value);
TypeController.AddDocumentToType(d.DocumentID, type.TypeID);
}
}
//if (ViewState["urlReferrer"] == null)
//{
Response.Redirect(Globals.ApplicationPath + "/admin" + path + "DocumentsList.aspx");
//}
//else
//{
// Response.Redirect(ViewState["urlReferrer"].ToString());
//}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
if (ViewState["urlReferrer"] == null)
{
Response.Redirect(Globals.ApplicationPath + "/admin" + ViewState["path"].ToString() + "DocumentsList.aspx");
}
else
{
Response.Redirect(ViewState["urlReferrer"].ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -