📄 documentmanage.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 System.Data.SqlClient;
using DocumentManager;
using SQLHelper;
//5_1_a_s_p_x.c_o_m
public partial class DocumentManage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
///绑定控件的数据
BindCategoryData();
if (CategoryList.Items.Count > 0)
{
CategoryList.SelectedIndex = 0;
}
if (CategoryList.SelectedIndex > -1)
{
BindDocumentData(Int32.Parse(CategoryList.SelectedValue));
}
}
///设置按钮的可用性
AddBtn.Enabled = CategoryList.Items.Count <= 0 ? false : true;
///添加删除确认对话框
deleteBtn.Attributes.Add("onclick", "return confirm('" + ASPNET2System.OPERATIONDELETEMESSAGE + "');");
}
private void BindCategoryData()
{
Category category = new Category();
category.BindCategoryTreeList(CategoryList);
}
private void BindDocumentData(int nCategoryID)
{
///定义获取数据的类
Document document = new Document();
SqlDataReader recd = document.GetDocumentByCategory(nCategoryID);
///设定控件的数据源
DocumentList.DataSource = recd;
///设定控件的Text属性和Value属性
DocumentList.DataTextField = "Desn";
DocumentList.DataValueField = "DocumentID";
///绑定控件的数据
DocumentList.DataBind();
///关闭数据读取器和数据库的连接
recd.Close();
///设置按钮的可用性
updateBtn.Enabled = deleteBtn.Enabled = AttachmentBtn.Enabled
= DocumentList.Items.Count <= 0 ? false : true;
}
protected void AddBtn_Click(object sender, EventArgs e)
{
///跳转到添加页面
Response.Redirect("~/DesktopModules/Document/AddDocument.aspx");
}
protected void updateBtn_Click(object sender, ImageClickEventArgs e)
{
if (DocumentList.SelectedIndex > -1)
{
///跳转到修改页面
Response.Redirect("~/DesktopModules/Document/UpdateDocument.aspx?DocumentID=" + DocumentList.SelectedValue);
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
protected void deleteBtn_Click(object sender, ImageClickEventArgs e)
{
if (DocumentList.SelectedIndex > -1)
{
///定义类
Document document = new Document();
try
{
///删除数据
int nIsAttachment = document.DeleteDocument(Int32.Parse(DocumentList.SelectedValue));
if (nIsAttachment <= 0)
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
}
if(nIsAttachment == 1)
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONATTACHMENTDATA + "')</script>");
}
if (nIsAttachment == 2)
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONPICTUREDATA + "')</script>");
}
if (nIsAttachment == 3)
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONATTACHMENTPICTUREDATA + "')</script>");
}
if (nIsAttachment <= 0)
{
///重新绑定数据
BindDocumentData(Int32.Parse(CategoryList.SelectedValue));
}
}
catch (Exception ex)
{
///显示删除操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
protected void AttachmentBtn_Click(object sender, EventArgs e)
{
if (DocumentList.SelectedIndex > -1)
{
///跳转到添加附件页面
Response.Redirect("~/DesktopModules/Attachment/AttachmentManage.aspx?DocumentID=" + DocumentList.SelectedValue);
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
protected void CategoryList_SelectedIndexChanged(object sender, EventArgs e)
{
///重新绑定控件的数据
if (CategoryList.SelectedIndex > -1)
{
BindDocumentData(Int32.Parse(CategoryList.SelectedValue));
}
else
{
DocumentList.Items.Clear();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -