Пример #1
0
        // 为输入的分类与匹配简表短分类号
        private void Match(string outputStyle)
        {
            this.bStop = false;

            if (this.ClassList.Count == 0)
            {
                MessageBox.Show(this, "尚未加载简表");
                return;
            }

            DateTime startTime = DateTime.Now;

            this.textBox_result.Text = "";
            string[] lines = Form_Class.GetLines(this.textBox_inputClass.Text.Trim());

            int totalCount = lines.Length;

            this.toolStripProgressBar1.Maximum = totalCount;
            this.toolStripProgressBar1.Minimum = 0;
            int count = 0;

            foreach (string line in lines)
            {
                if (bStop == true)
                {
                    MessageBox.Show(this, "用户中断,当前处理到第" + count + "个");
                    break;
                }

                count++;
                this.toolStripProgressBar1.Value = count;
                this.toolStripStatusLabel1.Text  = count.ToString() + "/" + totalCount;
                ClassItem classItem  = null;
                string    outputInfo = this.SearchClass(line, outputStyle, out classItem);
                this.textBox_result.Text += outputInfo;

                // 出让控制权
                Application.DoEvents();
            }

            TimeSpan timeLength = DateTime.Now - startTime;

            this.toolStripStatusLabel1.Text += "共用时" + timeLength.TotalSeconds.ToString();
        }
Пример #2
0
        // 加载简表到内存
        private bool LoadClassTable(string fileName, out string error)
        {
            error = "";
            this.ClassList.Clear();


            if (File.Exists(fileName) == false)
            {
                error = "简表文件[" + fileName + "]不存在";
                return(false);
            }

            StringBuilder sb = new StringBuilder();
            // 将简表文件读到内存,要求txt文件排过序
            int i = 0;

            using (StreamReader sr = new StreamReader(fileName, Encoding.Default))
            {
                while (!sr.EndOfStream)
                {
                    //读取一行数据
                    string line = sr.ReadLine().Trim();
                    i++;
                    if (line == "")
                    {
                        sb.AppendLine("第" + i.ToString() + "行为空");
                        continue;
                    }

                    // 按tab键拆分
                    string[] infos = line.Split(new char[] { '\t' });
                    if (infos.Length < 4)
                    {
                        sb.AppendLine("第" + i.ToString() + "行[" + line + "],不足4个字段\r\n");
                        continue;
                    }
                    ClassItem item = new ClassItem();
                    item.Class = infos[0].Trim();
                    if (item.Class == "")
                    {
                        sb.AppendLine("第" + i.ToString() + "行的分类号为空");
                        continue;
                    }

                    item.Name = infos[1].Trim();
                    if (item.Class == "")
                    {
                        sb.AppendLine("第" + i.ToString() + "行的名称为空");
                    }

                    item.Level = -1;
                    item.Level = Convert.ToInt32(infos[2]);
                    if (item.Level == -1)
                    {
                        sb.AppendLine("第" + i.ToString() + "行的级别为空");
                    }

                    item.No    = Convert.ToInt32(infos[3]);
                    item.Count = 0;

                    // 加到集合里
                    this.ClassList.Add(item);
                }
            }

            // 错误信息
            error = sb.ToString();
            if (error != "")
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        // 输入一个分类号,匹配简表对应分类号
        private string SearchClass(string inputClass,
                                   string outputStyle,
                                   out ClassItem classItem)
        {
            classItem = null;

            Debug.Assert(String.IsNullOrEmpty(inputClass) == false, "输入的分类号不能为空");
            StringBuilder sb = new StringBuilder();

            if (outputStyle == C_OutputStyle_Detail)
            {
                sb.AppendLine("=查询[" + inputClass + "]开始=");
            }

            string thisClass = inputClass;
            bool   bFound    = false;

            while (thisClass != "")
            {
                classItem = this.SearchOneClass(thisClass);
                if (classItem != null)
                {
                    string remark = "";
                    if (thisClass.Length == inputClass.Length)
                    {
                        remark = "等";
                    }
                    else
                    {
                        remark = "短";
                    }

                    if (outputStyle == C_OutputStyle_Detail)
                    {
                        sb.AppendLine("[" + thisClass + "]找到了");
                    }
                    else if (outputStyle == C_OutputStyle_Simple)
                    {
                        sb.AppendLine(inputClass + "\t" + thisClass + "\t" + remark);
                    }
                    else if (outputStyle == C_OutputStyle_File)
                    {
                        Write2File(inputClass + "\t" + thisClass + "\t" + remark + "\r\n");
                    }

                    // 标记找到了
                    bFound = true;

                    break;
                }
                if (outputStyle == C_OutputStyle_Detail)
                {
                    sb.AppendLine("[" + thisClass + "]未找到");
                }

                thisClass = thisClass.Substring(0, thisClass.Length - 1);
            }

            if (bFound == false)
            {
                string remark = "未找到";
                if (outputStyle == C_OutputStyle_Simple) //详细格式已经输入了信息
                {
                    sb.AppendLine(inputClass + "\t" + remark);
                }
                else if (outputStyle == C_OutputStyle_File)
                {
                    Write2File(inputClass + "\t" + remark + "\r\n");
                }
            }


            if (outputStyle == C_OutputStyle_Detail)
            {
                sb.AppendLine("结束");
                sb.AppendLine();
            }
            return(sb.ToString());
        }