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

📄 common.cs

📁 一个很简单的考试系统。实用性很强啊!数据库在里面
💻 CS
字号:
using System;
using System.Windows.Forms;

namespace bizdb
{
	/// <summary>
	/// common 的摘要说明。
	/// </summary>
	public class common
	{
		public common()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
	
		public static string rolestr;
		public string role
		{
			set
			{
				rolestr = value;
			}
			get
			{
				return rolestr;
			}
		}
		public static string sysnamestr;
		public string sysname
		{
			set
			{
				sysnamestr = value;
			}
			get
			{
				return sysnamestr;
			}
		}
		public static string rolenamestr;
		public string rolename
		{
			set
			{
				rolenamestr = value;
			}
			get
			{
				return rolenamestr;
			}
		}
		public static string emplidstr;
		public string emplid
		{
			set
			{
				emplidstr = value;
			}
			get
			{
				return emplidstr;
			}
		}

		///以下是陆海峰同志编写的学员选课中的部分代码,这些代码的作用是:设置界面控件(如Button等)的操作、List等的清空、异常处理等.
		
		public static int [] lstCount = new int[2];   ///该数组用来存放"课程名称"和"添加课程"列表框中项数的和
		private int [] mouLstIndex = new int[2];      ///该数组用来存放"课程名称"和"添加课程"列表框中当前选中项的Index,
		                                              ///将会在此类的检查焦点方法的Swith语句中使用

		public void chickListItemCount( ListBox kcmchLst, ListBox tjkchLst )
		{               ///向上面定义的数组中添加数值的方法。第一个参数必须为"课程名称"列表框,第二个参数必须为"添加课程"列表框
			kcmchLst.Refresh();
			tjkchLst.Refresh();

			lstCount[0] = kcmchLst.Items.Count;
			lstCount[1] = tjkchLst.Items.Count;
		}

		private void clear_Cbo( ComboBox cbo )
		{
			cbo.Text = "";
			cbo.Items.Clear();
		}
		
		public void clear_AllCbo( ComboBox cbo_Zhuanye, ComboBox cbo_Yixkxy, ComboBox cbo_Weixkxy) 
		{                                              ///+1次重载的方法,用来清除专业、已选课学员、未选课学员下拉框中的内容
			clear_Cbo( cbo_Zhuanye );
            
			clear_Cbo( cbo_Yixkxy );

			clear_Cbo( cbo_Weixkxy );
		}

		public void clear_AllCbo( ComboBox cbo_Yixkxy, ComboBox cbo_Weixkxy) 
		{                                                    ///+2次重载的方法,用来清除已选课学员、未选课学员下拉框中的内容
			clear_Cbo( cbo_Yixkxy );

			clear_Cbo( cbo_Weixkxy );
		}

