2015-04-04 76 views
0

對於使用VB.NET製作銷售點程序的學校項目,您可以選擇產品及其價格以及客戶名稱和付款方式(現金萬事達卡等)如何將列表視圖中的所有項目保存到文本文件

​​

在形式我也做

dim w as IO.StreamWriter 

保存文件的工作,但它不來了,我怎麼想它

它僅與出現冷杉在第一塔T列條目例如條目是「約翰史密斯」,並將其與該

ListViewItem的出現:{JOHN SMITH}

也應該拿出他買的,多少費用,他購買的物品數量以及物品的總價格

另外,如果客戶購買了多個物品示例,他購買了一個蛋糕和一個沙子,那麼有沒有辦法?要在同一列中總結金額?

在此先感謝

+0

您是否嘗試過 「lstOutput.Items(I).SubItems(ColumnIndex)」 – Insane 2015-04-04 07:27:56

+0

我在哪裏可以放的? – 2015-04-05 02:15:48

回答

0
 Dim sfile As New SaveFileDialog 
    With sfile 
     .Title = "Choose your path to save the information" 
     .InitialDirectory = "C:\" 
     .Filter = ("ONLY Text Files (*.txt) | *.txt") 
    End With 

    If sfile.ShowDialog() = Windows.Forms.DialogResult.OK Then 
     Dim Write As New IO.StreamWriter(sfile.FileName) 
     Dim k As ListView.ColumnHeaderCollection = lstOutput.Columns 
     For Each x As ListViewItem In lstOutput.Items 
      Dim StrLn As String = "" 
      For i = 0 To x.SubItems.Count - 1 
       StrLn += k(i).Text + " :" + x.SubItems(i).Text + Space(3) 
      Next 
      Write.WriteLine(StrLn) 
     Next 
     Write.Close() 'Or Write.Flush() 
    End If 

此外,有沒有一種方式,如果一個客戶購買他買了蛋糕和三明治多個項目的例子。要在同一列中總結金額?

是的,但給我們一個關於該領域的例子。

+0

例如,我希望程序在將信息添加到我的列表視圖中之後,總結John Smith支付的總價格。如果我輸入更多信息,它會更新這個數字。 感謝您的救助幫助,正是我想要的! – 2015-04-05 02:49:33

+0

不客氣,關於總價,你的意思是說,lstOutput包含許多具有相同名稱的行或在同一行中包含許多列? – 2015-04-05 13:31:12

0

關於總價,你的意思是這...

Dim ClientName As String = "John" 
    Dim IndexOfPrices As Int32 = 1 '// Index Of sub item that contains the item price 


    Dim lstOutput2 As ListView = lstOutput '// Fast loop without access the GUI 
    Dim Price As Int32 = 0 
    For Each x As ListViewItem In lstOutput2.Items 
     Application.DoEvents() '// No need to another thread to do loop inside, DoEvents will solve the problem 
     If x.SubItems(0).Text = ClientName Then 
      Price += Val(x.SubItems(IndexOfPrices).Text) 
     End If 
    Next 
    lblPrice.Text = "Price :" + Price.ToString + "$" 
相關問題