-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject42.txt
More file actions
251 lines (224 loc) · 10.2 KB
/
Project42.txt
File metadata and controls
251 lines (224 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
Imports System.IO
Module RealEstateManagementSystem
' Define a class to represent a property
Class PropertyRecord
Public Property ID As Integer
Public Property Address As String
Public Property PropertyType As String
Public Property Price As Decimal
Public Property Status As String
End Class
' Define a list to store property records
Dim Properties As New List(Of PropertyRecord)
' Specify the file paths for input and output files
Dim InputFilePath As String = "C:\Users\aliab\Desktop\REMSInput.csv"
Dim OutputFilePath As String = "C:\Users\aliab\Desktop\property_report.txt"
Sub Main()
LoadPropertiesFromFile()
While True
Console.WriteLine("Real Estate Management System")
Console.WriteLine("1. Add Property")
Console.WriteLine("2. Update Property")
Console.WriteLine("3. Delete Property")
Console.WriteLine("4. Search Properties")
Console.WriteLine("5. Property Statistics")
Console.WriteLine("6. Generate Reports")
Console.WriteLine("7. Exit")
Console.Write("Enter your choice: ")
Dim choice As Integer = Integer.Parse(Console.ReadLine())
Select Case choice
Case 1
AddProperties()
Case 2
UpdateProperty()
Case 3
DeleteProperty()
Case 4
SearchProperties()
Case 5
PropertyStatistics()
Case 6
GenerateReports()
Case 7
SavePropertiesToFile()
Exit Sub
Case Else
Console.WriteLine("Invalid choice. Please try again.")
End Select
Console.WriteLine()
End While
End Sub
' Load property data from the input file
Sub LoadPropertiesFromFile()
Try
Using reader As New StreamReader(InputFilePath) ' Update here
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
Dim values As String() = line.Split(vbTab)
If values.Length = 5 Then
Dim prop As New PropertyRecord()
prop.ID = Integer.Parse(values(0))
prop.Address = values(1)
prop.PropertyType = values(2)
prop.Price = Decimal.Parse(values(3))
prop.Status = values(4)
Properties.Add(prop)
End If
End While
End Using
Catch ex As Exception
Console.WriteLine("Error loading property data: " & ex.Message)
End Try
End Sub
' Save property data to a file
Sub SavePropertiesToFile()
Try
Using writer As New StreamWriter(OutputFilePath) ' Update here
For Each prop In Properties
writer.WriteLine($"{prop.ID}{vbTab}{prop.Address}{vbTab}{prop.PropertyType}{vbTab}{prop.Price}{vbTab}{prop.Status}")
Next
End Using
Catch ex As Exception
Console.WriteLine("Error saving property data: " & ex.Message)
End Try
End Sub
' Add properties
Sub AddProperties()
Console.WriteLine("Add Properties")
While True
Console.Write("Enter Address (or press Enter to finish): ")
Dim address As String = Console.ReadLine()
If String.IsNullOrEmpty(address) Then
Exit While
End If
Console.Write("Enter Property Type: ")
Dim propertyType As String = Console.ReadLine()
Console.Write("Enter Price: ")
Dim price As Decimal = Decimal.Parse(Console.ReadLine())
Console.Write("Enter Status: ")
Dim status As String = Console.ReadLine()
Dim newID As Integer = If(Properties.Any(), Properties.Max(Function(prop) prop.ID) + 1, 1)
Dim newProperty As New PropertyRecord With {
.ID = newID,
.Address = address,
.PropertyType = propertyType,
.Price = price,
.Status = status
}
Properties.Add(newProperty)
Console.WriteLine("Property added successfully.")
End While
End Sub
' Update an existing property
Sub UpdateProperty()
Console.Write("Enter Property ID to update: ")
Dim idToUpdate As Integer = Integer.Parse(Console.ReadLine())
Dim propertyToUpdate As PropertyRecord = Properties.FirstOrDefault(Function(prop) prop.ID = idToUpdate)
If propertyToUpdate IsNot Nothing Then
Console.Write("Enter new Address: ")
propertyToUpdate.Address = Console.ReadLine()
Console.Write("Enter new Property Type: ")
propertyToUpdate.PropertyType = Console.ReadLine()
Console.Write("Enter new Price: ")
propertyToUpdate.Price = Decimal.Parse(Console.ReadLine())
Console.Write("Enter new Status: ")
propertyToUpdate.Status = Console.ReadLine()
Console.WriteLine("Property updated successfully.")
Else
Console.WriteLine("Property not found.")
End If
End Sub
' Delete a property
Sub DeleteProperty()
Console.Write("Enter Property ID to delete: ")
Dim idToDelete As Integer = Integer.Parse(Console.ReadLine())
Dim propertyToDelete As PropertyRecord = Properties.FirstOrDefault(Function(prop) prop.ID = idToDelete)
If propertyToDelete IsNot Nothing Then
Properties.Remove(propertyToDelete)
Console.WriteLine("Property deleted successfully.")
Else
Console.WriteLine("Property not found.")
End If
End Sub
' Search properties based on criteria
Sub SearchProperties()
Console.WriteLine("Search Properties")
Console.WriteLine("1. By Property Type")
Console.WriteLine("2. By Price Range")
Console.WriteLine("3. By Status")
Console.Write("Enter your choice: ")
Dim searchChoice As Integer = Integer.Parse(Console.ReadLine())
Select Case searchChoice
Case 1
Console.Write("Enter Property Type: ")
Dim propertyType As String = Console.ReadLine()
Dim results = Properties.Where(Function(prop) prop.PropertyType.Equals(propertyType, StringComparison.OrdinalIgnoreCase))
DisplaySearchResults(results)
Case 2
Console.Write("Enter Minimum Price: ")
Dim minPrice As Decimal = Decimal.Parse(Console.ReadLine())
Console.Write("Enter Maximum Price: ")
Dim maxPrice As Decimal = Decimal.Parse(Console.ReadLine())
Dim results = Properties.Where(Function(prop) prop.Price >= minPrice AndAlso prop.Price <= maxPrice)
DisplaySearchResults(results)
Case 3
Console.Write("Enter Status: ")
Dim status As String = Console.ReadLine()
Dim results = Properties.Where(Function(prop) prop.Status.Equals(status, StringComparison.OrdinalIgnoreCase))
DisplaySearchResults(results)
Case Else
Console.WriteLine("Invalid choice.")
End Select
End Sub
' Display search results
Sub DisplaySearchResults(results As IEnumerable(Of PropertyRecord))
Console.WriteLine("Search Results:")
If results.Any() Then
For Each prop In results
Console.WriteLine($"ID: {prop.ID}, Address: {prop.Address}, Property Type: {prop.PropertyType}, Price: {prop.Price:C}, Status: {prop.Status}")
Next
Else
Console.WriteLine("No properties found.")
End If
End Sub
' Calculate and display property statistics
Sub PropertyStatistics()
Console.WriteLine("Property Statistics")
Console.WriteLine($"Total Properties: {Properties.Count}")
Console.WriteLine($"Average Price: {Properties.Average(Function(prop) prop.Price):C}")
Dim propertyTypes = Properties.GroupBy(Function(prop) prop.PropertyType).Select(Function(group) New With {.Type = group.Key, .Count = group.Count()})
Console.WriteLine("Property Type Distribution:")
For Each type In propertyTypes
Console.WriteLine($"{type.Type}: {type.Count}")
Next
End Sub
' Generate property reports and save to the output file
Sub GenerateReports()
Try
Using writer As New StreamWriter(OutputFilePath)
writer.WriteLine("List of Available Properties")
writer.WriteLine()
writer.WriteLine($"{"ID",-6}{"Address",-20}{"Property Type",-15}{"Price",-10}{"Status",-10}")
writer.WriteLine(New String("-", 60))
For Each prop In Properties
If prop.Status.Equals("For Sale", StringComparison.OrdinalIgnoreCase) Then
writer.WriteLine($"{prop.ID,-6}{prop.Address,-20}{prop.PropertyType,-15}{prop.Price,-10:C}{prop.Status,-10}")
End If
Next
writer.WriteLine()
writer.WriteLine("List of Sold Properties")
writer.WriteLine()
writer.WriteLine($"{"ID",-6}{"Address",-20}{"Property Type",-15}{"Price",-10}{"Status",-10}")
writer.WriteLine(New String("-", 60))
For Each prop In Properties
If prop.Status.Equals("Sold", StringComparison.OrdinalIgnoreCase) Then
writer.WriteLine($"{prop.ID,-6}{prop.Address,-20}{prop.PropertyType,-15}{prop.Price,-10:C}{prop.Status,-10}")
End If
Next
End Using
Console.WriteLine("Reports generated and saved to output.txt")
Catch ex As Exception
Console.WriteLine("Error generating reports: " & ex.Message)
End Try
End Sub
End Module