Exemple #1
0
        private void btnJYNew_Click(object sender, EventArgs e)
        {
            if (treeViewArithmeticList.Nodes.Count > 1 && selNode.Parent == treeViewArithmeticList.Nodes[1])
            {
                WeightArithmetic wa = (WeightArithmetic)selNode.Tag;

                if (!QueryWeightSort(wa))
                {
                    return;
                }
            }

            WeightArithmeticOperForm form = new WeightArithmeticOperForm("jynew", selNode);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            foreach (TreeNode node in treeViewArithmeticList.Nodes[0].Nodes)
            {
                if (node.Text == form.strWeightSortName)
                {
                    node.Nodes.Add(node.Name + "\\" + form.strWeightArithmeticFileName + ".wem", form.strWeightArithmeticFileName, 4, 5);
                    if (node.IsExpanded == false)
                    {
                        node.Expand();
                    }
                    break;
                }
            }
            WeightParameter.GetWeightParameterList()[10].Clear();
        }
Exemple #2
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            WeightArithmeticOperForm form = new WeightArithmeticOperForm("new", selNode);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            foreach (TreeNode node in treeViewArithmeticList.Nodes[0].Nodes)
            {
                if (node.Text == form.strWeightSortName)
                {
                    string key = node.Name + "\\" + form.strWeightArithmeticFileName + ".wem";
                    if (!node.Nodes.ContainsKey(key))
                    {
                        node.Nodes.Add(key, form.strWeightArithmeticFileName, 4, 5);
                    }
                    if (node.IsExpanded == false)
                    {
                        node.Expand();
                    }
                    break;
                }
            }

            WeightParameter.GetWeightParameterList()[10].Clear();
        }
        public WeightParameter FindParameter(string name, string unit)
        {
            WeightParameter localwp = waData.FindParameter(name, unit);

            if (localwp != null)
            {
                return(localwp);
            }

            List <List <WeightParameter> > WeightParaList = WeightParameter.GetWeightParameterList();

            for (int i = 0; i < WeightParaList.Count; ++i)
            {
                foreach (WeightParameter temp in WeightParaList[i])
                {
                    if (temp.ParaName == name)
                    {
                        if (unit == null || (temp.ParaUnit == unit))
                        {
                            return(new WeightParameter(temp));
                        }
                    }
                }
            }

            return(null);
        }
