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

📄 frmaddtopics.cs

📁 考试管理系统CS架构 不需更多说明
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ExamSystem.BusinessFacade.TeacherFac;
using ExamSystem.BusinessFacade.TopicsFacade;
using System.Data;
namespace TeachersClient.TopicsFrm
{
	/// <summary>
	/// FrmTopics 的摘要说明。
	/// </summary>
	public class FrmAddTopics : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.ComboBox cmbCate;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.NumericUpDown nudLevel;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.NumericUpDown nudAnwsers;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.CheckedListBox clbAnwser;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.RichTextBox rtbTitle;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		
		

		private void fillSelector()
		{

			CateFac cateFac=new CateFac();
			DataSet dsCate=cateFac.getCate(-1,"",-1);
			DataView dvCate=dsCate.Tables[0].DefaultView;
			dvCate.RowFilter="CateID>0";
			cmbCate.DataSource=dsCate.Tables[0];
			cmbCate.DisplayMember="CateName";
			cmbCate.ValueMember="CateID";
			if(cmbCate.Items.Count>0)
			{
				cmbCate.SelectedIndex=0;
			}
		}
		
		public FrmAddTopics()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <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.label1 = new System.Windows.Forms.Label();
			this.panel1 = new System.Windows.Forms.Panel();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.cmbCate = new System.Windows.Forms.ComboBox();
			this.label6 = new System.Windows.Forms.Label();
			this.nudLevel = new System.Windows.Forms.NumericUpDown();
			this.label4 = new System.Windows.Forms.Label();
			this.nudAnwsers = new System.Windows.Forms.NumericUpDown();
			this.label3 = new System.Windows.Forms.Label();
			this.clbAnwser = new System.Windows.Forms.CheckedListBox();
			this.label2 = new System.Windows.Forms.Label();
			this.panel2 = new System.Windows.Forms.Panel();
			this.rtbTitle = new System.Windows.Forms.RichTextBox();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.nudLevel)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.nudAnwsers)).BeginInit();
			this.panel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Dock = System.Windows.Forms.DockStyle.Top;
			this.label1.Location = new System.Drawing.Point(0, 0);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(336, 14);
			this.label1.TabIndex = 0;
			this.label1.Text = "题干";
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.button2);
			this.panel1.Controls.Add(this.button1);
			this.panel1.Controls.Add(this.cmbCate);
			this.panel1.Controls.Add(this.label6);
			this.panel1.Controls.Add(this.nudLevel);
			this.panel1.Controls.Add(this.label4);
			this.panel1.Controls.Add(this.nudAnwsers);
			this.panel1.Controls.Add(this.label3);
			this.panel1.Controls.Add(this.clbAnwser);
			this.panel1.Controls.Add(this.label2);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel1.Location = new System.Drawing.Point(0, 239);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(336, 174);
			this.panel1.TabIndex = 24;
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(180, 140);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(66, 22);
			this.button2.TabIndex = 33;
			this.button2.Text = "关闭";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(92, 140);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(66, 22);
			this.button1.TabIndex = 32;
			this.button1.Text = "添加";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// cmbCate
			// 
			this.cmbCate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cmbCate.Location = new System.Drawing.Point(230, 102);
			this.cmbCate.Name = "cmbCate";
			this.cmbCate.Size = new System.Drawing.Size(102, 20);
			this.cmbCate.TabIndex = 30;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(182, 106);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(50, 16);
			this.label6.TabIndex = 29;
			this.label6.Text = "科目:";
			// 
			// nudLevel
			// 
			this.nudLevel.Location = new System.Drawing.Point(230, 54);
			this.nudLevel.Maximum = new System.Decimal(new int[] {
																	 5,
																	 0,
																	 0,
																	 0});
			this.nudLevel.Minimum = new System.Decimal(new int[] {
																	 1,
																	 0,
																	 0,
																	 0});
			this.nudLevel.Name = "nudLevel";
			this.nudLevel.Size = new System.Drawing.Size(56, 21);
			this.nudLevel.TabIndex = 28;
			this.nudLevel.Value = new System.Decimal(new int[] {
																   1,
																   0,
																   0,
																   0});
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(190, 58);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(42, 16);
			this.label4.TabIndex = 27;
			this.label4.Text = "难度:";
			// 
			// nudAnwsers
			// 
			this.nudAnwsers.Location = new System.Drawing.Point(230, 12);
			this.nudAnwsers.Maximum = new System.Decimal(new int[] {
																	   10,
																	   0,
																	   0,
																	   0});
			this.nudAnwsers.Minimum = new System.Decimal(new int[] {
																	   3,
																	   0,
																	   0,
																	   0});
			this.nudAnwsers.Name = "nudAnwsers";
			this.nudAnwsers.Size = new System.Drawing.Size(62, 21);
			this.nudAnwsers.TabIndex = 26;
			this.nudAnwsers.Value = new System.Decimal(new int[] {
																	 3,
																	 0,
																	 0,
																	 0});
			this.nudAnwsers.ValueChanged += new System.EventHandler(this.nudAnwsers_ValueChanged);
			this.nudAnwsers.Leave += new System.EventHandler(this.nudAnwsers_ValueChanged);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(176, 16);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 16);
			this.label3.TabIndex = 25;
			this.label3.Text = "答案数:";
			// 
			// clbAnwser
			// 
			this.clbAnwser.Location = new System.Drawing.Point(46, 8);
			this.clbAnwser.Name = "clbAnwser";
			this.clbAnwser.Size = new System.Drawing.Size(112, 116);
			this.clbAnwser.TabIndex = 24;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(12, 12);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(42, 20);
			this.label2.TabIndex = 31;
			this.label2.Text = "答案:";
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.rtbTitle);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel2.Location = new System.Drawing.Point(0, 14);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(336, 225);
			this.panel2.TabIndex = 25;
			// 
			// rtbTitle
			// 
			this.rtbTitle.Dock = System.Windows.Forms.DockStyle.Fill;
			this.rtbTitle.Location = new System.Drawing.Point(0, 0);
			this.rtbTitle.Name = "rtbTitle";
			this.rtbTitle.Size = new System.Drawing.Size(336, 225);
			this.rtbTitle.TabIndex = 2;
			this.rtbTitle.Text = "";
			// 
			// FrmAddTopics
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(336, 413);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "FrmAddTopics";
			this.ShowInTaskbar = false;
			this.Text = "添加题目";
			this.Load += new System.EventHandler(this.FrmAddTopics_Load);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.nudLevel)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.nudAnwsers)).EndInit();
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void FrmAddTopics_Load(object sender, System.EventArgs e)
		{
			fillSelector();
			nudAnwsers_ValueChanged(null,null);
		}

		private void nudAnwsers_ValueChanged(object sender, System.EventArgs e)
		{
			clbAnwser.Items.Clear();
			int count=(int)nudAnwsers.Value;
			for(int i=0;i<count;i++)
			{
				clbAnwser.Items.Add((char)('A'+i));
			}
		}
		
		/// <summary>
		/// 判断是否有项没有填
		/// </summary>
		/// <returns></returns>
		private bool hasEmpty()
		{
			if(rtbTitle.Text.Trim()=="")
			{
				MessageBox.Show("请输入题干","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return true;
			}
			
			if(this.clbAnwser.CheckedItems.Count<=0)
			{
				MessageBox.Show("请选择正确答案","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return true;
			}
			return false;
		}
		private string getAnswer()
		{
			string ans="";
			for(int i=0;i<clbAnwser.CheckedItems.Count;i++)
			{
				
				ans+=clbAnwser.CheckedItems[i].ToString();
				if(i<clbAnwser.CheckedItems.Count-1)
				{
					ans+=",";
				}
			}
			return ans;
		}

		private void clearText()
		{
			rtbTitle.Text="";
			nudAnwsers.Value=3;
			nudLevel.Value=nudLevel.Minimum;
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(hasEmpty())
			{
				return;
			}
			
			string titDetil=rtbTitle.Text.Trim();
			string titAnswer=getAnswer();
			int answers=(int)nudAnwsers.Value;
			int cateID=0;
			if(this.cmbCate.SelectedIndex>=0)
			{
				cateID=(int)cmbCate.SelectedValue;
			}
			int topicLevel=(int)nudLevel.Value;

			TopicsFac topicFac=new TopicsFac();
			try
			{
				topicFac.insertTopic(titDetil,titAnswer,answers,cateID,topicLevel);
				MessageBox.Show("添加成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				clearText();
			}
			catch
			{
				MessageBox.Show("添加数据失败","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

⌨️ 快捷键说明

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