Setting.vb
- Public Class Setting
- 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"
- Dim BoxPath As String = DataPath & "\Box"
- Dim AlertsPath As String = DataPath & "\Alerts"
- Dim SettingsPath As String = DataPath & "\Settings"
- Dim AddToVindorBoolean As Boolean = False
- Private Shared SettingInstance As Setting
- Public Shared Function GetInstance() As Setting
- If (SettingInstance Is Nothing) Then
- SettingInstance = New Setting
- End If
- Return SettingInstance
- End Function
- Public Sub TestText()
- 'test values to add errors to Alerts :
- Dim PName As String = "الإعدادات"
- Dim WDir As String = ""
- '××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
- If CNameTXT.Text = "" Then
- StartUp.AlertsWriter(PName, "نقص في " & PName & " , أدخل إسم شركتك الآن", "S-name")
- Else
- WDir = AlertsPath & "\" & PName & "\S-name"
- If My.Computer.FileSystem.DirectoryExists(WDir) Then System.IO.Directory.Delete(WDir, True)
- End If
- '××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
- If CAddressTXT.Text = "" Then
- StartUp.AlertsWriter(PName, "نقص في " & PName & " , أدخل عنوان شركتك الآن", "S-address")
- Else
- WDir = AlertsPath & "\" & PName & "\S-address"
- If My.Computer.FileSystem.DirectoryExists(WDir) Then System.IO.Directory.Delete(WDir, True)
- End If
- '××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
- If CTelTXT.Text = "" Then
- StartUp.AlertsWriter(PName, "نقص في " & PName & " , أدخل رقم هاتف شركتك الآن", "S-tel")
- Else
- WDir = AlertsPath & "\" & PName & "\S-tel"
- If My.Computer.FileSystem.DirectoryExists(WDir) Then System.IO.Directory.Delete(WDir, True)
- End If
- '××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
- If FooterTXT.Text = "" Then
- StartUp.AlertsWriter(PName, "نقص في " & PName & " , أدخل تذييل فواتيرك الآن", "S-footer")
- Else
- WDir = AlertsPath & "\" & PName & "\S-footer"
- If My.Computer.FileSystem.DirectoryExists(WDir) Then System.IO.Directory.Delete(WDir, True)
- End If
- '××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
- If MainCurrencyTXT.Text = "" Then
- StartUp.AlertsWriter(PName, "نقص في " & PName & " , أدخل عملة التداول الآن", "S-carrency")
- Else
- WDir = AlertsPath & "\" & PName & "\S-carrency"
- If My.Computer.FileSystem.DirectoryExists(WDir) Then System.IO.Directory.Delete(WDir, True)
- End If
- '××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
- StartUp.LoadAlerts()
- End Sub
- Private Sub Setting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- SFD.InitialDirectory = "c:\"
- SFD.Title = "حفظ نسخة من البيانات"
- SFD.Filter = "Data files (*.dat)|*.dat"
- SFD.FileName = Date.Now.Year & "-" & Date.Now.Month & "-" & Date.Now.Day & " " & Date.Now.Hour & Date.Now.Minute
- RestDialog.Multiselect = False
- RestDialog.InitialDirectory = "c:\"
- RestDialog.Title = "إستعادة نسخة إحتياطية من البيانات"
- RestDialog.Filter = "Data files (*.dat)|*.dat"
- RestDialog.FileName = Date.Now.Year & "-" & Date.Now.Month & "-" & Date.Now.Day
- OFD.Multiselect = False
- OFD.InitialDirectory = "c:\"
- OFD.Title = "إنتقاء صورة للمنتج"
- OFD.Filter = "jpg files (*.jpg)|*.jpg|bmp files (*.bmp)|*.bmp|png files (*.png)|*.png"
- LoadSettings()
- End Sub
- Private Sub ProductCancleBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductCancleBTN.Click
- StartUp.CloseTabs()
- End Sub
- Public Sub LoadSettings()
- On Error Resume Next
- Dim MainCName As String = ""
- Dim SubCName As String = ""
- MainCName = My.Computer.FileSystem.ReadAllText(SettingsPath & "\maincurrency.dat", System.Text.Encoding.GetEncoding(0))
- MainCurrencyTXT.Text = MainCName
- 'If My.Computer.FileSystem.FileExists(SettingsPath & "\subcurrency.dat") = True Then
- 'SubCName = My.Computer.FileSystem.ReadAllText(SettingsPath & "\subcurrency.dat", System.Text.Encoding.GetEncoding(0))
- 'SubCurrencyTXT.Text = SubCName
- 'EveryLBL.Text = "كل 1 " & SubCName & " ="
- 'EqualTXT.Text = My.Computer.FileSystem.ReadAllText(SettingsPath & "\equal.dat", System.Text.Encoding.GetEncoding(0))
- 'SCNameLBL.Text = MainCName
- 'End If
- PSizeTXT.Text = My.Computer.FileSystem.ReadAllText(SettingsPath & "\psize.dat", System.Text.Encoding.GetEncoding(0))
- FooterTXT.Text = My.Computer.FileSystem.ReadAllText(SettingsPath & "\footer.dat", System.Text.Encoding.GetEncoding(0))
- CNameTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\name.dat", System.Text.Encoding.GetEncoding(0))
- CAddressTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\address.dat", System.Text.Encoding.GetEncoding(0))
- CTelTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\tel.dat", System.Text.Encoding.GetEncoding(0))
- CLogoPIC.Image = System.Drawing.Bitmap.FromFile(CompanyPath & "\img.pic")
- PlaceRentTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\placerent.dat", System.Text.Encoding.GetEncoding(0))
- ELCRentTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\electricity.dat", System.Text.Encoding.GetEncoding(0))
- WRentTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\water.dat", System.Text.Encoding.GetEncoding(0))
- WorkerTXT.Text = My.Computer.FileSystem.ReadAllText(CompanyPath & "\workerrent.dat", System.Text.Encoding.GetEncoding(0))
- End Sub
- Public Sub SaveChanges()
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\maincurrency.dat", MainCurrencyTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- 'If SubCurrencyTXT.Text <> "-" Then
- 'My.Computer.FileSystem.WriteAllText(SettingsPath & "\subcurrency.dat", SubCurrencyTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- 'My.Computer.FileSystem.WriteAllText(SettingsPath & "\equal.dat", EqualTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- 'End If
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\psize.dat", PSizeTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\footer.dat", FooterTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\name.dat", CNameTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\address.dat", CAddressTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\tel.dat", CTelTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\placerent.dat", PlaceRentTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\electricity.dat", ELCRentTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\water.dat", WRentTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\workerrent.dat", WorkerTXT.Text, False, System.Text.Encoding.GetEncoding(0))
- End Sub
- Private Sub ProductShowBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductShowBTN.Click
- SaveChanges()
- TestText()
- StartUp.CloseTabs()
- End Sub
- Private Sub SubCurrencyTXT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
- 'If SubCurrencyTXT.Text <> "-" Then
- 'EveryLBL.Visible = True
- 'EqualTXT.Visible = True
- 'SCNameLBL.Visible = True
- 'EveryLBL.Text = "كل 1 " & SubCurrencyTXT.Text & " ="
- 'SCNameLBL.Text = MainCurrencyTXT.Text
- 'End If
- End Sub
- Private Sub MainCurrencyTXT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainCurrencyTXT.TextChanged
- 'SCNameLBL.Text = MainCurrencyTXT.Text
- End Sub
- Private Sub OFD_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFD.FileOk
- On Error Resume Next
- ClearBTN_Click(sender, e)
- My.Computer.FileSystem.CopyFile(OFD.FileName, CompanyPath & "\img.pic", True)
- CLogoPIC.Image = System.Drawing.Bitmap.FromFile(CompanyPath & "\img.pic")
- End Sub
- Private Sub ClearBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearBTN.Click
- On Error Resume Next
- CLogoPIC.Image = Nothing
- CLogoPIC.Refresh()
- Dim TryNum As Integer = 0
- If My.Computer.FileSystem.FileExists(CompanyPath & "\img.pic") = False Then GoTo Finish
- Retry:
- System.IO.File.SetAttributes(CompanyPath & "\img.pic", IO.FileAttributes.Normal)
- System.IO.File.Delete(CompanyPath & "\img.pic")
- If My.Computer.FileSystem.FileExists(CompanyPath & "\img.pic") = True And TryNum < 100 Then TryNum += 1 : GoTo Retry Else MsgBox("لا يمكن التعامل مع الصورة حالياً أعد المحاولة بعد قليل")
- Finish:
- End Sub
- Private Sub BrowseBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseBTN.Click
- OFD.ShowDialog()
- End Sub
- Private Sub CleanDataBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CleanDataBTN.Click
- If MsgBox("هل أنت متأكد من رغبتك بمسح جميع بيانات البرنامج بما فيها بيانانك الخاصة", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
- DeleteAllData()
- End If
- End Sub
- Public Sub DeleteAllData()
- On Error Resume Next
- 'Deleting Alerts:
- System.IO.Directory.Delete(AlertsPath, True)
- My.Computer.FileSystem.CreateDirectory(AlertsPath)
- 'Zeroing Box :
- System.IO.Directory.Delete(BoxPath, True)
- My.Computer.FileSystem.CreateDirectory(BoxPath)
- '
- System.IO.Directory.Delete(CatPath, True)
- My.Computer.FileSystem.CreateDirectory(CatPath)
- '
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\address.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\electricity.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\name.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\placerent.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\tel.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\water.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(CompanyPath & "\workerrent.dat", "", False, System.Text.Encoding.GetEncoding(0))
- System.IO.File.Delete(CompanyPath & "\img.pic")
- '
- System.IO.Directory.Delete(CustomersPath, True)
- My.Computer.FileSystem.CreateDirectory(CustomersPath)
- '
- System.IO.Directory.Delete(MovmentPath, True)
- My.Computer.FileSystem.CreateDirectory(MovmentPath)
- '
- System.IO.Directory.Delete(ProductPath, True)
- My.Computer.FileSystem.CreateDirectory(ProductPath)
- '
- System.IO.Directory.Delete(RequestsPath, True)
- My.Computer.FileSystem.CreateDirectory(RequestsPath)
- '
- System.IO.Directory.Delete(ServicesPath, True)
- My.Computer.FileSystem.CreateDirectory(ServicesPath)
- '
- System.IO.Directory.Delete(ServicesPath, True)
- My.Computer.FileSystem.CreateDirectory(ServicesPath)
- '
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\equal.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\footer.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\maincurrency.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\psize.dat", "", False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.WriteAllText(SettingsPath & "\subcurrency.dat", "", False, System.Text.Encoding.GetEncoding(0))
- '
- System.IO.Directory.Delete(StoresPath, True)
- My.Computer.FileSystem.CreateDirectory(StoresPath)
- '
- System.IO.Directory.Delete(VendorsPath, True)
- My.Computer.FileSystem.CreateDirectory(VendorsPath)
- '
- My.Computer.FileSystem.WriteAllText(DataPath & "\defaultstore.dat", "", False, System.Text.Encoding.GetEncoding(0))
- Windows.Forms.Application.Restart()
- End Sub
- Private Sub SFD_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SFD.FileOk
- My.Computer.FileSystem.WriteAllText(SFD.FileName, Date.Now.Year & Date.Now.Month & Date.Now.Day & Date.Now.Hour & Date.Now.Minute, False, System.Text.Encoding.GetEncoding(0))
- My.Computer.FileSystem.CopyDirectory(DataPath, System.Environment.GetFolderPath(Environment.SpecialFolder.System) & "\uam backup\" & Date.Now.Year & Date.Now.Month & Date.Now.Day & Date.Now.Hour & Date.Now.Minute, FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
- MsgBox("لقد تم إعداد نسخة إحتياطية من بياناتك بنجاح")
- End Sub
- Private Sub SaveDataBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveDataBTN.Click
- SFD.ShowDialog()
- End Sub
- Private Sub RestDataBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RestDataBTN.Click
- RestDialog.ShowDialog()
- End Sub
- Private Sub RestDialog_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RestDialog.FileOk
- On Error Resume Next
- Dim Reader As String = My.Computer.FileSystem.ReadAllText(RestDialog.FileName, System.Text.Encoding.GetEncoding(0))
- Dim TargetData = System.Environment.GetFolderPath(Environment.SpecialFolder.System) & "\uam backup\" & Reader
- If My.Computer.FileSystem.DirectoryExists(TargetData) = True Then
- System.IO.Directory.Delete(DataPath, True)
- My.Computer.FileSystem.CreateDirectory(DataPath)
- My.Computer.FileSystem.CopyDirectory(TargetData, DataPath, True)
- End If
- MsgBox("لقد تمت إستعادة بياناتك بنجاح")
- Windows.Forms.Application.Restart()
- End Sub
- End Class