public Entity.ResultObj GetCarTakRenl(string Imei, string start, string end, int page,int uid)
{
DataSet ds;
int RecordCount = 0;
int PageCount = 0;
int PageSize = 6;
string sqlwhere;
start = start.Replace("/", "-");
end = end.Replace("/", "-");
Model.Person.pmEquipmentMap m = eqBLL.GetModelList("Imei='" + Imei + "' and uid=" + uid + " and ParentUid=0").FirstOrDefault();
if (m != null)
{
sqlwhere = "l.Imei='" + Imei + "' and l.CarState=2";
if (start != "" || end != "")
sqlwhere += "and CONVERT(varchar(100), l.DateStart, 23)>='" + start + "' and CONVERT(varchar(100), l.DateEnd, 23)<='" + end + "' and TrackState=1";
}
else
{
sqlwhere = "l.Imei='" + Imei + "'and l.uid=" + uid;
if (start != "" || end != "")
sqlwhere += "and CONVERT(varchar(100), l.DateStart, 23)>='" + start + "' and CONVERT(varchar(100), l.DateEnd, 23)<='" + end + "' and TrackState=1";
}
cBLL.GetCarTktaList(page, PageSize, sqlwhere, out ds, out RecordCount, out PageCount);
Entity.carTrackLog ctk;
Dictionary<string, List<object>> lists = new Dictionary<string, List<object>>();
List<object> datas = new List<object>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
List<object> list = new List<object>();
string key = Convert.ToDateTime(dr["DateStart"]).ToString("yyyy-MM-dd");//关键的kay
Datas dts = datas.Find(o => ((Datas)o).time == key) as Datas;
if (dts == null)
{
dts = new Datas();
dts.time = key;
datas.Add(dts);
}
ctk = new Entity.carTrackLog();
ctk.Id = Convert.ToInt32(dr["id"].ToString());
ctk.Imei = dr["Imei"].ToString();
if (!string.IsNullOrEmpty(dr["DateStart"]+""))
ctk.DateStart = Convert.ToDateTime(dr["DateStart"]).ToString("yyyy-MM-dd HH:mm:ss");
if (!string.IsNullOrEmpty(dr["DateEnd"]+""))
ctk.DateEnd = Convert.ToDateTime(dr["DateEnd"]).ToString("yyyy-MM-dd HH:mm:ss");
decimal Mileage;
if (decimal.TryParse(dr["Mileage"] + "", out Mileage))
ctk.Mileage = Mileage;
else
ctk.Mileage = 0;
if (!string.IsNullOrEmpty(dr["Time"]+""))
ctk.Time = Convert.ToInt32(dr["Time"]);
int Speed;
if (int.TryParse(dr["Speed"] + "", out Speed))
ctk.Speed = Speed;
else
ctk.Speed = 0;
ctk.NickName = dr["NickName"].ToString();
if (!string.IsNullOrEmpty(dr["DateCreated"]+""))
ctk.DateCreated = Convert.ToDateTime(dr["DateCreated"]).ToString("yyyy-MM-dd HH:mm:ss");
dts.lists.Add(ctk);
}
Entity.PageInfo p = new Entity.PageInfo();
p.content = datas;
p.totalPages = PageCount;
p.totalElements = RecordCount;
return new Entity.ResultObj(true, p);
}
public class Datas
{
public string time;
public List<object> lists = new List<object>();
}