/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.WorksItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into WorksItem("); strSql.Append("Title,No)"); strSql.Append(" values ("); strSql.Append("@Title,@No)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@No", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.No; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.WorksItem model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update WorksItem set "); strSql.Append("Title=@Title"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@No", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.ID; parameters[2].Value = model.No; 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 (this.txtTitle.Text.Trim().Length == 0) { strErr += "名称不能为空!\\n"; } if (!PageValidate.IsNumber(txtNo.Text)) { strErr += "No格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string Title = this.txtTitle.Text; int No = int.Parse(this.txtNo.Text); Maticsoft.Model.WorksItem model = new Maticsoft.Model.WorksItem(); model.Title = Title; model.No = No; Maticsoft.BLL.WorksItem bll = new Maticsoft.BLL.WorksItem(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtTitle.Text.Trim().Length == 0) { strErr += "名称不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int ID = int.Parse(this.lblID.Text); string Title = this.txtTitle.Text; int No = int.Parse(this.lblNo.Text); Maticsoft.Model.WorksItem model = new Maticsoft.Model.WorksItem(); model.ID = ID; model.Title = Title; model.No = No; Maticsoft.BLL.WorksItem bll = new Maticsoft.BLL.WorksItem(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int ID) { Maticsoft.BLL.WorksItem bll = new Maticsoft.BLL.WorksItem(); Maticsoft.Model.WorksItem model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.txtTitle.Text = model.Title; this.lblNo.Text = model.No.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.WorksItem DataRowToModel(DataRow row) { Maticsoft.Model.WorksItem model = new Maticsoft.Model.WorksItem(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Title"] != null) { model.Title = row["Title"].ToString(); } if (row["No"] != null && row["No"].ToString() != "") { model.No = int.Parse(row["No"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.WorksItem GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Title,No from WorksItem "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Maticsoft.Model.WorksItem model = new Maticsoft.Model.WorksItem(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }