/// <summary> /// 得到一个对象实体 /// </summary> public Bsam.Core.Model.Models.Model.BlogArticle DataRowToModel(DataRow row) { Bsam.Core.Model.Models.Model.BlogArticle model = new Bsam.Core.Model.Models.Model.BlogArticle(); if (row != null) { if (row["bID"] != null && row["bID"].ToString() != "") { model.bID = int.Parse(row["bID"].ToString()); } if (row["bsubmitter"] != null) { model.bsubmitter = row["bsubmitter"].ToString(); } if (row["btitle"] != null) { model.btitle = row["btitle"].ToString(); } if (row["bcategory"] != null) { model.bcategory = row["bcategory"].ToString(); } if (row["bcontent"] != null) { model.bcontent = row["bcontent"].ToString(); } if (row["btraffic"] != null && row["btraffic"].ToString() != "") { model.btraffic = int.Parse(row["btraffic"].ToString()); } if (row["bcommentNum"] != null && row["bcommentNum"].ToString() != "") { model.bcommentNum = int.Parse(row["bcommentNum"].ToString()); } if (row["bUpdateTime"] != null && row["bUpdateTime"].ToString() != "") { model.bUpdateTime = DateTime.Parse(row["bUpdateTime"].ToString()); } if (row["bCreateTime"] != null && row["bCreateTime"].ToString() != "") { model.bCreateTime = DateTime.Parse(row["bCreateTime"].ToString()); } if (row["bRemark"] != null) { model.bRemark = row["bRemark"].ToString(); } if (row["IsDeleted"] != null && row["IsDeleted"].ToString() != "") { if ((row["IsDeleted"].ToString() == "1") || (row["IsDeleted"].ToString().ToLower() == "true")) { model.IsDeleted = true; } else { model.IsDeleted = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Bsam.Core.Model.Models.Model.BlogArticle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BlogArticle set "); strSql.Append("bsubmitter=@bsubmitter,"); strSql.Append("btitle=@btitle,"); strSql.Append("bcategory=@bcategory,"); strSql.Append("bcontent=@bcontent,"); strSql.Append("btraffic=@btraffic,"); strSql.Append("bcommentNum=@bcommentNum,"); strSql.Append("bUpdateTime=@bUpdateTime,"); strSql.Append("bCreateTime=@bCreateTime,"); strSql.Append("bRemark=@bRemark,"); strSql.Append("IsDeleted=@IsDeleted"); strSql.Append(" where bID=@bID"); SQLiteParameter[] parameters = { new SQLiteParameter("@bsubmitter", DbType.String), new SQLiteParameter("@btitle", DbType.String), new SQLiteParameter("@bcategory", DbType.String), new SQLiteParameter("@bcontent", DbType.String), new SQLiteParameter("@btraffic", DbType.Int32, 8), new SQLiteParameter("@bcommentNum", DbType.Int32, 8), new SQLiteParameter("@bUpdateTime", DbType.DateTime), new SQLiteParameter("@bCreateTime", DbType.DateTime), new SQLiteParameter("@bRemark", DbType.String), new SQLiteParameter("@IsDeleted", DbType.bit, 1), new SQLiteParameter("@bID", DbType.Int32, 8) }; parameters[0].Value = model.bsubmitter; parameters[1].Value = model.btitle; parameters[2].Value = model.bcategory; parameters[3].Value = model.bcontent; parameters[4].Value = model.btraffic; parameters[5].Value = model.bcommentNum; parameters[6].Value = model.bUpdateTime; parameters[7].Value = model.bCreateTime; parameters[8].Value = model.bRemark; parameters[9].Value = model.IsDeleted; parameters[10].Value = model.bID; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int bID) { Bsam.Core.Model.Models.BLL.BlogArticle bll = new Bsam.Core.Model.Models.BLL.BlogArticle(); Bsam.Core.Model.Models.Model.BlogArticle model = bll.GetModel(bID); this.lblbID.Text = model.bID.ToString(); this.txtbsubmitter.Text = model.bsubmitter; this.txtbtitle.Text = model.btitle; this.txtbcategory.Text = model.bcategory; this.txtbcontent.Text = model.bcontent; this.txtbtraffic.Text = model.btraffic.ToString(); this.txtbcommentNum.Text = model.bcommentNum.ToString(); this.txtbUpdateTime.Text = model.bUpdateTime.ToString(); this.txtbCreateTime.Text = model.bCreateTime.ToString(); this.txtbRemark.Text = model.bRemark; this.chkIsDeleted.Checked = model.IsDeleted; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Bsam.Core.Model.Models.Model.BlogArticle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BlogArticle("); strSql.Append("bsubmitter,btitle,bcategory,bcontent,btraffic,bcommentNum,bUpdateTime,bCreateTime,bRemark,IsDeleted)"); strSql.Append(" values ("); strSql.Append("@bsubmitter,@btitle,@bcategory,@bcontent,@btraffic,@bcommentNum,@bUpdateTime,@bCreateTime,@bRemark,@IsDeleted)"); strSql.Append(";select LAST_INSERT_ROWID()"); SQLiteParameter[] parameters = { new SQLiteParameter("@bsubmitter", DbType.String), new SQLiteParameter("@btitle", DbType.String), new SQLiteParameter("@bcategory", DbType.String), new SQLiteParameter("@bcontent", DbType.String), new SQLiteParameter("@btraffic", DbType.Int32, 8), new SQLiteParameter("@bcommentNum", DbType.Int32, 8), new SQLiteParameter("@bUpdateTime", DbType.DateTime), new SQLiteParameter("@bCreateTime", DbType.DateTime), new SQLiteParameter("@bRemark", DbType.String), new SQLiteParameter("@IsDeleted", DbType.bit, 1) }; parameters[0].Value = model.bsubmitter; parameters[1].Value = model.btitle; parameters[2].Value = model.bcategory; parameters[3].Value = model.bcontent; parameters[4].Value = model.btraffic; parameters[5].Value = model.bcommentNum; parameters[6].Value = model.bUpdateTime; parameters[7].Value = model.bCreateTime; parameters[8].Value = model.bRemark; parameters[9].Value = model.IsDeleted; 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.BlogArticle GetModel(int bID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select bID,bsubmitter,btitle,bcategory,bcontent,btraffic,bcommentNum,bUpdateTime,bCreateTime,bRemark,IsDeleted from BlogArticle "); strSql.Append(" where bID=@bID"); SQLiteParameter[] parameters = { new SQLiteParameter("@bID", DbType.Int32, 4) }; parameters[0].Value = bID; Bsam.Core.Model.Models.Model.BlogArticle model = new Bsam.Core.Model.Models.Model.BlogArticle(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtbsubmitter.Text.Trim().Length == 0) { strErr += "bsubmitter不能为空!\\n"; } if (this.txtbtitle.Text.Trim().Length == 0) { strErr += "btitle不能为空!\\n"; } if (this.txtbcategory.Text.Trim().Length == 0) { strErr += "bcategory不能为空!\\n"; } if (this.txtbcontent.Text.Trim().Length == 0) { strErr += "bcontent不能为空!\\n"; } if (!PageValidate.IsNumber(txtbtraffic.Text)) { strErr += "btraffic格式错误!\\n"; } if (!PageValidate.IsNumber(txtbcommentNum.Text)) { strErr += "bcommentNum格式错误!\\n"; } if (!PageValidate.IsDateTime(txtbUpdateTime.Text)) { strErr += "bUpdateTime格式错误!\\n"; } if (!PageValidate.IsDateTime(txtbCreateTime.Text)) { strErr += "bCreateTime格式错误!\\n"; } if (this.txtbRemark.Text.Trim().Length == 0) { strErr += "bRemark不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string bsubmitter = this.txtbsubmitter.Text; string btitle = this.txtbtitle.Text; string bcategory = this.txtbcategory.Text; string bcontent = this.txtbcontent.Text; int btraffic = int.Parse(this.txtbtraffic.Text); int bcommentNum = int.Parse(this.txtbcommentNum.Text); DateTime bUpdateTime = DateTime.Parse(this.txtbUpdateTime.Text); DateTime bCreateTime = DateTime.Parse(this.txtbCreateTime.Text); string bRemark = this.txtbRemark.Text; bool IsDeleted = this.chkIsDeleted.Checked; Bsam.Core.Model.Models.Model.BlogArticle model = new Bsam.Core.Model.Models.Model.BlogArticle(); model.bsubmitter = bsubmitter; model.btitle = btitle; model.bcategory = bcategory; model.bcontent = bcontent; model.btraffic = btraffic; model.bcommentNum = bcommentNum; model.bUpdateTime = bUpdateTime; model.bCreateTime = bCreateTime; model.bRemark = bRemark; model.IsDeleted = IsDeleted; Bsam.Core.Model.Models.BLL.BlogArticle bll = new Bsam.Core.Model.Models.BLL.BlogArticle(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }