You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2288 lines
96 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using System.IO;
using DSWeb.Models;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace DSWeb.EntityDA
{
public class UserDA
{
#region 用户登录信息
private const string PARM_USER_GID = "@gid";
private const string PARM_USER_USERNAME = "@username";
private const string PARM_USER_CODENAME = "@codename";
private const string PARM_USER_PASSWORD = "@password";
private const string PARM_USER_SHOWNAME = "@showname";
private const string PARM_USER_ENROLLTIME = "@enrolltime";
private const string PARM_USER_CREATEBY = "@create_userid";
private const string PARM_USER_ISDELETE = "@is_deleted";
private const string PARM_USER_ISDISABLE = "@is_disable";
private const string PARM_USER_MODIFIEDUSER = "@MODIFIEDUSER";
private const string PARM_USER_DELETEUSER = "@delete_user";
private const string PARM_USER_DELETETIME = "@delete_time";
#endregion
#region 用户基本信息
private const string PARM_BASEINFO_GID = "@base_gid";
private const string PARM_BASEINFO_USERID = "@userid";
private const string PARM_BASEINFO_OFFICEPHONE = "@office_phone_num";
private const string PARM_BASEINFO_HOMEPHONE = "@home_phone_num";
private const string PARM_BASEINFO_MOBILE = "@mobile_phone_num";
private const string PARM_BASEINFO_FAX = "@fax_num";
private const string PARM_BASEINFO_EMAIL_1 = "@email_addr_p";
private const string PARM_BASEINFO_EMAIL_2 = "@email_addr_s";
private const string PARM_BASEINFO_HOMEADDR = "@home_addr";
private const string PARM_BASEINFO_REMARKS = "@remarks";
private const string PARM_BASEINFO_CREATEBY = "@create_userid";
private const string PARM_BASEINFO_CREATETIME = "@create_time";
private const string PARM_BASEINFO_MODIFIEDBY = "@modified_userid";
private const string PARM_BASEINFO_MODIFIEDTIME = "@modified_time";
private const string PARM_BASEINFO_EMERGUSER = "@emergency_user";
private const string PARM_BASEINFO_EMERGPHONE = "@emergency_phone";
private const string PARM_BASEINFO_EMERGEMAIL = "@emergency_email";
private const string PARM_BASEINFO_COMPANYNAME = "@COMPANYNAME";
private const string PARM_BASEINFO_DEPTNAME = "@DEPTNAME";
private const string PARM_BASEINFO_QQ = "@QQ";
private const string PARM_BASEINFO_MSN = "@MSN";
private const string PARM_BASEINFO_CONTRACTDATE = "@CONTRACTDATE";
private const string PARM_BASEINFO_TRIALTIME = "@TRIALTIME";
private const string PARM_BASEINFO_IDNUM = "@IDNUM";
private const string PARM_BASEINFO_EDURECORD = "@EDURECORD";
private const string PARM_BASEINFO_ANNUALLEAVE = "@ANNUALLEAVE";
//user_company
private const string PARM_USER_COMPANY_COMPANY_ID = "@company_id";
//company
private const string PARM_COMPANY_CODE_NAME = "@company_code_name";
#endregion
private const string PARM_MOBILE = "@MOBILE";
//只查询账户登录信息表
private const string SQL_SELECT_USERS_NO_BASEINFO = "SELECT GID,USERNAME,CODENAME,PASSWORD,SHOWNAME,ENROLLTIME,CREATEUSER,MODIFIEDUSER,MODIFIEDTIME,ISDELETED,ISDISABLE FROM [user] WHERE gid = @gid and ISDELETED=0";
//@showname查询账户登录信息表和账户基本信息表
private const string SQL_SELECT_USER_BASEINFO_SHOWNAME = " SELECT top 1 A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE, B.GID as BaseGid,B.OFFICEPHONE,B.HOMEPHONE,B.MOBILE,B.FAX,B.EMAIL1,B.EMAIL2,B.HOMEADDRESS,B.REMARK,B.CREATEUSER, B.CREATETIME,B.MODIFIEDUSER,B.MODIFIEDTIME,B.EMERGUSER,B.EMERGPHONE,B.EMERGEMAIL,B.POSTCODE,B.COMPANYNAME,B.DEPTNAME,B.QQ,B.MSN,B.SIGNATURE,B.FINANCESOFTCODE,B.IMAGEURL,B.SIGNATUREURL,dbo.trimdate(B.CONTRACTDATE) CONTRACTDATE,B.TRIALTIME, B.IDNUM, B.EDURECORD, B.ANNUALLEAVE FROM [user] AS A INNER JOIN user_baseinfo as B ON A.GID = B.USERID AND A.showname = @showname and A.ISDELETED=0 order by A.codename";
//@userid查询账户登录信息表和账户基本信息表
private const string SQL_SELECT_USER_BASEINFO = " SELECT A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE, B.GID as BaseGid,B.OFFICEPHONE,B.HOMEPHONE,B.MOBILE,B.FAX,B.EMAIL1,B.EMAIL2,B.HOMEADDRESS,B.REMARK,B.CREATEUSER, B.CREATETIME,B.MODIFIEDUSER,B.MODIFIEDTIME,B.EMERGUSER,B.EMERGPHONE,B.EMERGEMAIL,B.POSTCODE,B.COMPANYNAME,B.DEPTNAME,B.QQ,B.MSN,B.SIGNATURE,B.FINANCESOFTCODE,B.IMAGEURL,B.SIGNATUREURL,dbo.trimdate(B.CONTRACTDATE) CONTRACTDATE,B.TRIALTIME, B.IDNUM, B.EDURECORD, B.ANNUALLEAVE FROM [user] AS A INNER JOIN user_baseinfo as B ON A.GID = B.USERID AND A.GID = @userid and A.ISDELETED=0 order by A.codename";
//只查询账户基本信息表
private const string SQL_SELECT_BASEINFO = " SELECT GID,USERID,OFFICEPHONE,HOMEPHONE,MOBILE,FAX,EMAIL1,EMAIL2,HOMEADDRESS,REMARK,CREATEUSER,CREATETIME, MODIFIEDUSER,MODIFIEDTIME,EMERGUSER,EMERGPHONE,EMERGEMAIL,POSTCODE,COMPANYNAME,DEPTNAME,QQ,MSN,SIGNATURE,FINANCESOFTCODE,IMAGEURL,SIGNATUREURL,dbo.trimdate(CONTRACTDATE) CONTRACTDATE,TRIALTIME, IDNUM, EDURECORD, ANNUALLEAVE FROM user_baseinfo WHERE user_id = @userid ";
//只查询所有账户登录信息表
private const string SQL_SELECT_USERS_ALL = " SELECT GID,USERNAME,CODENAME,PASSWORD,SHOWNAME,CREATEUSER,MODIFIEDUSER,MODIFIEDTIME,ISDELETED,ISDIABLE FROM [user] where ISDELETED=0 order by codename ";
private string SQL_SELECT_USERS_BY_LIKE_SHOW_NAME = " SELECT GID,USERNAME,CODENAME,PASSWORD,SHOWNAME,CREATEUSER,MODIFIEDUSER,MODIFIEDTIME,ISDELETED FROM [user] WHERE ISDELETED=0 AND SHOWNAME LIKE '%{0}%' order by codename ";
//插入账户登录信息
private const string SQL_INSERT_USERS = " INSERT INTO [user] (GID,USERNAME,CODENAME,PASSWORD,SHOWNAME,CREATEUSER,ISDELETED,ISDISABLE) "
+ " VALUES (@gid,@username,@codename,@password,@showname,@create_userid,@is_deleted,@is_disable)";
//插入账户基本信息表
public string SQL_INSERT_BASEINFO = " INSERT INTO user_baseinfo(GID,USERID,OFFICEPHONE,HOMEPHONE,MOBILE,FAX,EMAIL1,EMAIL2,HOMEADDRESS,CREATEUSER,"
+ " EMERGUSER,EMERGPHONE,EMERGEMAIL,COMPANYNAME,DEPTNAME,QQ,MSN,FINANCESOFTCODE,IMAGEURL{0},SIGNATUREURL,CONTRACTDATE,TRIALTIME, IDNUM, EDURECORD, ANNUALLEAVE) VALUES (@base_gid,@userid,@office_phone_num,@home_phone_num, "
+ " @mobile_phone_num,@fax_num,@email_addr_p,@email_addr_s,@home_addr,@create_userid, "
+ " @emergency_user,@emergency_phone,@emergency_email,@COMPANYNAME,@DEPTNAME,@QQ,@MSN,@FINANCESOFTCODE,@IMAGEURL{1},@SIGNATUREURL,@CONTRACTDATE,@TRIALTIME,@IDNUM,@EDURECORD,@ANNUALLEAVE)";
//按用户登录名查找
private const string SQL_SELECT_EXISTUSER = "SELECT GID FROM [user] WHERE codename = @codename and ISDELETED=0";
private const string SQL_SELECT_USERLISTINFO = " SELECT A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,C.NAME as COMPANYNAME FROM [user] as A INNER JOIN user_company as B ON A.GID = B.USERID INNER JOIN company as C ON B.COMPANYID = C.GID and A.ISDELETED=0";
private const string SQL_INSERT_USERCOMPANY = " INSERT INTO user_company()";
//更新账户登录信息
private const string SQL_UPDATE_USERS = " update [user] set USERNAME=@username,CODENAME=@codename,PASSWORD=@password,SHOWNAME=@showname,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=GETDATE(),ISDELETED=@is_deleted,ISDISABLE=@is_disable where GID=@gid";
//更新账户基本信息表
public string SQL_UPDATE_BASEINFO = " update user_baseinfo set USERID=@userid,OFFICEPHONE=@office_phone_num,HOMEPHONE=@home_phone_num,MOBILE=@mobile_phone_num,FAX=@fax_num,EMAIL1=@email_addr_p,EMAIL2=@email_addr_s,HOMEADDRESS=@home_addr,MODIFIEDUSER=@modified_userid,MODIFIEDTIME=GETDATE(), EMERGUSER=@emergency_user,EMERGPHONE=@emergency_phone,EMERGEMAIL=@emergency_email,COMPANYNAME=@COMPANYNAME,DEPTNAME=@DEPTNAME,QQ=@QQ,MSN=@MSN,FINANCESOFTCODE=@FINANCESOFTCODE,IMAGEURL=@IMAGEURL{0},SIGNATUREURL=@SIGNATUREURL,CONTRACTDATE=@CONTRACTDATE,TRIALTIME=@TRIALTIME,IDNUM=@IDNUM,EDURECORD=@EDURECORD,ANNUALLEAVE=@ANNUALLEAVE where GID=@base_gid";
private const string SQL_SELECT_TOP1 = " SELECT top 1 A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE, B.GID as BaseGid,B.OFFICEPHONE,B.HOMEPHONE,B.MOBILE,B.FAX,B.EMAIL1,B.EMAIL2,B.HOMEADDRESS,B.REMARK,B.CREATEUSER, B.CREATETIME,B.MODIFIEDUSER,B.MODIFIEDTIME,B.EMERGUSER,B.EMERGPHONE,B.EMERGEMAIL,B.POSTCODE,B.COMPANYNAME,B.DEPTNAME,B.QQ,B.MSN,B.SIGNATURE,FINANCESOFTCODE,B.IMAGEURL,B.SIGNATUREURL,dbo.trimdate(B.CONTRACTDATE) CONTRACTDATE,B.TRIALTIME, B.IDNUM, B.EDURECORD, B.ANNUALLEAVE FROM [user] AS A INNER JOIN user_baseinfo as B ON A.GID = B.USERID AND A.ISDELETED=0 order by ISDISABLE,codename";
private const string SQL_SELECT_USER_DEPARTMENT_NAME_BY_USERID = " SELECT DEPTNAME FROM user_baseinfo WHERE USERID = @userid ";
private const string SQL_SELECT_USER_BY_COMPANY_AND_DEPTNAME = " SELECT A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE FROM [user] as A "
+ " INNER JOIN user_baseinfo as B ON A.GID = B.USERID INNER JOIN user_company as C ON A.GID = C.USERID WHERE C.COMPANYID = @company_id AND B.DEPTNAME = @DEPTNAME AND A.ISDELETED <> 1 AND A.ISDISABLE <> 1 order by A.codename";
private const string SQL_UPDATE_USER_PASSWORD_BY_GID = " UPDATE [user] SET PASSWORD = @password WHERE GID = @gid ";
private const string SQL_SELECT_USER_BY_COMPANY_AND_USERNAME = " SELECT A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE FROM company B INNER JOIN user_company C ON B.GID = C.COMPANYID INNER JOIN [user] A ON C.USERID = A.GID WHERE B.CODENAME = @CODENAME AND A.CODENAME = @USERNAME AND A.ISDELETED =0 AND A.ISDISABLE =0 AND B.ISDELETED =0 AND B.ISDISABLE =0 order by A.codename ";
private const string SQL_UPDATE_USER_ISDELETED = " UPDATE [user] SET ISDELETED = 1,DELETEUSER = @delete_user,DELETETIME = GETDATE() WHERE GID = @gid ";
private const string SQL_SELECT_USER_LOGIN = " SELECT A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE "
+ " FROM [user] AS A LEFT JOIN user_company as B ON A.GID = B.USERID INNER JOIN company AS C ON B.COMPANYID = C.GID WHERE A.CODENAME = @codename AND "
+ " A.PASSWORD collate Chinese_PRC_CS_AS_WS= @password AND C.CODENAME = @company_code_name ";
private const string SQL_SELECT_USER_LOGIN_BYTEL = " SELECT A.GID,A.USERNAME,A.CODENAME,A.PASSWORD,A.SHOWNAME,A.ENROLLTIME,A.CREATEUSER,A.MODIFIEDUSER,A.MODIFIEDTIME,A.ISDELETED,A.ISDISABLE "
+ " FROM [user] AS A LEFT JOIN user_baseinfo as B ON A.GID = B.USERID WHERE B.MOBILE = @MOBILE ";
#region 删除用户更新删除标志位
/// <summary>
/// 删除用户更新删除标志位
/// </summary>
/// <param name="tempCheckUserID">被删除用户GID</param>
/// <param name="tempDeleteOperator">删除操作人GID</param>
/// <returns></returns>
public int UpdateUserDelete(string tempCheckUserID,string tempDeleteOperator)
{
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] updateParms = new SqlParameter[] {
new SqlParameter(PARM_USER_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_USER_DELETEUSER,SqlDbType.VarChar,36)
};
updateParms[0].Value = tempCheckUserID;
updateParms[1].Value = tempDeleteOperator;
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_USER_ISDELETED, updateParms);
}
catch (Exception error)
{
iResult = -1;//更新异常
throw error;
}
}
return iResult;
}
#endregion
#region 获取与公司关联的账户登录信息
/// <summary>
/// 获取与公司关联的账户登录信息
/// </summary>
/// <param name="userGid"></param>
/// <returns></returns>
public UserEntity GetCAndU(string strCOMPANYCODENAME, string strUSERNAME)
{
//初始化返回对象
UserEntity userEntity = null;
//初始化参数并赋值
//初始化参数并赋值
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@CODENAME", SqlDbType.VarChar, 10),
new SqlParameter("@USERNAME", SqlDbType.VarChar, 150)
};
parms[0].Value = strCOMPANYCODENAME;
parms[1].Value = strUSERNAME;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_BY_COMPANY_AND_USERNAME, parms))
{
userEntity = new UserEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
#endregion
#region 更新用户密码
/// <summary>
/// 更新用户密码
/// </summary>
/// <param name="tempUserID">用户GID</param>
/// <param name="tempPassword">用户新密码</param>
/// <returns>值1表示更新成功 值不等于1表示更新失败</returns>
public int UpdateUserPassWord(string tempUserID,string tempPassword)
{
int iResult = 0;
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(PARM_USER_PASSWORD,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_GID,SqlDbType.VarChar,36)
};
parms[0].Value = tempPassword;
parms[1].Value = tempUserID;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
iResult = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_USER_PASSWORD_BY_GID, parms);
}
catch (Exception error)
{
throw error;
}
}
return iResult;
}
#endregion
#region 获取账户登录信息
/// <summary>
/// 获取账户登录信息
/// </summary>
/// <param name="userGid"></param>
/// <returns></returns>
public UserEntity GetUserSignByID(string userGid)
{
//初始化返回对象
UserEntity userEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_USER_GID, SqlDbType.VarChar, 36);
parm.Value = userGid;
using(SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USERS_NO_BASEINFO, parm))
{
userEntity = new UserEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
#endregion
#region 查看是否有已经使用的相同登录名的用户
/// <summary>
/// 查看是否有已经使用的相同登录名的用户
/// </summary>
/// <param name="strUserName"></param>
/// <returns></returns>
private bool ExistSameUser(string strUserName, string strISDELETED)
{
//调用SqlHelper访问组件的方法返回第一行第一列的值
object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, "SELECT GID FROM [user] WHERE codename ='" + strUserName + "' and ISDELETED=1", null);
//如果相同的用户名已经存在返回true如果存在返回false
if (obj == null)
{
return false;
}
else
{
return true;
}
}
#endregion
#region 创建新用户信息
/// <summary>
/// 创建新用户信息
/// </summary>
/// <param name="tempUserEntity">用户实体类</param>
/// <returns></returns>
public int InsertUserInfo(UserEntity tempUserEntity)
{
//查看要添加的用户登录名是否已经存在
if(ExistSameUser(tempUserEntity.CodeName))
{
if (ExistSameUser(tempUserEntity.CodeName, "ISDELETED"))
{
UpdateUserInfo(tempUserEntity);
return 1;
}
else
{
return -2;//所提交的登录名已存在
}
}
//
//查看要添加的用户中文名称是否已经存在
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string lsname = T_ALL_DA.GetStrSQL("SHOWNAME", "select top 1 SHOWNAME from [user] where SHOWNAME='" + tempUserEntity.ShowName.ToString().Trim() + "' and (ISDELETED=0 or ISDELETED is null)");
if (lsname.Trim()!="")
{
return -2;//所提交的登录名已存在
}
//
SqlParameter[] userParms = GetUserParms();
userParms[0].Value = tempUserEntity.Gid;
userParms[1].Value = tempUserEntity.UserName;
userParms[2].Value = tempUserEntity.CodeName;
userParms[3].Value = tempUserEntity.PassWord;
userParms[4].Value = tempUserEntity.ShowName;
userParms[5].Value = tempUserEntity.CreatedUserID;
userParms[6].Value = tempUserEntity.IsDeleted;
userParms[7].Value = tempUserEntity.IsDisable;
SqlParameter[] baseInfoParms = GetBaseParms();
UserBaseInfoEntity baseEntity = tempUserEntity.BaseInfo;
baseInfoParms[0].Value = baseEntity.Gid;
baseInfoParms[1].Value = baseEntity.UserID;
baseInfoParms[2].Value = baseEntity.OfficePhone;
baseInfoParms[3].Value = baseEntity.HomePhone;
baseInfoParms[4].Value = baseEntity.MobilePhone;
baseInfoParms[5].Value = baseEntity.FaxNum;
baseInfoParms[6].Value = baseEntity.EmailAddressPrimary;
baseInfoParms[7].Value = baseEntity.EmailAddressSecond;
baseInfoParms[8].Value = baseEntity.HomeAddress;
baseInfoParms[9].Value = baseEntity.CreateUserID;
baseInfoParms[10].Value = baseEntity.EmergencyUser;
baseInfoParms[11].Value = baseEntity.EmergencyPhone;
baseInfoParms[12].Value = baseEntity.EmergencyEmail;
baseInfoParms[13].Value = baseEntity.COMPANYNAME;
baseInfoParms[14].Value = baseEntity.DEPTNAME;
baseInfoParms[15].Value = baseEntity.QQ;
baseInfoParms[16].Value = baseEntity.MSN;
baseInfoParms[17].Value = baseEntity.FINANCESOFTCODE;
baseInfoParms[18].Value = baseEntity.IMAGEURL;
baseInfoParms[19].Value = baseEntity.SIGNATUREURL;
if (baseEntity.CONTRACTDATE == "") baseInfoParms[20].Value = "1900-01-01";
else
baseInfoParms[20].Value = baseEntity.CONTRACTDATE;
baseInfoParms[21].Value = baseEntity.TRIALTIME;
baseInfoParms[22].Value = baseEntity.IDNUM;
baseInfoParms[23].Value = baseEntity.EDURECORD;
baseInfoParms[24].Value = baseEntity.ANNUALLEAVE;
string strSIGNATURE = "";
string strSIGNATURE_name = "";
if (baseEntity.SIGNATURE != null && !baseEntity.SIGNATURE.ToString().Trim().Equals(""))
{
strSIGNATURE = ",'" + baseEntity.SIGNATURE.ToString() + "'";
strSIGNATURE_name = ",SIGNATURE";
}
SQL_INSERT_BASEINFO = String.Format(SQL_INSERT_BASEINFO, strSIGNATURE_name, strSIGNATURE);
using(SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
int existVal = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_INSERT_USERS, userParms);
if (existVal > 0)
{
int existVal2 = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_INSERT_BASEINFO, baseInfoParms);
if (existVal2 > 0)
{
sqlTran.Commit();
return 1;
}
else
{
return -1;//执行异常
}
}
else
{
return -1;//执行异常
}
}
catch (Exception execError)
{
sqlTran.Rollback();
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
}
#endregion
#region 查看是否有已经使用的相同登录名的用户
/// <summary>
/// 查看是否有已经使用的相同登录名的用户
/// </summary>
/// <param name="strUserName"></param>
/// <returns></returns>
private bool ExistSameUserUpdate(string strUserName,string strGid)
{
string str = "SELECT GID FROM [user] WHERE codename ='" + strUserName + "' and gid<>'" + strGid + "'";
//调用SqlHelper访问组件的方法返回第一行第一列的值
object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, str, null);
//如果相同的用户名已经存在返回true如果存在返回false
if (obj == null)
{
return false;
}
else
{
return true;
}
}
#endregion
#region 更新用户信息
/// <summary>
/// 更新用户信息
/// </summary>
/// <param name="tempUserEntity">用户实体类</param>
/// <returns></returns>
public int UpdateUserInfo(UserEntity tempUserEntity)
{
//查看要添加的用户登录名是否已经存在
if (ExistSameUserUpdate(tempUserEntity.CodeName,tempUserEntity.Gid))
{
return -2;//所提交的登录名已存在
}
//查看要添加的用户中文名称是否已经存在
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string lsname = T_ALL_DA.GetStrSQL("SHOWNAME", "select top 1 SHOWNAME from [user] where SHOWNAME='" + tempUserEntity.ShowName.ToString().Trim() + "' and (ISDELETED=0 or ISDELETED is null) and gid<>'" + tempUserEntity.Gid.ToString().Trim() + "'");
if (lsname.Trim() != "")
{
return -2;//所提交的登录名已存在
}
//
SqlParameter[] userParms = GetUserParmsU();
userParms[0].Value = tempUserEntity.Gid;
userParms[1].Value = tempUserEntity.UserName;
userParms[2].Value = tempUserEntity.CodeName;
userParms[3].Value = tempUserEntity.PassWord;
userParms[4].Value = tempUserEntity.ShowName;
userParms[5].Value = tempUserEntity.ModifiedUserID;
userParms[6].Value = tempUserEntity.IsDeleted;
userParms[7].Value = tempUserEntity.IsDisable;
SqlParameter[] baseInfoParms = GetBaseParmsU();
UserBaseInfoEntity baseEntity = tempUserEntity.BaseInfo;
baseInfoParms[0].Value = baseEntity.Gid;
baseInfoParms[1].Value = baseEntity.UserID;
baseInfoParms[2].Value = baseEntity.OfficePhone;
baseInfoParms[3].Value = baseEntity.HomePhone;
baseInfoParms[4].Value = baseEntity.MobilePhone;
baseInfoParms[5].Value = baseEntity.FaxNum;
baseInfoParms[6].Value = baseEntity.EmailAddressPrimary;
baseInfoParms[7].Value = baseEntity.EmailAddressSecond;
baseInfoParms[8].Value = baseEntity.HomeAddress;
baseInfoParms[9].Value = baseEntity.ModifiedUserID;
baseInfoParms[10].Value = baseEntity.EmergencyUser;
baseInfoParms[11].Value = baseEntity.EmergencyPhone;
baseInfoParms[12].Value = baseEntity.EmergencyEmail;
baseInfoParms[13].Value = baseEntity.COMPANYNAME;
baseInfoParms[14].Value = baseEntity.DEPTNAME;
baseInfoParms[15].Value = baseEntity.QQ;
baseInfoParms[16].Value = baseEntity.MSN;
baseInfoParms[17].Value = baseEntity.FINANCESOFTCODE;
baseInfoParms[18].Value = baseEntity.IMAGEURL;
baseInfoParms[19].Value = baseEntity.SIGNATUREURL;
if (baseEntity.CONTRACTDATE == "") baseInfoParms[20].Value = "1900-01-01";
else
baseInfoParms[20].Value = baseEntity.CONTRACTDATE;
baseInfoParms[21].Value = baseEntity.TRIALTIME;
baseInfoParms[22].Value = baseEntity.IDNUM;
baseInfoParms[23].Value = baseEntity.EDURECORD;
baseInfoParms[24].Value = baseEntity.ANNUALLEAVE;
string strSIGNATURE = "";
if (baseEntity.SIGNATURE != null && !baseEntity.SIGNATURE.ToString().Trim().Equals(""))
{
strSIGNATURE = ",SIGNATURE='" + baseEntity.SIGNATURE.ToString() + "'";
}
SQL_UPDATE_BASEINFO = String.Format(SQL_UPDATE_BASEINFO,strSIGNATURE);
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_USERS, userParms);
if (existVal > 0)
{
int existVal2 = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_BASEINFO, baseInfoParms);
if (existVal2 > 0)
{
//判断公司名称是不是"QDDS"
DataTable dt = SqlHelper.ExecuteSql("select NAME from company");
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i][0].ToString() == "青岛东胜")
{
string siteDestination = ConfigurationManager.AppSettings["filesDestination"];
string InstallPath = AppDomain.CurrentDomain.BaseDirectory;
InstallPath = InstallPath.Substring(0, InstallPath.Length - 1);
string fileName = InstallPath + "\\images\\userpic\\" + baseEntity.IMAGEURL;
string[] directory = InstallPath.Split('\\');
string path = "";
for (int j = 0; j < directory.Length - 2; j++)
{
path += directory[j] + "\\";
}
string destFile = path + siteDestination + baseEntity.IMAGEURL;
if(!File.Exists(destFile))
{
File.Copy(fileName, destFile);
}
}
}
sqlTran.Commit();
return 1;
}
else
{
return -1;//执行异常
}
}
else
{
return -1;//执行异常
}
}
catch (Exception execError)
{
sqlTran.Rollback();
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
}
#endregion
#region SHOWNAME 查询用户所有信息
/// <summary>
/// SHOWNAME 查询用户所有信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public UserEntity GetUserAllBySHOWNAME(string strSHOWNAME)
{
UserEntity userEntity = null;
UserBaseInfoEntity baseEntity = null;
SqlDataReader sqlRead = null;
SqlParameter parm = new SqlParameter(PARM_USER_SHOWNAME, SqlDbType.VarChar, 150);
parm.Value = strSHOWNAME;
using (sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_BASEINFO_SHOWNAME, parm))
{
try
{
userEntity = new UserEntity();
baseEntity = new UserBaseInfoEntity();
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
if (!sqlRead.IsDBNull(11))
{
baseEntity.Gid = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
baseEntity.OfficePhone = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
baseEntity.HomePhone = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
baseEntity.MobilePhone = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
baseEntity.FaxNum = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
baseEntity.EmailAddressPrimary = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
baseEntity.EmailAddressSecond = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
baseEntity.HomeAddress = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
baseEntity.Remarks = sqlRead.GetString(19);
}
if (!sqlRead.IsDBNull(20))
{
baseEntity.CreateUserID = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
baseEntity.CreateTime = sqlRead.GetDateTime(21);
}
if (!sqlRead.IsDBNull(22))
{
baseEntity.ModifiedUserID = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
baseEntity.ModifiedTime = sqlRead.GetDateTime(23);
}
if (!sqlRead.IsDBNull(24))
{
baseEntity.EmergencyUser = sqlRead.GetString(24);
}
if (!sqlRead.IsDBNull(25))
{
baseEntity.EmergencyPhone = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
baseEntity.EmergencyEmail = sqlRead.GetString(26);
}
if (!sqlRead.IsDBNull(27))
{
baseEntity.PostCode = sqlRead.GetString(27);
}
if (!sqlRead.IsDBNull(28))
{
baseEntity.COMPANYNAME = sqlRead.GetString(28);
}
if (!sqlRead.IsDBNull(29))
{
baseEntity.DEPTNAME = sqlRead.GetString(29);
}
if (!sqlRead.IsDBNull(30))
{
baseEntity.QQ = sqlRead.GetString(30);
}
if (!sqlRead.IsDBNull(31))
{
baseEntity.MSN = sqlRead.GetString(31);
}
if (!sqlRead.IsDBNull(32))
{
baseEntity.SIGNATURE = (byte[])sqlRead.GetSqlBinary(32);
}
if (!sqlRead.IsDBNull(33))
{
baseEntity.FINANCESOFTCODE = sqlRead.GetString(33);
}
if (!sqlRead.IsDBNull(34))
{
baseEntity.IMAGEURL = sqlRead.GetString(34);
}
if (!sqlRead.IsDBNull(35))
{
baseEntity.SIGNATUREURL = sqlRead.GetString(35);
}
if (!sqlRead.IsDBNull(36))
{
baseEntity.CONTRACTDATE = sqlRead.GetString(36);
}
if (!sqlRead.IsDBNull(37))
{
baseEntity.TRIALTIME = sqlRead.GetString(37);
}
if (!sqlRead.IsDBNull(38))
{
baseEntity.IDNUM = sqlRead.GetString(38);
}
if (!sqlRead.IsDBNull(39))
{
baseEntity.EDURECORD = sqlRead.GetString(39);
}
if (!sqlRead.IsDBNull(40))
{
baseEntity.ANNUALLEAVE = sqlRead.GetString(40);
}
userEntity.BaseInfo = baseEntity;
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
#endregion
#region 查询用户所有信息
/// <summary>
/// 查询用户所有信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public UserEntity GetUserAllByID(string strGid)
{
UserEntity userEntity = null;
UserBaseInfoEntity baseEntity = null;
SqlDataReader sqlRead = null;
SqlParameter parm = new SqlParameter(PARM_BASEINFO_USERID, SqlDbType.VarChar, 36);
parm.Value = strGid;
using (sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_BASEINFO, parm))
{
try
{
userEntity = new UserEntity();
baseEntity = new UserBaseInfoEntity();
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
if (!sqlRead.IsDBNull(11))
{
baseEntity.Gid = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
baseEntity.OfficePhone = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
baseEntity.HomePhone = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
baseEntity.MobilePhone = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
baseEntity.FaxNum = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
baseEntity.EmailAddressPrimary = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
baseEntity.EmailAddressSecond = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
baseEntity.HomeAddress = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
baseEntity.Remarks = sqlRead.GetString(19);
}
if (!sqlRead.IsDBNull(20))
{
baseEntity.CreateUserID = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
baseEntity.CreateTime = sqlRead.GetDateTime(21);
}
if (!sqlRead.IsDBNull(22))
{
baseEntity.ModifiedUserID = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
baseEntity.ModifiedTime = sqlRead.GetDateTime(23);
}
if (!sqlRead.IsDBNull(24))
{
baseEntity.EmergencyUser = sqlRead.GetString(24);
}
if (!sqlRead.IsDBNull(25))
{
baseEntity.EmergencyPhone = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
baseEntity.EmergencyEmail = sqlRead.GetString(26);
}
if (!sqlRead.IsDBNull(27))
{
baseEntity.PostCode = sqlRead.GetString(27);
}
if (!sqlRead.IsDBNull(28))
{
baseEntity.COMPANYNAME = sqlRead.GetString(28);
}
if (!sqlRead.IsDBNull(29))
{
baseEntity.DEPTNAME = sqlRead.GetString(29);
}
if (!sqlRead.IsDBNull(30))
{
baseEntity.QQ = sqlRead.GetString(30);
}
if (!sqlRead.IsDBNull(31))
{
baseEntity.MSN = sqlRead.GetString(31);
}
if (!sqlRead.IsDBNull(32))
{
baseEntity.SIGNATURE = (byte[])sqlRead.GetSqlBinary(32);
}
if (!sqlRead.IsDBNull(33))
{
baseEntity.FINANCESOFTCODE = sqlRead.GetString(33);
}
if (!sqlRead.IsDBNull(34))
{
baseEntity.IMAGEURL = "../images/userpic/" + sqlRead.GetString(34);
}
if (!sqlRead.IsDBNull(35))
{
baseEntity.SIGNATUREURL = sqlRead.GetString(35);
}
if (!sqlRead.IsDBNull(36))
{
baseEntity.CONTRACTDATE = sqlRead.GetString(36);
}
if (!sqlRead.IsDBNull(37))
{
baseEntity.TRIALTIME = sqlRead.GetString(37);
}
if (!sqlRead.IsDBNull(38))
{
baseEntity.IDNUM = sqlRead.GetString(38);
}
if (!sqlRead.IsDBNull(39))
{
baseEntity.EDURECORD = sqlRead.GetString(39);
}
if (!sqlRead.IsDBNull(40))
{
baseEntity.ANNUALLEAVE = sqlRead.GetString(40);
}
userEntity.BaseInfo = baseEntity;
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
#endregion
#region 获取用户登录信息参数组
/// <summary>
/// 获取用户登录信息参数组
/// </summary>
/// <returns></returns>
private SqlParameter[] GetUserParms()
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_USER_GID,SqlDbType.VarChar),
new SqlParameter(PARM_USER_USERNAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_CODENAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_PASSWORD,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_SHOWNAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_CREATEBY,SqlDbType.VarChar,36),
new SqlParameter(PARM_USER_ISDELETE,SqlDbType.Bit),
new SqlParameter(PARM_USER_ISDISABLE,SqlDbType.Bit)
};
return parms;
}
#endregion
#region 获取用户基本信息参数组
/// <summary>
/// 获取用户基本信息参数组
/// </summary>
/// <returns></returns>
private SqlParameter[] GetBaseParms()
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter(PARM_BASEINFO_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_BASEINFO_USERID,SqlDbType.VarChar,36),
new SqlParameter(PARM_BASEINFO_OFFICEPHONE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_HOMEPHONE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_MOBILE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_FAX,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_EMAIL_1,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_EMAIL_2,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_HOMEADDR,SqlDbType.VarChar,150),
new SqlParameter(PARM_BASEINFO_CREATEBY,SqlDbType.VarChar,36),
new SqlParameter(PARM_BASEINFO_EMERGUSER,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_EMERGPHONE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_EMERGEMAIL,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_COMPANYNAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_BASEINFO_DEPTNAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_QQ,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_MSN,SqlDbType.VarChar,100),
new SqlParameter("FINANCESOFTCODE",SqlDbType.VarChar,20),
new SqlParameter("IMAGEURL",SqlDbType.VarChar,100),
new SqlParameter("SIGNATUREURL",SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_CONTRACTDATE,SqlDbType.Date,100),
new SqlParameter(PARM_BASEINFO_TRIALTIME,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_IDNUM,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_EDURECORD,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_ANNUALLEAVE,SqlDbType.VarChar,100)
//new SqlParameter("@SIGNATURE",SqlDbType.Binary)//签名上传
};
return parms;
}
#endregion
#region 获取用户登录信息参数组
/// <summary>
/// 获取用户登录信息参数组
/// </summary>
/// <returns></returns>
private SqlParameter[] GetUserParmsU()
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_USER_GID,SqlDbType.VarChar),
new SqlParameter(PARM_USER_USERNAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_CODENAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_PASSWORD,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_SHOWNAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_USER_MODIFIEDUSER,SqlDbType.VarChar,36),
new SqlParameter(PARM_USER_ISDELETE,SqlDbType.Bit),
new SqlParameter(PARM_USER_ISDISABLE,SqlDbType.Bit)
};
return parms;
}
#endregion
#region 获取用户基本信息参数组
/// <summary>
/// 获取用户基本信息参数组
/// </summary>
/// <returns></returns>
private SqlParameter[] GetBaseParmsU()
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter(PARM_BASEINFO_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_BASEINFO_USERID,SqlDbType.VarChar,36),
new SqlParameter(PARM_BASEINFO_OFFICEPHONE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_HOMEPHONE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_MOBILE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_FAX,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_EMAIL_1,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_EMAIL_2,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_HOMEADDR,SqlDbType.VarChar,150),
new SqlParameter(PARM_BASEINFO_MODIFIEDBY,SqlDbType.VarChar,36),
new SqlParameter(PARM_BASEINFO_EMERGUSER,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_EMERGPHONE,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_EMERGEMAIL,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_COMPANYNAME,SqlDbType.VarChar,150),
new SqlParameter(PARM_BASEINFO_DEPTNAME,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_QQ,SqlDbType.VarChar,50),
new SqlParameter(PARM_BASEINFO_MSN,SqlDbType.VarChar,100),
new SqlParameter("FINANCESOFTCODE",SqlDbType.VarChar,20),
new SqlParameter("IMAGEURL",SqlDbType.VarChar,100),
new SqlParameter("SIGNATUREURL",SqlDbType.VarChar,100),
//new SqlParameter("@SIGNATURE",SqlDbType.Binary)//签名上传
new SqlParameter(PARM_BASEINFO_CONTRACTDATE,SqlDbType.Date,100),
new SqlParameter(PARM_BASEINFO_TRIALTIME,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_IDNUM,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_EDURECORD,SqlDbType.VarChar,100),
new SqlParameter(PARM_BASEINFO_ANNUALLEAVE,SqlDbType.VarChar,100)
};
return parms;
}
#endregion
#region 获取账户基本信息
/// <summary>
/// 获取账户基本信息
/// </summary>
/// <param name="strGid">账户Gid</param>
/// <returns>返回账户基本信息对象-UserBaseInfoEntity</returns>
public UserBaseInfoEntity GetUserBaseInfo(string strGid)
{
UserBaseInfoEntity baseEntity = null;
SqlParameter parm = new SqlParameter(PARM_BASEINFO_USERID, SqlDbType.VarChar, 36);
parm.Value = strGid;
using(SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_BASEINFO, parm))
{
try
{
baseEntity = new UserBaseInfoEntity();
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
baseEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
baseEntity.OfficePhone = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
baseEntity.HomePhone = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
baseEntity.MobilePhone = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
baseEntity.FaxNum = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
baseEntity.EmailAddressPrimary = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
baseEntity.EmailAddressSecond = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
baseEntity.HomeAddress = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
baseEntity.Remarks = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
baseEntity.CreateUserID = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
baseEntity.CreateTime = sqlRead.GetDateTime(10);
}
if (!sqlRead.IsDBNull(11))
{
baseEntity.ModifiedUserID = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
baseEntity.ModifiedTime = sqlRead.GetDateTime(12);
}
if (!sqlRead.IsDBNull(13))
{
baseEntity.PostCode = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
baseEntity.COMPANYNAME = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
baseEntity.DEPTNAME = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
baseEntity.QQ = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
baseEntity.MSN = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
baseEntity.SIGNATURE = (byte[])sqlRead.GetSqlBinary(18);
}
if (!sqlRead.IsDBNull(19))
{
baseEntity.FINANCESOFTCODE = sqlRead.GetString(19);
}
if (!sqlRead.IsDBNull(20))
{
baseEntity.IMAGEURL = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
baseEntity.SIGNATUREURL = sqlRead.GetString(21);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return baseEntity;
}
#endregion
public IList<UserEntity> GetAllUsersAccount()
{
//初始化返回对象
UserEntity userEntity = null;
IList<UserEntity> userEntities = new List<UserEntity>();
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USERS_ALL, null))
{
try
{
while (sqlRead.Read())
{
userEntity = new UserEntity();
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
if (userEntity.Gid != null)
{
userEntities.Add(userEntity);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntities;
}
/// <summary>
/// 根据用户SHOWNAME进行模糊查询返回实体类组
/// </summary>
/// <param name="tempShowName">要检索的ShowName信息</param>
/// <returns>返回用户实体类组</returns>
public IList<UserEntity> GetUserByShowNameLike(string tempShowName)
{
//初始化返回对象
IList<UserEntity> userEntities = new List<UserEntity>();
string strSql = String.Format(SQL_SELECT_USERS_BY_LIKE_SHOW_NAME, tempShowName);
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
{
try
{
while (sqlRead.Read())
{
UserEntity userEntity = new UserEntity();
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.CreatedUserID = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.ModifiedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.IsDeleted = sqlRead.GetBoolean(8);
}
userEntities.Add(userEntity);
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntities;
}
public int InsertUser(UserEntity tempUserEntity)
{
// 查看是否有已经使用的相同登录名的用户
bool isExistSameUserName = ExistSameUser(tempUserEntity.UserName);
if (!isExistSameUserName)
{
}
return 0;
}
#region 查看是否有已经使用的相同登录名的用户
/// <summary>
/// 查看是否有已经使用的相同登录名的用户
/// </summary>
/// <param name="strUserName"></param>
/// <returns></returns>
private bool ExistSameUser(string strUserName)
{
SqlParameter parm = new SqlParameter(PARM_USER_CODENAME, SqlDbType.VarChar, 6);
parm.Value = strUserName;
//调用SqlHelper访问组件的方法返回第一行第一列的值
object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_EXISTUSER, parm);
//如果相同的用户名已经存在返回true如果存在返回false
if(obj == null)
{
return false;
}
else
{
return true;
}
}
#endregion
#region 返回所有用户数据集
/// <summary>
/// 返回所有用户数据集
/// </summary>
/// <param name="strSql">查询SQL语句</param>
/// <returns></returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
#region 查询用户所有信息
/// <summary>
/// 查询用户所有信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public UserEntity GetUserTopOne()
{
UserEntity userEntity = null;
UserBaseInfoEntity baseEntity = null;
SqlDataReader sqlRead = null;
using (sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_TOP1, null))
{
try
{
userEntity = new UserEntity();
baseEntity = new UserBaseInfoEntity();
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
if (!sqlRead.IsDBNull(11))
{
baseEntity.Gid = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
baseEntity.OfficePhone = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
baseEntity.HomePhone = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
baseEntity.MobilePhone = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
baseEntity.FaxNum = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
baseEntity.EmailAddressPrimary = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
baseEntity.EmailAddressSecond = sqlRead.GetString(17);
}
if (!sqlRead.IsDBNull(18))
{
baseEntity.HomeAddress = sqlRead.GetString(18);
}
if (!sqlRead.IsDBNull(19))
{
baseEntity.Remarks = sqlRead.GetString(19);
}
if (!sqlRead.IsDBNull(20))
{
baseEntity.CreateUserID = sqlRead.GetString(20);
}
if (!sqlRead.IsDBNull(21))
{
baseEntity.CreateTime = sqlRead.GetDateTime(21);
}
if (!sqlRead.IsDBNull(22))
{
baseEntity.ModifiedUserID = sqlRead.GetString(22);
}
if (!sqlRead.IsDBNull(23))
{
baseEntity.ModifiedTime = sqlRead.GetDateTime(23);
}
if (!sqlRead.IsDBNull(24))
{
baseEntity.EmergencyUser = sqlRead.GetString(24);
}
if (!sqlRead.IsDBNull(25))
{
baseEntity.EmergencyPhone = sqlRead.GetString(25);
}
if (!sqlRead.IsDBNull(26))
{
baseEntity.EmergencyEmail = sqlRead.GetString(26);
}
if (!sqlRead.IsDBNull(27))
{
baseEntity.PostCode = sqlRead.GetString(27);
}
if (!sqlRead.IsDBNull(28))
{
baseEntity.COMPANYNAME = sqlRead.GetString(28);
}
if (!sqlRead.IsDBNull(29))
{
baseEntity.DEPTNAME = sqlRead.GetString(29);
}
if (!sqlRead.IsDBNull(30))
{
baseEntity.QQ = sqlRead.GetString(30);
}
if (!sqlRead.IsDBNull(31))
{
baseEntity.MSN = sqlRead.GetString(31);
}
if (!sqlRead.IsDBNull(32))
{
baseEntity.SIGNATURE = (byte[])sqlRead.GetSqlBinary(32);
}
if (!sqlRead.IsDBNull(33))
{
baseEntity.FINANCESOFTCODE = sqlRead.GetString(33);
}
if (!sqlRead.IsDBNull(34))
{
baseEntity.IMAGEURL = sqlRead.GetString(34);
}
if (!sqlRead.IsDBNull(35))
{
baseEntity.SIGNATUREURL = sqlRead.GetString(35);
}
userEntity.BaseInfo = baseEntity;
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
#endregion
#region 返回数据集 用户基本信息表user_baseinfo信息
/// 返回 公司表company删除
/// </summary>
/// <returns></returns>
/// <summary>
public String GetUserDel(string strGid, string strUserID)
{
string alt = "";
string str = "update [user] set ISDELETED=1 where Gid='" + strGid + "'";
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str);
if (bl == false)
{
alt = "用户基本信息表user_baseinfo删除操作出错";
return alt;
}
else
{
//string str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除用户基本信息表user_baseinfo的信息','更新操作','" + str + "','" + strUserID + "')";
//bool bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1);
}
return alt;
}
#endregion
#region 返回数据集 用户表user信息
/// <summary>
/// 返回 用户表user信息
/// </summary>
/// <returns></returns>
public DataSet GetUserSQL(string strSQL)
{
string str = "select * from [user] 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;
}
public static DataTable GetUserTipInfo(string codeName, string userName)
{
DataTable dt = new DataTable();
StringBuilder sql = new StringBuilder();
sql.AppendLine("select B.GID,B.USERNAME,B.CODENAME,B.PASSWORD,B.SHOWNAME,B.ENROLLTIME,B.CREATEUSER,B.MODIFIEDUSER,B.MODIFIEDTIME ");
sql.AppendLine("from [dbo].[user_company] as A ");
sql.AppendLine("left join [dbo].[user] as B on A.USERID=B.GID ");
sql.AppendLine("where A.COMPANYID=(select GID from dbo.company where CODENAME='" + codeName + "' and ISDELETED=0 and ISDISABLE=0) ");
sql.AppendLine("and B.CODENAME='" + userName + "' and ISDELETED=0 and ISDISABLE=0 ");// B.PASSWORD='"+password+"' and
dt = SqlHelper.ExecuteSql(sql.ToString());
return dt;
}
#endregion
#region
/// <summary>
/// 根据公司GID和部门NAME获取所有部门下的用户信息
/// </summary>
/// <param name="tempCompanyID">公司GID</param>
/// <param name="tempDeptName">部门名称</param>
/// <returns>返回部门下所有用户信息实体类</returns>
public IList<UserEntity> GetUserByCompanyAndDept(string tempCompanyID,string tempDeptName)
{
//初始化返回对象
IList<UserEntity> userEntities = new List<UserEntity>();
//初始化参数并赋值
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_USER_COMPANY_COMPANY_ID, SqlDbType.VarChar, 36),
new SqlParameter(PARM_BASEINFO_DEPTNAME, SqlDbType.VarChar, 100),
};
parms[0].Value = tempCompanyID;
parms[1].Value = tempDeptName;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_BY_COMPANY_AND_DEPTNAME, parms))
{
try
{
while (sqlRead.Read())
{
UserEntity userEntity = new UserEntity();
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
userEntities.Add(userEntity);
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntities;
}
#endregion
#region
/// 返回业务走势对比图表分析
/// <summary>
/// <returns></returns>
/// </summary>
public DataTable GetCompareRangeInfo(string companyID, string year, string day)
{
DataTable dt = new DataTable();
StringBuilder sql = new StringBuilder();
sql.AppendLine("select A.BSNO,A.OPDATE,A.LANE,A.INPUTBY,B.TTLDR,B.TTLCR,SUM(B.TTLDR-B.TTLCR) AS TTLAMOUNT from V_OP_BILL AS A left join v_op_gain_sum AS B on B.BSNO=A.BSNO ");
sql.AppendLine("where B.BSNO IS NOT NULL and INPUTBY in (select A.SHOWNAME from dbo.[user] as A left join dbo.user_company as B on A.GID=B.USERID left join dbo.company as C on B.COMPANYID=C.GID where C.GID='" + companyID + "') ");
sql.AppendLine("AND A.OPDATE LIKE '%" + day + "%' AND A.OPDATE LIKE '%" + year + "%' AND LANE !='' ");
sql.AppendLine("GROUP BY LANE,INPUTBY,OPDATE,A.BSNO,TTLDR,TTLCR ");
sql.AppendLine("ORDER BY LANE ");
dt = SqlHelper.ExecuteSql(sql.ToString());
return dt;
}
#endregion
#region 返回数据集 用户基本信息表user_baseinfo信息
/// 返回 公司表company删除
/// </summary>
/// <returns></returns>
/// <summary>
public String GetUserCompany(string COMPANYID, string USERID)
{
string alt = "";
string str = "delete from user_company where USERID='" + USERID + "'";
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str);
if (bl == false)
{
alt = "用户所属分公司属性表user_company删除操作出错";
return alt;
}
else
{
//string str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除用户所属分公司属性表user_company的信息','删除操作','" + str + "','" + USERID + "')";
//bool bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1);
//
str = "insert into user_company(COMPANYID,USERID) values('" + COMPANYID + "','" + USERID + "')";
bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str);
if (bl == false)
{
alt = "用户所属分公司属性表user_company插入操作出错";
return alt;
}
else
{
//str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('插入更新用户所属分公司属性表user_company的信息','插入操作','" + str + "','" + USERID + "')";
//bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1);
}
}
return alt;
}
#endregion
#region 返回数据集 用户基本信息表user_baseinfo信息
public string GetUserDepartmentName(string tempUserID)
{
string strResult = "";
SqlParameter parm = new SqlParameter(PARM_BASEINFO_USERID,SqlDbType.VarChar,36);
parm.Value = tempUserID;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
string strDeptName = (string)SqlHelper.ExecuteScalar(conn, CommandType.Text, SQL_SELECT_USER_DEPARTMENT_NAME_BY_USERID, parm) as String;
if(strDeptName != null)
{
strResult = strDeptName;
}
}
return strResult;
}
#endregion
#region 通过用户代码名、用户登录密码和分公司代码名获取用户登录信息
/// <summary>
/// 通过用户代码名、用户登录密码和分公司代码名获取用户登录信息
/// </summary>
/// <param name="tempCodeName">用户代码名</param>
/// <param name="tempPassword">用户登录密码</param>
/// <param name="tempCompanyCodeName">分公司代码名</param>
/// <returns>返回用户登录实体类</returns>
public UserEntity GetSigleUserInfoBySignIn(string tempCodeName,string tempPassword,string tempCompanyCodeName)
{
//初始化返回对象
UserEntity userEntity = null;
//初始化参数并赋值
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_USER_CODENAME, SqlDbType.VarChar, 10),
new SqlParameter(PARM_USER_PASSWORD, SqlDbType.VarChar, 150),
new SqlParameter(PARM_COMPANY_CODE_NAME, SqlDbType.VarChar, 10),
};
parms[0].Value = tempCodeName;
parms[1].Value = tempPassword;
parms[2].Value = tempCompanyCodeName;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_LOGIN, parms))
{
userEntity = new UserEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
public UserEntity GetSigleUserInfoByMOBILE(string MOBILE)
{
//初始化返回对象
UserEntity userEntity = null;
//初始化参数并赋值
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter(PARM_MOBILE, SqlDbType.VarChar, 50),
};
parms[0].Value = MOBILE;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_USER_LOGIN_BYTEL, parms))
{
userEntity = new UserEntity();
try
{
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0))
{
userEntity.Gid = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
userEntity.UserName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
userEntity.CodeName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
userEntity.PassWord = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
userEntity.ShowName = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
userEntity.EnrollTime = sqlRead.GetDateTime(5);
}
if (!sqlRead.IsDBNull(6))
{
userEntity.CreatedUserID = sqlRead.GetString(6);
}
if (!sqlRead.IsDBNull(7))
{
userEntity.ModifiedUserID = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
userEntity.ModifiedTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
userEntity.IsDeleted = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
userEntity.IsDisable = sqlRead.GetBoolean(10);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return userEntity;
}
#endregion
#region 通过用户代码获取公司代码和部门代码
public String GetCORPID(string strUserID)
{
string str = "select COMPANYID from user_company where USERID='" + strUserID + "' and COMPANYID in (select GID from [company] where ISDELETED=0 and ISDISABLE=0)";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
if (DS.Tables[0].Rows.Count > 0)
{
str = DS.Tables[0].Rows[0]["COMPANYID"].ToString();
}
else
{
str = "";
}
return str;
}
public String GetDEPTGID(string strUserID)
{
string strcompanyid = GetCORPID(strUserID);
string str = "select GID from sys_dept where LINKID='" + strcompanyid + "' and deptname=(select deptname from user_baseinfo where userid='" + strUserID + "')";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
if (DS.Tables[0].Rows.Count > 0)
{
str = DS.Tables[0].Rows[0]["GID"].ToString();
}
else
{
str = "";
}
return str;
}
#endregion
#region 返回数据集 用户表user信息
/// <summary>
/// 返回 用户表user信息
/// </summary>
/// <returns></returns>
public DataSet GetSQL(string strSQL)
{
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
#endregion
#region 更新账户列表信息
/// <summary>
/// 更新账户列表信息
/// </summary>
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
public int UpdateUserFromGrid(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
}
}