Пример #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            //每次搜索前都要情况其他控件
            txtDisp1.Text = String.Empty;

            txtDisp2.Text   = String.Empty;
            lblAnswer1.Text = String.Empty;
            lblAnswer2.Text = String.Empty;
            try
            {
                //获取剪切板数据
                IDataObject iData = Clipboard.GetDataObject();
                if (iData.GetDataPresent(DataFormats.Text))
                {
                    txtKeyValue.Text = ((String)iData.GetData(DataFormats.Text)).Trim();
                }
                //查找满足关键词的题目
                var models = list.Where(n => n.ProbText.Contains(txtKeyValue.Text)).ToList();
                //最多只显示2个包括选择关键词的题目
                if (models.Count == 1)
                {
                    lblTypeName1.Text = models[0].TypeName;
                    lblAnswer1.Text   = String.IsNullOrEmpty(models[0].Answer) ? "题目寻找答案" : models[0].Answer;
                    string s = models[0].ProbText;
                    s             = RemovedAnswer.getStr(models[0].TypeName, s);
                    txtDisp1.Text = models[0].ProbText;
                    txtDisp1.Text = s;
                }
                if (models.Count >= 2)
                {
                    lblTypeName1.Text = models[0].TypeName;
                    lblAnswer1.Text   = String.IsNullOrEmpty(models[0].Answer) ? "题目寻找答案" : models[0].Answer;
                    txtDisp1.Text     = models[0].ProbText;

                    lblTypeName2.Text = models[1].TypeName;
                    lblAnswer2.Text   = String.IsNullOrEmpty(models[1].Answer) ? "题目寻找答案" : models[1].Answer;
                    txtDisp2.Text     = models[1].ProbText;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("出现错误,重启后再试!");
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (conn = new SQLiteConnection(@"Data Source=E:\源码\题库\ExamSystem-master\bin\Debug\QB.db"))
                {
                    conn.Open();
                    if (conn.State == ConnectionState.Open)
                    {
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }



            int count = 0;
            //获取题目类型
            var typeName = comboBox1.Text.Trim();

            using (var db = new LiteDatabase(@"Prob.db"))
            {
                var col = db.GetCollection <Problem>("Problem");
                //先换行分割
                var     prolist = textBox1.Text.Trim().Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                Problem model;
                Int32   index = 0;
                //题目列表,多行的每次读最后一个
                List <Problem> modelList = new List <Problem>();
                //根据每行的第一个字符和、号进行区分,如果不是新题目,就作为选项添加到上一个题目中去
                while (index < prolist.Length)
                {
                    var item = prolist[index];
                    if (String.IsNullOrEmpty(item))
                    {
                        continue;
                    }
                    var titles = item.Trim().Split('、');
                    if (titles.Length > 0)
                    {
                        int number;
                        if (Int32.TryParse(titles[0], out number))
                        {                                   //是数字,添加
                            model          = new Problem(); //如果分割第1个是数字,则说明是1个新的题目
                            model.ProbId   = number;
                            model.ProbText = RemovedAnswer.getStr(typeName, item);
                            //model.ProbText = item;
                            model.TypeName = typeName;
                            //确定答案,答案在()里面,把括号里面是字符串分解并组合
                            var ans = item.Split('(', ')');
                            if (ans.Length < 2)
                            {
                                model.Answer = string.Empty;
                            }
                            if (ans.Length > 1)
                            {
                                model.Answer = ans[1];
                            }
                            if (ans.Length > 3)
                            {
                                model.Answer = ans[1] + "\r\n" + ans[3];
                            }
                            modelList.Add(model);
                        }
                        else
                        {
                            //不是数字,就添加到前一个实体中去,并更新题目内容
                            modelList.Last().ProbText += ("\r\n" + item);
                        }
                    }
                    else
                    {
                        //不是数字,就添加到前一个实体中去,并更新题目内容
                        modelList.Last().ProbText += ("\r\n" + item);
                    }
                    index++;
                }
                col.InsertBulk(modelList);
                count = modelList.Count;
            }
            MessageBox.Show("导入完成,共导入" + count + "道题,重启软件后生效!");
        }