예제 #1
0
 def _initialize_view(self, master):
     self.id_to_short = {}
     #SELECT INSTITUTESHORT
     from dboperate.db import Db
     try:
         db = Db()
         institu_short = db.query("select Iid, Ishort from Institutes")
         for item in institu_short:
             self.id_to_short[str(item[0])] = item[1]
     except Exception as e:
         messagebox.showerror("ERROR", e)
     db.destroy()
     import pandas as pd
     import sys
     from dboperate.db import Db
     try:
         db = Db()
         static_sql = "select Iid,count(Iid) from Students where Uid in (select Records.Uid from Records, Students where Records.Uid = Students.Uid) group by Iid"
         statics = db.query(static_sql)
     except Exception as e:
         messagebox.showerror("ERROR", e)
     db.destroy()
     static_dic = {}
     for item in statics:
         Iid = str(item[0])
         static_dic[self.id_to_short[Iid]] = item[1]
     static_cnt = pd.Series(static_dic)
     fig = static_cnt.plot(kind="bar").get_figure()
     fig.savefig("cuts/temp.png")
예제 #2
0
 def _initialize(self, master, usr_info):
     self.info = usr_info
     self.short_to_id = {}
     self.instituteshort = []
     #SELECT INSTITUTESHORT
     from dboperate.db import Db
     try:
         db = Db()
         institu_short = db.query("select Iid, Ishort from Institutes")
         for item in institu_short:
             self.short_to_id[item[1]] = str(item[0])
             self.instituteshort.append(item[1])
     except Exception as e:
         messagebox.showerror("ERROR", e)
     db.destroy()
     #SELECT IID
     self.Iid = StringVar()
예제 #3
0
 def show_room_state(self, floor, room):
     #SELECT FROM DATABASE
     room_id = "'" + floor[-1] + room + "'"
     query_statu_sql = "select STstatus from Seats where Rid = " + room_id
     try:
         from dboperate.db import Db
         db = Db()
         selected_seats_status = db.query(query_statu_sql)
         #print(selected_seats_status)
     except Exception as e:
         messagebox.showerror("ERROR", e)
     db.destroy()
     for i in range(4):
         for j in range(5):
             idx = i * 5 + j
             if selected_seats_status[idx][0]:
                 self.seats_btn_list[i][j]["image"] = self.img_seat_taken
                 self.seats_btn_list[i][j]["state"] = "disable"
             else:
                 self.seats_btn_list[i][j]["image"] = self.img_seat_takable
                 self.seats_btn_list[i][j]["state"] = "normal"
     self.frash()
예제 #4
0
 def _initialize(self, master, usr_info):
     self.info = usr_info
     self.records = [
         "RCDid, Uid, Rid, STid, Rtime, Operate_type, Operation"
     ]
     self.master
     from dboperate.db import Db
     try:
         db = Db()
         query_sql = "select * from Records order by Rtime desc"
         records = db.query(query_sql)
         for item in records:
             item = list(item)
             item[1] = str(item[1])
             item[4] = item[4].strftime("%Y-%m-%d %H:%M:%S")
             record = ""
             for j in item:
                 record = record + j + ", "
             self.records.append(record)
     except Exception as e:
         messagebox.showerror("ERROR", e)
     db.destroy()
예제 #5
0
 def _on_buttonclick_confirm(self):
     check = messagebox.askyesno(
         "CHECK", "Are you sure to creat a new student user?")
     if check:
         uid = self.uid_ety.get()
         passwd = self.passwd_ety.get()
         name = self.name_ety.get()
         sex = self.sex_cbb.get()
         age = self.age_ety.get()
         iid = self.Iid_ety.get()
         sclass = self.class_ety.get()
         major = self.major_ety.get()
         short = self.instiname_cbb.get()
         insert_sql = "insert into Students values(" + uid + ", '" + passwd + "', " + "'" + name + "', " + "'" + sex + "', " + age + ", " + iid + ", '" + sclass + "', '" + major + "', " + "'" + short + "')"
         #INSERT INTO STUDENTS
         from dboperate.db import Db
         try:
             db = Db()
             db.operate(insert_sql)
         except Exception as e:
             messagebox.showerror("ERROR", e)
         db.destroy()
예제 #6
0
 def take_a_seat(self, pos, floor, room):
     Rid = "'" + floor[-1] + room + "'"
     seat_num = (int(pos[0]) - 1) * 5 + (int(pos[2]) - 1) + 1
     STid = "'0"
     if seat_num < 10:
         STid += "0" + str(seat_num) + "'"
     else:
         STid += str(seat_num) + "'"
     #UPDATE INTO DATABASE
     update_Seats_sql = "update Seats set STstatus = 1 where Rid = " + Rid + " and " + "STid = " + STid
     #INSERT INTO RECOEDS
     from dboperate.db import Db
     import sys
     import time
     current_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                  time.localtime(time.time()))
     RCDid = current_time[0:4] + current_time[5:7] + current_time[8:10]
     current_time = "'" + current_time + "'"
     num = 0
     while True:
         tempid = "'" + RCDid + str("%02d" % num) + "'"
         db = Db()
         if not db.query("select * from Records where RCDid = " + tempid):
             break
         else:
             num += 1
     RCDid = tempid
     insert_Records_sql = "insert into Records values (" + RCDid + ", " + str(
         self.info[0][0]
     ) + ", " + Rid + ", " + STid + ", " + current_time + ", " + "'student', " + "'take')"
     try:
         db = Db()
         db.operate(insert_Records_sql)
         db.operate(update_Seats_sql)
     except Exception as e:
         messagebox.showerror("ERROR", e)
     db.destroy()
     from .formstudy import FormStudy
     FormStudy(Tk(), [pos, floor, room], self.info)
 def _on_buttonclick_leave(self):
     #print(self.info)
     pos, floor, room = self.info
     check = messagebox.askyesno("Check", "Do you want to leave")
     if check:
         # #UPDATE INTO DATABASE
         Rid = "'" + floor[-1] + room + "'"
         seat_num = (int(pos[0]) - 1) * 5 + (int(pos[2]) - 1) + 1
         STid = "'0"
         if seat_num < 10:
             STid += "0" + str(seat_num) + "'"
         else:
             STid += str(seat_num) + "'"
         update_Seats_sql = "update Seats set STstatus = 0 where Rid = " + Rid + " and " + "STid = " + STid
         from dboperate.db import Db
         import time
         current_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                      time.localtime(time.time()))
         RCDid = current_time[0:4] + current_time[5:7] + current_time[8:10]
         current_time = "'" + current_time + "'"
         num = 0
         db = Db()
         while True:
             tempid = "'" + RCDid + str("%02d" % num) + "'"
             if not db.query("select * from Records where RCDid = " +
                             tempid):
                 break
             else:
                 num += 1
         db.destroy()
         RCDid = tempid
         insert_Records_sql = "insert into Records values (" + RCDid + ", " + str(
             self.stu[0][0]
         ) + ", " + Rid + ", " + STid + ", " + current_time + ", " + "'student', " + "'leave')"
         try:
             db = Db()
             db.operate(insert_Records_sql)
             db.operate(update_Seats_sql)
         except Exception as e:
             messagebox.showerror("ERROR", e)
         db.destroy()
         self.close()
         FormMainStudent(Tk(), self.stu)
예제 #8
0
    def _on_buttonlogin_clicked(self, event=None):
        self.login_state_info.config(text="Logging you in...")
        self.master.update()
        sleep(1)

        user_name = (Decimal(self.username.get()), )
        password = (self.password.get(), )

        db = Db()
        #login success -> formmain
        try:
            query_librarians_id = "select Uid from Librarians"
            librarians_id_list = db.query(query_librarians_id)
            query_students_id = "select Uid from Students"
            students_id_list = db.query(query_students_id)
        except Exception as e:
            messagebox.showerror("ERROR!", e)
        if user_name in librarians_id_list:
            try:
                query_passwd = "select Upasswd from Librarians where Uid = " + str(
                    user_name[0])
                correct_passwd = db.query(query_passwd)
            except Exception as e:
                messagebox.showerror("ERROR!", e)
            if password in correct_passwd:
                query_info = "select * from Librarians where Uid = " + str(
                    user_name[0])
                try:
                    info = db.query(query_info)
                except Exception as e:
                    messagebox.showerror("ERROR!", e)
                self.close()
                #print(info)
                from .formmain import FormMainAdministor
                FormMainAdministor(Tk(), info)
            else:
                self.close()
                from .formloginfailure import FormLoginFailure
                FormLoginFailure(Tk())
        elif user_name in students_id_list:
            try:
                query_passwd = "select Upasswd from Students where Uid = " + str(
                    user_name[0])
                correct_passwd = db.query(query_passwd)
            except Exception as e:
                messagebox.showerror("ERROR!", e)
            if password in correct_passwd:
                query_info = "select * from Students where Uid = " + str(
                    user_name[0])
                try:
                    info = db.query(query_info)
                except Exception as e:
                    messagebox.showerror("ERROR!", e)
                self.close()
                from .formmain import FormMainStudent
                #print(info)
                FormMainStudent(Tk(), info)
            else:
                self.close()
                from .formloginfailure import FormLoginFailure
                FormLoginFailure(Tk())
        else:
            #login fail -> formloginfailure
            self.close()
            from .formloginfailure import FormLoginFailure
            FormLoginFailure(Tk())
        db.destroy()