⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 网络考试系统 系统基于 .NET 框架开发
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Data;
using System.Data.OleDb;

using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
using System.Threading;

//播放声音
using System.Runtime.InteropServices;

//序列化
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary ;

namespace ExamSystem
{
	/// <summary>
	/// MainForm 的摘要说明。
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Button button31;
		private System.Windows.Forms.Button button33;
		private System.Windows.Forms.Button button32;
		private System.Windows.Forms.Button button34;
		private System.Windows.Forms.PictureBox pictureBox2;

		/// <summary>
		/// 默认配置
		/// </summary>
		public PropertyStatic ps = new PropertyStatic();

		//是否取随要数
		private bool isW = false;
		public  bool con = true;

		//当前考试类型
		public string examType = "必考题";

		//客户端IP地址和对应姓名
		public string[] clientIPs  = new string[]{"","","","",""};
		public string[] clieckNas  = new string[]{"","","","",""};

		//当前抽取的试题
		private DataRow currentExam = null;

		public  int     timeOut     = 10;

		public  string  cuMSG       = "";

		/// <summary>
		/// IP 数据
		/// </summary>
		private IPAddress            ip;
		private IPEndPoint           po;
		private Socket               socket;

		private IPAddress            ip__;
		private IPEndPoint           po__;
		private Socket               socket__;
		private Socket               tempsocket;

		//
		public ArrayList ipStr = new ArrayList();

		private System.Windows.Forms.Button button105;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Button button104;
		private System.Windows.Forms.Button button102;
		private System.Windows.Forms.Button button103;
		private System.Windows.Forms.Button button101;
		private System.Windows.Forms.Label a;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label2;

		/// <summary>
		/// 数据库连接
		/// </summary>
		private OleDbConnection conn = null;

		//IP设置
		public string localIP  = "";
		public string serverIP = "";
		private System.Windows.Forms.Timer timeOutCon;

		private bool   isSelectExam = false;

		//软件类型
		public string softType = "SERVER";
		private System.Windows.Forms.Button ksp; //服务器类型,客户类型值为 CLIENT

		//是否捕捉空格
		private bool keySpace = false;

		//题数
		public string examC   = "0";

		//
		public SelectExam se   = null;
		private System.Windows.Forms.Label q;
		public bool      alert = false;
		private System.Timers.Timer timer;

		//非正式使用窗口
		public NoUse nu = new NoUse();

		private bool isAlert = false;

		public MainForm(string softType)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			this.softType = softType;
			this.timer.Stop();

			//打开配置
			this.OpenSystemSet();

			this.conn = new OleDbConnection(Config.connStr);
			this.CheckLocalIP();
			this.se = new SelectExam(this);

