protected void btnSave_Click(object sender, EventArgs e) { string strErr=""; if(!PageValidate.IsNumber(txtchat_ID.Text)) { strErr+="聊天记录ID格式错误!\\n"; } if(!PageValidate.IsNumber(txtchat_FROM.Text)) { strErr+="聊天记录FROM格式错误!\\n"; } if(!PageValidate.IsNumber(txtchat_TO.Text)) { strErr+="聊天记录TO格式错误!\\n"; } if(this.txtchat_content.Text.Trim().Length==0) { strErr+="聊天内容不能为空!\\n"; } if(!PageValidate.IsDateTime(txtchat_time.Text)) { strErr+="聊天时间格式错误!\\n"; } if(this.txtchat_comment.Text.Trim().Length==0) { strErr+="聊天备注不能为空!\\n"; } if(this.txtchat_state.Text.Trim().Length==0) { strErr+="聊天记录状态不能为空!\\n"; } if(strErr!="") { MessageBox.Show(this,strErr); return; } int chat_ID=int.Parse(this.txtchat_ID.Text); int chat_FROM=int.Parse(this.txtchat_FROM.Text); int chat_TO=int.Parse(this.txtchat_TO.Text); string chat_content=this.txtchat_content.Text; DateTime chat_time=DateTime.Parse(this.txtchat_time.Text); string chat_comment=this.txtchat_comment.Text; string chat_state=this.txtchat_state.Text; la.Model.chat_message model=new la.Model.chat_message(); model.chat_ID=chat_ID; model.chat_FROM=chat_FROM; model.chat_TO=chat_TO; model.chat_content=chat_content; model.chat_time=chat_time; model.chat_comment=chat_comment; model.chat_state=chat_state; la.BLL.chat_message bll=new la.BLL.chat_message(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功!","add.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public la.Model.chat_message DataRowToModel(DataRow row) { la.Model.chat_message model=new la.Model.chat_message(); if (row != null) { if(row["chat_ID"]!=null && row["chat_ID"].ToString()!="") { model.chat_ID=int.Parse(row["chat_ID"].ToString()); } if(row["chat_FROM"]!=null && row["chat_FROM"].ToString()!="") { model.chat_FROM=int.Parse(row["chat_FROM"].ToString()); } if(row["chat_TO"]!=null && row["chat_TO"].ToString()!="") { model.chat_TO=int.Parse(row["chat_TO"].ToString()); } if(row["chat_content"]!=null) { model.chat_content=row["chat_content"].ToString(); } if(row["chat_time"]!=null && row["chat_time"].ToString()!="") { model.chat_time=DateTime.Parse(row["chat_time"].ToString()); } if(row["chat_comment"]!=null) { model.chat_comment=row["chat_comment"].ToString(); } if(row["chat_state"]!=null) { model.chat_state=row["chat_state"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public la.Model.chat_message GetModel(int chat_ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 chat_ID,chat_FROM,chat_TO,chat_content,chat_time,chat_comment,chat_state from chat_message "); strSql.Append(" where chat_ID=@chat_ID "); SqlParameter[] parameters = { new SqlParameter("@chat_ID", SqlDbType.Int,4) }; parameters[0].Value = chat_ID; la.Model.chat_message model=new la.Model.chat_message(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }