def waiterLogin(): if request.method == 'GET': return render_template('waiterLogin.html') Rresult = sqlhelper.select_excution(''' select * from Rtable where Tid = %s; ''' % request.form['Tid']) Wresult = sqlhelper.select_excution(''' select * from Waiter where Wnum = '%s'; ''' % request.form['Wnum']) if (len(Rresult) != 1 or len(Wresult) != 1): return """ <script> alert('不存在桌号或工号'); history.go(-1); </script> """ print(Rresult) if(Rresult[0].Tstate == 0): return """ <script> alert('桌子没有客人'); history.go(-1); </script> """ if not session.has_key('menu'): menu = {'Tid':request.form['Tid'],'Wnum':request.form['Wnum'],'sum':0,'dishes':[],'Psum':0,'state':0} session.pop('menu', None) session['menu'] = menu return redirect(url_for('all_dishes'))
def all_dishes(Soid = '-1',page=1): print(session['menu']) if session['menu']['state'] !=0: return redirect(url_for('wait_dishes')) if(Soid=='-1'): Asum=int(sqlhelper.select_excution(""" select count(*) from dish """)[0][0]) else: Asum = int(sqlhelper.select_excution(""" select count(*) from dish where Soid = %s """ % Soid)[0][0]) print(Asum) if(page<1): page=1 if(page>(Asum-1)/6+1): page=(Asum-1)/6+1 sorts = sqlhelper.select_excution(""" select Soid,Sname from Sort; """) if(Soid=='-1'): dishes = sqlhelper.select_excution(""" select top 6 Did,Dname,Dpice,Dpic from dish where Did not in (select top %d Did from dish); """ % ((page-1)*6)) else: dishes = sqlhelper.select_excution(""" select top 6 Did,Dname,Dpice,Dpic from dish where Soid = %s and Did not in (select top %d Did from dish where Soid = %s); """ % (Soid,(page-1)*6,Soid)) return render_template('order_dish.html',page=page,dishes=dishes,sorts=sorts,Soid=int(Soid))
def add_cook(): if request.method == 'GET': return render_template('add_cook.html', sorts=sqlhelper.select_excution(''' select Soid,Sname from Sort; ''')) result = sqlhelper.insert_or_delet(""" insert into cook (Soid,Cname,Cage,Csex) values (%s,N'%s',%s,N'%s'); """ % (request.form['Soid'], request.form['Cname'], request.form['Cage'], request.form['Csex'])) return redirect(url_for('cookers'))
def add_waiter(): if request.method == 'GET': return render_template('add_waiter.html', Rooms=sqlhelper.select_excution(""" select Tname from Rtable where Tname!=N'´óÌü'; """)) result = sqlhelper.insert_or_delet(""" insert into Waiter (Wname,Wage,wsex,Wroom) values (N'%s',%s,N'%s',N'%s'); """ % (request.form['Wname'], request.form['Wage'], request.form['wsex'], request.form['Wroom'])) return redirect(url_for('waiters'))
def add_sort(): if request.method == 'GET': return render_template('add_sort.html', sorts=sqlhelper.select_excution(''' select Soid,Sname from Sort; ''')) result = sqlhelper.insert_or_delet(""" insert into Sort (Sname) values (N'%s'); """ % (request.form['Sname'])) return redirect(url_for('add_sort'))
def add_roomTable(): if request.method == 'GET': return render_template('add_roomTable.html', Tables=sqlhelper.select_excution(""" select Tname,Tsize,Tid from Rtable where Tname!=N'´óÌü'; """)) result = sqlhelper.insert_or_delet(""" insert into Rtable (Tsize,Tstate,Tname) values (%s,0,N'%s'); """ % (request.form['Tsize'], request.form['Tname'])) return redirect(url_for('add_roomTable'))
def display_bill(): bills=sqlhelper.select_excution(""" select Bid from bill where Bstate = 1; """) shows={} for b in bills: rows=sqlhelper.select_excution(""" select id,Dname,Sname,Dpice,nstate,B_D_T.Tid,Tname from B_D_T left join dish on B_D_T.Did=dish.Did left join Sort on dish.Soid=Sort.Soid left join Rtable on B_D_T.Tid=Rtable.Tid where Bid = %d """%b.Bid) psum=0 for r in rows: if(r.nstate==3): psum+=r.Dpice shows[str(b.Bid)]={'disher':rows,'psum':psum} print(shows) return render_template('display_bill.html',shows=shows)
def add_dish(): if request.method == 'GET': return render_template('add_dish.html', sorts=sqlhelper.select_excution(''' select Soid,Sname from Sort; ''')) file = request.files['picture'] if file and allowed_file(file.filename): savefile = str(uuid.uuid1()) + '.' + file.filename.rsplit('.', 1)[1]; file.save(os.path.join(app.config['UPLOAD_FOLDER'], savefile)) result = sqlhelper.insert_or_delet(""" insert into dish (Soid,Dname,Dpice,Dpic) values (%s,N'%s',%f,'%s'); """ % (request.form['Soid'], request.form['Dname'], float(request.form['Dpice']), savefile)) return redirect(url_for('dishes'))
def order_order(): Bid = sqlhelper.insert_get_seed(""" insert into bill (Bsun,Bstate) values (%f,0) """ % session['menu']['Psum']) for d in session['menu']['dishes']: sqlhelper.insert_or_delet(""" insert into B_D_T (Bid,Did,Tid,nstate) values (%s,%s,%s,0) """% (str(Bid),str(d['Did']),str(session['menu']['Tid']))) session['menu']['state']=1 session['menu']['Bid']=str(Bid) print(session['menu']) return render_template('wait_dishes.html',dishes=sqlhelper.select_excution(""" select id,Dname,Dpice,nstate from B_D_T left join dish on B_D_T.Did = dish.Did where B_D_T.Bid = %s """% str(Bid)))
def cook_job(): unfinish=sqlhelper.select_excution(""" select top 1 id,Dname,Dpic,Sname from B_D_T left join dish on B_D_T.Did=dish.Did left join Sort on dish.Soid=Sort.Soid where B_D_T.nstate = 1 and B_D_T.Cid = %s order by id """%session['cooker']['Cid']) if(len(unfinish)==1): return render_template('cook_job.html',row=unfinish[0]) row=sqlhelper.select_excution(""" select top 1 id,Dname,Dpic,Sname from B_D_T left join dish on B_D_T.Did=dish.Did left join Sort on dish.Soid=Sort.Soid where B_D_T.nstate = 0 and (dish.Soid = %s or Sort.Sname=N'¼Ò³£²Ë') order by id """% str(session['cooker']['Soid'])) if(len(row)>0): sqlhelper.insert_or_delet(""" update B_D_T set nstate = 1,Cid=%s where id = %s """ % (session['cooker']['Cid'],row[0].id)) return render_template('cook_job.html',row=row[0]) return (render_template('cook_job.html'))
def finish_order(): rows = sqlhelper.select_excution(""" select * from B_D_T where nstate != 3 and nstate !=4 and Bid = %s """ % str(session['menu']['Bid'])) if len(rows) != 0 : return """ <script> alert("you can't do that,still unfinish dish"); history.go(-1); </script> """ sqlhelper.insert_or_delet(""" update bill set Bstate = 1 where Bid = %s """% str(session['menu']['Bid'])) session.pop('menu', None) return redirect(url_for('waiterLogin'))
def cookLogin(): if request.method == 'GET': return render_template('cookerlogin.html') Rresult = sqlhelper.select_excution(''' select Cnum,Sname,Cook.Soid,Cid from Cook,Sort where Cnum = %s and Cook.Soid=Sort.Soid; ''' % request.form['Cnum']) if (len(Rresult) != 1): return """ <script> alert('not exist cooker number'); history.go(-1); </script> """ cooker = {'Cnum':Rresult[0].Cnum,'Cid':Rresult[0].Cid,'Sname':Rresult[0].Sname,'Soid':Rresult[0].Soid} session.pop('cooker', None) session['cooker'] = cooker return redirect(url_for('cook_job'))
def wait_dishes(): return render_template('wait_dishes.html',dishes=sqlhelper.select_excution(""" select id,Dname,Dpice,nstate from B_D_T left join dish on B_D_T.Did = dish.Did where B_D_T.Bid = %s """% str(session['menu']['Bid'])))
def cookers(): return render_template('cookers.html', cookers=sqlhelper.select_excution(''' select Cid,Sname,Cnum,Cname,Cage,Csex from Cook LEFT JOIN Sort ON Cook.Soid=Sort.Soid; '''))
def dishes(): return render_template('dish_list.html', dishes=sqlhelper.select_excution(''' select Did,Sname,Dname,Dpice from dish LEFT JOIN Sort ON dish.Soid=Sort.Soid; '''))
def select_hall(): return render_template('select_hall.html',tabless=sqlhelper.select_excution(""" select Tid,Tsize,Tstate from Rtable where Tname = N'´óÌü'; """))
def waiters(): return render_template('waiters.html', waiters=sqlhelper.select_excution(''' select Wid,Wnum,Wname,Wage,wsex,Wroom from Waiter; '''))