Exemplo n.º 1
0
class GetData:
    """
    从MySQL数据库中获取组件、部件、纸箱信息的类
    """
    def __init__(self, log=None):
        self.log = log
        self.mysql = MysqlPool()

    def is_needing_pack(self):
        """
        查询组件表单是否有需要打包的组件
        :return: None(没有需要打包的组件) or Sec_id(组件号)
        """
        sql = "SELECT `Index`, `Sec_id` FROM `order_section_online` WHERE `Package_state`=0"
        section_info = self.mysql.do_sql_one(sql)
        if section_info is None:  # 没有需要打包的组件
            return None
        else:
            return section_info[1]

    def get_part_info(self):
        """
        获取部件表单信息(原始数据)
        :return: None(没有组件或部件信息) or part_lists(部件二维列表信息)
        """
        sec_id = self.is_needing_pack()
        part_lists = []
        if sec_id:
            sql = "SELECT `Contract_id`, `Order_id`, `Sec_id`, `Part_id`, `Door_type`, `Door_height`, `Door_width`, " \
                  "`Door_thick`, `Package_state`, `Element_type_id` FROM `order_part_online` WHERE `Sec_id` = '%s'" % \
                  sec_id
            part_info = self.mysql.do_sql(sql)
            if part_info is None:  # 部件表单无部件信息
                return None, part_lists
            else:
                for i in range(len(part_info)):
                    part_lists.append(list(part_info[i]))
                return sec_id, part_lists
        else:
            return None, part_lists

    def get_box_info(self):
        """
        获取纸箱表单信息(原始数据)
        :return: None(没有纸箱信息) or box_lists(纸箱二维列表信息)
        """
        box_lists = []
        sql = "SELECT `Box_type`, `Box_long`, `Box_short`, `Box_height` FROM `equipment_package_box` WHERE " \
              "`State`=5"
        box_info = self.mysql.do_sql(sql)
        if box_info is None:
            return None
        else:
            for i in range(len(box_info)):
                box_lists.append(list(box_info[i]))
            return box_lists
Exemplo n.º 2
0
    def __init__(self,
                 parent,
                 id=-1,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.WANTS_CHARS,
                 name='结果显示'):
        wx.grid.Grid.__init__(self, parent, id, pos, size, style, name)
        self.app = wx.GetApp()
        self.mysql = MysqlPool()
        # self.showGrid()

        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.onCellLeftClick)
Exemplo n.º 3
0
 def __init__(self, solution, section_id):
     self.solution = solution
     self.section_id = section_id
     self.mysql = MysqlPool()
Exemplo n.º 4
0
class PutData:
    def __init__(self, solution, section_id):
        self.solution = solution
        self.section_id = section_id
        self.mysql = MysqlPool()

    def convert_package(self):
        result_dict = self.init_result_dict()
        if isinstance(self.solution, list):
            package_lists = [
                part_item.package_id_scheme for part_item in self.solution
            ]
            count = Counter(package_lists)
            for package_id in count.keys():
                total_area = 0
                total_weight = 0
                total_volume = 0
                current_counter = 0
                solution_item = []
                for part_item in self.solution:
                    if part_item.package_id_scheme == package_id:
                        total_area += part_item.area_scheme
                        total_weight += part_item.weight_scheme
                        total_volume += part_item.volume_scheme
                        current_counter += 1
                        solute = '&'.join((str(part_item.position_scheme[0]),
                                           str(part_item.position_scheme[1]),
                                           str(part_item.position_scheme[2]),
                                           str(part_item.part_size_scheme[0]),
                                           str(part_item.part_size_scheme[1]),
                                           str(part_item.part_size_scheme[2]),
                                           str(part_item.rotation_scheme),
                                           part_item.part_id_scheme))
                        solution_item.append(solute)
                        # print('旋转状态:%s'%part_item.rotation_scheme)
                        if current_counter == count[package_id]:
                            result_dict['package_id'] = package_id
                            result_dict[
                                'total_layers'] = part_item.position_scheme[2]
                            result_dict['total_area'] = total_area
                            result_dict['total_weight'] = total_weight
                            result_dict['total_volume'] = total_volume
                            result_dict['section_id'] = re.findall(
                                ".*P(.*)-.*", package_id)[0]  # 获取两个字符之间的字符串
                            result_dict['order_id'] = re.findall(
                                ".*P(.*)S.*", package_id)[0]
                            result_dict['box_type'] = part_item.box_type_scheme
                            result_dict[
                                'box_length'] = part_item.box_size_scheme[0]
                            result_dict[
                                'box_width'] = part_item.box_size_scheme[1]
                            result_dict[
                                'box_height'] = part_item.box_size_scheme[2]
                            result_dict['part_num'] = count[package_id]
                            result_dict['volume_rate'] = total_volume / (
                                part_item.box_size_scheme[0] *
                                part_item.box_size_scheme[1] *
                                part_item.box_size_scheme[2])
                            if len(solution_item) > 1:
                                solution_str = '#'.join(solution_item)
                                result_dict['solution'] = solution_str
                            else:
                                result_dict['solution'] = solution_item[0]
                            self.put_package_table(result_dict)
                    else:
                        continue
            self.update_database()

    def init_result_dict(self):
        result_dict = {
            'package_id': '',
            'total_layers': 0,
            'total_area': 0,
            'total_weight': 0,
            'total_volume': 0,
            'section_id': '',
            'order_id': '',
            'box_type': '',
            'box_length': 0,
            'box_width': 0,
            'box_height': 0,
            'solution': '',
            'part_num': 0,
            'volume_rate': 0
        }
        return result_dict

    def put_package_table(self, result_dict):
        if result_dict:
            column_str = ''  # 列的字段
            row_str = ''  # 行字段
            for key in result_dict.keys():
                column_str = column_str + ' ' + '`' + key + '`,'
                row_str = (row_str + '"%s"' + ',') % str(result_dict[key])
            sql = "INSERT INTO %s (%s) VALUES (%s);" % (
                'package_result', column_str[:-1], row_str[:-1]
            )  # 取[:-1]是去除字符串最后的逗号
            self.mysql.insert(sql)

    def update_database(self):
        sql = "UPDATE `order_section_online` SET `Package_state` = 5 WHERE `Sec_id` = '%s'" % self.section_id
        self.mysql.upda_sql(sql)
