ListProducts.vb
- Public Class ListProducts
- Dim ProgramName As String = My.Application.Info.AssemblyName
- Dim DataPath As String = System.Environment.CurrentDirectory & "\UAM"
- Dim ProductPath As String = DataPath & "\Products" '
- Dim ServicesPath As String = DataPath & "\Services"
- Dim CatPath As String = DataPath & "\Categories"
- Dim StoresPath As String = DataPath & "\Stores"
- Dim RequestsPath As String = DataPath & "\Requests"
- Private Shared ListProductsInstance As ListProducts
- Public Shared Function GetInstance() As ListProducts
- If (ListProductsInstance Is Nothing) Then
- ListProductsInstance = New ListProducts
- End If
- Return ListProductsInstance
- End Function
- Private Sub ListProducts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- LV.Columns.Add("إسم المنتج \ السلعة")
- LV.Columns.Add("تصنيف المنتج")
- LV.Columns.Add("سعر المبيع")
- LV.Columns.Add("الكمية المتوفرة")
- LV.Columns.Add("الكمية المباعة")
- LV.Columns.Add("الكمية المطلوبة من زبائنك")
- LV.Columns.Add("الواجب شراؤه")
- LoadProductsList()
- Refresher.Enabled = True
- End Sub
- Public Sub LoadProductsList()
- On Error Resume Next
- LV.Items.Clear()
- Dim Addad As Integer = 0
- Dim StoreNum As Integer = My.Computer.FileSystem.GetDirectories(StoresPath).Count - 1
- For Addad = 0 To My.Computer.FileSystem.GetDirectories(ProductPath).Count - 1
- Dim ProductName As String = ""
- ProductName = My.Computer.FileSystem.GetDirectoryInfo(My.Computer.FileSystem.GetDirectories(ProductPath).Item(Addad)).Name
- If ProductName.Contains(SearchTXT.Text) = False Then GoTo SkipThis
- LV.Items.Add(ProductName, 0)
- Dim ProductCat As String = ""
- ProductCat = My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\cat.dat", System.Text.Encoding.GetEncoding(0))
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(ProductCat)
- Dim ProductPurch As Double = 0
- ProductPurch = Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\purch.dat", System.Text.Encoding.GetEncoding(0)))
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(ProductPurch)
- Dim ProductMount As Double = 0
- ProductMount = Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\mount.dat", System.Text.Encoding.GetEncoding(0)))
- If Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\stores.dat", System.Text.Encoding.GetEncoding(0))) = 0 Then
- If My.Computer.FileSystem.FileExists(ProductPath & "\" & ProductName & "\mount0.dat") = True Then
- ProductMount += Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\mount0.dat", System.Text.Encoding.GetEncoding(0)))
- End If
- Else
- Dim SubAddad As Integer = 0
- For SubAddad = 0 To Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\stores.dat", System.Text.Encoding.GetEncoding(0)))
- ProductMount += Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\mount" & SubAddad & ".dat", System.Text.Encoding.GetEncoding(0)))
- Next
- End If
- 'ProductMount = Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\mount.dat", System.Text.Encoding.GetEncoding(0)))
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(ProductMount)
- Dim ProductSold As Double = 0
- ProductSold = Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & ProductName & "\sold.dat", System.Text.Encoding.GetEncoding(0)))
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(ProductSold)
- Dim ProductReq As Double = 0
- If My.Computer.FileSystem.DirectoryExists(RequestsPath & "\" & ProductName) = True Then
- ProductReq = Val(My.Computer.FileSystem.ReadAllText(RequestsPath & "\" & ProductName & "\amount.dat", System.Text.Encoding.GetEncoding(0)))
- End If
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(ProductReq)
- Dim ProductMostBuy As Double = 0
- ProductMostBuy = -ProductMount + (ProductReq)
- If ProductMostBuy <= 0 Then ProductMostBuy = 0 Else LV.Items.Item(LV.Items.Count - 1).BackColor = Color.Tan : LV.Items.Item(LV.Items.Count - 1).ForeColor = Color.DarkOliveGreen
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(ProductMostBuy)
- '-----------------------------------------------------------
- SkipThis:
- Next
- LV.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
- End Sub
- Private Sub LV_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LV.MouseDoubleClick
- LoadProduct()
- End Sub
- Private Sub ProductShowBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductShowBTN.Click
- LoadProduct()
- End Sub
- Public Sub LoadProduct()
- If LV.SelectedItems.Count > 0 Then
- NewProduct.GetInstance.LoadProduct(LV.FocusedItem.Text)
- StartUp.MainPanel.Controls.Clear()
- StartUp.MainPanel.Controls.Add(NewProduct.GetInstance())
- StartUp.AddNewTab(NewProduct.GetInstance.Tag, NewProduct.GetInstance.Name)
- End If
- End Sub
- Private Sub ProductCancleBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductCancleBTN.Click
- StartUp.CloseTabs()
- End Sub
- Dim LoadCount As Integer = 0
- Private Sub Refresher_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Refresher.Tick
- 'If My.Computer.FileSystem.GetDirectories(ProductPath).Count <> LoadCount Then
- 'LoadProductsList()
- 'LoadCount = My.Computer.FileSystem.GetDirectories(ProductPath).Count
- 'End If
- LoadProductsList()
- End Sub
- Private Sub SearchTXT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchTXT.TextChanged
- LoadProductsList()
- End Sub
- End Class