跟帖式回复,第二次回复会覆盖第一次的回复,不是每次都覆盖,只是偶尔

wodelaopos 2013-01-23 05:52:08
[img=http://]GN%365)YZWCB1JCXG3}I{XO.jpg[/img]有时候第二次的回复会覆盖掉第一次的回复.第一次的提问、回复和第二次的不在一张表里
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["database"].ToString());
con.Open();

SqlCommand cmd = new SqlCommand("select Flags,Retime from Question where id =@id",con);//查询主问题的状态与回复时间
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Request["id"].ToString();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
string flag = dt.Rows[0][0].ToString().Trim();
string retime = dt.Rows[0][1].ToString().Trim();
if (flag.Equals("处理中"))//根据状态判断如何操作
{
if (retime.Trim().Length == 0 ) //如果问题为处理中,则判断问题的回复者是否为该次登陆者,如果是同一人或有权限,则可以进入处理页面,反之则不准回复
{
cmd = new SqlCommand("select Number from Question where id =@id", con);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Request["id"].ToString();
if (Session["userid"].ToString().Equals(cmd.ExecuteScalar()) || Session["power"].ToString().Equals("1"))
{
string url="online_edit.aspx?id=" + Request["id"].ToString();
//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>window.open('" + url + "',''newwindow'') </script>");
//Response.Write(" <script>window.open('" + url + "') </script>");
Response.Redirect(url);
}
else
{
Response.Write("<script>alert('正在处理中。。。');</script>");
}
}
else
{
cmd = new SqlCommand("select Number from Discuss where QuestionID =@id and Retime is null", con);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Request["id"].ToString();
if (Session["userid"].ToString().Equals(cmd.ExecuteScalar()) || Session["power"].ToString().Equals("1"))
{
string url="online_edit.aspx?id=" + Request["id"].ToString();
//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>window.open('" + url + "',''newwindow'') </script>");
//Response.Write(" <script>window.open('" + url + "') </script>");
Response.Redirect(url);
}
else
{
Response.Write("<script>alert('正在处理中。。。。。');</script>");
}
}


}
else if (flag.Equals("已处理"))
{
Response.Write("<script>alert('已处理完毕');</script>");

}
else if (flag.Equals("转强制结案"))
{
Response.Write("<script>alert('已强制结案');</script>");

}
else if (flag.Equals("未处理"))//问题类型为未处理时,任何gm均可处理
{
//Response.Write("<script>alert('未处理');</script>");

cmd = new SqlCommand("update Question set Flags='处理中' where id =@id", con);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Request["id"].ToString();

try
{
cmd.ExecuteNonQuery();
string url = "online_edit.aspx?id=" + Request["id"].ToString();
//Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", " <script>window.open('" + url + "',''newwindow'') </script>");
//Response.Write(" <script>window.open('" + url + "') </script>");
Response.Redirect(url);
}
catch (Exception ex)
{
//Response.Write(ex);
}
}
else
{
Response.Write("<script>alert("+flag+");</script>");
}
con.Close();
}
这个是显示页面的后置代码,点击这个页面的处理,会跳到另一个页面输入数据,在另一个页面处理后返回显示页面,下面是处理页面的代码

public partial class server_behind_Default2 : System.Web.UI.Page
{
static string tableid = "";
public sgc_kf sgc = new sgc_kf();
protected void Page_Load(object sender, EventArgs e)
{
// if (Session["userid"] == null) Response.Redirect("login.aspx");
if (!IsPostBack)
{

this.bind();
}
}
public void bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["database"].ToString());
con.Open();


SqlCommand cmd = new SqlCommand("select * from Question where id=@cid",con);
cmd.Parameters.Add("@cid", SqlDbType.Int).Value = Request["id"].ToString();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());

Label1.Text = dt.Rows[0]["Questions"].ToString();

