Commit 03d8f1d4 authored by panos's avatar panos Committed by Georgios Dagkakis

Bug fixed in the interface to update the database

parent 766a6e6c
...@@ -24,7 +24,7 @@ Created on 20 March 2015 ...@@ -24,7 +24,7 @@ Created on 20 March 2015
import Tkinter as tk import Tkinter as tk
from Tkinter import * from Tkinter import *
import pyodbc import ImportDatabase
import tkMessageBox import tkMessageBox
from datetime import datetime from datetime import datetime
...@@ -120,11 +120,10 @@ class Demo1(Frame): ...@@ -120,11 +120,10 @@ class Demo1(Frame):
return return
def checkInsertedProject(self): def checkInsertedProject(self):
cnxn =pyodbc.connect("Driver={MySQL ODBC 3.51 Driver};SERVER=localhost; PORT=3306;DATABASE=bal_database;UID=root; PASSWORD=Pitheos10;") cnxn=ImportDatabase.ConnectionData(seekName='ServerData', file_path='C:\Users\Panos\Documents\DB_Approach\CapacityStations', implicitExt='txt', number_of_cursors=6)
cursor1 = cnxn.cursor() cursor=cnxn.getCursors()
cursor2 = cnxn.cursor()
a=cursor1.execute(""" a=cursor[0].execute("""
select Order_id, ProjectName, Status select Order_id, ProjectName, Status
from orders from orders
""") """)
...@@ -139,10 +138,10 @@ class Demo1(Frame): ...@@ -139,10 +138,10 @@ class Demo1(Frame):
return availableProject return availableProject
def alreadyInsertedWP(self): def alreadyInsertedWP(self):
cnxn =pyodbc.connect("Driver={MySQL ODBC 3.51 Driver};SERVER=localhost; PORT=3306;DATABASE=bal_database;UID=root; PASSWORD=Pitheos10; ") cnxn=ImportDatabase.ConnectionData(seekName='ServerData', file_path='C:\Users\Panos\Documents\DB_Approach\CapacityStations', implicitExt='txt', number_of_cursors=6)
cursor = cnxn.cursor() cursor=cnxn.getCursors()
c=cursor.execute(""" c=cursor[0].execute("""
select WP_id, END_DATE select WP_id, END_DATE
from production_status from production_status
""") """)
...@@ -157,54 +156,52 @@ class Demo1(Frame): ...@@ -157,54 +156,52 @@ class Demo1(Frame):
def updateDatabase(self): def updateDatabase(self):
cnxn =pyodbc.connect("Driver={MySQL ODBC 3.51 Driver};SERVER=localhost; PORT=3306;DATABASE=bal_database;UID=root; PASSWORD=Pitheos10; ") cnxn=ImportDatabase.ConnectionData(seekName='ServerData', file_path='C:\Users\Panos\Documents\DB_Approach\CapacityStations', implicitExt='txt', number_of_cursors=13)
cursor = cnxn.cursor() cursor=cnxn.getCursors()
cursor1 = cnxn.cursor()
if self.checkBoxVal2.get(): if self.checkBoxVal2.get():
update_order= ("INSERT INTO production_status(`status_id`, `WP_id`, `Operation_Name`, `START_DATE`, `Capacity_left`, `Remarks`,`END_DATE`) VALUES ( ?, ?, ?, ?, ?, ?, ?)") update_order= ("INSERT INTO production_status(`status_id`, `WP_id`, `Operation_Name`, `START_DATE`, `Capacity_left`, `Remarks`,`END_DATE`) VALUES ( ?, ?, ?, ?, ?, ?, ?)")
cursor.execute("SELECT @@IDENTITY AS ID") cursor[0].execute("SELECT @@IDENTITY AS ID")
order = self.OrderOption.get() order = self.OrderOption.get()
a = cursor1.execute(""" a = cursor[1].execute("""
select WP_id, Order_id select WP_id, Order_id
from sequence where Order_id=? from sequence where Order_id=?
""", order) """, order)
for j in range(a.rowcount): for j in range(a.rowcount):
ind2=a.fetchone() ind2=a.fetchone()
lastWP =ind2.WP_id lastWP =ind2.WP_id
print lastWP b = cursor[2].execute("""
b = cursor1.execute("""
select sequence.WP_id, sequence.Order_id select sequence.WP_id, sequence.Order_id
from sequence where Operation_Name=? from sequence where Operation_Name=?
""", self.operationOption.get()) """, self.operationOption.get())
ind4=b.fetchone() ind4=b.fetchone()
status2 = 'finished' status2 = 'finished'
row = cursor.fetchone() row = cursor[0].fetchone()
WP=ind4[0] WP=ind4[0]
order_ref = row.ID order_ref = row.ID
status1 = 'in progress' status1 = 'in progress'
cursor.execute(update_order, (order_ref, WP, self.operationOption.get(), str(datetime.now()), self.capacity.get(), self.comments.get(),str(datetime.now()) )) cursor[4].execute(update_order, (order_ref, WP, self.operationOption.get(), str(datetime.now()), self.capacity.get(), self.comments.get(),str(datetime.now()) ))
if WP == lastWP: if WP == lastWP:
cursor.execute("UPDATE orders SET `Status`=? WHERE Order_id=? ", status2, order) cursor[5].execute("UPDATE orders SET `Status`=? WHERE Order_id=? ", status2, order)
cursor.commit() cursor[6].commit()
self.close_window() self.close_window()
else: else:
update_order= ("INSERT INTO production_status(`status_id`, `WP_id`, `Operation_Name`, `START_DATE`, `Capacity_left`, `Remarks`) VALUES ( ?, ?, ?, ?, ?, ?)") update_order= ("INSERT INTO production_status(`status_id`, `WP_id`, `Operation_Name`, `START_DATE`, `Capacity_left`, `Remarks`) VALUES ( ?, ?, ?, ?, ?, ?)")
cursor.execute("SELECT @@IDENTITY AS ID") cursor[7].execute("SELECT @@IDENTITY AS ID")
order = self.OrderOption.get() order = self.OrderOption.get()
a = cursor1.execute(""" a = cursor[8].execute("""
select sequence.WP_id, sequence.Order_id, sequence.Operation_Name select sequence.WP_id, sequence.Order_id, sequence.Operation_Name
from sequence where Order_id=? and Operation_Name=? from sequence where Order_id=? and Operation_Name=?
""", order, self.operationOption.get()) """, order, self.operationOption.get())
ind3=a.fetchone() ind3=a.fetchone()
WP=ind3.WP_id WP=ind3.WP_id
row = cursor.fetchone() row = cursor[7].fetchone()
order_ref = row.ID order_ref = row.ID
status1 = 'in progress' status1 = 'in progress'
cursor.execute(update_order, (order_ref, WP, self.operationOption.get(), str(datetime.now()), self.capacity.get(), self.comments.get())) cursor[10].execute(update_order, (order_ref, WP, self.operationOption.get(), str(datetime.now()), self.capacity.get(), self.comments.get()))
cursor.execute("UPDATE orders SET `Status`=? WHERE Order_id=? ", status1, order) cursor[11].execute("UPDATE orders SET `Status`=? WHERE Order_id=? ", status1, order)
cursor.commit() cursor[12].commit()
self.close_window() self.close_window()
return return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment