要写一个common method来解析上节编写的TTServer Export导出的xml,但是查询条件会发生变化,经过研究,使用三木运算符可以解决这种问题,废话不多说,上代码:
private int QueryDefectNum(string type, string creater, string status, DateTime start, DateTime end)
{
var query = from defect in element.Descendants("Defect")
where
(!string.IsNullOrEmpty(type) ? defect.Element("type").Value.contains(type) : true) &&
(!string.IsNullOrEmpty(creater) ? defect.Element("creater").contains(creater) : true) &&
(!string.IsNullOrEmpty(status) ? defect.Element("status").contains(status) : true) &&
Convert.ToDateTime(defect.Element("date-created").Value) >= start &&
Convert.ToDateTime(defect.Element("date-created").Value) <= end
select defect;
return query.count;
}