📄 updatequestion.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 UpdateQuestion.
/// </summary>
public partial class UpdateQuestion : 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();
if(QuestionList.Items.Count > 0)
{
BindAllData(Int32.Parse(QuestionList.SelectedValue));
}
}
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()
{
QuestionList.Items.Clear();
QuestionDB question = new QuestionDB();
SqlDataReader recq = question.GetQuestionByOwner(Int32.Parse(Session["UserID"].ToString()));
while(recq.Read())
{
if(recq["SoluteState"].ToString() == "0")
{
//只有问题没有处理时才可以修改,否则是不能修改的
ListItem listItem = new ListItem(recq["Title"].ToString(),recq["ID"].ToString());
QuestionList.Items.Add(listItem);
}
}
recq.Close();
}
private void BindAllData(int nQuestionID)
{
QuestionDB question = new QuestionDB();
int[] arrayID = question.GetAllID(nQuestionID);
DirectionList.Items.Clear();
ChannelList.Items.Clear();
TopicList.Items.Clear();
SubTopicList.Items.Clear();
if(arrayID[0] > 0)
{
DirectionDB direction = new DirectionDB();
SqlDataReader recd = direction.GetSingleDirection(arrayID[0]);
DirectionList.DataSource = recd;
DirectionList.DataTextField = "DirectionName";
DirectionList.DataValueField = "ID";
DirectionList.DataBind();
recd.Close();
}
if(arrayID[1] > 0)
{
ChannelDB channel = new ChannelDB();
SqlDataReader recc = channel.GetSingleChannel(arrayID[1]);
ChannelList.DataSource = recc;
ChannelList.DataTextField = "ChannelName";
ChannelList.DataValueField = "ID";
ChannelList.DataBind();
recc.Close();
}
if(arrayID[2] > 0)
{
TopicDB topic = new TopicDB();
SqlDataReader recc = topic.GetSingleTopic(arrayID[2]);
TopicList.DataSource = recc;
TopicList.DataTextField = "TopicName";
TopicList.DataValueField = "ID";
TopicList.DataBind();
recc.Close();
}
if(arrayID[3] > 0)
{
SubTopicDB subtopic = new SubTopicDB();
SqlDataReader recs = subtopic.GetSingleSubtopic(arrayID[3]);
SubTopicList.DataSource = recs;
SubTopicList.DataTextField = "SubTopicName";
SubTopicList.DataValueField = "ID";
SubTopicList.DataBind();
recs.Close();
}
SqlDataReader recq = question.GetSingleQuestion(nQuestionID);
while(recq.Read())
{
Title.Text = recq["Title"].ToString();
Body.Text = recq["Question"].ToString();
}
recq.Close();
}
#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()
{
}
#endregion
protected void SubmitBtn_Click(object sender, System.EventArgs e)
{
QuestionDB question = new QuestionDB();
if(Title.Text.Trim().Length > 0)
{
try
{
question.UpdateQuestion(Int32.Parse(QuestionList.SelectedValue),CleanString.InputText(Title.Text.Trim(),50),CleanString.InputText(Body.Text,Body.Text.Length));
}
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"," "));
}
}
else
{
Response.Write("<script>alert(\"报修问题的标题不能为空!\")</script>");
}
Response.Write("<script>alert(\"修改报修问题成功!\")</script>");
}
protected void Resetbtn_Click(object sender, System.EventArgs e)
{
if(QuestionList.Items.Count > 0)
{
BindAllData(Int32.Parse(QuestionList.SelectedValue));
}
}
protected void QuestionList_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(QuestionList.Items.Count > 0)
{
BindAllData(Int32.Parse(QuestionList.SelectedValue));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -