C# 学生疫情防控系统

发布于:2023-07-04 ⋅ 阅读:(145) ⋅ 点赞:(0)

 

 

 

 

namespace 疫情防控管理
{
    public partial class frm_Login : Form
    {
        public string A;
        public frm_Login()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            cbBLimit.Text = ("--请选择--");
            cbBLimit.Items.Add("管理员");
            cbBLimit.Items.Add("学生");
            Random r = new Random();
            int a = r.Next(1000, 9999);//生成验证码
            this.lbl_Check.Text = a.ToString();
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            
            if (cbBLimit.Text == "--请选择--")
            {
                MessageBox.Show("请选择用户权限!");
                return; }
            if (txt_Check.Text != lbl_Check.Text)
            {
                MessageBox.Show("验证码输入错误!");
                Random r = new Random();
                int a = r.Next(1000, 9999);//生成验证码
                this.lbl_Check.Text = a.ToString();
                return;
                    }
            if (cbBLimit.Text == "管理员")
            {
                SqlConnection sqlConnection = new SqlConnection();//声明并实例化SQL连接
                sqlConnection.ConnectionString = "Server=(Local);Database=EdubaseManagement;Integrated Security=sspi"; //在字符串变量中,描述连接字符串所需的服务器地址、数据库名称、集成安全性(即是否使用Windows验证);
                SqlCommand sqlCommand = sqlConnection.CreateCommand(); //调用SQL连接的方法CreateCommand来创建SQL命令;该命令将绑定SQL连接;
                sqlCommand.CommandText =
                     $"SELECT COUNT(1) FROM tb_User WHERE NO = '{txt_NO.Text.Trim()}' AND PASSWORD = '{txt_Password.Text.Trim()}';";
                sqlConnection.Open();                                                           //打开SQL连接;
                int rowCount = (int)sqlCommand.ExecuteScalar();                                 //调用SQL命令的方法ExecuteScalar来执行命令,并接受单个结果(即标量);
                    sqlConnection.Close();                                                          //关闭SQL连接;
                if (rowCount == 1)                                                              //若查得所输用户号相应的1行记录;
                {
                    MessageBox.Show("登录成功,欢迎进入管理员界面!");//给出正确提示;
                    this.Hide();
                    new frm_Admin(this.txt_NO.Text).Show();
                    return;
                }
                else                                                                            //否则;
                {
                    MessageBox.Show("用户号/密码有误,请重新输入!");
                    return;//给出错误提示;
                }
            }
            if (cbBLimit.Text == "学生")
            {
                SqlConnection sqlConnection = new SqlConnection();
                sqlConnection.ConnectionString = "Server=(Local);Database=EdubaseManagement;Integrated Security=sspi";
                SqlCommand sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.CommandText =
                    $"SELECT COUNT(1) FROM tb_Student WHERE NO = '{txt_NO.Text.Trim()}' AND PASSWORD = '{txt_Password.Text.Trim()}';";
                sqlConnection.Open();                                                           //打开SQL连接;
                int rowCount = (int)sqlCommand.ExecuteScalar();                                 //调用SQL命令的方法ExecuteScalar来执行命令,并接受单个结果(即标量);
                  sqlConnection.Close();                                                          //关闭SQL连接;
                if (rowCount == 1)                                                              //若查得所输用户号相应的1行记录;
                {
                    MessageBox.Show("登录成功,欢迎进入学生界面!");//给出正确提示;
                    this.Hide();
                    new frm_Student(txt_NO.Text).Show();
                    return;
                }
                else                                                                            //否则;
                {
                    MessageBox.Show("用户号/密码有误,请重新输入!");
                    return;//给出错误提示;
                }                                                                         //执行标量的返回结果类型为object,可通过强制类型转换,转为整型;
                     }
        }

namespace 疫情防控管理
{
    public partial class frm_BackSchool : Form
    {
        private DataTable Back;
        public string no;
        public frm_BackSchool(string no)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.no = no;
            comboBox1.Text = "--请选择--";
            comboBox1.Items.Add("是");
            comboBox1.Items.Add("否");
        }