			if(this.softType == "CLIENT"){

				this.button101.Visible = false;
				this.button102.Visible = false;
				this.button103.Visible = false;
				this.button104.Visible = false;
				this.button105.Visible = false;

				this.button31.Visible  = false;
				this.button32.Visible  = false;
			}
	}

		private void CheckLocalIP(){
			if(this.localIP == ""){

				if(this.softType == "SERVER"){
					SystemSet ss = new SystemSet(this);
					ss.ShowDialog();
				}else{
					SystemSet_ ss = new SystemSet_(this);
					ss.ShowDialog();
				}
			}
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.button31 = new System.Windows.Forms.Button();
			this.button33 = new System.Windows.Forms.Button();
			this.button32 = new System.Windows.Forms.Button();
			this.button34 = new System.Windows.Forms.Button();
			this.pictureBox2 = new System.Windows.Forms.PictureBox();
			this.button105 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.button104 = new System.Windows.Forms.Button();
			this.button102 = new System.Windows.Forms.Button();
			this.button103 = new System.Windows.Forms.Button();
			this.button101 = new System.Windows.Forms.Button();
			this.a = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.timeOutCon = new System.Windows.Forms.Timer(this.components);
			this.ksp = new System.Windows.Forms.Button();
			this.q = new System.Windows.Forms.Label();
			this.timer = new System.Timers.Timer();
			((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(0, 0);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(1024, 136);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			// 
			// button31
			// 
			this.button31.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button31.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((System.Byte)(134)));
			this.button31.Location = new System.Drawing.Point(632, 88);
			this.button31.Name = "button31";
			this.button31.Size = new System.Drawing.Size(88, 32);
			this.button31.TabIndex = 1;
			this.button31.Text = "管理试题";
			this.button31.Click += new System.EventHandler(this.button31_Click);
			// 
			// button33
			// 
			this.button33.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button33.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((System.Byte)(134)));
			this.button33.Location = new System.Drawing.Point(824, 88);
			this.button33.Name = "button33";
			this.button33.Size = new System.Drawing.Size(88, 32);
			this.button33.TabIndex = 2;
			this.button33.Text = "系统设置";
			this.button33.Click += new System.EventHandler(this.button33_Click);
			// 
			// button32
			// 
			this.button32.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button32.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((System.Byte)(134)));
			this.button32.Location = new System.Drawing.Point(728, 88);
			this.button32.Name = "button32";
			this.button32.Size = new System.Drawing.Size(88, 32);
			this.button32.TabIndex = 3;
			this.button32.Text = "应试者设置";
			this.button32.Click += new System.EventHandler(this.button32_Click);
			// 
			// button34
			// 
			this.button34.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button34.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((System.Byte)(134)));
			this.button34.Location = new System.Drawing.Point(920, 88);
			this.button34.Name = "button34";
			this.button34.Size = new System.Drawing.Size(88, 32);
			this.button34.TabIndex = 4;
			this.button34.Text = "退出系统";
			this.button34.Click += new System.EventHandler(this.button4_Click);
			// 
			// pictureBox2
			// 
			this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
			this.pictureBox2.Location = new System.Drawing.Point(-8, 752);
			this.pictureBox2.Name = "pictureBox2";
			this.pictureBox2.Size = new System.Drawing.Size(1024, 50);
			this.pictureBox2.TabIndex = 15;
			this.pictureBox2.TabStop = false;
			// 
			// button105
			// 
			this.button105.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.button105.Enabled = false;
			this.button105.Font = new System.Drawing.Font("宋体-方正超大字符集", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button105.Location = new System.Drawing.Point(128, 656);
			this.button105.Name = "button105";
			this.button105.Size = new System.Drawing.Size(112, 40);
			this.button105.TabIndex = 16;
			this.button105.Text = "查看答案";
			this.button105.Click += new System.EventHandler(this.button105_Click);
			// 
			// label1
			// 
			this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.label1.Font = new System.Drawing.Font("宋体", 25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(16, 176);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 40);
			this.label1.TabIndex = 17;
			this.label1.Text = "考题:";
			// 
			// label4
			// 
			this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.label4.Font = new System.Drawing.Font("宋体", 25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label4.Location = new System.Drawing.Point(16, 432);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(120, 40);
			this.label4.TabIndex = 18;
			this.label4.Text = "答案:";
			// 
			// button104
			// 
			this.button104.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.button104.Font = new System.Drawing.Font("宋体-方正超大字符集", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button104.Location = new System.Drawing.Point(240, 656);
			this.button104.Name = "button104";
			this.button104.Size = new System.Drawing.Size(136, 40);
			this.button104.TabIndex = 1;
			this.button104.Text = "清空界面";
			this.button104.Click += new System.EventHandler(this.button5_Click_1);
			// 
			// button102
			// 
			this.button102.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.button102.Font = new System.Drawing.Font("宋体-方正超大字符集", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button102.Location = new System.Drawing.Point(576, 656);
			this.button102.Name = "button102";
			this.button102.Size = new System.Drawing.Size(200, 40);
			this.button102.TabIndex = 14;
			this.button102.Text = "(抢答)随机抽题";
			this.button102.Click += new System.EventHandler(this.button102_Click);
			// 
			// button103
			// 
			this.button103.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.button103.Font = new System.Drawing.Font("宋体-方正超大字符集", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button103.Location = new System.Drawing.Point(776, 656);
			this.button103.Name = "button103";
			this.button103.Size = new System.Drawing.Size(184, 40);
			this.button103.TabIndex = 13;
			this.button103.Text = "(自选)抽题";
			this.button103.Click += new System.EventHandler(this.button103_Click);
			// 
			// button101
			// 
			this.button101.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.button101.Font = new System.Drawing.Font("宋体-方正超大字符集", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button101.Location = new System.Drawing.Point(376, 656);
			this.button101.Name = "button101";
			this.button101.Size = new System.Drawing.Size(200, 40);
			this.button101.TabIndex = 1;
			this.button101.Text = "(必考)随机抽题";
			this.button101.Click += new System.EventHandler(this.button5_Click);
			// 
			// a
			// 
			this.a.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.a.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.a.Font = new System.Drawing.Font("宋体", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.a.Location = new System.Drawing.Point(128, 432);
			this.a.Name = "a";
			this.a.Size = new System.Drawing.Size(832, 200);
			this.a.TabIndex = 22;
			// 
			// label6
			// 
			this.label6.BackColor = System.Drawing.Color.Gray;
			this.label6.Font = new System.Drawing.Font("宋体", 25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label6.Location = new System.Drawing.Point(136, 440);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(832, 200);
			this.label6.TabIndex = 21;
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Gray;
			this.label2.Font = new System.Drawing.Font("宋体", 25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.Location = new System.Drawing.Point(136, 184);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(832, 240);
			this.label2.TabIndex = 20;
			// 
			// timeOutCon
			// 
			this.timeOutCon.Interval = 10000;
			this.timeOutCon.Tick += new System.EventHandler(this.timeOutCon_Tick);
			// 
			// ksp
			// 
			this.ksp.Location = new System.Drawing.Point(2000, 2000);
			this.ksp.Name = "ksp";
			this.ksp.TabIndex = 1;
			this.ksp.Text = "button1";
			this.ksp.Click += new System.EventHandler(this.ksp_Click);
			// 
			// q
			// 
			this.q.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.q.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.q.Font = new System.Drawing.Font("宋体", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.q.Location = new System.Drawing.Point(128, 176);
			this.q.Name = "q";
			this.q.Size = new System.Drawing.Size(832, 240);
			this.q.TabIndex = 19;
			// 
			// timer
			// 
			this.timer.Enabled = true;
			this.timer.Interval = 10;
			this.timer.SynchronizingObject = this;
			this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(1024, 768);
			this.Controls.Add(this.ksp);
			this.Controls.Add(this.a);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.q);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button105);
			this.Controls.Add(this.pictureBox2);
			this.Controls.Add(this.button104);
			this.Controls.Add(this.button102);
			this.Controls.Add(this.button103);
			this.Controls.Add(this.button101);
			this.Controls.Add(this.button34);
			this.Controls.Add(this.button32);
			this.Controls.Add(this.button33);
			this.Controls.Add(this.button31);
			this.Controls.Add(this.pictureBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "某单位内部考试系统";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
			this.Load += new System.EventHandler(this.MainForm_Load);
			((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#region Windows 退出系统
		/// <summary>
		/// 退出系统
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void button4_Click(object sender, System.EventArgs e) {
			if(!this.keySpace){
				this.ksp.Focus();
				if(MessageBox.Show("确定要退出系统吗?","退出提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
					Application.Exit();
				}
			}

			
		}
		#endregion

		#region Windows 必考题按钮事件
		/// <summary>
		/// 必考随机抽题
		/// </summary>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -