|
|
using System;
|
|
|
using System.Data;
|
|
|
using System.Configuration;
|
|
|
using System.Data.SqlClient;
|
|
|
using System.Text;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using DSWeb.Models;
|
|
|
using DSWeb.DataAccess;
|
|
|
|
|
|
namespace DSWeb.EntityDA
|
|
|
{
|
|
|
public class SysDeptDA
|
|
|
{
|
|
|
private const string PARM_SysDept_GID = "@gid";
|
|
|
private const string PARM_SysDept_COMPANY_ID = "@company_id";
|
|
|
private const string PARM_USER_BASEINFO_USER_ID = "@user_id";
|
|
|
|
|
|
private const string SQL_SELECT_SysDept_ALL = " SELECT GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,FINANCESOFTCODE FROM sys_dept order by DEPTNO";
|
|
|
|
|
|
private const string SQL_SELECT_SysDept_BY_COMPANY_ID = " SELECT GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,FINANCESOFTCODE FROM sys_dept WHERE LINKID = @company_id order by DEPTNO";
|
|
|
|
|
|
private const string SQL_SELECT_SysDept_BYGID = " SELECT GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,FINANCESOFTCODE FROM sys_dept WHERE GID = @gid";
|
|
|
|
|
|
private const string SQL_SELECT_SysDept_TOP1 = " SELECT top 1 GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,FINANCESOFTCODE FROM sys_dept order by DEPTNO";
|
|
|
|
|
|
private string strSqlInsertInfo = "insert into [sys_dept](GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,REMARK,CREATEUSER,MODIFIEDUSER,FINANCESOFTCODE) values(@GID,@LINKID,@DEPTNO,@DEPTNAME,@MANAGE1,@MANAGE2,@REMARK,@CREATEUSER,@MODIFIEDUSER,@FINANCESOFTCODE)";
|
|
|
|
|
|
private string strSqlUpdateInfo = "update [sys_dept] set LINKID=@LINKID,DEPTNO=@DEPTNO,DEPTNAME=@DEPTNAME,MANAGE1=@MANAGE1,MANAGE2=@MANAGE2,REMARK=@REMARK,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=GETDATE(),FINANCESOFTCODE=@FINANCESOFTCODE where GID=@GID";
|
|
|
|
|
|
private const string SQL_DELETE_SysDept_BY_GID = "DELETE FROM sys_dept WHERE GID = @gid";
|
|
|
|
|
|
private const string SQL_SELECT_SysDept_BY_USERID = " SELECT B.GID FROM user_baseinfo as A INNER JOIN sys_dept as B ON A.DEPTNAME = B.DEPTNAME INNER JOIN user_company as C ON A.USERID = C.USERID WHERE A.USERID = @user_id ";
|
|
|
|
|
|
private string SQL_SELECT_SYS_DEPT_BY_DEPTNAME = " SELECT GID,LINKID,DEPTNO,DEPTNAME FROM sys_dept WHERE DEPTNAME LIKE '%{0}%'";
|
|
|
|
|
|
#region 获取所有部门信息
|
|
|
/// <summary>
|
|
|
/// 获取所有部门信息
|
|
|
/// </summary>
|
|
|
/// <returns>返回所有部门实体类</returns>
|
|
|
public IList<SysDeptEntity> GetAllSysDept()
|
|
|
{
|
|
|
IList<SysDeptEntity> SysDeptEntites = new List<SysDeptEntity>();
|
|
|
SysDeptEntity SysDeptEntity = null;
|
|
|
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SysDept_ALL, null))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
while (sqlRead.Read())
|
|
|
{
|
|
|
SysDeptEntity = new SysDeptEntity();
|
|
|
if (!sqlRead.IsDBNull(0))
|
|
|
{
|
|
|
SysDeptEntity.GID = sqlRead.GetString(0);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(1))
|
|
|
{
|
|
|
SysDeptEntity.LINKID = sqlRead.GetString(1);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(2))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNO = sqlRead.GetString(2);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(3))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNAME = sqlRead.GetString(3);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(4))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE1 = sqlRead.GetString(4);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(5))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE2 = sqlRead.GetString(5);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(6))
|
|
|
{
|
|
|
SysDeptEntity.REMARK = sqlRead.GetString(6);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(7))
|
|
|
{
|
|
|
SysDeptEntity.CREATEUSER = sqlRead.GetString(7);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(8))
|
|
|
{
|
|
|
SysDeptEntity.CREATETIME = sqlRead.GetDateTime(8);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(9))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDUSER = sqlRead.GetString(9);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(10))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDTIME = sqlRead.GetDateTime(10);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(11))
|
|
|
{
|
|
|
SysDeptEntity.FINANCESOFTCODE = sqlRead.GetString(11);
|
|
|
}
|
|
|
SysDeptEntites.Add(SysDeptEntity);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
throw execError;
|
|
|
}
|
|
|
}
|
|
|
return SysDeptEntites;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 通过部门名称进行模糊检索
|
|
|
/// <summary>
|
|
|
/// 通过部门名称进行模糊检索
|
|
|
/// </summary>
|
|
|
/// <param name="tempSysDeptName">部门名称</param>
|
|
|
/// <returns>返回检索之后的部门信息实体类组</returns>
|
|
|
public IList<SysDeptEntity> GetDeptsByDeptName(string tempSysDeptName)
|
|
|
{
|
|
|
IList<SysDeptEntity> sysDeptEntities = new List<SysDeptEntity>();
|
|
|
|
|
|
string strSql = String.Format(SQL_SELECT_SYS_DEPT_BY_DEPTNAME, tempSysDeptName);
|
|
|
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
while (sqlRead.Read())
|
|
|
{
|
|
|
SysDeptEntity sysDeptEntity = new SysDeptEntity();
|
|
|
if (!sqlRead.IsDBNull(0))
|
|
|
{
|
|
|
sysDeptEntity.GID = sqlRead.GetString(0);
|
|
|
}
|
|
|
|
|
|
if (!sqlRead.IsDBNull(1))
|
|
|
{
|
|
|
sysDeptEntity.LINKID = sqlRead.GetString(1);
|
|
|
}
|
|
|
|
|
|
if (!sqlRead.IsDBNull(2))
|
|
|
{
|
|
|
sysDeptEntity.DEPTNO = sqlRead.GetString(2);
|
|
|
}
|
|
|
|
|
|
if (!sqlRead.IsDBNull(3))
|
|
|
{
|
|
|
sysDeptEntity.DEPTNAME = sqlRead.GetString(3);
|
|
|
}
|
|
|
|
|
|
sysDeptEntities.Add(sysDeptEntity);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
throw execError;
|
|
|
}
|
|
|
}
|
|
|
return sysDeptEntities;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 通过用户的部门GID
|
|
|
/// <summary>
|
|
|
/// 通过用户的部门GID
|
|
|
/// </summary>
|
|
|
/// <param name="tempUserID">用户GID</param>
|
|
|
/// <returns>返回用户部门的GID</returns>
|
|
|
public string GetDepartmentIdByUser(string tempUserID)
|
|
|
{
|
|
|
string strResult = "";
|
|
|
|
|
|
SqlParameter parm = new SqlParameter(PARM_USER_BASEINFO_USER_ID, SqlDbType.VarChar, 36);
|
|
|
parm.Value = tempUserID;
|
|
|
using (SqlConnection sqlConnection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
strResult = (string)SqlHelper.ExecuteScalar(sqlConnection, CommandType.Text, SQL_SELECT_SysDept_BY_USERID, parm) as string;
|
|
|
|
|
|
if (strResult == null)
|
|
|
{
|
|
|
strResult = "";
|
|
|
}
|
|
|
}
|
|
|
return strResult;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 公司内所有部门信息
|
|
|
/// <summary>
|
|
|
/// 公司内所有部门信息
|
|
|
/// </summary>
|
|
|
/// <returns>返回部门内所有部门的实体类</returns>
|
|
|
public IList<SysDeptEntity> GetDepartmentByCompanyID(string tempCompanyID)
|
|
|
{
|
|
|
IList<SysDeptEntity> SysDeptEntites = new List<SysDeptEntity>();
|
|
|
|
|
|
|
|
|
SqlParameter parm = new SqlParameter(PARM_SysDept_COMPANY_ID, SqlDbType.VarChar, 36);
|
|
|
|
|
|
parm.Value = tempCompanyID;
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SysDept_BY_COMPANY_ID, parm))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
while (sqlRead.Read())
|
|
|
{
|
|
|
SysDeptEntity sysDeptEntity = new SysDeptEntity();
|
|
|
if (!sqlRead.IsDBNull(0))
|
|
|
{
|
|
|
sysDeptEntity.GID = sqlRead.GetString(0);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(1))
|
|
|
{
|
|
|
sysDeptEntity.LINKID = sqlRead.GetString(1);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(2))
|
|
|
{
|
|
|
sysDeptEntity.DEPTNO = sqlRead.GetString(2);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(3))
|
|
|
{
|
|
|
sysDeptEntity.DEPTNAME = sqlRead.GetString(3);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(4))
|
|
|
{
|
|
|
sysDeptEntity.MANAGE1 = sqlRead.GetString(4);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(5))
|
|
|
{
|
|
|
sysDeptEntity.MANAGE2 = sqlRead.GetString(5);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(6))
|
|
|
{
|
|
|
sysDeptEntity.REMARK = sqlRead.GetString(6);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(7))
|
|
|
{
|
|
|
sysDeptEntity.CREATEUSER = sqlRead.GetString(7);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(8))
|
|
|
{
|
|
|
sysDeptEntity.CREATETIME = sqlRead.GetDateTime(8);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(9))
|
|
|
{
|
|
|
sysDeptEntity.MODIFIEDUSER = sqlRead.GetString(9);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(10))
|
|
|
{
|
|
|
sysDeptEntity.MODIFIEDTIME = sqlRead.GetDateTime(10);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(11))
|
|
|
{
|
|
|
sysDeptEntity.FINANCESOFTCODE = sqlRead.GetString(11);
|
|
|
}
|
|
|
SysDeptEntites.Add(sysDeptEntity);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
throw execError;
|
|
|
}
|
|
|
}
|
|
|
return SysDeptEntites;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 根据公司GID获取公司信息
|
|
|
/// <summary>
|
|
|
/// 根据公司GID获取公司信息
|
|
|
/// </summary>
|
|
|
/// <param name="strGid"></param>
|
|
|
/// <returns></returns>
|
|
|
public SysDeptEntity GetSysDeptByID(string strGid)
|
|
|
{
|
|
|
SysDeptEntity SysDeptEntity = null;
|
|
|
|
|
|
SqlParameter parm = new SqlParameter(PARM_SysDept_GID, SqlDbType.VarChar, 36);
|
|
|
parm.Value = strGid;
|
|
|
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SysDept_BYGID, parm))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
while (sqlRead.Read())
|
|
|
{
|
|
|
SysDeptEntity = new SysDeptEntity();
|
|
|
if (!sqlRead.IsDBNull(0))
|
|
|
{
|
|
|
SysDeptEntity.GID = sqlRead.GetString(0);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(1))
|
|
|
{
|
|
|
SysDeptEntity.LINKID = sqlRead.GetString(1);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(2))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNO = sqlRead.GetString(2);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(3))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNAME = sqlRead.GetString(3);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(4))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE1 = sqlRead.GetString(4);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(5))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE2 = sqlRead.GetString(5);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(6))
|
|
|
{
|
|
|
SysDeptEntity.REMARK = sqlRead.GetString(6);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(7))
|
|
|
{
|
|
|
SysDeptEntity.CREATEUSER = sqlRead.GetString(7);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(8))
|
|
|
{
|
|
|
SysDeptEntity.CREATETIME = sqlRead.GetDateTime(8);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(9))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDUSER = sqlRead.GetString(9);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(10))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDTIME = sqlRead.GetDateTime(10);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(11))
|
|
|
{
|
|
|
SysDeptEntity.FINANCESOFTCODE = sqlRead.GetString(11);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
throw execError;
|
|
|
}
|
|
|
}
|
|
|
return SysDeptEntity;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 根据公司GID获取公司信息
|
|
|
/// <summary>
|
|
|
/// 根据公司GID获取公司信息
|
|
|
/// </summary>
|
|
|
/// <param name="strGid"></param>
|
|
|
/// <returns></returns>
|
|
|
public SysDeptEntity GetSysDeptTop1()
|
|
|
{
|
|
|
SysDeptEntity SysDeptEntity = null;
|
|
|
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_SysDept_TOP1, null))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
while (sqlRead.Read())
|
|
|
{
|
|
|
SysDeptEntity = new SysDeptEntity();
|
|
|
if (!sqlRead.IsDBNull(0))
|
|
|
{
|
|
|
SysDeptEntity.GID = sqlRead.GetString(0);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(1))
|
|
|
{
|
|
|
SysDeptEntity.LINKID = sqlRead.GetString(1);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(2))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNO = sqlRead.GetString(2);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(3))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNAME = sqlRead.GetString(3);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(4))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE1 = sqlRead.GetString(4);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(5))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE2 = sqlRead.GetString(5);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(6))
|
|
|
{
|
|
|
SysDeptEntity.REMARK = sqlRead.GetString(6);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(7))
|
|
|
{
|
|
|
SysDeptEntity.CREATEUSER = sqlRead.GetString(7);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(8))
|
|
|
{
|
|
|
SysDeptEntity.CREATETIME = sqlRead.GetDateTime(8);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(9))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDUSER = sqlRead.GetString(9);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(10))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDTIME = sqlRead.GetDateTime(10);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(11))
|
|
|
{
|
|
|
SysDeptEntity.FINANCESOFTCODE = sqlRead.GetString(11);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
throw execError;
|
|
|
}
|
|
|
}
|
|
|
return SysDeptEntity;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
/// 插入信息
|
|
|
/// </summary>
|
|
|
/// <param name="SysDeptEntity">实体类</param>
|
|
|
/// <returns>值为1插入数据正常,-1操作异常</returns>
|
|
|
public int InserInfo(SysDeptEntity infoEntity)
|
|
|
{
|
|
|
int iResult = 0;
|
|
|
//获取参数
|
|
|
SqlParameter[] parms = GetInsertParms();
|
|
|
parms[0].Value = infoEntity.GID;//惟一编号
|
|
|
parms[1].Value = infoEntity.LINKID;//公司关联id
|
|
|
parms[2].Value = infoEntity.DEPTNO;//代码
|
|
|
parms[3].Value = infoEntity.DEPTNAME;//名称
|
|
|
parms[4].Value = infoEntity.MANAGE1;//经理
|
|
|
parms[5].Value = infoEntity.MANAGE2;//副经理
|
|
|
parms[6].Value = infoEntity.REMARK;//备注
|
|
|
parms[7].Value = infoEntity.CREATEUSER;//创建人gid
|
|
|
parms[8].Value = infoEntity.MODIFIEDUSER;//更新人gid
|
|
|
parms[9].Value = infoEntity.FINANCESOFTCODE;//
|
|
|
//parms[9].Value = infoEntity.MODIFIEDTIME;//更新时间
|
|
|
//parms[10].Value = infoEntity.CREATETIME;//创建时间
|
|
|
|
|
|
strSqlInsertInfo = String.Format(strSqlInsertInfo);
|
|
|
//
|
|
|
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlInsertInfo, parms);
|
|
|
if (existVal > 0)
|
|
|
{
|
|
|
iResult = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
iResult = -1;//执行异常
|
|
|
}
|
|
|
}
|
|
|
return iResult;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新信息
|
|
|
/// </summary>
|
|
|
/// <param name="SysDeptEntity">实体类</param>
|
|
|
/// <returns>值为1更新数据正常,-1操作异常</returns>
|
|
|
public int UpdateInfo(SysDeptEntity infoEntity)
|
|
|
{
|
|
|
int iResult = 0;
|
|
|
//获取参数
|
|
|
SqlParameter[] parms = GetUpdateParms();
|
|
|
parms[0].Value = infoEntity.GID;//惟一编号
|
|
|
parms[1].Value = infoEntity.LINKID;//公司关联id
|
|
|
parms[2].Value = infoEntity.DEPTNO;//代码
|
|
|
parms[3].Value = infoEntity.DEPTNAME;//名称
|
|
|
parms[4].Value = infoEntity.MANAGE1;//经理
|
|
|
parms[5].Value = infoEntity.MANAGE2;//副经理
|
|
|
parms[6].Value = infoEntity.REMARK;//备注
|
|
|
parms[7].Value = infoEntity.MODIFIEDUSER;//更新人gid
|
|
|
parms[8].Value = infoEntity.FINANCESOFTCODE;//
|
|
|
//parms[8].Value = infoEntity.CREATEUSER;//创建人gid
|
|
|
//parms[9].Value = infoEntity.MODIFIEDTIME;//更新时间
|
|
|
//parms[10].Value = infoEntity.CREATETIME;//创建时间
|
|
|
//
|
|
|
//string strMODIFIEDTIME = infoEntity.MODIFIEDTIME.ToString().IndexOf("0001")>-1 ? "null" : "'" + infoEntity.MODIFIEDTIME.ToString() + "'";
|
|
|
//string strMODIFIEDTIME_name = "MODIFIEDTIME="; //strETA.Equals("") ? "" : "ETA=";
|
|
|
//
|
|
|
strSqlUpdateInfo = String.Format(strSqlUpdateInfo);//, strMODIFIEDTIME_name, strMODIFIEDTIME);
|
|
|
//
|
|
|
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlUpdateInfo, parms);
|
|
|
if (existVal > 0)
|
|
|
{
|
|
|
iResult = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
iResult = -1;//执行异常
|
|
|
}
|
|
|
}
|
|
|
return iResult;
|
|
|
}
|
|
|
|
|
|
#region 生成插入语句参数
|
|
|
/// <summary>
|
|
|
/// 生成插入语句参数
|
|
|
/// </summary>
|
|
|
/// <returns>返回SqlParameter数组</returns>
|
|
|
private SqlParameter[] GetInsertParms()
|
|
|
{
|
|
|
SqlParameter[] parms = new SqlParameter[]
|
|
|
{
|
|
|
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
|
|
|
new SqlParameter("@LINKID",SqlDbType.VarChar,36),//公司关联id
|
|
|
new SqlParameter("@DEPTNO",SqlDbType.VarChar,20),//代码
|
|
|
new SqlParameter("@DEPTNAME",SqlDbType.VarChar,100),//名称
|
|
|
new SqlParameter("@MANAGE1",SqlDbType.VarChar,100),//经理
|
|
|
new SqlParameter("@MANAGE2",SqlDbType.VarChar,100),//副经理
|
|
|
new SqlParameter("@REMARK",SqlDbType.VarChar,100),//备注
|
|
|
new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人gid
|
|
|
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//更新人gid
|
|
|
new SqlParameter("@FINANCESOFTCODE",SqlDbType.VarChar,20)//
|
|
|
//new SqlParameter("@MODIFIEDTIME",SqlDbType.datetime),//更新时间
|
|
|
//new SqlParameter("@CREATETIME",SqlDbType.datetime),//创建时间
|
|
|
};
|
|
|
return parms;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 生成更新语句参数
|
|
|
/// <summary>
|
|
|
/// 生成更新语句参数
|
|
|
/// </summary>
|
|
|
/// <returns>返回SqlParameter数组</returns>
|
|
|
private SqlParameter[] GetUpdateParms()
|
|
|
{
|
|
|
SqlParameter[] parms = new SqlParameter[]{
|
|
|
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
|
|
|
new SqlParameter("@LINKID",SqlDbType.VarChar,36),//公司关联id
|
|
|
new SqlParameter("@DEPTNO",SqlDbType.VarChar,20),//代码
|
|
|
new SqlParameter("@DEPTNAME",SqlDbType.VarChar,100),//名称
|
|
|
new SqlParameter("@MANAGE1",SqlDbType.VarChar,100),//经理
|
|
|
new SqlParameter("@MANAGE2",SqlDbType.VarChar,100),//副经理
|
|
|
new SqlParameter("@REMARK",SqlDbType.VarChar,100),//备注
|
|
|
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//更新人gid
|
|
|
new SqlParameter("@FINANCESOFTCODE",SqlDbType.VarChar,20)//
|
|
|
//new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人gid
|
|
|
//new SqlParameter("@MODIFIEDTIME",SqlDbType.DateTime),//更新时间
|
|
|
//new SqlParameter("@CREATETIME",SqlDbType.datetime),//创建时间
|
|
|
};
|
|
|
return parms;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 返回数据集 公司表(SysDept)信息
|
|
|
/// <summary>
|
|
|
/// 返回 公司表(SysDept)信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public DataSet GetSysDeptSQL(string strSQL)
|
|
|
{
|
|
|
string str = "select * from [sys_dept] where 1=1 " + strSQL;
|
|
|
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
|
|
|
try
|
|
|
{
|
|
|
if (DS.Tables[0].Rows.Count <= 0)
|
|
|
{
|
|
|
DS = null;
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
DS = null;
|
|
|
}
|
|
|
return DS;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 返回数据集 公司表(SysDept)信息
|
|
|
/// 返回 公司表(SysDept)删除
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
/// <summary>
|
|
|
public String GetSysDeptDel(string strGid, string strUserID)
|
|
|
{
|
|
|
string alt = "";
|
|
|
string str = "update sys_dept set ISDELETED=1 where Gid='" + strGid + "'";
|
|
|
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str);
|
|
|
if (bl == false)
|
|
|
{
|
|
|
alt = "部门表(sys_dept)删除操作出错!";
|
|
|
return alt;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//string str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除部门表(sys_dept)的信息','更新操作','" + str + "','" + strUserID + "')";
|
|
|
//bool bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1);
|
|
|
}
|
|
|
return alt;
|
|
|
}
|
|
|
#endregion
|
|
|
/// <summary>
|
|
|
/// 根据SQL语句查询部门数据集
|
|
|
/// </summary>
|
|
|
/// <param name="strSql"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataSet GetExcuteSql(string strSql)
|
|
|
{
|
|
|
DataSet userSet = new DataSet();
|
|
|
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
|
|
|
return userSet;
|
|
|
}
|
|
|
#region 插入部门列表信息
|
|
|
/// <summary>
|
|
|
/// 插入部门列表信息
|
|
|
/// </summary>
|
|
|
/// <param name="sqlList">插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
|
|
|
/// <returns>返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0</returns>
|
|
|
public int InsertSysDeptFromGrid(ArrayList sqlList)
|
|
|
{
|
|
|
int result = 0;
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < sqlList.Count; i++)
|
|
|
{
|
|
|
string strUpdateSql = sqlList[i].ToString();
|
|
|
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
|
|
|
}
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
result = 1;//状态为1表示插入成功
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
result = -1;//有异常,插入失败
|
|
|
sqlTran.Rollback();
|
|
|
result = -2;//插入异常,事务已回滚成功
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
#region 更新部门列表信息
|
|
|
/// <summary>
|
|
|
/// 更新部门列表信息
|
|
|
/// </summary>
|
|
|
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
|
|
|
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
|
|
|
public int UpdateSysDeptFromGrid(ArrayList sqlList)
|
|
|
{
|
|
|
int result = 0;
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < sqlList.Count; i++)
|
|
|
{
|
|
|
string strUpdateSql = sqlList[i].ToString();
|
|
|
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
|
|
|
}
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
result = 1;//状态为1表示更新成功
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
result = -1;//有异常,更新失败
|
|
|
sqlTran.Rollback();
|
|
|
result = -2;//更新异常,事务已回滚成功
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
#region 通过关联编号LINKID与部门类型获取部门信息
|
|
|
/// <summary>
|
|
|
/// 通过关联编号LINKID与部门类型获取部门信息
|
|
|
/// </summary>
|
|
|
/// <param name="strGID"></param>
|
|
|
/// <returns></returns>
|
|
|
public SysDeptEntity GetSysDeptByLINKIDAndType(string strLINKID)
|
|
|
{
|
|
|
SysDeptEntity SysDeptEntity = null;
|
|
|
|
|
|
string strSql = " SELECT top 1 GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,FINANCESOFTCODE FROM sys_dept WHERE LINKID = '" + strLINKID + "'";
|
|
|
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
|
|
|
{
|
|
|
|
|
|
try
|
|
|
{
|
|
|
while (sqlRead.Read())
|
|
|
{
|
|
|
SysDeptEntity = new SysDeptEntity();
|
|
|
if (!sqlRead.IsDBNull(0))
|
|
|
{
|
|
|
SysDeptEntity.GID = sqlRead.GetString(0);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(1))
|
|
|
{
|
|
|
SysDeptEntity.LINKID = sqlRead.GetString(1);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(2))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNO = sqlRead.GetString(2);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(3))
|
|
|
{
|
|
|
SysDeptEntity.DEPTNAME = sqlRead.GetString(3);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(4))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE1 = sqlRead.GetString(4);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(5))
|
|
|
{
|
|
|
SysDeptEntity.MANAGE2 = sqlRead.GetString(5);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(6))
|
|
|
{
|
|
|
SysDeptEntity.REMARK = sqlRead.GetString(6);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(7))
|
|
|
{
|
|
|
SysDeptEntity.CREATEUSER = sqlRead.GetString(7);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(8))
|
|
|
{
|
|
|
SysDeptEntity.CREATETIME = sqlRead.GetDateTime(8);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(9))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDUSER = sqlRead.GetString(9);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(10))
|
|
|
{
|
|
|
SysDeptEntity.MODIFIEDTIME = sqlRead.GetDateTime(10);
|
|
|
}
|
|
|
if (!sqlRead.IsDBNull(11))
|
|
|
{
|
|
|
SysDeptEntity.FINANCESOFTCODE = sqlRead.GetString(11);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
throw execError;
|
|
|
}
|
|
|
}
|
|
|
return SysDeptEntity;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 通过部门GID删除单条部门
|
|
|
public int DeleteSysDeptByGid(string tempGid)
|
|
|
{
|
|
|
int result = 0;
|
|
|
SqlParameter parm = new SqlParameter(PARM_SysDept_GID, SqlDbType.VarChar, 36);
|
|
|
parm.Value = tempGid;
|
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_SysDept_BY_GID, parm);
|
|
|
|
|
|
result = 1;//状态为1表示删除成功
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception execError)
|
|
|
{
|
|
|
result = -1;//有异常,插入失败
|
|
|
sqlTran.Rollback();
|
|
|
result = -2;//插入异常,事务已回滚成功
|
|
|
throw execError;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|