DAL中:
//////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.Answer GetModel(string AnswerID,string QuestionID)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 ");
strSql.Append(" AnswerID,QuestionID,TeacherID,AnswerContent,AnswerStatus,AnswerTime");
strSql.Append(" from Answer ");
strSql.Append(" where AnswerID='"+AnswerID+"' and QuestionID='"+QuestionID+"' " );
Model.Answer model=new Model.Answer();
DataSet ds=DbHelperSQL.Query(strSql.ToString());
if(ds.Tables[0].Rows.Count>0)
{
model.AnswerID=ds.Tables[0].Rows[0]["AnswerID"].ToString();
model.QuestionID=ds.Tables[0].Rows[0]["QuestionID"].ToString();
model.TeacherID=ds.Tables[0].Rows[0]["TeacherID"].ToString();
model.AnswerContent=ds.Tables[0].Rows[0]["AnswerContent"].ToString();
if(ds.Tables[0].Rows[0]["AnswerStatus"].ToString()!="")
{
model.AnswerStatus=int.Parse(ds.Tables[0].Rows[0]["AnswerStatus"].ToString());
}
model.AnswerTime = DateTime.Parse(ds.Tables[0].Rows[0]["AnswerTime"].ToString());
return model;
}
else
{
return null;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
BLL中:
/////////////////////////////////////////////////////////////////////////////////////////////////////
public Model.Answer GetModel(string AnswerID,string QuestionID)
{
return dal.GetModel(AnswerID,QuestionID);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
Answer.aspx页面DataGrid中:
/////////////////////////////////////////////////////////////////////////////////////////////////////
<td style="width: 796px;background-color:White; color:#284775;"><div align="left"><asp:LinkButton ID="lbtnUpdate" runat="server" Text="更改回复状态" CommandArgument='<%# Eval("id") %>' CommandName="update"></asp:LinkButton> <asp:LinkButton ID="lbtnDel" runat="server" Text="删除" CommandArgument='<%# Eval("id") %>' CommandName="del"></asp:LinkButton></div></td>
/////////////////////////////////////////////////////////////////////////////////////////////////////
Answer.aspx.cs:
/////////////////////////////////////////////////////////////////////////////////////////////////////
if (e.CommandName == "update")
{
Label lblQuestionID = (Label)e.Item.FindControl("lblQuestionID");
string strSql = "";
Course.BLL.Answer answerBLL = new Course.BLL.Answer();
Course.Model.Answer answerModel = new Course.Model.Answer();
//ke neng shi zheju cuowu
answerModel = answerBLL.GetModel(e.CommandArgument.ToString(),lblQuestionID.Text);
if (answerModel.AnswerStatus == 0)
{
strSql = "update Answer set AnswerStatus=1 where AnswerID='" + e.CommandArgument.ToString() + "'";
}
else
{
strSql = "update Answer set AnswerStatus=0 where AnswerID='" + e.CommandArgument.ToString() + "'";
}
Maticsoft.DBUtility.myDb db = new Maticsoft.DBUtility.myDb();
db.ExeSql(strSql);
bindAnswer();
}//更新状态
//////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.Answer GetModel(string AnswerID,string QuestionID)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 ");
strSql.Append(" AnswerID,QuestionID,TeacherID,AnswerContent,AnswerStatus,AnswerTime");
strSql.Append(" from Answer ");
strSql.Append(" where AnswerID='"+AnswerID+"' and QuestionID='"+QuestionID+"' " );
Model.Answer model=new Model.Answer();
DataSet ds=DbHelperSQL.Query(strSql.ToString());
if(ds.Tables[0].Rows.Count>0)
{
model.AnswerID=ds.Tables[0].Rows[0]["AnswerID"].ToString();
model.QuestionID=ds.Tables[0].Rows[0]["QuestionID"].ToString();
model.TeacherID=ds.Tables[0].Rows[0]["TeacherID"].ToString();
model.AnswerContent=ds.Tables[0].Rows[0]["AnswerContent"].ToString();
if(ds.Tables[0].Rows[0]["AnswerStatus"].ToString()!="")
{
model.AnswerStatus=int.Parse(ds.Tables[0].Rows[0]["AnswerStatus"].ToString());
}
model.AnswerTime = DateTime.Parse(ds.Tables[0].Rows[0]["AnswerTime"].ToString());
return model;
}
else
{
return null;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
BLL中:
/////////////////////////////////////////////////////////////////////////////////////////////////////
public Model.Answer GetModel(string AnswerID,string QuestionID)
{
return dal.GetModel(AnswerID,QuestionID);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
Answer.aspx页面DataGrid中:
/////////////////////////////////////////////////////////////////////////////////////////////////////
<td style="width: 796px;background-color:White; color:#284775;"><div align="left"><asp:LinkButton ID="lbtnUpdate" runat="server" Text="更改回复状态" CommandArgument='<%# Eval("id") %>' CommandName="update"></asp:LinkButton> <asp:LinkButton ID="lbtnDel" runat="server" Text="删除" CommandArgument='<%# Eval("id") %>' CommandName="del"></asp:LinkButton></div></td>
/////////////////////////////////////////////////////////////////////////////////////////////////////
Answer.aspx.cs:
/////////////////////////////////////////////////////////////////////////////////////////////////////
if (e.CommandName == "update")
{
Label lblQuestionID = (Label)e.Item.FindControl("lblQuestionID");
string strSql = "";
Course.BLL.Answer answerBLL = new Course.BLL.Answer();
Course.Model.Answer answerModel = new Course.Model.Answer();
//ke neng shi zheju cuowu
answerModel = answerBLL.GetModel(e.CommandArgument.ToString(),lblQuestionID.Text);
if (answerModel.AnswerStatus == 0)
{
strSql = "update Answer set AnswerStatus=1 where AnswerID='" + e.CommandArgument.ToString() + "'";
}
else
{
strSql = "update Answer set AnswerStatus=0 where AnswerID='" + e.CommandArgument.ToString() + "'";
}
Maticsoft.DBUtility.myDb db = new Maticsoft.DBUtility.myDb();
db.ExeSql(strSql);
bindAnswer();
}//更新状态
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货