protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txttsid.Text)) { strErr += "tsid格式错误!\\n"; } if (!PageValidate.IsNumber(txttuid.Text)) { strErr += "tuid格式错误!\\n"; } if (!PageValidate.IsNumber(txttreplycount.Text)) { strErr += "treplycount格式错误!\\n"; } if (this.txtTTopic.Text.Trim().Length == 0) { strErr += "TTopic不能为空!\\n"; } if (this.txtTContents.Text.Trim().Length == 0) { strErr += "TContents不能为空!\\n"; } if (!PageValidate.IsDateTime(txtTTime.Text)) { strErr += "TTime格式错误!\\n"; } if (!PageValidate.IsNumber(txtTClickCount.Text)) { strErr += "TClickCount格式错误!\\n"; } if (!PageValidate.IsDateTime(txtTLastClickT.Text)) { strErr += "TLastClickT格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int tsid = int.Parse(this.txttsid.Text); int tuid = int.Parse(this.txttuid.Text); int treplycount = int.Parse(this.txttreplycount.Text); string TTopic = this.txtTTopic.Text; string TContents = this.txtTContents.Text; DateTime TTime = DateTime.Parse(this.txtTTime.Text); int TClickCount = int.Parse(this.txtTClickCount.Text); DateTime TLastClickT = DateTime.Parse(this.txtTLastClickT.Text); BBS.Model.BBSTopic model = new BBS.Model.BBSTopic(); model.tsid = tsid; model.tuid = tuid; model.treplycount = treplycount; model.TTopic = TTopic; model.TContents = TContents; model.TTime = TTime; model.TClickCount = TClickCount; model.TLastClickT = TLastClickT; BBS.BLL.BBSTopic bll = new BBS.BLL.BBSTopic(); bll.Add(model); Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
public void ProcessRequest(HttpContext context) { // context.Response.ContentType = "text/plain"; context.Response.ContentType = "text/html"; string action = context.Request.Form["Action"]; string json = "{\"info\":\"已登录\"}"; if (action == "Load") { if (context.Session["ID"] == null) { json = "{\"info\":\"未登录\"}"; } else { BBS.BLL.BBSSection bll0 = new BBS.BLL.BBSSection(); DataSet ds = bll0.GetList(""); ds.Tables[0].TableName = "BBSSection"; string json1 = Web.DataConvertJson.DataTable2Json(ds.Tables[0]); json = "{\"info\":\"已登录\"," + json1.Substring(1); } } else if (action == "Add") { json = "{\"info\":\"发表失败\"}"; string content = context.Request.Form["Content"]; //保存文本框对象,提高效率 content = HttpContext.Current.Server.UrlDecode(content); //反编码 int tsid = int.Parse(context.Request.Form["section"]); int tuid = int.Parse(context.Session["ID"].ToString()); int treplycount = 0; string TTopic = context.Request.Form["title"]; string TContents = content; DateTime TTime = DateTime.Now; int TClickCount = 0; DateTime TLastClickT = DateTime.Now; BBS.Model.BBSTopic model = new BBS.Model.BBSTopic(); model.tsid = tsid; model.tuid = tuid; model.treplycount = treplycount; model.TTopic = TTopic; model.TContents = TContents; model.TTime = TTime; model.TClickCount = TClickCount; model.TLastClickT = TLastClickT; BBS.BLL.BBSTopic bll = new BBS.BLL.BBSTopic(); int n = bll.Add(model); //返回单个文字信息 if (n > 0) { json = "{\"info\":\"增加数据成功\",\"UID\":\"" + tuid + "\"}"; } } context.Response.Write(json); }