/// <summary> /// Convierte un DataSet(será un usuario) en un objeto User /// </summary> /// <param name="data"></param> /// <returns></returns> public static User UserToObject(DataSet data) { if (data != null) { string dni, nom, email, pass, tit = "", img = "", frs = ""; int curso = 0, codH = 0; DataRowCollection rows = data.Tables[0].Rows; if (rows.Count != 0) { dni = rows[0].ItemArray[0].ToString(); nom = rows[0].ItemArray[1].ToString(); email = rows[0].ItemArray[2].ToString(); pass = rows[0].ItemArray[3].ToString(); if (rows[0].ItemArray[4].ToString() != "") curso = (int)rows[0].ItemArray[4]; if (rows[0].ItemArray[5].ToString() != "") tit = rows[0].ItemArray[5].ToString(); if (rows[0].ItemArray[6].ToString() != "") codH = (int)rows[0].ItemArray[6]; img = rows[0].ItemArray[7].ToString(); frs = rows[0].ItemArray[8].ToString(); User user = new User(nom, dni, email, pass, curso, tit,codH,img,frs); user.SetDatos(); return user; } } return null; }
/// <summary> /// Convierte un DataSet (que tendrá filas de usuarios) en una lista de usuarios /// </summary> /// <param name="data"></param> /// <returns></returns> public static List<User> UsersToList(DataSet data) { if (data != null) { List<User> list = new List<User>(); string dni, nom, email, pass, tit = "",img="",frs = ""; int curso = 0, codH = 0; DataRowCollection rows = data.Tables[0].Rows; for (int i = 0; i < rows.Count; i++) { dni = rows[i].ItemArray[0].ToString(); nom = rows[i].ItemArray[1].ToString(); email = rows[i].ItemArray[2].ToString(); pass = rows[i].ItemArray[3].ToString(); if (rows[i].ItemArray[4].ToString() != "") curso = (int)rows[i].ItemArray[4]; if (rows[i].ItemArray[5].ToString() != "") tit = rows[i].ItemArray[5].ToString(); if (rows[i].ItemArray[6].ToString() != "") codH = (int)rows[i].ItemArray[6]; img = rows[i].ItemArray[7].ToString(); frs = rows[i].ItemArray[8].ToString(); User user = new User(nom, dni, email, pass, curso, tit, codH, frs); user.SetDatos(); list.Add(user); } return list; } return null; }