htmlrapor.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. #import MySQLdb as mdb
  4. import pymysql
  5. import sys,time
  6. import decimal
  7. from mysql_ayar import *
  8. class statikrapor:
  9. global baglanti
  10. baglanti=MysqlBaglanti()
  11. col_names=[]
  12. stoklistvt='stoklist.db'
  13. html=""
  14. deger=0
  15. sirano=1
  16. def __init__(self):
  17. #self.html="<META http-equiv=content-type content=text/html;charset=windows-1254>"
  18. self.html=""
  19. self.deger=0.0
  20. self.data = []
  21. def tabloekle(self):
  22. #self.html+="<table border=1>"+"\n"
  23. self.html+="<table id='hareketrapor' border=1 class='tablesorter' ><thead>"+"\n"
  24. def tablobitir(self):
  25. self.html+="</tbody></table>"+"\n"
  26. def satirekle(self,noekle=0):
  27. if noekle==0:
  28. self.html+="<tr align='left'>"+"\n"
  29. else:
  30. self.html+="<tr align='left'><td>"+str(self.sirano)+"</td>"+"\n"
  31. self.sirano+=1
  32. def satirbitir(self):
  33. self.html+="</tr>"+"\n"
  34. def sutunekle(self,string):
  35. if "href" in string or "input" in string:
  36. self.html+="<td><font color='black'>"+string+"</font></td>"+"\n"
  37. else:
  38. self.html+="<td id=pano_kopya@"+string+"><font color='black'>"+string+"</font></td>"+"\n"
  39. def sutunac(self):
  40. self.html+="<td>"+"\n"
  41. def thsutunekle(self,string):
  42. self.html+="<th align='left'><font color=#003366>"+string+"</font></th>"+"\n"
  43. def sutunbitir(self):
  44. self.html+="</td>"+"\n"
  45. def tablo_baslik_bitir(self):
  46. self.html+="</thead><tbody>"+"\n"
  47. def tablobaslik(self,basliklar):
  48. self.satirekle()
  49. for baslik in basliklar:
  50. self.sutunekle(str(baslik))
  51. self.satirbitir()
  52. def linkekle(self,link,linkbas,yukle,sil):
  53. self.sutunekle("<a id=sisLink href="+link+">"+linkbas+"</a><p>")
  54. #17:52 26.10.2014
  55. if yukle!="":
  56. #self.sutunekle("<div id="+"yukle"+"@"+linkbas+" ><img src='static/yukle.jpeg' alt=''></div><p>")
  57. self.sutunekle("<input type='image' src='back16.png' name='"+yukle+"@"+linkbas+"' id='"+yukle+"@"+linkbas+"' value='<--' style='margin-left:5px;margin-right:0px; margin-top:0px;' />")
  58. if sil!="":
  59. #self.sutunekle("<div id="+"sil"+"@"+linkbas+" >sil</div><p>")
  60. self.sutunekle("<input type='image' src='delete16.png' name='"+sil+"@"+linkbas+"' id='"+sil+"@"+linkbas+"' value='X' style='margin-left:5px;margin-right:0px; margin-top:0px;' />")
  61. #16:38 26.10.2014 kapandi
  62. #self.sutunekle("<a href="+link+">"+linkbas+"</a><p>")
  63. #self.divekle("deneme",linkbas)
  64. def sql(self,sqlstr,rapbas="rapor",tabbas=[],alt="sayac",link="",sqlitero=None,colnam=None,yukle="",sil="",topsut=[],noekle=0):
  65. alttoplam=[]#[0,0,0,0,0,0,0,0,0,0,0,0,0]
  66. ekolon_sayi=0
  67. for j in range(0,len(topsut)):
  68. alttoplam.append(0)
  69. if(sqlitero!=None):
  70. rows=sqlitero
  71. self.col_names = colnam
  72. else:
  73. ta=time.clock()
  74. rows =self.calistir(sqlstr)
  75. tm=time.clock()
  76. print "htmlrapor.py sql calisma hizi:",tm-ta
  77. if(rows is None):
  78. return None
  79. #sonuc tablosunun eklenmesi
  80. self.tabloekle()
  81. #rapor baslik eklenmesi
  82. self.satirekle()
  83. if(alt is "bag"):
  84. self.linkekle(link,rapbas)
  85. else:
  86. self.sutunekle(rapbas)
  87. self.satirbitir()
  88. self.tablobaslik(tabbas)
  89. #col_names = [cn[0] for cn in cursor.description]
  90. self.satirekle()
  91. if noekle==1:
  92. self.thsutunekle("no")
  93. for sutoba in self.col_names:
  94. self.thsutunekle(sutoba)
  95. if yukle!="":
  96. self.thsutunekle("yukle")
  97. ekolon_sayi+=1
  98. #self.sutunekle("<input type='submit' name='"+"yukle@"+linkbas+"' id='"+"yukle@"+linkbas+"' value='<--' style='margin-left:20px;margin-right:20px; margin-top:10px;' />")
  99. if sil!="":
  100. self.thsutunekle("sil")
  101. ekolon_sayi+=1
  102. #self.sutunekle("<input type='submit' name='"+"sil@"+linkbas+"' id='"+"sil@"+linkbas+"' value='X' style='margin-left:20px;margin-right:20px; margin-top:10px;' />")
  103. self.satirbitir()
  104. self.tablo_baslik_bitir()
  105. s=0
  106. for rowx in rows:
  107. s+=1
  108. if noekle==1:
  109. self.satirekle(1)
  110. else:
  111. self.satirekle()
  112. for baslik in range(0,len(rowx)):
  113. self.deger=rowx[baslik]
  114. if(self.deger is None):
  115. self.deger=""
  116. if(type(self.deger) in [datetime.date,datetime.datetime,decimal.Decimal,int,float,long]):
  117. if(type(self.deger) is int or type(self.deger) is float or type(self.deger) is decimal.Decimal):
  118. if baslik in topsut:
  119. alttoplam[baslik]+=float(self.deger)
  120. self.deger=str(self.deger)
  121. if(link!="" and self.col_names[baslik] in link):
  122. self.linkekle(link+"="+self.deger,self.deger,yukle,sil)
  123. else:
  124. self.sutunekle(self.deger)
  125. self.satirbitir()
  126. #alttoplam ekleme
  127. self.satirekle()
  128. if noekle==1:
  129. self.sutunekle("-")
  130. for i in range(0,len(self.col_names)+ekolon_sayi):
  131. if i in topsut:
  132. self.sutunekle(str(alttoplam[i]))
  133. else:
  134. self.sutunekle('-')
  135. self.satirbitir()
  136. if(alt is "sayac"):
  137. self.satirekle()
  138. self.sutunekle(str(s)+" kayit")
  139. self.satirbitir()
  140. self.tablobitir()
  141. def getHtml(self):
  142. return self.html
  143. #return "<html><div id='printableArea'>"+self.html+"</div></html>"
  144. def getdosHtml(self,dosya):
  145. self.html=""
  146. with open(dosya) as f:
  147. content = f.readlines()
  148. self.tabloekle()
  149. for row in content:
  150. self.satirekle()
  151. hareket=row.split('@')
  152. for atom in hareket:
  153. self.sutunekle(atom)
  154. self.satirbitir()
  155. self.tablobitir()
  156. return "<html>"+self.html+"</html>"
  157. def getHrkt(self,dosya):
  158. hareketler=[[]]
  159. with open(dosya) as f:
  160. content = f.readlines()
  161. for row in content:
  162. row=row.split('@')
  163. hareketler.append(row)
  164. return hareketler
  165. def getlisteHtml(self,liste):
  166. #self.html=""
  167. self.tabloekle()
  168. for row in liste:
  169. self.satirekle()
  170. #self.sutunekle(row[2])#stkod
  171. self.sutunekle("<a href=http://192.168.1.254:5000/halis/"+row[2]+">"+row[2]+"</a>")
  172. self.sutunekle(row[4])#stkad
  173. self.sutunekle(row[54])#barkod1
  174. self.sutunekle(row[55])#barkod2
  175. self.sutunekle(row[56])#barkod3
  176. self.satirbitir()
  177. self.tablobitir()
  178. #return "<html>"+self.html+"</html>"
  179. return self.html
  180. def getlisteHtml_test(self,liste):
  181. #self.html=""
  182. self.tabloekle()
  183. for row in liste:
  184. self.satirekle()
  185. self.sutunekle(str(row[0]))
  186. self.sutunekle(row[1])
  187. self.sutunekle(row[2])
  188. self.sutunekle(str(row[3]))
  189. self.sutunekle(str(row[4]))
  190. self.sutunekle(str(row[5]))
  191. self.sutunekle(str(row[6]))
  192. self.sutunekle(str(row[7]))
  193. self.sutunekle(str(row[8]))
  194. self.satirbitir()
  195. self.tablobitir()
  196. #return "<html>"+self.html+"</html>"
  197. return self.html
  198. def diziYhtml(self,dizi,dizibas,topsut=[]):
  199. alttoplam=[]
  200. for j in range(0,len(topsut)):
  201. alttoplam.append(0)
  202. self.tabloekle()
  203. #self.tablobaslik(dizibas)
  204. for bas in dizibas:
  205. self.thsutunekle(bas)
  206. self.tablo_baslik_bitir()
  207. for row in dizi:
  208. self.satirekle()
  209. for i in range(0,len(row)):
  210. deger=row[i]
  211. if(type(deger) is int or type(deger) is float or type(deger) is decimal.Decimal):
  212. if i in topsut:
  213. alttoplam[i]+=deger
  214. self.sutunekle(str(deger))
  215. self.satirbitir()
  216. #alttoplam ekleme
  217. self.satirekle()
  218. for i in range(0,len(dizibas)):
  219. if i in topsut:
  220. self.sutunekle(str(alttoplam[i]))
  221. else:
  222. self.sutunekle('-')
  223. self.satirbitir()
  224. self.tablobitir()
  225. return self.html
  226. def calistir(self,sql):
  227. sqlparca=""
  228. con=""
  229. try:
  230. con = pymysql.connect(baglanti.host, baglanti.kullanici,baglanti.sifre,baglanti.vt,charset='latin5')
  231. #con.set_character_set('latin5')
  232. cur = con.cursor()
  233. #print "htmlrapor.py-baglanti acildi"
  234. sql=sql.split(';')
  235. for sqlparca in sql:
  236. cur.execute(sqlparca)
  237. rows = cur.fetchall()
  238. if(rows):
  239. self.col_names = [i[0] for i in cur.description]
  240. #print col_names
  241. rows=list(rows)
  242. if con:
  243. #print "htmlrapor.py-baglanti kapandi-select islemi"
  244. con.close()
  245. return rows
  246. if con:
  247. print "htmlrapor.py-baglanti kapandi-select islemi"
  248. con.close()
  249. #00:23 06.02.2014
  250. except :
  251. print "htmlrapor.py-HATA:",str(sys.exc_info()[1])
  252. if con:
  253. #print "htmlrapor.py-baglanti kapandi-select islemi"
  254. con.close()