PDA

View Full Version : مشکل با کلاس پرینت



sepideh06
یک شنبه 21 مهر 1387, 12:27 عصر
سلام دوستان.من یه تکه برنامه ی کوچیک با کنترل های پرینت نوشته بودم که داده ها ی یه dataset رو چاپ می کرد. حالا همین برنامه رو در غالب یه function در داخل یه کلاس نوشتم که 2 تا پارامتر می گیره و نتیجه ی حاصل از اجرای stored procedure را بر می گردونه در داخل DataSet .اما نمی دونم چرا در print preview هیچ نتیجه ای دیدده نمی شه.تنها راه اینه که کد رو اینجا کپی کنم.ممنون می شم اگه کمکم کنید.



Imports System

Imports System.Drawing

Imports System.Drawing.Printing

Public Class Class1
Inherits Printing.PrintDocument
Sub New()
MyBase.New()
End Sub

Public Function print1(ByVal vDepartment As String, ByVal iSalesYear As Integer) As Boolean

Dim flag As Boolean

Try

Dim e As System.Drawing.Printing.PrintPageEventArgs
Dim rightMargin As Single = e.MarginBounds.Right
Dim topMargin As Single = e.MarginBounds.Top

Dim printFont As New Font("tahoma", 9)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim line As String = Nothing

Dim j As Integer

Dim dst As New DataSet
Dim adaptor As New SqlClient.SqlDataAdapter
Dim SqlConnection1 As New SqlClient.SqlConnection("Data Source=ABASALEH;Initial Catalog=testDB;Integrated Security=True")

linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
Dim cmd As New SqlClient.SqlCommand
cmd = New SqlClient.SqlCommand("Sel_SalesData", SqlConnection1)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@vDepartment", vDepartment)
cmd.Parameters.AddWithValue("@iSalesYear", iSalesYear)
If SqlConnection1.State = ConnectionState.Closed Then

SqlConnection1.Open()
End If

cmd.ExecuteScalar()
adaptor.SelectCommand = cmd

adaptor.Fill(dst, "Sel_SalesData")

For j = 0 To 3 'column

e.Graphics.DrawString(dst.Tables(0).Rows(0)(j).ToS tring(), printFont, Brushes.Black, rightMargin, yPos, New StringFormat())
count += 1
yPos = topMargin + count * printFont.GetHeight(e.Graphics)
Next

flag = True

Catch

flag = False

End Try

Return flag
End Function



End Class