Exemplo n.º 5
0
 def __init__(self, log=None):
     self.log = log
     self.mysql = MysqlPool()
Exemplo n.º 6
0
class ShowByGrid(wx.grid.Grid):
    def __init__(self,
                 parent,
                 id=-1,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.WANTS_CHARS,
                 name='结果显示'):
        wx.grid.Grid.__init__(self, parent, id, pos, size, style, name)
        self.app = wx.GetApp()
        self.mysql = MysqlPool()
        # self.showGrid()

        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.onCellLeftClick)

    def getRows(self):
        """获取数据库状态为0的打包数据"""
        sql = "SELECT `package_id`, `total_layers`, `total_area`, `total_weight`, `total_volume`, `section_id`, " \
              "`order_id`, `create_time`, `box_type`, `box_length`, `box_width`, `box_height`, `part_num`, " \
              "`volume_rate`, `state` FROM `package_result` WHERE `state` = '0'"
        self.package = self.mysql.do_sql(sql)
        if self.package:
            return len(self.package)

    def showGrid(self):
        print('当前线程是:', threading.current_thread().name)
        rows_num = self.getRows()
        if rows_num:
            self.CreateGrid(rows_num, 15)  # 创建Grid
            #######################设置Column的Header####################
            colHeaders = [
                '包编号', '层数', '面积', '重量', '体积', '组件号', '订单号', '创建时间', '纸箱类型',
                '纸箱长', '纸箱宽', '纸箱高', '部件数', '体积利用率', '状态'
            ]
            for i, colHeader in enumerate(colHeaders):
                self.SetColLabelValue(col=i, value=colHeader)
            #######################显示每个单元Cell的值####################
            for j, row in enumerate(self.package):
                for k, col in enumerate(row):
                    self.SetCellValue(j, k, str(col))
                    self.SetReadOnly(j, k)
            self.SetFont(
                wx.Font(pointSize=12,
                        family=wx.FONTFAMILY_ROMAN,
                        style=wx.FONTSTYLE_NORMAL,
                        weight=wx.FONTWEIGHT_BOLD))
            # self.AutoSize()
            self.SetColSize(col=0, width=90)
            self.SetColSize(col=7, width=130)
            self.SetColSize(col=8, width=90)

    def onCellLeftClick(self, event):
        self.app.frame.logTextCtrl.write_textctrl_txt(
            '第{}行,第{}列,单元格左上角坐标{} \r\n'.format(str(event.GetRow()),
                                               str(event.GetCol()),
                                               str(event.GetPosition())))
        # total_rows = self.GetNumberRows()
        # total_cols = self.GetNumberCols()
        # gridRowAttr = wx.grid.GridCellAttr()
        # gridRowAttr.SetBackgroundColour('yellow')
        # self.SetRowAttr(event.GetRow(), gridRowAttr)

        # attr = wx.grid.GridCellAttr()
        # attr.SetBackgroundColour('yellow')
        # self.SetRowAttr(event.GetRow(), attr)

        evtRow = event.GetRow()  # 获取cell点击事件所在的行
        package_id = self.GetCellValue(evtRow, 0)
        create_time = self.GetCellValue(evtRow, 7)

        sql = "SELECT `solution`,`total_layers`,`box_length`,`box_width`,`box_height`, `part_num` FROM `package_result` WHERE `package_id` = '%s' and `create_time`='%s'" % (
            package_id, create_time)
        solution = self.mysql.do_sql_one(sql)
        if solution:

            packResultShowDialog = PackResultShowDialog(parent=None,
                                                        id=-1,
                                                        package_id=package_id,
                                                        solution=solution)
            packResultShowDialog.ShowModal()
            packResultShowDialog.Destroy()
        self.app.frame.logTextCtrl.write_textctrl_txt(package_id)
        event.Skip()