Beispiel #1
0
    def POST(self):
        x = web.input(myfile={})
        filedir = "static/upload"
        if 'myfile' in x:  # to check if the file-object is created
            # replaces the windows-style slashes with linux ones.
            filepath = x.myfile.filename.replace('\\', '/')

            # splits the and chooses the last part (the filename with extension)
            filename = filepath.split('/')[-1]

            # creates the file where the uploaded file should be stored

            fullpath = filedir + '/' + lazy.getYmdhms() + '.xls'
            fout = open(fullpath, 'wb')  #使用 wb 是为了在windows下能正确的上传文件。

            # writes the uploaded file to the newly created file.
            fout.write(x.myfile.file.read())

            # closes the file, upload complete.
            fout.close()
        # 去预览数据,并进行挑选
        print fullpath
        print unicode('/previewPage?filename=')
        print unicode(fullpath)
        raise web.seeother('/previewPage?filename=' + fullpath)
Beispiel #2
0
    def POST(self):
        x = web.input(myfile={})
        filedir = "static/upload"
        if "myfile" in x:  # to check if the file-object is created
            # replaces the windows-style slashes with linux ones.
            filepath = x.myfile.filename.replace("\\", "/")

            # splits the and chooses the last part (the filename with extension)
            filename = filepath.split("/")[-1]

            # creates the file where the uploaded file should be stored

            fullpath = filedir + "/" + lazy.getYmdhms() + ".xls"
            fout = open(fullpath, "wb")  # 使用 wb 是为了在windows下能正确的上传文件。

            # writes the uploaded file to the newly created file.
            fout.write(x.myfile.file.read())

            # closes the file, upload complete.
            fout.close()
        # 去预览数据,并进行挑选
        print fullpath
        print unicode("/previewPage?filename=")
        print unicode(fullpath)
        raise web.seeother("/previewPage?filename=" + fullpath)
Beispiel #3
0
    def POST(self):
        flag = True
        runData = {'runFlag': True, 'showMsg': 'OK'}
        ''' 
        先上传文件,再检查文件,
        包括格式、内容、以及是否和数据库中已有内容冲突, 
        如果不正确,报错,要求重新上传正确文件;
        如果正确,把内容灌入DB。
        灌入数据完成后,将全部机型代码显示在页面上。
        '''

        # 上传文件
        x = web.input(myfile={})
        filedir = "static/upload"
        if 'myfile' in x:
            # replaces the windows-style slashes with linux ones.
            filepath = x.myfile.filename.replace('\\', '/')

            # splits the and chooses the last part (the filename with extension)
            filename = filepath.split('/')[-1]

            # creates the file where the uploaded file should be stored
            fullpath = filedir + '/' + getYmdhms() + '.txt'
            print fullpath
            fout = open(fullpath, 'wb')  #使用 wb 是为了在windows下能正确的上传文件。

            # writes the uploaded file to the newly created file.
            fout.write(x.myfile.file.read())

            fout.close()
        else:
            runData['showMsg'] = '上传文件出错。'
            return render.err(runData)

        # 存放合法数据的列表
        infos = []

        # 检查数据
        phoneInfoFile = open(fullpath, 'r')
        phoneInfoLine = phoneInfoFile.readlines()
        phoneInfoFile.close()
        for i, line in enumerate(phoneInfoLine):
            line = line.strip()
            if len(line) == 0:
                continue  #空行直接跳过
            else:
                info = line.split(None, 1)  # 用第一个空格分成两个部分
                if len(info) < 2:
                    # 格式不对,报错
                    runData['showMsg'] = '文件格式错误。在第 %d 行:%s' % (i, line)
                    return render.err(runData)
                else:
                    infos.append(info)

        con = getConn()
        cur = con.cursor()

        # 检查是否和DB中已有数据冲突。
        for i, info in enumerate(infos):
            strSql = "SELECT * from phone_info WHERE phone_name='%s'" % info[1]
            print strSql
            cur.execute(strSql)
            if cur.fetchone():
                # 机型代码和DB中已有数据冲突,报错
                runData['showMsg'] = '数据错误,机型名称已经存在,在第 %d 条数据: %s %s' % (
                    i + 1, info[0], info[1])
                cur.close()
                con.close()
                return render.err(runData)

        # 内容灌入DB
        for info in infos:
            strSql = "insert into phone_info (phone_no, phone_name) values ('%s','%s') " % (
                info[0], info[1])
            print strSql
            cur.execute(strSql)

        con.commit()

        # 将DB中的全部机型信息取出
        allPhoneInfo = []
        # strSql = "select phone_no, phone_name from phone_info order by phone_no  "
        strSql = "select phone_no, phone_name from phone_info order by rowid DESC  "
        print strSql
        cur.execute(strSql)
        for record in cur:
            phone = dict()
            phone['phone_no'] = record[0]
            phone['phone_name'] = record[1]
            allPhoneInfo.append(phone)

        cur.close()
        con.close()

        runData['AllPhoneInfo'] = allPhoneInfo
        runData['showMsg'] = '增加机型信息成功'

        return render.phoneInfo(runData)
Beispiel #4
0
    def POST(self):
        flag = True
        runData = {"runFlag": True, "showMsg": "OK"}

        req = web.input()

        # 检查必填项是否都有值
        mustName = ["report_type", "filename"]
        for name in mustName:
            if req.has_key(name):
                flag = True
            else:
                flag = False

        if not flag:
            msg = "输入参数不正确,请按照正常流程使用系统。"
            runData["showMsg"] = msg
            return render.err(runData)

        # 取出所有的excel表中的列和数据库中的field的对应关系
        fld_data_col = []
        fld_data_col.append(req["fld_data_col_1"])
        fld_data_col.append(req["fld_data_col_2"])
        fld_data_col.append(req["fld_data_col_3"])
        fld_data_col.append(req["fld_data_col_4"])
        fld_data_col.append(req["fld_data_col_5"])
        fld_data_col.append(req["fld_data_col_6"])
        fld_data_col.append(req["fld_data_col_7"])
        fld_data_col.append(req["fld_data_col_8"])
        fld_data_col.append(req["fld_data_col_9"])
        fld_data_col.append(req["fld_data_col_10"])
        fld_data_col.append(req["fld_data_col_11"])
        fld_data_col.append(req["fld_data_col_12"])
        fld_data_col.append(req["fld_data_col_13"])
        fld_data_col.append(req["fld_data_col_14"])
        print (fld_data_col)
        report_type = req["report_type"]

        # 读出excel文件中的数据,并取出第一个sheet
        filename = req["filename"]
        data = xlsUtil.getExcelData(filename)
        tables = data["tables"]
        table1 = tables[0]
        sheet1 = table1["t_data"]

        strInsertTail = ""
        iCount = 0
        cx = getConn()
        cu = cx.cursor()

        for row in sheet1:
            """ 第一条数据是标题,不需要导入,所以把第 0 条跳过 """
            if iCount > 0:

                strInsertTail = ""
                for strIndex in fld_data_col:
                    if strIndex == u"":
                        strInsertTail = strInsertTail + ",''"
                    else:
                        iIndex = int(strIndex)
                        strText = row[iIndex - 1]
                        strInsertTail = strInsertTail + ",'" + unicode(strText) + "'"

                data_no = getYmdhms() + "_" + str(iCount)
                strInsertHead = (
                    "INSERT INTO temp_data (data_no, data_type, use_flag, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14 ) VALUES  ( '"
                    + data_no
                    + "', '"
                    + report_type
                    + "', '0'"
                )
                strSql = strInsertHead + strInsertTail + ")"
                print strSql
                cu.execute(strSql)
            iCount = iCount + 1
        cx.commit()
        cu.close()
        cx.close()

        # 检查机型名称能否对应到机型代码,如果不能,去机型名称出错页面。
        invalidPhone = findInvalidPhoneName()
        if len(invalidPhone) == 0:
            print "机型名称检查合格。"
        else:
            runData["showMsg"] = "某些机型名称无法找到对应的机型代码,请先检查上传文件是否正确,或者维护好机型信息再进行制单操作。"
            runData["invalidPhone"] = invalidPhone
            return render.phoneNameLost(runData)

        reportType = req["report_type"]

        if reportType == "fld":
            saveFld()
        elif reportType == "sld":
            saveSld()
        elif reportType == "jld":
            saveJld()
        elif reportType == "lyd":
            saveLyd()
        elif reportType == "nbdbd":
            saveNbdbd()
        elif reportType == "rkd":
            saveRkd()
        else:
            msg = "报表类型不正确"
            runData["showMsg"] = msg
            return render.err(runData)

        msg = "导入操作执行成功,共导入数据" + str(iCount) + "条。"
        runData["showMsg"] = msg
        return render.msg(runData)
