private void buttonApply_Click(object sender, EventArgs e)
        {
            string errmsg;

            ZstExpression.CExpression expr = ZstExpression.CExpression.Parse(textBoxFormulaEdit.Text, out errmsg);

            if (expr == null)
            {
                MessageBox.Show(errmsg);
                return;
            }
            textBoxFormulaEdit.Text = expr.GetExpression();

            TreeNode      node = treeViewWeightSortNode.SelectedNode;
            NodeFormula   nf   = (NodeFormula)node.Tag;
            WeightFormula wf   = nf[nEditFormulaIndex];

            wf.Formula = textBoxFormulaEdit.Text;
            List <string> paras = new List <string>();

            expr.GetVariables(ref paras);

            wf.ParaList.Clear();

            foreach (string paraname in paras)
            {
                WeightParameter wp = null;
                if (dictTempPara.ContainsKey(paraname))
                {
                    wp = FindParameter(paraname, dictTempPara[paraname]);
                }
                else
                {
                    wp = FindParameter(paraname, null);
                }
                if (wp == null)
                {
                    wp          = new WeightParameter();
                    wp.ParaName = paraname;
                    wp.ParaType = 10;
                }
                wf.ParaList.Add(wp);
            }
            HashSet <WeightParameter> wpSet = new HashSet <WeightParameter>();

            foreach (WeightParameter wp in nf.XFormula.ParaList)
            {
                wpSet.Add(wp);
            }
            foreach (WeightParameter wp in nf.YFormula.ParaList)
            {
                wpSet.Add(wp);
            }
            SetParaList(wpSet);

            if (nEditFormulaIndex == 0)
            {
                textBoxFormulaX.Text     = wf.Formula;
                textBoxFormulaX.Modified = false;
            }
            else
            {
                textBoxFormulaY.Text     = wf.Formula;
                textBoxFormulaY.Modified = false;
            }

            SetEditMode(1);

            dateTimePickerLastModifyTime.Value = DateTime.Today;
        }
        private void buttonApply_Click(object sender, EventArgs e)
        {
            WeightFormula wf = null;

            if (groupBoxSelectFormula.Visible)
            {
                TreeNode node = treeViewWeightSortNode.SelectedNode;

                WeightFormula oldwf = (WeightFormula)node.Tag;
                oldwf.nAttach       = 0;
                wf                  = mapCandidateFormula.First(temppair => temppair.Value == (string)listBoxCandidateFormula.SelectedItem).Key;
                node.Tag            = wf;
                wf.NodePath         = node.Name;
                wf.nAttach          = 1;
                textBoxFormula.Text = wf.Formula;
                listBoxCandidateFormula.Items.Remove(listBoxCandidateFormula.SelectedItem);

                if (mapCandidateFormula.ContainsKey(oldwf))
                {
                    listBoxCandidateFormula.Items.Add(mapCandidateFormula[oldwf]);
                }
            }
            else
            {
                string errmsg;
                ZstExpression.CExpression expr = ZstExpression.CExpression.Parse(textBoxFormula.Text, out errmsg);

                if (expr == null)
                {
                    MessageBox.Show(errmsg);
                    return;
                }
                textBoxFormula.Text = expr.GetExpression();

                TreeNode node = treeViewWeightSortNode.SelectedNode;
                wf = (WeightFormula)node.Tag;

                wf.Formula = textBoxFormula.Text;
                List <string> paras = new List <string>();
                expr.GetVariables(ref paras);

                wf.ParaList.Clear();

                foreach (string paraname in paras)
                {
                    WeightParameter wp = null;
                    if (dictTempPara.ContainsKey(paraname))
                    {
                        wp = FindParameter(paraname, dictTempPara[paraname]);
                    }
                    else
                    {
                        wp = FindParameter(paraname, null);
                    }
                    if (wp == null)
                    {
                        wp          = new WeightParameter();
                        wp.ParaName = paraname;
                        wp.ParaType = 10;
                    }
                    wf.ParaList.Add(wp);
                }
            }
            SetParaList(wf.ParaList);
            textBoxFormula.Modified = false;
            SetEditMode(1);

            dateTimePickerLastModifyTime.Value = DateTime.Today;
        }