private void cmbWeightMethod_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!bEditProject)
     {
         string itemkey = (string)cmbWeightMethod.SelectedItem;
         curWa = CoreEnvelopeArithmetic.ReadArithmeticData(waItems[itemkey]);
     }
     OnCurWaChanged();
 }
        public CoreEnvelopeArithmeticOperForm(string str_Type, TreeNode selNode)
        {
            InitializeComponent();
            strType = str_Type;

            switch (strType)
            {
            case "new":
            {
                txtName.ReadOnly = false;
                txtName.Text     = "新建算法";
                break;
            }

            case "edit":
            {
                waData      = CoreEnvelopeArithmetic.ReadArithmeticData(selNode.Name);
                FormulaBase = waData.FormulaList.Count;
                dateTimePickerCreateTime.Text     = waData.CreateTime;
                dateTimePickerLastModifyTime.Text = waData.LastModifyTime;
                txtRemark.Text = waData.Remark;

                txtName.Text     = waData.Name;
                txtName.ReadOnly = true;
                break;
            }

            case "jynew":
            {
                if (selNode.Tag == null)
                {
                    waData = CoreEnvelopeArithmetic.ReadArithmeticData(selNode.Name);
                }
                else
                {
                    CoreEnvelopeArithmetic tempwa = selNode.Tag as CoreEnvelopeArithmetic;
                    waData = (tempwa != null) ? tempwa.Clone() : (new CoreEnvelopeArithmetic());
                }

                FormulaBase = waData.FormulaList.Count;
                dateTimePickerCreateTime.Text     = waData.CreateTime;
                dateTimePickerLastModifyTime.Text = waData.LastModifyTime;
                txtRemark.Text = waData.Remark;

                txtName.Text     = waData.Name + " 副本";
                txtName.ReadOnly = false;
                break;
            }
            }

            foreach (NodeFormula nf in waData.FormulaList)
            {
                TreeNode node = treeViewWeightSortNode.Nodes[0].Nodes.Add(nf.NodeName, nf.NodeName);
                node.Tag = nf;
            }
            treeViewWeightSortNode.ExpandAll();
        }
        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog();
                dlg.RestoreDirectory = true;
                dlg.Filter           = "Mcem files (*.mcem)|*.mcem";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                CoreEnvelopeArithmetic cea = CoreEnvelopeArithmetic.ReadArithmeticData(dlg.FileName);;
                if (cea == null)
                {
                    return;
                }

                bool boverwrite = false;

                TreeNode node = treeViewArithmeticList.Nodes[0];

                while (true)
                {
                    bool binclude = false;
                    foreach (TreeNode subnode in node.Nodes)
                    {
                        if (subnode.Text == cea.Name)
                        {
                            binclude = true;
                            break;
                        }
                    }
                    if (binclude)
                    {
                        DialogResult dr = MessageBox.Show("已有该算法,是否重命名?\r\n选\"否\"的话将覆盖现有算法。\r\n选\"取消\"则停止导入。", "该算法已存在", MessageBoxButtons.YesNoCancel);
                        if (dr == DialogResult.Yes)
                        {
                            string sortname = Microsoft.VisualBasic.Interaction.InputBox("请输入新的算法名称:", "输入新的算法名称", cea.Name, -1, -1);
                            sortname = sortname.Trim();
                            if (sortname == "")
                            {
                                return;
                            }

                            cea.Name = sortname;
                        }
                        else if (dr == DialogResult.Cancel)
                        {
                            return;
                        }
                        else
                        {
                            boverwrite = true;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }


                if (CoreEnvelopeArithmeticOperForm.WriteArithmeticFile(cea, false))
                {
                    if (!boverwrite)
                    {
                        node.Nodes.Add("CenterofGravityEnvelopeMethod\\" + cea.Name + ".mcem", cea.Name, 4, 5);
                    }
                }

                XCommon.XLog.Write("成功导入算法\"" + cea.Name + "\"!");
            }
            catch (Exception ex)
            {
                XCommon.XLog.Write("导入重心包线算法文件错误." + ex.Message);
            }
        }