This is my python code you will need easy gui to run it and the username is q and the password is 1 i need to select a customer and then overwrite there information and not change the id number that it already has the code is from a different program i have wrote and the create despatch notes is the edit function or the not edit function i guess
#Kit order database
from easygui import *
import csv
from easygui import EgStore
from datetime import *
import os
username = ""
password = ""
failed = 0
#continue/cancel box to request authentication to start the program
proceedLogon = ccbox("Authentication required to use this program","Security")
#if cancel is selected on the continue/cancel box to start the program
if proceedLogon == 0:
exit()
#while username or password are wrong and some of the 3 treis remain"
while (username != "q" or password != "1") and failed < 3:
#set a list for field names to enter
fieldNames = ["Username","Password"]
#create a list of values input in multi password box
fieldValues = multpasswordbox("Logon","System Access",fieldNames)
#handle user using cancel button on multpasswordbox, setting username to an
#empty string which will give a failed atte,pt
if fieldValues == None:
proceedLogon = ccbox("Are you sure you want to exit?","Logon")
# if continue is selected on the continue/cancel box exit the program
if proceedLogon == 1:
exit()
else:
#assign username and password to values input by user
username = fieldValues[0]
password = fieldValues[1]
#add one to the failed count if the username or password is wrong
if (username != "q" or password != "1"):
failed = failed+1
#if fail count exhausted
if failed == 3:
#message box to state login has failed
msgbox("Login failed")
#exit the program
exit()
elif(username !="q" or password !="1") and failed < 3:
#build a string for message box output to show number of tries remaining
failedMessage = (str(3-failed)+" tries remaining")
msgbox(failedMessage, "Failed Logon")
#if username and password are corret start the program
msgbox("Login successful")
#function to add a record to a givern record
def setUpFolders():
#if the program does not see a Invoices folder it creates one
if not os.path.exists("invoices"):
os.makedirs("invoices")
#if the program does not see a despatch notes folder it creates one
if not os.path.exists("despatch notes"):
os.makedirs("despatch notes")
#if the program does not see a paid invoices folder it creates one
if not os.path.exists("paid invoices"):
os.makedirs("paid invoices")
def addRecord(values, filename):
#set highest file number to 01
highestFileID = 0
#try opening file for reading, else use w+ to create file
#and reading records from file to get the highest ID number from first record
try:
file = open(filename, "r+")
#for each line in the file
for line in file:
#create a blank list for each line of the file to be read into
records = []
#at each pipe character split the string
for field in line.split("|"):
#add each entry in turn to a new position in the list
records.append(field)
#if the number in the first postition in the
#list is higher than the current highestfileID
if int(records[0]) > highestFileID:
#update the highestFileID to that higher
#number which is in the 1st positio of the list
highestFileID = int(records[0])
file.close()
#if file isn't there then create the file
except EnvironmentError as exception:
#create file for later appending
file = open(filename,"w+")
#create primary key for record
key = str(highestFileID + 1)
#create string for record joining the key to the details sent to this function(member/kit item/order)
record = "|".join([key] + values)
#write string to appropriate record file
file = open(filename,"a")
file.write(record + "\n")
file.close()
#returns next runner,event or entry ID
return highestFileID + 1
def enterClubMember():
#set fields for member information input dialogue box
msg = "Enter the new information"
title = "Add a new member"
fieldNames = ["Name","Street Address","Town/City","Postcode"]
#setting user details as a blank list
fieldValues = []
#set number of complete entries member details to 0
numberOfEntries = 0
#while there are less than 4 complete entries
while numberOfEntries < 4:
#input field values(new member details) in a multenter box
fieldValues = multenterbox(msg,title,fieldNames)
#cancel button option for member details entry to return to the menu
if fieldValues == None:
mainMenu()
#check each entry is the input list to see if it is not blank
#adding one to the complete entry count as appropriate
for entry in fieldValues:
if entry != "":
numberOfEntries += 1
#show error message if any of the lines was found to be blank
if numberOfEntries < 4:
msgbox("All fields must be filled in")
#reset counter for complete entries ready for data re-entry
numberOfEntries = 0
#format member details for neat case
fieldValues[0] = fieldValues[0].title()
fieldValues[1] = fieldValues[1].title()
fieldValues[2] = fieldValues[2].title()
fieldValues[3] = fieldValues[3].upper()
#return the list of entered member details to file by
#calling the addRecord function sending parametres of
#the member details list and the file name to save to
addRecord(fieldValues,"Bank company customers.txt")
def recordList(fileName):
#set record list empty
records = []
#attempt to open the requested filename
try:
file = open(fileName, "r+")
#process each line of the file
for line in file:
#create 2d list of contects from each line if the records file
records.append(line.split("|"))
file.close()
#if the file cannot be opened or loooped through
except EnvironmentError as exception:
msgbox("Could not open/read from the file")
#would return nothing
return None
#return records to the calling function
return records
#creating a function and setting it to createDespatchNote()
def createDespatchNote():
msg = "Enter the new information"
title = "Add a new member"
fieldNames = ["Name","Street Address","Town/City","Postcode"]
#calling a different function to find the text file
orderList = recordList("Bank company customers.txt")
updatedlist=[]
temporarylist=[]
with open("Bank company customers.txt",newline="") as f:
reader=list(csv.reader(f))#convert iterable to a list to make it easier
ynbox("CHANGE PASSWORD?!")
username=enterbox("Enter the name for the required customer:")
temporarylist=reader #store a copy of the data
for row in reader: #for every row in the file
for field in row:
if field==username: #if a field is == to the required username
updatedlist.append(row) #add each row, line by line, into a list called 'udpatedlist'
newpassword=multenterbox(msg,title,fieldNames)
updatedlist[1][2] = newpassword #set the field for password to the new password
updatepassword(updatedlist,temporarylist)
def updatepassword(updatedlist,temporarylist):
for index, row in enumerate(temporarylist):
for field in row:
if field==updatedlist[1]:
temporarylist[index]=updatedlist #replace old record with updated records
with open("Bank company customers.txt","w",newline="") as f:
Writer=csv.writer(f)
Writer.writerows(temporarylist)
print("File has been updated")
def markInvoiceAsPaid():
#calling a different function to find the text file
orderList = recordList("Bank Members.txt")
#if their isnt a file ouput error
if orderList == None:
msgbox("Error reading order file")
return
#setting choicelist to an empty list
choiceList = []
#for every order in the text file run the following code
for order in orderList:
#setting choice to a blank string
choice = ""
#for every position in the order
for field in order:
#after each field add a double space
choice += "{}|".format(field)
#after the choice list add the users choice to the end of the list
choiceList.append(choice)
#creating a title and message to go in a choice box
title = "Mark order as paid"
msg = "Select order to mark as paid"
#creating a choice box to mark the order as paid
orderChoice = choicebox(msg,title,choiceList)
#if their is no orders in the choice return to the main menu
if orderChoice == None:
mainMenu()
#setting markAsPaidID as order choice split with double space at position 0 with a strip
markAsPaidID = orderChoice.split(" ")[0].strip()
#setting invoiceFile as the invoices text file
invoiceFile = "invoices/order {} - confirmation.txt".format(markAsPaidID)
#if their is not an invoice file follow the following code
if os.path.isfile(invoiceFile):
#rename a text file called paid invoices and mark it as paid
os.rename(invoiceFile,"paid invoices/Order {} - paid.txt".format(markAsPaidID))
#creating a message to be used in a text box
msg = "Order " + markAsPaidID + " has been marked as paid"
#telling the user that the order has been marked as paid
msgbox(msg,"Confirmation")
return
#if the order does not successfully get marked as paid output an error
else:
msg = "failed to mark invoice as paid, because the original invoice could not be found"
msgbox(msg,"Failed operation")
#creating a function for unpaid invoices
def checkForUnpaidInvoices():
#setting unpaid invoices as an empty list
unpaidInvoices = []
#for every file in invoices
for filename in os.listdir("invoices"):
#try the following code
try:
#checking the date on the text file name
modifiedTime = os.path.getmtime("invoices/" + filename)
#if their is no time in the file name then it will outpun an error
except OSError:
modifiedTime = 0
msgbox("Unable to find files to check dates","Error")
#setting modified date
modifiedDate = datetime.fromtimestamp(modifiedTime)
#if modified date is more than 7 add it to the unpaid invoices file
if modifiedDate + timedelta(days=7) < datetime.now():
unpaidInvoices.append(filename)
#if the unpaid invoices file is larger than 0 run the following code
if len(unpaidInvoices) > 0:
#output the unpaid invoices
msgbox("\n".join(unpaidInvoices),"Unpaid invoices")
#if their are no unpaid invoices outputing saying that their are no unpaid invoices
else:
msgbox("There are not unpaid receipts over 7 days old","Report")
def mainMenu():
#initialise choice to an option that is not available
choice = 5
#while choice isnt the exit option
while choice != 0:
#set the button names as a list
choices = ["Exit","New club member",
"New kit item","New kit order & receipt","Create despatch note",
"Mark invoice as paid","check for unpaid orders over 7 days old"]
#input users gui choice
choice = indexbox("Choose a menu option","Kit Orders Database",
choices)
#if the choice to exit is selected then exit with a message
if choice == 0:
msgbox("Good bye!")
exit()
#else if choice is 1 call the enter club member function
elif choice == 1:
enterClubMember()
#else if choice is 2 call the enter kit item function
elif choice == 2:
enterKitItem()
#else if choice is 3 call the enter kit order function
elif choice == 3:
enterKitOrder()
#else if choice is 4 call the create despatch note function
elif choice == 4:
createDespatchNote()
#else if choice is 5 call the mark invoice as paid function
elif choice == 5:
markInvoiceAsPaid()
#else if choice is 6 call the check for unpaid invoices function
elif choice == 6:
checkForUnpaidInvoices()
#option for user using red cross exit button output invalid option
elif choice == None:
msgbox("Use the \"Exit\" option to leave the program","Invalid option")
#calling the main menu function
mainMenu()