/// <summary> /// 得到一个对象实体 /// </summary> public la.Model.carInfo DataRowToModel(DataRow row) { la.Model.carInfo model=new la.Model.carInfo(); if (row != null) { if(row["car_id"]!=null && row["car_id"].ToString()!="") { model.car_id=int.Parse(row["car_id"].ToString()); } if(row["user_telphone"]!=null) { model.user_telphone=row["user_telphone"].ToString(); } if(row["car_level"]!=null) { model.car_level=row["car_level"].ToString(); } if(row["car_brand"]!=null) { model.car_brand=row["car_brand"].ToString(); } if(row["car_type"]!=null) { model.car_type=row["car_type"].ToString(); } if(row["car_photo1"]!=null) { model.car_photo1=row["car_photo1"].ToString(); } if(row["car_photo2"]!=null) { model.car_photo2=row["car_photo2"].ToString(); } if(row["car_photo3"]!=null) { model.car_photo3=row["car_photo3"].ToString(); } if(row["car_photo1_state"]!=null) { model.car_photo1_state=row["car_photo1_state"].ToString(); } if(row["car_photo2_state"]!=null) { model.car_photo2_state=row["car_photo2_state"].ToString(); } if(row["car_photo3_state"]!=null) { model.car_photo3_state=row["car_photo3_state"].ToString(); } } return model; }
public void btnSave_Click(object sender, EventArgs e) { string strErr=""; if(this.txtcar_level.Text.Trim().Length==0) { strErr+="车辆等级不能为空!\\n"; } if(this.txtcar_brand.Text.Trim().Length==0) { strErr+="车辆牌子不能为空!\\n"; } if(this.txtcar_type.Text.Trim().Length==0) { strErr+="车辆型号不能为空!\\n"; } if(this.txtcar_photo1.Text.Trim().Length==0) { strErr+="车辆图片1不能为空!\\n"; } if(this.txtcar_photo2.Text.Trim().Length==0) { strErr+="车辆图片2不能为空!\\n"; } if(this.txtcar_photo3.Text.Trim().Length==0) { strErr+="车辆图片3不能为空!\\n"; } if(this.txtcar_photo1_state.Text.Trim().Length==0) { strErr+="车辆图片1审核状态不能为空!\\n"; } if(this.txtcar_photo2_state.Text.Trim().Length==0) { strErr+="车辆图片2审核状态不能为空!\\n"; } if(this.txtcar_photo3_state.Text.Trim().Length==0) { strErr+="车辆图片3审核状态不能为空!\\n"; } if(strErr!="") { MessageBox.Show(this,strErr); return; } int car_id=int.Parse(this.lblcar_id.Text); string user_telphone=this.lbluser_telphone.Text; string car_level=this.txtcar_level.Text; string car_brand=this.txtcar_brand.Text; string car_type=this.txtcar_type.Text; string car_photo1=this.txtcar_photo1.Text; string car_photo2=this.txtcar_photo2.Text; string car_photo3=this.txtcar_photo3.Text; string car_photo1_state=this.txtcar_photo1_state.Text; string car_photo2_state=this.txtcar_photo2_state.Text; string car_photo3_state=this.txtcar_photo3_state.Text; la.Model.carInfo model=new la.Model.carInfo(); model.car_id=car_id; model.user_telphone=user_telphone; model.car_level=car_level; model.car_brand=car_brand; model.car_type=car_type; model.car_photo1=car_photo1; model.car_photo2=car_photo2; model.car_photo3=car_photo3; model.car_photo1_state=car_photo1_state; model.car_photo2_state=car_photo2_state; model.car_photo3_state=car_photo3_state; la.BLL.carInfo bll=new la.BLL.carInfo(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功!","list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public la.Model.carInfo GetModel(int car_id,string user_telphone) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 car_id,user_telphone,car_level,car_brand,car_type,car_photo1,car_photo2,car_photo3,car_photo1_state,car_photo2_state,car_photo3_state from carInfo "); strSql.Append(" where car_id=@car_id and user_telphone=@user_telphone "); SqlParameter[] parameters = { new SqlParameter("@car_id", SqlDbType.Int,4), new SqlParameter("@user_telphone", SqlDbType.VarChar,20) }; parameters[0].Value = car_id; parameters[1].Value = user_telphone; la.Model.carInfo model=new la.Model.carInfo(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }