Esempio n. 1
0
        public void init_kemu2(string kemu)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("科目拼音");
            dt.Columns.Add("科目名称");

            using (StreamReader sr = new StreamReader("科目.txt", Encoding.Default))
            {
                while (!sr.EndOfStream)
                {
                    string[] line = sr.ReadLine().Trim().Trim(new char[] { '|', '\r', '\n', '\t', ' ' }).Split('|');
                    if (line.Length < 2 || line[0].Trim() != kemu || dt.Select("科目名称='" + line[0].Trim() + "'").Length > 0)
                    {
                        continue;
                    }

                    DataRow dr = dt.NewRow();
                    dr["科目拼音"] = PingYinHelper.GetFirstSpell(line[1].Trim()).ToLowerInvariant();
                    dr["科目名称"] = line[1].Trim();
                    dt.Rows.Add(dr);
                }
            }

            myComboBox2.ColumnsWidth = new string[] { "1", "120" };
            myComboBox2.dtSource     = dt;
        }
Esempio n. 2
0
        public void init_kemu()
        {
            if (this.InvokeRequired)
            {
                dele_init _init = new dele_init(init_kemu);
                this.Invoke(_init);
            }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("科目拼音");
                dt.Columns.Add("科目名称");

                using (FileStream fs = new FileStream("科目.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(fs, Encoding.Default))
                    {
                        while (!sr.EndOfStream)
                        {
                            string[] line = sr.ReadLine().Trim().Trim(new char[] { '|', '\r', '\n', '\t', ' ' }).Split('|');
                            if (line.Length < 2 || dt.Select("科目名称='" + line[0].Trim() + "'").Length > 0)
                            {
                                continue;
                            }

                            DataRow dr = dt.NewRow();
                            dr["科目拼音"] = PingYinHelper.GetFirstSpell(line[0].Trim()).ToLowerInvariant();
                            dr["科目名称"] = line[0].Trim();
                            dt.Rows.Add(dr);
                        }
                    }
                }


                myComboBox1.ColumnsWidth = new string[] { "1", "120" };
                myComboBox1.dtSource     = dt;
            }
        }