PDA

View Full Version : print گرفتن از محتویات DataSet



sh_m
سه شنبه 17 آذر 1383, 10:37 صبح
سلام
آیا می توان بدون استفاده از CrystalReport از محتویات یک DataSet پرینت گرفت؟ به طور کلی برای تهیه پرینت از رکوردهای یک جدول به غیر از استفاده از crystal report چه راه دیگری وجود دارد ؟ چون من میخوام در برنامه ام گزارشات معمولی قابل پرینت جهت اطلاع کاربر داشته باشم که نیازی به امکانات crystal report ندارم و به دنبال راهی هستم که دردسرهای crystal report را نداشته باشد .
ممنون میشم اگر راهنمایی کنید.

sh
سه شنبه 17 آذر 1383, 23:21 عصر
خوب میتونی از امکان پرینت پریویو استفاده کنی یا خودت مستقیما اطلاعات رو به چاپگر بفرستی

M.GhanaatPisheh
چهارشنبه 18 آذر 1383, 02:53 صبح
crystal report و درد سر
هر کار دیگهای بخوا بکنی دردسرت خیلی بیشتر میشه.

moiid63
یک شنبه 23 اردیبهشت 1386, 13:13 عصر
'----------------------------- کنترل های مورد استفاده
'-------------PageSetupDialog
'-------------PrintDocument
'-------------PrintPreviewDialog
'--------------------------------------------------------------
Private Sub MnItmPRINT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnItmPRINT.Click
If -DataSet-Name- .Rows.Count > 0 Then
CountLine = 0
NumberColumnsForPrint = -DataSet-Name- .Columns.Count
Titr = " جدول ..."
'-در این صفحه متغییر های سراسری را کاربر تنظیم می کند
'-مانند تعداد ستونها یا نوع خط جدول و ...
Dim OBJ As New PrintSettingPAGE()
OBJ.ShowDialog()
PageSetupDialog1.ShowDialog()
PrintPreviewDialog1.ShowDialog()
Else
MsgBox("اطلاعاتی برای پرینت وجود ندارد", MsgBoxStyle.OKOnly, "")
End If
End Sub
'------------------------------------------------------------------
'----------------------------- توابع مورد نیاز پرینت ---------------
'-------------------------------------------------------------------
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'----------------------------- متغیر های سراسری استفاده شده-------------
'-------------dim VerticalPAGE as Boolean افقی یا عمودی بودن صفحه
'-------------dim NumberColumnsForPrint as integer
'--------DirectionVertical تعداد ستونهای دیتاست که میخواهیم چاپ کنیم
'-------------dim LinesPerPage as Integer تعداد خطهای هر صفحه
'-------------dim Titr as String تیتر هر صفحه
'--------------------------------------------------------------
Dim xCell As Integer
Dim yCell As Integer
Dim WidthCell As Integer
Dim xTITR As Integer
Dim yTITR As Integer
Dim HeightTITR As Integer
Dim WidthTITR As Integer
'--------------------------------------------------------------
'------------مقدار دهی اندازه ها و موقعیت سلول های جدول
'--------------------------------------------------------------
yTITR = CInt(PageSetupDialog1.PageSettings.Margins.Top)
xTITR = CInt(PageSetupDialog1.PageSettings.Margins.Left)
If PageSetupDialog1.PageSettings.Landscape = True Then
WidthTITR = CInt(PageSetupDialog1.PageSettings.PaperSize.Heigh t) - (xTITR + CInt(PageSetupDialog1.PageSettings.Margins.Right))
Else
WidthTITR = CInt(PageSetupDialog1.PageSettings.PaperSize.Width ) - (xTITR + CInt(PageSetupDialog1.PageSettings.Margins.Right))
End If
HeightTITR = 35
xCell = PageSetupDialog1.PageSettings.Margins.Left
yCell = yTITR + HeightTITR
WidthCell = CInt(WidthTITR \ NumberColumnsForPrint)
'--------------------------------------------------------------
'------------محاسبه تعداد خطهای هر صفحه
Dim LinesPerPage As Integer
If PageSetupDialog1.PageSettings.Landscape = True Then
LinesPerPage = CInt((CInt(PageSetupDialog1.PageSettings.PaperSize .Width) - (yTITR + HeightTITR + HeightHeaderCell + CInt(PageSetupDialog1.PageSettings.Margins.Bottom) )) \ HeightCell)
Else
LinesPerPage = CInt((CInt(PageSetupDialog1.PageSettings.PaperSize .Height) - (yTITR + HeightTITR + HeightHeaderCell + CInt(PageSetupDialog1.PageSettings.Margins.Bottom) )) \ HeightCell)
End If
'----------------------------------------------------------------------
Dim RectF As RectangleF
If -DataSet-Name- .Rows.Count <> 0 Then
'----------------------------------------------------------
'------------ نوشتن متن تیتر
'----------------------------------------------------------
Dim StrForm As StringFormat
StrForm = New StringFormat(StringFormatFlags.DirectionRightToLef t)
StrForm.Alignment = StringAlignment.Center
StrForm.LineAlignment = StringAlignment.Center
RectF.X = xTITR ' xTITR = 15 or 790
RectF.Y = yTITR ' yTITR = 15 or 15
RectF.Height = HeightTITR ' HeightTITR = 25 or 25
RectF.Width = WidthTITR ' WidthTITR = 750 or 1140
e.Graphics.DrawString(Titr, TitrFont, Brushes.Black, RectF, StrForm)
'----------------------------------------------------------
'------------ نوشتن سطرها
'----------------------------------------------------------
RectF.X = xCell
RectF.Y = yCell + HeightHeaderCell
RectF.Width = WidthCell
RectF.Height = HeightCell
StrForm.Alignment = StringAlignment.Far
StrForm.LineAlignment = StringAlignment.Far
Dim PrintFont As New Font("Arial", 10)
PrintFont = DataGrid1.Font
Dim StrField As String '' برای دریافت فیلدهای جدول
Dim counter As Integer '' شمارهنده
For I2 = 0 To LinesPerPage - 1
RectF.X = xCell
For I = (NumberColumnsForPrint - 1) To 0 Step -1
StrField = " " & CStr( -DataSet-Name- .Rows(CountLine).Item(I))
e.Graphics.DrawRectangle(PenRow, RectF.X, RectF.Y, RectF.Width, RectF.Height)
e.Graphics.DrawString(StrField, PrintFont, Brushes.Black, RectF, StrForm)
RectF.X += WidthCell
StrField = ""
Next
RectF.Y += HeightCell
CountLine += 1
If -DataSet-Name- .Rows.Count = CountLine Then
Exit For
End If
Next
'----------------------------------------------------------
'------------ کشیدن نام ستونها
'----------------------------------------------------------
StrForm.Alignment = StringAlignment.Center
StrForm.LineAlignment = StringAlignment.Center
RectF.X = xCell
RectF.Y = yCell
RectF.Width = WidthCell
RectF.Height = HeightHeaderCell
PrintFont = DataGrid1.HeaderFont
For I = (NumberColumnsForPrint - 1) To 0 Step -1
StrField = CStr( -DataSet-Name- .Columns(I).ColumnName)
e.Graphics.DrawRectangle(PenColumn, RectF.X, RectF.Y, RectF.Width, RectF.Height)
e.Graphics.DrawString(StrField, PrintFont, Brushes.Black, RectF, StrForm)
RectF.X += WidthCell
StrField = ""
Next
End If
'--------------------------------------------------------------
'------------اگر تعداد خطها زیاد شد باید صفحه دیگر ایجاد شود
'------------در غیر این صورت صفحه جدید نباید تولید شود
'--------------------------------------------------------------
If CountLine < -DataSet-Name- .Rows.Count Then
e.HasMorePages = True
Else
CountLine = 0
e.HasMorePages = False
End If
End Sub