I'm doing a basic exercise in C# that uses a XML file as a database. The program must allow the user to search, edit, delete, and add a person's registration.
The search method is working, but now I want to implement functionality to find the person regardless of whether uppercase/lowercase letters are used. For example, as I have it now, if I search "MATHEUS" and the database (XML file) has "matheus", my program does not seem to find that person.
public static List<Entidades.Pessoa> Listar(string nome, string cpfcnpj)
{
//Variável de retorno
List<Entidades.Pessoa> pessoas = new List<Entidades.Pessoa>();
//Carrega o arquivo xml
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("Database.xml");
//Representa uma coleção ordenada de nós.
XmlNodeList xmlNodeListPessoa = null;
if ((cpfcnpj != null) && (cpfcnpj != ""))
{
//Cria uma lista somente com a identificação informada pelo cpfcnpj
xmlNodeListPessoa = xmlDocument.SelectNodes(string.Format("Lista/Pessoa[CpfCnpj='{0}']", cpfcnpj));
}
else if ((nome != null) && (nome != ""))
{
//Cria uma lista somente com a identificação informada pelo nome
xmlNodeListPessoa = xmlDocument.SelectNodes(string.Format("Lista/Pessoa[contains(Nome,'{0}')]", nome));
//xmlNodeListPessoa = xmlDocument.SelectNodes(string.Format("Lista/Pessoa[starts-with(Nome,'{0}')]", nome));
}
else
{
//Senao criar uma lista normal
xmlNodeListPessoa = xmlDocument.SelectNodes(string.Format("Lista/Pessoa"));
}
//Carrega
foreach (XmlElement xmlElementPessoa in xmlNodeListPessoa)
{
//incializar a instancia do objeto pessoa
Entidades.Pessoa objPessoa = Entidade(xmlElementPessoa);
// adicionar objeto ba lista
pessoas.Add(objPessoa);
}
//Retorna
return pessoas;
}