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

📄 teacher.cs

📁 asp.net连带c++技术开发
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using System.Configuration;

namespace Server
{
    public  class Teacher
    {
        public static DataSet ApplyClass(string teacher_id,string dept_id)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["strConn"].Trim());

            SqlCommand cmd = new SqlCommand("select class_id from applyClass_tb where teacher_id =@teacher and dept_id =@dept_id", conn);
            cmd.Parameters .Add("@teacher", SqlDbType.BigInt).Value = Convert.ToInt64( teacher_id);
            cmd.Parameters.Add("@dept_id", SqlDbType.BigInt).Value =  Convert.ToInt64( dept_id);
           
            SqlDataAdapter _da = new SqlDataAdapter(cmd);
            DataSet _ds = new DataSet();
            _da.Fill(_ds);
            _da.Dispose();
            string strCmd = "select * from class_tb where class_teach_id is NULL and class_dep_id=@dept_id " ;
            
                for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                {
                    strCmd += "and class_id<>" + Convert.ToInt64(_ds.Tables[0].Rows[i][0].ToString());
                }

                SqlCommand _cmd = new SqlCommand(strCmd, conn);
                _cmd.Parameters.Add("@dept_id", SqlDbType.BigInt).Value = Convert.ToInt64(dept_id);

                SqlDataAdapter da = new SqlDataAdapter(_cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                da.Dispose();
                conn.Close();
                return ds;
            
        }
        public static DataSet ApplyingClass(string teacher_id, string dept_id)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["strConn"].Trim());

            SqlCommand cmd = new SqlCommand("select class_id from applyClass_tb where teacher_id =@teacher and dept_id =@dept_id", conn);
            cmd.Parameters.Add("@teacher", SqlDbType.BigInt).Value = Convert.ToInt64(teacher_id);
            cmd.Parameters.Add("@dept_id", SqlDbType.BigInt).Value = Convert.ToInt64(dept_id);

            SqlDataAdapter _da = new SqlDataAdapter(cmd);
            DataSet _ds = new DataSet();
            _da.Fill(_ds);
            _da.Dispose();
            string strCmd = "select * from class_tb where class_dep_id=@dept_id ";
            if (_ds.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            else
            {
                for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        strCmd += "and class_id=" + Convert.ToInt64(_ds.Tables[0].Rows[i][0].ToString());
                    }
                    else
                    {
                        strCmd += "or class_id=" + Convert.ToInt64(_ds.Tables[0].Rows[i][0].ToString());
                    }
                    
                }

                SqlCommand _cmd = new SqlCommand(strCmd, conn);
                _cmd.Parameters.Add("@dept_id", SqlDbType.BigInt).Value = Convert.ToInt64(dept_id);

                SqlDataAdapter da = new SqlDataAdapter(_cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                da.Dispose();
                conn.Close();
                return ds;
            }
        }
        public static string[] TeacherInfo(string teacher_id)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["strConn"].Trim());
            string strCmd = "SELECT teach_id, teach_dep_id, teach_post, teach_name, teach_info,teach_sex FROM teacher_tb where teach_id=@teacher_id";
            SqlCommand cmd = new SqlCommand(strCmd,conn);
            cmd.Parameters.Add("@teacher_id", SqlDbType.BigInt).Value = Convert.ToInt32(teacher_id);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            conn.Open();
            da.Fill(ds);
            da.Dispose();
            string[] teacher_tb = new string[6];
            for (int i = 0; i <=5; i++)
            { 
                teacher_tb[i]=ds.Tables[0].Rows[0][i].ToString();
            }
            return teacher_tb;
        }
        public static bool UpdatTeacherInfo(teach_tb teach)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["strConn"].Trim());
            string strCmd = "update teacher_tb set teach_name=@teach_name,teach_post=@teach_post,teach_info=@teach_info,teach_sex=@teach_sex where teach_id=@teach_id";
            
            SqlCommand cmd = new SqlCommand(strCmd, conn);

            cmd.Parameters.Add("@teach_name",SqlDbType.VarChar).Value=teach.Teach_nane;
            cmd.Parameters.Add("@teach_post",SqlDbType.VarChar).Value=teach.Teach_post;
            cmd.Parameters.Add("@teach_info",SqlDbType.VarChar).Value=teach.Teach_info;
            cmd.Parameters.Add("@teach_sex", SqlDbType.VarChar).Value = teach.Teach_sex;
            cmd.Parameters.Add("@teach_id", SqlDbType.BigInt).Value = teach.Teach_id;
            
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
            finally
            { 
                conn.Close();
            }
        }
        public static string  UpdatePassword(teach_tb teach,string old)
        {
            string strCmd;
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["strConn"].Trim());
            strCmd = "select teach_pwd from teacher_tb where teach_id="+teach.Teach_id;
            SqlCommand cmd = new SqlCommand(strCmd, conn);
            conn.Open();
            if (old.Trim() != cmd.ExecuteScalar().ToString().Trim())
            {
                return "输入的旧密码不正确";
            }
            strCmd = "UPDATE  teacher_tb SET teach_pwd =@teach_pwd where teach_id =@teach_id";
            SqlCommand _cmd = new SqlCommand(strCmd, conn);
            _cmd.Parameters.Add("@Teach_pwd", SqlDbType.VarChar).Value = teach.Teach_pwd;
            _cmd.Parameters.Add("@teach_id", SqlDbType.BigInt).Value = teach.Teach_id;

            try
            {
                _cmd.ExecuteNonQuery();
                return "密码修改成功";
            }
            catch 
            {
                return "密码修改失败";
            }
            finally
            {
                conn.Close();
            }
        }
    }
}

⌨️ 快捷键说明

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