Beispiel #5
0
    def POST(self):
        flag = True
        runData = {'runFlag':True,'showMsg':'OK'}
        
        req = web.input()

        # 检查必填项是否都有值
        mustName = ['report_type','filename']
        for name in mustName:
            if req.has_key(name) :
                flag = True
            else:
                flag = False

        if not flag :
            msg = "输入参数不正确,请按照正常流程使用系统。"
            runData['showMsg'] = msg
            return render.err(runData)
        
        # 取出所有的excel表中的列和数据库中的field的对应关系
        fld_data_col = []
        fld_data_col.append( req['fld_data_col_1'])
        fld_data_col.append( req['fld_data_col_2'])
        fld_data_col.append( req['fld_data_col_3'])
        fld_data_col.append( req['fld_data_col_4'])
        fld_data_col.append( req['fld_data_col_5'])
        fld_data_col.append( req['fld_data_col_6'])
        fld_data_col.append( req['fld_data_col_7'])
        fld_data_col.append( req['fld_data_col_8'])
        fld_data_col.append( req['fld_data_col_9'])
        fld_data_col.append( req['fld_data_col_10'])
        fld_data_col.append( req['fld_data_col_11'])
        fld_data_col.append( req['fld_data_col_12'])
        fld_data_col.append( req['fld_data_col_13'])
        fld_data_col.append( req['fld_data_col_14'])
        print( fld_data_col )
        report_type =  req["report_type"]

        # 读出excel文件中的数据,并取出第一个sheet
        filename = req["filename"]
        data = xlsUtil.getExcelData(filename)
        tables = data['tables']
        table1 = tables[0]
        sheet1 = table1['t_data']

        strInsertTail = ''
        iCount = 0
        cx = getConn()
        cu = cx.cursor()

        for row in sheet1:
            """ 第一条数据是标题,不需要导入,所以把第 0 条跳过 """
            if iCount > 0 :
                

                strInsertTail = ''
                for strIndex in fld_data_col :
                    if strIndex == u'' :
                        strInsertTail = strInsertTail + ",''"
                    else:
                        iIndex = int(strIndex)
                        strText = row[iIndex-1]
                        strInsertTail = strInsertTail + ",'" + unicode(strText) + "'"
                
                data_no = getYmdhms() + "_" + str(iCount)
                strInsertHead = "INSERT INTO temp_data (data_no, data_type, use_flag, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14 ) VALUES  ( '" + data_no + "', '" + report_type + "', '0'"
                strSql = strInsertHead + strInsertTail + ")"
                print strSql
                cu.execute(strSql)
            iCount = iCount + 1 
        cx.commit()
        cu.close()
        cx.close()

        #检查机型名称能否对应到机型代码,如果不能,去机型名称出错页面。
        invalidPhone = findInvalidPhoneName();
        if len(invalidPhone) == 0 :
            print '机型名称检查合格。'
        else:
            runData['showMsg']='某些机型名称无法找到对应的机型代码,请先检查上传文件是否正确,或者维护好机型信息再进行制单操作。'
            runData['invalidPhone']=invalidPhone
            return render.phoneNameLost(runData)


        reportType =  req["report_type"]

        if reportType == "fld" :
            saveFld()
        elif reportType == "sld" :
            saveSld()
        elif reportType == "jld" :
            saveJld()
        elif reportType == "lyd" :
            saveLyd()
        elif reportType == "nbdbd" :
            saveNbdbd()
        elif reportType == "rkd" :
            saveRkd()
        else :
            msg = "报表类型不正确"
            runData['showMsg'] = msg
            return render.err(runData)

        msg = "导入操作执行成功,共导入数据" + str(iCount) + "条。"
        runData['showMsg'] = msg
        return render.msg(runData)
