Example #1
0
        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);
        }
Example #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            TreeNode lSelectedNode = treeExitControls.SelectedNode;

            if (lSelectedNode == null || lSelectedNode.Text.StartsWith("Exit") || !lSelectedNode.Parent.Text.StartsWith("Exit"))
            {
                System.Windows.Forms.MessageBox.Show("Select a Control Device for update.", "Update Control Device");
                return;
            }
            string lSelectedOCAlias = lSelectedNode.Text.Substring(0, lSelectedNode.Text.IndexOf("_"));
            int    lSelectedOCIndex = int.Parse(lSelectedNode.Text.Substring(lSelectedNode.Text.IndexOf("_") + 1));
            string lParentNodeName  = lSelectedNode.Parent.Text;
            string lExitNo          = lParentNodeName.Substring(lParentNodeName.IndexOf(" ") + 1);
            int    lExitNum         = int.Parse(lExitNo);

            FTableCalculator lCalc = GetControlDeviceFromForm();

            if (lSelectedOCAlias == FTableCalculator.OCTypeNames[lCalc.ControlDevice].ToString())
            {
                Dictionary <string, double> lParams = lCalc.ParamValues();
                double lVal = 0;
                foreach (TreeNode lParamNode in lSelectedNode.Nodes)
                {
                    string lParamName = lParamNode.Text.Substring(0, lParamNode.Text.LastIndexOf("("));
                    lVal            = lParams[lParamName];
                    lParamNode.Text = lParamName + "(" + lVal.ToString() + ")";
                }
                this.treeExitControls.MouseUp -= this.treeExitControls_MouseUp;
                AdjustNodeNames(lSelectedNode.Parent);
                lSelectedNode.Expand();
                treeExitControls.SelectedNode  = lSelectedNode;
                this.treeExitControls.MouseUp += new System.Windows.Forms.MouseEventHandler(this.treeExitControls_MouseUp);
            }
            if (lExitNum != SelectedExit())
            {
                TreeNode lNewNode = new TreeNode();
                lNewNode.Text = lSelectedNode.Text;
                foreach (TreeNode lParamNode in lSelectedNode.Nodes)
                {
                    TreeNode lnewParamNode = new TreeNode();
                    lnewParamNode.Text = lParamNode.Text;
                    lNewNode.Nodes.Add(lnewParamNode);
                }
                lSelectedNode.Remove();

                foreach (TreeNode lExitNode in treeExitControls.Nodes)
                {
                    if (lExitNode.Text.Contains(SelectedExit().ToString()))
                    {
                        lExitNode.Nodes.Add(lNewNode);
                        break;
                    }
                }

                this.treeExitControls.MouseUp -= this.treeExitControls_MouseUp;
                AdjustNodeNames(lNewNode.Parent);
                lNewNode.Expand();
                treeExitControls.SelectedNode  = lNewNode;
                this.treeExitControls.MouseUp += new System.Windows.Forms.MouseEventHandler(this.treeExitControls_MouseUp);
            }
        }
Example #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string lErrMsg = ParamsOK();

            if (!string.IsNullOrEmpty(lErrMsg))
            {
                System.Windows.Forms.MessageBox.Show("Please address the following error before proceeding:" + Environment.NewLine + lErrMsg,
                                                     "Adding New Control Devices");
                return;
            }


            int lSelectedExit      = SelectedExit();
            FTableCalculator lCalc = GetControlDeviceFromForm();

            if (lCalc == null)
            {
                System.Windows.Forms.MessageBox.Show("Please select a proper control device type.", "Adding New Control Devices");
                return;
            }

            //Add OC node
            string   lOCCommonName = FTableCalculator.OCTypeNames[lCalc.ControlDevice];
            int      typeCounter   = -99;
            TreeNode lExitNode     = treeExitControls.Nodes[lSelectedExit - 1];

            foreach (TreeNode lOCNode in lExitNode.Nodes)
            {
                string lOCAlias = lOCNode.Text.Substring(0, lOCNode.Text.IndexOf("_"));
                string lOCId    = lOCNode.Text.Substring(lOCNode.Text.IndexOf("_") + 1);
                int    liOCId   = int.Parse(lOCId);

                if (lOCAlias == lOCCommonName)
                {
                    if (typeCounter < liOCId)
                    {
                        typeCounter = liOCId;
                    }
                }
            }

            if (typeCounter < 0)
            {
                typeCounter = 0;
            }
            else
            {
                typeCounter++;
            }

            string lnewOCName = lOCCommonName + "_" + typeCounter.ToString();

            TreeNode lnewOCNode = lExitNode.Nodes.Add(lnewOCName);

            //Add OC's param nodes
            Dictionary <string, double> lParams = lCalc.ParamValues();
            List <string> lParamNames           = lParams.Keys.ToList <string>();
            List <double> lParamValues          = lParams.Values.ToList <double>();

            foreach (string lParamName in lParams.Keys)
            {
                TreeNode lParamNode = new TreeNode();
                lParamNode.Text = lParamName + "(" + lParams[lParamName].ToString() + ")";
                lnewOCNode.Nodes.Add(lParamNode);
            }

            //Refresh tree
            //AddOCtoTree(lCalc);
            AdjustNodeNames(lExitNode);
        }