AdminDB.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:15k
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- namespace qminoa.DA
- {
- public class AdminDB
- {
- public bool InsertRoleInfo(string RoleName,string RoleDescription)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysInsertRoleInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterRoleName = new SqlParameter("@rolename", SqlDbType.VarChar, 20);
- parameterRoleName.Value = RoleName;
- myCommand.Parameters.Add(parameterRoleName);
- SqlParameter parameterRoleDescription = new SqlParameter("@roledescription", SqlDbType.VarChar, 100);
- parameterRoleDescription.Value = RoleDescription;
- myCommand.Parameters.Add(parameterRoleDescription);
- myConnection.Open();
- int result = myCommand.ExecuteNonQuery();
- myConnection.Close();
- if(result>0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- public bool InsertFuncInfo(string FuncName,string FuncDescription)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysInsertFuncInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterFuncName = new SqlParameter("@Funcname", SqlDbType.VarChar, 20);
- parameterFuncName.Value = FuncName;
- myCommand.Parameters.Add(parameterFuncName);
- SqlParameter parameterFuncDescription = new SqlParameter("@Funcdescription", SqlDbType.VarChar, 100);
- parameterFuncDescription.Value = FuncDescription;
- myCommand.Parameters.Add(parameterFuncDescription);
- myConnection.Open();
- int result = myCommand.ExecuteNonQuery();
- myConnection.Close();
- if(result>0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool UpdateRoleInfo(int roleid, String rolename,String roledes)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysUpdateRoleInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- parameterRoleID.Value = roleid;
- myCommand.Parameters.Add(parameterRoleID);
- SqlParameter parameterRoleName = new SqlParameter("@rolename", SqlDbType.NVarChar, 50);
- parameterRoleName.Value = rolename;
- myCommand.Parameters.Add(parameterRoleName);
- SqlParameter parameterRoleDes = new SqlParameter("@roledes", SqlDbType.NVarChar, 50);
- parameterRoleDes.Value = roledes;
- myCommand.Parameters.Add(parameterRoleDes);
- try
- {
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- catch
- {
- return false;
- }
- return true;
- }
-
- public void UpdateFuncRoleRight(int funcid,int roleid ,int rightflag)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysUpdateFuncRoleRight", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterFuncID = new SqlParameter("@funcid", SqlDbType.Int, 4);
- parameterFuncID.Value = funcid;
- myCommand.Parameters.Add(parameterFuncID);
- SqlParameter parameterRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- parameterRoleID.Value = roleid;
- myCommand.Parameters.Add(parameterRoleID);
- SqlParameter parameterFlag = new SqlParameter("@rightflag", SqlDbType.Int, 4);
- parameterFlag.Value = rightflag;
- myCommand.Parameters.Add(parameterFlag);
-
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- public void UpdateUserInfo(int empid, String loginid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysUpdateEmpInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraEmpID = new SqlParameter("@empid", SqlDbType.Int, 4);
- paraEmpID.Value = empid;
- myCommand.Parameters.Add(paraEmpID);
- SqlParameter paraLoginID = new SqlParameter("@loginid", SqlDbType.NVarChar, 50);
- paraLoginID.Value = loginid;
- myCommand.Parameters.Add(paraLoginID);
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- public void UpdateFuncInfo(int funcid, String funcname ,String funcdes)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysUpdateFuncInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraFuncID = new SqlParameter("@funcid", SqlDbType.Int, 4);
- paraFuncID.Value = funcid;
- myCommand.Parameters.Add(paraFuncID);
- SqlParameter paraFuncName = new SqlParameter("@funcname", SqlDbType.NVarChar, 50);
- paraFuncName.Value = funcname;
- myCommand.Parameters.Add(paraFuncName);
- SqlParameter parameterFuncDes = new SqlParameter("@funcdes", SqlDbType.NVarChar, 50);
- parameterFuncDes.Value = funcdes;
- myCommand.Parameters.Add(parameterFuncDes);
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
-
-
- public SqlDataReader GetUserRoles(int UserId)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetEmpRoles", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraEmpID = new SqlParameter("@empid", SqlDbType.Int, 4);
- paraEmpID.Value = UserId;
- myCommand.Parameters.Add(paraEmpID);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetFuncRole(int funcid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetFuncRoles", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraFuncID = new SqlParameter("@funcid", SqlDbType.Int, 4);
- paraFuncID.Value = funcid;
- myCommand.Parameters.Add(paraFuncID);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetRoleFunc(int roleid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetRoleFunc", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- paraRoleID.Value = roleid;
- myCommand.Parameters.Add(paraRoleID);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetRoleUser(int roleid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetRoleEmp", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- paraRoleID.Value = roleid;
- myCommand.Parameters.Add(paraRoleID);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public void AddUserRole(int EmpId,int RoleId)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysAddEmpRole", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterEmpID = new SqlParameter("@empid", SqlDbType.Int, 4);
- parameterEmpID.Value = EmpId;
- myCommand.Parameters.Add(parameterEmpID);
- SqlParameter parameterRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- parameterRoleID.Value = RoleId;
- myCommand.Parameters.Add(parameterRoleID);
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- public void AddFuncRole(int funcid, int roleid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysAddFuncRole", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterFuncID = new SqlParameter("@funcid", SqlDbType.Int, 4);
- parameterFuncID.Value = funcid;
- myCommand.Parameters.Add(parameterFuncID);
- SqlParameter parameterRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- parameterRoleID.Value = roleid;
- myCommand.Parameters.Add(parameterRoleID);
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- public bool DeleteRoleUser(int EmpId,int RoleId)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysDeleteRoleUser", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterEmpId = new SqlParameter("@empid", SqlDbType.Int, 4);
- parameterEmpId.Value = EmpId;
- myCommand.Parameters.Add(parameterEmpId);
- SqlParameter parameterRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- parameterRoleID.Value = RoleId;
- myCommand.Parameters.Add(parameterRoleID);
- try
- {
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- catch
- {
- return false;
- }
- return true;
- }
-
- public bool DeleteFuncRole(int FuncID,int RoleId)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysDeleteFuncRole", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter parameterFuncID = new SqlParameter("@funcid", SqlDbType.Int, 4);
- parameterFuncID.Value = FuncID;
- myCommand.Parameters.Add(parameterFuncID);
- SqlParameter parameterRoleID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- parameterRoleID.Value = RoleId;
- myCommand.Parameters.Add(parameterRoleID);
- try
- {
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- catch
- {
- return false;
- }
- return true;
- }
-
- public SqlDataReader GetEmpInfo(int pkid ,String type)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetEmpByType", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraID = new SqlParameter("@pkid", SqlDbType.Int, 4);
- paraID.Value = pkid;
- myCommand.Parameters.Add( paraID);
- SqlParameter paraType = new SqlParameter("@type", SqlDbType.VarChar,10);
- paraType.Value = type;
- myCommand.Parameters.Add( paraType);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public bool DeleteFuncRoleUser(int pkid,String type)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysDeleteFuncRoleUser", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraID = new SqlParameter("@pkid", SqlDbType.Int, 4);
- paraID.Value = pkid;
- myCommand.Parameters.Add(paraID);
- SqlParameter paraType = new SqlParameter("@type", SqlDbType.VarChar,10);
- paraType.Value = type;
- myCommand.Parameters.Add( paraType);
- try
- {
- myConnection.Open();
- myCommand.ExecuteNonQuery();
- myConnection.Close();
- }
- catch
- {
- return false;
- }
- return true;
- }
-
- public SqlDataReader GetFuncInfo(int funcid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetFuncInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraID = new SqlParameter("@funcid", SqlDbType.Int, 4);
- paraID.Value = funcid;
- myCommand.Parameters.Add( paraID);
-
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetRoleInfo(int roleid)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetRoleInfo", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraID = new SqlParameter("@roleid", SqlDbType.Int, 4);
- paraID.Value = roleid;
- myCommand.Parameters.Add( paraID);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetAllFuncs()
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetAllFuncs", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetAllRoles()
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetAllRoles", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetAllBranch()
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetAllBranch", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- public SqlDataReader GetDepByBranch(int BranchID)
- {
- SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand myCommand = new SqlCommand("sysGetDepByBranch", myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter paraBranchID = new SqlParameter("@branchid", SqlDbType.Int, 4);
- paraBranchID.Value = BranchID;
- myCommand.Parameters.Add( paraBranchID);
- myConnection.Open();
- SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
- return dr;
- }
- }
- }