Print Record with tabular formats in VB.net Winform with crystal report or sql server-2022

Print Record with tabular formats in VB.net Winform with crystal report or sql server-2022


CREATE TABLE [dbo].[TBL_Barcode](
[Barcode1] [varchar](max) NULL,
[Barcode2] [varchar](max) NULL,
[Barcode3] [varchar](max) NULL,
[Barcode4] [varchar](max) NULL,
[Barcode5] [varchar](max) NULL,
[ID] [bigint] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_TBL_Barcode] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


  Private Sub CloudButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloudButton1.Click
        Dim x, i As Integer
        Dim cnt As Integer
        Dim XHOLD As Integer
        Dim name As String
        Dim Report As New FrmREPORTS
        Dim holdI As Integer
        'Dim ast As String = "11"
        'Dim ast1 As String = "Emp Name-Mukesh"
        'Dim ast2 As String = "Emp code-1009"
        Dim ast, ast1, ast2, ast3 As String
        cnt = 0
        holdI = 0
        If DataGridView4.Rows.Count > 0 Then
            sqlSTR = "DELETE FROM TBL_Barcode"
            ExecuteSQLQuery(sqlSTR)
            '  For i As Integer = 0 To DataGridView2.Rows.Count - 1

            For x = 0 To DataGridView4.Rows.Count - 1
                ast = Me.DataGridView4.Rows(x).Cells(1).Value.ToString()
                ast1 = Me.DataGridView4.Rows(x).Cells(4).Value.ToString()
                ast2 = Me.DataGridView4.Rows(x).Cells(5).Value.ToString()
                ast3 = Me.DataGridView4.Rows(x).Cells(0).Value.ToString()
                cnt = cnt + 1
                If cnt < 4 Then
                    If cnt = 1 Then
                        ' sqlSTR = "INSERT INTO TBL_Barcode (Barcode1) VALUES ('" & lstbarcode.Items(x).Text & "'+'" & lstbarcode.Items(x).Text & "')"
                        '  lstbarcode.Item.SubItems.Item(1).Text()
                        sqlSTR = "INSERT INTO TBL_Barcode (Barcode1) VALUES ('" & ast3 & "'+'" & Environment.NewLine & ast & "'+'" & Environment.NewLine & ast1 & "'+'" & Environment.NewLine & ast2 & "')"

                        ExecuteSQLQuery(sqlSTR)
                        sqlSTR = "SELECT * FROM TBL_Barcode ORDER BY ID DESC"
                        ExecuteSQLQuery(sqlSTR)
                        XHOLD = sqlDT.Rows(0)("ID")
                        ' name = sqlDT.Rows(1)("Barcode1")
                    ElseIf cnt = 2 Then
                        sqlSTR = "UPDATE TBL_Barcode SET Barcode2 ='" & ast3 & "'+'" & Environment.NewLine & ast & " '+'" & Environment.NewLine & ast1 & "'+'" & Environment.NewLine & ast2 & "' WHERE ID =" & XHOLD
                        ExecuteSQLQuery(sqlSTR)
                    ElseIf cnt = 3 Then
                        sqlSTR = "UPDATE TBL_Barcode SET Barcode3 ='" & ast3 & "'+'" & Environment.NewLine & ast & " '+'" & Environment.NewLine & ast1 & "'+'" & Environment.NewLine & ast2 & "' WHERE ID =" & XHOLD
                        ExecuteSQLQuery(sqlSTR)
                    End If
                Else
                    cnt = 1
                    sqlSTR = "INSERT INTO TBL_Barcode (Barcode1) VALUES ('" & ast3 & "'+'" & Environment.NewLine & ast & "'+'" & Environment.NewLine & ast1 & "'+'" & Environment.NewLine & ast2 & "')"
                    ExecuteSQLQuery(sqlSTR)
                    sqlSTR = "SELECT * FROM TBL_Barcode ORDER BY ID DESC"
                    ExecuteSQLQuery(sqlSTR)
                    XHOLD = sqlDT.Rows(0)("ID")
                End If
            Next
        
        End If

        ' End If

        globalFRM = "patientIntakeForm"
        Rpt_SqlStr = "SELECT * FROM TBL_Barcode "
        Report.Show()
    End Sub
