public static List <TypeUser> GetAllTypeUsers() { List <TypeUser> tus = new List <TypeUser>(); SqlParameter[] parameters = new SqlParameter[] { }; #region sql string sqlText = $@" SELECT ID_TYPE_USER, NameTU FROM [TypeUser] "; #endregion DataTable dt = new DataTable();// при наличии данных // получаем данные из запроса dt = ExecuteSqlGetDataTableStatic(sqlText); foreach (DataRow row in dt.Rows) { TypeUser tu = new TypeUser { ID_TYPE_USER = (long)row["ID_TYPE_USER"], NameTU = (string)row["NameTU"] }; tus.Add(tu); } return(tus); }
public static User GetUser(long ID_USER) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter(@"ID_USER", SqlDbType.BigInt) { Value = ID_USER } }; #region sql string sqlText = $@" SELECT [ID_USER] ,[Name] ,[Passw] ,tu.[ID_TYPE_USER] ,tu.[NameTU] ,[Login] ,[Phone] ,[Sessionid] ,[PasswMaster] ,[DateAdd] ,[Deleted] ,msisdnMaster FROM [dbo].[User] u JOIN [TypeUser] tu ON tu.ID_TYPE_USER=u.ID_TYPE_USER WHERE ID_USER=@ID_USER AND deleted=0 "; #endregion DataTable dt = new DataTable();// при наличии данных // получаем данные из запроса dt = ExecuteSqlGetDataTableStatic(sqlText, parameters); foreach (DataRow row in dt.Rows) { TypeUser tu = new TypeUser { ID_TYPE_USER = (long)row["ID_TYPE_USER"], NameTU = (string)row["NameTU"] }; bool tmpAdmin = false; if (tu.ID_TYPE_USER == 1) { tmpAdmin = true; } // попали в цикл, значит авторизовались, т.к. такой пользователь существует User us = new User { ID_USER = (long)row["ID_USER"], Name = (string)row["Name"], Login = (string)row["Login"], PasswMaster = (string)row["PasswMaster"], TYPE_USER = tu, DateAdd = (DateTime)row["DateAdd"], Phone = (string)row["Phone"], Admin = tmpAdmin, msisdnMaster = (string)row["msisdnMaster"] }; return(us); } return(null); }
/// <summary> /// Только для админа /// </summary> public static List <User> GetAllUsers(long ID_USER) { List <User> users = new List <User>(); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter(@"ID_USER", SqlDbType.BigInt) { Value = ID_USER } }; #region sql string sqlText = $@" declare @admin bit; set @admin=( SELECT count(1) FROM [User] WHERE ID_USER=@ID_USER AND ID_TYPE_USER=1 ) -- вывод всех пользователей мастеров и диспетчеров if @admin=1 BEGIN SELECT ID_USER, Name, tu.ID_TYPE_USER, tu.NameTU, Login, Phone, PasswMaster, -- Пароль мастера для вывода админу DateAdd, msisdnMaster FROM [User] u JOIN [TypeUser] tu ON u.ID_TYPE_USER=tu.ID_TYPE_USER WHERE 1=1 AND Deleted=0 ORDER BY DateAdd DESC END "; #endregion DataTable dt = new DataTable();// при наличии данных // получаем данные из запроса dt = ExecuteSqlGetDataTableStatic(sqlText, parameters); foreach (DataRow row in dt.Rows) { TypeUser tu = new TypeUser { ID_TYPE_USER = (long)row["ID_TYPE_USER"], NameTU = (string)row["NameTU"] }; bool tmpAdmin = false; if (tu.ID_TYPE_USER == 1) { tmpAdmin = true; } // попали в цикл, значит авторизовались, т.к. такой пользователь существует User us = new User { ID_USER = (long)row["ID_USER"], Name = (string)row["Name"], Login = (string)row["Login"], PasswMaster = (string)row["PasswMaster"], TYPE_USER = tu, DateAdd = (DateTime)row["DateAdd"], Phone = (string)row["Phone"], Admin = tmpAdmin, msisdnMaster = (string)row["msisdnMaster"] }; users.Add(us); } return(users); }