        private void frm_BackSchool_Load(object sender, EventArgs e)
        {
            txt_ID.Text = no;
            
           
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = "Server=(local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText =
               $"SELECT * FROM tb_Student WHERE No = '{txt_ID.Text.Trim()}';";
            sqlConnection.Open();
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            if (sqlDataReader.Read())
            {
                this.txt_Name.Text = sqlDataReader["NAME"].ToString();
                this.txt_Class.Text = sqlDataReader["Class"].ToString();
                this.txt_teacherName.Text = sqlDataReader["TeacherName"].ToString();
            }
        }

        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (txt_destination.Text.Trim() == "")
            {
                MessageBox.Show("请输入目的地!");
                return;
            }
            if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请选择是否高风险!");
                return;
            }
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString =
                "Server=(Local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText =
                "INSERT tb_BackApply " +
                 " (NO,NAME,Class,TeacherName,ActionLoation,IsSecurity,BackTime,ApplyTime,Solution)" +
                 " VALUES (@NO,@NAME,@Class,@TeacherName,@ActionLoation,@IsSecurity,@BackTime,@ApplyTime,'未审批')";
            sqlCommand.Parameters.AddWithValue("@No", txt_ID.Text.Trim());
            sqlCommand.Parameters["@No"].SqlDbType = SqlDbType.VarChar;
            sqlCommand.Parameters.AddWithValue("@Name", txt_Name.Text.Trim());
            sqlCommand.Parameters["@Name"].SqlDbType = SqlDbType.VarChar;
            sqlCommand.Parameters.AddWithValue("@Class", this.txt_Class.Text.Trim());
            sqlCommand.Parameters.AddWithValue("@TeacherName", this.txt_teacherName.Text.Trim());
             DateTime dr = dateTimePicker2.Value;
            String tt = dr.ToShortDateString();
            sqlCommand.Parameters.AddWithValue("@BackTime", tt);
            sqlCommand.Parameters.AddWithValue("@ActionLoation", txt_destination.Text.Trim());
            sqlCommand.Parameters.AddWithValue("@IsSecurity", comboBox1.Text.Trim());
            string d = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            sqlCommand.Parameters.AddWithValue("@ApplyTime", d);
            sqlConnection.Open();
            int rowAffected = sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
            if (rowAffected != 0)
            {
                MessageBox.Show("提交成功");
            }
        }

        private void btn_Seek_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = "Server=(local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = $"select  *from tb_BackApply where NO='{no}'";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataTable BackTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(BackTable);
            sqlConnection.Close();
            this.Back = BackTable;
            this.dgv_Already.Columns.Clear();
            this.dgv_Already.DataSource = BackTable;
            this.dgv_Already.Columns["NO"].HeaderText = "账号";
            this.dgv_Already.Columns["NAME"].HeaderText = "姓名";
            this.dgv_Already.Columns["Class"].HeaderText = "年级";
            this.dgv_Already.Columns["TeacherName"].HeaderText = "导师名字";
             this.dgv_Already.Columns["ActionLoation"].HeaderText = "出发地";
            this.dgv_Already.Columns["IsSecurity"].HeaderText = "是否为高风险";
            this.dgv_Already.Columns["BackTime"].HeaderText = "返校时间";
            this.dgv_Already.Columns["ApplyTime"].HeaderText = "申请时间";
            this.dgv_Already.Columns["solution"].HeaderText = "状态";
            this.dgv_Already.DataSource = BackTable;
            this.dgv_Already.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.label9.Text =                                                                 
              $"共{this.Back.Compute("count(NO)", "")}条";
        }
    }
}

