Exemple #1
0
 def on_btn_Download_clicked(self, addtionalInfoRow=None):
     # 生成临时文件夹
     tm = time.strftime('%Y%m%d%H%M%S', time.localtime())
     uid = JPUser().currentUserID()
     topath = os.path.join(os.getcwd(), "temp", "{}_{}".format(uid, tm))
     if not os.path.exists(topath):
         os.makedirs(topath)
     # 下载文件列表
     lst = addtionalInfoRow if addtionalInfoRow else \
         [item for item in self.addtionalInfo if not item.deleted]
     copylst = []
     for i, item in enumerate(lst):
         if item.archives_pk:
             fr = os.path.join(self.archivesPathInDatabase,
                               item.md5FilePath)
             to = os.path.join(topath, item.original_name)
             copylst.append([fr, to])
         else:
             fr = item.original_path
             to = os.path.join(topath, item.original_name)
             copylst.append([fr, to])
     pop = FormPopProgressBar(self)
     pop.reset(len(copylst) - 1)
     for r in copylst:
         pop.dispInfo("复制{}".format(r[1]), i)
         myCopy(r[0], r[1])
     pop.close()
     txt = '文件保存在:【{}】,点击确定打开该文件夹!'.format(topath)
     if QMessageBox.question(self, '完成', txt,
                             (QMessageBox.Yes | QMessageBox.No),
                             QMessageBox.Yes) == QMessageBox.Yes:
         topath1 = os.path.abspath(topath)
         os.system("start explorer {}".format(topath1))
Exemple #2
0
 def __SavePic(self, result):
     pic = self.ui.label_Tax_Registration
     if not (pic.to_FullPath and pic.NewFileName):
         return
     try:
         myCopy(pic.NewFileName, pic.to_FullPath)
     except Exception as e:
         raise MyCopyFileError(pic.NewFileName, pic.to_FullPath, str(e))
Exemple #3
0
    def listItemDoubleClicked(self, item):
        def check(item):
            cunzai = [r for r in self.laseDoubleInfo if r.item is item]
            if not cunzai:
                t = datetime.datetime.now()
                self.laseDoubleInfo.append(lastDoubleItemInfo(item, t))
                return True
            else:
                n = datetime.datetime.now()
                if (n - cunzai[0].clickTime).seconds > 3:
                    cunzai[0].clickTime = n
                    return True
                else:
                    t = "您刚刚点击过本条目,正在调用系统功能打开文件,请不要重复点击!"
                    QMessageBox.warning(self, '提示', t, QMessageBox.ok)

        if item.picInfo.iconPath:
            if not check(item):
                return
            self.pop = FormPopProgressBar(self)
            self.pop.setMinimumDuration(0)
            self.pop.open()
            self.pop.reset(2)
            uid = JPUser().currentUserID()
            tm = time.strftime('%Y%m%d%H%M%S', time.localtime())
            topath = os.path.join(os.getcwd(), "temp", "{}_{}".format(uid, tm))
            if not os.path.exists(topath):
                os.makedirs(topath)
            topath = os.path.join(topath,
                                  item.picInfo.originalName.replace(" ", ''))
            self.pop.dispInfo("正在下载{}".format(item.picInfo.originalName), 1)
            myCopy(item.picInfo.originalPath, topath)
            self.pop.dispDelayed(
                "正在调用系统功能打开文件{},请稍候....".format(item.picInfo.originalName), 2)
            os.system(topath)

        else:
            frm = Form_ViewPic(self, item.picInfo, self.viewPicInfos)
            # frm.setData(item.picInfo, self.viewPicInfos)
            frm.show
Exemple #4
0
    def on_butFileImport_clicked(self):

        def getInsertAndFileSQL():
            return
        QF = QFileDialog.getOpenFileNames
        fns, filetype = QF(self,
                           "Select a File",
                           JPPub().getOrSetlastOpenDir(),  # 起始路径
                           "Files (*.jpg *.PDF *.doc *.docx *.xls *.xlsx)")
        if not fns:
            return
        JPPub().getOrSetlastOpenDir(fns[0])
        newPKString = JPDb().LAST_INSERT_ID_SQL()
        self.showInfo(len(fns))
        hasError = 0
        for i, original_path in enumerate(fns):
            SQLS = []
            s = "检查是否存在数据库中{}".format(original_path)
            logging.getLogger().debug(s)
            self.dispInfo(s, i+1)
            exist, md5FileName, md5BaseName, file_pk = md5Exist(
                original_path, self.con_path)
            fldValues = self.getFieldsValues(original_path)
            SQLS.append(self.getInsertArchiveSQL(self.archive_type, fldValues))
            SQLS.append("{} INTO @archive_pk;".format(newPKString))
            if exist:
                SQLS.append("select {} into @file_pk;".format(file_pk))
            else:
                s2 = "insert into t_additionals (original_name,filemd5"
                s2 = s2 + ",file_type) VALUES ('{}',unhex('{}'),'{}');"
                SQLS.append(s2.format(os.path.basename(original_path),
                                      md5BaseName, getExName(original_path)))
                SQLS.append("{} INTO @file_pk;".format(newPKString))
            s1 = "insert into t_additionals_archives(archives_pk, file_pk)"
            s1 = s1+" VALUES (@archive_pk,@file_pk);"
            SQLS.append(s1)
            if not exist:
                s = "复制【{}】".format(original_path)
                logging.getLogger().debug(s)
                self.dispInfo(s, i+1)
                try:
                    toPath = "{}/{}".format(self.con_path, md5FileName)
                    myCopy(original_path, toPath)
                except Exception as e:
                    hasError += 1
                    t = '上传文件过程出现错误,档案未上传,错误信息为:\n{}'
                    logging.getLogger().debug(t)
                    msgBox = QMessageBox(QMessageBox.Critical,
                                         u'提示', t.format(str(e)))
                    msgBox.exec_()
            try:
                JPDb().executeTransaction(SQLS)
            except Exception as e:
                hasError += 1
                t = '执行增加档案SQL中出现错误,档案并未实际添加,错误信息为:\n{}\n执行SQL为\n{}'
                strSql = '\n'.join(SQLS)
                errStr = t.format(str(e), strSql)
                logging.getLogger().error("生成的导入文件夹SQL错误:"+strSql)
                msgBox = QMessageBox(QMessageBox.Critical,
                                     u'提示', errStr)
                msgBox.exec_()

        # 循环执行完后报告
        else:
            self.hideInfo()
            okStr = "完成但出现{}个错误".format(hasError) if hasError else "完成"
            QMessageBox.information(self, '提示', okStr)
Exemple #5
0
 def on_butPathImport_clicked(self):
     path_lst = self.getAndCheckPaths()
     newPKString = JPDb().LAST_INSERT_ID_SQL()
     self.showInfo(len(path_lst))
     hasError = 0
     SQLS = []
     for i, path in enumerate(path_lst):
         dic = self.getFieldsValues(path)
         fns = ["CONCAT('包含文件:',char(10),REPEAT('-',150))"]
         addFileSQL = []
         subPath = os.listdir(path)
         subPath = ["/".join((path, item)) for item in subPath]
         s = "正在处理{}".format(path)
         logging.getLogger().debug(s)
         self.dispInfo(s, i+1)
         for j, sub in enumerate(subPath):
             fns.append(sqm(os.path.basename(sub)+";"))
             exist, md5FileName, md5BaseName, file_pk = md5Exist(
                 sub, self.con_path)
             if not exist:
                 s = "--->复制【{}】".format(sub)
                 self.dispInfo(s, i+1)
                 logging.getLogger().debug(s)
                 try:
                     toPath = "{}/{}".format(self.con_path, md5FileName)
                     myCopy(sub, toPath)
                     s2 = "insert into t_additionals (original_name,filemd5,"
                     s2 = s2+"file_type) VALUES ('{}',unhex('{}'),'{}');"
                     s2 = [s2.format(os.path.basename(sub),
                                     md5BaseName, getExName(sub)), newPKString]
                     isOK, pk = JPDb().executeTransaction(s2)
                     addFileSQL.append(
                         "select {} into @file_pk{};".format(pk, j))
                 except Exception as e:
                     hasError += 1
                     t = '上传文件过程出现错误,档案未上传,错误信息为:\n{}'
                     logging.getLogger().debug(t)
                     msgBox = QMessageBox(QMessageBox.Critical,
                                          u'提示', t.format(str(e)))
                     msgBox.exec_()
                     print(t)
             else:
                 addFileSQL.append(
                     "SELECT {} INTO @file_pk{};".format(file_pk, j))
             s1 = "insert into t_additionals_archives(archives_pk, file_pk)"
             s1 = s1 + " VALUES(@archive_pk, @file_pk{})"
             addFileSQL.append(s1.format(j))
         dic['archive_describe'] = "CONCAT({})".format(
             (",char(10),").join(fns))
         dic['archive_type'] = sqm(self.archive_type)
         SQLS.append(self.getInsertArchiveSQL('50', dic))
         SQLS.append("{} INTO @archive_pk;".format(newPKString))
         SQLS = SQLS + addFileSQL
         try:
             JPDb().executeTransaction(SQLS)
             SQLS = []
         except Exception as e:
             hasError += 1
             t = '执行增加档案SQL中出现错误,档案并未实际添加,错误信息为:\n{}\n执行SQL为\n{}'
             strSql = '\n'.join(SQLS)
             errStr = t.format(str(e), strSql)
             msgBox = QMessageBox(QMessageBox.Critical,
                                  u'提示', errStr)
             msgBox.exec_()
     QMessageBox.information(self, '提示', "OK")
