Example #1
0
        public bool LoadFromXML(string filename, LoadOptions lo)
        {
            if (!System.IO.File.Exists(filename)) return false;

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(filename);

            XmlElement root = xmldoc["project"];

            if (root == null) return false;

            if (root["name"] == null || root["id"] == null) return false;

            name = root["name"].InnerText;
            id = root["id"].InnerText;

            if (root["startfrom"] != null)
            {
                try
                {
                    startFrom = DateTime.ParseExact(root["startfrom"].ToString(), "dd.MM.yyyy", null);
                }
                catch
                {
                    startFrom = DateTime.Now;
                }
            }

            XmlElement cfs = root["coefs"];

            if (cfs != null && (lo == LoadOptions.All || lo == LoadOptions.Coefs))
            {
                coefs.Clear();
                foreach (XmlNode cf in cfs.ChildNodes)
                {
                    ProjectCoef pc = new ProjectCoef();
                    pc.CoefProject = this;
                    if (pc.LoadFromXML(cf))
                        coefs[pc.ProviderName] = pc;
                }
            }

            XmlElement schedules = root["schedules"];

            if (schedules == null) return false;

            if (lo == LoadOptions.All || lo == LoadOptions.Schedules)
            {
                Schedules.Items.Clear();
                foreach (XmlNode node in schedules.ChildNodes)
                {
                    if (node.Name.ToLower() != "schedule") continue;

                    ProjectSchedule ps = new ProjectSchedule();
                    ps.ParentProject = this;

                    if (ps.LoadFromXML(node))
                        Schedules.Items.Add(ps);
                }
            }

            return true;
        }