-
Notifications
You must be signed in to change notification settings - Fork 0
/
tianshu.py
178 lines (164 loc) · 6.06 KB
/
tianshu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
'''
#=============================================================================
# FileName: tianshu.py
# Desc: 配货天数
# Author: solomon
# Email: [email protected]
# HomePage:
# Version: 0.0.1
# LastChange: 2012-11-16 09:29:19
# History:
#=============================================================================
'''
from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
import confsql
import datetime
from mylog import log
from django.utils import simplejson
from functions import trim_csv,verifyData
confsql=confsql.Confsql()
def save_tianshu(request):
'保存拳头产品'
rs1=[]
result=[]
myjson=simplejson.loads(request.POST["myjson"])
rs1=trim_csv(myjson["table"])
for rs in rs1:
if rs[4]==u'数据库已存在!':
try:
confsql.runSql("delete from tianshu where braid='"+rs[0]+"'")
except:
rs[4]=u'删除失败!'
try:
confsql.runSql("insert into tianshu values('"+rs[0]+"','"+rs[2]+"','"+rs[3]+"','"+datetime.date.today().strftime("%Y-%m-%d")+"')")
rs[4]=u'插入成功!'
except:
rs[4]=u'插入失败!'
res={}
res['braid']=rs[0]
res['braname']=rs[1]
res['anquankucun']=rs[2]
res['peisongzhouqi']=rs[3]
res['info']=rs[4]
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)
def insult_tianshu(request):
'查询拳头商品'
t=get_template('mana1/insult_tianshu.html')
sqlstr='select t1.braid,t2.braname,t1.anquankucun,t1.peisongzhouqi,t1.adddate from tianshu t1 left join branch t2 on t1.braid=t2.braid'
result=confsql.runquery(sqlstr)
html=t.render(Context({'result':result}))
return HttpResponse(html)
def import_tianshu(request):
if request.method=='POST':
value=request.POST['value']
rs1=trim_csv(value,itemlenth=4)
rs2,rs1=verifyData(rs1,length=4,required=[0,2,3])
'重复项覆盖'
temp=[]
if len(rs1)>0:
for rs in rs1:
if confsql.checkExist("select * from tianshu where braid='"+rs[0]+"'")==1: #检查数据库是否已存在
temp.append(rs)
rs.append(u'数据库已存在!')
rs2.append(rs)
if len(temp)>0:
for rs in temp:
rs1.remove(rs)
html=u"<table width='800'><tr><th>门店代码</th><th>门店名称</th><th>安全库存天数</th><th>送货周期天数</th></tr>"
if len(rs2)>0:
for rs in rs2:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td style='background-color:yellow'>" + rs[4] + "</td>"
html+="</tr>"
if len(rs1)>0:
for rs in rs1:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td></td>"
html+="</tr>"
html+="</table>"
return HttpResponse(Context(html))
else:
t=get_template('mana1/import_tianshu.html')
html=t.render(Context())
return HttpResponse(html)
def delete_tianshu(request):
'删除订货规则'
if request.method=='POST':
value=request.POST['value']
rs1=trim_csv(value,itemlenth=4)
rs2,rs1=verifyData(rs1,length=4,required=[0,2,3])
html=u"<table width='800'><tr><th>门店代码</th><th>门店名称</th><th>安全库存天数</th><th>配送周期天数</th></tr>"
if len(rs2)>0:
for rs in rs2:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td style='background-color:yellow'>" + rs[4] + "</td>"
html+="</tr>"
if len(rs1)>0:
for rs in rs1:
html+="<tr>"
html+="<td>" + rs[0] + "</td>"
html+="<td>" + rs[1] + "</td>"
html+="<td>" + rs[2] + "</td>"
html+="<td>" + rs[3] + "</td>"
html+="<td></td>"
html+="</tr>"
html+="</table>"
return HttpResponse(Context(html))
else:
t=get_template('mana1/delete_tianshu.html')
html=t.render(Context())
return HttpResponse(html)
def deleteData_tianshu(request):
'删除数据'
result=[]
myjson=simplejson.loads(request.POST["myjson"])
rs1=trim_csv(myjson["table"],itemlenth=0)
if len(rs1)>0:
for rs in rs1:
if rs[4]<>'': #出错信息的保留
res={}
res['braid']=rs[0]
res['braname']=rs[1]
res['anquankucun']=rs[2]
res['peisongzhouqi']=rs[3]
res['info']=rs[4]
result.append(res)
else:
try:
res={}
sqlstr=u"delete from tianshu where braid='"+rs[0]+"'"
confsql.runSql(sqlstr)
res={}
res['braid']=rs[0]
res['braname']=rs[1]
res['anquankucun']=rs[2]
res['peisongzhouqi']=rs[3]
res['info']=u'删除成功!'
result.append(res)
except:
res={}
res['proid']=rs[0]
res['proname']=rs[1]
res['anquankucun']=rs[2]
res['peisongzhouqi']=rs[3]
res['info']=u'删除失败!'
result.append(res)
jsonres=simplejson.dumps(result)
return HttpResponse(jsonres)