Beispiel #6
0
    def POST(self):
        flag = True
        runData = {'runFlag':True,'showMsg':'OK'}

        ''' 
        先上传文件,再检查文件,
        包括格式、内容、以及是否和数据库中已有内容冲突, 
        如果不正确,报错,要求重新上传正确文件;
        如果正确,把内容灌入DB。
        灌入数据完成后,将全部机型代码显示在页面上。
        '''
        
        # 上传文件
        x = web.input(myfile={})
        filedir = "static/upload"
        if 'myfile' in x: 
            # replaces the windows-style slashes with linux ones.
            filepath=x.myfile.filename.replace('\\','/')

            # splits the and chooses the last part (the filename with extension)
            filename=filepath.split('/')[-1] 
            
            # creates the file where the uploaded file should be stored
            fullpath = filedir +'/'+ getYmdhms() + '.txt'
            print fullpath
            fout = open( fullpath,'wb') #使用 wb 是为了在windows下能正确的上传文件。
            
            # writes the uploaded file to the newly created file.
            fout.write(x.myfile.file.read())            

            fout.close()
        else:
            runData['showMsg'] = '上传文件出错。'
            return render.err(runData)
        
        # 存放合法数据的列表
        infos = [ ]

        # 检查数据
        phoneInfoFile = open( fullpath, 'r' )
        phoneInfoLine = phoneInfoFile.readlines();
        phoneInfoFile.close()
        for i,line in enumerate(phoneInfoLine):
            line = line.strip()
            if len(line)==0 :
                continue         #空行直接跳过
            else :
                info = line.split(None,1) # 用第一个空格分成两个部分
                if len(info) < 2 :
                    # 格式不对,报错
                    runData['showMsg'] = '文件格式错误。在第 %d 行:%s' %  (i,line)
                    return render.err(runData)
                else:
                    infos.append(info)
        
        con = getConn()
        cur = con.cursor()


        # 检查是否和DB中已有数据冲突。
        for i,info in enumerate(infos):
            strSql = "SELECT * from phone_info WHERE phone_name='%s'" % info[1] 
            print strSql
            cur.execute(strSql)
            if cur.fetchone() :
                # 机型代码和DB中已有数据冲突,报错
                runData['showMsg'] = '数据错误,机型名称已经存在,在第 %d 条数据: %s %s' %  ( i+1,info[0],info[1])
                cur.close()
                con.close()
                return render.err(runData)

        # 内容灌入DB
        for info in infos:
            strSql = "insert into phone_info (phone_no, phone_name) values ('%s','%s') " % (info[0],info[1])
            print strSql
            cur.execute(strSql)

        con.commit()

        # 将DB中的全部机型信息取出
        allPhoneInfo = []
        # strSql = "select phone_no, phone_name from phone_info order by phone_no  " 
        strSql = "select phone_no, phone_name from phone_info order by rowid DESC  " 
        print strSql
        cur.execute(strSql)
        for record in cur:
            phone = dict()
            phone['phone_no'] = record[0]
            phone['phone_name'] = record[1]
            allPhoneInfo.append(phone)


        cur.close()
        con.close()

         
        runData['AllPhoneInfo'] = allPhoneInfo
        runData['showMsg'] = '增加机型信息成功'

        return render.phoneInfo(runData)