Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从数据表一页打印20行_C#_.net_Winforms_Visual Studio_Printing - Fatal编程技术网

C# 从数据表一页打印20行

C# 从数据表一页打印20行,c#,.net,winforms,visual-studio,printing,C#,.net,Winforms,Visual Studio,Printing,我想一页打印20行。我使用for each循环从数据表中获取数据 如果行数小于20,则一切正常。如果行数大于20,则代码无法打印第二页 请看下面的代码,帮助我找到解决方案 int CurrentRecord = 0; int RecordsPerPage = 20; // twenty items in a page decimal Amount = 0; bool StopReading = false; foreach

我想一页打印20行。我使用for each循环从数据表中获取数据

如果行数小于20,则一切正常。如果行数大于20,则代码无法打印第二页

请看下面的代码,帮助我找到解决方案

        int CurrentRecord = 0;
        int RecordsPerPage = 20; // twenty items in a page
        decimal Amount = 0;
        bool StopReading = false;

   foreach (DataRow row in table.Rows)
        {

                string ItemCode = row["ItemCode"].ToString();
                g.DrawString(ItemCode, InvoiceFont, BlackBrush, xProductID, CurrentY);

                string PartName = row["PartName"].ToString();
                if (PartName.Length > 20)
                    PartName = PartName.Remove(20);
                g.DrawString(PartName, InvoiceFont, BlackBrush, xProductName, CurrentY);

                string Id = row["Identification"].ToString();
                g.DrawString(Id, InvoiceFont, BlackBrush, xId, CurrentY);

                string Size = row["Sizes"].ToString();
                g.DrawString(Size, InvoiceFont, BlackBrush, xSize, CurrentY);

                string Chasis = row["Chasis"].ToString();
                if (Chasis.Length > 6)
                    Chasis = Chasis.Remove(7);
                g.DrawString(Chasis, InvoiceFont, BlackBrush, xChasis, CurrentY);


                string Qty = row["Qty"].ToString();
                g.DrawString(Qty, InvoiceFont, BlackBrush, xQty, CurrentY);


                string Rate = row["Rate"].ToString();
                g.DrawString(String.Format("{0:0.0}", Rate), InvoiceFont, BlackBrush, xPrice, CurrentY);


                //string t =Convert.ToInt32(row["Total"].ToString());

                string Total = row["Total"].ToString();

                //   FieldValue = String.Format("{0:0.00}", Amount);
                int xAmount = AmountPosition + (int)g.MeasureString("Price", InvoiceFont).Width;
                xAmount = xAmount - (int)g.MeasureString("Total", InvoiceFont).Width;
                // txtTotal.Text = Convert.ToInt32 (xAmount).ToString("N");

                g.DrawString(Total, InvoiceFont, BlackBrush, xAmount, CurrentY);


                CurrentY = CurrentY + InvoiceFontHeight;

                CurrentRecord++;

            if (CurrentRecord > RecordsPerPage)
            {
                e.HasMorePages = true;
                CurrentRecord = 0;
               // CurrentY = 20;

            }
            else
            {
                    e.HasMorePages = false;
            }

        }

在表单级别声明变量:

int printRow = 0;
在打印之前或在BeingPrint事件中,将printRow的值设置为零

在这种情况下不能使用ForEach,因为每次打印页面时都需要跟踪索引位置:

int recordsPerPage = 20;
int rowsPrinted = 0;

for (; printRow < table.Rows.Count; printRow++) {
  DataRow row = table.Rows[printRow];

  // print code

  rowsPrinted++;
  if (rowsPrinted >= recordsPerPage && printRow < table.Rows.Count - 1) {
    printRow++;
    e.HasMorePages = true;
    break;
  }
}
int-recordsPerPage=20;
int rowded=0;
对于(;printRow=recordsPerPage&&printRow
在表单级别声明变量:

int printRow = 0;
在打印之前或在BeingPrint事件中,将printRow的值设置为零

在这种情况下不能使用ForEach,因为每次打印页面时都需要跟踪索引位置:

int recordsPerPage = 20;
int rowsPrinted = 0;

for (; printRow < table.Rows.Count; printRow++) {
  DataRow row = table.Rows[printRow];

  // print code

  rowsPrinted++;
  if (rowsPrinted >= recordsPerPage && printRow < table.Rows.Count - 1) {
    printRow++;
    e.HasMorePages = true;
    break;
  }
}
int-recordsPerPage=20;
int rowded=0;
对于(;printRow=recordsPerPage&&printRow
在调试器中的
e.HasMorePages=true
处设置断点,然后逐步执行代码。在
CurrentRecord>RecordsPerPage
之后继续打印。在调试器中的
e.HasMorePages=true
处设置断点,然后逐步执行代码。您在
CurrentRecord>RecordsPerPage
之后继续打印。如果您有任何想法,请参阅下面的链接guide@SM关于这个链接问题,我帮不了什么忙,因为它是关于ASP.Net的。我主要研究桌面软件。如果你有任何想法,请参阅下面的链接guide@SM关于这个链接问题,我帮不了什么忙,因为它是关于ASP.Net的。我主要研究桌面软件。