首页 新闻 搜索 专区 学院

请问我该怎么一次性查出准确的数据

0
[待解决问题]

/// <summary>
/// 房源返回类
/// </summary>
[DataContract]
public class RoomRet : AppInfoDataRet
{
[DataMember]
public int errcode { get; set; }
[DataMember]
public string errmsg { get; set; }
[DataMember]
public List<Roominfo> lss { get; set; }
}

/// <summary>
/// 房屋详细信息
/// </summary>
[DataContract]
public class Roominfo
{
[DataMember]
public string RoomID { get; set; }
[DataMember]
public string RoomName { get; set; }
[DataMember]
public string UserID { get; set; }
[DataMember]
public string RoomAddr { get; set; }
[DataMember]
public string StructCode { get; set; }
[DataMember]
public string RoomCode { get; set; }
[DataMember]
public int FloolNum { get; set; }
[DataMember]
public int TopNum { get; set; }
[DataMember]
public string RoomTypeCode { get; set; }
[DataMember]
public float SumArea { get; set; }
[DataMember]
public string Remart { get; set; }
[DataMember]
public List<RoomDevice> device { get; set; }
[DataMember]
public List<RoomRent> rentInfo { get; set; }
}

///房屋下的设备
[DataContract]
public class RoomDevice
{
[DataMember]
public string DeviceID { get; set; }
[DataMember]
public string DeviceName { get; set; }
}

///房屋的各种生活费用

[DataContract]
public class RoomRent
{
[DataMember]
public double WaterRent { get; set; }
[DataMember]
public double PowerRent { get; set; }
[DataMember]
public double GasRent { get; set; }
[DataMember]
public double PropetyRent { get; set; }
[DataMember]
public double OtherRent { get; set; }

}

 

这里是主代码

public static List<Roominfo> GetAllRoomInfo(ref bool flag, ref string errmsg,string RoomId, string userID,string Address)
{
try
{
string tableName = "tb_RoomInfo";
string where = "where c_RoomAddr like '%"+Address+"%';
var dt = DBHelper.SqlHelper.GetDataTable(tableName, where);

List<Roominfo> Roomlist = new List<Roominfo>();
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
int i = 0;
Roominfo datainfo = new Roominfo();
datainfo.FloolNum = Convert.ToInt32(dr["i_FloolNum"]);
datainfo.Remart = dr["c_Remart"].ToString();
datainfo.RoomAddr = dr["c_RoomAddr"].ToString();
datainfo.RoomCode = dr["c_RoomCode"].ToString();
datainfo.RoomID = dr["c_RoomID"].ToString();
datainfo.RoomName = dr["c_RoomName"].ToString();
datainfo.RoomTypeCode = dr["c_RoomTypeCode"].ToString();
datainfo.StructCode = dr["c_StructCode"].ToString();
datainfo.SumArea = Convert.ToInt32(dr["i_SumArea"]);
datainfo.TopNum = Convert.ToInt32(dr["i_TopNum"]);
datainfo.UserID = dr["c_AccountID"].ToString();

List<RoomDevice> dev = new List<RoomDevice>();
string tablename1 = "tb_RoomDevice";
string where1 = "where c_RoomID=" + OPHelper.Operation.AddQuot(RoomId);
var dt1 = DBHelper.SqlHelper.GetDataTable(tablename1, where1);
if (dt1.Rows.Count > 0)
{
foreach (DataRow dr1 in dt1.Rows)
{
RoomDevice newdev = new RoomDevice();
newdev.DeviceID = dr1["c_DeviceID"].ToString();
newdev.DeviceName = dr1["c_DeviceName"].ToString();
dev.Add(newdev);
}
}
datainfo.device = dev;

List<RoomRent> roomrent = new List<RoomRent>();
string tablename2 = "tb_RoomRentInfo";
string where2 = "where c_RoomID=" + OPHelper.Operation.AddQuot(RoomId);
var dt2 = DBHelper.SqlHelper.GetDataTable(tablename2, where2);
if (dt2.Rows.Count >0)
{
foreach (DataRow dr2 in dt2.Rows)
{
RoomRent newrent = new RoomRent();
newrent.WaterRent =Convert.ToDouble( dr2["i_WaterRent"]);
newrent.PowerRent = Convert.ToDouble(dr2["i_PowerRent"]);
newrent.GasRent = Convert.ToDouble(dr2["i_GasRent"]);
newrent.PropetyRent = Convert.ToDouble(dr2["i_PropertyRent"]);
newrent.OtherRent = Convert.ToDouble(dr2["i_Other"]);
roomrent.Add(newrent);
}
}
datainfo.rentInfo = roomrent;

Roomlist.Add(datainfo);
i++;
}
flag = true;
errmsg = CacheData.GetAppErrorDscription(0);
return Roomlist;
}
else
{
flag = false;
errmsg = CacheData.GetAppErrorDscription(1);
}
}
catch (Exception ex)
{
ClsFun.writeLog("", "loginError:" + ex.Message + " UserId:" + userID, "error");
}
return new List<Roominfo>();
}

现在问题是,Roomlist每次循环都包含着List<RoomDevice>,

List<RoomRent> roomrent 同样的数据,

可是现实中是,Roomlist其中几条数据是不应该有

List<RoomDevice>,

List<RoomRent> roomrent这两条数据,其余的应该有,

那么返回集合的时候,怎么把该有和不该有的数据(也就是Roomlist)同时返回,问的可能没有很明白,请原谅,本人小白

起早抹黑的程序猿的主页 起早抹黑的程序猿 | 初学一级 | 园豆:126
提问于:2018-01-29 18:00

建议给代码加上高亮

dudu 2年前
< >
分享
所有回答(1)
0

说实话没太明白你的问题,大概看了下代码,有个A的集合,A中有属性B和C的集合,最后分门别类的取出数据返回

Daniel Cai | 园豆:10374 (专家六级) | 2018-01-30 10:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册