Exception for add document variable(I cant figure out) - vb.net

I cant figure out where is my error is.Below is my code and the exception:
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing
Public Class Form1
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Create a word file
Using wordDocument As WordprocessingDocument = WordprocessingDocument.Create("C:\Users\local\Desktop\vb testing purpose\test.docx", WordprocessingDocumentType.Document)
' Add a main document part.
Dim mainPart As MainDocumentPart = wordDocument.AddMainDocumentPart()
' Create the document structure and add some text.
mainPart.Document = New Document()
Dim body As Body = mainPart.Document.AppendChild(New Body())
Dim para As Paragraph = body.AppendChild(New Paragraph())
Dim run As Run = para.AppendChild(New Run())
run.AppendChild(New Text(""))
End Using
Dim strDoc As String = "C:\Users\local\Desktop\vb testing purpose\test.docx"
Dim varname As String = "Hi"
Dim varvalue As String = "Bryan"
AddDocVar(strDoc, varname, varvalue)
End Sub
Public Sub AddDocVar(ByVal sender As Object, ByVal varName As String, ByVal varValue As String)
Dim mainPart As MainDocumentPart = sender.MainDocumentPart
Dim settingsPart As DocumentSettingsPart = mainPart.DocumentSettingsPart
settingsPart.Settings = New Settings(New DocumentVariables(New DocumentVariable() With {.Name = varName, .Val = varValue}))
End Sub
End Class
Comes out a
exception(System.MissingMemberException: 'Public member 'MainDocumentPart' on type 'String' not found.') in
Dim mainPart As MainDocumentPart = sender.MainDocumentPart

Related

vb.net - How to get webbrowser InnerHtml under multithread

I use SetApartmentState in webbrowser:
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Dim th As System.Threading.Thread = New Threading.Thread(AddressOf Task_A)
th.SetApartmentState(ApartmentState.STA)
th.Start()
End Sub
Public Sub Task_A()
Dim frmBuild = New NewForm()
Dim WebBrowser1 = New WebBrowser()
Application.Run(frmBuild)
frmBuild.Controls.Add(WebBrowser1)
WebBrowser1.CreateControl()
End Sub
Private Delegate Function GetInnerHTMLCallBack() As String
Private Function GetInnerHTML() As String
If WebBrowser1.InvokeRequired Then
Return CStr(WebBrowser1.Invoke(New GetInnerHTMLCallBack(AddressOf GetInnerHTML)))
Else
Return WebBrowser1.Document.Body.InnerHtml
End If
End Function
Dim innerHTML As String = GetInnerHTML()
frmMain.textbox1.text=innerHTML
Dim docs As mshtml.HTMLDocument = WebBrowser1.Document.DomDocument
I get nothing, how can I get or set string in cross threading?
I am very poor in multi-threading.

Printing two pages in SSRS using VB.net

I am working on a project where a button is clicked in a program and a two page duplex report that is in SSRS prints out. I have gotten it to the point where I get one of the two pages to print but not the duplex page. I know I need to set e.HasMorePages to true and put in an index. The problem is when it goes to page two it errors because of the metafile. I'm not sure how to get around this.
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports Microsoft.Reporting.WinForms
Public Class Printing
Dim pages As New List(Of Metafile)
Dim pageIndex As Integer = 0
Dim doc As New System.Drawing.Printing.PrintDocument()
Dim ReportViewer1 As New ReportViewer
Dim TotalQTY As Int32
Dim data() As Byte
Dim receiveText As String
Private Sub Printing_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'receiveText = Command()
receiveText = "08NFA-0000"
With ReportViewer1
.Visible = False
.ProcessingMode = ProcessingMode.Remote
.ServerReport.ReportPath = "/Traveler/Traveler"
.ServerReport.ReportServerUrl = New _
Uri("http://sql01/ReportServer_MADE2MANAGE")
End With
Me.Controls.Add(ReportViewer1)
Dim doc As New System.Drawing.Printing.PrintDocument()
doc = New System.Drawing.Printing.PrintDocument()
AddHandler doc.PrintPage, AddressOf PrintPageHandler
Dim dialog As New PrintDialog()
dialog.Document = doc
doc.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical
Dim deviceInfo As String =
"<DeviceInfo>" &
"<OutputFormat>emf</OutputFormat>" &
" <PageWidth>8.5in</PageWidth>" &
" <PageHeight>11in</PageHeight>" &
" <MarginTop>0.125in</MarginTop>" &
" <MarginLeft>0.125in</MarginLeft>" &
" <MarginRight>0.125in</MarginRight>" &
" <MarginBottom>0.125in</MarginBottom>" &
"</DeviceInfo>"
Dim warnings() As Microsoft.Reporting.WinForms.Warning
Dim streamids() As String
Dim mimeType, encoding, filenameExtension As String
mimeType = "" : encoding = "" : filenameExtension = ""
Dim Parm As New ReportParameter("JobOrder", receiveText)
Dim parmSO1(0) As ReportParameter
parmSO1(0) = Parm
ReportViewer1.ServerReport.SetParameters(parmSO1)
data = ReportViewer1.ServerReport.Render("Image",
deviceInfo, mimeType, encoding, filenameExtension,
streamids, warnings)
pages.Add(New Metafile(New MemoryStream(data)))
For Each pageName As String In streamids
data = ReportViewer1.ServerReport.RenderStream("Image",
pageName, deviceInfo, mimeType, encoding)
pages.Add(New Metafile(New MemoryStream(data)))
Next
doc.Print()
Me.ReportViewer1.RefreshReport()
Me.Close()
End Sub
Private Sub PrintPageHandler(ByVal sender As Object,
ByVal e As PrintPageEventArgs)
Dim page As Metafile = pages(pageIndex)
pageIndex += 1
Dim pWidth As Integer = 910
Dim pHeight As Integer = 1500
e.Graphics.DrawImage(page, 0, 0, pWidth, pHeight)
e.HasMorePages = pageIndex < pages.Count
End Sub
End Class

