?? updategenericinfo.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 System.IO;
public partial class Content_Admin_UpdateGenericInfo:System.Web.UI.Page
{
int nContentID = -1;
protected void Page_Load(object sender,EventArgs e)
{
if(Session[SystemConst.USERIDKEY] == null)
{
Response.Write(SysOperation.OpenDialog(
"你還沒有登錄,請先登錄..."));
Response.Write("<script>history.back()<script>");
return;
}
if(Request.Params["ColumnID"] != null)
{
ViewState[SystemConst.COLUMNIDKEY] = Request.Params["ColumnID"].ToString();
}
if(Request.Params["ContentID"] != null)
{
ViewState[SystemConst.CONTENTIDKEY] = Request.Params["ContentID"].ToString();
if(Int32.TryParse(Request.Params["ContentID"].ToString(),out nContentID) == false)
{
return;
}
}
if(!Page.IsPostBack)
{
if(nContentID > -1)
{
BindContentData(nContentID);
}
}
UpdateBtn.Enabled = nContentID > -1 ? true : false;
}
#region 綁定頁面的數(shù)據(jù)
private void BindContentData(int nContentID)
{
IContent content = new Content();
SqlDataReader dr = content.GetSingleContent(nContentID);
short dpFlag = 0;
if(dr.Read())
{
Name.Text = dr["Name"].ToString();
tbDesn.Text = dr["Desn"].ToString();
dpFlag = short.Parse(dr["dpFlag"].ToString());
ViewState[SystemConst.CONTENTINFOIDKEY] = dr["ContentInfoID"].ToString();
}
dr.Close();
///如果已經(jīng)存在文檔
if(dpFlag > 0)
{
cbDocument.Visible = cbDocument.Checked
= cbDocument.Enabled = true;
///顯示已經(jīng)存在的文檔
BindDocumentData(nContentID);
}
else
{ ///不存在文檔,則可以添加新的附件和圖片
cbDocument.Visible = cbDocument.Enabled = true;
cbDocument.Checked = false;
}
pFile.Visible = cbDocument.Checked;
}
private void BindDocumentData(int nContentID)
{
IDocument doc = new Document();
SqlDataReader dr = doc.GetDocumentByContent(nContentID);
DocView.DataSource = dr;
DocView.DataBind();
dr.Close();
DocView.Visible = DocView.Rows.Count > 0 ? true : false;
}
protected string FormatContentdpFlag(short sdpFlag)
{
switch(sdpFlag)
{
case 1:
///"附件";
return "~/Images/Attch.gif";
case 2:
///"圖片";
return "~/Images/pic.gif";
default:
///"未知狀態(tài)";
return "~/Images/unknown.gif";
}
}
protected void DocView_RowDataBound(object sender,GridViewRowEventArgs e)
{
ImageButton deleteBtn = (ImageButton)e.Row.FindControl("DeleteBtn");
if(deleteBtn != null)
{
deleteBtn.Attributes.Add("onclick","return confirm('你確定要?jiǎng)h除所選擇的數(shù)據(jù)嗎?');");
}
}
#endregion
protected void Btn_Command(object sender,CommandEventArgs e)
{
string sCmdName = e.CommandName.ToLower();
if(SysOperation.StringNullChecked(sCmdName) == false)
{
return;
}
switch(sCmdName)
{
case "update":
{
UpdateContent();
break;
}
case "return":
{
if(ViewState[SystemConst.COLUMNIDKEY] == null)
{
break;
}
switch(Int32.Parse(ViewState[SystemConst.COLUMNIDKEY].ToString()))
{
case (int)Column.Advice:
Response.Redirect("~/Content/Admin/AdviceManage.aspx");
break;
case (int)Column.Board:
Response.Redirect("~/Content/Admin/BoardManage.aspx");
break;
case (int)Column.News:
Response.Redirect("~/Content/Admin/NewsManage.aspx");
break;
case (int)Column.OfficePlan:
Response.Redirect("~/Content/Admin/OfficePlanManage.aspx");
break;
case (int)Column.Plan:
Response.Redirect("~/Content/Admin/PlanManage.aspx");
break;
default: break;
}
break;
}
default: break;
}
}
private void UpdateContent()
{
IContent content = new Content();
///修改內(nèi)容
try
{
content.UpdateContent(nContentID,Name.Text.Trim(),tbDesn.Text.Trim());
Response.Write(SysOperation.OpenDialog(
SysInfomation.UPDATE_DATA_SUCESS + " 你還可以修改、或添加該內(nèi)容的附件或圖片。"
));
}
catch(Exception ex)
{
Server.Transfer(SysOperation.FormatErrorPageUrl(
SysOperation.FormatErrorUrl(Request.RawUrl),ex.Message),
false);
}
}
protected void cbDocument_CheckedChanged(object sender,EventArgs e)
{
DocView.Visible = fuFile.Visible = fuFile.Enabled
= btnUpload.Visible = btnUpload.Enabled
= pFile.Visible = cbDocument.Checked;
}
protected void btnUpload_Click(object sender,EventArgs e)
{
if(fuFile.HasFile == false || ViewState[SystemConst.CONTENTIDKEY] == null)
{
Response.Write(SysOperation.OpenDialog(
"數(shù)據(jù)為空,不能上載所選擇的文件")
);
return;
}
string tfName = fuFile.PostedFile.FileName;
string fileName = SysOperation.CreateFileNameByDateTime()
+ tfName.Substring(tfName.LastIndexOf("."));
string fullfilePath = Server.MapPath("../../Files/" + fileName);
if(File.Exists(fullfilePath) == true)
{
Response.Write(SysOperation.OpenDialog(
"你上載的文件" + fileName + "已經(jīng)存在,不能上載所選擇的文件")
);
return;
}
try
{ ///上載文件
fuFile.SaveAs(fullfilePath);
///添加文檔信息
IDocument doc = new Document();
doc.AddDocument(tbDocName.Text,
"Files/" + fileName,fuFile.PostedFile.ContentType,
Int32.Parse(ViewState[SystemConst.CONTENTINFOIDKEY].ToString()),
short.Parse(rbFileType.SelectedValue));
///修改內(nèi)容的附加信息
IContentInfo contentInfo = new ContentInfo();
contentInfo.UpdatedpFlag(Int32.Parse(ViewState[SystemConst.CONTENTINFOIDKEY].ToString()),
short.Parse(rbFileType.SelectedValue));
///顯示附件和圖片信息
BindDocumentData(Int32.Parse(ViewState[SystemConst.CONTENTIDKEY].ToString()));
}
catch(Exception ex)
{
Server.Transfer(SysOperation.FormatErrorPageUrl(
SysOperation.FormatErrorUrl(Request.RawUrl),ex.Message),
false);
}
}
protected void DocView_RowDeleting(object sender,GridViewDeleteEventArgs e)
{
///
}
protected void DocView_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName.ToString() == "delete")
{
///讀取刪除附件或圖片的信息
IDocument doc = new Document();
int nDocumentID = Int32.Parse(e.CommandArgument.ToString());
SqlDataReader dr = doc.GetSingleDocument(nDocumentID);
int nContentInfoID = -1;
string sUrl = "";
if(dr.Read())
{
sUrl = dr["Url"].ToString();
nContentInfoID = Int32.Parse(dr["ContentInfoID"].ToString());
}
dr.Close();
if(nContentInfoID <= 0 || ViewState[SystemConst.CONTENTIDKEY] == null)
{
Response.Write(SysOperation.OpenDialog(
"數(shù)據(jù)為空,不能刪除所選擇的文件")
);
return;
}
///設(shè)置新的dpFlag標(biāo)志
SqlDataReader drdoc = doc.GetDocumentByContent(
Int32.Parse(ViewState[SystemConst.CONTENTIDKEY].ToString()));
EPictureAttachment dpFlag = EPictureAttachment.Normal;
while(drdoc.Read())
{
if(drdoc["ID"].ToString() != nDocumentID.ToString())
{
dpFlag |= (EPictureAttachment)short.Parse(drdoc["dpFlag"].ToString());
}
}
drdoc.Close();
///更新dpFlag標(biāo)志
IContentInfo contentInfo = new ContentInfo();
try
{
contentInfo.UpdatadpFlagDelete(nContentInfoID,(short)dpFlag);
///刪除選擇的附件
doc.DeleteDocument(nDocumentID);
}
catch(Exception ex)
{
Server.Transfer(SysOperation.FormatErrorPageUrl(
SysOperation.FormatErrorUrl(Request.RawUrl),ex.Message),
false);
}
string fullfilePath = Server.MapPath("../../" + sUrl);
if(File.Exists(fullfilePath) == false)
{
Response.Write(SysOperation.OpenDialog(
"要?jiǎng)h除的文件:" + sUrl + "不存在。請檢查文件是否被意外刪除。")
);
return;
}
try
{
File.Delete(fullfilePath);
///重新顯示內(nèi)容的附件和圖片
BindDocumentData(
Int32.Parse(ViewState[SystemConst.CONTENTIDKEY].ToString()));
}
catch(Exception ex)
{
Server.Transfer(SysOperation.FormatErrorPageUrl(
SysOperation.FormatErrorUrl(Request.RawUrl),ex.Message),
false);
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -