示例#1
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);
        }
示例#2
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();
            }
        }