📄 detailquestion.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;
using System.Text;
namespace Service
{
/// <summary>
/// Summary description for DetailQuestion.
/// </summary>
public partial class DetailQuestion : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image SpaceImage;
private ArrayList QuestionData = new ArrayList();
public String sOperation = "";
public String sLinkName = "";
public bool isLead = false;
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)
{
BindData();
//总共的页数
PageCount.Text = myDataGrid.PageCount.ToString() + " ";
//当前的页码
PageCurrentCount.Text = (myDataGrid.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 BindData()
{
UserDB user = new UserDB();
QuestionDB question = new QuestionDB();
SqlDataReader recq = null;
if("ValidRepairMark" == UserDB.GetUserLoginRole(Int32.Parse(Session["UserID"].ToString())))
{
isLead = true;
}
if(isLead == true)
{
recq = question.GetQuestions();
}
else
{
recq = question.GetQuestionByUser(Int32.Parse(Session["UserID"].ToString()));
}
for(int i = 0; i < GlobalVarables.DEGREE; i++)
{
while(recq.Read())
{
QuestionDetails questionDetail = new QuestionDetails();
questionDetail.OwnerID = Int32.Parse(recq["OwnerID"].ToString());
SqlDataReader reco = user.GetSingleUser(questionDetail.OwnerID);
if(reco.Read())
{
questionDetail.OwnerName = reco["UserName"].ToString();
}
reco.Close();
questionDetail.QuestionID = Int32.Parse(recq["QuestionID"].ToString());
questionDetail.Title = recq["Title"].ToString();
questionDetail.SoluteState = Int32.Parse(recq["SoluteState"].ToString());
questionDetail.PubTime = (DateTime)recq["PubTime"];
questionDetail.DisposeTime = recq["DisposeTime"].ToString();
questionDetail.IsTypeError = Int32.Parse(recq["IsTypeError"].ToString());
if(recq["SoluteState"].ToString() == "2")
{
questionDetail.SoluteTime = recq["SoluteTime"].ToString();
}
else
{
questionDetail.SoluteTime = "";
}
QuestionData.Add(questionDetail);
}
recq.NextResult();
}
ItemCount.Text = QuestionData.Count.ToString();
myDataGrid.DataSource = QuestionData;
myDataGrid.DataBind();
recq.Close();
}
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 = "报修类型错误";
}
return(strState);
}
#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.myDataGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.myDataGrid_ItemCommand);
this.myDataGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.myDataGrid_ItemDataBound);
}
#endregion
private void myDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName.ToLower() == "question")
{
Response.Write("<script>window.open(" + @"""" + "SimpleShowQuestion.aspx?QuestionID="
+ e.CommandArgument + @"""" + ", " + @"""" + "查看问题的详细信息" + @"""" + ", "
+ @"""" + "height=265,width=422,toolbar=no,menubar=no,scrollbar=yes,resizable=no,location=no,status=no,left=200" + @"""" + ");</script>");
}
if(e.CommandName.ToLower() == "owner")
{
Response.Write("<script>window.open(" + @"""" + "LookUserInfo.aspx?UserID="
+ e.CommandArgument + @"""" + ", " + @"""" + "查看用户详细信息" + @"""" + ", "
+ @"""" + "height=180,width=422,toolbar=no,menubar=no,scrollbar=yes,resizable=no,location=no,status=no,left=200" + @"""" + ");</script>");
}
if(e.CommandName.ToLower() == "comment")
{
Response.Write("<script>window.open(" + @"""" + "LookQueComment.aspx?QuestionID="
+ e.CommandArgument + @"""" + ", " + @"""" + "查看问题反馈意见" + @"""" + ", "
+ @"""" + "height=225,width=422,toolbar=no,menubar=no,scrollbar=no,resizable=no,location=no,status=no,left=200" + @"""" + ");</script>");
}
if(e.CommandName.ToLower() == "submit")
{
QuestionDB question = new QuestionDB();
try
{
question.UpdateQuestionState(Int32.Parse(e.CommandArgument.ToString()),2);
}
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"," "));
}
Response.Write("<script>alert(\"问题提交成功!\");</script>");
BindData();
}
}
private void myDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Button button = (Button)e.Item.FindControl("Submitbtn");
if(button != null)
{
button.Attributes.Add("onclick","return confirm('你确定要提交所选择的问题吗?');");
}
}
/// <summary>
/// 实现分页机制
/// </summary>
protected void Page_Click(object sender, System.EventArgs e)
{
String commangArg = ((LinkButton)sender).CommandArgument;
switch(commangArg)
{
//首页
case "First":
{
myDataGrid.CurrentPageIndex = 0;
break;
}
//上一页
case "Prev":
{
myDataGrid.CurrentPageIndex = (int)Math.Max(0,myDataGrid.CurrentPageIndex - 1);
break;
}
//下一页
case "Next":
{
myDataGrid.CurrentPageIndex = (int)Math.Min(myDataGrid.PageCount -1,myDataGrid.CurrentPageIndex +1);
break;
}
//最后一页
case "Last":
{
myDataGrid.CurrentPageIndex = myDataGrid.PageCount -1;
break;
}
default:
{
break;
}
}
//重新绑定myDataGrid的数据
BindData();
//重新绑定当前的页码
PageCurrentCount.Text = (myDataGrid.CurrentPageIndex + 1).ToString();
//控制页面导向按钮的可见性
IsFirstLastPage();
}
//控制页面导向按钮的可见性
private void IsFirstLastPage()
{
if(myDataGrid.PageCount != 1)
{
if(myDataGrid.CurrentPageIndex == 0)
{
PagePrev.Visible = false;
}
else
{
PagePrev.Visible = true;
}
if(myDataGrid.CurrentPageIndex == myDataGrid.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()) <= myDataGrid.PageCount))
{
myDataGrid.CurrentPageIndex = Int32.Parse(MoveToPageCount.Text.Trim()) -1;
BindData();
//重新绑定当前的页码
PageCurrentCount.Text = (myDataGrid.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 + -