My Crystal Report is not showing the hole list

Please help with my crystal report, because it doesn't show the hole list when i use parameter fields for a list. here is my class below
`Imports System.Windows.Forms.Application
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Windows.Forms
Public Class CrystalReportHelperClass
Dim Sql As New SqlHelper
Dim CR_ParamDisVals As New ParameterDiscreteValue
Dim CR_ParamVals As New ParameterValues
Dim CR_ParamDef As ParameterFieldDefinition
Dim CR_ParamDefs As ParameterFieldDefinitions
Dim CRPTDoc As New ReportDocument
Dim CRPTViewer As New CrystalReportViewer
Public Sub New(ByRef CReport As CrystalDecisions.Windows.Forms.CrystalReportViewer)
CRPTViewer = CReport
CRPTDoc = CReport.ReportSource
End Sub
Public Sub CrystalObjectParam(ByVal CrystalReportObject As String, ByVal Message As String)
CR_ParamDisVals.Value = Message
CR_ParamDefs = CRPTDoc.DataDefinition.ParameterFields
CR_ParamDef = CR_ParamDefs.Item(CrystalReportObject)
CR_ParamVals = CR_ParamDef.CurrentValues
CR_ParamVals.Clear()
CR_ParamVals.Add(CR_ParamDisVals)
CR_ParamDef.ApplyCurrentValues(CR_ParamVals)
End Sub
Public Function GetCrystalReport() As ReportDocument
Return CRPTDoc
End Function
End Class
`
then here is the form load
Private Sub ReportEmployeeList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RepDoc As New ReportDocument
RepDoc = CRPT_Employee.ReportSource
If Sql.HasConnection() = True Then
Dim DT As DataTable = Sql.ExecuteDataTableSP("SelectWorking")
For Each Data As DataRow In DT.Rows
CRPT.CrystalObjectParam("ID", Data(1))
Next
Else
MsgBox("System Database Cannot be Connected", MsgBoxStyle.Information)
End If
CRPT_Employee.ReportSource = CRPT.GetCrystalReport
CRPT_Employee.Refresh()
End Sub
then i have 1 parameter field in my crystal report, id -> discrete value
what should i do?
i already used other methods like this one
Private Sub SetCurrentValuesForParameterField(ByVal myParameterFields As ParameterFields, ByVal myArrayList As ArrayList)
Dim currentParameterValues As ParameterValues = New ParameterValues()
For Each submittedValue As Object In myArrayList
Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
myParameterDiscreteValue.Value = submittedValue.ToString()
currentParameterValues.Add(myParameterDiscreteValue)
Next
Dim myParameterField As ParameterField = myParameterFields(PARAMETER_FIELD_NAME)
myParameterField.CurrentValues = currentParameterValues
End Sub
modify your method as below if i understood what do you want>>>
Dim DT As DataTable = Sql.ExecuteDataTableSP("SelectWorking")
For Each Data As DataRow In DT.Rows
CRPT.SetParameterValue("ID", Data(1))

Print Preview not displaying file