---------------------------------------------------------------
print page 
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.OleDb
Imports System.Data

Public Class FrmREPORTS
    Private Sub FrmREPORTS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ParamCollection As New CrystalDecisions.Shared.ParameterValues
        mReport = New ReportDocument()

           Select Case UCase(globalFRM)
            Case UCase("frmcatitemlist")

            Case UCase("patientIntakeForm")
                'mReport.Load("D:\Sales and Inventory\prjSalesInventory\prjSalesInventory\ReportX\BARCODE.rpt")
                mReport.Load(Application.StartupPath & "\ReportX\BARCODE.rpt")
                Call DataSourceConnection_Report()
                mReport.SetDataSource(ExecuteSQLQuery(Rpt_SqlStr))
                CrystalReportViewer1.ReportSource = mReport

                'Me.MdiParent = MDIMain

            Case UCase("frmproduct_pacing")
                ''mReport.Load("D:\_PROGRAM\_VB.NET\Sales and Inventory\prjSalesInventory\prjSalesInventory\ReportX\ProductPacing_Report.rpt")
                'mReport.Load(Application.StartupPath & "\ReportX\physicalcount_report.rpt")
                'Call DataSourceConnection_Report()
                'mReport.SetDataSource(ExecuteSQLQuery(Rpt_SqlStr))
                'ParamCollection.Add(_USER)
                'mReport.DataDefinition.ParameterFields("user").ApplyCurrentValues(ParamCollection)

                'ParamCollection.Add(ParamCompanyName)
                'mReport.DataDefinition.ParameterFields("CompName").ApplyCurrentValues(ParamCollection)

                'ParamCollection.Add(ParamCompanyLoc)
                'mReport.DataDefinition.ParameterFields("CompLoc").ApplyCurrentValues(ParamCollection)

                'CrystalReportViewer1.ReportSource = mReport
                ' Me.MdiParent = MDIMain
        End Select
        
    End Sub
End Class
---
----
 Public Function ExecuteSQLQuery(ByVal SQLQuery As String) As DataTable
        Try
            Dim sqlCon As New SqlConnection(CnString) 'main conntion string.
            Dim sqlDA As New SqlDataAdapter(SQLQuery, sqlCon)
            Dim sqlCB As New SqlCommandBuilder(sqlDA)
            sqlDT.Reset() ' refresh 
            sqlDA.Fill(sqlDT)
        Catch ex As Exception
            MsgBox("Error: " & ex.ToString)
            If Err.Number = 5 Then
                MsgBox("Invalid Database, Configure TCP/IP", MsgBoxStyle.Exclamation, "Hosoft")
            Else
                MsgBox("Error : " & ex.Message)
            End If
            MsgBox("Error No. " & Err.Number & " Invalid database or no database found !! Adjust settings first", MsgBoxStyle.Critical, "Hosoft")
            MsgBox(SQLQuery)
        End Try
        Return sqlDT
    End Function

------------
    Public Function DataSourceConnection_Report()
        If Split(tmpStr, ":")(4) = "1" Then
            '  mReport.DataSourceConnections

            'mReport.DataSourceConnections(0).SetConnection(Split(tmpStr, ":")(1), "SaleInv_DB", Split(tmpStr, ":")(2), Split(tmpStr, ":")(3))
            mReport.DataSourceConnections(0).SetConnection(Split(tmpStr, ":")(1), "Hospital_Disk", False)
            'MsgBox(Split(tmpStr, ":")(2) & "  " & Split(tmpStr, ":")(3))
            mReport.DataSourceConnections(0).SetLogon(Split(tmpStr, ":")(2), Split(tmpStr, ":")(3))
        Else

            mReport.DataSourceConnections(0).SetConnection(Split(tmpStr, ":")(1), "Hospital_Disk", True)
        End If
        'MsgBox(mReport.DataSourceConnections(0).ServerName.ToString)
        Return 0
    End Function

Post a Comment

Previous Post Next Post

Design a beautiful Login/Signup (with google map) in Flutter | Flutter UI | VS Code | iOS Android