Exemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length != 1)
     {
         MessageBox.Show("分割字符必須為恰好一個字");
         textBox1.Focus();
         return;
     }
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         string   path      = openFileDialog1.FileName;
         string   text      = File.ReadAllText(path);
         string[] lineArray = text.Replace("\r", "").Split('\n');
         listBox1.Items.Clear();
         for (int i = 0; i < lineArray.Length; i++)
         {
             string   line  = lineArray[i];
             string[] s     = line.Split(textBox1.Text[0]);
             QandA    qAndA = new QandA();
             qAndA.q = s[0];
             qAndA.a = s[1];
             listBox1.Items.Add(qAndA);
         }
         //listBox1.Items.AddRange(lineArray);
     }
 }
Exemplo n.º 2
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (UserLibrary.nowUserLibrary != null)
     {
         for (int i = 0; i < listBox1.Items.Count; i++)
         {
             QandA item = listBox1.Items[i] as QandA;
             UserLibrary.nowUserLibrary.qAndAList.Add(item);
         }
         UserLibrary.nowUserLibrary.save();
         MessageBox.Show("匯入了" + listBox1.Items.Count + "個到" + UserLibrary.nowUserLibrary.userName + "的庫");
     }
 }
Exemplo n.º 3
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (UserLibrary.nowUserLibrary != null)
     {
         int del = 0;
         for (int i = 0; i < listBox1.Items.Count; i++)
         {
             QandA item = listBox1.Items[i] as QandA;
             for (int j = 0; j < UserLibrary.nowUserLibrary.qAndAList.Count; j++)
             {
                 QandA qandA2 = UserLibrary.nowUserLibrary.qAndAList[j];
                 if (qandA2.q == item.q)
                 {
                     del++;
                     UserLibrary.nowUserLibrary.qAndAList.RemoveAt(j);
                     break;
                 }
             }
         }
         UserLibrary.nowUserLibrary.save();
         MessageBox.Show("刪除了" + del + "個在" + UserLibrary.nowUserLibrary.userName + "的庫");
     }
 }