/// <summary> /// 获得数据列表 /// </summary> public List<DataEntity.Model.ModelList> DataTableToList(DataTable dt) { List<DataEntity.Model.ModelList> modelList = new List<DataEntity.Model.ModelList>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DataEntity.Model.ModelList model; for (int n = 0; n < rowsCount; n++) { model = new DataEntity.Model.ModelList(); if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "") { model.ID = int.Parse(dt.Rows[n]["ID"].ToString()); } if (dt.Rows[n]["ModelName"] != null && dt.Rows[n]["ModelName"].ToString() != "") { model.ModelName = dt.Rows[n]["ModelName"].ToString(); } if (dt.Rows[n]["Unit"] != null && dt.Rows[n]["Unit"].ToString() != "") { model.Unit = dt.Rows[n]["Unit"].ToString(); } if (dt.Rows[n]["ModelPrice"] != null && dt.Rows[n]["ModelPrice"].ToString() != "") { model.ModelPrice = decimal.Parse(dt.Rows[n]["ModelPrice"].ToString()); } if (dt.Rows[n]["StationPrice"] != null && dt.Rows[n]["StationPrice"].ToString() != "") { model.StationPrice = decimal.Parse(dt.Rows[n]["StationPrice"].ToString()); } if (dt.Rows[n]["ModelProfit"] != null && dt.Rows[n]["ModelProfit"].ToString() != "") { model.ModelProfit = decimal.Parse(dt.Rows[n]["ModelProfit"].ToString()); } if (dt.Rows[n]["StationProfit"] != null && dt.Rows[n]["StationProfit"].ToString() != "") { model.StationProfit = decimal.Parse(dt.Rows[n]["StationProfit"].ToString()); } if (dt.Rows[n]["Remark"] != null && dt.Rows[n]["Remark"].ToString() != "") { model.Remark = dt.Rows[n]["Remark"].ToString(); } if (dt.Rows[n]["EG1"] != null && dt.Rows[n]["EG1"].ToString() != "") { model.EG1 = dt.Rows[n]["EG1"].ToString(); } if (dt.Rows[n]["EG2"] != null && dt.Rows[n]["EG2"].ToString() != "") { model.EG2 = dt.Rows[n]["EG2"].ToString(); } if (dt.Rows[n]["EG3"] != null && dt.Rows[n]["EG3"].ToString() != "") { model.EG3 = decimal.Parse(dt.Rows[n]["EG3"].ToString()); } if (dt.Rows[n]["EG4"] != null && dt.Rows[n]["EG4"].ToString() != "") { model.EG4 = decimal.Parse(dt.Rows[n]["EG4"].ToString()); } if (dt.Rows[n]["EG5"] != null && dt.Rows[n]["EG5"].ToString() != "") { model.EG5 = int.Parse(dt.Rows[n]["EG5"].ToString()); } modelList.Add(model); } } return modelList; }
/// <summary> /// 得到一个对象实体 /// </summary> public DataEntity.Model.ModelList GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" ID,ModelName,Unit,ModelPrice,StationPrice,ModelProfit,StationProfit,Remark,EG1,EG2,EG3,EG4,EG5 "); strSql.Append(" from ModelList "); strSql.Append(" where ID=" + ID + ""); DataEntity.Model.ModelList model = new DataEntity.Model.ModelList(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["ModelName"] != null && ds.Tables[0].Rows[0]["ModelName"].ToString() != "") { model.ModelName = ds.Tables[0].Rows[0]["ModelName"].ToString(); } if (ds.Tables[0].Rows[0]["Unit"] != null && ds.Tables[0].Rows[0]["Unit"].ToString() != "") { model.Unit = ds.Tables[0].Rows[0]["Unit"].ToString(); } if (ds.Tables[0].Rows[0]["ModelPrice"] != null && ds.Tables[0].Rows[0]["ModelPrice"].ToString() != "") { model.ModelPrice = decimal.Parse(ds.Tables[0].Rows[0]["ModelPrice"].ToString()); } if (ds.Tables[0].Rows[0]["StationPrice"] != null && ds.Tables[0].Rows[0]["StationPrice"].ToString() != "") { model.StationPrice = decimal.Parse(ds.Tables[0].Rows[0]["StationPrice"].ToString()); } if (ds.Tables[0].Rows[0]["ModelProfit"] != null && ds.Tables[0].Rows[0]["ModelProfit"].ToString() != "") { model.ModelProfit = decimal.Parse(ds.Tables[0].Rows[0]["ModelProfit"].ToString()); } if (ds.Tables[0].Rows[0]["StationProfit"] != null && ds.Tables[0].Rows[0]["StationProfit"].ToString() != "") { model.StationProfit = decimal.Parse(ds.Tables[0].Rows[0]["StationProfit"].ToString()); } if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "") { model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); } if (ds.Tables[0].Rows[0]["EG1"] != null && ds.Tables[0].Rows[0]["EG1"].ToString() != "") { model.EG1 = ds.Tables[0].Rows[0]["EG1"].ToString(); } if (ds.Tables[0].Rows[0]["EG2"] != null && ds.Tables[0].Rows[0]["EG2"].ToString() != "") { model.EG2 = ds.Tables[0].Rows[0]["EG2"].ToString(); } if (ds.Tables[0].Rows[0]["EG3"] != null && ds.Tables[0].Rows[0]["EG3"].ToString() != "") { model.EG3 = decimal.Parse(ds.Tables[0].Rows[0]["EG3"].ToString()); } if (ds.Tables[0].Rows[0]["EG4"] != null && ds.Tables[0].Rows[0]["EG4"].ToString() != "") { model.EG4 = decimal.Parse(ds.Tables[0].Rows[0]["EG4"].ToString()); } if (ds.Tables[0].Rows[0]["EG5"] != null && ds.Tables[0].Rows[0]["EG5"].ToString() != "") { model.EG5 = int.Parse(ds.Tables[0].Rows[0]["EG5"].ToString()); } return model; } else { return null; } }