/
py_foroosh.py
185 lines (140 loc) · 4.39 KB
/
py_foroosh.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
177
178
179
180
181
182
183
184
185
#!d:/Python27/python.exe -u
# -*- coding: UTF-8 -*-
import MySQLdb
import cgi
import sys
import cgitb
import py_convert_cgi_form_to_array_with_mapping
import py_db
import Cookie
from datetime import *
import os
from pyDes import *
cgitb.enable();
def get_company_names():
rows = py_db.executeAndReturnRows("SELECT `scn_name` FROM `tbl_sale_company_names` ORDER BY SCN_NAME DESC");
s=''
for row in rows:
s=s+'jotl'+row.__str__()
print "Content-Type: text/html"
print
print s
def chk_n(str): #check null
if str=='':
return null
else:
return str
def do_insert(_param):
print "Content-Type: text/html"
print
sqlstr=''
main_rows = _param.split("[[[a")
data_field = main_rows[0].split("91A1")
sqlstr="'{0}','{1}','{2}','{3}'".format(chk_n(data_field[0]),chk_n(data_field[1]),chk_n(data_field[2]),chk_n(data_field[3]))
fs = """
INSERT INTO `automation`.`tbl_sale_kharidha`
(`sk_link_to_company`,
`sk_namayande_sherkat`,
`sk_link_faaliat`,
`sk_tel_no`)
VALUES (
{0});
""" .format(sqlstr)
py_db.executesql(fs)
new_id = py_db.executeAndReturnRows("select sk_id from tbl_sale_kharidha order by sk_id desc limit 1")[0][0].__str__()
sqlstr_details = ' DELIMITER ; ';
if main_rows[1]=='':
print "no_item"
return
for row in main_rows[1].split("al12c"):
row_arr = row.split(",")
py_db.executesql("""
insert into `automation`.`tbl_sale_kharidha_details`
(
`skd_link_to_kharid_ha`,
`skd_zekhamate_varagh`,
`skd_arz`,
`skd_tool`,
`skd_mizan`,
`skd_zekhamte_ghal`,
`skd_shekle_varagh`,
skd_date_kharid)
values (
'{0}',
'{1}',
'{2}',
'{3}',
'{4}',
'{5}',
'{6}',
'{7}');
""".format(new_id,
chk_n(row_arr[0]),
chk_n(row_arr[1]),
chk_n(row_arr[2]),
chk_n(row_arr[3]),
chk_n(row_arr[4]),
chk_n(row_arr[5]),
chk_n(row_arr[6])))
#al12c
print "ok"
def create_excel():
from tempfile import TemporaryFile
from xlwt import Workbook
from xlwt import *
book = Workbook()
sheet1 = book.add_sheet('Sheet 1')
book.add_sheet('Sheet 2')
sheet1.write(0,0,'نام شرکت')
sheet1.write(0,1,'تاریخ خرید')
sheet1.write(0,2,'ضخامت')
sheet1.write(0,3,'عرض')
sheet1.write(0,4,'طول')
sheet1.write(0,5,'میزان کیلوگرم')
sheet1.write(0,6,'ضخامت قلع')
sheet1.write(0,7,'شکل ورق')
rows = py_db.executeAndReturnRows("""
SELECT
(SELECT `sk_link_to_company` FROM `tbl_sale_kharidha` WHERE `sk_id`=`skd_link_to_kharid_ha`) AS kha,
`skd_date_kharid`,
`skd_zekhamate_varagh`,
`skd_arz`,
`skd_tool`,
`skd_mizan`,
`skd_zekhamte_ghal`,
`skd_shekle_varagh`
FROM `tbl_sale_kharidha_details`
ORDER BY kha, skd_date_kharid
""")
i=1
for row in rows:
row1 = sheet1.row(i)
row1.write(0,row[0].__str__())
row1.write(1,row[1].__str__())
row1.write(2,Formula("VALUE("+row[2].__str__()+")"))
row1.write(3,Formula("VALUE("+row[3].__str__()+")"))
row1.write(4,Formula("VALUE("+row[4].__str__()+")"))
row1.write(5,Formula("VALUE("+row[5].__str__()+")"))
row1.write(6,Formula("VALUE("+row[6].__str__()+")"))
row1.write(7,Formula("VALUE("+row[7].__str__()+")"))
i+=1
sheet1.col(0).width = 10000
sheet2 = book.get_sheet(1)
sheet2.row(0).write(0,'Sheet 2 A1')
sheet2.row(0).write(1,'Sheet 2 B1')
sheet2.flush_row_data()
sheet2.write(1,0,'Sheet 2 A3')
sheet2.col(0).width = 5000
sheet2.col(0).hidden = True
book.save('simple.xls')
book.save(TemporaryFile())
print "Content-Type: text/html"
print
print "ok"
form = cgi.FieldStorage()
param = form.getvalue("get_co_names","-1")
param2= form.getvalue("req_str","-1")
param3= form.getvalue("req_getfile","-1")
if param != "-1" : get_company_names()
if param2 != "-1" : do_insert(param2)
if param3 != "-1" : create_excel()