/// <summary> /// 修改用户 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(UserInfo model) { URrelationDAL urDal = new URrelationDAL(); StringBuilder strSql = new StringBuilder(); strSql.Append("update OA_User set "); strSql.Append("UserCode=@UserCode,"); strSql.Append("UserName=@UserName,"); strSql.Append("UserState=@UserState,"); strSql.Append("DeptID=@DeptID,"); strSql.Append("Operator=@Operator"); strSql.Append(" where UserID=@UserID "); SqlParameter[] parameters = { new SqlParameter("@UserCode", SqlDbType.NVarChar, 20), new SqlParameter("@UserName", SqlDbType.VarChar, 20), new SqlParameter("@UserState", SqlDbType.Char, 1), new SqlParameter("@DeptID", SqlDbType.VarChar, 36), new SqlParameter("@Operator", SqlDbType.NVarChar, 30), new SqlParameter("@UserID", SqlDbType.VarChar, 36) }; parameters[0].Value = model.UserCode; parameters[1].Value = model.UserName; parameters[2].Value = model.UserState; parameters[3].Value = model.DeptID; parameters[4].Value = model.Operator; parameters[5].Value = model.UserID; IDbTransaction transaction = DBAccess.BeginDbTransaction(DB.Type, DB.ConnectionString); try { int rows = DBAccess.ExecuteNonQuery(DB.Type, DB.ConnectionString, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { urDal.Delete(model.UserID); URrelation ur = new URrelation(); ur.ID = System.Guid.NewGuid().ToString(); ur.UserID = model.UserID; ur.RoleID = model.RoleID; urDal.Add(ur); transaction.Commit(); return(true); } else { return(false); } } catch { transaction.Rollback(); } return(false); }
/// <summary> /// 新增 /// </summary> /// <param name="model">用户实体类</param> /// <returns>用户ID</returns> public bool Add(OA.Model.UserInfo userInfo) { URrelationDAL urDal = new URrelationDAL(); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into OA_User("); strSql.Append("UserID,UserCode,UserName,UserPwd,UserState,CreateTime,CreateUserID,DeptID,Operator)"); strSql.Append(" values ("); strSql.Append("@UserID,@UserCode,@UserName,@UserPwd,@UserState,@CreateTime,@CreateUserID,@DeptID,@Operator)"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.VarChar, 36), new SqlParameter("@UserCode", SqlDbType.NVarChar, 20), new SqlParameter("@UserName", SqlDbType.VarChar, 20), new SqlParameter("@UserPwd", SqlDbType.VarChar, 36), new SqlParameter("@UserState", SqlDbType.Char, 1), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.VarChar, 36), new SqlParameter("@DeptID", SqlDbType.VarChar, 36), new SqlParameter("@Operator", SqlDbType.NVarChar, 30) }; parameters[0].Value = userInfo.UserID; parameters[1].Value = userInfo.UserCode; parameters[2].Value = userInfo.UserName; parameters[3].Value = userInfo.UserPwd; parameters[4].Value = userInfo.UserState; parameters[5].Value = userInfo.CreateTime; parameters[6].Value = userInfo.CreateUserID; parameters[7].Value = userInfo.DeptID; parameters[8].Value = userInfo.Operator; IDbTransaction transaction = DBAccess.BeginDbTransaction(DB.Type, DB.ConnectionString); try { int obj = DBAccess.ExecuteNonQuery(DB.Type, DB.ConnectionString, CommandType.Text, strSql.ToString(), parameters); if (obj > 0) { urDal.Delete(userInfo.UserID); URrelation ur = new URrelation(); ur.ID = System.Guid.NewGuid().ToString(); ur.UserID = userInfo.UserID; ur.RoleID = userInfo.RoleID; urDal.Add(ur); transaction.Commit(); return(true); } else { return(false); } } catch { transaction.Rollback(); } return(false); }