コード例 #1
0
        //Pesquisar dadores pelo tipo sanguíneo.
        public List <Donor> searchByBloodType(string sh_blood)
        {
            XmlDocument  doc = new XmlDocument();
            List <Donor> list_dadoresFounded = new List <Donor>();

            doc.Load(FILEPATH);
            XmlNode root = doc.DocumentElement;

            if (root.HasChildNodes)
            {
                string      xpth_way = "//Dador/BloodType";
                XmlNodeList nodeList = root.SelectNodes(xpth_way);

                for (int i = 0; i < nodeList.Count; i++)
                {
                    if (nodeList[i].InnerText.Equals(sh_blood))
                    {
                        XmlNode dadorNode = root.ChildNodes[i];
                        int     cm        = Convert.ToInt32(dadorNode.ChildNodes[20].InnerText);
                        double  kg        = double.Parse(dadorNode.ChildNodes[19].InnerText, CultureInfo.InvariantCulture);
                        int     age       = Int32.Parse(dadorNode.ChildNodes[14].InnerText);
                        int     num_dador = int.Parse(dadorNode.ChildNodes[0].InnerText);
                        int     phone_number;
                        double  imc = CalculateIMC(kg, cm);
                        int.TryParse(dadorNode.ChildNodes[11].InnerText, out phone_number);
                        DateTime.TryParseExact(dadorNode.ChildNodes[13].InnerText, "M/d/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime birthDate);
                        double latitude;
                        double.TryParse(dadorNode.ChildNodes[22].InnerText, out latitude);
                        double longitude;
                        double.TryParse(dadorNode.ChildNodes[23].InnerText, out longitude);
                        Donor newDador = new Donor(num_dador, dadorNode.ChildNodes[1].InnerText, dadorNode.ChildNodes[2].InnerText,
                                                   dadorNode.ChildNodes[3].InnerText, dadorNode.ChildNodes[4].InnerText,
                                                   dadorNode.ChildNodes[5].InnerText, dadorNode.ChildNodes[6].InnerText,
                                                   dadorNode.ChildNodes[7].InnerText, dadorNode.ChildNodes[8].InnerText,
                                                   dadorNode.ChildNodes[9].InnerText, dadorNode.ChildNodes[10].InnerText,
                                                   phone_number, dadorNode.ChildNodes[12].InnerText, birthDate, age, dadorNode.ChildNodes[15].InnerText,
                                                   dadorNode.ChildNodes[16].InnerText, dadorNode.ChildNodes[17].InnerText, dadorNode.ChildNodes[18].InnerText,
                                                   kg, cm, dadorNode.ChildNodes[21].InnerText, latitude, longitude, imc);
                        list_dadoresFounded.Add(newDador);
                    }
                }
            }
            else
            {
                return(null);
            }
            return(list_dadoresFounded);
        }
コード例 #2
0
        //Listar todos os dadores
        public List <Donor> GetDonors()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(FILEPATH);
            List <Donor> list_dadores = new List <Donor>();

            XmlNodeList donorNodes = doc.SelectNodes("/ListaDador/Dador");

            for (int i = 0; i < donorNodes.Count; i++)
            {
                //XmlNode dadorNode = donorNodes[i].ChildNodes;
                int    cm        = Convert.ToInt32(donorNodes[i].ChildNodes[20].InnerText);
                double kg        = double.Parse(donorNodes[i].ChildNodes[19].InnerText, CultureInfo.InvariantCulture);
                int    num_dador = int.Parse(donorNodes[i].ChildNodes[0].InnerText);
                int    phone_number;
                double imc = CalculateIMC(kg, cm);
                int.TryParse(donorNodes[i].ChildNodes[11].InnerText, out phone_number);
                DateTime.TryParseExact(donorNodes[i].ChildNodes[13].InnerText, "M/d/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime birthDate);
                int    age = CalculateAge(birthDate);
                double latitude;
                double.TryParse(donorNodes[i].ChildNodes[22].InnerText, out latitude);
                double longitude;
                double.TryParse(donorNodes[i].ChildNodes[23].InnerText, out longitude);

                Donor newDador = new Donor(num_dador, donorNodes[i].ChildNodes[1].InnerText,
                                           donorNodes[i].ChildNodes[2].InnerText, donorNodes[i].ChildNodes[3].InnerText, donorNodes[i].ChildNodes[4].InnerText,
                                           donorNodes[i].ChildNodes[5].InnerText, donorNodes[i].ChildNodes[6].InnerText, donorNodes[i].ChildNodes[7].InnerText,
                                           donorNodes[i].ChildNodes[8].InnerText, donorNodes[i].ChildNodes[9].InnerText, donorNodes[i].ChildNodes[10].InnerText, phone_number,
                                           donorNodes[i].ChildNodes[12].InnerText, birthDate, age, donorNodes[i].ChildNodes[15].InnerText, donorNodes[i].ChildNodes[16].InnerText,
                                           donorNodes[i].ChildNodes[17].InnerText, donorNodes[i].ChildNodes[18].InnerText, kg, cm,
                                           donorNodes[i].ChildNodes[21].InnerText, latitude, longitude, imc);
                list_dadores.Add(newDador);
            }
            return(list_dadores);
        }
コード例 #3
0
        //Método para adicionar um novo dador.
        public bool addDador(Donor newDonor)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(FILEPATH);
            XmlElement root = doc.DocumentElement;

            XmlElement dador  = doc.CreateElement("Dador");
            XmlElement number = doc.CreateElement("Number");

            number.InnerText = newDonor.Number.ToString();
            XmlElement gender = doc.CreateElement("Gender");

            gender.InnerText = newDonor.Gender;
            XmlElement givenName = doc.CreateElement("GivenName");

            givenName.InnerText = newDonor.GivenName;
            XmlElement surname = doc.CreateElement("Surname");

            surname.InnerText = newDonor.Surname;
            XmlElement streetAddress = doc.CreateElement("StreetAddress");

            streetAddress.InnerText = newDonor.StreetAddress;
            XmlElement city = doc.CreateElement("City");

            city.InnerText = newDonor.City;
            XmlElement stateFull = doc.CreateElement("StateFull");

            stateFull.InnerText = newDonor.StateFull;
            XmlElement zipCode = doc.CreateElement("ZipCode");

            zipCode.InnerText = newDonor.ZipCode;
            XmlElement emailAddress = doc.CreateElement("EmailAddress");

            emailAddress.InnerText = newDonor.EmailAddress;
            XmlElement username = doc.CreateElement("Username");

            username.InnerText = newDonor.Username;
            XmlElement password = doc.CreateElement("Password");

            password.InnerText = newDonor.Password;
            XmlElement telephoneNumber = doc.CreateElement("TelephoneNumber");

            telephoneNumber.InnerText = newDonor.TelephoneNumber.ToString();
            XmlElement mothersMaiden = doc.CreateElement("MothersMaiden");

            mothersMaiden.InnerText = newDonor.MothersMaiden;
            XmlElement birthday = doc.CreateElement("Birthday");

            birthday.InnerText = newDonor.Birthday.ToString("M/d/yyyy", CultureInfo.InvariantCulture);

            XmlElement age = doc.CreateElement("Age");

            //age.InnerText = Model.calcularIdade(newDonor.Birthday).ToString();

            XmlElement occupation = doc.CreateElement("Occupation");

            occupation.InnerText = newDonor.Occupation;
            XmlElement company = doc.CreateElement("Company");

            company.InnerText = newDonor.Company;
            XmlElement vehicle = doc.CreateElement("Vehicle");

            vehicle.InnerText = newDonor.Vehicle;
            XmlElement bloodType = doc.CreateElement("BloodType");

            bloodType.InnerText = newDonor.BloodType;
            XmlElement kilograms = doc.CreateElement("Kilograms");

            kilograms.InnerText = newDonor.Kilograms.ToString();
            XmlElement centimeters = doc.CreateElement("Centimeters");

            centimeters.InnerText = newDonor.Centimeters.ToString();
            XmlElement guid = doc.CreateElement("GUID");

            guid.InnerText = newDonor.Guid;
            XmlElement latitude = doc.CreateElement("Latitude");

            latitude.InnerText = newDonor.Latitude.ToString();
            XmlElement longitude = doc.CreateElement("Longitude");

            longitude.InnerText = newDonor.Longitude.ToString();

            dador.AppendChild(number);
            dador.AppendChild(gender);
            dador.AppendChild(givenName);
            dador.AppendChild(surname);
            dador.AppendChild(streetAddress);
            dador.AppendChild(city);
            dador.AppendChild(stateFull);
            dador.AppendChild(zipCode);
            dador.AppendChild(emailAddress);
            dador.AppendChild(username);
            dador.AppendChild(password);
            dador.AppendChild(telephoneNumber);
            dador.AppendChild(mothersMaiden);
            dador.AppendChild(birthday);
            dador.AppendChild(age);
            dador.AppendChild(occupation);
            dador.AppendChild(company);
            dador.AppendChild(vehicle);
            dador.AppendChild(bloodType);
            dador.AppendChild(kilograms);
            dador.AppendChild(centimeters);
            dador.AppendChild(guid);
            dador.AppendChild(latitude);
            dador.AppendChild(longitude);
            root.AppendChild(dador);

            doc.Save(FILEPATH);

            return(true);
        }