private Boolean Equals(ProjectResult that) { if (that == null) return false; return this.TotalCost == that.TotalCost && this.TotalEI == that.TotalEI && this.TotalDuration == that.TotalDuration; }
private void btnViewResults_Click(object sender, EventArgs e) { List<ProjectResult> results = new List<ProjectResult>(); String fName = ""; using (OpenFileDialog openDlg = new OpenFileDialog()) { openDlg.Title = "Open Project Results"; openDlg.Filter = "XML File|*.xml"; openDlg.ShowDialog(); if (!String.IsNullOrEmpty(openDlg.FileName)) { fName = openDlg.FileName; FileStream reader = new FileStream(openDlg.FileName, FileMode.Open, FileAccess.Read); XmlDocument projects = new System.Xml.XmlDocument(); projects.Load(reader); XmlNodeList nList = projects.GetElementsByTagName("Project"); foreach (XmlNode node in nList) { ProjectResult res = new ProjectResult(); XmlNodeList children = node.ChildNodes; //id attribute has project name res.ProjectName = node.Attributes["id"].InnerText; //project level data res.TotalCost = Double.Parse(children[0].InnerText); res.TotalEI = Double.Parse(children[1].InnerText); res.TotalDuration = Double.Parse(children[2].InnerText); res.SelectedAssemblies = new List<Assembly>(); //get selected assemblies for each project for (int i = 3; i < children.Count; i++) { XmlNode component = children[i]; XmlNodeList compData = component.ChildNodes; Assembly assem = new Assembly(); assem.Category = component.Attributes["id"].Value; assem.AssemblyName = compData[0].InnerText; assem.Cost = Double.Parse(compData[1].InnerText); assem.CO2 = Double.Parse(compData[2].InnerText); assem.Duration = Double.Parse(compData[3].InnerText); res.SelectedAssemblies.Add(assem); } if (!results.Contains(res)) results.Add(res); } } } if (results.Count <= 0) return; using (ResultsForm resFrm = new ResultsForm()) { resFrm.FileName = fName; resFrm.Results = results; resFrm.ShowDialog(); } }