コード例 #1
0
        private void btnCompute_Click(object sender, EventArgs e)
        {
            if (!bEditProject)
            {
                txtWeightEstName.Text = txtWeightEstName.Text.Trim();
                if (txtWeightEstName.Text.Length == 0)
                {
                    MessageBox.Show("设计数据名称不能为空!");
                    return;
                }

                if (Verification.IsCheckString(txtWeightEstName.Text))
                {
                    MessageBox.Show("设计数据名称含有非法字符");
                    return;
                }
                curWa.DataName = txtWeightEstName.Text;
            }

            for (int i = 0; i < curWa.FormulaList.Count; ++i)
            {
                CExpression expr = curExprList[i];
                foreach (ParaData wp in curWa.FormulaList[i].ParaList)
                {
                    expr.SetVariableValue(wp.paraName, wp.paraValue);
                }

                double value = expr.Run();
                if (double.IsInfinity(value) || double.IsNaN(value))
                {
                    MessageBox.Show("参数值或公式有误!节点: " + curWa.FormulaList[i].NodePath);
                    return;
                }
                curWa.FormulaList[i].Value = value;
            }

            //curWa.WriteArithmeticFile("test.xml", true);

            if (mainForm.designProjectData == null)
            {
                CoreDesignProject coreForm = new CoreDesignProject(mainForm, "new");
                coreForm.ShowDialog();
            }

            if (mainForm.designProjectData.lstWeightArithmetic == null)
            {
                mainForm.designProjectData.lstWeightArithmetic = new List<WeightArithmetic>();
            }

            //计算
            Dictionary<ParaData, ParaData> wpDict = new Dictionary<ParaData, ParaData>();

            List<WeightFormula> FormulaList = new List<WeightFormula>();
            foreach (WeightFormula formula in curWa.FormulaList)
            {
                List<ParaData> ParaList = new List<ParaData>();
                foreach (ParaData para in formula.ParaList)
                {
                    ParaData tempWp = null;
                    if (!wpDict.ContainsKey(para))
                    {
                        tempWp = new ParaData(para);
                        wpDict.Add(para, tempWp);
                    }
                    else
                    {
                        tempWp = wpDict[para];
                    }
                    ParaList.Add(tempWp);
                }
                formula.ParaList = ParaList;
            }

            if (!bEditProject)
            {
                mainForm.designProjectData.lstWeightArithmetic.Add(curWa);
                mainForm.BindProjectTreeData(mainForm.designProjectData);
                mainForm.SetWeightDesignTab(curWa, mainForm.designProjectData.lstWeightArithmetic.Count - 1);

                XLog.Write("设计数据\"" + txtWeightEstName.Text + "\"计算完成!");
            }
            else
            {
                //刷新页面
                mainForm.SetWeightDesignReuslt(curWa);
                XLog.Write("设计数据\"" + txtWeightEstName.Text + "\"重新计算完成!");
            }

            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #2
0
        private void btnCompute_Click(object sender, EventArgs e)
        {
            if (!bEditProject)
            {
                txtWeightEstName.Text = txtWeightEstName.Text.Trim();
                if (txtWeightEstName.Text.Length == 0)
                {
                    MessageBox.Show("设计数据名称不能为空!");
                    return;
                }

                if (Verification.IsCheckString(txtWeightEstName.Text))
                {
                    MessageBox.Show("设计数据名称含有非法字符");
                    return;
                }
                curWa.DataName = txtWeightEstName.Text;
            }

            for (int i = 0; i < curWa.FormulaList.Count; ++i)
            {
                CExpression expr = curExprList[i];
                foreach (WeightParameter wp in curWa.FormulaList[i].ParaList)
                {
                    expr.SetVariableValue(wp.ParaName, wp.ParaValue);
                }
                curWa.FormulaList[i].Value = expr.Run();
            }

            //curWa.WriteArithmeticFile("test.xml", true);

            if (mainForm.designProjectData == null)
            {
                CoreDesignProject coreForm = new CoreDesignProject(mainForm, "new");
                coreForm.ShowDialog();
            }

            if (mainForm.designProjectData.lstWeightArithmetic == null)
            {
                mainForm.designProjectData.lstWeightArithmetic = new List <WeightArithmetic>();
            }


            //计算
            Dictionary <WeightParameter, WeightParameter> wpDict = new Dictionary <WeightParameter, WeightParameter>();

            List <WeightFormula> FormulaList = new List <WeightFormula>();

            foreach (WeightFormula formula in curWa.FormulaList)
            {
                List <WeightParameter> ParaList = new List <WeightParameter>();
                foreach (WeightParameter para in formula.ParaList)
                {
                    WeightParameter tempWp = null;
                    if (!wpDict.ContainsKey(para))
                    {
                        tempWp = new WeightParameter(para);
                        wpDict.Add(para, tempWp);
                    }
                    else
                    {
                        tempWp = wpDict[para];
                    }
                    ParaList.Add(tempWp);
                }
                formula.ParaList = ParaList;
            }

            if (!bEditProject)
            {
                mainForm.designProjectData.lstWeightArithmetic.Add(curWa);
                mainForm.BindProjectTreeData(mainForm.designProjectData);
                mainForm.SetWeightDesignTab(curWa, mainForm.designProjectData.lstWeightArithmetic.Count - 1);

                XLog.Write("设计数据\"" + txtWeightEstName.Text + "\"计算完成!");
            }
            else
            {
                //刷新页面
                mainForm.SetWeightDesignReuslt(curWa);
                XLog.Write("设计数据\"" + txtWeightEstName.Text + "\"重新计算完成!");
            }

            DialogResult = DialogResult.OK;
            Close();
        }