namespace 疫情防控管理
{
    public partial class frm_adminLeave : Form
    {
        private DataTable LeaveTable;
        public frm_adminLeave()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void frm_adminLeave_Load(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = "Server=(local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "select  *from tb_leave where solution='未审批'";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataTable LeaveTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(LeaveTable);
            sqlConnection.Close();
            this.LeaveTable = LeaveTable;
            this.dgv_Already.Columns.Clear();
            this.dgv_Already.DataSource = LeaveTable;
            this.dgv_Already.Columns["NO"].HeaderText = "账号";
            this.dgv_Already.Columns["NAME"].HeaderText = "姓名";
            this.dgv_Already.Columns["Major"].HeaderText = "专业";
            this.dgv_Already.Columns["Class"].HeaderText = "年级";
            this.dgv_Already.Columns["TeacherName"].HeaderText = "导师名字";
            this.dgv_Already.Columns["ApplyTime"].HeaderText = "请假时间";
            this.dgv_Already.Columns["BackTime"].HeaderText = "返校时间";
            this.dgv_Already.Columns["Detail"].HeaderText = "具体时间";
            this.dgv_Already.Columns["Destination"].HeaderText = "目的地";
            this.dgv_Already.Columns["solution"].HeaderText = "状态";
            this.dgv_Already.DataSource = LeaveTable;
            this.dgv_Already.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.label2.Text =                                                                       //在标签中显示已注册学生的人数总和;
              $"共{this.LeaveTable.Compute("count(NO)", "")}条";
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = "Server=(local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "UPDATE tb_leave SET solution=@solution WHERE ApplyTime=@ApplyTime";
            sqlCommand.Parameters.Add("@ApplyTime", SqlDbType.VarChar, 0, "ApplyTime");
            sqlCommand.Parameters.AddWithValue("@solution", "申请通过");
            sqlCommand.Parameters["@solution"].SqlDbType = SqlDbType.VarChar;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            DataRowView currentCourseRowView =
              this.dgv_Already.CurrentRow.DataBoundItem as DataRowView;  
            DataRow
            currentCourseRow = currentCourseRowView.Row     ; 
           currentCourseRow.SetModified();
            sqlDataAdapter.UpdateCommand = sqlCommand;
            DataTable LeaveTable = this.LeaveTable;

            sqlConnection.Open();
            int rowAffected = sqlDataAdapter.Update(LeaveTable);
            sqlConnection.Close();
            MessageBox.Show($"完成{rowAffected}次审批");
        }

        private void btn_No_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = "Server=(local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "UPDATE tb_leave SET solution=@solution WHERE ApplyTime=@ApplyTime";
            sqlCommand.Parameters.Add("@ApplyTime", SqlDbType.VarChar, 0, "ApplyTime");
            sqlCommand.Parameters.AddWithValue("@solution", "申请驳回");
            sqlCommand.Parameters["@solution"].SqlDbType = SqlDbType.VarChar;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            DataRowView currentCourseRowView =
              this.dgv_Already.CurrentRow.DataBoundItem as DataRowView;
            DataRow
            currentCourseRow = currentCourseRowView.Row ;                                                   
             currentCourseRow.SetModified();
            sqlDataAdapter.UpdateCommand = sqlCommand;
            DataTable LeaveTable = this.LeaveTable;
            sqlConnection.Open();
            int rowAffected = sqlDataAdapter.Update(LeaveTable);
            sqlConnection.Close();
            MessageBox.Show($"完成{rowAffected}次审批");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = "Server=(local);Database=EdubaseManagement;Integrated Security=sspi";
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "select  *from tb_leave where solution='未审批'";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataTable LeaveTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(LeaveTable);
            sqlConnection.Close();
            this.LeaveTable = LeaveTable;
            this.dgv_Already.Columns.Clear();
            this.dgv_Already.DataSource = LeaveTable;
            this.dgv_Already.Columns["NO"].HeaderText = "账号";
            this.dgv_Already.Columns["NAME"].HeaderText = "姓名";
            this.dgv_Already.Columns["Major"].HeaderText = "专业";
            this.dgv_Already.Columns["Class"].HeaderText = "年级";
            this.dgv_Already.Columns["TeacherName"].HeaderText = "导师名字";
            this.dgv_Already.Columns["ApplyTime"].HeaderText = "请假时间";
            this.dgv_Already.Columns["BackTime"].HeaderText = "返校时间";
            this.dgv_Already.Columns["Detail"].HeaderText = "请假理由";
            this.dgv_Already.Columns["Destination"].HeaderText = "目的地";
            this.dgv_Already.Columns["solution"].HeaderText = "状态";
            this.dgv_Already.DataSource = LeaveTable;
            this.dgv_Already.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.label2.Text =                                                                       //在标签中显示已注册学生的人数总和;
              $"共{this.LeaveTable.Compute("count(NO)", "")}条";
        }
    }
}
 

本文含有隐藏内容,请 开通VIP 后查看

微信公众号

今日签到

点亮在社区的每一天
去签到