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