資源簡介
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 MRSOFTASPNET.XmlBBS;
using MRSOFTASPNET.CommonOperation;
using MRSOFTASPNET.UserCommonOperation;
using System.IO;
public partial class ProjectBBS_AddTitle : System.Web.UI.Page
{
int boardID = -1;
protected void Page_Load(object sender, EventArgs e)
{
///判斷用戶是否登錄
UserInfo info = (UserInfo)UserCommonOperation.GetUserInfo(Session);
if (info == null)
{ ///返回到上一個頁面
Response.Write("<script>history.back()</script>");
///跳轉到登錄頁面
Response.Redirect("~/ProjectBBS/UserLogin.aspx");
return;
}
///獲取新帖所屬的頁面ID值,并保存在變量boardID中
if (Request.Params["BoardID"] != null)
{
boardID = DataTypeConvert.ConvertToInt(Request.Params["BoardID"].ToString());
}
if (!Page.IsPostBack)
{
//調用自定義方法BindPageData顯示系統中的當前版面的層次信息
BindPageData();
}
///設置按鈕的可用性
ListControl[] list = {
ddlBoard,
ddlState
};
ButtonEnable.ControlButtonEnable(btnAdd, list);
ButtonEnable.ControlButtonEnable(btnAddAndReturn, list);
}
public void BindPageData()
{
///顯示版面的層次信息
Board board = new Board();
board.CreateHiberarchyBoard(ddlBoard);
if (boardID > 0)
{ ///選擇帖子的版面
ListSelectedItem.ListSelectedItemByValue(ddlBoard, boardID.ToString());
}
}
//自定義AddTitle方法將帖子保存到數據庫中,并返回帖子的附件的鏈接地址
private int AddTitle(out string url)
{
//獲取用戶登錄信息
UserInfo info = (UserInfo)UserCommonOperation.GetUserInfo(Session);
if (info == null)
{
url = string.Empty;
return -1;
}
//實例化BBS
BBS bbs = new BBS();
//顯示帖子的狀態
byte state = (byte)TitleState.Reply;
//調用自定義方法AddAttachmenth上傳附件,獲取用戶上傳文件的鏈接地址
url = AddAttachment(fileUpLoad);
//根據是否上傳附件設置帖子的狀態
if (string.IsNullOrEmpty(url) == true)
{
//顯示用戶未上傳附件狀態
state = byte.Parse(ddlState.SelectedValue);
}
else
{
//顯示用戶上傳附件狀態
state = (byte)((int)(TitleState.ReplyAttachment) int.Parse(ddlState.SelectedValue));
}
//添加帖子到數據庫中,同時返回新添加帖子的ID值
return (bbs.AddTitle(tbName.Text,
tbBody.Text,
info.UserID,
DataTypeConvert.ConvertToInt(ddlBoard.SelectedValue), state));
}
private string AddAttachment(FileUpload fu)
{
//判斷上傳文件控件是否存在文件
if(fu.HasFile==false) return null;
//獲取上傳文件名稱
string tfName=fu.PostedFile.FileName;
//創建基于時間的文件名稱
string fileName=DealwithString.CreatedStringByTime() tfName.Substring(tfName.LastIndexOf("."));
fileName ="../XmlDatabase/Files/" fileName;
//獲取服務器端的文件名稱
string allfilePath=Server.MapPath(fileName);
//判斷基于服務器端的文件名是否存在,如果存在則不能上傳
if(File.Exists(allfilePath) == true)
{
//彈出對話框
Dialog.OpenDialog(Response,
"你上傳的文件" fileName "已經存在,不能上傳所選擇的文件");
}
try
{
//保存上傳文件,并返回基于服務器端的文件名稱
fu.SaveAs(allfilePath); return (fileName);
}
catch(Exception ex)
{
//導向到錯誤捕捉頁面,并獲取當前請求的原始URL及錯誤信息
Server.Transfer("~/ProjectBBS/ErrorPage.aspx?Url=" Request.RawUrl "& ErrorMsg = " ex.Message,false);
}
return null;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
//添加新的帖子
string url = string.Empty;
//調用自定義方法AddTitle方法將帖子保存到數據庫中
int titleID = AddTitle(out url);
if (titleID > 0 && string.IsNullOrEmpty(url) == true)
{
//調用Dialog類中的OpenDialog方法彈出對話框
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是你沒有上傳附件……");
this.tbName.Text = this.tbBody.Text = string.Empty;
return;
}
if (titleID > 0)
{
//添加附件信息到數據庫中
BBS bbs = new BBS();
if (bbs.AddAttachment(fileUpLoad.FileName,
url,
fileUpLoad.PostedFile.ContentType, titleID) > 0)
{
//彈出添加新帖成功對話框
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功……");
}
else
{
//彈出添加新帖成功,上傳附件失敗對話框
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是上傳附件失敗……");
}
}
}
}
protected void btnAddAndReturn_Click(object sender, EventArgs e)
{
///添加新的帖子
string url = string.Empty;
int titleID = AddTitle(out url);
if (titleID > 0 && string.IsNullOrEmpty(url) == true)
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是你沒有上載附件……");
///返回管理頁面
Server.Transfer("~/ProjectBBS/TitleManage.aspx");
return;
}
if (titleID > 0)
{ ///添加附件信息到數據庫中
BBS bbs = new BBS();
if (bbs.AddAttachment(fileUpLoad.FileName,
url,
fileUpLoad.PostedFile.ContentType,
titleID) > 0)
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功……");
}
else
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是你沒有上載附件……");
}
///返回管理頁面
Server.Transfer("~/ProjectBBS/TitleManage.aspx");
}
}
protected void btnReturn_Click(object sender, EventArgs e)
{
///返回管理頁面
Server.Transfer("~/ProjectBBS/TitleManage.aspx");
}
}
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 MRSOFTASPNET.XmlBBS;
using MRSOFTASPNET.CommonOperation;
using MRSOFTASPNET.UserCommonOperation;
using System.IO;
public partial class ProjectBBS_AddTitle : System.Web.UI.Page
{
int boardID = -1;
protected void Page_Load(object sender, EventArgs e)
{
///判斷用戶是否登錄
UserInfo info = (UserInfo)UserCommonOperation.GetUserInfo(Session);
if (info == null)
{ ///返回到上一個頁面
Response.Write("<script>history.back()</script>");
///跳轉到登錄頁面
Response.Redirect("~/ProjectBBS/UserLogin.aspx");
return;
}
///獲取新帖所屬的頁面ID值,并保存在變量boardID中
if (Request.Params["BoardID"] != null)
{
boardID = DataTypeConvert.ConvertToInt(Request.Params["BoardID"].ToString());
}
if (!Page.IsPostBack)
{
//調用自定義方法BindPageData顯示系統中的當前版面的層次信息
BindPageData();
}
///設置按鈕的可用性
ListControl[] list = {
ddlBoard,
ddlState
};
ButtonEnable.ControlButtonEnable(btnAdd, list);
ButtonEnable.ControlButtonEnable(btnAddAndReturn, list);
}
public void BindPageData()
{
///顯示版面的層次信息
Board board = new Board();
board.CreateHiberarchyBoard(ddlBoard);
if (boardID > 0)
{ ///選擇帖子的版面
ListSelectedItem.ListSelectedItemByValue(ddlBoard, boardID.ToString());
}
}
//自定義AddTitle方法將帖子保存到數據庫中,并返回帖子的附件的鏈接地址
private int AddTitle(out string url)
{
//獲取用戶登錄信息
UserInfo info = (UserInfo)UserCommonOperation.GetUserInfo(Session);
if (info == null)
{
url = string.Empty;
return -1;
}
//實例化BBS
BBS bbs = new BBS();
//顯示帖子的狀態
byte state = (byte)TitleState.Reply;
//調用自定義方法AddAttachmenth上傳附件,獲取用戶上傳文件的鏈接地址
url = AddAttachment(fileUpLoad);
//根據是否上傳附件設置帖子的狀態
if (string.IsNullOrEmpty(url) == true)
{
//顯示用戶未上傳附件狀態
state = byte.Parse(ddlState.SelectedValue);
}
else
{
//顯示用戶上傳附件狀態
state = (byte)((int)(TitleState.ReplyAttachment) int.Parse(ddlState.SelectedValue));
}
//添加帖子到數據庫中,同時返回新添加帖子的ID值
return (bbs.AddTitle(tbName.Text,
tbBody.Text,
info.UserID,
DataTypeConvert.ConvertToInt(ddlBoard.SelectedValue), state));
}
private string AddAttachment(FileUpload fu)
{
//判斷上傳文件控件是否存在文件
if(fu.HasFile==false) return null;
//獲取上傳文件名稱
string tfName=fu.PostedFile.FileName;
//創建基于時間的文件名稱
string fileName=DealwithString.CreatedStringByTime() tfName.Substring(tfName.LastIndexOf("."));
fileName ="../XmlDatabase/Files/" fileName;
//獲取服務器端的文件名稱
string allfilePath=Server.MapPath(fileName);
//判斷基于服務器端的文件名是否存在,如果存在則不能上傳
if(File.Exists(allfilePath) == true)
{
//彈出對話框
Dialog.OpenDialog(Response,
"你上傳的文件" fileName "已經存在,不能上傳所選擇的文件");
}
try
{
//保存上傳文件,并返回基于服務器端的文件名稱
fu.SaveAs(allfilePath); return (fileName);
}
catch(Exception ex)
{
//導向到錯誤捕捉頁面,并獲取當前請求的原始URL及錯誤信息
Server.Transfer("~/ProjectBBS/ErrorPage.aspx?Url=" Request.RawUrl "& ErrorMsg = " ex.Message,false);
}
return null;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
//添加新的帖子
string url = string.Empty;
//調用自定義方法AddTitle方法將帖子保存到數據庫中
int titleID = AddTitle(out url);
if (titleID > 0 && string.IsNullOrEmpty(url) == true)
{
//調用Dialog類中的OpenDialog方法彈出對話框
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是你沒有上傳附件……");
this.tbName.Text = this.tbBody.Text = string.Empty;
return;
}
if (titleID > 0)
{
//添加附件信息到數據庫中
BBS bbs = new BBS();
if (bbs.AddAttachment(fileUpLoad.FileName,
url,
fileUpLoad.PostedFile.ContentType, titleID) > 0)
{
//彈出添加新帖成功對話框
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功……");
}
else
{
//彈出添加新帖成功,上傳附件失敗對話框
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是上傳附件失敗……");
}
}
}
}
protected void btnAddAndReturn_Click(object sender, EventArgs e)
{
///添加新的帖子
string url = string.Empty;
int titleID = AddTitle(out url);
if (titleID > 0 && string.IsNullOrEmpty(url) == true)
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是你沒有上載附件……");
///返回管理頁面
Server.Transfer("~/ProjectBBS/TitleManage.aspx");
return;
}
if (titleID > 0)
{ ///添加附件信息到數據庫中
BBS bbs = new BBS();
if (bbs.AddAttachment(fileUpLoad.FileName,
url,
fileUpLoad.PostedFile.ContentType,
titleID) > 0)
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功……");
}
else
{
Dialog.OpenDialog(Response, "恭喜您,添加新帖子成功,但是你沒有上載附件……");
}
///返回管理頁面
Server.Transfer("~/ProjectBBS/TitleManage.aspx");
}
}
protected void btnReturn_Click(object sender, EventArgs e)
{
///返回管理頁面
Server.Transfer("~/ProjectBBS/TitleManage.aspx");
}
}
代碼片段和文件信息
using?System;
using?System.Data;
using?System.Configuration;
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?MRSOFTASPNET.xmlBBS;
using?MRSOFTASPNET.CommonOperation;
using?MRSOFTASPNET.UserCommonOperation;
public?partial?class?_Default?:?System.Web.UI.Page?
{
????protected?void?Page_Load(object?sender?EventArgs?e)
????{
????????if?(IsPostBack)
????????{
????????????UpdateUserStat();
????????}
????????Response.Redirect(“~/ProjectBBS/UserLogin.aspx“);
????}
????private?void?UpdateUserStat()
????{
????????//實例化公共類
????????BBS?bbs=new?BBS();
????????//定義一個DataTable類型的變量dt并調用公共類中的GetUserStat方法,獲取UserStat表中的ID值
????????DataTable?dt=bb
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.......??????3020??2008-05-13?19:28??2?基于xm
????.......??????3173??2008-07-25?14:23??2?基于xm
????.......??????2201??2008-04-11?10:06??2?基于xm
????.......??????4169??2008-04-14?09:00??2?基于xm
????.......??????2451??2008-04-17?17:49??2?基于xm
????.......??????1832??2008-04-20?11:12??2?基于xm
????.......??????5960??2008-04-14?18:04??2?基于xm
????.......??????2816??2008-04-16?13:07??2?基于xm
????.......???????831??2008-05-15?14:51??2?基于xm
????.......???????417??2008-04-19?11:10??2?基于xm
????.......??????5511??2008-07-21?15:49??2?基于xm
????.......??????2824??2008-07-21?15:56??2?基于xm
????.......??????7554??2008-08-15?09:46??2?基于xm
????.......???????777??2008-05-15?14:45??2?基于xm
????.......??????4393??2008-09-17?13:48??2?基于xm
????.......??????3285??2008-09-17?14:43??2?基于xm
????.......??????4421??2008-09-17?13:14??2?基于xm
????.......??????2078??2008-09-17?13:56??2?基于xm
????.......??????1994??2008-09-17?15:50??2?基于xm
????.......??????3023??2008-09-17?15:50??2?基于xm
????.......??????2780??2008-07-21?15:39??2?基于xm
????.......??????2888??2008-04-29?19:08??2?基于xm
????.......??????3302??2008-07-21?15:39??2?基于xm
????.......??????2250??2008-05-14?09:34??2?基于xm
????.......??????2510??2008-09-18?11:38??2?基于xm
????.......??????2882??2008-07-25?14:26??2?基于xm
????.......??????2240??2008-05-13?19:34??2?基于xm
????.......??????2265??2008-04-20?11:21??2?基于xm
????.......??????3198??2008-04-15?10:09??2?基于xm
????.......??????2301??2008-04-18?14:40??2?基于xm
............此處省略253個文件信息
- 上一篇:wpf 縱向tab標簽
- 下一篇:C# 大話設計模式 完整
評論
共有 條評論
相關資源
- ASP.NET C#在線音樂網站帶數據庫2017更新
- ASP.NET C#在線音樂網站
- ASP.NET C# 在線音樂網站
- ASP.NET MVC Json表格數據 為Excel
- 基于ASP.NET醫院在線掛號系統源碼
- 在ASP.NET MVC中使用Redis 的Demo:通過R
- 在線教育 asp.net源碼
- 微廈在線學習學院版 mooc慕課系統 a
- C# ftp多線程斷點上傳
-
(C#)json to xm
l 解析轉換源代碼 - 基于C#WinForm數據庫在線考試系統項目
-
C#將數據庫數據生成xm
l文件 - 基于ASP.NET SQL2008的在線考試系統源代
- ASP.Net編寫的在線會議管理系統全部源
- ASP.NET在線圖書館管理系統源代碼
- Asp.net在線考試系統源碼
- ASP.NET在線心理測試系統
- 用asp.net做的在線考試系統
- ASP.NET在線圖書館管理系統完整源碼
- asp.net+sql在線心理測試系統
- C#版asp.net在線考試系統(可用作課程
- 基于asp.net在線報名系統
- 基于asp.net的在線學習系統
- 基于ASP.NET的網絡在線投票系統
- 通用在線考試系統
- aspx在線答疑系統源碼
- asp.net在線通訊錄系統
- 畢業設計 甜橙在線音樂MP3網
- 畢業答辯-ASP.NET在線二手交易系統的設
- 畢業答辯-ASP.NET在線英語自學系統——