Exemple #4
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            WeightArithmeticOperForm form = new WeightArithmeticOperForm("edit", selNode);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            WeightParameter.GetWeightParameterList()[10].Clear();
        }
        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter           = "Excel files (*.xls)|*.xls|All files (*.*)|*.*";
            dialog.OverwritePrompt  = true;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Excel.Application app = new Excel.ApplicationClass();
            try
            {
                Object missing = System.Reflection.Missing.Value;
                app.Visible = false;

                Excel.Workbook wBook = app.Workbooks.Add(missing);

                Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet;

                Excel.Range DataCell = wSheet.get_Range("A1", "A1");
                DataCell.Value2           = "参数名称";
                DataCell.Next.Value2      = "参数单位";
                DataCell.Next.Next.Value2 = "参数数值";

                for (int i = 0; i < curWaParas.Count; ++i)
                {
                    WeightParameter wp = curWaParas[i];

                    string cellid = "A" + (i + 2).ToString();
                    DataCell                  = wSheet.get_Range(cellid, cellid);
                    DataCell.Value2           = wp.ParaName;
                    DataCell.Next.Value2      = wp.ParaUnit;
                    DataCell.Next.Next.Value2 = wp.ParaValue;
                }

                //设置禁止弹出保存和覆盖的询问提示框
                app.DisplayAlerts          = false;
                app.AlertBeforeOverwriting = false;
                //保存工作簿
                wBook.SaveAs(dialog.FileName, Excel.XlFileFormat.xlWorkbookNormal, missing, missing, missing, missing, Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
                wBook.Close(false, missing, missing);
                app.Quit();
                app = null;
                XLog.Write("成功导出参数值到文件\"" + dialog.FileName + "\"!");
            }
            catch (Exception err)
            {
                MessageBox.Show("导出Excel出错!错误原因:" + err.Message, "提示信息",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #6
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog();
                dlg.RestoreDirectory = true;
                dlg.Filter           = "Wem files (*.wem)|*.wem";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                List <WeightSortData> wsDataList = WeightSortManageForm.GetListWeightSortData(false);

                WeightArithmetic wa = WeightArithmetic.ReadArithmeticData(dlg.FileName);
                WeightParameter.GetWeightParameterList()[10].Clear();

                if (!QueryWeightSort(wa))
                {
                    return;
                }

                if (!WeightArithmeticOperForm.WriteArithmeticFile(wa, true))
                {
                    return;
                }
                //加节点
                foreach (TreeNode treenode in treeViewArithmeticList.Nodes[0].Nodes)
                {
                    if (treenode.Text == wa.SortName)
                    {
                        string filename = "weightCategory\\" + wa.SortName + "\\" + wa.Name + ".wem";
                        if (!treenode.Nodes.ContainsKey(filename))
                        {
                            treenode.Nodes.Add(filename, wa.Name, 4, 5);
                            if (treenode.IsExpanded == false)
                            {
                                treenode.Expand();
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                XCommon.XLog.Write("导入重量算法文件错误");
            }
        }
Exemple #7
0
 private void listViewPara_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewPara.SelectedItems.Count != 0)
     {
         WeightParameter wp = TempParaList[listViewPara.SelectedItems[0].Index];
         textBoxParaUnit.Text   = wp.ParaUnit;
         textBoxParaRemark.Text = wp.ParaRemark;
     }
     else
     {
         textBoxParaUnit.Text   = "";
         textBoxParaRemark.Text = "";
     }
     textBoxParaUnit.Modified   = false;
     textBoxParaRemark.Modified = false;
 }
        public CoreEnvelopeAtithmeticManageForm(MainForm form)
        {
            InitializeComponent();
            mainForm = form;
            WeightParameter.ResetWeightParameterList();

            treeViewArithmeticList.ImageList = imageListTreeView;

            //if (!System.IO.Directory.Exists("CenterofGravityEnvelopeMethod"))
            //{
            //    MessageBox.Show("不存在 CenterofGravityEnvelopeMethod 目录!");
            //    Close();
            //    return;
            //}

            Dictionary <string, string> waItems = GetArithmeticItems();

            TreeNode rootnode1 = treeViewArithmeticList.Nodes.Add("CenterofGravityEnvelopeMethod", "重心包线算法", 0, 1);

            foreach (KeyValuePair <string, string> pair in waItems)
            {
                rootnode1.Nodes.Add(pair.Value, pair.Key, 4, 5);
            }

            rootnode1.ExpandAll();

            if (mainForm == null)
            {
                return;
            }
            DesignProjectData dpData = mainForm.designProjectData;

            if (dpData == null)
            {
                return;
            }
            if (dpData.lstCoreEnvelopeDesign != null)
            {
                TreeNode rootnode2 = treeViewArithmeticList.Nodes.Add("设计结果列表", "设计结果列表", 0, 1);
                foreach (CoreEnvelopeArithmetic wa in dpData.lstCoreEnvelopeDesign)
                {
                    TreeNode node = rootnode2.Nodes.Add(wa.DataName, wa.DataName, 4, 5);
                    node.Tag = wa;
                }
                rootnode2.Expand();
            }
        }
Exemple #9
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (textBoxParaUnit.Modified || textBoxParaRemark.Modified)
            {
                WeightParameter wp = TempParaList[listViewPara.SelectedItems[0].Index];

                if (wp.ParaUnit == textBoxParaUnit.Text && wp.ParaRemark == textBoxParaRemark.Text)
                {
                    return;
                }

                wp.ParaUnit   = textBoxParaUnit.Text;
                wp.ParaRemark = textBoxParaRemark.Text;

                listViewPara.SelectedItems[0].SubItems[0].Text = wp.ParaName + " *";

                textBoxParaUnit.Modified   = false;
                textBoxParaRemark.Modified = false;
            }
        }
        private void listBoxParaType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxParaType.SelectedIndex == -1)
            {
                return;
            }
            listViewParaAll.Items.Clear();

            List <List <WeightParameter> > WeightParaList = WeightParameter.GetWeightParameterList();

            List <WeightParameter> wplist = WeightParaList[listBoxParaType.SelectedIndex];

            for (int i = 0; i < wplist.Count; ++i)
            {
                ListViewItem lvi = listViewParaAll.Items.Add(wplist[i].ParaName);
                lvi.SubItems.Add(wplist[i].ParaUnit);
                lvi.SubItems.Add(wplist[i].ParaRemark);
            }

            textBoxFormulaEdit.Focus();
        }
        private void btnJYNew_Click(object sender, EventArgs e)
        {
            CoreEnvelopeArithmeticOperForm form = new CoreEnvelopeArithmeticOperForm("jynew", selNode);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            TreeNode node = treeViewArithmeticList.Nodes[0];

            string key = "CenterofGravityEnvelopeMethod\\" + form.strCoreEnvelopeArithmeticFileName + ".mcem";

            if (!node.Nodes.ContainsKey(key))
            {
                node.Nodes.Add(key, form.strCoreEnvelopeArithmeticFileName, 4, 5);
            }
            if (node.IsExpanded == false)
            {
                node.Expand();
            }

            WeightParameter.GetWeightParameterList()[10].Clear();
        }
        private void btnImportFromExcel_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Excel.Application app = new Excel.ApplicationClass();
            try
            {
                Object missing = System.Reflection.Missing.Value;
                app.Visible = false;
                Excel.Workbook  wBook  = app.Workbooks.Open(dialog.FileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet;

                if (wSheet.Rows.Count > 1)
                {
                    for (int i = 2; i <= wSheet.Rows.Count; ++i)
                    {
                        string      cellid   = "A" + i.ToString();
                        Excel.Range DataCell = wSheet.get_Range(cellid, cellid);

                        string ParaName = (string)DataCell.Text;

                        ParaName = ParaName.Trim();
                        if (ParaName == "")
                        {
                            break;
                        }

                        WeightParameter wp = curWaParas.Find(p => p.ParaName == ParaName);
                        if (wp == null)
                        {
                            continue;
                        }
                        if (wp.ParaUnit != (string)DataCell.Next.Text)
                        {
                            continue;
                        }

                        wp.ParaValue = (double)DataCell.Next.Next.Value2;
                    }
                }

                for (int i = 0; i < dataGridViewParaInput.Rows.Count; ++i)
                {
                    dataGridViewParaInput.Rows[i].Cells[1].Value = curWaParas[i].ParaValue.ToString();
                }

                app.Quit();
                app = null;

                XLog.Write("从文件\"" + dialog.FileName + "\"导入参数值成功!");
            }
            catch (Exception err)
            {
                MessageBox.Show("导入Excel出错!错误原因:" + err.Message, "提示信息",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void btnExportToXml_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter           = "Xml files (*.xml)|*.xml|Excel files (*.xls)|*.xls|All files (*.*)|*.*";
            dialog.OverwritePrompt  = true;
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //导出至xml文件
            if (dialog.FileName.EndsWith(".xml"))
            {
                XmlDocument   xmldoc   = new XmlDocument();
                XmlTextWriter writeXml = null;
                try
                {
                    writeXml = new XmlTextWriter(dialog.FileName, Encoding.GetEncoding("gb2312"));
                }
                catch
                {
                    MessageBox.Show("创建或写入文件失败!");
                    return;
                }

                writeXml.Formatting  = Formatting.Indented;
                writeXml.Indentation = 5;
                writeXml.WriteStartDocument();

                writeXml.WriteStartElement("参数列表");
                {
                    foreach (WeightParameter wp in curWaParas)
                    {
                        writeXml.WriteStartElement("参数");
                        {
                            writeXml.WriteStartElement("参数名称");
                            writeXml.WriteString(wp.ParaName);
                            writeXml.WriteEndElement();
                        }
                        {
                            writeXml.WriteStartElement("参数单位");
                            writeXml.WriteString(wp.ParaUnit);
                            writeXml.WriteEndElement();
                        }
                        {
                            writeXml.WriteStartElement("参数类型");
                            writeXml.WriteValue(wp.ParaType);
                            writeXml.WriteEndElement();
                        }
                        {
                            writeXml.WriteStartElement("参数数值");
                            writeXml.WriteValue(wp.ParaValue);
                            writeXml.WriteEndElement();
                        }
                        {
                            writeXml.WriteStartElement("参数备注");
                            writeXml.WriteString(wp.ParaRemark);
                            writeXml.WriteEndElement();
                        }
                        writeXml.WriteEndElement();
                    }
                }
                writeXml.WriteEndElement();
                writeXml.Close();
            }

            //导出至xml文件
            if (dialog.FileName.EndsWith(".xls"))
            {
                Excel.Application app = new Excel.ApplicationClass();
                try
                {
                    Object missing = System.Reflection.Missing.Value;
                    app.Visible = false;

                    Excel.Workbook wBook = app.Workbooks.Add(missing);

                    Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet;

                    Excel.Range DataCell = wSheet.get_Range("A1", "A1");
                    DataCell.Value2           = "参数名称";
                    DataCell.Next.Value2      = "参数单位";
                    DataCell.Next.Next.Value2 = "参数数值";

                    for (int i = 0; i < curWaParas.Count; ++i)
                    {
                        WeightParameter wp = curWaParas[i];

                        string cellid = "A" + (i + 2).ToString();
                        DataCell                  = wSheet.get_Range(cellid, cellid);
                        DataCell.Value2           = wp.ParaName;
                        DataCell.Next.Value2      = wp.ParaUnit;
                        DataCell.Next.Next.Value2 = wp.ParaValue;
                    }

                    //设置禁止弹出保存和覆盖的询问提示框
                    app.DisplayAlerts          = false;
                    app.AlertBeforeOverwriting = false;
                    //保存工作簿
                    wBook.SaveAs(dialog.FileName, Excel.XlFileFormat.xlWorkbookNormal, missing, missing, missing, missing, Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
                    wBook.Close(false, missing, missing);
                    app.Quit();
                    app = null;
                }
                catch (Exception err)
                {
                    MessageBox.Show("导出Excel出错!错误原因:" + err.Message, "提示信息",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            XLog.Write("成功导出参数值到文件\"" + dialog.FileName + "\"!");
        }
        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 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[2 * i];
                foreach (WeightParameter wp in curWa.FormulaList[i].XFormula.ParaList)
                {
                    expr.SetVariableValue(wp.ParaName, wp.ParaValue);
                }
                curWa.FormulaList[i].XFormula.Value = expr.Run();

                expr = curExprList[2 * i + 1];
                foreach (WeightParameter wp in curWa.FormulaList[i].YFormula.ParaList)
                {
                    expr.SetVariableValue(wp.ParaName, wp.ParaValue);
                }
                curWa.FormulaList[i].YFormula.Value = expr.Run();
            }

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

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

            if (mainForm.designProjectData.lstCoreEnvelopeDesign == null)
            {
                mainForm.designProjectData.lstCoreEnvelopeDesign = new List <Model.CoreEnvelopeArithmetic>();
            }


            Dictionary <WeightParameter, WeightParameter> wpDict = new Dictionary <WeightParameter, WeightParameter>();

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

            foreach (NodeFormula ndformula in curWa.FormulaList)
            {
                for (int i = 0; i < 2; ++i)
                {
                    WeightFormula          formula  = ndformula[i];
                    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.lstCoreEnvelopeDesign.Add(curWa);
                mainForm.BindProjectTreeData(mainForm.designProjectData);
                mainForm.SetCoreEnvelopeDesignTab(curWa, mainForm.designProjectData.lstCoreEnvelopeDesign.Count - 1);
                XLog.Write("设计数据\"" + txtWeightEstName.Text + "\"计算完成!");
            }
            else
            {
                //设置页面数据
                mainForm.SetCoreEnvelopeDesignResult(curWa);
                XLog.Write("设计数据\"" + txtWeightEstName.Text + "\"重新计算完成!");
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        private void btnImportFromXml_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter           = "Xml files (*.xml)|*.xml|Excel files (*.xls)|*.xls|All files (*.*)|*.*";
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //从xml文件导入
            if (dialog.FileName.EndsWith(".xml") || dialog.FileName.EndsWith(".XML"))
            {
                XmlDocument xmldoc = new XmlDocument();

                try
                {
                    xmldoc.Load(dialog.FileName);
                }
                catch
                {
                    MessageBox.Show("打开文件错误!");
                    return;
                }


                XmlNode rootnode = xmldoc.SelectSingleNode("参数列表");

                if (rootnode == null)
                {
                    MessageBox.Show("错误的参数文件!");
                    return;
                }

                foreach (XmlNode node in rootnode.ChildNodes)
                {
                    string ParaName = node.ChildNodes[0].InnerText;

                    ParaName = ParaName.Trim();

                    WeightParameter wp = curWaParas.Find(p => p.ParaName == ParaName);
                    if (wp == null)
                    {
                        continue;
                    }
                    if (wp.ParaUnit != node.ChildNodes[1].InnerText.Trim())
                    {
                        continue;
                    }

                    double value = 0;
                    double.TryParse(node.ChildNodes[3].InnerText, out value);
                    wp.ParaValue = value;
                }
                for (int i = 0; i < dataGridViewParaInput.Rows.Count; ++i)
                {
                    dataGridViewParaInput.Rows[i].Cells[1].Value = curWaParas[i].ParaValue.ToString();
                }
            }

            //从excel文件导入
            if (dialog.FileName.EndsWith(".xls"))
            {
                Excel.Application app = new Excel.ApplicationClass();
                try
                {
                    Object missing = System.Reflection.Missing.Value;
                    app.Visible = false;
                    Excel.Workbook  wBook  = app.Workbooks.Open(dialog.FileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                    Excel.Worksheet wSheet = wBook.Worksheets[1] as Excel.Worksheet;

                    if (wSheet.Rows.Count > 1)
                    {
                        for (int i = 2; i <= wSheet.Rows.Count; ++i)
                        {
                            string      cellid   = "A" + i.ToString();
                            Excel.Range DataCell = wSheet.get_Range(cellid, cellid);

                            string ParaName = (string)DataCell.Text;

                            ParaName = ParaName.Trim();
                            if (ParaName == "")
                            {
                                break;
                            }

                            WeightParameter wp = curWaParas.Find(p => p.ParaName == ParaName);
                            if (wp == null)
                            {
                                continue;
                            }
                            if (wp.ParaUnit != (string)DataCell.Next.Text)
                            {
                                continue;
                            }

                            wp.ParaValue = (double)DataCell.Next.Next.Value2;
                        }
                    }

                    for (int i = 0; i < dataGridViewParaInput.Rows.Count; ++i)
                    {
                        dataGridViewParaInput.Rows[i].Cells[1].Value = curWaParas[i].ParaValue.ToString();
                    }

                    app.Quit();
                    app = null;
                }

                catch (Exception err)
                {
                    MessageBox.Show("导入Excel出错!错误原因:" + err.Message, "提示信息",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            XLog.Write("从文件\"" + dialog.FileName + "\"导入参数值成功!");
        }
Exemple #17
0
 public WeightArithmeticManageForm(MainForm form)
 {
     InitializeComponent();
     mainForm = form;
     WeightParameter.ResetWeightParameterList();
 }
        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;
        }