FileRight.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:10k
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Text;
- using qminoa.Common;
- namespace qminoa.DA
- {
- //该类用于处理文件管理的权限问题
- public class FileRight:IDisposable
- {
- private SqlDataAdapter dsCommand;
- public SqlConnection mySqlConnection;
- public static string CONN;
-
- public FileRight()
- {
- CONN=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
- mySqlConnection = new SqlConnection(CONN);
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(true);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (! disposing)
- return;
- if (dsCommand != null)
- {
- if(dsCommand.SelectCommand != null)
- {
- if( dsCommand.SelectCommand.Connection != null )
- dsCommand.SelectCommand.Connection.Dispose();
- dsCommand.SelectCommand.Dispose();
- }
- dsCommand.Dispose();
- dsCommand = null;
- }
- }
- //获得文件的访问权限
- public FileData GetDocCtr(int docid,int empid,int opt)
- {
- mySqlConnection.Open();
- dsCommand = new SqlDataAdapter();
- dsCommand.SelectCommand = mySqlConnection.CreateCommand();
- dsCommand.SelectCommand.CommandText="fmGetDocRight";
- dsCommand.SelectCommand.CommandType=CommandType.StoredProcedure;
- SqlParameterCollection sqlParams = dsCommand.SelectCommand.Parameters;
- sqlParams.Add(new SqlParameter("@docid", SqlDbType.Int));
- sqlParams["@docid"].Value=docid;
- sqlParams.Add(new SqlParameter("@empid", SqlDbType.Int));
- sqlParams["@empid"].Value=empid;
- sqlParams.Add(new SqlParameter("@opt", SqlDbType.Int));
- sqlParams["@opt"].Value=opt;
- dsCommand.SelectCommand.ExecuteNonQuery();
- FileData data = new FileData();
- //填充FileData数据集
- dsCommand.Fill(data,FileData.FMDOCFOLDERCTR_TABLE);
- int count=data.Tables[FileData.FMDOCFOLDERCTR_TABLE].DefaultView.Count;
- mySqlConnection.Close();
- return data;
- }
- //获取文件夹访问权限
- public FileData GetDocFolderCtr(int folderid,int empid,int opt)
- {
- mySqlConnection.Open();
- dsCommand = new SqlDataAdapter();
- dsCommand.SelectCommand = mySqlConnection.CreateCommand();
- dsCommand.SelectCommand.CommandText="fmGetDocFolderCtr";
- dsCommand.SelectCommand.CommandType=CommandType.StoredProcedure;
- SqlParameterCollection sqlParams = dsCommand.SelectCommand.Parameters;
- sqlParams.Add(new SqlParameter("@folderid", SqlDbType.Int));
- sqlParams["@folderid"].Value=folderid;
- sqlParams.Add(new SqlParameter("@empid", SqlDbType.Int));
- sqlParams["@empid"].Value=empid;
- sqlParams.Add(new SqlParameter("@opt", SqlDbType.Int));
- sqlParams["@opt"].Value=opt;
- dsCommand.SelectCommand.ExecuteNonQuery();
- FileData data = new FileData();
- dsCommand.Fill(data,FileData.FMDOCFOLDERCTR_TABLE);
- int count=data.Tables[FileData.FMDOCFOLDERCTR_TABLE].DefaultView.Count;
- mySqlConnection.Close();
- return data;
- }
- //得到部门名称
- public DataSet GetAllUnitName()
- {
- dsCommand = new SqlDataAdapter("fmGetmrDepartment",CONN);
- if (dsCommand == null )
- {
- throw new System.ObjectDisposedException( GetType().FullName );
- }
- DataSet data = new DataSet();
- SqlCommand command = dsCommand.SelectCommand;
- command.CommandText ="fmGetmrDepartment";
- command.CommandType = CommandType.StoredProcedure;
- dsCommand.Fill(data,"unitname");
- return data;
- }
-
- //得到各个部门的用户
- public DataSet GetUser(int Depid,int opt)
- {
- dsCommand = new SqlDataAdapter("fmGetUser",CONN);
- if (dsCommand == null )
- {
- throw new System.ObjectDisposedException( GetType().FullName );
- }
- DataSet data = new DataSet();
- SqlCommand command = dsCommand.SelectCommand;
- command.CommandText ="fmGetUser";
- command.CommandType = CommandType.StoredProcedure;
- SqlParameter param1 = new SqlParameter("@depid", SqlDbType.Int);
- param1.Value = Depid;
- command.Parameters.Add(param1);
- SqlParameter param2 = new SqlParameter("@opt", SqlDbType.Int);
- param2.Value = opt;
- command.Parameters.Add(param2);
- dsCommand.Fill(data,"unitname");
- return data;
- }
- //利用存储过程将数据集中的内容保存到数据库中
- public void SaveDocFolderRight(FileData dataset,int type)
- {
- mySqlConnection.Open();
- SqlCommand command = mySqlConnection.CreateCommand();
- command.CommandText ="fmSaveDocFolderRight";
- command.CommandType =CommandType.StoredProcedure;
- DataTable data =dataset.Tables[FileData.FMDOCFOLDERCTR_TABLE];
- int num=data.Rows.Count;
- SqlParameter param0 = new SqlParameter("@type" ,SqlDbType.Int);
- param0.Value =type;
- command.Parameters.Add(param0);
- SqlParameter param1 = new SqlParameter("@Conid" ,SqlDbType.Int);
- param1.Value =Convert.ToInt32(data.Rows[0][0]);
- command.Parameters.Add(param1);
- SqlParameter param2 = new SqlParameter("@folderid" ,SqlDbType.Int);
- param2.Value =Convert.ToInt32(data.Rows[0][1]);
- command.Parameters.Add(param2);
- SqlParameter param3 = new SqlParameter("@depid" ,SqlDbType.Int);
- param3.Value =Convert.ToInt32(data.Rows[0][2]);
- command.Parameters.Add(param3);
- SqlParameter param4 = new SqlParameter("@empid" ,SqlDbType.Int);
- param4.Value =Convert.ToInt32(data.Rows[0][3]);
- command.Parameters.Add(param4);
- SqlParameter param5 = new SqlParameter("@adminflag" ,SqlDbType.Bit,2);
- param5.Value =Convert.ToByte(data.Rows[0][4]);
- command.Parameters.Add(param5);
- SqlParameter param6 = new SqlParameter("@readflag" ,SqlDbType.Bit,2);
- param6.Value =Convert.ToByte(data.Rows[0][5]);
- command.Parameters.Add(param6);
- SqlParameter param7 = new SqlParameter("@writeflag" ,SqlDbType.Bit,2);
- param7.Value =Convert.ToByte(data.Rows[0][6]);
- command.Parameters.Add(param7);
- command.ExecuteNonQuery();
- mySqlConnection.Close();
- }
-
- //利用存储过程将数据集中的内容保存到数据库中
- public void SaveDocRight(FileData dataset,int type)
- {
- mySqlConnection.Open();
- SqlCommand command = mySqlConnection.CreateCommand();
- command.CommandText ="fmSaveDocRight";
- command.CommandType =CommandType.StoredProcedure;
- DataTable data =dataset.Tables[FileData.FMDOCFOLDERCTR_TABLE];
- int num=data.Rows.Count;
- SqlParameter param0 = new SqlParameter("@type" ,SqlDbType.Int);
- param0.Value =type;
- command.Parameters.Add(param0);
- SqlParameter param1 = new SqlParameter("@Conid" ,SqlDbType.Int);
- param1.Value =Convert.ToInt32(data.Rows[0][0]);
- command.Parameters.Add(param1);
- SqlParameter param2 = new SqlParameter("@docid" ,SqlDbType.Int);
- param2.Value =Convert.ToInt32(data.Rows[0][1]);
- command.Parameters.Add(param2);
- SqlParameter param3 = new SqlParameter("@depid" ,SqlDbType.Int);
- param3.Value =Convert.ToInt32(data.Rows[0][2]);
- command.Parameters.Add(param3);
- SqlParameter param4 = new SqlParameter("@empid" ,SqlDbType.Int);
- param4.Value =Convert.ToInt32(data.Rows[0][3]);
- command.Parameters.Add(param4);
- SqlParameter param5 = new SqlParameter("@adminflag" ,SqlDbType.Bit,2);
- param5.Value =Convert.ToByte(data.Rows[0][4]);
- command.Parameters.Add(param5);
- SqlParameter param6 = new SqlParameter("@readflag" ,SqlDbType.Bit,2);
- param6.Value =Convert.ToByte(data.Rows[0][5]);
- command.Parameters.Add(param6);
- SqlParameter param7 = new SqlParameter("@writeflag" ,SqlDbType.Bit,2);
- param7.Value =Convert.ToByte(data.Rows[0][6]);
- command.Parameters.Add(param7);
- command.ExecuteNonQuery();
- mySqlConnection.Close();
- }
- public static int GetEmpId(string Name)
- {
- int empid=0;
- DataSet data=(new FileRight()).GetUser(0,1);
- //这里就用到了opt参数,opt!=0时取出所有人员的信息
- DataView dvdata=data.Tables[0].DefaultView;
- dvdata.RowFilter="EmpName='"+Name+"'";
- int num=dvdata.Count;
- if(num!=0)
- {
- empid=Convert.ToInt32(dvdata[0].Row[0].ToString(),10);
- }
- else
- {
- //数据库中没有这个人
- }
- return empid;
- }
- public static int Right_GetFolderId(int pkid)
- {
- SqlDataAdapter dsCommand = new SqlDataAdapter("select * from fmDocFolderCtr",CONN);
- dsCommand.SelectCommand.CommandType=CommandType.Text;
- DataSet data = new DataSet();;
- dsCommand.Fill(data);
- DataView dvdata=data.Tables[0].DefaultView;
- dvdata.RowFilter="FolderConId="+pkid;
- int folderid=Convert.ToInt32(dvdata[0].Row[1].ToString(),10);
- return folderid;
- }
- public static int Right_GetDocFolderId(int pkid)
- {
- SqlDataAdapter dsCommand = new SqlDataAdapter("select * from fmDocCtr",CONN);
- dsCommand.SelectCommand.CommandType=CommandType.Text;
- DataSet data = new DataSet();;
- dsCommand.Fill(data);
- DataView dvdata=data.Tables[0].DefaultView;
- dvdata.RowFilter="ConId="+pkid;
- int folderid=Convert.ToInt32(dvdata[0].Row[1].ToString(),10);
- return folderid;
- }
- public int GetDepId(string DepName)
- {
- dsCommand = new SqlDataAdapter("fmGetmrDepartment",CONN);
- dsCommand.SelectCommand.CommandType=CommandType.StoredProcedure;
- DataTable data = new DataTable();
- dsCommand.Fill(data);
- int depid;
- DataView dv=data.DefaultView;
- dv.RowFilter="DepName='"+DepName+"'";
- depid=Convert.ToInt32(dv[0].Row[0].ToString());
- return depid;
- }
- public int GetDepId(int Empid)
- {
- int depid;
- DataSet data=(new FileRight()).GetUser(0,1);
- DataView dvdata=data.Tables[0].DefaultView;
- dvdata.RowFilter="Empid="+Empid;
- depid=Convert.ToInt32(dvdata[0].Row[2].ToString(),10);
- return depid;
- }
- }
- }