		private bool doubLstCatch( ListBox lst )  ///用于双击ListBox时的异常处理方法
		{
			int searchIndex = lst.SelectedIndex;   ///获得当前项的索引,若当前项为空,则返回-1,反之,返回0
			int lstItemCount = lst.Items.Count;        ///获得当前ListBox中,项数之和

			if ( searchIndex == -1 && lstItemCount != 0 && lst.Name.ToString() == "lst_xyxk" )  ///对应于课程名称ListBox
			{                      ///当课程名称列表框中有记录,但未被正确选择时,执行的提示
				MessageBox.Show("请选择课程名称!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning );
				return true;
			}
			else if ( searchIndex == -1 && lstItemCount == 0 && lst.Name.ToString() == "lst_xyxk" )
			{                     ///当课程名称列表框中无记录,也未被正确选择时,执行的提示
				MessageBox.Show("无有效课程名称,请先选择研修方向及专业名称!", "系统提示",	
					             MessageBoxButtons.OK, MessageBoxIcon.Information);
				return true;
			}
			else if ( searchIndex == -1 && lstItemCount == 0 && lst.Name.ToString() == "lst_xkxy" ) ///对应于添加课程ListBox
			{                     ///当添加课程列表框中无记录时,执行的操作
				MessageBox.Show("尚未添加课程,请按专业选择课程后添加!", "系统提示", 
					MessageBoxButtons.OK, MessageBoxIcon.Information );
				return true;
			}
			else if ( searchIndex == -1 )
			{ ///当添加课程列表框中有记录,但未被正确选择时,执行的操作(由于有了上面的判断,因此这里只需一个条件即可)
				MessageBox.Show("未选择所需课程!", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning );
				return true;
			}
			else
				return false;
		}

		public void setLstFoucs( ListBox chickLstbox, ListBox otherLstbox, Button btnAdd, Button btnDel )
		{        ///处理焦点的方法,由于是用在鼠标单击事件中,因此,可能会单击无记录而产生异常,故需先处理异常的发生
			int msdCatch = mousedown_Catch( chickLstbox, otherLstbox );

			switch ( msdCatch )
			{
				case 1:
				case 3:
					break;

				case 4:
				case 6:
			    case 7:
					btnFou( chickLstbox, btnAdd, btnDel );
					break;
                             ///由于C#中的方法只能有一个返回值,因此需要全局数组以表示当前鼠标位置项的Index值
				case 2:
					chickLstbox.SetSelected( mouLstIndex[0], true );
					btnFou( chickLstbox, btnAdd, btnDel );
					break;

				case 5:
					chickLstbox.SetSelected( mouLstIndex[0], true );
					otherLstbox.SetSelected( mouLstIndex[1], false );
					btnFou( chickLstbox, btnAdd, btnDel );
					break;
			}			
			
		}

		private void btnFou( ListBox lst, Button addBtn, Button delBtn )
		{               ///在上个方法中调用此方法,使按钮的焦点跟着ListBox中的焦点走.参数2和3不能颠倒,必须为btn_add和btn_del
			if ( lst.Name.ToString() == "lst_xyxk" )
				addBtn.Focus();
			else
				delBtn.Focus();
		}

		private int mousedown_Catch ( ListBox moucatch_Lst, ListBox other_Lst )
		{    ///为增加方法的灵活性,本方法第一个参数对应于发生事件的列表框,故不能使用已限定参数次序的lstCount全局数组
			mouLstIndex[0] = moucatch_Lst.SelectedIndex;
			int mou_LstCount = moucatch_Lst.Items.Count;
			mouLstIndex[1] = other_Lst.SelectedIndex;
			int oth_LstCount = other_Lst.Items.Count;

			if ( mouLstIndex[0] == -1 && mou_LstCount != 0 && mouLstIndex[1] == -1 && oth_LstCount == 0 )  
				//表示第二个List无记录,第一个List有记录,但没被选择,应该将此操作忽略,以便使DoubleClick事件生效
				return 1;
			else if ( mouLstIndex[0] >= 0 && mou_LstCount != 0 && mouLstIndex[1] == -1 && oth_LstCount == 0)  
				//正常情况,第二个List无记录,第一个List有记录,并也有记录被正确选择,应该将焦点给当前记录
				return 2;
			else if ( mouLstIndex[0] == -1 && mou_LstCount == 0 && mouLstIndex[1] == -1 && oth_LstCount == 0 ) 
				//这是异常,表明两个List都没有记录,此条件通常发生在FormLoad时,应该将此操作忽略,以便使DoubleClick事件生效
				return 3;
			else if ( mouLstIndex[0] == -1 && mou_LstCount != 0 && mouLstIndex[1] == -1 && oth_LstCount != 0 )
				//第一个ListBox有记录,但没被选择,第二个ListBox也有记录,应该将此操作忽略,以便使DoubleClick事件生效
				return 4;
			else if ( mouLstIndex[0] >= 0 && mou_LstCount != 0 && mouLstIndex[1] >= 0 && oth_LstCount != 0 )
				//正常情况,第一个ListBox有记录,且已被选择,第二个ListBox也有记录,且已被选择,应使第一个获得焦点,第二个失去焦点
				return 5;
			else if ( mouLstIndex[0] == -1 && mou_LstCount != 0 && mouLstIndex[1] >= 0 && oth_LstCount != 0 )
				//第一个ListBox有记录,但没被选择,第二个有记录,且被选择,应该将此操作忽略,以便使DoubleClick事件生效
				return 6;
			else
				return 7;

		}

		public void delListItem( ListBox chk_List )       ///删除当前列表框中记录的方法
		{
			bool chick_Lst = doubLstCatch( chk_List );
			if ( chick_Lst  == false )
				chk_List.Items.RemoveAt( chk_List.SelectedIndex );
								
		}

		public void lst_Insert ( ListBox chkList, ListBox addList )
		{           ///在无异常发生的情况下,将"课程名称"列表框中所选中的字段添加进"添加课程"列表框中,并将该字段删除
			bool chick_Lst = doubLstCatch( chkList );
			if ( chick_Lst == false )
			{
				addList.Items.Add( chkList.Items[chkList.SelectedIndex].ToString());
				chkList.Items.RemoveAt( chkList.SelectedIndex );
			}
		}

		///以上是陆海峰同志编写的学员选课中的部分代码,这些代码的作用是:设置界面控件(如Button等)的操作、List等的清空、异常处理等.
	}
}

⌨️ 快捷键说明

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