I am working on a menu strip Print Preview event. i worked out the following procedure to view a pdf file located in the same path as my workbook.
Private WithEvents docPrint As New PrintDocument()
' Declare a string to hold the entire document contents.
Private documentContents As String
' Declare a variable to hold the portion of the document that
' is not printed.
Private stringToPrint As String
Private Sub ReadDocument()
Dim xlWBPath As String = Globals.ThisWorkbook.Application.ActiveWorkbook.Path
Dim docName As String = xlWBPath & "\" & "CustomRanges.pdf"
docPrint.DocumentName = docName
Dim stream As New FileStream(docName, FileMode.Open)
Try
Dim reader As New StreamReader(stream)
Try
documentContents = reader.ReadToEnd()
Finally
reader.Dispose()
End Try
Finally
stream.Dispose()
End Try
stringToPrint = documentContents
End Sub
Private Sub prnPrvStripCustomRange_Click(sender As Object, e As EventArgs) Handles prnPrvStripCustomRanges.Click
ReadDocument()
prnPrvCustomRanges.Document = docPrint
prnPrvCustomRanges.ShowDialog()
End Sub
The dialog pops up on click, but my document page is blank. I have another event for printing and that one prints the same document. So I don't understand what I am doing wrong on my preview.
Here is my print procedure:
Private Sub prnCustonPages_Click(sender As Object, e As EventArgs) Handles prnCustonPages.Click
Dim xlWBPath As String = Globals.ThisWorkbook.Application.ActiveWorkbook.Path
Dim docName As String = xlWBPath & "\" & "CustomRanges.pdf"
docPrint.DocumentName = docName
prnPrtCustomRanges.Document = docPrint
prnPrtCustomRanges.PrinterSettings = docPrint.PrinterSettings
prnPrtCustomRanges.AllowSomePages = True
If prnPrtCustomRanges.ShowDialog = DialogResult.OK Then
docPrint.PrinterSettings = prnPrtCustomRanges.PrinterSettings
docPrint.Print()
End If
End Sub

Empty ControlCollection at Runtime

I can't find an answer to this anywhere. I define a new instance of a forms control collection, but at runtime, the collection is empty. It works for one load button on the form, but not another. The code is exactly the same, but one works, the other doesn't. Here is the relevant code:
Private Sub miFLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miFLoad.Click
Dim FilePath As String = "C:\FList\FList.flt"
Dim LoadFile As New SaveandLoad.SaveAndLoad
Dim FileRead As New Simple3Des("MyPassword")
Dim FileString As String = FileRead.ReadFile(FilePath)
With LoadFile
.WhichList = dgFList
.FilePath = FilePath
.DecryptedString = FileRead.DecryptData(FileString)
End With
Call LoadFile.LoadFile()
End Sub
This load button not loading
Private Sub miCLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miCLoad.Click
Dim FilePath As String = "C:\FList\CList.clt"
Dim LoadFile As New SaveandLoad.SaveAndLoad
Dim FileRead As New Simple3Des("MyPassword")
Dim FileString As String = FileRead.ReadFile(FilePath)
With LoadFile
.WhichList = dgCourses
.FilePath = FilePath
.DecryptedString = FileRead.DecryptData(FileString)
End With
Call LoadFile.LoadFile()
End Sub
This one is.
Public Sub LoadFile()
Dim dgRow As DataGridViewRow
Dim dgCell As DataGridViewTextBoxCell
Dim Lines() As String = DecryptedString.Split(vbLf)
Dim LinesList As List(Of String) = Lines.ToList
LinesList.RemoveAt(Lines.Length - 1)
For Each Line As String In LinesList
Dim Fields() As String = Line.Split(",")
dgRow = New DataGridViewRow
For x = 0 To (WhichList.Columns.Count - 1) Step 1
dgCell = New DataGridViewTextBoxCell
dgCell.Value = Fields(x).ToString
dgRow.Cells.Add(dgCell)
Next
WhichList.Rows.Add(dgRow)
Next
Dim FormControls As New frmFacultyList.ControlCollection(frmFacultyList)
For Each DGV As DataGridView In FormControls
If WhichList.Name = DGV.Name Then
DGV = WhichList
DGV.Refresh()
End If
Next
End Sub
Here is where they pass the info to. Again, the FormControls variable is empty for FLoad button click, but not for CLoad button click. Any help would be appreciated.
Edit: Sorry, here are the relevant Public Properties
Public Property WhichList As New DataGridView
Public Property FilePath As String
Public Property DecryptedString As String
Public Property EncryptedString As String
Turns I solved my own problem. The Save Function wasn't writing to the file correctly, so it wasn't pulling the information correctly. Fixed.