Role.cs
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:2k
源码类别:

Email客户端

开发平台:

Visual C++

  1. /********************************************************************************
  2. ** 作者:ebDoing
  3. ** 创始时间: 2008-10-22
  4. ** 描述:
  5. **    主要用于后台管理员进行用户的角色分配,…
  6. ** 表:
  7. *********************************************************************************/
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11. using System.Data.SqlClient;
  12. using System.Configuration;
  13. namespace background
  14. {
  15.     public class Role
  16.     {
  17.         SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TZroomConnectionString"].ConnectionString);
  18.         /// <summary>
  19.         /// 
  20.         /// </summary>
  21.         /// <param name="name">普通用户的名字</param>
  22.         /// <returns></returns>
  23.         public bool popedom(String name) {
  24.             String T_name = name;
  25.             String sql = "insert into administrator(administrator,password) select UserName,Password from U_Info where UserName='" + T_name + "'";
  26.             SqlCommand cmd = new SqlCommand(sql, conn);
  27.             int Result = -1;
  28.             try
  29.             {
  30.                 conn.Open();
  31.                 Result = cmd.ExecuteNonQuery();
  32.                 int delyes = -1;
  33.                 delyes = del(T_name);
  34.                 if (Result != -1 && delyes != -1)
  35.                 {
  36.                     return true;
  37.                 }
  38.                 else {
  39.                     return false;
  40.                 }
  41.             }
  42.             catch (Exception ex)
  43.             {
  44.                 throw (ex);
  45.             }
  46.             finally {
  47.                 conn.Close();
  48.             }
  49.         }
  50.         public int del(String name) {
  51.             String T_name = name;
  52.             String sql = "delete from U_Info where UserName='" + T_name + "'";
  53.             SqlCommand cmd = new SqlCommand(sql, conn);
  54.             int Result = -1;
  55.             try
  56.             {
  57.                 Result = cmd.ExecuteNonQuery();
  58.                 if (Result != -1)
  59.                 {
  60.                     return 1;
  61.                 }
  62.                 else {
  63.                     return -1;
  64.                 }
  65.             }
  66.             catch (Exception ex)
  67.             {
  68.                 throw (ex);
  69.             }
  70.         }
  71.     }
  72. }