def on_dev_print(self): cache = './cache' html = unicode("设备区域:%s<br>\n%s<br>%s") area = session.match(session.areas, "ID", "INT", int(self.id), "NAME") table = "<table width='100%' border=1 align='center' cellpadding=0 cellspacing=0>\n" table += "<tr><td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n </tr>" % ( unicode('设备名称'), unicode('设备电话'), unicode('站点号'), unicode('设备类型'), unicode('放置地点')) list = [] for i in session.user.repeaters: if i['AREA_ID'] == self.id: #主设备 product = session.match(session.products, "ID", "INT", i['PRODUCT_ID'], "DESCRIPT") table += "\n<tr><td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n </tr>" % ( i['NAME'], i['REPEATER_PHONE'], i['REPEATER_ID'], product, i['SITE']) table += "</table>" timetag = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime()) html = html % (area, table, unicode('打印时间:') + timetag) tempreport = "%s/%s.htm" % (cache, str(time.clock())) fh = open(tempreport, 'w') fh.write(html) fh.close() #显示报表输出 webbrowser.open(tempreport)
def show(self,devid): ''' 显示指定的设备信息,只显示主设备信息 ''' sql ="select * from repeaterinfo where id =%s"%devid devs = session.getdata(sql) if len(devs)==0: return self.devinfo = devs[0] self.devname.setentry(self.devinfo['NAME'].strip()) #self.devno.setentry(self.devinfo['REPEATER_ID']) self.manufaturer.configure(value=session.match(session.providers,'ID','INT',self.devinfo['PROVIDER_ID'],'NAME')) #显示指定厂商的产品型号 self.devtype.slistbox.listbox.delete(0,'end') for i in session.products: if self.devinfo['PROVIDER_ID']==i["PROVIDER"]: self.devtype.append_history(i['DESCRIPT']) if self.devinfo['PRODUCT_ID']==i['ID']: self.devtype.configure(value= i['DESCRIPT']) #self.subdevno.setentry( self.devinfo['EQUIPMENT_ID'] ) self.area.configure(value=session.match(session.areas,'ID','INT',self.devinfo['AREA_ID'],'NAME')) self.site.setentry(self.devinfo['SITE']) time = self.devinfo['RUN_DATE'] time = time.Format('%Y/%m/%d') self.runtime.setentry(time) #self.commtype.config(value = constdef.COMM_MODE_BY_ID[str(self.devinfo['COMM_MODE'])] ) self.devphone.setentry(self.devinfo['REPEATER_PHONE'].strip()) #self.queryphone.setentry(self.devinfo['QUERY_PHONE'].strip()) #self.alertphone.setentry(self.devinfo['ALARM_PHONE'].strip()) self.query_interval.setentry(self.devinfo['QUERY_INTERVAL'] ) pass
def on_provider_sel(self, item): self.product.slistbox.listbox.delete(0, 'end') providerid = session.match(session.providers, 'NAME', 'STRING', self.provider.cget('value').strip(), 'ID') for i in session.products: if i['PROVIDER'] == providerid: self.product.append_history(i['DESCRIPT'].strip())
def onselprovider(self, val): providerid = session.match(session.providers, 'NAME', 'STRING', self.manufaturer.cget('value').strip(), 'ID') self.devtype.slistbox.listbox.delete(0, 'end') for i in session.products: if i['PROVIDER'] == providerid: self.devtype.append_history(i['DESCRIPT'].strip())
def on_product_sel(self,item): self.subtype.slistbox.listbox.delete(0,'end') productid= session.match(session.products,'DESCRIPT','STRING',self.product.cget('value').strip(),'ID') for i in session.repeatertype: if i['PRODUCT_ID']==productid: desc = constdef.dev_cat[str(i['DEVCAT'])] self.subtype.append_history(desc)
def on_product_sel(self, item): self.subtype.slistbox.listbox.delete(0, 'end') productid = session.match(session.products, 'DESCRIPT', 'STRING', self.product.cget('value').strip(), 'ID') for i in session.repeatertype: if i['PRODUCT_ID'] == productid: desc = constdef.dev_cat[str(i['DEVCAT'])] self.subtype.append_history(desc)
def on_dev_print(self): cache ='./cache' html =unicode("设备区域:%s<br>\n%s<br>%s") area = session.match(session.areas,"ID","INT",int(self.id),"NAME") table ="<table width='100%' border=1 align='center' cellpadding=0 cellspacing=0>\n" table+="<tr><td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n </tr>" %(unicode('设备名称'),unicode('设备电话'),unicode('站点号'),unicode('设备类型'),unicode('放置地点')) list =[] for i in session.user.repeaters: if i['AREA_ID']==self.id: #主设备 product = session.match(session.products,"ID","INT",i['PRODUCT_ID'],"DESCRIPT") table+="\n<tr><td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n<td>%s</td>\n </tr>"%(i['NAME'],i['REPEATER_PHONE'],i['REPEATER_ID'],product,i['SITE']) table+="</table>" timetag = time.strftime("%Y-%m-%d %H:%M:%S ",time.localtime()) html = html%(area,table,unicode('打印时间:')+timetag) tempreport = "%s/%s.htm"%(cache,str(time.clock())) fh = open(tempreport,'w') fh.write(html) fh.close() #显示报表输出 webbrowser.open(tempreport)
def show(self, devid): ''' 显示指定的设备信息,只显示主设备信息 ''' sql = "select * from repeaterinfo where id =%s" % devid devs = session.getdata(sql) if len(devs) == 0: return self.devinfo = devs[0] self.devname.setentry(self.devinfo['NAME'].strip()) #self.devno.setentry(self.devinfo['REPEATER_ID']) self.manufaturer.configure( value=session.match(session.providers, 'ID', 'INT', self.devinfo['PROVIDER_ID'], 'NAME')) #显示指定厂商的产品型号 self.devtype.slistbox.listbox.delete(0, 'end') for i in session.products: if self.devinfo['PROVIDER_ID'] == i["PROVIDER"]: self.devtype.append_history(i['DESCRIPT']) if self.devinfo['PRODUCT_ID'] == i['ID']: self.devtype.configure(value=i['DESCRIPT']) #self.subdevno.setentry( self.devinfo['EQUIPMENT_ID'] ) self.area.configure(value=session.match( session.areas, 'ID', 'INT', self.devinfo['AREA_ID'], 'NAME')) self.site.setentry(self.devinfo['SITE']) time = self.devinfo['RUN_DATE'] time = time.Format('%Y/%m/%d') self.runtime.setentry(time) #self.commtype.config(value = constdef.COMM_MODE_BY_ID[str(self.devinfo['COMM_MODE'])] ) self.devphone.setentry(self.devinfo['REPEATER_PHONE'].strip()) #self.queryphone.setentry(self.devinfo['QUERY_PHONE'].strip()) #self.alertphone.setentry(self.devinfo['ALARM_PHONE'].strip()) self.query_interval.setentry(self.devinfo['QUERY_INTERVAL']) pass
def onsave(self): name = self.enArea.getvalue().strip() if name == '': tkMessageBox.showwarning(unicode('警告!'), unicode('名称无效!')) return if self.status == 'new': id = session.match(session.areas, 'NAME', 'STRING', name, 'ID') if id: tkMessageBox.showwarning(unicode('警告!'), unicode('区域名称已经存在!')) return sql = "insert into area (id,name) values(?,?)" data = [] data.append(['id', ado.INT, session.getsequence()]) data.append(['name', ado.STRING, name]) try: session.dbcnn.Execute(sql, data) tkMessageBox.showwarning(unicode(''), unicode('区域添加成功!')) except: tkMessageBox.showwarning(unicode('警告!'), unicode('操作失败,无法添加区域!')) return else: sql = "update area set name=:name where id=%s" % self.id data = [] data.append(['name', name]) try: session.dbcnn.Execute2(sql, data) tkMessageBox.showwarning(unicode(''), unicode('区域修改成功!')) except: tkMessageBox.showwarning(unicode('警告!'), unicode('修改失败!')) return sql = "select * from area" session.areas = session.getdata(sql) session.user.load_area_rights() self.master.reload_area() #刷新区域信息列表 self.destroy()
def onsave(self): name = self.enArea.getvalue().strip() if name=='': tkMessageBox.showwarning(unicode('警告!'),unicode('名称无效!')) return if self.status=='new': id =session.match(session.areas,'NAME','STRING',name,'ID') if id : tkMessageBox.showwarning(unicode('警告!'),unicode('区域名称已经存在!')) return sql = "insert into area (id,name) values(?,?)" data =[] data.append(['id',ado.INT,session.getsequence()]) data.append(['name',ado.STRING,name]) try: session.dbcnn.Execute(sql,data) tkMessageBox.showwarning(unicode(''),unicode('区域添加成功!')) except: tkMessageBox.showwarning(unicode('警告!'),unicode('操作失败,无法添加区域!')) return else: sql = "update area set name=:name where id=%s"%self.id data=[] data.append(['name',name]) try: session.dbcnn.Execute2(sql,data) tkMessageBox.showwarning(unicode(''),unicode('区域修改成功!')) except: tkMessageBox.showwarning(unicode('警告!'),unicode('修改失败!')) return sql = "select * from area" session.areas = session.getdata(sql) session.user.load_area_rights() self.master.reload_area() #刷新区域信息列表 self.destroy()
def onselprovider(self,val): providerid = session.match(session.providers,'NAME','STRING',self.manufaturer.cget('value').strip(),'ID') self.devtype.slistbox.listbox.delete(0,'end') for i in session.products: if i['PROVIDER']==providerid: self.devtype.append_history(i['DESCRIPT'].strip())
def doquery(self): case1= self.cb_opttype1.cget('value').strip() case2 = self.cb_opttype2.cget('value').strip() time1 = re.findall('\s*(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)', self.time1.getvalue()) time2 = re.findall('\s*(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)', self.time2.getvalue()) if len(time1)==0: time1 = re.findall('\s*(\d+)-(\d+)-(\d+)\s*', self.time1.getvalue()) if len(time1)==0: tkMessageBox.showwarning(unicode('警告!'),unicode('查询起始时间无效!')) return if len(time2)==0: time2 = re.findall('\s*(\d+)-(\d+)-(\d+)\s*', self.time1.getvalue()) if len(time2)==0: tkMessageBox.showwarning(unicode('警告!'),unicode('查询结束时间无效!')) return time1= self.gen_time_str(time1[0]) time2= self.gen_time_str(time2[0]) print time1 print time2 if case1=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请选择查询大类!')) return if case2=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请选择查询次类!')) return if case1 ==unicode("设备"): dev = self.cb_repeaters.cget('value').strip() #subdev = self.cb_subdev.cget('value').strip() if dev=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请选择设备!')) return devids=[] if dev!=unicode('所有设备'): masterid = session.match(session.user.repeaters,"NAME","STRING",dev,"ID") if masterid==None: tkMessageBox.showwarning(unicode('警告!'),unicode('设备无法匹配!')) return #if subdev=='': # tkMessageBox.showwarning(unicode('警告!'),unicode('请选择子设备!')) # return #if subdev==unicode('所有子设备'): # devids=[] # devids.append(masterid) #主设备 # for i in session.user.repeaters: # if i['PARENT_ID']==masterid: # devids.append(i['ID']) #else: # devids=[] # devtype = constdef.dev_cat2[subdev] # if devtype==1 or devtype==3 or devtype==4 or devtype==5 or devtype==7: # devids.append(masterid) #主设备 # else: # for i in session.user.repeaters: # if i['PARENT_ID']==masterid: # devids.append(i['ID']) devids.append(masterid) else:#==unicode('所有设备'): devids=[] for i in session.user.repeaters: devids.append(i['ID']) ######################################################## searchkey='' if case2==unicode('状态'): searchkey='repeater_id' ls=[] for i in devids: ls.append(searchkey+"=%s"%i) where1 = string.join(ls," or ") where1="("+where1+")" sql = "select * from status where "+where1 sql+=" and opttime between '%s' and '%s'"%(time1,time2) sql+=" order by opttime desc" self.showdetail(sql,'status') self.export_title="设备状态" if case2==unicode('告警'): searchkey='repeater_id' ls=[] for i in devids: ls.append(searchkey+"=%s"%i) where1 = string.join(ls," or ") where1="("+where1+")" sql = "select * from status where "+where1 sql+=" and opttime between '%s' and '%s'"%(time1,time2) sql+=" and warninglevel<>0 " sql+=" order by opttime desc" self.showdetail(sql,'warning') self.export_title="设备告警" if case2==unicode('控制'): searchkey='repeater_id' ls=[] for i in devids: ls.append(searchkey+"=%s"%i) where1 = string.join(ls," or ") where1="("+where1+")" sql = "select a.*,b.transactionstatus,b.settime,b.result from control a,transactionstatus b where "+where1 sql+=" and opttime between '%s' and '%s'"%(time1,time2) sql+=" and a.transactionno= b.transactionno " sql+=" order by opttime desc" self.showdetail(sql,'control') self.export_title="设备控制" pass elif case1 ==unicode("管理员"): user = self.cb_users.cget('value') if user=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请选择管理员!')) return loginname = session.match(session.users,"REAL_NAME","STRING",user,"LOGIN_NAME") sql = '' if case2==unicode('系统登录'): sql = "select * from logininfo where " if loginname!=None: sql +=" username='******' and "%loginname sql+=" logintime between '%s' and '%s'"%(time1,time2) sql+=" order by logintime desc" self.showdetail(sql,'login') self.export_title="系统登录" if case2==unicode('管理操作'): sql = "select a.*,b.descript,c.real_name,d.result from operateinfo a,action_type b,userinfo c ,transactionstatus d " sql+=" where a.actionid = b.actionid and a.operator=c.login_name and a.transactionno =d.transactionno" if loginname!=None: sql +=" and operator='%s' and "%loginname sql+=" and opttime between '%s' and '%s'"%(time1,time2) sql+=" order by opttime desc" self.showdetail(sql,'usermgr') self.export_title="管理员操作 " pass
def on_provider_sel(self,item): self.product.slistbox.listbox.delete(0,'end') providerid = session.match(session.providers,'NAME','STRING',self.provider.cget('value').strip(),'ID') for i in session.products: if i['PROVIDER']==providerid: self.product.append_history(i['DESCRIPT'].strip())
def onsave(self): '''数据储存''' save_to_close = 1 sql = '' data = [] id = 0 if self.devinfo != None: if self.check('UPDATE') == 0: return else: # do update sql = """ update repeaterinfo set NAME=:NAME, REPEATERTYPE=:REPEATERTYPE, AREA_ID=:AREA_ID, RUN_DATE=:RUN_DATE, REPEATER_PHONE=:REPEATER_PHONE, PRODUCT_ID=:PRODUCT_ID, PROVIDER_ID=:PROVIDER_ID, QUERY_INTERVAL=:QUERY_INTERVAL, SITE=:SITE where id=%s """ % self.devinfo['ID'] else: if self.check('INSERT') == 0: return else: sql = """ insert into repeaterinfo (ID,NAME,REPEATERTYPE,AREA_ID, RUN_DATE,REPEATER_PHONE, PRODUCT_ID,PROVIDER_ID, QUERY_INTERVAL,SITE) values(:ID,:NAME,:REPEATERTYPE,:AREA_ID, :RUN_DATE,:REPEATER_PHONE, :PRODUCT_ID,:PROVIDER_ID, :QUERY_INTERVAL,:SITE) """ id = session.getsequence() data.append(['ID', id]) data.append(['NAME', self.devname.getvalue().strip()]) providerid = session.match(session.providers, 'NAME', 'STRING', self.manufaturer.cget('value').strip(), 'ID') productid = session.match(session.products, 'DESCRIPT', 'STRING', self.devtype.cget('value').strip(), 'ID') repeatertype = 0 devcat = 0 subdevno = 0 #设备编号 for i in session.repeatertype: #查找设备类别 if providerid == i['PROVIDER'] and productid == i['PRODUCT_ID']: repeatertype = i['TYPE_ID'] devcat = 8 data.append(['REPEATERTYPE', int(repeatertype)]) area_id = session.match(session.areas, 'NAME', 'STRING', self.area.cget('value').strip(), 'ID') data.append(['AREA_ID', int(area_id)]) data.append(['RUN_DATE', self.runtime.getvalue()]) data.append(['REPEATER_PHONE', self.devphone.getvalue()]) data.append(['PRODUCT_ID', productid]) data.append(['PROVIDER_ID', providerid]) data.append(['QUERY_INTERVAL', int(self.query_interval.getvalue())]) data.append(['SITE', self.site.getvalue()]) #print data try: session.dbcnn.Execute2(sql, data) except: tkMessageBox.showwarning(unicode('警告'), unicode('数据操作失败 !')) return if self.devinfo != None: id = int(self.devinfo['ID']) #更新当前记录 sql = "select * from repeaterinfo where id =%s" % id devs = session.getdata(sql) self.devinfo = devs[0] #更新设备缓存信息 session.user.load_repeaters() # send updatelist package to mss str = "0,1,2,3,%s,4,5,6,7,8" % constdef.cmd_list["UPDATE_DEV_LIST"] if net_train.send2mss(str) == 0: tkMessageBox.showwarning(unicode('设备更新'), unicode('通知MSS失败!')) return #窗口关闭 self.destroy()
def on_subtype_sel(self, item): for i in self.list: i[1].destroy() i[2].destroy() self.list = [] devcat_id = constdef.dev_cat2[self.subtype.cget('value').strip()] productid = session.match(session.products, 'DESCRIPT', 'STRING', self.product.cget('value').strip(), 'ID') productid = int(productid) #4种设备命令参数都一样,不用区分 self.devtype = session.match(session.repeatertype, 'PRODUCT_ID', 'INT', productid, 'TYPE_ID') sql = "select * from warninglevel where repeatertype=%s" % self.devtype rs = session.getdata(sql) wl0 = 0 wl1 = 0 wl2 = 0 wl3 = 0 if len(rs) == 0: wl0 = 0 wl1 = 0 wl2 = 0 wl3 = 0 else: wl1 = rs[0]['NORMAL'] wl2 = rs[0]['SLIGHT'] wl3 = rs[0]['SEVERE'] wl1 = long(wl1) wl2 = long(wl2) wl3 = long(wl3) sql = "select * from param_config where repeatertype=%s and is_warning=1 order by paramname" % self.devtype rs = session.getdata(sql) if len(rs) == 0: return for i in range(len(rs)): lb = Label(self.fcontext, text=rs[i]['DESCRIPT']) lb.grid(column=0, row=i, sticky='w') cb = ComboBox(self.fcontext) cb.grid(column=1, row=i, sticky='w') cb.append_history(unicode('屏蔽')) cb.append_history(unicode('一般')) cb.append_history(unicode('重要')) cb.append_history(unicode('严重')) pick_item = 0 idx = rs[i]['ORD'] idx = int(idx) - 1 print wl1, rs[i]['ORD'] print type(wl1), type(idx) if wl1 & (1 << idx): pick_item = 1 elif wl2 & (1 << idx): pick_item = 2 elif wl3 & (1 << idx): pick_item = 3 cb.pick(pick_item) self.list.append([rs[i]['PARAMNAME'], lb, cb])
def onsave(self): '''数据储存''' save_to_close=1 sql ='' data=[] id =0 if self.devinfo!=None: if self.check('UPDATE')==0: return else: # do update sql = """ update repeaterinfo set NAME=:NAME, REPEATERTYPE=:REPEATERTYPE, AREA_ID=:AREA_ID, RUN_DATE=:RUN_DATE, REPEATER_PHONE=:REPEATER_PHONE, PRODUCT_ID=:PRODUCT_ID, PROVIDER_ID=:PROVIDER_ID, QUERY_INTERVAL=:QUERY_INTERVAL, SITE=:SITE where id=%s """%self.devinfo['ID'] else: if self.check('INSERT')==0: return else: sql =""" insert into repeaterinfo (ID,NAME,REPEATERTYPE,AREA_ID, RUN_DATE,REPEATER_PHONE, PRODUCT_ID,PROVIDER_ID, QUERY_INTERVAL,SITE) values(:ID,:NAME,:REPEATERTYPE,:AREA_ID, :RUN_DATE,:REPEATER_PHONE, :PRODUCT_ID,:PROVIDER_ID, :QUERY_INTERVAL,:SITE) """ id = session.getsequence() data.append(['ID',id]) data.append(['NAME',self.devname.getvalue().strip()]) providerid = session.match(session.providers,'NAME','STRING',self.manufaturer.cget('value').strip(),'ID') productid = session.match(session.products,'DESCRIPT','STRING',self.devtype.cget('value').strip(),'ID') repeatertype = 0 devcat =0 subdevno =0 #设备编号 for i in session.repeatertype:#查找设备类别 if providerid==i['PROVIDER'] and productid==i['PRODUCT_ID']: repeatertype=i['TYPE_ID'] devcat =8 data.append(['REPEATERTYPE',int(repeatertype)]) area_id = session.match(session.areas,'NAME','STRING',self.area.cget('value').strip(),'ID') data.append(['AREA_ID',int(area_id)]) data.append(['RUN_DATE',self.runtime.getvalue()]) data.append(['REPEATER_PHONE',self.devphone.getvalue()]) data.append(['PRODUCT_ID',productid]) data.append(['PROVIDER_ID',providerid]) data.append(['QUERY_INTERVAL',int(self.query_interval.getvalue())]) data.append(['SITE',self.site.getvalue()]) #print data try: session.dbcnn.Execute2(sql,data) except: tkMessageBox.showwarning(unicode('警告'),unicode('数据操作失败 !')) return if self.devinfo!=None: id = int(self.devinfo['ID']) #更新当前记录 sql ="select * from repeaterinfo where id =%s"%id devs = session.getdata(sql) self.devinfo = devs[0] #更新设备缓存信息 session.user.load_repeaters() # send updatelist package to mss str ="0,1,2,3,%s,4,5,6,7,8"%constdef.cmd_list["UPDATE_DEV_LIST"] if net_train.send2mss(str)==0: tkMessageBox.showwarning(unicode('设备更新'),unicode('通知MSS失败!')) return #窗口关闭 self.destroy()
def on_subtype_sel(self,item): for i in self.list: i[1].destroy() i[2].destroy() self.list=[] devcat_id = constdef.dev_cat2[self.subtype.cget('value').strip()] productid= session.match(session.products,'DESCRIPT','STRING',self.product.cget('value').strip(),'ID') productid = int(productid) #4种设备命令参数都一样,不用区分 self.devtype= session.match(session.repeatertype,'PRODUCT_ID','INT',productid,'TYPE_ID') sql = "select * from warninglevel where repeatertype=%s"%self.devtype rs = session.getdata(sql) wl0 = 0 wl1 = 0 wl2 = 0 wl3 = 0 if len(rs)==0: wl0 = 0 wl1 = 0 wl2 = 0 wl3 = 0 else: wl1 = rs[0]['NORMAL'] wl2 = rs[0]['SLIGHT'] wl3 = rs[0]['SEVERE'] wl1 = long(wl1) wl2 = long(wl2) wl3 = long(wl3) sql = "select * from param_config where repeatertype=%s and is_warning=1 order by paramname"%self.devtype rs = session.getdata(sql) if len(rs)==0: return for i in range(len(rs)): lb = Label(self.fcontext,text=rs[i]['DESCRIPT']) lb.grid(column=0,row=i,sticky='w') cb = ComboBox(self.fcontext) cb.grid(column=1,row=i,sticky='w') cb.append_history(unicode('屏蔽')) cb.append_history(unicode('一般')) cb.append_history(unicode('重要')) cb.append_history(unicode('严重')) pick_item = 0 idx = rs[i]['ORD'] idx = int(idx)-1 print wl1,rs[i]['ORD'] print type(wl1),type(idx) if wl1&(1<<idx): pick_item=1 elif wl2 & (1<<idx): pick_item=2 elif wl3 & (1<<idx): pick_item=3 cb.pick(pick_item) self.list.append([ rs[i]['PARAMNAME'],lb,cb])