User.cs
上传用户:gooyliu
上传日期:2018-09-29
资源大小:5816k
文件大小:8k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using DataAccessLayer;
  7. namespace BusinessLogicLayer
  8. {
  9.     public class Users
  10.     {
  11.         #region  私有成员
  12.         private string _userID;                     //用户编号
  13.         private string _userName;
  14.         private string _userPassword;
  15.         private bool _userGender;
  16.         private string _userDepartment;
  17.         private string _userAddress;
  18.         private string _userPhone;
  19.         private string _userBirthday;
  20.         private int _roleID;
  21.         #endregion
  22.         #region 属性
  23.         public string UserID
  24.         {
  25.             set
  26.             {
  27.                 this._userID = value;
  28.             }
  29.             get
  30.             {
  31.                 return this._userID;
  32.             }
  33.         }
  34.         public string UserName
  35.         {
  36.             set
  37.             {
  38.                 this._userName = value;
  39.             }
  40.             get
  41.             {
  42.                 return this._userName;
  43.             }
  44.         }
  45.         public string UserPassword
  46.         {
  47.             set
  48.             {
  49.                 this._userPassword = value;
  50.             }
  51.             get
  52.             {
  53.                 return this._userPassword;
  54.             }
  55.         }
  56.         public bool UserGender
  57.         {
  58.             set
  59.             {
  60.                 this._userGender = value;
  61.             }
  62.             get
  63.             {
  64.                 return this._userGender;
  65.             }
  66.         }
  67.         public string UserDepartment
  68.         {
  69.             set
  70.             {
  71.                 this._userDepartment = value;
  72.             }
  73.             get
  74.             {
  75.                 return this._userDepartment;
  76.             }
  77.         }
  78.         public string UserAddress
  79.         {
  80.             set
  81.             {
  82.                 this._userAddress = value;
  83.             }
  84.             get
  85.             {
  86.                 return this._userAddress;
  87.             }
  88.         }
  89.         public string UserPhone
  90.         {
  91.             set
  92.             {
  93.                 this._userPhone = value;
  94.             }
  95.             get
  96.             {
  97.                 return this._userPhone;
  98.             }
  99.         }
  100.         public string UserBirthday
  101.         {
  102.             set
  103.             {
  104.                 this._userBirthday = value;
  105.             }
  106.             get
  107.             {
  108.                 return this._userBirthday;
  109.             }
  110.         }
  111.         public int RoleID
  112.         {
  113.             set
  114.             {
  115.                 this._roleID = value;
  116.             }
  117.             get
  118.             {
  119.                 return this._roleID;
  120.             }
  121.         }
  122.         #endregion
  123.         
  124.         
  125.         
  126.         
  127.         //public bool CheckPassword(string XUserID)
  128.         //{
  129.         //    string sqlStr = "select * from User WHERE userID='" + XUserID + "'";
  130.         //    DataBase db = new DataBase();
  131.         //    if (db. GetRecord(sqlStr))
  132.         //    {
  133.         //        return true;
  134.         //    }
  135.         //    else
  136.         //        return false;
  137.         //}
  138.         //根据UserID和UserPassword判断密码是否正确
  139.         //输入:
  140.         //      XUserID - 用户编号
  141.         //输出:
  142.         //      用户存在:返回True;
  143.         //      用户不在:返回False;
  144.         public bool CheckPassword(string XUserID)
  145.         {
  146.             SqlParameter[] Params = new SqlParameter[1];
  147.             DataBase DB = new DataBase();
  148.             Params[0] = DB.MakeInParam("@UserID", SqlDbType.VarChar, 50, XUserID);                            
  149.             SqlDataReader DR = DB.RunProcGetReader("Proc_UsersDetail", Params);
  150.             if (!DR.Read())
  151.             {
  152.                 return false;
  153.             }
  154.             else
  155.             {
  156.                 this._userPassword = DR["userPassword"].ToString();
  157.                 this._roleID = int.Parse(DR["roleID"].ToString());
  158.                 return true;
  159.             }
  160.         }
  161.         public DataSet GetUserInfoByID(string XuserID)
  162.         {
  163.             DataSet ds = new DataSet();
  164.             UserID = XuserID;
  165.             DataBase DB = new DataBase();
  166.             SqlParameter[] Params = new SqlParameter[1];
  167.             Params[0] = DB.MakeInParam("@UserID", SqlDbType.NVarChar, XuserID.Length, UserID);
  168.             ds = DB.GetDataSet("Proc_UsersDetail", Params);
  169.             return ds;
  170.         }
  171.        
  172.         public bool  AddUser(string   XInsertStr)
  173.         {
  174.             DataBase DB = new DataBase();
  175.             int val=DB.ExecuteNonQuery(XInsertStr);
  176.             if (val == 0)
  177.                 return false;
  178.             else
  179.                 return  true;
  180.         }
  181.         public DataSet GetBorrowBook(string userID)
  182.         {
  183.             DataBase DB = new DataBase();
  184.             SqlParameter[] Params = new SqlParameter[] { DB.MakeInParam("@userID", SqlDbType.NVarChar, userID.Length, userID) };
  185.             DataSet ds = DB.GetDataSet("Proc_GetCurrentBorrow", Params);
  186.             return ds;
  187.         }
  188.         /// <summary>
  189.         /// 查询所有注册用户
  190.         /// </summary>
  191.         /// <returns>返回users的结果集</returns>
  192.         public DataSet QueryUsers()
  193.         {
  194.             DataBase DB = new DataBase();   
  195.             DataSet ds = DB.GetDataSet("Proc_GetUsers");
  196.             return ds;
  197.         }
  198.         //删除用户
  199.         //输入:
  200.         //      XUserID - 用户编号;
  201.         //输出:
  202.         //      删除成功:返回True;
  203.         //      删除失败:返回False;
  204.         public bool DeleteByProc(string XUserID)
  205.         {
  206.             SqlParameter[] Params = new SqlParameter[1];
  207.             DataBase DB = new DataBase();
  208.             Params[0] = DB.MakeInParam("@userID", SqlDbType.VarChar, 50, XUserID);               //用户编号          
  209.             int Count = -1;
  210.             Count = DB.RunProc("Proc_DeleteUsers", Params);
  211.             if (Count > 0)
  212.                 return true;
  213.             else 
  214.                 return false;
  215.         }
  216.         //管理员更新用户的信息
  217.         public bool UpdateByProc(string XUserID)
  218.         {
  219.             SqlParameter[] Params = new SqlParameter[6];
  220.             DataBase DB = new DataBase();
  221.             Params[0] = DB.MakeInParam("@userID", SqlDbType.VarChar, 50, XUserID);               //用户编号            
  222.             Params[1] = DB.MakeInParam("@roleID", SqlDbType.SmallInt, 2, RoleID);         //用户权限
  223.             Params[2] = DB.MakeInParam("@userName", SqlDbType.VarChar, 50, UserName);           //用户姓名            
  224.             Params[3] = DB.MakeInParam("@userDepartment", SqlDbType.VarChar, 50, UserDepartment);        //用户系院
  225.             Params[4] = DB.MakeInParam("@userGender", SqlDbType.Bit,2, UserGender); //用户电话
  226.             Params[5] = DB.MakeInParam("@userAddress", SqlDbType.VarChar, 50, UserAddress);         //用户EMail
  227.             int Count = -1;
  228.             Count = DB.RunProc("Proc_UpdateUser", Params);
  229.             if (Count > 0)
  230.                 return true;
  231.             else return false;
  232.         }
  233.         //各个角色共同的修改功能
  234.         public bool UpdateUserComm(string XUserID)
  235.         {
  236.             
  237.             SqlParameter[] Params = new SqlParameter[4];
  238.             DataBase DB = new DataBase();
  239.             Params[0] = DB.MakeInParam("@userID", SqlDbType.VarChar, 50, XUserID);               //用户编号            
  240.             Params[1] = DB.MakeInParam("@userDepartment", SqlDbType.VarChar, 50, UserDepartment);        //用户系院
  241.             Params[2] = DB.MakeInParam("@userAddress", SqlDbType.VarChar, 50, UserAddress);         //用户EMail
  242.             Params[3] = DB.MakeInParam("@userPhone", SqlDbType.VarChar, 50, UserPhone);           //用户姓名            
  243.            
  244.             int Count = -1;
  245.             Count = DB.RunProc("Proc_UpdateUserInfo", Params);
  246.             if (Count > 0)
  247.                 return true;
  248.             else return false;
  249.         }
  250.         public DataSet GetBorrowHistory(string XUserID)
  251.         {
  252.             DataBase DB = new DataBase();
  253.             SqlParameter[] param = new SqlParameter[1];
  254.             param[0] = DB.MakeInParam("@userID", SqlDbType.VarChar, 50, XUserID);
  255.             DataSet ds = new DataSet();
  256.             ds = DB.GetDataSet("Proc_GetBorrowHistory", param);
  257.             return ds;
  258.         }
  259.     }
  260. }