当前位置:文档之家› 简单题库管理系统设计

简单题库管理系统设计

简单题库管理系统设计一1. 数据库dxjsj.mdb 结构(由9张表组成)2. 表结构(这里列出选择题、填充题、知识点3张表)3. 数据存放目录结构4.管理程序菜单功能标准答案文件夹存放数据库的文件夹设计操作题素材文件夹OS 操作题素材文件夹操作结果样例文件夹试题维护包括不同题型的处理界面知识点、OS操作类型、设计操作类型处理界面(1)设计涉及到多个窗体,需要通过下图所示操作加入新窗体,结果如右图所示。

添加新窗体结果(需要修改窗体文件名)其中,testm为主窗体(设计时第一个建立的窗体),应用程序的主入口,提供菜单功能,菜单建立使用menuStrip控件。

(2) 窗体的打开(以单选题为例)Form fdxt = new fdxt();fdxt.MdiParent = this; //作为主窗体testm的子窗体fdxt.Show();窗体的关闭使用命令:this.Close();注意:应用程序的关闭退出使用命令:Application.Exit();(3) 窗体之间共用的变量先定义一个private/public的类,然后在类中声明一个static public属性的变量,可以在类中初始化或第一次使用之前初始化。

使用“类名.变量名”形式引用。

根据本例的数据存放目录结构,需要获得程序的运行路径,可在主窗体testm的外面定义一个类,本例的类名为mv,如下所示。

namespace jsjtest{public partial class testm : Form{主窗体testm中的代码}定义一个窗体之间共用的变量mpathpublic class mv{public static string mpath = Application.StartupPath; //获得程序的运行路径}}在其他窗体内使用变量mpath的方法:string connStr = "Provider = Microsoft.Jet.OleDB.4.0;Data Source=" + mv.mpath + "\\db\\dxjsj.mdb";5. 具体设计:(1)新建一个解决方案jsjtest.sln,将Form1窗体命名为testm,使用menuStrip控件建立菜单。

需要引用using System.Data.OleDb;(2)添加新窗体,命名为zsd,用于知识点的数据管理。

设置窗体标题为“知识点设置”。

按图所示,在知识点窗体添加网格控件,文本框,命令按钮、标签等,其中用于导航,label4显示记录号。

设置网格的AutoSizeColumnMode属性为Fill,可调整列宽。

在知识点窗体也需要引用using System.Data.OleDb;声明全局变量:string connStr = "Provider = Microsoft.Jet.OleDB.4.0;Data Source=" + mv.mpath +"\\db\\dxjsj.mdb";OleDbConnection conn; // 连接对象OleDbDataAdapter da ; // 适配器对象DataSet ds = new DataSet(); // 数据集对象BindingManagerBase bind; // 绑定管理对象string strSql = "Select 题号,章号,章,标志From 知识点";int sp;编写一个显示当前页面的子过程:private void getPage() // 获取当前页码{label4.Text = (bind.Position + 1) + "/" + bind.Count;dataGridView1.Rows[bind.Position].Selected = true;dataGridView1.CurrentCell = dataGridView1.Rows[bind.Position].Cells[0];//行头的小三角 dataGridView1.FirstDisplayedScrollingRowIndex = bind.Position;}在private void zsd_Load(object sender, EventArgs e)中完成数据连接和绑定:conn = new OleDbConnection(connStr); // 创建一个数据连接conn.Open();da = new OleDbDataAdapter(strSql, conn); // 配置适配器da.Fill(ds, "知识点"); // 填充ds对象conn.Close();bind = this.BindingContext[ds, "知识点"]; //导航绑定dataGridView1.DataSource = ds.Tables["知识点"];; //网格绑定dataGridView1.Columns[0].FillWeight = 10; //第1列的相对宽度为%dataGridView1.Columns[1].FillWeight =15; //第2列的相对宽度为%dataGridView1.Columns[2].FillWeight = 60; //第3列的相对宽度为%dataGridView1.Columns[3].FillWeight = 15; //第4列的相对宽度为%dataGridView1.Columns[0].HeaderText = "序号"; //给每列设置标头dataGridView1.Columns[1].HeaderText = "章节编号";dataGridView1.Columns[2].HeaderText = "章节标题";dataGridView1.Columns[3].HeaderText = "章节标志";dataGridView1.Rows[0].Selected=true ;textBox1.DataBindings.Add(new Binding("Text", ds, "知识点.章号")); //文本框绑定textBox2.DataBindings.Add(new Binding("Text", ds, "知识点.章"));textBox3.DataBindings.Add(new Binding("Text", ds, "知识点.标志"));if (ds.Tables["知识点"].Rows.Count == 0)button5_Click(sender, e);elsebutton1_Click(sender, e);为导航添加代码:private void button1_Click(object sender, EventArgs e){bind.Position = 0; getPage();}private void button2_Click(object sender, EventArgs e){bind.Position -= 1; getPage();}private void button3_Click(object sender, EventArgs e){bind.Position += 1; getPage();}private void button4_Click(object sender, EventArgs e){bind.Position = bind.Count - 1; getPage();}增、删、改设计private void button5_Click(object sender, EventArgs e){if (button5.Text == "添加") // 进入添加模式{button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; button5.Text = "确认"; button6.Enabled = false; button7.Enabled = false; button8.Enabled = true; button9.Enabled = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = "";sp = bind.Position;}else{if (textBox1.Text=="" || textBox2.Text=="" || textBox3.Text==""){MessageBox.Show("缺少知识点数据!");return;}conn.Open();strSql = "Insert Into 知识点(章号,章,标志) Values(@zhangh, @zhang, @zhbz)";OleDbCommand cmd = new OleDbCommand(strSql, conn);//操作命令cmd.Parameters.AddWithValue("@zhangh", textBox1.Text);cmd.Parameters.AddWithValue("@zhang", textBox2.Text);cmd.Parameters.AddWithValue("@zhbz", textBox3.Text);try{cmd.ExecuteNonQuery();ds.Clear();da.Fill(ds, "知识点"); //填充ds对象bind.Position = this.BindingContext[ds, "知识点"].Count - 1;MessageBox.Show("成功添加知识点" + textBox2.Text + "!");}catch{MessageBox.Show("知识点添加失败!\n\n请重试!");}conn.Close();getPage();button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button5.Text = "添加"; button6.Enabled = true; button7.Enabled = true; button8.Enabled = false; button9.Enabled = true; }}private void button6_Click(object sender, EventArgs e){DialogResult dr = MessageBox.Show("确定要删除当前记录(" + (bind.Position + 1) + ")?", "注意:", MessageBoxButtons.OKCancel);if (dr == DialogResult.OK) // 确定要更新{conn.Open();int k = bind.Position;int th = Convert.ToInt32(ds.Tables["知识点"].Rows[k]["题号"]);strSql = "Delete From 知识点Where 题号=" + th;OleDbCommand cmd = new OleDbCommand(strSql, conn);//操作命令cmd.ExecuteNonQuery(); // 删除数据库当前行:ds.Clear();da.Fill(ds, "知识点"); //填充ds对象if (k < bind.Count)bind.Position = k;elsebind.Position = this.BindingContext[ds, "知识点"].Count - 1;conn.Close();getPage();}}private void button7_Click(object sender, EventArgs e){conn.Open();int k = bind.Position;int th = Convert.ToInt16(ds.Tables["知识点"].Rows[k]["题号"]);strSql = "UPDATE 知识点Set 章号=@zhangh,章=@zhang,标志=@zhbz Where 题号=@xth";OleDbCommand cmd = new OleDbCommand(strSql, conn);//操作命令cmd.Parameters.AddWithValue("@zhangh", textBox1.Text);cmd.Parameters.AddWithValue("@zhang", textBox2.Text);cmd.Parameters.AddWithValue("@zhbz", textBox3.Text);cmd.Parameters.AddWithValue("@xth", th);try{cmd.ExecuteNonQuery();dataGridView1.Refresh(); //刷新MessageBox.Show("当前记录(" + (bind.Position + 1) + "成功更新!");}catch{MessageBox.Show("更新失败!\n\n请重试!");}conn.Close();}private void button8_Click(object sender, EventArgs e){button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button5.Text = "添加"; button6.Enabled = true; button7.Enabled = true; button8.Enabled = false; button9.Enabled = true; ds.Clear();da.Fill(ds, "知识点"); //填充ds对象bind.Position = sp;getPage();}关闭窗口private void button9_Click(object sender, EventArgs e){this.Close();}控制输入为大写private void textBox1_TextChanged(object sender, EventArgs e){textBox1.Text = textBox1.Text.ToUpper();}控制输入为大写Y Nprivate void textBox3_TextChanged(object sender, EventArgs e){Regex reg=new Regex("^[NYny]+$");if (! reg.IsMatch(textBox3.Text))textBox3.Text ="";elsetextBox3.Text = textBox3.Text.ToUpper();}设置网格自动移屏,添加dataGridView1_CellMouseClick事件private void dataGridView1_CellMouseClick(object sender, idViewCellMouseEventArgs e){bind.Position = dataGridView1.CurrentCell.RowIndex;getPage();}(3) 与主程序的的连接进入到testm窗体,双击菜单项“知识点”。

相关主题