/// <summary> /// 得到一个对象实体 /// </summary> public Bsam.Core.Model.Models.Model.Guestbook DataRowToModel(DataRow row) { Bsam.Core.Model.Models.Model.Guestbook model = new Bsam.Core.Model.Models.Model.Guestbook(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["blogId"] != null && row["blogId"].ToString() != "") { model.blogId = int.Parse(row["blogId"].ToString()); } if (row["createdate"] != null && row["createdate"].ToString() != "") { model.createdate = DateTime.Parse(row["createdate"].ToString()); } if (row["username"] != null) { model.username = row["username"].ToString(); } if (row["phone"] != null) { model.phone = row["phone"].ToString(); } if (row["QQ"] != null) { model.QQ = row["QQ"].ToString(); } if (row["body"] != null) { model.body = row["body"].ToString(); } if (row["ip"] != null) { model.ip = row["ip"].ToString(); } if (row["isshow"] != null && row["isshow"].ToString() != "") { if ((row["isshow"].ToString() == "1") || (row["isshow"].ToString().ToLower() == "true")) { model.isshow = true; } else { model.isshow = false; } } } return(model); }
private void ShowInfo(int id) { Bsam.Core.Model.Models.BLL.Guestbook bll = new Bsam.Core.Model.Models.BLL.Guestbook(); Bsam.Core.Model.Models.Model.Guestbook model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtblogId.Text = model.blogId.ToString(); this.txtcreatedate.Text = model.createdate.ToString(); this.txtusername.Text = model.username; this.txtphone.Text = model.phone; this.txtQQ.Text = model.QQ; this.txtbody.Text = model.body; this.txtip.Text = model.ip; this.chkisshow.Checked = model.isshow; }
private void ShowInfo(int id) { Bsam.Core.Model.Models.BLL.Guestbook bll = new Bsam.Core.Model.Models.BLL.Guestbook(); Bsam.Core.Model.Models.Model.Guestbook model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblblogId.Text = model.blogId.ToString(); this.lblcreatedate.Text = model.createdate.ToString(); this.lblusername.Text = model.username; this.lblphone.Text = model.phone; this.lblQQ.Text = model.QQ; this.lblbody.Text = model.body; this.lblip.Text = model.ip; this.lblisshow.Text = model.isshow?"是":"否"; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Bsam.Core.Model.Models.Model.Guestbook model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Guestbook set "); strSql.Append("blogId=@blogId,"); strSql.Append("createdate=@createdate,"); strSql.Append("username=@username,"); strSql.Append("phone=@phone,"); strSql.Append("QQ=@QQ,"); strSql.Append("body=@body,"); strSql.Append("ip=@ip,"); strSql.Append("isshow=@isshow"); strSql.Append(" where id=@id"); SQLiteParameter[] parameters = { new SQLiteParameter("@blogId", DbType.Int32, 8), new SQLiteParameter("@createdate", DbType.DateTime), new SQLiteParameter("@username", DbType.String), new SQLiteParameter("@phone", DbType.String), new SQLiteParameter("@QQ", DbType.String), new SQLiteParameter("@body", DbType.String), new SQLiteParameter("@ip", DbType.String), new SQLiteParameter("@isshow", DbType.bit, 1), new SQLiteParameter("@id", DbType.Int32, 8) }; parameters[0].Value = model.blogId; parameters[1].Value = model.createdate; parameters[2].Value = model.username; parameters[3].Value = model.phone; parameters[4].Value = model.QQ; parameters[5].Value = model.body; parameters[6].Value = model.ip; parameters[7].Value = model.isshow; parameters[8].Value = model.id; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Bsam.Core.Model.Models.Model.Guestbook model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Guestbook("); strSql.Append("blogId,createdate,username,phone,QQ,body,ip,isshow)"); strSql.Append(" values ("); strSql.Append("@blogId,@createdate,@username,@phone,@QQ,@body,@ip,@isshow)"); strSql.Append(";select LAST_INSERT_ROWID()"); SQLiteParameter[] parameters = { new SQLiteParameter("@blogId", DbType.Int32, 8), new SQLiteParameter("@createdate", DbType.DateTime), new SQLiteParameter("@username", DbType.String), new SQLiteParameter("@phone", DbType.String), new SQLiteParameter("@QQ", DbType.String), new SQLiteParameter("@body", DbType.String), new SQLiteParameter("@ip", DbType.String), new SQLiteParameter("@isshow", DbType.bit, 1) }; parameters[0].Value = model.blogId; parameters[1].Value = model.createdate; parameters[2].Value = model.username; parameters[3].Value = model.phone; parameters[4].Value = model.QQ; parameters[5].Value = model.body; parameters[6].Value = model.ip; parameters[7].Value = model.isshow; object obj = DbHelperSQLite.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Bsam.Core.Model.Models.Model.Guestbook GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,blogId,createdate,username,phone,QQ,body,ip,isshow from Guestbook "); strSql.Append(" where id=@id"); SQLiteParameter[] parameters = { new SQLiteParameter("@id", DbType.Int32, 4) }; parameters[0].Value = id; Bsam.Core.Model.Models.Model.Guestbook model = new Bsam.Core.Model.Models.Model.Guestbook(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtblogId.Text)) { strErr += "blogId格式错误!\\n"; } if (!PageValidate.IsDateTime(txtcreatedate.Text)) { strErr += "createdate格式错误!\\n"; } if (this.txtusername.Text.Trim().Length == 0) { strErr += "username不能为空!\\n"; } if (this.txtphone.Text.Trim().Length == 0) { strErr += "phone不能为空!\\n"; } if (this.txtQQ.Text.Trim().Length == 0) { strErr += "QQ不能为空!\\n"; } if (this.txtbody.Text.Trim().Length == 0) { strErr += "body不能为空!\\n"; } if (this.txtip.Text.Trim().Length == 0) { strErr += "ip不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); int blogId = int.Parse(this.txtblogId.Text); DateTime createdate = DateTime.Parse(this.txtcreatedate.Text); string username = this.txtusername.Text; string phone = this.txtphone.Text; string QQ = this.txtQQ.Text; string body = this.txtbody.Text; string ip = this.txtip.Text; bool isshow = this.chkisshow.Checked; Bsam.Core.Model.Models.Model.Guestbook model = new Bsam.Core.Model.Models.Model.Guestbook(); model.id = id; model.blogId = blogId; model.createdate = createdate; model.username = username; model.phone = phone; model.QQ = QQ; model.body = body; model.ip = ip; model.isshow = isshow; Bsam.Core.Model.Models.BLL.Guestbook bll = new Bsam.Core.Model.Models.BLL.Guestbook(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }