/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.City DataRowToModel(DataRow row) { Maticsoft.Model.City model=new Maticsoft.Model.City(); if (row != null) { if(row["CityID"]!=null) { model.CityID=row["CityID"].ToString(); } if(row["ProvincesID"]!=null) { model.ProvincesID=row["ProvincesID"].ToString(); } if(row["CityName"]!=null) { model.CityName=row["CityName"].ToString(); } if(row["SortID"]!=null && row["SortID"].ToString()!="") { model.SortID=int.Parse(row["SortID"].ToString()); } if(row["CityCode"]!=null) { model.CityCode=row["CityCode"].ToString(); } if(row["IsOpen"]!=null && row["IsOpen"].ToString()!="") { if((row["IsOpen"].ToString()=="1")||(row["IsOpen"].ToString().ToLower()=="true")) { model.IsOpen=true; } else { model.IsOpen=false; } } if(row["Letter"]!=null) { model.Letter=row["Letter"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.City GetModel(string CityID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 CityID,ProvincesID,CityName,SortID,CityCode,IsOpen,Letter from City "); strSql.Append(" where CityID=@CityID "); SqlParameter[] parameters = { new SqlParameter("@CityID", SqlDbType.NVarChar,50) }; parameters[0].Value = CityID; Maticsoft.Model.City model=new Maticsoft.Model.City(); DataSet ds=ServerDbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }