目的:在GroupDetail表里查询所有不重复的年级和科目,并保存在ArrayList里
在数据访问层
internal class GroupDetailInfoDal : DaoImplements<int, GroupDetail>
{
internal GroupDetailInfoDal()
: base("userCenter")
{
}
internal ArrayList GetGrade()
{
ArrayList arrayGrade = new ArrayList();
var query = (from x in this.Table
where x.GradeID != 0
select x.GradeID).Distinct();
if(query != null)
{
var qq = query.ToList();
for (int i = 0; i < qq.Count; i++)
{
arrayGrade.Add(qq[i]);
}
}
return arrayGrade;
}
/// <summary>
/// 查出所有科目编号
/// </summary>
/// <returns></returns>
internal ArrayList GetSubject()
{
var query = (from n in this.Table
where n.SubjectID != 0
select n.SubjectID).Distinct();
ArrayList arraySubject = new ArrayList();
if (query != null)
{
var qq = query.ToList();
for (int i = 0; i < qq.Count;i++ )
{
arraySubject.Add(qq[i]);
}
}
return arraySubject;
}
}
接收:
//得到导航所有内容
void GetAllDetail()
{
//得到所有年级
ArrayList arrayGrade = new ArrayList(); //年级编号
arrayGrade = GroupDetailInfoBll.GetGrade();
string Gname = "";
for (int i = 0; i < arrayGrade.Count; i++)
{
Gname = GradeBll.Get(Convert.ToByte(arrayGrade[i])).Name;
arrayGName.Add(Gname);
}
//得到所有科目
ArrayList arraySuject = new ArrayList(); //科目编号
arraySuject = GroupDetailInfoBll.GetSubject();
string SName = "";
for (int j = 0; j < arraySuject.Count; j++)
{
SName = SubjectBll.Get(Convert.ToInt16(arraySuject[j])).Name;
arraySName.Add(SName);
}
}
就OK了!