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