def recLog(target, action_id, trans_no='0'): sql = "insert into operateinfo (id,target,actionid,TRANSACTIONNO,OPERATOR,OPTTIME) values(:id,:target,:actionid,:TRANSACTIONNO,:OPERATOR,:OPTTIME)" data = [] data.append(['id', session.getsequence()]) data.append(['target', target]) data.append(['actionid', action_id]) t_no = trans_no if trans_no == '0': trans_no = session.getsequence() data.append(['TRANSACTIONNO', int(trans_no)]) data.append(['OPERATOR', session.user.login_name]) t = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime()) data.append(['OPTTIME', str(t)]) try: session.dbcnn.Execute2(sql, data) sql = "insert into transactionstatus (TRANSACTIONNO,TRANSACTIONSTATUS) values(:TRANSACTIONNO,:TRANSACTIONSTATUS)" data = [] data.append(['TRANSACTIONNO', int(trans_no)]) data.append(['TRANSACTIONSTATUS', 1]) session.dbcnn.Execute2(sql, data) except: tkMessageBox.showwarning(unicode('警告!'), unicode('无法记录事务日志')) print "error" return #调度者传递进来的 事务号不为0则显示发送命令状态窗口 if int(t_no): if session.form_send_status == None: session.form_send_status = net_train.net_send_status(None) session.form_send_status.add_item(int(trans_no))
def recLog(target,action_id,trans_no='0'): sql ="insert into operateinfo (id,target,actionid,TRANSACTIONNO,OPERATOR,OPTTIME) values(:id,:target,:actionid,:TRANSACTIONNO,:OPERATOR,:OPTTIME)" data=[] data.append(['id',session.getsequence()]) data.append(['target',target]) data.append(['actionid',action_id]) t_no = trans_no if trans_no=='0': trans_no = session.getsequence() data.append(['TRANSACTIONNO',int(trans_no)]) data.append(['OPERATOR',session.user.login_name]) t = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime()) data.append(['OPTTIME',str(t)]) try: session.dbcnn.Execute2(sql,data) sql = "insert into transactionstatus (TRANSACTIONNO,TRANSACTIONSTATUS) values(:TRANSACTIONNO,:TRANSACTIONSTATUS)" data=[] data.append(['TRANSACTIONNO',int(trans_no)]) data.append(['TRANSACTIONSTATUS',1]) session.dbcnn.Execute2(sql,data) except: tkMessageBox.showwarning(unicode('警告!'),unicode('无法记录事务日志')) print "error" return #调度者传递进来的 事务号不为0则显示发送命令状态窗口 if int(t_no): if session.form_send_status==None: session.form_send_status = net_train.net_send_status(None) session.form_send_status.add_item(int(trans_no))
def recLogin(): sql = "insert into logininfo (id,username,password,logintime,loginip) values(:id,:username,:password,:logintime,:loginip)" data = [] data.append(['id', session.getsequence()]) data.append(['username', session.user.login_name]) data.append(['password', session.user.psw]) t = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime()) data.append(['logintime', t]) localip = net_train.getlocalip() data.append(['loginip', localip]) try: session.dbcnn.Execute2(sql, data) except: return
def recLogin(): sql ="insert into logininfo (id,username,password,logintime,loginip) values(:id,:username,:password,:logintime,:loginip)" data =[] data.append(['id',session.getsequence()]) data.append(['username',session.user.login_name]) data.append(['password',session.user.psw]) t = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime()) data.append(['logintime',t]) localip = net_train.getlocalip() data.append(['loginip',localip]) try: session.dbcnn.Execute2(sql,data) except: return
def onsave(self): intval = 0 params = [] for w in self.widgets: if w[2] == 'ck': v = 0 stm = "v = self.var%s.get()" % w[0] #取checkbutton帮定的IntVar的值 exec(stm) if v: params.append("%s,1,1" % w[0]) else: params.append("%s,1,0" % w[0]) # pos = constdef.alarmflags.index(w[0]) # intval |=1<<pos #将告警值存入数据库 #sql = "update repeaterinfo set ALARMFLAG=%d where id = %d"%(intval,self.id) #print sql data = session.grab_tcp_package(self.id) data[4] = "%s" % constdef.cmd_list['SET_AUTO_ALARM_FLAG'] data[8] = "%s" % session.getsequence() try: #session.dbcnn.Execute(sql) #notify mss by net_train sendstr = "%s@%s" % (string.join(data, ','), string.join(params, ";")) if net_train.send2mss(sendstr) != 1: raise 1 tkMessageBox.showwarning('', unicode('告警使能标志设置发送中!')) except: tkMessageBox.showwarning('', unicode(' 与MSS通信失败!')) return #写入日志 log.recLog(str(self.id), log.LOG_MODIFY_ALARMFLAG, data[8])
def onsave(self): intval=0 params=[] for w in self.widgets: if w[2]=='ck': v =0 stm = "v = self.var%s.get()"%w[0] #取checkbutton帮定的IntVar的值 exec(stm) if v: params.append("%s,1,1"%w[0]) else: params.append("%s,1,0"%w[0]) # pos = constdef.alarmflags.index(w[0]) # intval |=1<<pos #将告警值存入数据库 #sql = "update repeaterinfo set ALARMFLAG=%d where id = %d"%(intval,self.id) #print sql data = session.grab_tcp_package(self.id) data[4]="%s"%constdef.cmd_list['SET_AUTO_ALARM_FLAG'] data[8]= "%s"%session.getsequence() try: #session.dbcnn.Execute(sql) #notify mss by net_train sendstr= "%s@%s"%(string.join(data,','),string.join(params,";")) if net_train.send2mss(sendstr)!=1: raise 1 tkMessageBox.showwarning('',unicode('告警使能标志设置发送中!')) except: tkMessageBox.showwarning('',unicode(' 与MSS通信失败!')) return #写入日志 log.recLog(str(self.id),log.LOG_MODIFY_ALARMFLAG,data[8])
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 onsave(self): ''' 用户信息存储 ''' if self.login_name.getvalue().strip() == '': tkMessageBox.showwarning(unicode('警告!'), unicode('请输入登录用户名')) return if self.psw.getvalue().strip() == '': tkMessageBox.showwarning(unicode('警告!'), unicode('请输入登录密码 ')) return if self.user_type.cget('value').strip() == '': tkMessageBox.showwarning(unicode('警告!'), unicode('请选择用户类别!')) return if self.user_type.cget('value').strip() == unicode('厂商管理员'): if self.provider.cget('value').strip() == '': tkMessageBox.showwarning(unicode('警告!'), unicode('请选择设备厂商')) return ##########################################3 login_name = self.login_name.getvalue().strip() psw = self.psw.getvalue().strip() real_name = self.real_name.getvalue().strip() tel = self.tel.getvalue().strip() user_type = self.user_type.cget('value').strip() provider = self.provider.cget('value').strip() #取用户管辖厂商 if user_type == unicode('区域管理员'): provider = 0 else: for p in self.provider_list: if provider == p['NAME'].strip(): provider = int(p['ID']) found = 0 found_user = None for i in self.userlist: if i['LOGIN_NAME'] == login_name: found = i['ID'] found_user = i break # get user's rights and areas rights = self.sel_rights.getselection() areas = self.sel_areas.getselection() if provider: #if provider manager ,no areas cannt prowl areas = [] #------------------------------- data = [] data.append(['login_name', ado.STRING, login_name]) data.append(['psw', ado.STRING, psw]) data.append(['real_name', ado.STRING, real_name]) data.append(['tel', ado.STRING, tel]) data.append(['provider', ado.INT, provider]) if found: #do update print 'do update' #-- delete all area and rights as user,and insert all sql = 'delete from userarea where user_id=%s' % found_user['ID'] session.dbcnn.Execute(sql) sql = 'delete from userrights where user_id=%s' % found_user['ID'] session.dbcnn.Execute(sql) for i in rights: sql = 'insert into userrights (user_id,rights_id) values(%s,%s)' % ( found_user['ID'], i) #print sql session.dbcnn.Execute(sql) for i in areas: sql = 'insert into userarea (user_id,area_id) values(%s,%s)' % ( found_user['ID'], i) #print sql session.dbcnn.Execute(sql) sql = "update userinfo set login_name=?,psw=?,real_name=?,tel=?,provider=? where id = %s" % found sql = sql.upper() try: session.dbcnn.Execute(sql, data) self.shl.hlist.tk.call(self.shl.hlist, 'entryconfigure', found_user['ID'], '-text', real_name) tkMessageBox.showwarning(unicode(''), unicode('修改用户信息成功!')) except: tkMessageBox.showwarning(unicode('警告!'), unicode('修改用户信息失败!')) return #print sql else: # do insert print 'do insert' try: sql = 'insert into userinfo (id,login_name,psw,real_name,tel,provider) values(?,?,?,?,?,?)' id = session.getsequence() data.insert(0, ['id', ado.INT, int(id)]) session.dbcnn.Execute(sql, data) for i in rights: if i.strip() == '': continue sql = 'insert into userrights (user_id,rights_id) values(%s,%s)' % ( id, i) #print sql session.dbcnn.Execute(sql) print "areas:" print areas for i in areas: if i.strip() == '': continue sql = 'insert into userarea (user_id,area_id) values(%s,%s)' % ( id, i) print sql #print sql session.dbcnn.Execute(sql) print "begin to update hlist" self.shl.hlist.add(str(id), itemtype='imagetext', image=self.pi, text=real_name) tkMessageBox.showwarning(unicode(''), unicode('添加用户成功!')) except: tkMessageBox.showwarning(unicode('警告!'), unicode('添加用户失败!')) return pass #更新当前用户列表 sql = "select * from userinfo where login_name<>'admin' and login_name<>'super' order by real_name" sql = sql.upper() self.userlist = session.getdata(sql)
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 onset(self): """ 系统参数设置""" if self.devinfo['MONI_ALARM_ID1'] == None: tkMessageBox.showwarning(unicode('警告!'), unicode('设备当前无系统参数返回!')) return data = [] data = session.grab_tcp_package(self.devinfo['ID']) data[4] = "%s" % constdef.CMD_REMOTE_SYS_SET data[8] = "%s" % session.getsequence() #------------------------------------------------------- s = [] if sys_value_can_set['NMS_PHONE']: # if self.central_phone.getvalue().strip() == '': tkMessageBox.showwarning(unicode('警告!'), unicode('控制中心电话不能为空!')) return s.append("QUERY_PHONE,2,%s" % self.central_phone.getvalue().strip()) else: s.append("NMS_PHONE,2,%s" % self.devinfo['QUERY_PHONE'].strip()) if sys_value_can_set['ALARM_PHONE']: # if self.alert_phone.getvalue().strip() == '': tkMessageBox.showwarning(unicode('警告!'), unicode('告警电话不能为空!')) return s.append("ALARM_PHONE,2,%s" % self.alert_phone.getvalue().strip()) else: s.append("ALARM_PHONE,2,%s" % self.devinfo['ALARAM_PHONE'].strip()) if sys_value_can_set['MONI_ALARM_ID1']: # #if self.alert_phone.getvalue().strip()=='': # tkMessageBox.showwarning(unicode('警告!'),unicode('告警电话不能为空!')) # return #s.append('ALARM_PHONE',2,self.alert_phone.getvalue().strip()) pass else: s.append("MONI_ALARM_ID1,1,%s" % self.devinfo['MONI_ALARM_ID1']) if sys_value_can_set['MONI_ALARM_ID2']: # #if self.alert_phone.getvalue().strip()=='': # tkMessageBox.showwarning(unicode('警告!'),unicode('告警电话不能为空!')) # return #s.append('ALARM_PHONE',2,self.alert_phone.getvalue().strip()) pass else: s.append("MONI_ALARM_ID2,1,%s" % self.devinfo['MONI_ALARM_ID2']) if sys_value_can_set['MONI_ALARMFLAG']: v = 0 mask = constdef.LT_ALARM_SWITCH[self.ad0_alert.cget('value')] v = v | (mask << 4) mask = constdef.LT_ALARM_SWITCH[self.ad1_alert.cget('value')] v = v | (mask << 5) mask = constdef.LT_ALARM_SWITCH[self.ad2_alert.cget('value')] v = v | (mask << 6) mask = constdef.LT_ALARM_SWITCH[self.ad3_alert.cget('value')] v = v | (mask << 7) s.append("MONI_ALARMFLAG,1,%s" % str(v)) else: s.append("MONI_ALARMFLAG,1,%s" % self.devinfo['MONI_ALARMFLAG']) if sys_value_can_set['AD0MIN']: if not self.ad0min.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD0MIN 无效!')) return else: s.append("AD0MIN,1,%s" % self.ad0min.getvalue().strip()) else: s.append("AD0MIN,1,%s" % self.devinfo['AD0MIN']) if sys_value_can_set['AD0MAX']: if not self.ad0max.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD0MAX 无效!')) return else: s.append("AD0MAX,1,%s" % self.ad0max.getvalue().strip()) else: s.append("AD0MAX,1,%s" % self.devinfo['AD0MAX']) #------------------------------------------------------------------ if sys_value_can_set['AD1MIN']: if not self.ad1min.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD1MIN 无效!')) return else: s.append("AD1MIN,1,%s" % self.ad1min.getvalue().strip()) else: s.append("AD1MIN,1,%s" % self.devinfo['AD1MIN']) if sys_value_can_set['AD1MAX']: if not self.ad1max.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD1MAX 无效!')) return else: s.append("AD1MAX,1,%s" % self.ad1max.getvalue().strip()) else: s.append("AD1MAX,1,%s" % self.devinfo['AD1MAX']) #------------------------------------------------------------------ if sys_value_can_set['AD2MIN']: if not self.ad2min.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD2MIN 无效!')) return else: s.append("AD2MIN,1,%s" % self.ad2min.getvalue().strip()) else: s.append("AD2MIN,1,%s" % self.devinfo['AD2MIN']) if sys_value_can_set['AD2MAX']: if not self.ad2max.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD2MAX 无效!')) return else: s.append("AD2MAX,1,%s" % self.ad2max.getvalue().strip()) else: s.append("AD2MAX,1,%s" % self.devinfo['AD2MAX']) #------------------------------------------------------------------ if sys_value_can_set['AD3MIN']: if not self.ad3min.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD3MIN 无效!')) return else: s.append("AD3MIN,1,%s" % self.ad3min.getvalue().strip()) else: s.append("AD3MIN,1,%s" % self.devinfo['AD3MIN']) if sys_value_can_set['AD3MAX']: if not self.ad3max.valid(): tkMessageBox.showwarning(unicode('警告!'), unicode('AD3MAX 无效!')) return else: s.append("AD3MAX,1,%s" % self.ad3max.getvalue().strip()) else: s.append("AD3MAX,1,%s" % self.devinfo['AD3MAX']) #------------------------------------------------------------------ if sys_value_can_set['DIGIT_ALARM1']: pass #if not self.digit_alert.valid(): # tkMessageBox.showwarning(unicode('警告!'),unicode('数字量告警值无效!')) # return #else: # s.append("AD3MAX,1,%s"%self.ad3max.getvalue().strip()) else: s.append("DIGIT_ALARM1,1,%s" % self.devinfo['DIGIT_ALARM1']) if sys_value_can_set['DIGIT_ALARM2']: pass else: s.append("DIGIT_ALARM2,1,%s" % self.devinfo['DIGIT_ALARM2']) #------------------------------------------------------------------ mask_val = 0 if sys_value_can_set['DIGIT_ALARMFLAG1']: #bit 0-15 for i in range(16): stm = "v =self.d%s_alert.cget('value')" % i exec(stm) print v stm = "v = constdef.LT_ALARM_SWITCH[unicode('%s')]" % v print stm exec(stm) mask_val = mask_val | (int(v) << i) print hex(mask_val) s.append("DIGIT_ALARMFLAG1,1,%s" % (mask_val & 0x0ff)) #low 8 bits s.append("DIGIT_ALARMFLAG2,1,%s" % ((mask_val & 0xff00) >> 8)) #==>high 8 bits else: s.append("DIGIT_ALARMFLAG1,1,%s" % self.devinfo['DIGIT_ALARMFLAG1']) s.append("DIGIT_ALARMFLAG2,1,%s" % self.devinfo['DIGIT_ALARMFLAG2']) sendstr = "%s@%s" % (string.join(data, ','), string.join(s, ';')) print sendstr try: if net_train.send2mss(sendstr) != 1: print "invoke send2mss failed" raise 1 tkMessageBox.showwarning('', unicode('控制命令发送中!')) except: tkMessageBox.showwarning('', unicode(' 与MSS通信失败!')) return log.recLog(str(self.devinfo['ID']), log.LOG_CONTROL, data[8])
def oncontrol(self): if self.status==[]: return if self.control_params==[]: return sel_list =[] has_sel=0 for pc in self.control_params: stm = "v= self.var%s.get()"%pc['PARAMNAME'] exec(stm) if v: #如果选择设置 print pc['PARAMNAME'] has_sel=1 for c in self.control_widget: if c[0]==pc['PARAMNAME']: w = c[1] val ='' if c[2]=='en': if not w.valid(): tkMessageBox.showwarning(unicode('警告!'),unicode('参数值无效:')+pc['DESCRIPT']) return else: sel_list.append([pc['PARAMNAME'],w.getvalue(),0,1]) if c[2]=='cb': val = w.cget('value') try: ls1=[] ls1 = re.split(';',pc['UI_VALUE_RANGE']) for s in ls1: ls2 =re.split(':',s) if ls2[0]==val: # print ls2[0],val,"compare" val = int(ls2[1]) break except: val =0 #tkMessageBox.showwarning(unicode('警告!'),unicode('参数值无效:')+pc['DESCRIPT']) #return sel_list.append([pc['PARAMNAME'],val,0,1]) else: #取当前状态记录的当前字段值 fieldname=pc['FIELDNAME'] cur_rec = self.status[0] try: v =cur_rec[fieldname] if v==None: v=str(session.control_run_param_default) except: v =str(session.control_run_param_default) sel_list.append([pc['PARAMNAME'],v,0,0]) if has_sel==0: #当前无控制参数,撤销操作 return s=[] for ctrl_item in sel_list: type ="" type = self.get_paramtype(self.cur_dev['REPEATERTYPE'],ctrl_item[0]) s.append("%s,%s,%s"%(ctrl_item[0],type,ctrl_item[1])) data = session.grab_tcp_package(self.id) data[4]="%s"%constdef.CMD_REMOTE_CTRL data[8]= "%s"%session.getsequence() sendstr = "%s@%s"%(string.join(data,','),string.join(s,';')) print sendstr try: if net_train.send2mss(sendstr)!=1: raise 1 log.recLog(str(self.id),log.LOG_CONTROL,data[8]) tkMessageBox.showwarning('',unicode('控制命令发送中!')) except: tkMessageBox.showwarning('',unicode(' 与MSS通信失败!')) return
def onsave(self): ''' 用户信息存储 ''' if self.login_name.getvalue().strip()=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请输入登录用户名')) return if self.psw.getvalue().strip()=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请输入登录密码 ')) return if self.user_type.cget('value').strip()=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请选择用户类别!')) return if self.user_type.cget('value').strip()==unicode('厂商管理员'): if self.provider.cget('value').strip()=='': tkMessageBox.showwarning(unicode('警告!'),unicode('请选择设备厂商')) return ##########################################3 login_name = self.login_name.getvalue().strip() psw = self.psw.getvalue().strip() real_name = self.real_name.getvalue().strip() tel = self.tel.getvalue().strip() user_type = self.user_type.cget('value').strip() provider = self.provider.cget('value').strip() #取用户管辖厂商 if user_type==unicode('区域管理员'): provider =0 else: for p in self.provider_list: if provider == p['NAME'].strip(): provider = int(p['ID']) found = 0 found_user =None for i in self.userlist : if i['LOGIN_NAME']==login_name: found = i['ID'] found_user = i break # get user's rights and areas rights = self.sel_rights.getselection() areas = self.sel_areas.getselection() if provider: #if provider manager ,no areas cannt prowl areas=[] #------------------------------- data =[] data.append(['login_name',ado.STRING ,login_name]) data.append(['psw',ado.STRING ,psw]) data.append(['real_name',ado.STRING ,real_name]) data.append(['tel',ado.STRING ,tel]) data.append(['provider',ado.INT ,provider]) if found : #do update print 'do update' #-- delete all area and rights as user,and insert all sql ='delete from userarea where user_id=%s'%found_user['ID'] session.dbcnn.Execute(sql) sql ='delete from userrights where user_id=%s'%found_user['ID'] session.dbcnn.Execute(sql) for i in rights: sql = 'insert into userrights (user_id,rights_id) values(%s,%s)'%(found_user['ID'],i) #print sql session.dbcnn.Execute(sql) for i in areas: sql = 'insert into userarea (user_id,area_id) values(%s,%s)'%(found_user['ID'],i) #print sql session.dbcnn.Execute(sql) sql = "update userinfo set login_name=?,psw=?,real_name=?,tel=?,provider=? where id = %s"%found sql = sql.upper() try: session.dbcnn.Execute(sql,data) self.shl.hlist.tk.call(self.shl.hlist,'entryconfigure',found_user['ID'],'-text',real_name) tkMessageBox.showwarning(unicode(''),unicode('修改用户信息成功!')) except: tkMessageBox.showwarning(unicode('警告!'),unicode('修改用户信息失败!')) return #print sql else: # do insert print 'do insert' try: sql = 'insert into userinfo (id,login_name,psw,real_name,tel,provider) values(?,?,?,?,?,?)' id = session.getsequence() data.insert(0,['id',ado.INT,int(id)]) session.dbcnn.Execute(sql,data) for i in rights: if i.strip()=='': continue sql = 'insert into userrights (user_id,rights_id) values(%s,%s)'%(id,i) #print sql session.dbcnn.Execute(sql) print "areas:" print areas for i in areas: if i.strip()=='': continue sql = 'insert into userarea (user_id,area_id) values(%s,%s)'%(id,i) print sql #print sql session.dbcnn.Execute(sql) print "begin to update hlist" self.shl.hlist.add(str(id),itemtype='imagetext',image=self.pi,text=real_name) tkMessageBox.showwarning(unicode(''),unicode('添加用户成功!')) except: tkMessageBox.showwarning(unicode('警告!'),unicode('添加用户失败!')) return pass #更新当前用户列表 sql = "select * from userinfo where login_name<>'admin' and login_name<>'super' order by real_name" sql = sql.upper() self.userlist = session.getdata(sql)
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 oncontrol(self): if self.status == []: return if self.control_params == []: return sel_list = [] has_sel = 0 for pc in self.control_params: stm = "v= self.var%s.get()" % pc['PARAMNAME'] exec(stm) if v: #如果选择设置 print pc['PARAMNAME'] has_sel = 1 for c in self.control_widget: if c[0] == pc['PARAMNAME']: w = c[1] val = '' if c[2] == 'en': if not w.valid(): tkMessageBox.showwarning( unicode('警告!'), unicode('参数值无效:') + pc['DESCRIPT']) return else: sel_list.append( [pc['PARAMNAME'], w.getvalue(), 0, 1]) if c[2] == 'cb': val = w.cget('value') try: ls1 = [] ls1 = re.split(';', pc['UI_VALUE_RANGE']) for s in ls1: ls2 = re.split(':', s) if ls2[0] == val: # print ls2[0], val, "compare" val = int(ls2[1]) break except: val = 0 #tkMessageBox.showwarning(unicode('警告!'),unicode('参数值无效:')+pc['DESCRIPT']) #return sel_list.append([pc['PARAMNAME'], val, 0, 1]) else: #取当前状态记录的当前字段值 fieldname = pc['FIELDNAME'] cur_rec = self.status[0] try: v = cur_rec[fieldname] if v == None: v = str(session.control_run_param_default) except: v = str(session.control_run_param_default) sel_list.append([pc['PARAMNAME'], v, 0, 0]) if has_sel == 0: #当前无控制参数,撤销操作 return s = [] for ctrl_item in sel_list: type = "" type = self.get_paramtype(self.cur_dev['REPEATERTYPE'], ctrl_item[0]) s.append("%s,%s,%s" % (ctrl_item[0], type, ctrl_item[1])) data = session.grab_tcp_package(self.id) data[4] = "%s" % constdef.CMD_REMOTE_CTRL data[8] = "%s" % session.getsequence() sendstr = "%s@%s" % (string.join(data, ','), string.join(s, ';')) print sendstr try: if net_train.send2mss(sendstr) != 1: raise 1 log.recLog(str(self.id), log.LOG_CONTROL, data[8]) tkMessageBox.showwarning('', unicode('控制命令发送中!')) except: tkMessageBox.showwarning('', unicode(' 与MSS通信失败!')) return