protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = int.Parse(Request["id"]); college = bll.GetModel(id); txtName.Text = college.Name; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Eva.Model.College DataRowToModel(DataRow row) { Eva.Model.College model=new Eva.Model.College(); if (row != null) { if(row["Id"]!=null && row["Id"].ToString()!="") { model.Id=int.Parse(row["Id"].ToString()); } if(row["Name"]!=null) { model.Name=row["Name"].ToString(); } } return model; }
protected void btnSave_Click(object sender, EventArgs e) { string strErr=""; if(this.txtName.Text.Trim().Length==0) { strErr+="Name不能为空!\\n"; } if(strErr!="") { MessageBox.Show(this,strErr); return; } string Name=this.txtName.Text; Eva.Model.College model=new Eva.Model.College(); model.Name=Name; Eva.BLL.College bll=new Eva.BLL.College(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功!","add.aspx"); }
public void btnSave_Click(object sender, EventArgs e) { string strErr=""; if(this.txtName.Text.Trim().Length==0) { strErr+="Name不能为空!\\n"; } if(strErr!="") { MessageBox.Show(this,strErr); return; } int Id=int.Parse(this.lblId.Text); string Name=this.txtName.Text; Eva.Model.College model=new Eva.Model.College(); model.Id=Id; model.Name=Name; Eva.BLL.College bll=new Eva.BLL.College(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功!","list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public Eva.Model.College GetModel(int Id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Id,Name from College "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; Eva.Model.College model=new Eva.Model.College(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }