0
我正在将XML文件的内容读取到IEnumerable集合(数组)中,我需要在单独的页面上打印每个迭代(类似XML数据的块)。重叠打印IEnumerable集合
我正在使用Print()函数和e.HasMorePages。我的问题是,foreach循环遍历IEnumerable集合的每次打印,因此我打印的页数是正确的,但每个页面都包含所有迭代,而不是每页都有一个迭代。任何人都可以给我一个解决方案或更好的方法来管理这个过程的想法?
下面的代码的相关部分...
// Print Employee General info
foreach (EmployeeInfo itm in GEmployeeXGD.GetEmployeeGeneralData())
{
try
{
empFirstName = itm.FirstName;
empLastName = itm.LastName;
empMidInitial = itm.MidInitial;
etc…
// Set field coordinates for each employee
// ******* Employee's general information ********
PointF empFirstNameLoc = new PointF(430, 271);
PointF empLastNameLoc = new PointF(600, 271);
PointF empMidInitialLoc = new PointF(563, 271);
etc…
// Send field text data
using (Font courierFont = new Font("Courier", 10, FontStyle.Bold))
{
e.Graphics.DrawString(empFirstName, courierFont, Brushes.Black, empFirstNameLoc);
e.Graphics.DrawString(empLastName, courierFont, Brushes.Black, empLastNameLoc);
e.Graphics.DrawString(empMidInitial, courierFont, Brushes.Black, empMidInitialLoc);
etc…
}
}
catch (Exception error) { MessageBox.Show(error.ToString()); }
e.HasMorePages = (records < Globals.totalRecordCount);
}
这是有帮助的乔尔,谢谢。
GEmployeeXGD崇敬一种方法。该方法读入我需要的XML数据,并将IEnumerable集合作为数组填充。这里的方法..
public Array GetEmployeeGeneralData()
{
// XML source file
var xmlEmployeeFile = File.ReadAllText("Corrections.xml");
XDocument employeeDoc = XDocument.Parse(xmlEmployeeFile);
XElement w2cEmployeeDat = employeeDoc.Element("CorrectedDAta");
EmployeeInfo[] employeeGenInfo = null;
if (w2cEmployeeDat != null)
{
IEnumerable<XElement> employeeRecords = w2cEmployeeDat.Elements("Employee");
try
{
employeeGenInfo = (from itm in employeeRecords
select new EmployeeInfo()
{
FirstName = (itm.Element("FirstName") != null) ? itm.Element("FirstName").Value : string.Empty,
LastName = (itm.Element("LastName") != null) ? itm.Element("LastName").Value : string.Empty,
MidInitial = (itm.Element("MidInitial") != null) ? itm.Element("MidInitial").Value : string.Empty,
etc…
}).ToArray<EmployeeInfo>();
}
catch (Exception) { MessageBox.Show(error.ToString()); }
}
Globals.SetRecordCount(employeeGenInfo.Count<EmployeeInfo>());
recordCount = Globals.totalRecordCount;
return employeeGenInfo;
}
Skip不适用于GEmployeeXGD.GetEmployeeGeneralData()。如果按照指示分配(var items = GEmployeeXGD.GetEmployeeGeneralData();),则项目包含所有集合的数组元素(即employeeInfo [0],employeeInfo [1]等)。有没有办法索引这些元素,以便foreach每次只使用一个? – David