예제 #1
0
def addmon():
    with open("Prem.csv","r") as f:
        csb=DictReader(f)
        for row in csb:
            mong=int(row['amount'])
    mon =int(enbug.get())
    ms=tk.messagebox.askquestion('Add money',f'Are you sure you want to add {mon}rs to your budget? ')
    if ms == 'yes':
        with open("Prem.csv","w") as g:
            csb=DictWriter(g,fieldnames=['name','amount'])
            csb.writeheader()
            csb.writerow({
                'name': 'budget',
                'amount': f"{mon+mong}"
                })
        tk.messagebox.showinfo('info',f"Now you budget has been {mon+mong}rs !")
        global l
        l.grid_forget()
        with open("Prem.csv","r") as fh:
            csb=DictReader(fh)
            for row in csb:
                mongn=row['amount']
        l=ttk.Label(framebug,text=f"Your current budget ramain {mongn} rs...")
        l.grid(row=5,column=0,pady=5)
        enbug.delete(0,'end')
예제 #2
0
def action4():
    con=mysql.connector.connect(host="localhost",user="******",password="",database="project")
    mycursor=con.cursor()
    if choice=="education":
        name=namestu.get()
        classs=classstu.get()
        mycursor=con.cursor()
        mycursor.execute(f"SELECT Fee from {databasen} where {en[0]}=\"{name}\" and {en[1]}=\"{classs}\" ")
        stu=mycursor.fetchone()
        if stu != None:
            fee=str(stu[0])
            if int(fee) == 0:
                messagebox.showerror('Error','Full fee deposit for this student')
            else:
                mycursor=con.cursor()
                with open("Prem.csv",'r') as f:
                    csv=DictReader(f)
                    for row in csv:
                        if classs==row['class']:
                            mon=row['fee']
                if int(money.get()) <= int(mon):
                    mycursor.execute(f"UPDATE {databasen} SET Fee={int(fee)-max(0,int(money.get()))} where {en[0]}=\"{name}\" AND {en[1]}=\"{classs}\" ")
                else:
                    mycursor.execute(f"UPDATE {databasen} SET Fee=0 where {en[0]}=\"{name}\" AND {en[1]}=\"{classs}\"  ")
                    messagebox.showinfo('Info',f'you have to return {int(money.get())-int(mon)} rupees to customer')
                messagebox.showinfo('Info','fee deposit')
            entryfee1.delete(0,"end")
            entryfee2.delete(0,"end")
            entryfee3.delete(0,"end")
        else:
            messagebox.showerror('Error','Name/class is not found in database')
    
    if choice == 'housework':
        nam=nmofc.get()
        mycursor=con.cursor()
        mycursor.execute(f"SELECT {en[1]},Payment_done from {databasen} where {en[0]}=\"{nam}\"  ")
        stu=mycursor.fetchone()
        if stu != None:
            if int(stu[0]) == 0:
                messagebox.showerror('Error','Full bill paid')
            else:
                mycursor=con.cursor()
                mon=money.get()
                with open('Prem.csv','r') as f:
                    csb=DictReader(f)
                    for row in csb:
                        bud=row['amount']
                if int(bud)<int(mon) or int(bud) == 0:
                    messagebox.showwarning('Warning','You have not sufficient budget')
                    return(0)
                if int(mon) <= int(stu[0]):
                    mycursor=con.cursor()
                    mycursor.execute(f"UPDATE {databasen} SET {en[1]}=\"{str(int(stu[0])-max(0,int(mon)))}\" where {en[0]}=\"{nam}\"  ")
                    mycursor=con.cursor()
                    mycursor.execute(f"UPDATE {databasen} SET Payment_done=\"{str(int(stu[1])+max(0,int(mon)))}\" where {en[0]}=\"{nam}\"  ")
                    pay=int(bud)-int(mon)
                else:
                    mycursor.execute(f"UPDATE {databasen} SET {en[1]}=\"0\" where {en[0]}=\"{nam}\"")
                    mycursor=con.cursor()
                    mycursor.execute(f"UPDATE {databasen} SET Payment_done=\"{str(int(stu[1])+max(0,int(mon)))}\" where {en[0]}=\"{nam}\"  ")
                    messagebox.showinfo('Info',f'you are paying {int(mon)-int(stu[0])} rs more')
                    pay=int(bud)-int(stu[0])
                with open('Prem.csv','w',newline="") as f:
                    csb=DictWriter(f,fieldnames=['name','amount'])
                    csb.writeheader()
                    csb.writerow({
                        'name':'budget',
                        'amount':pay
                    })                        
                messagebox.showinfo('Info',f'Amount paid to {nam.upper()}')
            nmofc.delete(0,"end")
            entryfee3.delete(0,"end")
        else:
            messagebox.showerror('Error','Data is not found in database')
    con.commit()
예제 #3
0
    for row in csv_f:
        print(
            f"The product \"{row['name']}\" has an id of {row['id']}. It sells for {row['cost']}, and there are only {row['qty']} left."
        )

# can specify a delimiter
# example: csv.DictReader(f, delimiter='|')

# # writing to a CSV file, using writer
from csv import writer
# creating path to CSV
path = r'C:\Users\truth\Desktop\code and resources\projects\resources\python\MIS-5400\mod_5\csv_test.csv'
# writing to CSV with writer
with open(path, 'a') as f:
    csv_f = writer(f)
    csv_f.writerow([2356, 'Hot Tamales', '', '$0.68', 66])
    csv_f.writerow([2326, 'Bit of Honey', '', '$0.06', 300])
    # you could also use writerows to put them all and at once
    # csv_f.writerows([['2326', 'Bit of Honey', '', '$0.06', '300'], ['2356', 'Hot Tamales', '', '$0.68', '66']])

# # writing to a CSV file, using DictWriter
from csv import DictWriter
# creating path to CSV
path = r'C:\Users\truth\Desktop\code and resources\projects\resources\python\MIS-5400\mod_5\csv_test.csv'
# writing to CSV with DictWriter
with open(path, 'a') as f:
    headers = ['id', 'name', 'description', 'cost', 'qty']
    csv_f = DictWriter(f, fieldnames=headers)
    csv_f.writerow({
        'id': 2356,
        'name': 'Hot Tamales',