/// <summary> /// 得到一个对象实体 /// </summary> public DNSABC.Model.DNSABC_MessagesResult GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,MessagesID,UserID,AdminID,Title,Contents,IP,CreateTime from DNSABC_MessagesResult "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; DNSABC.Model.DNSABC_MessagesResult model = new DNSABC.Model.DNSABC_MessagesResult(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if (ds.Tables[0].Rows[0]["MessagesID"] != null && ds.Tables[0].Rows[0]["MessagesID"].ToString() != "") { model.MessagesID = int.Parse(ds.Tables[0].Rows[0]["MessagesID"].ToString()); } if (ds.Tables[0].Rows[0]["UserID"] != null && ds.Tables[0].Rows[0]["UserID"].ToString() != "") { model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString()); } if (ds.Tables[0].Rows[0]["AdminID"] != null && ds.Tables[0].Rows[0]["AdminID"].ToString() != "") { model.AdminID = int.Parse(ds.Tables[0].Rows[0]["AdminID"].ToString()); } if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "") { model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); } if (ds.Tables[0].Rows[0]["Contents"] != null && ds.Tables[0].Rows[0]["Contents"].ToString() != "") { model.Contents = ds.Tables[0].Rows[0]["Contents"].ToString(); } if (ds.Tables[0].Rows[0]["IP"] != null && ds.Tables[0].Rows[0]["IP"].ToString() != "") { model.IP = ds.Tables[0].Rows[0]["IP"].ToString(); } if (ds.Tables[0].Rows[0]["CreateTime"] != null && ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } return(model); } else { return(null); } }
private void ShowInfo(int Id) { DNSABC.BLL.DNSABC_MessagesResult bll = new DNSABC.BLL.DNSABC_MessagesResult(); DNSABC.Model.DNSABC_MessagesResult model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.lblMessagesID.Text = model.MessagesID.ToString(); this.lblUserID.Text = model.UserID.ToString(); this.lblAdminID.Text = model.AdminID.ToString(); this.lblTitle.Text = model.Title; this.lblContents.Text = model.Contents; this.lblIP.Text = model.IP; this.lblCreateTime.Text = model.CreateTime.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DNSABC.Model.DNSABC_MessagesResult model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update DNSABC_MessagesResult set "); strSql.Append("MessagesID=@MessagesID,"); strSql.Append("UserID=@UserID,"); strSql.Append("AdminID=@AdminID,"); strSql.Append("Title=@Title,"); strSql.Append("Contents=@Contents,"); strSql.Append("IP=@IP,"); strSql.Append("CreateTime=@CreateTime"); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@MessagesID", SqlDbType.Int, 4), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@AdminID", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.VarChar, 200), new SqlParameter("@Contents", SqlDbType.VarChar, 8000), new SqlParameter("@IP", SqlDbType.VarChar, 20), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.MessagesID; parameters[1].Value = model.UserID; parameters[2].Value = model.AdminID; parameters[3].Value = model.Title; parameters[4].Value = model.Contents; parameters[5].Value = model.IP; parameters[6].Value = model.CreateTime; parameters[7].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(DNSABC.Model.DNSABC_MessagesResult model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into DNSABC_MessagesResult("); strSql.Append("Id,MessagesID,UserID,AdminID,Title,Contents,IP,CreateTime)"); strSql.Append(" values ("); strSql.Append("@Id,@MessagesID,@UserID,@AdminID,@Title,@Contents,@IP,@CreateTime)"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@MessagesID", SqlDbType.Int, 4), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@AdminID", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.VarChar, 200), new SqlParameter("@Contents", SqlDbType.VarChar, 8000), new SqlParameter("@IP", SqlDbType.VarChar, 20), new SqlParameter("@CreateTime", SqlDbType.DateTime) }; parameters[0].Value = model.Id; parameters[1].Value = model.MessagesID; parameters[2].Value = model.UserID; parameters[3].Value = model.AdminID; parameters[4].Value = model.Title; parameters[5].Value = model.Contents; parameters[6].Value = model.IP; parameters[7].Value = model.CreateTime; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtId.Text)) { strErr += "编号格式错误!\\n"; } if (!PageValidate.IsNumber(txtMessagesID.Text)) { strErr += "消息ID格式错误!\\n"; } if (!PageValidate.IsNumber(txtUserID.Text)) { strErr += "用户ID格式错误!\\n"; } if (!PageValidate.IsNumber(txtAdminID.Text)) { strErr += "【管理员字段】管理员ID格式错误!\\n"; } if (this.txtTitle.Text.Trim().Length == 0) { strErr += "标题不能为空!\\n"; } if (this.txtContents.Text.Trim().Length == 0) { strErr += "内容不能为空!\\n"; } if (this.txtIP.Text.Trim().Length == 0) { strErr += "IP不能为空!\\n"; } if (!PageValidate.IsDateTime(txtCreateTime.Text)) { strErr += "发布时间格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Id = int.Parse(this.txtId.Text); int MessagesID = int.Parse(this.txtMessagesID.Text); int UserID = int.Parse(this.txtUserID.Text); int AdminID = int.Parse(this.txtAdminID.Text); string Title = this.txtTitle.Text; string Contents = this.txtContents.Text; string IP = this.txtIP.Text; DateTime CreateTime = DateTime.Parse(this.txtCreateTime.Text); DNSABC.Model.DNSABC_MessagesResult model = new DNSABC.Model.DNSABC_MessagesResult(); model.Id = Id; model.MessagesID = MessagesID; model.UserID = UserID; model.AdminID = AdminID; model.Title = Title; model.Contents = Contents; model.IP = IP; model.CreateTime = CreateTime; DNSABC.BLL.DNSABC_MessagesResult bll = new DNSABC.BLL.DNSABC_MessagesResult(); bll.Add(model); ROYcms.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }