diff --git a/Course.Designer.cs b/Course.Designer.cs index dcb4e52..a167acb 100644 --- a/Course.Designer.cs +++ b/Course.Designer.cs @@ -35,8 +35,8 @@ private void InitializeComponent() this.button4 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); - this.label2 = new System.Windows.Forms.Label(); this.domainUpDown1 = new System.Windows.Forms.DomainUpDown(); + this.label2 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); this.SuspendLayout(); // @@ -81,6 +81,7 @@ private void InitializeComponent() this.button4.TabIndex = 0; this.button4.Text = "考试"; this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); // // label1 // @@ -102,6 +103,14 @@ private void InitializeComponent() this.panel1.Size = new System.Drawing.Size(584, 428); this.panel1.TabIndex = 2; // + // domainUpDown1 + // + this.domainUpDown1.Location = new System.Drawing.Point(33, 48); + this.domainUpDown1.Name = "domainUpDown1"; + this.domainUpDown1.Size = new System.Drawing.Size(149, 27); + this.domainUpDown1.TabIndex = 0; + this.domainUpDown1.Text = "domainUpDown1"; + // // label2 // this.label2.AutoSize = true; @@ -111,14 +120,6 @@ private void InitializeComponent() this.label2.TabIndex = 0; this.label2.Text = "目录:"; // - // domainUpDown1 - // - this.domainUpDown1.Location = new System.Drawing.Point(33, 48); - this.domainUpDown1.Name = "domainUpDown1"; - this.domainUpDown1.Size = new System.Drawing.Size(149, 27); - this.domainUpDown1.TabIndex = 0; - this.domainUpDown1.Text = "domainUpDown1"; - // // Course // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); diff --git a/Course.cs b/Course.cs index 66fefcf..dce6da6 100644 --- a/Course.cs +++ b/Course.cs @@ -5,19 +5,22 @@ using System.Drawing; using System.Text; using System.Windows.Forms; - +using System.Data.SqlClient; namespace WinFormsApp1 { public partial class Course : Form { + String coursename; public Course() { InitializeComponent(); + } public Course(String Cname) { InitializeComponent(); label1.Text = "课程:"+Cname; + coursename = Cname; } private void Course_Load(object sender, EventArgs e) @@ -27,7 +30,14 @@ private void Course_Load(object sender, EventArgs e) private void button3_Click(object sender, EventArgs e) { - + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + string sql = "select COURSE_ID from COURSES where COURSES_NAME = '" + coursename + "'"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + int a = (int)com.ExecuteScalar(); + DatabaseDesign.Work wk = new DatabaseDesign.Work(label1.Text, a,0); + wk.Show(); } private void button1_Click(object sender, EventArgs e) @@ -35,5 +45,17 @@ private void button1_Click(object sender, EventArgs e) DatabaseDesign.Notice nc= new DatabaseDesign.Notice(); nc.Show(); } + + private void button4_Click(object sender, EventArgs e) + { + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + string sql = "select COURSE_ID from COURSES where COURSES_NAME = '" + coursename + "'"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + int a = (int)com.ExecuteScalar(); + DatabaseDesign.Work wk = new DatabaseDesign.Work(label1.Text, a, 1); + wk.Show(); + } } } diff --git a/Form1.Designer.cs b/Notice.Designer.cs similarity index 100% rename from Form1.Designer.cs rename to Notice.Designer.cs diff --git a/Form1.cs b/Notice.cs similarity index 100% rename from Form1.cs rename to Notice.cs diff --git a/Form1.resx b/Notice.resx similarity index 100% rename from Form1.resx rename to Notice.resx diff --git a/Work.Designer.cs b/Work.Designer.cs new file mode 100644 index 0000000..4d1e17a --- /dev/null +++ b/Work.Designer.cs @@ -0,0 +1,128 @@ + +namespace DatabaseDesign +{ + partial class Work + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(282, 280); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(120, 44); + this.button1.TabIndex = 0; + this.button1.Text = "创建作业"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft YaHei UI", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(62, 53); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(87, 32); + this.label1.TabIndex = 1; + this.label1.Text = "label1"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft YaHei UI", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(234, 144); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(92, 35); + this.label2.TabIndex = 2; + this.label2.Text = "label2"; + this.label2.Click += new System.EventHandler(this.label2_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(106, 280); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(93, 29); + this.button2.TabIndex = 3; + this.button2.Text = "上一个作业"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(508, 280); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(93, 29); + this.button3.TabIndex = 4; + this.button3.Text = "下一个作业"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(73, 156); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(116, 20); + this.label3.TabIndex = 5; + this.label3.Text = "点击名称开始->"; + // + // Work + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(718, 397); + this.Controls.Add(this.label3); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Name = "Work"; + this.Text = "Work"; + this.Load += new System.EventHandler(this.Work_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label label3; + } +} \ No newline at end of file diff --git a/Work.cs b/Work.cs new file mode 100644 index 0000000..553a5a7 --- /dev/null +++ b/Work.cs @@ -0,0 +1,275 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; +namespace DatabaseDesign +{ + public partial class Work : Form + { + private string InputBox(string Caption, string Hint, string Default) + { + Form InputForm = new Form(); + InputForm.MinimizeBox = false; + InputForm.MaximizeBox = false; + InputForm.StartPosition = FormStartPosition.CenterScreen; + InputForm.Width = 250; + InputForm.Height = 190; + //InputForm.Font.Name = "宋体"; + //InputForm.Font.Size = 10; + InputForm.Text = Caption; + Label lbl = new Label(); + lbl.Text = Hint; + lbl.Left = 10; + lbl.Top = 20; + lbl.Parent = InputForm; + lbl.AutoSize = true; + TextBox tb = new TextBox(); + tb.Left = 30; + tb.Top = 45; + tb.Width = 160; + tb.Parent = InputForm; + tb.Text = Default; + tb.SelectAll(); + Button btnok = new Button(); + btnok.Left = 30; + btnok.Top = 80; + btnok.Parent = InputForm; + btnok.Text = "确定"; + InputForm.AcceptButton = btnok;//回车响应 + + btnok.DialogResult = DialogResult.OK; + Button btncancal = new Button(); + btncancal.Left = 120; + btncancal.Top = 80; + btncancal.Parent = InputForm; + btncancal.Text = "取消"; + btncancal.DialogResult = DialogResult.Cancel; + try + { + if (InputForm.ShowDialog() == DialogResult.OK) + { + return tb.Text; + } + else + { + return null; + } + } + finally + { + InputForm.Dispose(); + } + } + int is_test = 0; + int courseID; + int slt = 1; //选第一个考试/作业 + public Work() + { + InitializeComponent(); + slt = 1; + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //查询 + string sql = "select TOP 1 EXAM_NAME from EXAM where is_test=" + is_test + " order by EXAM_ID"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + String s7 = (String)com.ExecuteScalar(); + label2.Text = s7; + } + public Work(String s,int cID,int x) + { + InitializeComponent(); + is_test = x; //0 work ,1 exam + bool iden = WinFormsApp1.login.identity; + label1.Text = s; + courseID = cID; + if (iden == false) + { + button1.Enabled = false; + button1.Visible = false; + } + if(is_test==1) + { + button1.Text = "创建考试"; + button2.Text = "上一个考试"; + button3.Text = "下一个考试"; + } + if(is_test == 0) + { + button1.Text = "创建作业"; + button2.Text = "上一个作业"; + button3.Text = "下一个作业"; + } + slt = 1; + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //查询 + string sql = "select TOP 1 EXAM_NAME from EXAM where is_test="+is_test+" order by EXAM_ID"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + String s7 = (String)com.ExecuteScalar(); + label2.Text = s7; + } + private void Work_Load(object sender, EventArgs e) + { + + } + private void button1_Click(object sender, EventArgs e) + { + string s1="提示", s2="请输入要创建作业的名称:", s3=""; + string s = InputBox(s1, s2, s3); + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //找下一个examID + string sql = "select TOP 1 EXAM_ID from EXAM order by EXAM_ID desc"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + int examid = (int)com.ExecuteScalar(); + examid = examid + 1; + //插入 + string sss = "insert into EXAM(EXAM_ID,EXAM_NAME,COURSE_ID,IS_TEST,QNUM) values("+examid+",'"+s+"',"+courseID+","+is_test+","; + //输入题目 + int cnt = 1; + while (true) + { + //输入题目 + s2 = "输入第" + cnt.ToString() + "道题的题目(单选题请一起输入选项)"; + s1 = "(输入q以结束输入)"; + string qs= InputBox(s1, s2, s3); + if (String.Equals(qs, "q")) break; + //输入答案 + s2 = "输入第" + cnt.ToString() + "道题的答案(输入非ABCD即视作简答)"; + s1 = "(输入q以结束输入)"; + string ans = InputBox(s1, s2, s3); + if (String.Equals(ans, "q")) break; + //获取QID + string s6 = "select TOP 1 QID from QS order by QID desc"; + SqlCommand com2 = new SqlCommand(s6, sqlCnt); + int qid = (int)com2.ExecuteScalar(); + qid = qid + 1; + //插入题目 + string s5 = "insert into QS(QID,EXAM_ID,Q,A) values(" +qid+","+ examid + ",'" + qs + "',"; + //插入答案 + switch (ans) + { + case "A": + s5 = s5 + "1)"; + break; + case "B": + s5 = s5 + "2)"; + break; + case "C": + s5 = s5 + "3)"; + break; + case "D": + s5 = s5 + "4)"; + break; + default: + s5 = s5 + "0)"; + break; + } + SqlCommand com1 = new SqlCommand(s5, sqlCnt); + com1.ExecuteScalar(); + cnt++; + } + cnt--; + sss = sss + cnt + ")"; + SqlCommand co = new SqlCommand(sss, sqlCnt); + co.ExecuteScalar(); + } + + private void button2_Click(object sender, EventArgs e) + { + if (slt <= 1) MessageBox.Show("没有上一条了"); + else + { + slt--; + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //查询 + string sql = "select TOP 1 EXAM_NAME from EXAM where EXAM_NAME in(select TOP "+slt+ " EXAM_NAME from EXAM where is_test="+is_test+" order by EXAM_ID) order by EXAM_ID desc"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + String s7 = (String)com.ExecuteScalar(); + label2.Text = s7; + } + } + + private void button3_Click(object sender, EventArgs e) + { + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //查询 + string sql = "select COUNT(*) from EXAM where is_test="+is_test; + SqlCommand com = new SqlCommand(sql, sqlCnt); + int coun = (int)com.ExecuteScalar(); + if (slt >=coun) MessageBox.Show("没有下一条了"); + else + { + slt++; + string s8 = "select TOP 1 EXAM_NAME from EXAM where EXAM_NAME in(select TOP " + slt + " EXAM_NAME from EXAM where is_test=" + is_test + " order by EXAM_ID) order by EXAM_ID desc"; + SqlCommand co1 = new SqlCommand(s8, sqlCnt); + String s9 = (String)co1.ExecuteScalar(); + label2.Text = s9; + } + } + + private void label2_Click(object sender, EventArgs e) + { + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + string sql = "select EXAM_ID from EXAM where EXAM_NAME = '"+label2.Text+"'"; + SqlCommand com = new SqlCommand(sql, sqlCnt); + int eid= (int)com.ExecuteScalar(); + DatabaseDesign.Working wking = new DatabaseDesign.Working(eid,label1.Text,label2.Text,is_test); + wking.Show(); + } + } + +} + + +public class FilesSelectDialog +{ + public OpenFileDialog fileDialog; + //默认打开路径 + public string DirPath = "C:\\"; + public string FilePath; + public string Title; + public FilesSelectDialog(string title) + { + Title = title; + fileDialog = new OpenFileDialog();//打开文件对话框 + } + public bool Show() + { + fileDialog.InitialDirectory = DirPath;//初始化路径 + fileDialog.FilterIndex = 0;//当前使用第二个过滤字符串 + fileDialog.RestoreDirectory = true;//对话框关闭时恢复原目录 + fileDialog.Title = Title; + if (fileDialog.ShowDialog() == DialogResult.OK) + { + + FilePath = fileDialog.FileName; + try + { + DirPath = System.IO.Path.GetDirectoryName(FilePath);//更改默认路径为最近打开路径 + } + catch (Exception) + { + return false; + } + return true; + } + else + { + return false; + } + } +} \ No newline at end of file diff --git a/Work.resx b/Work.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Work.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Working.Designer.cs b/Working.Designer.cs new file mode 100644 index 0000000..09d3593 --- /dev/null +++ b/Working.Designer.cs @@ -0,0 +1,185 @@ + +namespace DatabaseDesign +{ + partial class Working + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.button3 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.button4 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(93, 358); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(93, 29); + this.button1.TabIndex = 0; + this.button1.Text = "上一题"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(614, 358); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(93, 29); + this.button2.TabIndex = 1; + this.button2.Text = "下一题"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(59, 28); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 20); + this.label1.TabIndex = 2; + this.label1.Text = "label1"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(423, 28); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 20); + this.label2.TabIndex = 3; + this.label2.Text = "label2"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft YaHei UI", 17F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label3.Location = new System.Drawing.Point(150, 136); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(101, 38); + this.label3.TabIndex = 4; + this.label3.Text = "label3"; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(344, 358); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(93, 29); + this.button3.TabIndex = 5; + this.button3.Text = "结束答题"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(206, 274); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(410, 27); + this.textBox1.TabIndex = 6; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(81, 277); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(84, 20); + this.label4.TabIndex = 7; + this.label4.Text = "你的答案:"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(59, 94); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(54, 20); + this.label5.TabIndex = 8; + this.label5.Text = "第题:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(164, 94); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(53, 20); + this.label6.TabIndex = 9; + this.label6.Text = "label6"; + // + // button4 + // + this.button4.Location = new System.Drawing.Point(637, 273); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(108, 29); + this.button4.TabIndex = 10; + this.button4.Text = "获取正确答案"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // Working + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(779, 450); + this.Controls.Add(this.button4); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.button3); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "Working"; + this.Text = "Working"; + this.Load += new System.EventHandler(this.Working_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Button button4; + } +} \ No newline at end of file diff --git a/Working.cs b/Working.cs new file mode 100644 index 0000000..fa3a5e0 --- /dev/null +++ b/Working.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using System.Data.SqlClient; +namespace DatabaseDesign +{ + public partial class Working : Form + { + int examid=0; + int qidnow=0; + int qtotal = 0; + int stl = 1; + public Working() + { + InitializeComponent(); + } + public Working(int eid,string Cname,string Ename,int is_test) + { + InitializeComponent(); + stl = 1; + examid = eid; + label1.Text = Cname; + if(is_test==0) + label2.Text = "作业名称:"+Ename; + else + label2.Text = "考试名称:"+Ename; + if(is_test==1) + { + button4.Enabled = false; + button4.Visible = false; + } + + //链接数据库 + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //读取总共多少题目 + string sql = "select count(*) from QS where EXAM_ID=" +examid; + SqlCommand com = new SqlCommand(sql, sqlCnt); + qtotal = (int)com.ExecuteScalar(); + if (qtotal == 0) + { + MessageBox.Show("本试题库为空!"); + } + else + { + //读取第一道题目stl=1 + try + { + string s8 = "select TOP 1 QID from QS where QID in(select TOP " + stl + " QID from QS where EXAM_ID=" + examid + " order by QID) order by QID desc"; + SqlCommand co1 = new SqlCommand(s8, sqlCnt); + qidnow = (int)co1.ExecuteScalar(); + string sql1 = "select Q from QS where QID=" + qidnow; + SqlCommand com1 = new SqlCommand(sql1, sqlCnt); + String ss = (String)com1.ExecuteScalar(); + label3.Text = ss; + label5.Text = "第" + stl + "题:"; + label6.Text = "题型:"; + string sql2 = "select A from QS where QID=" + qidnow; + SqlCommand com2 = new SqlCommand(sql2, sqlCnt); + int a = (int)com2.ExecuteScalar(); + if (a != 0) + label6.Text += "单项选择题"; + else + label6.Text += "简答题"; + } + catch (Exception) + { + MessageBox.Show("发生错误"); + } + } + } + private void Working_Load(object sender, EventArgs e) + { + if (qtotal == 0) + { + Close(); + } + } + + private void button4_Click(object sender, EventArgs e) + { + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + string sql2 = "select A from QS where QID=" + qidnow; + SqlCommand com2 = new SqlCommand(sql2, sqlCnt); + int ans = (int)com2.ExecuteScalar(); + switch (ans) + { + case 0: + MessageBox.Show("本题为简答题,不提供答案"); + break; + case 1: + MessageBox.Show("本题选A"); + break; + case 2: + MessageBox.Show("本题选B"); + break; + case 3: + MessageBox.Show("本题选C"); + break; + case 4: + MessageBox.Show("本题选D"); + break; + default: + MessageBox.Show("本题为简答题,不提供答案"); + break; + } + } + + private void button3_Click(object sender, EventArgs e) + { + //上传学生答题结果 + Close(); + } + + private void button1_Click(object sender, EventArgs e) + { + if (stl <= 1) MessageBox.Show("没有上一条了"); + else + { + stl--; + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + string s8 = "select TOP 1 QID from QS where QID in(select TOP " + stl + " QID from QS where EXAM_ID=" + examid + " order by QID) order by QID desc"; + SqlCommand co1 = new SqlCommand(s8, sqlCnt); + qidnow = (int)co1.ExecuteScalar(); + string sql1 = "select Q from QS where QID=" + qidnow; + SqlCommand com1 = new SqlCommand(sql1, sqlCnt); + String ss = (String)com1.ExecuteScalar(); + label3.Text = ss; + label5.Text = "第" + stl + "题:"; + label6.Text = "题型:"; + string sql2 = "select A from QS where QID=" + qidnow; + SqlCommand com2 = new SqlCommand(sql2, sqlCnt); + int a = (int)com2.ExecuteScalar(); + if (a != 0) + label6.Text += "单项选择题"; + else + label6.Text += "简答题"; + } + } + + private void button2_Click(object sender, EventArgs e) + { + string ConStr = "server=121.196.159.49;database=Course;uid=sa;pwd=02200059Yl"; + SqlConnection sqlCnt = new SqlConnection(ConStr); + sqlCnt.Open(); + //查询 + if (stl >= qtotal) MessageBox.Show("没有下一条了,请选择结束答题以交卷"); + else + { + stl++; + string s8 = "select TOP 1 QID from QS where QID in(select TOP " + stl + " QID from QS where EXAM_ID=" + examid + " order by QID) order by QID desc"; + SqlCommand co1 = new SqlCommand(s8, sqlCnt); + qidnow = (int)co1.ExecuteScalar(); + string sql1 = "select Q from QS where QID=" + qidnow; + SqlCommand com1 = new SqlCommand(sql1, sqlCnt); + String ss = (String)com1.ExecuteScalar(); + label3.Text = ss; + label5.Text = "第" + stl + "题:"; + label6.Text = "题型:"; + string sql2 = "select A from QS where QID=" + qidnow; + SqlCommand com2 = new SqlCommand(sql2, sqlCnt); + int a = (int)com2.ExecuteScalar(); + if (a != 0) + label6.Text += "单项选择题"; + else + label6.Text += "简答题"; + } + } + } +} diff --git a/Working.resx b/Working.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Working.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/login.Designer.cs b/login.Designer.cs index 735536d..7f669aa 100644 --- a/login.Designer.cs +++ b/login.Designer.cs @@ -153,7 +153,7 @@ private void InitializeComponent() // // button2 // - this.button2.Location = new System.Drawing.Point(549, 356); + this.button2.Location = new System.Drawing.Point(530, 356); this.button2.Margin = new System.Windows.Forms.Padding(4); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(104, 41); diff --git a/login.cs b/login.cs index e272986..e3dff65 100644 --- a/login.cs +++ b/login.cs @@ -13,6 +13,8 @@ namespace WinFormsApp1 { public partial class login : Form { + public static bool identity=true; //laoshi + public static int id_card=1; public login() { InitializeComponent();