StoreCat.vb
- Public Class StoreCat
- 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 CustomersPath As String = DataPath & "\Customers"
- Dim CompanyPath As String = DataPath & "\Company"
- Dim MovmentPath As String = DataPath & "\Movment"
- Dim RequestsPath As String = DataPath & "\Requests"
- Dim VendorsPath As String = DataPath & "\Vendors"
- Private Shared StoreCatInstance As StoreCat
- Public Shared Function GetInstance() As StoreCat
- If (StoreCatInstance Is Nothing) Then
- StoreCatInstance = New StoreCat
- End If
- Return StoreCatInstance
- End Function
- Private Sub StoreCat_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("ربح القطعة")
- LoadStores()
- LoadCats()
- LoadSelectedStore()
- Refresher.Enabled = True
- End Sub
- Public Sub LoadStores()
- On Error Resume Next
- CNameTXT.Items.Clear()
- Dim Addad As Integer = 0
- For Addad = 0 To My.Computer.FileSystem.GetDirectories(StoresPath).Count - 1
- Dim SPath As String = My.Computer.FileSystem.GetDirectories(StoresPath).Item(Addad)
- Dim SName As String = My.Computer.FileSystem.GetDirectoryInfo(My.Computer.FileSystem.GetDirectories(StoresPath).Item(Addad)).Name
- CNameTXT.Items.Add(SName)
- Next
- CNameTXT.Text = My.Computer.FileSystem.ReadAllText(DataPath & "\defaultstore.dat", System.Text.Encoding.GetEncoding(0))
- End Sub
- Public Sub LoadCats()
- On Error Resume Next
- CatNameTXT.Items.Clear()
- Dim Addad As Integer = 0
- For Addad = 0 To My.Computer.FileSystem.GetFiles(CatPath).Count - 1
- Dim SPath As String = My.Computer.FileSystem.GetFiles(CatPath).Item(Addad)
- Dim SName As String = My.Computer.FileSystem.GetFileInfo(My.Computer.FileSystem.GetFiles(CatPath).Item(Addad)).Name.Replace(".dat", "")
- CatNameTXT.Items.Add(SName)
- ToStoresTXT.Items.Add(SName)
- Next
- CatNameTXT.SelectedIndex = 0
- ToStoresTXT.SelectedIndex = 0
- 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 LV_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles LV.DoubleClick
- LoadProduct()
- End Sub
- Public Sub LoadSelectedStore()
- On Error Resume Next
- LV.Items.Clear()
- Dim SName As String = ""
- Dim SAmount As Double = 0
- Dim SSold As String = ""
- Dim SPurch As Double = 0
- Dim SInter As Double = 0
- Dim Addad As Integer = 0
- Dim MyArr() As String = {""}
- MyArr = System.IO.File.ReadAllLines(CatPath & "\" & CatNameTXT.Text & ".dat", System.Text.Encoding.GetEncoding(0))
- LV.Items.Clear()
- For Addad = 0 To MyArr.Length - 1
- SName = MyArr(Addad)
- SSold = My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\sold.dat", System.Text.Encoding.GetEncoding(0))
- SPurch = Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\purch.dat", System.Text.Encoding.GetEncoding(0)))
- '.............................
- Dim MyStoreName As String = CNameTXT.Text
- Dim FName As String = ""
- If MyStoreName = My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\store.dat", System.Text.Encoding.GetEncoding(0)) Then FName = "mount.dat" : GoTo FinishStoreName
- If Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\stores.dat", System.Text.Encoding.GetEncoding(0))) = 0 Then
- If My.Computer.FileSystem.FileExists(ProductPath & "\" & SName & "\mount0.dat") = True Then
- If MyStoreName = My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\store0.dat", System.Text.Encoding.GetEncoding(0)) Then FName = "mount0.dat" : GoTo FinishStoreName
- End If
- Else
- Dim SubAddad As Integer = 0
- For SubAddad = 0 To Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\stores.dat", System.Text.Encoding.GetEncoding(0)))
- If MyStoreName = My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\store" & SubAddad & ".dat", System.Text.Encoding.GetEncoding(0)) Then FName = "mount" & SubAddad & ".dat" : GoTo FinishStoreName
- Next
- End If
- SAmount = 0
- GoTo NextStep
- FinishStoreName:
- SAmount = Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\" & FName, System.Text.Encoding.GetEncoding(0)))
- NextStep:
- '.............................
- Dim InterValue As Double = 0
- Dim TaxValue As Double = 0
- TaxValue = Val(Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\price.dat", System.Text.Encoding.GetEncoding(0))) * Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\maintax.dat", System.Text.Encoding.GetEncoding(0))) / 100) + Val(Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\price.dat", System.Text.Encoding.GetEncoding(0))) * Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\subtax.dat", System.Text.Encoding.GetEncoding(0))) / 100)
- InterValue = SPurch - Val(Val(My.Computer.FileSystem.ReadAllText(ProductPath & "\" & SName & "\price.dat", System.Text.Encoding.GetEncoding(0)))) - (TaxValue)
- SInter = InterValue
- LV.Items.Add(SName)
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(SAmount)
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(SSold)
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(SPurch)
- LV.Items.Item(LV.Items.Count - 1).SubItems.Add(SInter)
- Next
- LV.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
- End Sub
- Private Sub CNameTXT_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CNameTXT.SelectedIndexChanged
- LoadSelectedStore()
- End Sub
- Private Sub CatNameTXT_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CatNameTXT.SelectedIndexChanged
- LoadSelectedStore()
- End Sub
- Public Sub RenameCat(ByVal OldName As String, ByVal NewName As String)
- My.Computer.FileSystem.RenameFile(CatPath & "\" & OldName & ".dat", NewName & ".dat")
- Dim Addad As Integer = 0
- For Addad = 0 To LV.Items.Count - 1
- Dim SName As String = LV.Items.Item(Addad).Text
- My.Computer.FileSystem.WriteAllText(ProductPath & "\" & SName & "\cat.dat", NewName, False, System.Text.Encoding.GetEncoding(0))
- Next
- LoadStores()
- LoadCats()
- CatNameTXT.SelectedItem = NewName
- LoadSelectedStore()
- End Sub
- Private Sub RenameStoreBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RenameStoreBTN.Click
- Dim NewName As String = ""
- NewName = InputBox("إسم التصنيف الجديد", "إعادة تسمية التصنيف", CatNameTXT.Text)
- If NewName <> "" And NewName <> CNameTXT.Text Then
- RenameCat(CatNameTXT.Text, NewName)
- End If
- End Sub
- Private Sub LV_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles LV.GotFocus
- ToStoresTXT.Visible = True
- MoveBTN.Visible = True
- End Sub
- Public Sub MoveCat()
- If CatNameTXT.Text <> CatNameTXT.Text Then
- Dim PName As String = ""
- PName = LV.FocusedItem.Text
- My.Computer.FileSystem.WriteAllText(ProductPath & "\" & PName & "\cat.dat", ToStoresTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- Dim LastCatReader As String = ""
- LastCatReader = My.Computer.FileSystem.ReadAllText(CatPath & "\" & CatNameTXT.Text & ".dat", System.Text.Encoding.GetEncoding(0))
- LastCatReader = LastCatReader.Replace(PName & System.Environment.NewLine, "")
- My.Computer.FileSystem.WriteAllText(CatPath & "\" & CatNameTXT.Text & ".dat", LastCatReader, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CatPath & "\" & ToStoresTXT.Text & ".dat", PName & System.Environment.NewLine, True, System.Text.Encoding.GetEncoding(0))
- LoadSelectedStore()
- End If
- End Sub
- Private Sub MoveBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MoveBTN.Click
- MoveCat()
- End Sub
- Private Sub ProductCancleBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductCancleBTN.Click
- ToStoresTXT.Visible = False
- MoveBTN.Visible = False
- StartUp.CloseTabs()
- End Sub
- Private Sub Refresher_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Refresher.Tick
- LoadSelectedStore()
- End Sub
- End Class