Exemplo n.º 1
0
        public static bool AddCharity(Charity charity)
        {
            int ID = addCharity(charity.RegNumber, charity.UserRoleID, charity.UserFullName, charity.UserCity, charity.UserProvince, charity.UserPostalCode, charity.UserAddress1, charity.UserAddress2, charity.UserPhone, charity.UserWebsite, charity.UserEmail);

            if (ID == -1)
                return false;

            if (!addCharityProfile(ID, charity.RegNumber, charity.CharityCategoryID, charity.CharityDesignationID))
                return false;

            foreach (string Program in charity.CharityPrograms)
            {
                bool valid = addCharityProgram(ID, Program);
            }

            foreach (string Country in charity.CharityCountries)
            {
                bool valid = addCharityActivityCountry(ID, Country);
            }

            return true;
        }
Exemplo n.º 2
0
        private bool loadCharitiesIdentificationFile(string FileName)
        {
            charities = new List<Charity>();
            charitiesDistinctRegNumbers = new List<string>();
            charitiesErros = 0;

            try
            {
                FileStream file = new FileStream(FileName, FileMode.Open);
                StreamReader reader = new StreamReader(file);

                if (!reader.EndOfStream)
                    reader.ReadLine();

                int counter = 0;
                while (!reader.EndOfStream)
                {
                    counter++;
                    string line = reader.ReadLine();
                    string[] values = line.Split(',');

                    if (values.Length == 0)
                        continue;

                    for (int i = 0; i < values.Length; i++)
                        values[i] = values[i].Replace("***", ",").Trim();

                    string RegNum = values[0];
                    int CategoryID = int.Parse(values[1]);
                    string DesignationID = values[2];
                    string FullName = values[4];
                    string Address1 = values[5];
                    string Address2 = values[6];
                    string City = values[7];
                    string Province = values[8];
                    string PostalCode = values[9];
                    string Country = values[10].Trim();
                    string Phone = values[12];
                    string Email = values[13];
                    string Website = values[14];

                    if (Country.ToLower() != "ca")
                    {
                        charitiesErros++;
                        continue;
                    }

                    if (!charitiesDistinctRegNumbers.Contains(RegNum))
                        charitiesDistinctRegNumbers.Add(RegNum);

                    if (!charityTypesConvertedTable.ContainsKey(CategoryID))
                    {
                        charitiesErros++;
                        continue;
                    }
                    if (!designationConvertedTable.ContainsKey(DesignationID))
                    {
                        charitiesErros++;
                        continue;
                    }

                    Charity charity = new Charity(RegNum, FullName, City, Province, PostalCode, Address1, Address2, Phone, Website, Email, charityTypesConvertedTable[CategoryID], designationConvertedTable[DesignationID]);
                    charities.Add(charity);
                }

                file.Close();
                reader.Close();

                return true;
            }
            catch
            {
                MessageBox.Show("Charities Error");
                return false;
            }
        }