/// <summary> /// 把AD用户集合转化为DataTable,表名为USER /// </summary> /// <returns></returns> public DataTable ToDataTable() { DataTable dt = DomainUser.ToDataTableSchema(); foreach (DomainUser user in List) { DataRow dr = dt.NewRow(); user.FillDataRow(dr); dt.Rows.Add(dr); } return(dt); }
/// <summary> /// 把当前组织单元和用户集合转换成数据表 /// </summary> public DataTable ToDataTable() { DataTable dtOUSchema = DomainOrganizationUnit.ToDataTableSchema(); DataTable dtUserSchema = DomainUser.ToDataTableSchema(); DataTable dtResult = new DataTable(); dtResult.TableName = "组织单元用户表"; foreach (DataColumn col in dtOUSchema.Columns) { col.ColumnName = "OU_" + col.ColumnName; dtResult.Columns.Add(new DataColumn() { ColumnName = col.ColumnName, Caption = col.Caption }); } foreach (DataColumn col in dtUserSchema.Columns) { col.ColumnName = "USER_" + col.ColumnName; dtResult.Columns.Add(new DataColumn() { ColumnName = col.ColumnName, Caption = col.Caption }); } foreach (DomainOrganizationUnitUser ouUser in List) { DataTable dtResultTemp = dtResult.Clone(); DataTable dtOU = ouUser.OU.ToDataTable(); DataTable dtUsers = ouUser.Users.ToDataTable(); if (dtUsers.Rows.Count == 0) { continue; } foreach (DataRow drUser in dtUsers.Rows) { DataRow drNew = dtResultTemp.NewRow(); foreach (DataRow drOU in dtOU.Rows) { foreach (DataColumn col in dtOU.Columns) { drNew["OU_" + col.ColumnName] = drOU[col]; } } foreach (DataColumn col in dtUsers.Columns) { drNew["USER_" + col.ColumnName] = drUser[col]; } dtResultTemp.Rows.Add(drNew); } dtResult.Merge(dtResultTemp); } return(dtResult); }