📄 commentquestion.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 CommentQuestion.
/// </summary>
public partial class CommentQuestion : System.Web.UI.Page
{
private int nQuestionID = 0;
private static int nCommentID = 0;
private bool IsEdit = 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(Request.Params["QuestionID"] != null)
{
nQuestionID = Int32.Parse(Request.Params["QuestionID"].ToString());
}
if(Request.Params["IsEdit"] != null)
{
if(Request.Params["IsEdit"].ToString().ToLower() == "y")
{
IsEdit = true;
}
}
if(!Page.IsPostBack)
{
if(nQuestionID > 0)
{
BindAllData(nQuestionID);
if(IsEdit == false)
{
if(IntPerComment.SelectedIndex == 0)
{
BindCommentTypeData();
IntegrateCommentList.Visible = true;
SubmitBtn.Text = "提交";
Resetbtn.Text = "重置";
}
}
else
{
IntPerComment.Enabled = false;
IntegrateCommentList.Enabled = false;
BindCommentData();
SubmitBtn.Text = "修改";
Resetbtn.Text = "清空";
}
}
}
}
private void BindAllData(int nQuestionID)
{
QuestionDB question = new QuestionDB();
SqlDataReader recq = question.GetSingleQuestion(nQuestionID);
while(recq.Read())
{
Title.Text = recq["Title"].ToString();
CreateTime.Text = recq["PubTime"].ToString();
DisposeTime.Text = recq["DisposeTime"].ToString();
if(recq["SoluteState"].ToString() == "0")
{
SoluteState.Text = "尚未处理";
SoluteState.ForeColor = Color.Red;
}
if(recq["SoluteState"].ToString() == "1")
{
SoluteState.Text = "正在处理";
SoluteState.ForeColor = Color.Blue;
}
if(recq["SoluteState"].ToString() == "2")
{
SoluteState.Text = "已经完成";
SoluteState.ForeColor = Color.Black;
}
if(recq["SoluteState"].ToString() == "3")
{
SoluteState.Text = "报修类型错误";
SoluteState.ForeColor = Color.Red;
}
if(recq["IsTypeError"].ToString() == "1")
{
IsTypeError.Checked = true;
}
else
{
IsTypeError.Checked = false;
}
}
recq.Close();
}
private void BindCommentTypeData()
{
IntegrateCommentList.Items.Clear();
CommentTypeDB comment = new CommentTypeDB();
SqlDataReader recc = comment.GetCommentTypes();
IntegrateCommentList.DataSource = recc;
IntegrateCommentList.DataTextField = "CommentTypeName";
IntegrateCommentList.DataValueField = "ID";
IntegrateCommentList.DataBind();
IntegrateCommentList.SelectedIndex = 0;
recc.Close();
}
private void BindEmployeeData(int nQuestionID)
{
EmployeeQuestionDB employee = new EmployeeQuestionDB();
SqlDataReader rece = employee.GetEmployeeByQuestion(nQuestionID);
CommentList.DataSource = rece;
CommentList.DataBind();
rece.Close();
}
//重载评论等级数据绑定函数
private void BindCommentTypeData(DropDownList dropList)
{
dropList.Items.Clear();
CommentTypeDB comment = new CommentTypeDB();
SqlDataReader recc = comment.GetCommentTypes();
dropList.DataSource = recc;
dropList.DataTextField = "CommentTypeName";
dropList.DataValueField = "ID";
dropList.DataBind();
recc.Close();
}
private void BindCommentData()
{
QuestionDB question = new QuestionDB();
SqlDataReader recq = question.GetQuestionComment(nQuestionID);
while(recq.Read())
{
Comment.Text = recq["Comment"].ToString();
nCommentID = Int32.Parse(recq["CommentID"].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()
{
this.CommentList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.CommentList_ItemDataBound);
}
#endregion
protected void IntPerComment_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(IntPerComment.SelectedIndex == 0)
{
//总体评价
IntegrateCommentList.Visible = true;
CommentList.Visible = false;
}
else
{
//动态加载个人评价(同时进行数据初始化)
CommentList.Visible = true;
BindEmployeeData(nQuestionID);
IntegrateCommentList.Visible = false;
}
}
protected void SubmitBtn_Click(object sender, System.EventArgs e)
{
EmployeeCommentTypeDB employee = new EmployeeCommentTypeDB();
CommentDB comment = new CommentDB();
if(Comment.Text.Trim().Length > 0)
{
//添加问题的详细评论
if(nCommentID > 0)
{
try
{
comment.UpdateComment(nCommentID,CleanString.InputText(Comment.Text,Comment.Text.Length));
Response.Write("<script>alert(\"修改报修问题的评论成功!\");</script>");
}
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
{
try
{
comment.AddComment(CleanString.InputText(Comment.Text,Comment.Text.Length),nQuestionID);
}
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"," "));
}
if(IntPerComment.SelectedIndex == 0)
{
//保存总体评价
EmployeeQuestionDB employeeQ = new EmployeeQuestionDB();
SqlDataReader rece = employeeQ.GetEmployeeByQuestion(nQuestionID);
while(rece.Read())
{
try
{
employee.AddEmployeeCommentType(Int32.Parse(rece["EmployeeID"].ToString()),
Int32.Parse(IntegrateCommentList.SelectedValue));
}
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"," "));
}
}
rece.Close();
}
else
{
//保存对个人的评价
foreach(DataGridItem gridItem in CommentList.Items)
{
Label label = (Label)gridItem.FindControl("EmployeeID");
DropDownList dropList = (DropDownList)gridItem.FindControl("DegreeList");
if(dropList != null && label != null)
{
try
{
employee.AddEmployeeCommentType(Int32.Parse(label.Text),Int32.Parse(dropList.SelectedValue));
}
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"," "));
}
}
}
}
Comment.Text = "";
Response.Write("<script>alert(\"添加报修问题的评论成功!\");</script>");
}
}
else
{
Response.Write("<script>alert(\"报修问题的评论不能为空,请输入问题的评论!\");</script>");
}
}
private void CommentList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(IntPerComment.SelectedIndex == 1)
{
//动态绑定个人评价等级
DropDownList dropList = (DropDownList)e.Item.FindControl("DegreeList");
if(dropList != null)
{
BindCommentTypeData(dropList);
}
}
}
protected void Resetbtn_Click(object sender, System.EventArgs e)
{
Comment.Text = "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -