?
Solved

Problem with code

Posted on 2009-02-20
4
Medium Priority
?
191 Views
Last Modified: 2012-05-06
I have a listview that is filled with data and that data I export to XML with the code attached.

What I want to do is if I have no item in column 1 it does not write it to the XML but how can I also check column 2 & 3 also to see if that contains data if not then again do not export to XML.

So how can I check column 1,2,3 and if they contain data write it to out if not then do not export. I have got it to work for column 1 but cannot do it for any others.
Dim AppLog As New Logger
 
        Dim os As New StreamWriter(filename)
 
        os.Write("<!-- Generated By Gardiff Fourth Hospitaility Utility " & DateTime.Today.ToString("dd/MM/yyyy") & "-->")
        os.WriteLine()
        os.Write("<!-- Total Sales: " & Label1.Text & "-->")
        os.WriteLine()
        os.Write("<FourthHeader xmlns="""">")
        os.WriteLine()
        os.Write("<OrganisationID>" & FrmSettings.txtID.Text & "</OrganisationID>")
        os.WriteLine()
        os.Write("<UserName>" & FrmSettings.txtFourthUsername.Text & "</UserName>")
        os.WriteLine()
        os.Write("<Password>" & FrmSettings.txtFourthPassword.Text & "</Password>")
        os.WriteLine()
        os.Write("<SalesHeader>")
        os.WriteLine()
        os.Write("<SalesDate>" & DateTime.Today.ToString("dd/MM/yyyy") & "</SalesDate>")
        os.WriteLine()
 
        For i As Integer = 0 To lv.Items.Count - 1
            If lv.Items(i).SubItems(1).Text <> "" Then
 
                'End If
 
                'If lv.Items(i).SubItems(5).Text = "0.00" Then
 
                If FrmSettings.chkPrice1.CheckState = CheckState.Checked Then
 
                    'Price Level 1
                    os.Write("<SalesTransaction>")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(0).Text & ">")
                    os.Write(lv.Items(i).SubItems(0).Text)
                    os.Write("</" & lv.Columns.Item(0).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(1).Text & ">")
                    os.Write(lv.Items(i).SubItems(1).Text)
                    os.Write("</" & lv.Columns.Item(1).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(2).Text & ">")
                    os.Write(lv.Items(i).SubItems(2).Text)
                    os.Write("</" & lv.Columns.Item(2).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(5).Text & ">")
                    os.Write(lv.Items(i).SubItems(5).Text)
                    os.Write("</" & lv.Columns.Item(5).Text & ">")
                    os.WriteLine()
                    os.Write("<" & lv.Columns.Item(8).Text & ">")
                    os.Write(lv.Items(i).SubItems(8).Text)
                    os.Write("</" & lv.Columns.Item(8).Text & ">")
                    os.WriteLine()
                    os.Write("</SalesTransaction>")
                    os.WriteLine()
 
                    If FrmSettings.chkPrice2.CheckState = CheckState.Checked Then
 
                        'Price Level 2
                        os.Write("<SalesTransaction>")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(0).Text & ">")
                        os.Write(lv.Items(i).SubItems(0).Text)
                        os.Write("</" & lv.Columns.Item(0).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(1).Text & ">")
                        os.Write(lv.Items(i).SubItems(1).Text)
                        os.Write("</" & lv.Columns.Item(1).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(3).Text & ">")
                        os.Write(lv.Items(i).SubItems(3).Text)
                        os.Write("</" & lv.Columns.Item(3).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(6).Text & ">")
                        os.Write(lv.Items(i).SubItems(6).Text)
                        os.Write("</" & lv.Columns.Item(6).Text & ">")
                        os.WriteLine()
                        os.Write("<" & lv.Columns.Item(9).Text & ">")
                        os.Write(lv.Items(i).SubItems(9).Text)
                        os.Write("</" & lv.Columns.Item(9).Text & ">")
                        os.WriteLine()
                        os.Write("</SalesTransaction>")
                        os.WriteLine()
 
                        If FrmSettings.chkPrice3.CheckState = CheckState.Checked Then
 
                            'Price Level 3
                            os.Write("<SalesTransaction>")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(0).Text & ">")
                            os.Write(lv.Items(i).SubItems(0).Text)
                            os.Write("</" & lv.Columns.Item(0).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(1).Text & ">")
                            os.Write(lv.Items(i).SubItems(1).Text)
                            os.Write("</" & lv.Columns.Item(1).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(4).Text & ">")
                            os.Write(lv.Items(i).SubItems(4).Text)
                            os.Write("</" & lv.Columns.Item(4).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(7).Text & ">")
                            os.Write(lv.Items(i).SubItems(7).Text)
                            os.Write("</" & lv.Columns.Item(7).Text & ">")
                            os.WriteLine()
                            os.Write("<" & lv.Columns.Item(10).Text & ">")
                            os.Write(lv.Items(i).SubItems(10).Text)
                            os.Write("</" & lv.Columns.Item(10).Text & ">")
                            os.WriteLine()
                            os.Write("</SalesTransaction>")
                            os.WriteLine()
 
                        End If
                    End If
                End If
            End If
        Next
 
        os.Write("</SalesHeader>")
        os.WriteLine()
        os.Write("</FourthHeader>")
        os.WriteLine()
        os.Close()
 
        AppLog.WriteLog("Created XML File: " & filename)

Open in new window

0
Comment
Question by:richard_gar
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 23695488
try something like the following
            If lv.Items(i).SubItems(1).Text <> "" Then
               If lv.Items(i+1).SubItems(1).Text <> "" Then
                 If lv.Items(i+2).SubItems(1).Text <> "" Then
                 ... process xml
                 End If
               End If
            End If
0
 

Author Comment

by:richard_gar
ID: 23695545
no that ain't working
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 23695655
You mean like the below?

Dim AppLog As New Logger
 
Dim os As New StreamWriter(filename)
 
os.Write("<!-- Generated By Gardiff Fourth Hospitaility Utility " & DateTime.Today.ToString("dd/MM/yyyy") & "-->")
os.WriteLine()
os.Write("<!-- Total Sales: " & Label1.Text & "-->")
os.WriteLine()
os.Write("<FourthHeader xmlns="""">")
os.WriteLine()
os.Write("<OrganisationID>" & FrmSettings.txtID.Text & "</OrganisationID>")
os.WriteLine()
os.Write("<UserName>" & FrmSettings.txtFourthUsername.Text & "</UserName>")
os.WriteLine()
os.Write("<Password>" & FrmSettings.txtFourthPassword.Text & "</Password>")
os.WriteLine()
os.Write("<SalesHeader>")
os.WriteLine()
os.Write("<SalesDate>" & DateTime.Today.ToString("dd/MM/yyyy") & "</SalesDate>")
os.WriteLine()
 
For i As Integer = 0 To lv.Items.Count - 1
	If lv.Items(i).SubItems(1).Text <> "" Then
		If FrmSettings.chkPrice1.CheckState = CheckState.Checked Then
 
		'Price Level 1
		os.Write("<SalesTransaction>")
		os.WriteLine()
		if lv.Items(i).SubItems(0)<>"" then
			os.Write("<" & lv.Columns.Item(0).Text & ">")
			os.Write(lv.Items(i).SubItems(0).Text)
			os.Write("</" & lv.Columns.Item(0).Text & ">")
			os.WriteLine()
		end if
		if lv.Items(i).SubItems(1).Text<>"" then
			os.Write("<" & lv.Columns.Item(1).Text & ">")
			os.Write(lv.Items(i).SubItems(1).Text)
			os.Write("</" & lv.Columns.Item(1).Text & ">")
			os.WriteLine()
		end if
		if lv.Items(i).SubItems(2).Text<>"" then
			os.Write("<" & lv.Columns.Item(2).Text & ">")
			os.Write(lv.Items(i).SubItems(2).Text)
			os.Write("</" & lv.Columns.Item(2).Text & ">")
			os.WriteLine()
		end if
		os.Write("<" & lv.Columns.Item(5).Text & ">")
		os.Write(lv.Items(i).SubItems(5).Text)
		os.Write("</" & lv.Columns.Item(5).Text & ">")
		os.WriteLine()
		os.Write("<" & lv.Columns.Item(8).Text & ">")
		os.Write(lv.Items(i).SubItems(8).Text)
		os.Write("</" & lv.Columns.Item(8).Text & ">")
		os.WriteLine()
		os.Write("</SalesTransaction>")
		os.WriteLine()
 
		If FrmSettings.chkPrice2.CheckState = CheckState.Checked Then
			'Price Level 2
			os.Write("<SalesTransaction>")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(0).Text & ">")
			os.Write(lv.Items(i).SubItems(0).Text)
			os.Write("</" & lv.Columns.Item(0).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(1).Text & ">")
			os.Write(lv.Items(i).SubItems(1).Text)
			os.Write("</" & lv.Columns.Item(1).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(3).Text & ">")
			os.Write(lv.Items(i).SubItems(3).Text)
			os.Write("</" & lv.Columns.Item(3).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(6).Text & ">")
			os.Write(lv.Items(i).SubItems(6).Text)
			os.Write("</" & lv.Columns.Item(6).Text & ">")
			os.WriteLine()
			os.Write("<" & lv.Columns.Item(9).Text & ">")
			os.Write(lv.Items(i).SubItems(9).Text)
			os.Write("</" & lv.Columns.Item(9).Text & ">")
			os.WriteLine()
			os.Write("</SalesTransaction>")
			os.WriteLine()
 
			If FrmSettings.chkPrice3.CheckState = CheckState.Checked Then
				'Price Level 3
				os.Write("<SalesTransaction>")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(0).Text & ">")
				os.Write(lv.Items(i).SubItems(0).Text)
				os.Write("</" & lv.Columns.Item(0).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(1).Text & ">")
				os.Write(lv.Items(i).SubItems(1).Text)
				os.Write("</" & lv.Columns.Item(1).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(4).Text & ">")
				os.Write(lv.Items(i).SubItems(4).Text)
				os.Write("</" & lv.Columns.Item(4).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(7).Text & ">")
				os.Write(lv.Items(i).SubItems(7).Text)
				os.Write("</" & lv.Columns.Item(7).Text & ">")
				os.WriteLine()
				os.Write("<" & lv.Columns.Item(10).Text & ">")
				os.Write(lv.Items(i).SubItems(10).Text)
				os.Write("</" & lv.Columns.Item(10).Text & ">")
				os.WriteLine()
				os.Write("</SalesTransaction>")
				os.WriteLine()
 
				End If
			End If
		End If
	End If
Next
 
os.Write("</SalesHeader>")
os.WriteLine()
os.Write("</FourthHeader>")
os.WriteLine()
os.Close()
 
AppLog.WriteLog("Created XML File: " & filename)

Open in new window

0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 1500 total points
ID: 23695658
Note I've only added the check for three items.  You can use similar checks for all the items as you need.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question