Exemple #6
0
    def CopyPicAndGetSaveFileSQL(self) -> list:
        sqls = []
        if not self.addtionalChanged:
            return sqls
        used_sql = """
                select archives_pk from t_additionals_archives
                where file_pk={file_pk}
                    and archives_pk<>{archives_pk} limit 1;
                """
        del_sql = """
                delete from t_additionals_archives
                where archives_pk={archives_pk}
                    and file_pk={file_pk};
                """
        ins_file = """
                insert into t_additionals
                    (original_name,filemd5,file_type)
                    Values ('{original_name}',
                    unhex('{filemd5}'),'{file_type}');
                """
        ins_add = """
                insert into t_additionals_archives
                    (archives_pk,file_pk,file_index)
                    Values ({archives_pk},{file_pk},{file_index});
                """
        up_index = """update t_additionals_archives
                        set file_index={file_index}
                        where archives_pk={archives_pk}
                            and file_pk={file_pk}"""
        temp_id = self.ui.archives_pk.text()
        cur_pk = temp_id.replace(",", "") if self.isEditMode else ''
        if self.isNewMode:

            cur_pk = '@archives_pk'

        def fileIsUsed(file_pk, archives_pk):
            s = used_sql.format(file_pk=file_pk, archives_pk=archives_pk)
            return JPDb().executeTransaction(s)

        # self.setCursor(Qt.WaitCursor)
        for iRow, r in enumerate(self.addtionalInfo):
            # 删除情况1:用户删除了一个数据库已经存在的文件
            if r.archives_pk and r.deleted:
                # 删除本附件对文件的引用
                tempsql = del_sql.format(file_pk=r.file_pk,
                                         archives_pk=r.archives_pk)
                sqls.append(tempsql)
                if fileIsUsed(r.file_pk, r.archives_pk):
                    # 如果文件已经被其他附件引用,则只删除本附件的引用
                    continue
                else:
                    # 如果没有没有被其他用户引用,物理删除之
                    filePath = r.md5FilePath
                    if os.path.exists(filePath):
                        self.ui.Label_Info.setText("正在删除【{}】".format(filePath))
                        os.remove(filePath)
                        self.self.ui.Label_Info.setText('')
            # 删除情况2:如果是刚刚增加的文件被用户删除,则跳过不处理本行数据
            if not r.archives_pk and r.deleted:
                continue

            # 增加情况1:增加的文件数据库中已经有其他附件引用
            # if r.file_pk and not r.deleted:
            if r.isNew and r.file_pk:
                p_s = ins_add.format(archives_pk=cur_pk,
                                     file_pk=r.file_pk,
                                     file_index=iRow)
                sqls.append(p_s)
            # 增加情况2:增加的文件数据库中不存在,进行物理复制
            # if not r.file_pk and not r.archives_pk:
            if r.isNew and not r.file_pk:
                p_s = "{con_path}/{filemd5}.{file_type}"
                # newPath = p_s.format(
                #     con_path=self.archivesPathInDatabase,
                #     filemd5=r.md5FileName,
                #     file_type=r.file_type)
                self.ui.Label_Info.setText("正在复制【{}】".format(r.original_path))
                myCopy(r.original_path, r.md5FilePath)
                self.ui.Label_Info.setText('')
                # 先增加一个文件,后面要用到自动生成的文件PK
                tempsql = ins_file.format(original_name=r.original_name,
                                          filemd5=r.md5FileName,
                                          file_type=r.file_type)
                sqls.append(tempsql)
                tempsql = ins_add.format(archives_pk=cur_pk,
                                         file_pk='({})'.format(
                                             JPDb().LAST_INSERT_ID_SQL()),
                                         file_index=iRow)
                sqls.append(tempsql)

            # 如果没有删除并且是一个已经存在的文件,修改显示顺序
            if r.archives_pk and not r.deleted:
                tempsql = up_index.format(archives_pk=cur_pk,
                                          file_pk=r.file_pk,
                                          file_index=iRow)
                sqls.append(tempsql)

        return sqls