示例#1
0
        static public List <Dictionary <string, string> > GetArithmeticItems()
        {
            List <Dictionary <string, string> > waItem = new List <Dictionary <string, string> >();

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

            System.IO.Directory.SetCurrentDirectory(strPath);

            foreach (WeightSortData wsd in wsDataList)
            {
                Dictionary <string, string> waDict = new Dictionary <string, string>();
                waItem.Add(waDict);

                string   dirname = "weightCategory\\" + wsd.sortName;
                string[] files   = System.IO.Directory.GetFiles(dirname, "*.WEM");
                for (int i = 0; i < files.Length; ++i)
                {
                    string strname = files[i];
                    strname = strname.Substring(strname.LastIndexOf('\\') + 1);
                    strname = strname.Substring(0, strname.Length - 4);
                    waDict.Add(strname, files[i]);
                }
            }

            return(waItem);
        }
        public WeightSortEditForm(WeightSortManageForm _weightSortManage, string str_Type)
        {
            InitializeComponent();
            this.Text = "重量分类新建对话框";

            strType = str_Type;
            IntiSettingButton();
        }
示例#3
0
        public WeightSortEditForm(WeightSortManageForm _weightSortManage, string str_Type)
        {
            InitializeComponent();
            this.Text = "重量分类新建对话框";

            strType = str_Type;
            IntiSettingButton();
        }
        private void WeightArithmeticManageForm_Load(object sender, EventArgs e)
        {
            treeViewArithmeticList.ImageList = imageListTreeView;

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

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

            TreeNode rootnode1 = treeViewArithmeticList.Nodes.Add("weightCategory", "重量分类", 0, 1);

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

            if (wsDataList.Count > 0)
            {
                for (int i = 0; i < wsDataList.Count; ++i)
                {
                    TreeNode subnode = rootnode1.Nodes.Add("weightCategory\\" + wsDataList[i].sortName, wsDataList[i].sortName, 2, 3);

                    foreach (KeyValuePair <string, string> pair in waItems[i])
                    {
                        subnode.Nodes.Add(pair.Value, pair.Key, 4, 5);
                    }
                }
            }
            else
            {
                btnNew.Enabled = false;
            }

            rootnode1.ExpandAll();

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

            if (dpData == null)
            {
                return;
            }
            if (dpData.lstWeightArithmetic != null)
            {
                TreeNode rootnode2 = treeViewArithmeticList.Nodes.Add("设计结果列表", "设计结果列表", 0, 1);
                foreach (WeightArithmetic wa in dpData.lstWeightArithmetic)
                {
                    TreeNode node = rootnode2.Nodes.Add(wa.DataName, wa.DataName, 4, 5);
                    node.Tag = wa;
                }
                rootnode2.Expand();
            }
        }
        public WeightSortEditForm(WeightSortManageForm _weightSortManage, WeightSortData _weightSort, string str_Type)
        {
            InitializeComponent();
            weightSort = _weightSort;
            strType = str_Type;

            btnAddNode.Text = "添加子节点(&N)";

            SetPageData();
            IntiSettingButton();
        }
示例#6
0
        public WeightSortEditForm(WeightSortManageForm _weightSortManage, WeightSortData _weightSort, string str_Type)
        {
            InitializeComponent();
            weightSort = _weightSort;
            strType    = str_Type;


            btnAddNode.Text = "添加子节点(&N)";

            SetPageData();
            IntiSettingButton();
        }
示例#7
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("导入重量算法文件错误");
            }
        }
