luochengPC vor 2 Jahren
Ursprung
Commit
00b61bb7d3
4 geänderte Dateien mit 60 neuen und 4 gelöschten Zeilen
  1. 7 4
      batch.py
  2. 43 0
      pro.py
  3. 9 0
      sql/sql.txt
  4. 1 0
      var.py

+ 7 - 4
batch.py

@@ -92,10 +92,13 @@ class my_batch(Frame):
 
     def bitch_release_event(self, event, bitch):
         if self.batch_timeout >= 1:
-            self.user_var.batch_y = bitch
-            self.batch_view.set("当前年份批号:" + self.user_var.batch_y)
-            self.user_var.order_year_str.set(self.user_var.batch_y)
-            self.user_var.batch_str.set(self.user_var.batch_y + self.user_var.batch_m + self.user_var.batch_d)
+            if self.user_var.batch_y != bitch:
+                self.user_var.batch_y = bitch
+                self.batch_view.set("当前年份批号:" + self.user_var.batch_y)
+                self.user_var.order_year_str.set(self.user_var.batch_y)
+                self.user_var.batch_str.set(self.user_var.batch_y + self.user_var.batch_m + self.user_var.batch_d)
+                self.user_var.order_update_stat = True
+                self.user_var.batch_update_stat = True
 
     # 控制栏
     def button_canvas_init(self):

+ 43 - 0
pro.py

@@ -292,9 +292,47 @@ class work_server(threading.Thread):
                     self.user_var.number_count = self.user_var.order_ok + 1
                     self.product_number_pro()
                     self.user_var.serial_num_working = self.user_var.serial_num_value
+                elif (airng_r == True and airng_w == True) or (airok_r == True and airok_w == True):
+                    print("no start to working")
+                    self.user_var.airdata_work_stat = 'working'
+                    self.user_var.serial_num = self.user_var.order_ok + self.user_var.order_ng + 1
+                    self.user_var.number_count = self.user_var.order_ok + 1
+                    self.product_number_pro()
+                    self.user_var.serial_num_working = self.user_var.serial_num_value
 
     # def database_pro(self):
 
+    def update_batch_tbl(self):
+        sqlstr = "UPDATE batch_tbl SET end_time={0}, stat={1} WHERE stat = {2}".format(
+                                                        int(time.time()), True, False)
+        self.sqlclient.sql_action_all(sqlstr)
+
+    def insert_batch_tbl(self):
+        sqlstr = "INSERT INTO batch_tbl "
+        sqlstr = sqlstr + "(year, begin_time, end_time, stat)"
+        sqlstr = sqlstr + " VALUES ('{0}', '{1}', '{2}', {3})".format(
+            self.user_var.batch_y,
+            int(time.time()),
+            int(time.time()),
+            False
+        )
+        self.sqlclient.sql_action_all(sqlstr)
+
+    def batch_tbl_check(self):
+        sqlstr = 'SELECT year FROM batch_tbl WHERE stat=False ORDER by begin_time DESC'
+        results = self.sqlclient.sql_inquire_all(sqlstr)
+        if results != None and len(results) > 0:
+            idx = 0
+            for row in results:
+                if idx == 0:
+                    if row[0] >= 'A' and row[0] <= 'Z':
+                        self.user_var.batch_y = row[0]
+                        self.user_var.order_year_str.set(self.user_var.batch_y)
+                        self.user_var.batch_str.set(
+                        self.user_var.batch_y + self.user_var.batch_m + self.user_var.batch_d)
+        else:
+            self.insert_batch_tbl()
+
     def update_data_tbl(self, status):
         sqlstr = 'UPDATE product_data_tbl SET '
         if status == True:
@@ -596,6 +634,7 @@ class work_server(threading.Thread):
             time.sleep(1)
 
         if self.exit_stat == False:
+            self.batch_tbl_check()
             self.batch_pro()
             self.order_tbl_check()
             # self.param_tbl_check()
@@ -604,6 +643,10 @@ class work_server(threading.Thread):
             with main.threadlock:
                 if self.user_var.product_load == True:
                     self.product_name_set()
+                if self.user_var.batch_update_stat == True:
+                    self.user_var.batch_update_stat = False
+                    self.update_batch_tbl()
+                    self.insert_batch_tbl()
                 self.product_name_check()
                 self.plc_conn_check()
                 self.opc_data_pro()

+ 9 - 0
sql/sql.txt

@@ -11,6 +11,15 @@ CREATE TABLE IF NOT EXISTS user_tbl(
 
 INSERT INTO user_tbl (name,password) VALUES('admin', '123456');
 
+CREATE TABLE IF NOT EXISTS batch_tbl(
+   id INT UNSIGNED AUTO_INCREMENT,
+   year CHAR(1) NOT NULL,
+   begin_time BIGINT NOT NULL,
+   end_time BIGINT,
+   stat BOOL NOT NULL,
+   PRIMARY KEY ( id )
+)ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 CREATE TABLE IF NOT EXISTS order_tbl(
    id INT UNSIGNED AUTO_INCREMENT,
    order_num VARCHAR(30) NOT NULL,

+ 1 - 0
var.py

@@ -116,6 +116,7 @@ class Var_value(Frame):
         self.order_targe = 0
         self.order_sng = 0
         self.order_update_stat = False
+        self.batch_update_stat = False
 
         # 批号
         self.number_type = '2GN'