/// <summary> /// 得到一个对象实体 /// </summary> public BBS.Model.BBSSection DataRowToModel(DataRow row) { BBS.Model.BBSSection model = new BBS.Model.BBSSection(); if (row != null) { if (row["SID"] != null && row["SID"].ToString() != "") { model.SID = int.Parse(row["SID"].ToString()); } if (row["SName"] != null) { model.SName = row["SName"].ToString(); } if (row["SMasterID"] != null && row["SMasterID"].ToString() != "") { model.SMasterID = int.Parse(row["SMasterID"].ToString()); } if (row["SStatement"] != null) { model.SStatement = row["SStatement"].ToString(); } if (row["SClickCount"] != null && row["SClickCount"].ToString() != "") { model.SClickCount = int.Parse(row["SClickCount"].ToString()); } if (row["STopicCount"] != null && row["STopicCount"].ToString() != "") { model.STopicCount = int.Parse(row["STopicCount"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BBS.Model.BBSSection model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BBSSection set "); if (model.SName != null) { strSql.Append("SName='" + model.SName + "',"); } else { strSql.Append("SName= null ,"); } if (model.SMasterID != null) { strSql.Append("SMasterID=" + model.SMasterID + ","); } if (model.SStatement != null) { strSql.Append("SStatement='" + model.SStatement + "',"); } else { strSql.Append("SStatement= null ,"); } if (model.SClickCount != null) { strSql.Append("SClickCount=" + model.SClickCount + ","); } else { strSql.Append("SClickCount= null ,"); } if (model.STopicCount != null) { strSql.Append("STopicCount=" + model.STopicCount + ","); } else { strSql.Append("STopicCount= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where SID=" + model.SID + ""); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
private void ShowInfo(int SID) { BBS.BLL.BBSSection bll = new BBS.BLL.BBSSection(); BBS.Model.BBSSection model = bll.GetModel(SID); this.lblSID.Text = model.SID.ToString(); this.lblSName.Text = model.SName; this.lblSMasterID.Text = model.SMasterID.ToString(); this.lblSStatement.Text = model.SStatement; this.lblSClickCount.Text = model.SClickCount.ToString(); this.lblSTopicCount.Text = model.STopicCount.ToString(); }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtSName.Text.Trim().Length == 0) { strErr += "SName不能为空!\\n"; } if (!PageValidate.IsNumber(txtSMasterID.Text)) { strErr += "SMasterID格式错误!\\n"; } if (this.txtSStatement.Text.Trim().Length == 0) { strErr += "SStatement不能为空!\\n"; } if (!PageValidate.IsNumber(txtSClickCount.Text)) { strErr += "SClickCount格式错误!\\n"; } if (!PageValidate.IsNumber(txtSTopicCount.Text)) { strErr += "STopicCount格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int SID = int.Parse(this.lblSID.Text); string SName = this.txtSName.Text; int SMasterID = int.Parse(this.txtSMasterID.Text); string SStatement = this.txtSStatement.Text; int SClickCount = int.Parse(this.txtSClickCount.Text); int STopicCount = int.Parse(this.txtSTopicCount.Text); BBS.Model.BBSSection model = new BBS.Model.BBSSection(); model.SID = SID; model.SName = SName; model.SMasterID = SMasterID; model.SStatement = SStatement; model.SClickCount = SClickCount; model.STopicCount = STopicCount; BBS.BLL.BBSSection bll = new BBS.BLL.BBSSection(); bll.Update(model); Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(BBS.Model.BBSSection model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.SName != null) { strSql1.Append("SName,"); strSql2.Append("'" + model.SName + "',"); } if (model.SMasterID != null) { strSql1.Append("SMasterID,"); strSql2.Append("" + model.SMasterID + ","); } if (model.SStatement != null) { strSql1.Append("SStatement,"); strSql2.Append("'" + model.SStatement + "',"); } if (model.SClickCount != null) { strSql1.Append("SClickCount,"); strSql2.Append("" + model.SClickCount + ","); } if (model.STopicCount != null) { strSql1.Append("STopicCount,"); strSql2.Append("" + model.STopicCount + ","); } strSql.Append("insert into BBSSection("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DbHelperSQL.GetSingle(strSql.ToString()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BBS.Model.BBSSection GetModel(int SID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" SID,SName,SMasterID,SStatement,SClickCount,STopicCount "); strSql.Append(" from BBSSection "); strSql.Append(" where SID=" + SID + ""); BBS.Model.BBSSection model = new BBS.Model.BBSSection(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }