📄 deletequestion.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Service
{
/// <summary>
/// Summary description for DeleteQuestion.
/// </summary>
public partial class DeleteQuestion : System.Web.UI.Page
{
public String sOperation = "";
public String sLinkName = "";
protected void Page_Load(object sender, System.EventArgs e)
{
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
else
{
String sUserRoleName = UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString()));
if(sUserRoleName.IndexOf("Valid") == -1 && sUserRoleName.IndexOf("Normal") == -1)
{
Response.Redirect("~/Default.aspx");
}
}
if(!Page.IsPostBack)
{
BindQuestionData();
//总共的页数
PageCount.Text = QuestionList.PageCount.ToString() + " ";
//当前的页码
PageCurrentCount.Text = (QuestionList.CurrentPageIndex + 1).ToString() + " ";
//初始化页面导向按钮的可见性
IsFirstLastPage();
}
if(Request.Params["LinkID"] != null)
{
GetLinkName(Request.Params["LinkID"].ToString());
}
}
private void GetLinkName(String sLinkID)
{
String[] aName = new String[2];
aName = GlobalVarables.GetLinkName(sLinkID);
sOperation = aName[0].ToString();
sLinkName = aName[1].ToString();
}
private void BindQuestionData()
{
QuestionDB question = new QuestionDB();
DataSet ds = question.GetQuestionByOwnerDS(Int32.Parse(Session["UserID"].ToString()));
QuestionList.DataSource = ds;
QuestionList.DataBind();
}
public String FormatState(int nState)
{
String strState = "";
if(nState == 0)
{
strState = "<font color=red>尚未处理</font>";
}
if(nState == 1)
{
strState = "<font color=blue>正在处理</font>";
}
if(nState == 2)
{
strState = "已经完成";
}
if(nState == 3)
{
strState = "<font color=red>报修类型错误</font>";
}
return(strState);
}
public String FormatDisposeTime(int nState,String sDisposeTime)
{
if(nState > 0)
{
return(sDisposeTime);
}
else
{
return("");
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.QuestionList.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.QuestionList_ItemCommand);
this.QuestionList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.QuestionList_DeleteCommand);
this.QuestionList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.QuestionList_ItemDataBound);
}
#endregion
private void QuestionList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName.ToLower() == "link")
{
//导航到查看问题的详细情况
Response.Write("<script>window.open('LookQuestion.aspx?QuestionID="
+ e.CommandArgument
+ "');</script>");
}
}
private void QuestionList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//添加删除时的确认对话框
Button button = (Button)e.Item.FindControl("deleteBtn");
if(button != null)
{
button.Attributes.Add("onclick","return confirm('你确定要删除所选择的问题吗?');");
}
}
private void QuestionList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName.ToLower() == "delete")
{
QuestionDB question = new QuestionDB();
try
{
question.DeleteQuestion(Int32.Parse(e.CommandArgument.ToString()));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/ManageSystem/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
BindQuestionData();
}
}
/// <summary>
/// 实现分页机制
/// </summary>
protected void Page_Click(object sender, System.EventArgs e)
{
String commangArg = ((LinkButton)sender).CommandArgument;
switch(commangArg)
{
//首页
case "First":
{
QuestionList.CurrentPageIndex = 0;
break;
}
//上一页
case "Prev":
{
QuestionList.CurrentPageIndex = (int)Math.Max(0,QuestionList.CurrentPageIndex - 1);
break;
}
//下一页
case "Next":
{
QuestionList.CurrentPageIndex = (int)Math.Min(QuestionList.PageCount -1,QuestionList.CurrentPageIndex +1);
break;
}
//最后一页
case "Last":
{
QuestionList.CurrentPageIndex = QuestionList.PageCount -1;
break;
}
default:
{
break;
}
}
//重新绑定QuestionList的数据
BindQuestionData();
//重新绑定当前的页码
PageCurrentCount.Text = (QuestionList.CurrentPageIndex + 1).ToString();
//控制页面导向按钮的可见性
IsFirstLastPage();
}
//控制页面导向按钮的可见性
private void IsFirstLastPage()
{
if(QuestionList.PageCount != 1)
{
if(QuestionList.CurrentPageIndex == 0)
{
PagePrev.Visible = false;
}
else
{
PagePrev.Visible = true;
}
if(QuestionList.CurrentPageIndex == QuestionList.PageCount -1)
{
PageNext.Visible = false;
}
else
{
PageNext.Visible = true;
}
}
else
{
PagePrev.Visible = false;
PageNext.Visible = false;
}
}
//实现随机定位页面
protected void MoveToPageCountBtn_Click(object sender, System.EventArgs e)
{
if((MoveToPageCount.Text.Trim() != "")&&(MoveToPageCount.Text.Trim() != null))
{
if((Int32.Parse(MoveToPageCount.Text.Trim()) > 0)&&(Int32.Parse(MoveToPageCount.Text.Trim()) <= QuestionList.PageCount))
{
QuestionList.CurrentPageIndex = Int32.Parse(MoveToPageCount.Text.Trim()) -1;
BindQuestionData();
//重新绑定当前的页码
PageCurrentCount.Text = (QuestionList.CurrentPageIndex + 1).ToString();
//控制页面导向按钮的可见性
IsFirstLastPage();
}
else
{
Response.Write("<script>alert(\"你输入的页码值超出页码的范围,请重新输入!\")</script>");
}
}
else
{
Response.Write("<script>alert(\"请输入你要转到的页码!\")</script>");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -