首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印学生记录:我想在不同的页面上显示每一张记录

打印学生记录:我想在不同的页面上显示每一张记录
EN

Stack Overflow用户
提问于 2019-07-31 06:29:24
回答 1查看 76关注 0票数 2
代码语言:javascript
复制
int b = 1;

    //Here is my print document event
    private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        try
        {

            if (b <= 1)
            {
                //Here im using string connection and fetching data through loop
                conn = new SqlConnection(Db_Path.path);
                conn.Open();
                query = "select StudentsRecord.Student_Id,StudentsRecord.GR_No,StudentsRecord.Section,StudentsRecord.Name,StudentsRecord.Father_Name,Classes.Monthly_Fee,StudentsRecord.Tuition_Fee_Discount from StudentsRecord inner join Classes on StudentsRecord.Admission_Class_Id=Classes.Class_Id where Classes.Class_Name='" + cbclass.SelectedItem + "'";
                cmd = new SqlCommand(query, conn);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {

                    int a = Convert.ToInt32(dr[5].ToString()) - Convert.ToInt32(dr[6].ToString());
                    int c = a + Convert.ToInt32(txtlatefee.Text);


                    e.Graphics.DrawString("BABA FOUNDATION PUBLIC", new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(20, 10));
                    e.Graphics.DrawString("HIGH SCHOOL (REGD)", new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(50, 35));
                    e.Graphics.DrawString("Domonwah Road Hyderabad.", new Font("Arial", 8, FontStyle.Bold), Brushes.Black, new Point(80, 60));
                    e.Graphics.DrawString("School's Copy", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(20, 90));
                    e.Graphics.DrawString("Issue Date", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(40, 140));
                    e.Graphics.DrawString("" + txtissuedate.Text, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(120, 140));
                    e.Graphics.DrawString("Due Date", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(40, 155));
                    e.Graphics.DrawString("" + txtduedate.Text, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(120, 155));
                    e.Graphics.DrawString("V. No.", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, 205));
                    e.Graphics.DrawString("SID.", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(215, 205));
                    e.Graphics.DrawString("" + dr[0].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(245, 205));
                    e.Graphics.DrawString("Fee for the month of:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, 225));
                    e.Graphics.DrawString("" + txtfeemonth.Text, new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(170, 225));
                    e.Graphics.DrawString("Roll No:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, 245));
                    e.Graphics.DrawString("GR#:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(180, 245));
                    e.Graphics.DrawString("" + dr[1].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(220, 245));
                    e.Graphics.DrawString("Class:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, 265));
                    e.Graphics.DrawString("" + cbclass.SelectedItem, new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(100, 265));
                    e.Graphics.DrawString("Sec:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(180, 265));
                    e.Graphics.DrawString("" + dr[2].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(220, 265));
                    e.Graphics.DrawString("Name:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, 285));
                    e.Graphics.DrawString("" + dr[3].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(70, 285));
                    e.Graphics.DrawString("F/Name:", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, 305));
                    e.Graphics.DrawString("" + dr[4].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(80, 305));
                    e.Graphics.DrawRectangle(new Pen(Color.Black), 20, 340, 300, 350);
                    e.Graphics.DrawString("Particulars", new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(65, 345));
                    e.Graphics.DrawString("Amount", new Font("Arial", 13, FontStyle.Bold), Brushes.Black, new Point(235, 345));
                    e.Graphics.DrawLine(new Pen(Color.Black), 230, 340, 230, 688);
                    e.Graphics.DrawString("Admission Fee", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 388));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 388));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 380, 320, 380);
                    e.Graphics.DrawString("Monthly Tuition Fee", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 418));
                    e.Graphics.DrawString("" + a.ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 418));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 410, 320, 410);
                    e.Graphics.DrawString("Other Fee", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 443));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 443));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 440, 320, 440);
                    e.Graphics.DrawString("Exam Fee", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 470));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 470));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 465, 320, 465);
                    e.Graphics.DrawString("Stationary Charges", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 494));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 494));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 490, 320, 490);
                    e.Graphics.DrawString("Annual Charges", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 518));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 518));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 515, 320, 515);
                    e.Graphics.DrawString("Course Payment", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 545));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 545));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 540, 320, 540);
                    e.Graphics.DrawString("Library Fee", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 570));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 570));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 565, 320, 565);
                    e.Graphics.DrawString("Others", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 596));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 596));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 590, 320, 590);
                    e.Graphics.DrawString("Arrears", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(30, 621));
                    e.Graphics.DrawString("0.00", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(235, 621));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 615, 320, 615);
                    e.Graphics.DrawString("Payable within due date", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(30, 643));
                    e.Graphics.DrawString("" + a.ToString(), new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(235, 646));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 640, 320, 640);
                    e.Graphics.DrawString("Payable after due date", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(30, 667));
                    e.Graphics.DrawString("" + c.ToString(), new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(235, 670));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 665, 320, 665);
                    e.Graphics.DrawString("Rupees (In Words):", new Font("Arial", 13, FontStyle.Bold), Brushes.Black, new Point(20, 705));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 785, 320, 785);
                    e.Graphics.DrawString("Note:", new Font("Arial", 13, FontStyle.Bold), Brushes.Black, new Point(20, 795));
                    e.Graphics.DrawLine(new Pen(Color.Black), 20, 820, 70, 820);

                    var r = new Rectangle(20, 825, 300, 100);

                    e.Graphics.DrawString(txtnote.Text, new Font("Arial", 10, FontStyle.Bold), Brushes.Black, r);


                    if (dr[0].ToString() != null)
                    {
                        MessageBox.Show(dr[0].ToString());
                        e.HasMorePages = true;

                    }
                    else
                    {
                        e.HasMorePages = false;

                    }


                }
                b++;
            }


        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

我想在一页上显示一份学生记录,在另一页上显示另一页,如何在单独的一页上显示每一份学生记录?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-31 07:32:40

您需要更改读取的逻辑。

将读取器放在PrintPage事件的外部,在中放置,读取和DrawString等,直到页面满或阅读器为空为止。然后从事件中返回。如果是真的话,将再次自动调用。

下面是一个打印逻辑结构的示例:

代码语言:javascript
复制
SqlDataReader dr = null;
PrintDocument pdoc = null;
int pageNr = 0;

private void printButton_Click(object sender, EventArgs e)
{
    // connect and open reader
    // ..
    // set up the print document..
    pdoc = new PrintDocument();
    pdoc.DocumentName = "Printer Test";
    pdoc.PrintPage += PrintDocument_PrintPage;
    // ..
    pageNr = 0;
    pdoc.Print();
    // close connection & reader..
}

private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
    bool pageDone = false;
    pageNr++;
    if (pageNr > maxPage) return;  // optional

    while(dr.Read())
    {
        e.HasMorePages = true;  // we have more data
        // print stuff
        // ..
        // if each Read fills one page..:
        pageDone = true; // ..or else use condition like y > yMax
        if (pageDone) return;  // return to print next page
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57284559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档