private bool AddOCtoTree(FTableCalculator aCalc)
        {
            bool lCalcAdded = false;

            FTableCalculator.ControlDeviceType lOCType = aCalc.ControlDevice;
            int lExit = aCalc.myExit;
            Dictionary <string, double> lParamValues = aCalc.ParamValues();
            string lOCDisplayName = "";

            FTableCalculator.OCTypeNames.TryGetValue(aCalc.ControlDevice, out lOCDisplayName);

            TreeNode lExitNode = null;

            if (treeExitControls.Nodes.ContainsKey(lExit.ToString()))
            {
                lExitNode = treeExitControls.Nodes[lExit.ToString()]; //.Add(lKey, lOCName + "_" + Id.ToString());
            }
            else
            {
                lExitNode = treeExitControls.Nodes.Add(lExit.ToString(), "Exit " + lExit.ToString());
            }

            //add OC node
            string lOCNameClass = aCalc.GetType().Name;
            int    Ctr          = 0;
            string lOCNodeName  = lOCDisplayName + "_" + Ctr.ToString();
            string lOCNodeKey   = lOCNameClass + "_" + Ctr.ToString();

            while (lExitNode.Nodes.ContainsKey(lOCNodeKey))
            {
                Ctr++;
                lOCNodeKey  = lOCNameClass + "_" + Ctr.ToString();
                lOCNodeName = lOCDisplayName + "_" + Ctr.ToString();
            }
            TreeNode lOCNode = lExitNode.Nodes.Add(lOCNodeKey, lOCNodeName);

            //add parameter value nodes
            List <string> lParamNames = lParamValues.Keys.ToList <string>();
            List <double> lParamVals  = lParamValues.Values.ToList <double>();

            for (int z = 0; z < lParamNames.Count; z++)
            {
                lOCNode.Nodes.Add(lParamNames[z], lParamNames[z] + "(" + lParamVals[z] + ")");
            }
            lCalcAdded = true;

            return(lCalcAdded);
        }
 /**
  * The inputs parameter must be put in the correct order that calcuator expects
  * @param calculatorType
  * @param inputs
  */
 public ControlDeviceMiddleware(FTableCalculator.ControlDeviceType calculatorType)
 {
     this.myCalcType = calculatorType;
 }
        private FTableCalculator GetControlDeviceFromForm()
        {
            List <FTableCalculator.ControlDeviceType> listOCTypes = FTableCalculator.OCTypeNames.Keys.ToList <FTableCalculator.ControlDeviceType>();
            List <string> listOCCommonNames = FTableCalculator.OCTypeNames.Values.ToList <string>();

            FTableCalculator.ControlDeviceType lSelectedOCType = FTableCalculator.ControlDeviceType.None;
            for (int i = 0; i < listOCTypes.Count; i++)
            {
                if (cboOCTypes.SelectedItem.ToString() == listOCCommonNames[i])
                {
                    lSelectedOCType = listOCTypes[i];
                    break;
                }
            }

            int lSelectedExit = SelectedExit();

            double lParam0 = 0;
            double lParam1 = 0;
            double lDisCoe = 0;

            double.TryParse(txtOCParm_0.Text, out lParam0);
            double.TryParse(txtOCParm_1.Text, out lParam1);
            double.TryParse(txtOCDisCoeff.Text, out lDisCoe);

            FTableCalculator lCalc = null;

            switch (lSelectedOCType)
            {
            case FTableCalculator.ControlDeviceType.OrificeRiser:
                lCalc = new FTableCalcOCOrificeRiser();
                ((FTableCalcOCOrificeRiser)lCalc).myExit = lSelectedExit;
                ((FTableCalcOCOrificeRiser)lCalc).OrificePipeDiameter         = lParam0;
                ((FTableCalcOCOrificeRiser)lCalc).OrificeDepth                = lParam1;
                ((FTableCalcOCOrificeRiser)lCalc).OrificeDischargeCoefficient = lDisCoe;
                break;

            case FTableCalculator.ControlDeviceType.OrificeUnderdrain:
                lCalc = new FTableCalcOCOrificeUnderflow();
                ((FTableCalcOCOrificeUnderflow)lCalc).myExit = lSelectedExit;
                ((FTableCalcOCOrificeUnderflow)lCalc).OrificePipeDiameter         = lParam0;
                ((FTableCalcOCOrificeUnderflow)lCalc).OrificeInvertDepth          = lParam1;
                ((FTableCalcOCOrificeUnderflow)lCalc).OrificeDischargeCoefficient = lDisCoe;
                break;

            case FTableCalculator.ControlDeviceType.WeirBroadCrest:
                lCalc = new FTableCalcOCWeirBroad();
                ((FTableCalcOCWeirBroad)lCalc).myExit               = lSelectedExit;
                ((FTableCalcOCWeirBroad)lCalc).WeirWidth            = lParam0;
                ((FTableCalcOCWeirBroad)lCalc).WeirInvert           = lParam1;
                ((FTableCalcOCWeirBroad)lCalc).DischargeCoefficient = lDisCoe;
                break;

            case FTableCalculator.ControlDeviceType.WeirRectangular:
                lCalc = new FTableCalcOCWeirRectangular();
                ((FTableCalcOCWeirRectangular)lCalc).myExit               = lSelectedExit;
                ((FTableCalcOCWeirRectangular)lCalc).WeirWidth            = lParam0;
                ((FTableCalcOCWeirRectangular)lCalc).WeirInvert           = lParam1;
                ((FTableCalcOCWeirRectangular)lCalc).DischargeCoefficient = lDisCoe;
                break;

            case FTableCalculator.ControlDeviceType.WeirTrapeCipolletti:
                lCalc = new FTableCalcOCWeirTrapeCipolletti();
                ((FTableCalcOCWeirTrapeCipolletti)lCalc).myExit               = lSelectedExit;
                ((FTableCalcOCWeirTrapeCipolletti)lCalc).WeirWidth            = lParam0;
                ((FTableCalcOCWeirTrapeCipolletti)lCalc).WeirInvert           = lParam1;
                ((FTableCalcOCWeirTrapeCipolletti)lCalc).DischargeCoefficient = lDisCoe;
                break;

            case FTableCalculator.ControlDeviceType.WeirTriVNotch:
                lCalc = new FTableCalcOCWeirTriVNotch();
                ((FTableCalcOCWeirTriVNotch)lCalc).myExit               = lSelectedExit;
                ((FTableCalcOCWeirTriVNotch)lCalc).WeirAngle            = lParam0;
                ((FTableCalcOCWeirTriVNotch)lCalc).WeirInvert           = lParam1;
                ((FTableCalcOCWeirTriVNotch)lCalc).DischargeCoefficient = lDisCoe;
                break;
            }
            return(lCalc);
        }
        private void cboOCTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!pLoaded)
            {
                return;
            }
            string lSelectedOCName = cboOCTypes.SelectedItem.ToString();

            if (lSelectedOCName == "None")
            {
                return;
            }
            string lName = "";

            FTableCalculator.ControlDeviceType lSelectedOCType = FTableCalculator.ControlDeviceType.None;
            foreach (FTableCalculator.ControlDeviceType lOCType in FTableCalculator.OCTypeNames.Keys)
            {
                if (FTableCalculator.OCTypeNames.TryGetValue(lOCType, out lName))
                {
                    if (lSelectedOCName == lName)
                    {
                        lSelectedOCType = lOCType;
                        break;
                    }
                }
            }

            Dictionary <string, double> lDefaults = null;
            FTableCalculator            lCalc     = null;

            switch (lSelectedOCType)
            {
            case FTableCalculator.ControlDeviceType.WeirTriVNotch:
                lCalc     = new FTableCalcOCWeirTriVNotch();
                lDefaults = ((FTableCalcOCWeirTriVNotch)lCalc).ParamValueDefaults();
                break;

            case FTableCalculator.ControlDeviceType.WeirTrapeCipolletti:
                lCalc     = new FTableCalcOCWeirTrapeCipolletti();
                lDefaults = ((FTableCalcOCWeirTrapeCipolletti)lCalc).ParamValueDefaults();
                break;

            case FTableCalculator.ControlDeviceType.WeirRectangular:
                lCalc     = new FTableCalcOCWeirRectangular();
                lDefaults = ((FTableCalcOCWeirRectangular)lCalc).ParamValueDefaults();
                break;

            case FTableCalculator.ControlDeviceType.WeirBroadCrest:
                lCalc     = new FTableCalcOCWeirBroad();
                lDefaults = ((FTableCalcOCWeirBroad)lCalc).ParamValueDefaults();
                break;

            case FTableCalculator.ControlDeviceType.OrificeUnderdrain:
                lCalc     = new FTableCalcOCOrificeUnderflow();
                lDefaults = ((FTableCalcOCOrificeUnderflow)lCalc).ParamValueDefaults();
                break;

            case FTableCalculator.ControlDeviceType.OrificeRiser:
                lCalc     = new FTableCalcOCOrificeRiser();
                lDefaults = ((FTableCalcOCOrificeRiser)lCalc).ParamValueDefaults();
                break;
            }
            ;

            List <string> lParamLbls = lDefaults.Keys.ToList <string>();
            List <double> lParamVals = lDefaults.Values.ToList <double>();

            lblOCParm0.Text = lParamLbls[0];
            lblOCParm1.Text = lParamLbls[1];

            txtOCParm_0.Text   = lParamVals[0].ToString();
            txtOCParm_1.Text   = lParamVals[1].ToString();
            txtOCDisCoeff.Text = lParamVals[2].ToString();

            //if (clsGlobals.gToolType == clsGlobals.ToolType.Gray)
            //{
            //    rdoExit2.Checked = true;
            //}
            //else
            //{
            //    rdoExit1.Checked = true;
            //}
        }