private void btnSearchKnowledge_Click(object sender, EventArgs e)
{
char[] delimiters = new char[] { ',', ' ' };
if(txtBoxKnowledgeQuestion.Text == string.Empty)
{
return;
}
string[] keywords = txtBoxKnowledgeQuestion.Text.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
XmlDocument doc = new XmlDocument();
doc.Load("XMLQandA.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/messages/messageItem");
foreach (XmlNode node in nodeList)
{
bool hasAllWords = true;
bool hasAnyWord = false;
foreach (string keyword in keywords)
{
if (node.InnerText.Contains(keyword))
{
hasAnyWord = true;
}
else
{
hasAllWords = false;
}
}
if (hasAllWords || hasAnyWord)
{
lstBoxQA.Items.Add(node.InnerText);
lstBoxQA.Items.Add("======================");
}
}
bool badWordFound = false;
foreach (string kw in keywords)
{
if(newBadwordFilter.IsCleanString(kw) == false)
{
badWordFound = true;
txtBoxKnowledgeQuestion.Text = txtBoxKnowledgeQuestion.Text.Replace(kw, new string( '#', kw.Length ));
}
}
if(badWordFound)
{
MessageBox.Show("You have typed a word that has been deemed \n inapropriate - it will be blanked out - Next time an email \n will be sent to HR and IT to have your access cut off");
}
}
|