|
This is that FoxPro project that I'm working on, and creating a sub report for a report; while using the event handler for SubReportProcessing.
So I have this dataset that I pass to the RDLC file which is a list of invoices for the month. Each invoice has items that I'm using a sub report for. So I made an event handler for it. I have the data already, and perhaps it would be easier to just write another function to load the data in the event handler instead.
But I just can't get this last part in my event handler, it's so foreign to me.
This is the dataset below that has my invoice items, that I add to LocalReport and is passed to the RDLC. so I have a dataset that is ready to go in "ds_invoice_items"
Dim ds_items As New DataSet()
ds_items.DataSetName = "ds_invoice_items"
ds_items.Tables.Clear()
ds_items.Tables.Add(table_Items)
ds_items.Tables(0).TableName = "tablix_invoice_items"
'Write the datasource to the report canvas
rv_Canvas.LocalReport.DataSources.Clear()
rv_Canvas.LocalReport.DataSources.Add(New ReportDataSource("ds_salesRep", ds_salesRep.Tables(0)))
rv_Canvas.LocalReport.DataSources.Add(New ReportDataSource("ds_salesRep_invoices", ds_invoices.Tables(0)))
rv_Canvas.LocalReport.DataSources.Add(New ReportDataSource("ds_invoice_bAddress", ds_bAddress.Tables(0)))
rv_Canvas.LocalReport.DataSources.Add(New ReportDataSource("ds_invoice_sAddress", ds_sAddress.Tables(0)))
rv_Canvas.LocalReport.DataSources.Add(New ReportDataSource("ds_invoice_items", ds_items.Tables(0)))
rv_Canvas.LocalReport.DisplayName = p_salesRepName & " Invoices"
AddHandler rv_Canvas.LocalReport.SubreportProcessing, AddressOf Me.SetSubDataSource
This is my event handler. The first and 2nd line works. It's the 3rrd line.
My Question is:
I know List(Of model_invoice_items) is wrong. I can't figure out what to replace it with.
Do I get the type, or hard code the type, I don't even know what the type is.
Private Sub SetSubDataSource(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
<pre>
Dim mainSource = CType(sender, LocalReport).DataSources("ds_invoice_items")
Dim FINVNO = Integer.Parse(e.Parameters("FINVNO").Values.First)
Dim subSource = CType(mainSource.Value, List(Of model_invoice_items)).Single(Function(m) m.FINVNO = FINVNO)
e.DataSources.Add(New ReportDataSource("ds_invoice_items", subSource))
End Sub
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
jkirkerx wrote: New ReportDataSource("ds_invoice_items", ds_items.Tables(0))
You're creating the ReportDataSource by passing in a DataTable . Therefore, I would expect the mainSource.Value property to return a DataTable .
Private Sub SetSubDataSource(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
Dim FINVNO As Integer = Integer.Parse(e.Parameters("FINVNO").Values.First)
Dim mainSource As ReportDataSource = DirectCast(sender, LocalReport).DataSources("ds_invoice_items")
Dim mainTable As DataTable = DirectCast(mainSource.Value, DataTable)
Dim subSource As New DataView(mainTable)
subSource.RowFilter = String.Format("FINVNO = {0:D}", FINVNO)
e.DataSources.Add(New ReportDataSource("ds_invoice_items", subSource))
End Sub
If that doesn't work, then you'll need to debug your code; Visual Studio should be able to show you the correct type of the mainSource.Value property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It runs without error and produces results, I just need to validate the results
Question:
subSource.RowFilter = String.Format("FINVNO = {0 }", FINVNO)
The
{0:d} , the value is just a string of numbers, should I change that?
I Actually started thinking a dataview, but ended up with a rats nest, not clean like yours.
Dim FINVNO = Integer.Parse(e.Parameters("FINVNO").Values.First)
Dim ds_invoiceItems As ReportDataSource = CType(sender, LocalReport).DataSources("ds_invoice_items")
Dim dt_invoiceItems As DataTable = ds_invoiceItems.Value
Dim dv_invoiceItems As New DataView(dt_invoiceItems)
Dim view_items = dv_invoiceItems.ToTable().Rows.Cast(Of DataRow)()
Dim table_items As DataTable = view_items.Where(Function(row) row.Field(Of String)("FINVNO") = FINVNO).CopyToDataTable()
Dim ds_items As New DataSet()
ds_items.DataSetName = "ds_invoice_items"
ds_items.Tables.Clear()
ds_items.Tables.Add(table_Items)
ds_items.Tables(0).TableName = "tablix_invoice_items"
e.DataSources.Add(New ReportDataSource("ds_invoice_items", ds_items.Tables(0)))
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
Since the FINVNO variable is an Integer , I assumed the FINVNO column would be as well.
The D is just a standard numeric format string: The Decimal ("D") Format Specifier[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
so, i am a newbie, and i have this code for my .INI settings:
Module Module1
Public Class IniFile
Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String,
ByVal lpKeyName As String,
ByVal lpDefault As String,
ByVal lpReturnedString As System.Text.StringBuilder,
ByVal nSize As Integer,
ByVal lpFileName As String) _
As Integer
Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String,
ByVal lpKeyName As String,
ByVal lpString As String,
ByVal lpFileName As String) _
As Integer
Public Property Path As String
Public Sub New(ByVal IniPath As String)
_Path = IniPath
End Sub
Public Function ReadValue(ByVal section As String, ByVal key As String) As String
Dim sb As New System.Text.StringBuilder(255)
Dim i = GetPrivateProfileString(section, key, "", sb, 255, Path)
Return sb.ToString()
End Function
Public Sub WriteValue(ByVal section As String, ByVal key As String, ByVal value As String)
WritePrivateProfileString(section, key, value, Path)
End Sub
End Class
End Module
.. but this does not allows me to read multiline... it is writing multiline in the .INI file, but it is not reading!!
What do i need to change or do to read multiline of the .INI file?
TIA,
Duarte
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Can you show the response that it read, vs. the input that was given? I think you are reading entire content as text (instead of lines).
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: Can you show the response that it read, vs. the input that was given?
Well, i am inserting text like this in a multiline textbox:
test now
multiline etc...
And it is returning on read only the first line, in this case only the "test now" words!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
INI file elements are expected to each be on a single line. If you have large amounts of data then you need to think of an alternative method of storing it. Also these functions have been deprecated in favour of using the Registry.
|
|
|
|
|
ok... so what do you advise for storing text?!!
I am very newbie but i understand some snippets!!
Thanks!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
The first thing you need to answer is: what is this information used for, and how long do you need to store it? If it is just simple text that your program needs to process then use a text file or similar. INI files are really just for static key/value pairs that do not change often.
|
|
|
|
|
Yes i understand... i am currently trying a piece of code from MSDN to write a reaad from .txt!
Thanks : )
Duarte
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Hi,
sorry to bother again but i need a bit more help!!!
Now i have this code to write and read from .txt files:
Sub readtext()
Dim path As String = Directory.GetCurrentDirectory()
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(path + Form1.TextBox1.Text + ".txt")
Form1.TextBox2.Text = fileReader
End Sub
Sub writetext()
Dim objStreamWriter As StreamWriter
Dim path As String = Directory.GetCurrentDirectory()
objStreamWriter = New StreamWriter(path + Form1.TextBox1.Text + ".txt")
objStreamWriter.WriteLine(Form2.TextBox2.Text)
objStreamWriter.Close()
End Sub
... but when it tries to read from an unexisting file, it returns a code error.... my question is what can i do so that when i press a button that applies te "readtext" function, but the file does not exists, it shows a msgbox instead of returnning code error?
I hope i s clear enough!!!??
Thanks,
Duarte
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Try something like this:
Sub readtext()
Dim folderPath As String = Directory.GetCurrentDirectory()
Dim filePath As String = Path.Combine(folderPath, Form1.TextBox1.Text + ".txt")
If Not File.Exists(filePath) Then
MessageBox.Show("File not found.")
Return
End If
Try
Dim fileContents As String = File.ReadAllText(filePath)
Form1.TextBox2.Text = fileContents
Catch ex As FileNotFoundException
MessageBox.Show("File was deleted")
Catch ex As IOException
MessageBox.Show(ex.Message)
End Try
End Sub
Sub writetext()
Dim folderPath As String = Directory.GetCurrentDirectory()
Dim filePath As String = Path.Combine(folderPath, Form1.TextBox1.Text + ".txt")
Using writer As StreamWriter = File.AppendText(filePath)
writer.WriteLine(Form2.TextBox2.Text)
End Using
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks... i think i can drive it from here!! : )
Merry Xmas,
Duarte
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Hi there,
just a bit more...please... i have this code to search for data in a .txt/.ini file but it is only returning the first line found!
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim folderPath As String = Directory.GetCurrentDirectory()
Dim filePath As String = Path.Combine(folderPath + ("Data1.ini"))
TextBox7.Text = File.ReadAllLines(filePath).FirstOrDefault(Function(x) x.Contains("11/12/2016"))
End Sub
My idea is to get all lines that contain the "date i want".....if possible without the .ini key name!!!
Help?!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Let me repeat what has been said; INI files are deprecated. There is hardly any support for them in .NET, and there is no reason to prefer them over XML.
There's an error on below line;
Dim filePath As String = Path.Combine(folderPath + ("Data1.ini")) You are concatenating two strings, and passing them to the Path.Combine method. That method gets one single string, and does nothing to it.
Below code lists all the occurences of a string in your textbox. With XML, you could simply select the required elements.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim folderPath As String = Directory.GetCurrentDirectory()
Dim filePath As String = Path.Combine(folderPath, "TextFile1.txt")
TextBox1.Multiline = True
TextBox1.Size = New Size(100, 100)
TextBox1.Text = String.Join(Environment.NewLine, File.ReadAllLines(filePath).Where(Function(x) x.Contains("audio")))
End Sub
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
ok thanks.. i am using a .ini file just to keep some dates and names...nothing big...
modified 7-Jan-19 21:02pm.
|
|
|
|
|
You can do the same with XML, for which there IS support. Why use an outdated format?
It can't be the fact that you can easily edit INI-files in a text-editor, as XML files have the same option. It can't be due to the support, as there is none. It's a bad idea.
Rolling your own text-files and using a file-extension to your liking is even a better option.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i am very newbie..if i change to XML i gotta ask you almost everything.. as i already made some code with .ini some years ago, i am more familiarized of how to work with it... : )
Thanks,
Duarte
modified 7-Jan-19 21:02pm.
|
|
|
|
|
The problem is that the framework is not familiair with it, and that there is no "nice" way of getting those values or, like you may have noticed, have some strange characters in them (like a newline).
It ain't that hard to learn to read/write XML. No more problems with newlines or weird characters.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
ok my code as changed..i googled for new code and i believe i found some that i can understand and is easy to apply.
The only problem is that is writing and reading only the first node.
How can i create new nodes and read only those that have the Date i want selected?
Please give me a hand here..this is not important as hell but i would like to be able to end my gadget... i believe i can do it with a few lines of code and is nothing really hard..but yes.. i am not understanding how to read and write more than one node...
here is my current code:
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim folderPath As String = Directory.GetCurrentDirectory()
Dim filePath As String = Path.Combine(folderPath, "MEMOS\Database.xml")
Dim dat = TextBox1.Text
Dim plc = TextBox2.Text
Dim hed = TextBox3.Text
Dim mem = TextBox4.Text
Dim hor = ComboBox1.Text + " : " + ComboBox2.Text + " " + ComboBox3.Text
Dim writer As New XmlTextWriter(filePath, System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("MEMOSAVE")
createNode(dat, hor, plc, hed, mem, writer)
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim folderPath As String = Directory.GetCurrentDirectory()
Dim filePath As String = Path.Combine(folderPath, "MEMOS\Database.xml")
If Not File.Exists(filePath) Then
MessageBox.Show("DataBase not found!")
Else
Dim sav = TextBox1.Text
Dim xmlFile As XmlReader
xmlFile = XmlReader.Create(filePath, New XmlReaderSettings())
Dim ds As New DataSet
Dim dv As DataView
ds.ReadXml(xmlFile)
dv = New DataView(ds.Tables(0))
dv.Sort = "Date"
Dim index As Integer = dv.Find(sav)
If index = -1 Then
MsgBox("Item Not Found")
Else
Label9.Text = (dv(index)("Date").ToString())
Label10.Text = (dv(index)("Hour").ToString())
Label11.Text = (dv(index)("Place").ToString())
Label12.Text = (dv(index)("Header").ToString())
TextBox4.Text = (dv(index)("MEMO").ToString())
End If
Return
End If
End Sub
Thank you!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
Alienoiz wrote: The only problem is that is writing and reading only the first node. I only see one call to the "createNode" method. What happens if you call that method twice?
="1.0"="utf-8"="yes"
<MEMOSAVE>
<15/12/2016>
<Date>15/12/2016</Date>
<Hour>01 : 05 PM</Hour>
<Place>USA</Place>
<Header>Testing Memo</Header>
<MEMO>Memorando test text!</MEMO>
</15/12/2016>
</MEMOSAVE> Your fragment has an element with the name 15/12/2016, but element-names (the things between the < and >) aren't allowed to have slashes in them. You could name it "entry" though. You already have the date in the properties following that, so it would also be a bit redundant to specify it twice.
Alienoiz wrote: i believe i can do it with a few lines of code and is nothing really hard..but yes.. You may need a bit more to handle multiple memo's.
I'd recommend creating a POCO, put those entries in a list, and XmlSerialize that. It looks more readable, and is easier to play with.
Imports System.IO
Imports System.Xml.Serialization
Public Class MyMemoEntry
Public CreatedOn As DateTime
Public Location As String
Public Header As String
Public Memo As String
End Class
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Entries As New List(Of MyMemoEntry)
Dim newEntry As New MyMemoEntry
newEntry.CreatedOn = DateTime.Now
newEntry.Location = "Home, sweet home"
newEntry.Header = "How to build a decent chicken-soup"
newEntry.Memo = "Call Mom and say you want chicken-soup"
Entries.Add(newEntry)
Dim serializer As New XmlSerializer(Entries.GetType(), "space")
Using FileStream As New FileStream("output.xml", FileMode.Create)
serializer.Serialize(FileStream, Entries)
End Using
End Sub
End Class Which results in a file similar to below;
="1.0"
<ArrayOfMyMemoEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="space">
<MyMemoEntry>
<CreatedOn>2016-12-14T17:59:55.9937761+01:00</CreatedOn>
<Location>Home, sweet home</Location>
<Header>How to build a decent chicken-soup</Header>
<Memo>Call Mom and say you want chicken-soup</Memo>
</MyMemoEntry>
</ArrayOfMyMemoEntry> That should be somewhat easier than writing the XML using a writer directly.
Also note that above saves a list of entries, not just one entry. You can fetch the CreatedOn property and get either the Date-part, the Time-part or both parts. Aw, and you don't have to use the "xml" file-extension when writing to a file, as long as you're using the right format.
Another nice thing about the above is that it is quite easy to replace the XmlSerializer with a JsonSerializer or the BinarySerializer. That way you are not limited or bound to XML.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
ok.. thanks.. i am going to explore this as i am.. i hope i can get this done : )
Thanks again!
modified 7-Jan-19 21:02pm.
|
|
|
|
|
something is wrong.. i am not still being able to create various "myMemoEntry" nodes.. i would like to support each dataset in different nodes and access it by "Date"...
i would like to write something like this:
="1.0"
<ArrayOfMyMemoEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="space">
<MyMemoEntry>
<CreatedOn>2016-12-14T17:59:55.9937761+01:00</CreatedOn>
<Location>Home, sweet home</Location>
<Header>How to build a decent chicken-soup</Header>
<Memo>Call Mom and say you want chicken-soup</Memo>
</MyMemoEntry>
<MyMemoEntry1>
<CreatedOn>2016-12-14T17:59:55.9937761+01:00</CreatedOn>
<Location>Home</Location>
<Header>chicken-soup</Header>
<Memo>Call Mom</Memo>
</MyMemoEntry1>
</ArrayOfMyMemoEntry>
: ) .. and then when i read, get all data inside the entry that has for eg: "2016-12-14"
:s
modified 7-Jan-19 21:02pm.
|
|
|
|
|
That's not a valid* XML format; forget about how you want it to look, the format is simply there to provide structure to load and save from.
Dim newEntry As New MyMemoEntry
newEntry.CreatedOn = DateTime.Now
newEntry.Location = "Home, sweet home"
newEntry.Header = "How to build a decent chicken-soup"
newEntry.Memo = "Call Mom and say you want chicken-soup"
Dim notherEntry As New MyMemoEntry
notherEntry.CreatedOn = DateTime.Now
notherEntry.Location = "Home, sweet home"
notherEntry.Header = "How to build a decent noodle-soup"
notherEntry.Memo = "Call Mom and say you want noodle-soup"
Dim testEntry As New MyMemoEntry
testEntry.CreatedOn = DateTime.Now.AddDays(-2)
testEntry.Location = "The restaurant at the end of the Universe"
testEntry.Header = "Eat more soup"
testEntry.Memo = "I forgot the reason"
Entries.Add(newEntry)
Entries.Add(notherEntry)
Entries.Add(testEntry)
Gives you valid XML like below;
="1.0"
<ArrayOfMyMemoEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="space">
<MyMemoEntry>
<CreatedOn>2016-12-14T18:54:25.0337545+01:00</CreatedOn>
<Location>Home, sweet home</Location>
<Header>How to build a decent chicken-soup</Header>
<Memo>Call Mom and say you want chicken-soup</Memo>
</MyMemoEntry>
<MyMemoEntry>
<CreatedOn>2016-12-14T18:54:25.0337545+01:00</CreatedOn>
<Location>Home, sweet home</Location>
<Header>How to build a decent noodle-soup</Header>
<Memo>Call Mom and say you want noodle-soup</Memo>
</MyMemoEntry>
<MyMemoEntry>
<CreatedOn>2016-12-12T18:54:25.0337545+01:00</CreatedOn>
<Location>The restaurant at the end of the Universe</Location>
<Header>Eat more soup</Header>
<Memo>I forgot the reason</Memo>
</MyMemoEntry>
</ArrayOfMyMemoEntry> ..accessing the items in a list by date would not be hard either this way;
For Each item As MyMemoEntry In Entries _
.Where(Function(ent As MyMemoEntry) As Boolean
Return ent.CreatedOn.Date = DateTime.Today
End Function)
MessageBox.Show(item.Header)
Next
You can filter on any of the other fields in a similar way.
--edit
It is valid to confuse stuff more, as any XML-validator will tell you. It would also be abusing the format, as items representing the same thing are supposed to have the same element-name.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|