if (dt.Rows[0][21].ToString().Trim().Length == 0)//根据回复时间判断本次处理回复的是哪张表里的内容
{
SqlCommand qcmd = new SqlCommand("update Question set Number=@userid where id=@uid", con);//获取gm工号,存入数据库
qcmd.Parameters.Add("@uid", SqlDbType.Int).Value = Request["id"].ToString();
qcmd.Parameters.Add("@userid", SqlDbType.VarChar).Value = Session["userid"].ToString();
qcmd.ExecuteNonQuery();
TextBox1.Text = dt.Rows[0]["Content"].ToString();
Label3.Text = dt.Rows[0][22].ToString();
tableid = "Question";

}
else
{
SqlCommand wcmd = new SqlCommand("update Discuss set Number=@userid where QuestionID=@uid and Retime is null", con);//获取gm工号,存入数据库
wcmd.Parameters.Add("@uid", SqlDbType.Int).Value = Request["id"].ToString();
wcmd.Parameters.Add("@userid", SqlDbType.VarChar).Value = Session["userid"].ToString();
wcmd.ExecuteNonQuery();

DataTable dtline = new DataTable();
cmd.CommandText = "select Content,AddTime from Discuss where ReTime is null and QuestionID=@sid";
cmd.Parameters.Add("@sid", SqlDbType.Int).Value = Request["id"].ToString();
dtline.Load(cmd.ExecuteReader());

TextBox1.Text = dtline.Rows[0][0].ToString();
Label3.Text = dtline.Rows[0][1].ToString();

tableid = "Discuss";

}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if (txta_transact.Value.Length > 0)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["database"].ToString());
con.Open();
SqlCommand cmd;
SqlCommand cmd1;

if (tableid.Equals("Question"))//添加处理内容和时间
{
SqlCommand cmd0 = new SqlCommand("select * from Question where id=@cid", con);
cmd0.Parameters.Add("@cid", SqlDbType.Int).Value = Request["id"].ToString();
DataTable dte = new DataTable();
dte.Load(cmd0.ExecuteReader());
if ((dte.Rows[0]["ReContent"].ToString() == null || dte.Rows[0]["ReContent"].ToString() == "") && (dte.Rows[0]["ReTime"].ToString().Length == 0))
{
cmd = new SqlCommand("update Question set ReContent=@txt,Retime=getdate() where id=@id", con);
cmd.Parameters.Add("@txt", SqlDbType.VarChar).Value = txta_transact.Value;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Request["id"].ToString();
cmd.ExecuteNonQuery();
}


}
else//添加处理内容和时间
{
if (tableid.Equals("Discuss"))//如果操作的表为Discuss
{
cmd = new SqlCommand("update Discuss set ReContent=@txt,ReTime=getdate() where QuestionID=@id and ReTime is null", con);
cmd.Parameters.Add("@txt", SqlDbType.VarChar).Value = txta_transact.Value;
cmd.Parameters.Add("@id", SqlDbType.Int).Value = Request["id"].ToString();
cmd.ExecuteNonQuery();
}

}

cmd1 = new SqlCommand("update Question set Flags='已处理',isread=0 where id=@pid", con);//更改主问题状态
cmd1.Parameters.Add("@pid", SqlDbType.Int).Value = Request["id"].ToString();
try
{

cmd1.ExecuteNonQuery();
//Response.Write("<script>alert('处理成功');window.location='online.aspx?type=0'</script>");
}
catch (Exception ex)
{
Response.Write(ex);
}

调试了好几天也没发现哪里的问题,求大神们帮忙解决感激不尽
...全文
106 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
风一样的大叔 2013-01-26
  • 打赏
  • 举报
回复
楼主可以把关键的代码贴出来就可以了
段传涛 2013-01-25
  • 打赏
  • 举报
回复
代码好长, 注意 关键字或id
strife013 2013-01-25
  • 打赏
  • 举报
回复
逻辑太复杂了,建议写成小段代码
wodelaopos 2013-01-25
  • 打赏
  • 举报
回复
都没人回答啊

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