Esempio n. 1
0
        public static void ParseRegions(bool useInternational = false)
        {
            XDocument document = XDocument.Parse(DownloadXML(Database.Regions, useInternational));
            XElement  parent   = document.Element("Regions");

            if (RegionList != new List <Region>())
            {
                RegionList = new List <Region>();
            }

            Region blankRegion = new Region();

            RegionList.Add(blankRegion);

            foreach (XElement element in parent.Elements("Region"))
            {
                Region region = new Region();

                try
                {
                    region.Name         = element.Element("Name").Value;
                    region.Abbreviation = element.Element("Abbreviation").Value;
                    region.Area         = element.Element("Area").Value;
                    region.Picture      = element.Element("Picture").Value;
                }
                catch
                {
                    Common.Log("Could not read region " + region.Name + " from xml");
                }

                RegionList.Add(region);
            }

            UpdateComboBoxes.Invoke();
        }
Esempio n. 2
0
        public static void ParseReps(bool useInternational = false)
        {
            XDocument document = XDocument.Parse(DownloadXML(Database.Reps, useInternational));
            XElement  parent   = document.Element("SalesReps");

            if (SalesRepList != new List <SalesRep>())
            {
                SalesRepList = new List <SalesRep>();
            }

            SalesRep blankRep = new SalesRep();

            blankRep.Name             = new Name();
            blankRep.Responsibilities = new List <string>();
            blankRep.CC = new List <string>();
            SalesRepList.Add(blankRep);

            foreach (XElement element in parent.Elements("Rep"))
            {
                SalesRep rep = new SalesRep();

                try
                {
                    Name name = new Name();
                    name.First = element.Element("Name").Element("First").Value;
                    name.Last  = element.Element("Name").Element("Last").Value;
                    rep.Name   = name;
                    rep.Email  = element.Element("Email").Value;
                    try { rep.Phone = element.Element("Phone").Value; } catch { rep.Phone = ""; }
                    try { rep.SkypeIdentity = element.Element("SkypeIdentity").Value; } catch { rep.SkypeIdentity = ""; }

                    List <string> responsibilities = new List <string>();
                    foreach (XElement responsibility in element.Element("Responsibilities").Elements("Region"))
                    {
                        responsibilities.Add(responsibility.Value);
                    }

                    rep.Responsibilities = responsibilities.Count > 0 ? responsibilities : null;

                    List <string> CC = new List <string>();
                    foreach (XElement cc in element.Element("CC").Elements("Area"))
                    {
                        CC.Add(cc.Value);
                    }

                    rep.CC = CC.Count > 0 ? CC : null;

                    List <string> SIMS = new List <string>();
                    try
                    {
                        foreach (XElement sims in element.Element("SIMS").Elements("Area"))
                        {
                            SIMS.Add(sims.Value);
                        }

                        rep.SIMS = SIMS;
                    }
                    catch
                    {
                        rep.SIMS = null;
                    }

                    rep.Picture = element.Element("Picture").Value;

                    if (rep.SIMS != null && rep.SIMS.Count > 0)
                    {
                        SIMadmins.Add(rep);
                        continue;
                    }

                    SalesRepList.Add(rep);
                }
                catch
                {
                    Common.Log("Could not read rep " + rep.Name.First + " " + rep.Name.Last + " from xml");
                }
            }

            //Make list sorted by first name by default
            var result = XMLFunctions.SalesRepList.ToList();

            result.RemoveAt(0);
            result = result.OrderBy(p => p.Name.First).ToList();
            result.Insert(0, XMLFunctions.SalesRepList[0]);
            SalesRepList = result;

            UpdateComboBoxes.Invoke();
        }