public static bool CopyandInitStockCalculator(Calculator1 calc, ME2Stock newStock) { bool bHasCopy = false; if (calc != null) { if (calc.GetType().Equals(newStock.GetType())) { ME2Stock oldStock = (ME2Stock)calc; if (oldStock != null) { //initiate analyzer objects newStock.InitTotalME2StocksProperties(); //but keep calc props newStock.CopyCalculatorProperties(oldStock); if (oldStock.CalcParameters != null) { newStock.CalcParameters = new CalculatorParameters(oldStock.CalcParameters); } bHasCopy = true; } } } return(bHasCopy); }
public ME2Stock SetME2Properties(CostBenefitCalculator baseElement, XElement currentCalculationsElement, XElement currentElement) { ME2Stock me2 = new ME2Stock(this.GCCalculatorParams, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); //204 not used //if (this.ME2DescendentStock != null) //{ // //only property set by analyzer // me2.TotalME2Stage = this.ME2DescendentStock.TotalME2Stage; //} ME2Calculator me2Calc = new ME2Calculator(this.GCCalculatorParams); me2.CalcParameters.CurrentElementNodeName = currentElement.Name.LocalName; bool bHasCalcs = false; if (currentCalculationsElement != null) { //have to make sure its not a stockanalyzer string sCalculatorType = CalculatorHelpers.GetAttribute( currentCalculationsElement, Calculator1.cCalculatorType); if (sCalculatorType == ME2CalculatorHelper.CALCULATOR_TYPES.me2.ToString()) { //deserialize xml to object me2Calc.SetME2Properties(currentCalculationsElement, currentElement); //only need alttype and targettype (alts are groupedby using base elements) baseElement.AlternativeType = me2Calc.AlternativeType; baseElement.TargetType = me2Calc.TargetType; bHasCalcs = true; } } if (!bHasCalcs) { //see if a sibling holds the calculations (currentCalcs could be the analyzer) XElement lv = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cCalculatorType, ME2CalculatorHelper.CALCULATOR_TYPES.me2.ToString()); if (lv != null) { //deserialize xml to object me2Calc.SetME2Properties(lv, currentElement); //only need alttype and targettype (alts are groupedby using base elements) baseElement.AlternativeType = me2Calc.AlternativeType; baseElement.TargetType = me2Calc.TargetType; bHasCalcs = true; } } if (!bHasCalcs) { //else don't need the ids from calculator me2.CopyCalculatorProperties(baseElement); } //all calcs and analyses are stored in the appropriate analysis object (i.e. me2.Total, me2.Stat) me2.InitTotalME2StocksProperties(); //copy the initial calculator to the appropriate analysis object.ME2Indicators collection me2.CopyME2CalculatorToME2Stock(me2Calc); me2.AnalyzerType = this.GCCalculatorParams.AnalyzerParms.AnalyzerType; //label and date comes from baseelement me2.Label = baseElement.Label; me2.Date = baseElement.Date; //kiss with the multipliers me2.Multiplier = baseElement.Multiplier; me2.CalculatorId = me2Calc.Id; //adjust id if children analyzers are being inserted/updated ChangeCalculatorIdForUpdatedChildren(currentElement, ref currentCalculationsElement, me2); return(me2); }