uo_userpwr.sru 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. $PBExportHeader$uo_userpwr.sru
  2. forward
  3. global type uo_userpwr from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_userpwr from nonvisualobject
  7. end type
  8. global uo_userpwr uo_userpwr
  9. forward prototypes
  10. public function integer check_closeloop (long arg_objid, long arg_checkid, integer arg_grouptype)
  11. public function integer deluser (boolean if_delall, long arg_scid, long arg_empid, ref string arg_msg, boolean arg_ifcommit)
  12. public function integer reset_userpwd (long arg_scid, long arg_empid, string arg_userid, ref string arg_msg)
  13. public function integer savegroup (long arg_scid, long arg_groupid, string arg_usergroup, ref string arg_msg, boolean arg_ifcommit)
  14. public function integer delgroup (long arg_scid, long arg_groupid, ref string arg_msg, boolean arg_ifcommit)
  15. public function integer f_rst_empid_arr (long arg_scid, long arg_usergpid, ref long arg_arr[])
  16. public function integer f_rst_msgemp_arr (long arg_scid, string arg_objpdm, ref long arg_arr[])
  17. public function integer saveuser (boolean arg_ifmodify, long arg_scid, long arg_empid, string arg_userid, string arg_username, string arg_dscrp, string arg_powerstring, string arg_storagestr, string arg_scstr, ref string arg_msg, boolean arg_ifcommit)
  18. public function integer add_shortcut (long arg_scid, long arg_empid, long arg_funcid, ref string arg_msg, boolean arg_ifcommit)
  19. public function integer del_shortcut (long arg_scid, long arg_empid, long arg_funcid, ref string arg_msg, boolean arg_ifcommit)
  20. end prototypes
  21. public function integer check_closeloop (long arg_objid, long arg_checkid, integer arg_grouptype);//查闭环
  22. //check_closeloop
  23. int rslt=1
  24. if arg_checkid=arg_objid and arg_grouptype=1 then return 1
  25. if arg_grouptype=0 then return 0
  26. long relid[],ls_i,count,rt_b
  27. int grouptype[]
  28. DECLARE ug_cur CURSOR FOR
  29. SELECT u_usergroup.empid,
  30. u_usergroup.grouptype
  31. FROM u_usergroup
  32. WHERE ( u_usergroup.usergroupid = :arg_checkid);
  33. open ug_cur;
  34. count=1
  35. fetch ug_cur into :relid[count],:grouptype[count];
  36. do while sqlca.sqlcode=0
  37. count++
  38. fetch ug_cur into :relid[count],:grouptype[count];
  39. loop
  40. count=count - 1
  41. close ug_cur;
  42. for ls_i=1 to count
  43. rt_b=check_closeloop(arg_objid,relid[ls_i],grouptype[count])
  44. if rt_b<>0 then return rt_b
  45. next
  46. return 0
  47. return rslt
  48. end function
  49. public function integer deluser (boolean if_delall, long arg_scid, long arg_empid, ref string arg_msg, boolean arg_ifcommit);//删除用户
  50. int rslt=1
  51. if if_delall then
  52. delete from u_user where empid <> 0 and scid=:arg_scid;
  53. else
  54. delete from u_user where empid=:arg_empid and scid=:arg_scid;
  55. end if
  56. if sqlca.sqlcode<>0 then
  57. arg_msg='删除用户基本资料失败'
  58. rslt=0
  59. goto ext
  60. end if
  61. ext:
  62. if rslt=0 then
  63. rollback;
  64. elseif rslt=1 and arg_ifcommit then
  65. commit;
  66. end if
  67. return rslt
  68. end function
  69. public function integer reset_userpwd (long arg_scid, long arg_empid, string arg_userid, ref string arg_msg);//重设用户密码
  70. //reset_userpwd(arg_scid,arg_empid,arg_userid,arg_msg)
  71. string ls_pwd=''
  72. ls_pwd=f_psw_bczh(lower(arg_userid),0,sys_power_key)
  73. UPDATE u_user SET psw = :ls_pwd where empid=:arg_empid and scid=:arg_scid;
  74. if sqlca.sqlcode<>0 then
  75. arg_msg="恢复密码失败"
  76. rollback;
  77. return 0
  78. else
  79. commit;
  80. arg_msg="恢复密码成功"
  81. return 1
  82. end if
  83. end function
  84. public function integer savegroup (long arg_scid, long arg_groupid, string arg_usergroup, ref string arg_msg, boolean arg_ifcommit);//新建组
  85. //savegroup(arg_scid,arg_groupid,arg_usergroup,arg_msg,arg_ifcommit)
  86. //arg_groupid 0:新建,>0:修改
  87. int rslt=1
  88. long ls_newid
  89. if arg_groupid=0 then
  90. ls_newid=f_sys_scidentity(arg_scid,"u_usergroupdef","UsergroupID",arg_msg,false,sqlca)
  91. if ls_newid<0 then
  92. rslt=0
  93. goto ext
  94. end if
  95. INSERT INTO u_usergroupdef (scid,UsergroupID,usergroup ) VALUES (:arg_scid,:ls_newid, :arg_usergroup );
  96. if sqlca.sqlcode<>0 then
  97. rslt=0
  98. arg_msg='新建组"'+arg_usergroup+'"失败,可能是名称已经存在或网络故障!'
  99. goto ext
  100. end if
  101. else
  102. update u_usergroupdef set usergroup =:arg_usergroup
  103. where UsergroupID =:arg_groupid and scid=:arg_scid ;
  104. if sqlca.sqlcode<>0 then
  105. rslt=0
  106. arg_msg='修改名称操作失败,可能是新名称已经存在或网络故障!'
  107. goto ext
  108. end if
  109. end if
  110. ext:
  111. if rslt=0 then
  112. rollback;
  113. elseif rslt=1 and arg_ifcommit then
  114. commit;
  115. end if
  116. return rslt
  117. end function
  118. public function integer delgroup (long arg_scid, long arg_groupid, ref string arg_msg, boolean arg_ifcommit);//删除组
  119. //delgroup(arg_scid,arg_groupid,arg_msg,arg_ifcommit)
  120. int rslt=1
  121. long cnt
  122. select count(*) into :cnt
  123. from u_usergroup
  124. where ( u_usergroup.empid=:arg_groupid and Grouptype=1 )
  125. and ( u_usergroup.UsergroupID=:arg_groupid )
  126. and ( u_usergroup.scid=:arg_scid);
  127. if sqlca.sqlcode<>0 then
  128. arg_msg='查询组成员明细失败!'
  129. rslt=0
  130. goto ext
  131. end if
  132. if cnt > 0 then
  133. arg_msg='该组已用于组成员管理,不能删除!如果要删除请在成员列表中先删除'
  134. rslt=0
  135. goto ext
  136. end if
  137. DELETE u_usergroupdef where u_usergroupdef.UsergroupID=:arg_groupid and scid=:arg_scid;
  138. if sqlca.sqlcode<>0 then
  139. rslt=0
  140. arg_msg='删除组操作失败>>'+sqlca.sqlerrtext
  141. goto ext
  142. end if
  143. ext:
  144. if rslt=0 then
  145. rollback;
  146. elseif rslt=1 and arg_ifcommit then
  147. commit;
  148. end if
  149. return rslt
  150. end function
  151. public function integer f_rst_empid_arr (long arg_scid, long arg_usergpid, ref long arg_arr[]);//递归调用返回empid[]
  152. //f_rst_empid_arr(arg_scid,arg_usergpid,arg_arr[])
  153. long ls_empgpid[],tmp_empgpid,itmxt,arr_mxt,it_arr_mxt
  154. int ls_gptype[],tmp_gptype
  155. long i,j
  156. boolean if_exist=false
  157. DECLARE usergp CURSOR FOR
  158. SELECT u_usergroup.Empid,
  159. u_usergroup.Grouptype
  160. FROM u_usergroup
  161. WHERE u_usergroup.scid=:arg_scid
  162. AND u_usergroup.UsergroupID=:arg_usergpid;
  163. open usergp;
  164. fetch usergp into :tmp_empgpid,:tmp_gptype;
  165. do while sqlca.sqlcode = 0
  166. itmxt++
  167. ls_empgpid[itmxt]=tmp_empgpid
  168. ls_gptype[itmxt]=tmp_gptype
  169. fetch usergp into :tmp_empgpid,:tmp_gptype;
  170. loop
  171. close usergp;
  172. arr_mxt=upperbound(arg_arr)
  173. if itmxt > 0 then
  174. for i=1 to itmxt
  175. if ls_gptype[i]=0 then //用户
  176. if_exist=false
  177. for j=1 to arr_mxt
  178. if ls_empgpid[i]=arg_arr[j] then if_exist=true
  179. next
  180. if not if_exist then
  181. arr_mxt++
  182. arg_arr[arr_mxt]=ls_empgpid[i]
  183. end if
  184. else
  185. f_rst_empid_arr(arg_scid,ls_empgpid[i],arg_arr[])
  186. end if
  187. next
  188. end if
  189. return 1
  190. end function
  191. public function integer f_rst_msgemp_arr (long arg_scid, string arg_objpdm, ref long arg_arr[]);//返回消息用户列表
  192. //f_rst_msgemp_arr(arg_scid,arg_objpdm,arg_arr[])
  193. long it_mxt,ls_usergrpid,i
  194. string ls_usergpname,ls_objpdm
  195. long dot_pos
  196. boolean if_exist=false
  197. ls_objpdm=arg_objpdm
  198. do while ls_objpdm <> ''
  199. dot_pos=pos(ls_objpdm,';')
  200. if dot_pos<=0 then
  201. ls_usergpname=ls_objpdm
  202. ls_objpdm=''
  203. else
  204. ls_usergpname = left(ls_objpdm,dot_pos - 1)
  205. ls_objpdm=mid(ls_objpdm,dot_pos + 1)
  206. end if
  207. select usergroupid into :ls_usergrpid from u_usergroupdef
  208. where usergroup=:ls_usergpname and scid = :arg_scid;
  209. if sqlca.sqlcode<>0 then
  210. select empid into :ls_usergrpid from u_user
  211. where username=:ls_usergpname and scid = :arg_scid;
  212. if sqlca.sqlcode=0 then
  213. it_mxt=upperbound(arg_arr)
  214. if_exist=false
  215. for i=1 to it_mxt
  216. if arg_arr[i]=ls_usergrpid then if_exist=true
  217. next
  218. if not if_exist then
  219. it_mxt++
  220. arg_arr[it_mxt]=ls_usergrpid
  221. end if
  222. end if
  223. else
  224. f_rst_empid_arr(arg_scid,ls_usergrpid,arg_arr[])
  225. end if
  226. loop
  227. return 1
  228. end function
  229. public function integer saveuser (boolean arg_ifmodify, long arg_scid, long arg_empid, string arg_userid, string arg_username, string arg_dscrp, string arg_powerstring, string arg_storagestr, string arg_scstr, ref string arg_msg, boolean arg_ifcommit);//====================================================================
  230. // Function: saveuser()
  231. //--------------------------------------------------------------------
  232. // Description:
  233. //--------------------------------------------------------------------
  234. // Arguments:
  235. // value boolean arg_ifmodify
  236. // value long arg_scid
  237. // value long arg_empid
  238. // value string arg_userid
  239. // value string arg_username
  240. // value string arg_dscrp
  241. // value string arg_powerstring
  242. // value string arg_storagestr
  243. // value string arg_scstr
  244. // reference string arg_msg
  245. // value boolean arg_ifcommit
  246. //--------------------------------------------------------------------
  247. // Returns: integer
  248. //--------------------------------------------------------------------
  249. // Author: yyx Date: 2004.10.21
  250. //--------------------------------------------------------------------
  251. // Modify History:
  252. //
  253. //====================================================================
  254. int rslt=1
  255. string ls_pass
  256. if arg_userid <> 'super' then
  257. if arg_empid=0 then
  258. arg_msg="请选择人员!"
  259. rslt=0
  260. goto ext
  261. end if
  262. end if
  263. if arg_userid="" then
  264. arg_msg="必须填写用户代码!"
  265. rslt=0
  266. goto ext
  267. end if
  268. if arg_username="" then
  269. arg_msg="必须填写用户姓名!"
  270. rslt=0
  271. goto ext
  272. end if
  273. if not arg_ifmodify then
  274. ls_pass=f_psw_bczh(arg_userid,0,sys_power_key) //加密
  275. insert into u_user(scid,empid,userid,username,descrp,storagestr,scstr,psw,Rightstring)
  276. values (:arg_scid,:arg_empid,:arg_userid,:arg_username,:arg_dscrp,:arg_storagestr,:arg_scstr,:ls_pass,:arg_powerstring);
  277. if sqlca.sqlcode<>0 then
  278. arg_msg='新建用户基本资料失败>>'+sqlca.sqlerrtext
  279. rslt=0
  280. goto ext
  281. end if
  282. else
  283. update u_user
  284. set userid=:arg_userid,
  285. username=:arg_username,
  286. descrp=:arg_dscrp,
  287. storagestr=:arg_storagestr,
  288. Rightstring=:arg_powerstring,
  289. scstr=:arg_scstr
  290. where empid = :arg_empid and scid=:arg_scid;
  291. if sqlca.sqlcode<>0 then
  292. arg_msg='更新用户基本资料失败'
  293. rslt=0
  294. goto ext
  295. end if
  296. end if
  297. if rslt=0 then
  298. rollback;
  299. elseif rslt=1 and arg_ifcommit then
  300. commit;
  301. end if
  302. ext:
  303. return rslt
  304. end function
  305. public function integer add_shortcut (long arg_scid, long arg_empid, long arg_funcid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  306. String ls_shortcutstr,ls_funstr
  307. SELECT shortcutstr INTO :ls_shortcutstr
  308. FROM u_user
  309. Where scid = :arg_scid And empid = :arg_empid;
  310. IF sqlca.SQLCode <> 0 THEN
  311. rslt = 0
  312. arg_msg = '查询快捷方式失败!'
  313. GOTO ext
  314. END IF
  315. ls_funstr = String(arg_funcid)+','
  316. IF Pos(ls_shortcutstr,ls_funstr) = 0 THEN
  317. ls_shortcutstr = ls_shortcutstr+ls_funstr
  318. END IF
  319. UPDATE u_user
  320. SET shortcutstr = :ls_shortcutstr
  321. Where scid = :arg_scid And empid = :arg_empid;
  322. IF sqlca.SQLCode <> 0 THEN
  323. rslt = 0
  324. arg_msg = '添加快捷方式失败!'
  325. GOTO ext
  326. END IF
  327. ext:
  328. IF rslt = 0 THEN
  329. ROLLBACK;
  330. ELSEIF rslt = 1 And arg_ifcommit THEN
  331. COMMIT;
  332. END IF
  333. RETURN rslt
  334. end function
  335. public function integer del_shortcut (long arg_scid, long arg_empid, long arg_funcid, ref string arg_msg, boolean arg_ifcommit);int rslt = 1
  336. string str_shortcutstr,str_funstr,str_tmp,str_leftstr,str_rightstr
  337. select shortcutstr into :str_shortcutstr
  338. from u_user
  339. where scid = :arg_scid and empid = :arg_empid;
  340. if sqlca.sqlcode <> 0 then
  341. rslt = 0
  342. arg_msg = '查询快捷方式失败!'
  343. goto ext
  344. end if
  345. str_funstr =string(arg_funcid)
  346. do while pos(str_shortcutstr,',') <> 0
  347. str_tmp = trim(left(str_shortcutstr,pos(str_shortcutstr,',') - 1 ))
  348. str_rightstr= right(str_shortcutstr,len(str_shortcutstr) - pos(str_shortcutstr,','))
  349. if str_tmp=str_funstr then
  350. str_shortcutstr=str_leftstr+str_rightstr
  351. exit
  352. end if
  353. str_leftstr=str_leftstr+str_tmp+','
  354. str_shortcutstr =str_rightstr
  355. loop
  356. update u_user
  357. set
  358. shortcutstr = :str_shortcutstr
  359. where scid = :arg_scid and empid = :arg_empid;
  360. if sqlca.sqlcode <> 0 then
  361. rslt = 0
  362. arg_msg = '删除快捷方式失败!'
  363. goto ext
  364. end if
  365. ext:
  366. if rslt = 0 then
  367. rollback;
  368. elseif rslt = 1 and arg_ifcommit then
  369. commit;
  370. end if
  371. return rslt
  372. end function
  373. on uo_userpwr.create
  374. call super::create
  375. TriggerEvent( this, "constructor" )
  376. end on
  377. on uo_userpwr.destroy
  378. TriggerEvent( this, "destructor" )
  379. call super::destroy
  380. end on