Exemplo n.º 1
0
 public void AppEnable(object sender, CQAppEnableEventArgs e)
 {
     if (File.Exists(e.CQApi.AppDirectory + "data.db") == false)
     {
         File.WriteAllBytes(e.CQApi.AppDirectory + "data.db", Properties.Resources.data);
     }
     PoemData.Init();
 }
 public void ClickAddExecute()
 {
     PoemData.AddData(new PoemData
     {
         Key   = this.Key,
         Verse = this.Verse,
         Info  = this.Info
     });
     Datas = new ObservableCollection <PoemData>(PoemData.pd);
     MessageBox.Show("添加成功!");
 }
        public void ClickDelExecute(object parameter)
        {
            Common.CQLog.Debug("", parameter.GetType().ToString());
            if (parameter.GetType() != typeof(PoemData))
            {
                return;
            }
            PoemData p = parameter as PoemData;

            PoemData.DelData(p);
            Datas = new ObservableCollection <PoemData>(PoemData.pd);
            MessageBox.Show("删除成功!");
        }
Exemplo n.º 4
0
        public void ClickImportExecute()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = false;//该值确定是否可以选择多个文件
            dialog.Title       = "请选择文件";
            dialog.Filter      = "词库(*.db)|*.db";
            string file = string.Empty;

            if (dialog.ShowDialog() == true)
            {
                file = dialog.FileName;
            }
            if (file == string.Empty)
            {
                MessageBox.Show("未选择文件!");
                return;
            }

            try
            {
                Info.BtnVisibility  = Visibility.Hidden;
                Info.TipsVisibility = Visibility.Visible;
                Thread tImport = new Thread(new ThreadStart(() =>
                {
                    SQLiteConnection conn = new SQLiteConnection($"data source={file};");
                    conn.Open();
                    SQLiteDataAdapter adapter = new SQLiteDataAdapter(new SQLiteCommand("Select * from Poem where 1=1", conn));
                    DataSet set = new DataSet();
                    adapter.Fill(set, "Poem");
                    int affected = PoemData.ImportData(set, Info);
                    set.Dispose();
                    adapter.Dispose();
                    conn.Dispose();
                    Info.BtnVisibility  = Visibility.Visible;
                    Info.TipsVisibility = Visibility.Hidden;
                    MessageBox.Show($"导入成功!共导入{affected}条诗句!");
                }));
                tImport.Start();
            }
            catch
            {
                MessageBox.Show("导入错误!不是正确词库!");
                Info.BtnVisibility  = Visibility.Visible;
                Info.TipsVisibility = Visibility.Hidden;
            }
        }