示例#8
0
        private bool QueryWeightSort(WeightArithmetic wa)
        {
            List <WeightSortData> wsDataList = WeightSortManageForm.GetListWeightSortData(false);

            int nindex = -1;

            for (nindex = wsDataList.Count - 1; nindex >= 0; --nindex)
            {
                if (wsDataList[nindex].sortName == wa.SortName)
                {
                    break;
                }
            }

            bool bHasSort = false;
            int  nfit     = 0;

            if (nindex != -1)
            {
                bHasSort = true;

                if (wa.MatchWeightSort(wsDataList[nindex], false))
                {
                    nfit = 1;
                }
            }
            if (nfit == 0)
            {
                for (int i = 0; i < wsDataList.Count; ++i)
                {
                    if (i == nindex)
                    {
                        continue;
                    }

                    if (wa.MatchWeightSort(wsDataList[i], false))
                    {
                        string       Message = bHasSort ? ("算法文件未能和分类\"" + wa.SortName + "\"匹配,但和分类\"") : ("分类\"" + wa.SortName + "\"不存在,但算法文件和分类\"");
                        DialogResult dr      = MessageBox.Show(Message + wsDataList[i].sortName + "\"匹配。是否导入到分类\"" + wsDataList[i].sortName + "\"?", "分类不匹配", MessageBoxButtons.YesNoCancel);
                        if (dr == DialogResult.Cancel)
                        {
                            return(false);
                        }
                        else if (dr == DialogResult.Yes)
                        {
                            wa.SortName = wsDataList[i].sortName;
                            nindex      = i;
                            nfit        = 2;
                            break;
                        }
                        else
                        {
                            nfit = 0;
                        }
                    }
                }

                // 0 建分类
                // 1 符合
                // 2 在其它分类找到

                if (nfit == 0)
                {
                    DialogResult dr = MessageBox.Show("算法未找到匹配分类,是否新建分类?", "是否建分类", MessageBoxButtons.YesNo);
                    if (dr != DialogResult.Yes)
                    {
                        return(false);
                    }
                    // 建分类

                    if (bHasSort)
                    {
                        string strmsg    = "请输入分类名称";
                        bool   bcontinue = true;
                        while (bcontinue)
                        {
                            string sortname = Microsoft.VisualBasic.Interaction.InputBox(strmsg, "输入名称", wa.SortName, -1, -1);
                            sortname = sortname.Trim();
                            if (sortname == "")
                            {
                                return(false);
                            }
                            bcontinue = false;
                            foreach (WeightSortData wsditem in wsDataList)
                            {
                                if (wsditem.sortName == sortname)
                                {
                                    bcontinue = true;
                                    strmsg    = "分类\"" + sortname + "\"已存在!\r\n请重新输入分类名称";
                                }
                            }
                            if (!bcontinue)
                            {
                                wa.SortName = sortname;
                            }
                        }
                    }

                    WeightSortData wsd = wa.MakeNewWeightSort();
                    if (!WeightSortManageForm.SaveHccFile(wsd, false))
                    {
                        return(false);
                    }
                    wsDataList.Add(wsd);

                    treeViewArithmeticList.Nodes[0].Nodes.Add("weightCategory\\" + wa.SortName, wa.SortName, 2, 3);
                }
            }

            return(true);
        }
        private void comboBoxWeightSort_SelectedIndexChanged(object sender, EventArgs e)
        {
            int nwsort = comboBoxWeightSort.SelectedIndex;

            if (nwsort == -1)
            {
                return;
            }
            List <WeightSortData> wsDataList = WeightSortManageForm.GetListWeightSortData();

            WeightSortEditForm.BindTreeList(treeViewWeightSortNode, wsDataList[nwsort]);

            List <TreeNode> FinalNodes = new List <TreeNode>();

            foreach (TreeNode node in treeViewWeightSortNode.Nodes)
            {
                GetFinalNodeList(node, ref FinalNodes);
            }

            if (strType == "jynew")
            {
                waData.FormulaList.RemoveRange(mapCandidateFormula.Count, waData.FormulaList.Count - mapCandidateFormula.Count);

                foreach (KeyValuePair <WeightFormula, string> wfpair in mapCandidateFormula)
                {
                    wfpair.Key.nAttach = 0;
                    foreach (TreeNode node in FinalNodes)
                    {
                        if (node.Name == wfpair.Value)
                        {
                            wfpair.Key.nAttach = 1;
                            node.Tag           = wfpair.Key;
                            break;
                        }
                    }
                }

                listBoxCandidateFormula.Items.Clear();
                foreach (KeyValuePair <WeightFormula, string> wfpair in mapCandidateFormula)
                {
                    if (wfpair.Key.nAttach == 0)
                    {
                        listBoxCandidateFormula.Items.Add(wfpair.Value);
                    }
                }
            }
            else if (waData.FormulaList.Count > 0)
            {
                foreach (WeightFormula wf in waData.FormulaList)
                {
                    wf.nAttach = 0;
                    foreach (TreeNode node in FinalNodes)
                    {
                        if (node.Name == wf.NodePath)
                        {
                            wf.nAttach = 1;
                            node.Tag   = wf;
                            break;
                        }
                    }
                }
            }

            foreach (TreeNode node in FinalNodes)
            {
                if (node.Tag == null)
                {
                    WeightFormula wf = new WeightFormula();
                    wf.NodePath = node.Name;
                    wf.nAttach  = 1;
                    node.Tag    = wf;
                    waData.FormulaList.Add(wf);
                }
            }

            treeViewWeightSortNode.ExpandAll();
            SetEditMode(1);
            textBoxFormula.Text     = "";
            textBoxFormula.Modified = false;
            buttonEdit.Enabled      = false;
            buttonSelect.Enabled    = false;
            listViewPara.Items.Clear();
        }
        public WeightArithmeticOperForm(string str_Type, TreeNode selNode)
        {
            InitializeComponent();
            strType = str_Type;

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

            for (int i = 0; i < wsDataList.Count; ++i)
            {
                comboBoxWeightSort.Items.Add(wsDataList[i].sortName);
            }
            string wsortname = null;

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

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

                comboBoxWeightSort.Enabled = false;
                wsortname        = selNode.Parent.Text;
                txtName.Text     = waData.Name;
                txtName.ReadOnly = true;
                break;
            }

            case "jynew":
            {
                if (selNode.Tag == null)
                {
                    waData    = WeightArithmetic.ReadArithmeticData(selNode.Name);
                    wsortname = selNode.Parent.Text;
                }
                else
                {
                    WeightArithmetic tempwa = selNode.Tag as WeightArithmetic;
                    waData    = (tempwa != null) ? tempwa.Clone() : (new WeightArithmetic());
                    wsortname = waData.SortName;
                }
                dateTimePickerCreateTime.Text     = waData.CreateTime;
                dateTimePickerLastModifyTime.Text = waData.LastModifyTime;
                txtRemark.Text = waData.Remark;

                mapCandidateFormula = new Dictionary <WeightFormula, string>();
                foreach (WeightFormula wf in waData.FormulaList)
                {
                    mapCandidateFormula.Add(wf, wf.NodePath);
                }

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

            for (int i = 0; i < wsDataList.Count; ++i)
            {
                if (wsDataList[i].sortName == wsortname)
                {
                    nselindex = i;
                    break;
                }
            }
            comboBoxWeightSort.SelectedIndex = nselindex;
        }
