public CoreEnvelopeDesignForm(MainForm main_Form, CoreEnvelopeArithmetic _coreEnvelope)
        {
            InitializeComponent();
            dataGridViewParaInput.Columns[1].ValueType = System.Type.GetType("System.Decimal");

            mainForm = main_Form;
            curWa = _coreEnvelope;
        }
        public CoreEnvelopeDesignForm(MainForm main_Form, CoreEnvelopeArithmetic _coreEnvelope)
        {
            InitializeComponent();
            dataGridViewParaInput.Columns[1].ValueType = System.Type.GetType("System.Decimal");

            mainForm = main_Form;
            curWa    = _coreEnvelope;
        }
 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();
        }
        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();
        }
        /// <summary>
        /// 导出重心包线设计结果到SyswareDataObject.xml
        /// </summary>
        /// <param name="coreEnvelope"></param>
        /// <param name="isAddChildren"></param>
        /// <returns></returns>
        public static string saveCoreEnvelopeDesignDataObjectToXml(CoreEnvelopeArithmetic coreEnvelope, bool isAddChildren)
        {
            string path = null;

            try
            {
                SyswareDataObject sdo    = new SyswareDataObject();
                SyswareDataObject subSdo = new SyswareDataObject();

                foreach (NodeFormula n in coreEnvelope.FormulaList)
                {
                    SyswareDataObject nSdo = new SyswareDataObject();
                    nSdo.name = n.NodeName;
                    SyswareDataObject xSdo = new SyswareDataObject();
                    xSdo.name  = n.XFormula.NodePath;
                    xSdo.value = Math.Round(Convert.ToDouble(n.XFormula.Value), 6).ToString();
                    xSdo.unit  = "Millimeter";
                    nSdo.children.Add(xSdo);
                    SyswareDataObject ySdo = new SyswareDataObject();
                    ySdo.name  = n.YFormula.NodePath;
                    ySdo.value = Math.Round(Convert.ToDouble(n.YFormula.Value), 6).ToString();
                    ySdo.unit  = "Kilogram";

                    nSdo.children.Add(ySdo);

                    subSdo.children.Add(nSdo);
                }

                if (isAddChildren)
                {
                    subSdo.name = coreEnvelope.DataName;
                    sdo         = subSdo;
                }
                else
                {
                    sdo.name    = "重心包线设计结果";
                    subSdo.name = coreEnvelope.DataName;
                    sdo.children.Add(subSdo);
                }


                XmlDocument myXmlDoc = saveSyswareDataObjectToXML(null, null, sdo);
                path = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName() + ".xml";
                //将xml文件保存到临时路径下
                myXmlDoc.Save(path);
            }
            catch
            {
                //XLog.Write("无法保存重量设计XML." + e.Message);
                return(null);
            }

            return(path);
        }
 private void cmbWeightMethod_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!bEditProject)
     {
         string itemkey = (string)cmbWeightMethod.SelectedItem;
         curWa = CoreEnvelopeArithmetic.ReadArithmeticData(waItems[itemkey]);
     }
     OnCurWaChanged();
 }
        private void btnExport_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();
            dlg.FileName = selNode.Text;

            CoreEnvelopeArithmetic wa = null;

            if (selNode.Tag != null)
            {
                wa           = selNode.Tag as CoreEnvelopeArithmetic;
                dlg.FileName = wa.Name;
            }

            dlg.OverwritePrompt = false;
            dlg.DefaultExt      = "mcem";
            dlg.Filter          = "Mcem files (*.mcem)|*.mcem";
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            //从本地导出
            if (selNode.Tag == null)
            {
                if (selNode.Name != dlg.FileName)
                {
                    string strSourcefile = System.AppDomain.CurrentDomain.BaseDirectory + selNode.Name;
                    try
                    {
                        if (File.Exists(dlg.FileName))
                        {
                            if (MessageBox.Show("文件\"" + dlg.FileName + "\"已存在,是否覆盖?", "文件已存在", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                System.IO.File.Copy(strSourcefile, dlg.FileName, true);
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            System.IO.File.Copy(strSourcefile, dlg.FileName, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
            }
            else
            {
                if (!wa.WriteArithmeticFile(dlg.FileName, true))
                {
                    return;
                }
            }

            if (selNode != null)
            {
                //int index = selNode.Name.LastIndexOf("\\");
                //string strSFName = index == -1 ? string.Empty : selNode.Name.Substring(index + 1, selNode.Name.Length - index - 1);

                //int index1 = strSFName.LastIndexOf(".");
                //string strName = index1 == -1 ? string.Empty : strSFName.Substring(0, index1);


                XCommon.XLog.Write("成功导出算法到文件\"" + dlg.FileName + "\"!");
            }
        }
        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);
            }
        }
        static public bool WriteArithmeticFile(CoreEnvelopeArithmetic wa, bool bOverWritePrompt)
        {
            string filepath = "CenterofGravityEnvelopeMethod\\" + wa.Name + ".mcem";

            return(wa.WriteArithmeticFile(filepath, bOverWritePrompt));
        }
        public static bool WriteArithmeticFile(CoreEnvelopeArithmetic wa, bool bOverWritePrompt)
        {
            string filepath = "CenterofGravityEnvelopeMethod\\" + wa.Name + ".mcem";

            return wa.WriteArithmeticFile(filepath, bOverWritePrompt);
        }