我正在尝试使情况像这样:用户可以填写“just txtComStartDate”或“just txtComEndDate”或“txtComStartDate & txtComEndDate”。
如果用户填写txtComStartDate
为 18/08/12,则仅显示 18/08/12 以后的数据。
如果用户填写txtComEndDate
为 19/08/12,则仅显示 19/08/12 之前的数据。
如果用户同时限制txtComStartDate
18/08/12 和txtComEndDate
19/08/12,则会显示这两个日期之间的数据。
该if
声明给了我错误并且无法正常工作。我对&&
and感到困惑||
。有人可以帮忙吗?您的帮助将不胜感激。谢谢你。
我的代码:
private void searchComByDate()
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(sourceDir);
foreach (string fileName in fileEntries)
{
XmlDocument xmlDoc = new XmlDocument(); //* create an xml document object.
string docPath = fileName;
xmlDoc.Load(docPath); //* load the XML document from the specified file.
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("item");
foreach (XmlNode node in nodeList)
{
XmlElement itemElement = (XmlElement)node;
string itemDate = itemElement.GetElementsByTagName("pubDate")[0].InnerText;
CultureInfo provider = CultureInfo.InvariantCulture;
if (txtComStartDate.Text != (String.Empty) && DateTime.Parse(itemDate) >= DateTime.ParseExact(txtComStartDate.Text, "dd/MM/yy", provider)
|| txtComEndDate.Text != (String.Empty) && DateTime.Parse(itemDate) <= DateTime.ParseExact(txtComEndDate.Text, "dd/MM/yy", provider)
|| (txtComStartDate.Text != (String.Empty) && DateTime.Parse(itemDate) >= DateTime.ParseExact(txtComStartDate.Text, "dd/MM/yy", provider) && txtComEndDate.Text != (String.Empty) && DateTime.Parse(itemDate) <= DateTime.ParseExact(txtComEndDate.Text, "dd/MM/yy", provider)))
{
string itemAuthor = itemElement.GetElementsByTagName("author")[0].InnerText;
string itemTitle = itemElement.GetElementsByTagName("title")[0].InnerText;
string itemDescription = itemElement.GetElementsByTagName("description")[0].InnerText;
string itemXMLFile = Path.GetFileNameWithoutExtension(fileName);
richComByTemplate.AppendText("SYMBOL: " + itemXMLFile + "\nAUTHOR: " + itemAuthor + "\nDATE: " + itemDate +
"\nTITLE: " + itemTitle + "\nDESCRIPTION: " + itemDescription + "\n\n--------\n\n");
}
}
}
}