示例#11
0
        /// <summary>
        /// 确定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            string strSortName = txtWeightSortName.Text.Trim();

            if (strSortName.Length == 0)
            {
                MessageBox.Show("重量分类名称为空!");
                return;
            }
            else
            {
                if (Verification.IsCheckString(strSortName))
                {
                    MessageBox.Show("重量分类名称含有非法字符!");
                    return;
                }
            }

            if (treeViewWeightStructure.Nodes.Count == 0)
            {
                MessageBox.Show("重量分类必须有根节点!");
                return;
            }

            WeightSortData ws = null;

            if (strType == "edit" || strType == "readOnlyEdit")
            {
                foreach (WeightSortData tempwsd in WeightSortManageForm.GetListWeightSortData())
                {
                    if (tempwsd.sortName == strSortName)
                    {
                        ws = tempwsd;
                        ws.lstWeightData.Clear();
                    }
                }
                if (ws == null)
                {
                    MessageBox.Show("未知错误!");
                    return;
                }
            }
            else
            {
                ws = new WeightSortData();
            }
            ws.sortName = strSortName;

            int nNodeID = -1;

            for (int k = 0; k < treeViewWeightStructure.Nodes.Count; k++)
            {
                TreeNode          subnode       = treeViewWeightStructure.Nodes[k];
                List <WeightData> lstWeightData = ws.lstWeightData;

                //添加根节点
                WeightData rootWeightData = new WeightData();
                rootWeightData.nID        = ++nNodeID;
                rootWeightData.weightName = subnode.Text;
                rootWeightData.strRemark  = subnode.ToolTipText;
                rootWeightData.nParentID  = -1;

                lstWeightData.Add(rootWeightData);

                WriteTreeDataToList(subnode, ref lstWeightData, ref nNodeID);
            }

            if (WeightSortManageForm.SaveHccFile(ws, strType != "edit" && strType != "readOnlyEdit"))
            {
                if (strType == "edit" || strType == "readOnlyEdit")
                {
                    XLog.Write("编辑重量分类成功");
                }
                else
                {
                    if (strType == "new")
                    {
                        XLog.Write("新建重量分类成功");
                    }
                    if (strType == "JYNew")
                    {
                        XLog.Write("基于新建重量分类成功");
                    }
                    WeightSortManageForm.GetListWeightSortData().Add(ws);
                }
                DialogResult = DialogResult.OK;
                this.Close();
            }
        }