/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.DishesTable GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 DishesID,DishesName,DishesMoney,DishesUnit,DishesTypeID,BusinessID,IsCurrentPrice,DishesBrief,ImageUrl,CookingStyleID,Popularity,Special,IsTakeAway,State,PraiseCount,ShareCount,ComCount,SortID,CreateDate,ChainStoreDishesID,ChainStoreID,ChainStoreDishesTypeID,IsSetMeal,VisibityType,DishCode,DisheCate,IsEvaluate,SpicyNum,RecNum from DishesTable "); strSql.Append(" where "); SqlParameter[] parameters = { }; Maticsoft.Model.DishesTable model=new Maticsoft.Model.DishesTable(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.DishesTable DataRowToModel(DataRow row) { Maticsoft.Model.DishesTable model=new Maticsoft.Model.DishesTable(); if (row != null) { if(row["DishesID"]!=null) { model.DishesID=row["DishesID"].ToString(); } if(row["DishesName"]!=null) { model.DishesName=row["DishesName"].ToString(); } if(row["DishesMoney"]!=null && row["DishesMoney"].ToString()!="") { model.DishesMoney=decimal.Parse(row["DishesMoney"].ToString()); } if(row["DishesUnit"]!=null) { model.DishesUnit=row["DishesUnit"].ToString(); } if(row["DishesTypeID"]!=null) { model.DishesTypeID=row["DishesTypeID"].ToString(); } if(row["BusinessID"]!=null) { model.BusinessID=row["BusinessID"].ToString(); } if(row["IsCurrentPrice"]!=null && row["IsCurrentPrice"].ToString()!="") { if((row["IsCurrentPrice"].ToString()=="1")||(row["IsCurrentPrice"].ToString().ToLower()=="true")) { model.IsCurrentPrice=true; } else { model.IsCurrentPrice=false; } } if(row["DishesBrief"]!=null) { model.DishesBrief=row["DishesBrief"].ToString(); } if(row["ImageUrl"]!=null) { model.ImageUrl=row["ImageUrl"].ToString(); } if(row["CookingStyleID"]!=null) { model.CookingStyleID=row["CookingStyleID"].ToString(); } if(row["Popularity"]!=null && row["Popularity"].ToString()!="") { model.Popularity=int.Parse(row["Popularity"].ToString()); } if(row["Special"]!=null && row["Special"].ToString()!="") { if((row["Special"].ToString()=="1")||(row["Special"].ToString().ToLower()=="true")) { model.Special=true; } else { model.Special=false; } } if(row["IsTakeAway"]!=null && row["IsTakeAway"].ToString()!="") { if((row["IsTakeAway"].ToString()=="1")||(row["IsTakeAway"].ToString().ToLower()=="true")) { model.IsTakeAway=true; } else { model.IsTakeAway=false; } } if(row["State"]!=null && row["State"].ToString()!="") { model.State=int.Parse(row["State"].ToString()); } if(row["PraiseCount"]!=null && row["PraiseCount"].ToString()!="") { model.PraiseCount=int.Parse(row["PraiseCount"].ToString()); } if(row["ShareCount"]!=null && row["ShareCount"].ToString()!="") { model.ShareCount=int.Parse(row["ShareCount"].ToString()); } if(row["ComCount"]!=null && row["ComCount"].ToString()!="") { model.ComCount=int.Parse(row["ComCount"].ToString()); } if(row["SortID"]!=null && row["SortID"].ToString()!="") { model.SortID=int.Parse(row["SortID"].ToString()); } if(row["CreateDate"]!=null && row["CreateDate"].ToString()!="") { model.CreateDate=DateTime.Parse(row["CreateDate"].ToString()); } if(row["ChainStoreDishesID"]!=null) { model.ChainStoreDishesID=row["ChainStoreDishesID"].ToString(); } if(row["ChainStoreID"]!=null) { model.ChainStoreID=row["ChainStoreID"].ToString(); } if(row["ChainStoreDishesTypeID"]!=null) { model.ChainStoreDishesTypeID=row["ChainStoreDishesTypeID"].ToString(); } if(row["IsSetMeal"]!=null && row["IsSetMeal"].ToString()!="") { if((row["IsSetMeal"].ToString()=="1")||(row["IsSetMeal"].ToString().ToLower()=="true")) { model.IsSetMeal=true; } else { model.IsSetMeal=false; } } if(row["VisibityType"]!=null && row["VisibityType"].ToString()!="") { model.VisibityType=int.Parse(row["VisibityType"].ToString()); } if(row["DishCode"]!=null) { model.DishCode=row["DishCode"].ToString(); } if(row["DisheCate"]!=null && row["DisheCate"].ToString()!="") { model.DisheCate=int.Parse(row["DisheCate"].ToString()); } if(row["IsEvaluate"]!=null && row["IsEvaluate"].ToString()!="") { if((row["IsEvaluate"].ToString()=="1")||(row["IsEvaluate"].ToString().ToLower()=="true")) { model.IsEvaluate=true; } else { model.IsEvaluate=false; } } if(row["SpicyNum"]!=null && row["SpicyNum"].ToString()!="") { model.SpicyNum=int.Parse(row["SpicyNum"].ToString()); } if(row["RecNum"]!=null && row["RecNum"].ToString()!="") { model.RecNum=int.Parse(row["RecNum"].ToString()); } } return model; }