基本信息
源码名称:C# 考试管理系统源码下载(含教师、学生、管理员三个角色入口)
源码大小:7.17M
文件格式:.zip
开发语言:C#
更新时间:2016-12-01
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 5 元 
   源码介绍

考试管理系统 首先要 附加Ctgu 这个数据库,然后 将 dbhelper.cs中的 连接串 改成本机的,即可测试了

管理员账号:admin 密码 admin1

教师账号:t002 密码 12345

学生账号:

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 MySchool
{
    /// <summary>
    /// 登录窗体
    /// </summary>
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录类型属性
        /// </summary>
        public string LoginType {
            get {
                return this.cboLoginType.Text;
            }
        }
        /// <summary>
        /// 登录帐号属性
        /// </summary>
        public string LoginId {
            get {
                return txtLoginId.Text.Trim();
            }
        }

        // “登录”按钮的单击事件
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!chkInput()) return; //检查输入

            string loginType = cboLoginType.Text;
            Form firform = null;

            switch (loginType)
            {
                case "教师":
                    if (TeacherLogin())
                        firform = new TeacherForm();
                    break;
                case "管理员":
                    if (AdminLogin())
                        firform = new AdminForm();
                    break;
                case "学生":
                    if (StudentLogin())
                        firform = new StudentForm();
                    break;

            }
           
            if (firform!=null)
            {
                this.Hide();
                firform.ShowDialog();
               
            }
            else
            {
                MessageBox.Show("登录失败,请检查帐号或密码是否有误!", "CTGU在线考试系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

           
        }

        private bool StudentLogin()
        {
            UserHelper.loginId = txtLoginId.Text;

            string strsql = string.Format("select count(*) from {2} where StudentNO='{0}' and Pwd='{1}'", txtLoginId.Text, txtLoginPwd.Text, "Student");
            SqlCommand comm = new SqlCommand(strsql, DBHelper.connection);
            try
            {
                DBHelper.connection.Open();
                int result = (int)comm.ExecuteScalar();
               
                    
                    return result > 0;
              
            }
            catch
            {
                return false;
            }
            finally
            {
                DBHelper.connection.Close();
            }
        }

        private bool AdminLogin()
        {
            UserHelper.loginId = txtLoginId.Text;
           string strsql = string.Format("select count(*) from {2} where AdminId='{0}' and Pwd='{1}'", txtLoginId.Text, txtLoginPwd.Text, "Admin");
            SqlCommand comm = new SqlCommand(strsql, DBHelper.connection);
            try
            {
                DBHelper.connection.Open();
                int result = (int)comm.ExecuteScalar();
                return result > 0;
            }
            catch
            {
                return false;
            }
            finally
            {
                DBHelper.connection.Close();
            }
        }
       
        private bool TeacherLogin()
        {
            UserHelper.loginId = txtLoginId.Text;
           string strsql = string.Format("select count(*) from {2} where TeacherId='{0}' and Pwd='{1}'", txtLoginId.Text, txtLoginPwd.Text, "Teacher");
            SqlCommand comm = new SqlCommand(strsql, DBHelper.connection);
            try
            {
                DBHelper.connection.Open();
                int result = (int)comm.ExecuteScalar();
                return result > 0;
            }
            catch
            {
                return false;
            }
            finally
            {
                DBHelper.connection.Close();
            }
        }
        /// <summary>
        /// 主要用于校验客户端的输入的合法性
       
        private bool chkInput()
        {
            string accountId = txtLoginId.Text.Trim();
            string pwd = txtLoginPwd.Text;

            if (accountId == "")
            {
                MessageBox.Show("帐号不允许为空!", "CTGU在线考试系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            if (pwd == "")
            {
                MessageBox.Show("请输入密码!", "CTGU在线考试系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            string loginType = cboLoginType.Text;

            if (loginType == "")
            {
                MessageBox.Show("请选择登陆类型!", "CTGU在线考试系统", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            return true;

        }
        private void btnRegister_Click(object sender, EventArgs e)
        {
            StudentRegister sr = new StudentRegister();
            this.Hide();
            sr.Show();
              
        }
    }
}