/// <summary> /// Invoked when the user click on an item in the tree list view /// Retrieve the IPathway or IMix object stored in the tag and sends it to the ResultsControl /// for displaying the results associated with that pathway or mix main output /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void treeView1_MouseDown(object sender, MouseEventArgs e) { treeView1.SelectedNode = treeView1.GetNodeAt(e.Location); if (this.treeView1.SelectedNode != null) { Object tag = this.treeView1.SelectedNode.Tag; IResults result = null; int productID = -1; string name = ""; //if the retrieved object is a pathway if (tag is IPathway) { IPathway path = tag as IPathway; //We ask the pathway what is the product defined as the main product for this pathway //then store an integer that corresponds to an IResource.ID productID = path.MainOutputResourceID; //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results Dictionary <int, IResults> availableResults = path.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data); if (availableResults.ContainsKey(productID)) { result = availableResults[productID]; } //We set the string variable as the name of the pathway name = path.Name; } //if the retrieved object is a pathway else if (tag is IMix) { IMix mix = tag as IMix; //We ask the mix what is the product defined as the main product for this mix //then store an integer that corresponds to an IResource.ID productID = mix.MainOutputResourceID; //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results Dictionary <int, IResults> availableResults = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data); if (availableResults.ContainsKey(productID)) { result = availableResults[productID]; } //We set the string variable as the name of the pathway name = mix.Name; } //if we found a pathway or a mix and we have all the necessary parameters //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results if (result != null && productID != -1 && !String.IsNullOrEmpty(name)) { this.resultsControl1.SetResults(name, result, productID); } } }
/// <summary> /// Invoked when the user click on an item in the tree list view /// Retrieve the IPathway or IMix object stored in the tag and sends it to the ResultsControl /// for displaying the results associated with that pathway or mix main output /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void treeView1_MouseDown(object sender, MouseEventArgs e) { treeView1.SelectedNode = treeView1.GetNodeAt(e.Location); if (this.treeView1.SelectedNode != null) { Object tag = this.treeView1.SelectedNode.Tag; IResults result = null; int productID = -1; string name = ""; if (tag is IPathway) {//if the retrieved object is a pathway IPathway path = tag as IPathway; //We ask the pathway what is the product defined as the main product for this pathway //then store an integer that corresponds to an IResource.ID productID = ResultsAccess.controler.CurrentProject.Data.Helper.PathwayMainOutputResouce(path.Id); //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results Dictionary <IIO, IResults> availableResults = path.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data); Guid desiredOutput = new Guid(); if (null == availableResults.Keys.SingleOrDefault(item => item.ResourceId == productID)) { MessageBox.Show("Selected pathway does not produce the fuel selected. Please remove it from the Fule Types list"); return; } else { foreach (IIO io in availableResults.Keys.Where(item => item.ResourceId == productID)) { desiredOutput = io.Id; if (io.Id == path.MainOutput) { desiredOutput = io.Id; break; } } } result = availableResults.SingleOrDefault(item => item.Key.Id == desiredOutput).Value; //We set the string variable as the name of the pathway name = path.Name; } else if (tag is IMix) {//if the retrieved object is a mix IMix mix = tag as IMix; //We ask the mix what is the product defined as the main product for this mix //then store an integer that corresponds to an IResource.ID productID = mix.MainOutputResourceID; //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results var upstream = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data); if (null == upstream.Keys.SingleOrDefault(item => item.ResourceId == productID)) { MessageBox.Show("Selected mix does not produce the fuel selected. Please remove it from the Fule Types list"); return; } //a mix has a single output so we can safely do the folowing result = upstream.SingleOrDefault(item => item.Key.ResourceId == productID).Value; //We set the string variable as the name of the pathway name = mix.Name; } //if we found a pathway or a mix and we have all the necessary parameters //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results if (result != null && productID != -1 && !String.IsNullOrEmpty(name)) { this.resultsControl1.SetResults(name, result, productID); } } }