37,719
社区成员
发帖
与我相关
我的任务
分享
def hz_channelorder():
showbill_hz.delete(1.0,"end")
#正式库
conn=pyodbc.connect(r'DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=KFT;UID=test;PWD=test##')
#测试库
#conn=pyodbc.connect(r'DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=KFT_TEST;UID=md;PWD=123')
cur=conn.cursor()
#获取输入值
cd=str(t_hz.get("1.0","end"))
cd=cd.strip()
if (cd==''):
mes.showerror("贴心小提示","未输入单号")
else:
billnos=re.findall(r'\w{2}\d{6}-\d{4}',cd)
#print(billno)
for billno in billnos:
type=billno[0:2]
if (type=='KH'):
select_sql="select billstate from kft_applynew where billno='%s'"%(str(billno))
elif (type=='WX'):
select_sql="select billstate from kft_repair where billno='%s'"%(str(billno))
else:
select_sql="select billstate from kft_exchange where billno='%s'"%(str(billno))
#print(select_sql)
cur.execute(select_sql)
test=cur.fetchone()
if (test is None):
info="%s单据在系统未找到,请检查单据是否输入错误"%(str(billno))
hz_print_info(info)
save_log(info)
else:
billstate=str(test[0])
#if (billstate=='150' or billstate=='330' or billstate=='430' or billstate=='130'):
if (billstate in ('150','130','330','430','-100','140','-300','-400')):
#可能会中断循环操作
#mes.showerror("拒绝操作","%s单据是已完成或已撤单状态,无法撤单"%(str(billno)))
info="%s单据是已完成或已撤单状态,无法撤单"%(str(billno))
hz_print_info(info)
save_log(info)
else:
update_sql="exec cd '%s'"%(str(billno))
#print(update_sql)
cur.execute(update_sql)
conn.commit()
info="%s单据已撤单"%(str(billno))
hz_print_info(info)
save_log(info)
cur.close()
conn.close()
这段代码有没有问题。最后执行的update_sql是个存储过程,代码如下:CREATE procedure cd(@billno varchar(50))
as
begin
declare @type varchar(20),@table varchar(50),@sql nvarchar(max),@billstate varchar(50)
set @type=left(@billno,2)
if @type='TJ' or @type='HJ' or @type='YJ' or @type='TH'
begin
set @table='kft_exchange'
set @billstate='-400'
end
else if @type='WX'
begin
set @table='kft_repair'
set @billstate='-300'
end
else if @type='KH'
begin
set @table='kft_applynew'
set @billstate='-100'
update KFT_AccountCards set IsOpen=0,OpenDate=null where CardCode in (select CardCode from kft_applynew where BillNo=@billno)
end
else
begin
print 'error:单号输入错误'
end
set @sql='update '+@table+' set billstate='+@billstate+' where billno='''+@billno+''''
exec sp_executesql @sql
end