-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsUserCode.py
131 lines (106 loc) · 4.25 KB
/
clsUserCode.py
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
# This code was written by Ahmed Abu-Awwad 202210704
import clsPersonCode
from tkinter import messagebox
class clsUser(clsPersonCode.clsPerson):
Filepath = 'Users.txt'
def __init__(self,FirstName,LastName,Email,Phone,username,password,permission):
super().__init__(FirstName, LastName, Email, Phone)
self._username = username
self._password = password
self._permission = permission
def Setusername(self,username):
self._username = username
def Getusername(self):
return self._username
def Setpassword(self,password):
self._password = password
def Getpassword(self):
return self._password
def Setpermission(self,permission):
self._permission = permission
def Getpermission(self):
return self._permission
def Print(self):
print('Info: \n')
print('\n---------------------')
print(f'\nUserName: {self._username}')
print(f'\nFirstName: {self._FirstName}')
print(f'\nLastName: {self._LastName}')
print(f'\nFullName: {self.GetFullName()}')
print(f'\nEmail: {self._Email}')
print(f'\nPhone: {self._Phone}')
print(f'\nPassword: {self._password}')
print(f'\npermission: {self._permission}')
print('\n---------------------\n')
@staticmethod
def LoadDataOnTuple():
try:
allData = []
file = open(clsUser.Filepath, 'r')
Data = file.readlines()
for line in Data:
line = line.split('#//#')
allData.append( (line[0], line[1], line[2], line[3], line[4], line[5], int(line[6]) ) )
file.close()
return tuple(allData)
except:
messagebox.showerror('Error','You have error in file')
@staticmethod
def LoadDataOnObjects():
try:
allData = []
file = open(clsUser.Filepath, 'r')
Data = file.readlines()
for line in Data:
line = line.split('#//#')
allData.append(clsUser(line[0], line[1], line[2], line[3], line[4], line[5], int(line[6])))
file.close()
return allData
except:
messagebox.showerror('Error','You have error in file')
def ConvertObjectToLine(self,obj,Delim='#//#'):
return obj.GetFirstName()+Delim+obj.GetLastName()+Delim+obj.GetEmail()+Delim+obj.GetPhone()+Delim+obj.Getusername()+Delim+obj.Getpassword()+Delim+str(obj.Getpermission())
def AddNew(self):
file = open(clsUser.Filepath,'a')
line = self.ConvertObjectToLine(self)+'\n'
file.write(line)
file.close()
def Update(self,Email,Phone,password,permissions):
alldata = self.LoadDataOnObjects()
file = open(clsUser.Filepath,'w')
file.close()
file = open(clsUser.Filepath, 'a')
for obj in alldata:
if self.Getusername() == obj.Getusername():
obj.SetEmail(Email)
obj.SetPhone(Phone)
obj.Setpassword(password)
obj.Setpermission(permissions)
file.write(self.ConvertObjectToLine(obj)+'\n')
file.close()
def Delete(self):
alldata = self.LoadDataOnObjects()
file = open(clsUser.Filepath, 'w')
file.close()
file = open(clsUser.Filepath, 'a')
for obj in alldata:
if self.Getusername() != obj.Getusername():
file.write(self.ConvertObjectToLine(obj) + '\n')
file.close()
@staticmethod
def IsExist(username):
return ''!=clsUser.Find(username).Getusername()
@staticmethod
def Find(Username):
alldata = clsUser.LoadDataOnObjects()
for obj in alldata:
if Username == obj.Getusername():
return obj
return clsUser('','','','','','',0)
@staticmethod
def Find2(Username,Password):
alldata = clsUser.LoadDataOnObjects()
for obj in alldata:
if Username == obj.Getusername() and Password == obj.Getpassword():
return obj
return clsUser('', '', '', '', '', '', 0)