uo_usergroup.sru 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. $PBExportHeader$uo_usergroup.sru
  2. forward
  3. global type uo_usergroup from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_usergroup from nonvisualobject
  7. end type
  8. global uo_usergroup uo_usergroup
  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 check_psw (string arg_psw, ref string arg_msg)
  18. public function integer saveuser_knwldg (long arg_empid, string arg_userid, integer arg_knwldgencrypttype, integer arg_knwldgtchnlogytype, string arg_knwldgrgtstr, ref string arg_msg)
  19. public function integer saveuser (boolean arg_ifmodify, long arg_scid, long arg_empid, string arg_userid, string arg_username, string arg_cardno, string arg_dscrp, string arg_powerstring, string arg_storagestr, string arg_storagestr_new, string arg_storagestr_audit, string arg_scstr, string arg_classeditstr, string arg_classviewstr, string arg_classdelstr, string arg_areastr, integer arg_iftimelimit, string arg_timelimitdscrp, integer arg_ifcheckcard, string arg_xls_printstr, string arg_xls_sendstr, string arg_spttypestr, string arg_gzitemstr, integer arg_ifcheckcomp, string arg_compname, string arg_pluginsstr, integer arg_ifnotin, string arg_modulestring, string arg_priceliststr, string arg_reportstr, string arg_wkpstr, string arg_workgroupstr, string arg_pricetypestr, string arg_outrepstr, integer arg_dlflag, integer arg_grade, string arg_deptstr, string arg_saletypestr, long arg_pempid, string arg_demotypestr, 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. Long cnt
  52. If if_delall Then
  53. Delete From u_user Where empid <> 0 And scid = :arg_scid;
  54. Else
  55. Select count(*)
  56. Into :cnt
  57. From u_user
  58. Where pempid = :arg_empid ;
  59. If sqlca.SQLCode <> 0 Then
  60. arg_msg = '查询用户是否有下级用户失败,'+sqlca.sqlerrtext
  61. rslt = 0
  62. Goto ext
  63. End If
  64. if cnt > 0 then
  65. rslt = 0
  66. arg_msg = '该用户有下级用户,请先删除下级用户'
  67. goto ext
  68. end if
  69. Delete From u_user Where empid = :arg_empid And scid = :arg_scid;
  70. End If
  71. If sqlca.SQLCode <> 0 Then
  72. arg_msg = '删除用户基本资料失败'
  73. rslt = 0
  74. Goto ext
  75. End If
  76. ext:
  77. If rslt = 0 Then
  78. Rollback;
  79. ElseIf rslt = 1 And arg_ifcommit Then
  80. Commit;
  81. End If
  82. Return rslt
  83. end function
  84. public function integer reset_userpwd (long arg_scid, long arg_empid, string arg_userid, ref string arg_msg);//重设用户密码
  85. //reset_userpwd(arg_scid,arg_empid,arg_userid,arg_msg)
  86. String ls_pwd = ''
  87. String ls_p1,ls_p2
  88. Int ll_len
  89. ls_pwd = f_psw_bczh(Lower(arg_userid),0,sys_power_key_new)
  90. ll_len = Int(Len(ls_pwd) / 2)
  91. ls_p1 = Mid(ls_pwd,1,ll_len)
  92. ls_p2 = Mid(ls_pwd,ll_len + 1)
  93. UPDATE u_user
  94. SET psw = '',
  95. pone = :ls_p1,
  96. ptwo = :ls_p2
  97. WHERE empid = :arg_empid
  98. And scid = :arg_scid;
  99. IF sqlca.SQLCode <> 0 THEN
  100. arg_msg = "恢复密码失败"
  101. ROLLBACK;
  102. RETURN 0
  103. ELSE
  104. COMMIT;
  105. arg_msg = "恢复密码成功"
  106. RETURN 1
  107. END IF
  108. end function
  109. public function integer savegroup (long arg_scid, long arg_groupid, string arg_usergroup, ref string arg_msg, boolean arg_ifcommit);//新建组
  110. //savegroup(arg_scid,arg_groupid,arg_usergroup,arg_msg,arg_ifcommit)
  111. //arg_groupid 0:新建,>0:修改
  112. int rslt=1
  113. long ls_newid
  114. if arg_groupid=0 then
  115. ls_newid=f_sys_scidentity(arg_scid,"u_usergroupdef","UsergroupID",arg_msg,TRUE,id_sqlca)
  116. if ls_newid<0 then
  117. rslt=0
  118. goto ext
  119. end if
  120. INSERT INTO u_usergroupdef (scid,UsergroupID,usergroup ) VALUES (:arg_scid,:ls_newid, :arg_usergroup );
  121. if sqlca.sqlcode<>0 then
  122. rslt=0
  123. arg_msg='新建组"'+arg_usergroup+'"失败,可能是名称已经存在或网络故障!'
  124. goto ext
  125. end if
  126. else
  127. update u_usergroupdef set usergroup =:arg_usergroup
  128. where UsergroupID =:arg_groupid and scid=:arg_scid ;
  129. if sqlca.sqlcode<>0 then
  130. rslt=0
  131. arg_msg='修改名称操作失败,可能是新名称已经存在或网络故障!'
  132. goto ext
  133. end if
  134. end if
  135. ext:
  136. if rslt=0 then
  137. rollback;
  138. elseif rslt=1 and arg_ifcommit then
  139. commit;
  140. end if
  141. return rslt
  142. end function
  143. public function integer delgroup (long arg_scid, long arg_groupid, ref string arg_msg, boolean arg_ifcommit);//删除组
  144. //delgroup(arg_scid,arg_groupid,arg_msg,arg_ifcommit)
  145. int rslt=1
  146. long cnt
  147. select count(*) into :cnt
  148. from u_usergroup
  149. where ( u_usergroup.empid=:arg_groupid and Grouptype=1 )
  150. and ( u_usergroup.UsergroupID=:arg_groupid )
  151. and ( u_usergroup.scid=:arg_scid);
  152. if sqlca.sqlcode<>0 then
  153. arg_msg='查询组成员明细失败!'
  154. rslt=0
  155. goto ext
  156. end if
  157. if cnt > 0 then
  158. arg_msg='该组已用于组成员管理,不能删除!如果要删除请在成员列表中先删除'
  159. rslt=0
  160. goto ext
  161. end if
  162. DELETE u_usergroupdef where u_usergroupdef.UsergroupID=:arg_groupid and scid=:arg_scid;
  163. if sqlca.sqlcode<>0 then
  164. rslt=0
  165. arg_msg='删除组操作失败>>'+sqlca.sqlerrtext
  166. goto ext
  167. end if
  168. ext:
  169. if rslt=0 then
  170. rollback;
  171. elseif rslt=1 and arg_ifcommit then
  172. commit;
  173. end if
  174. return rslt
  175. end function
  176. public function integer f_rst_empid_arr (long arg_scid, long arg_usergpid, ref long arg_arr[]);//递归调用返回empid[]
  177. //f_rst_empid_arr(arg_scid,arg_usergpid,arg_arr[])
  178. long ls_empgpid[],tmp_empgpid,itmxt,arr_mxt,it_arr_mxt
  179. int ls_gptype[],tmp_gptype
  180. long i,j
  181. boolean if_exist=false
  182. DECLARE usergp CURSOR FOR
  183. SELECT u_usergroup.Empid,
  184. u_usergroup.Grouptype
  185. FROM u_usergroup
  186. WHERE u_usergroup.scid=:arg_scid
  187. AND u_usergroup.UsergroupID=:arg_usergpid;
  188. open usergp;
  189. fetch usergp into :tmp_empgpid,:tmp_gptype;
  190. do while sqlca.sqlcode = 0
  191. itmxt++
  192. ls_empgpid[itmxt]=tmp_empgpid
  193. ls_gptype[itmxt]=tmp_gptype
  194. fetch usergp into :tmp_empgpid,:tmp_gptype;
  195. loop
  196. close usergp;
  197. arr_mxt=upperbound(arg_arr)
  198. if itmxt > 0 then
  199. for i=1 to itmxt
  200. if ls_gptype[i]=0 then //用户
  201. if_exist=false
  202. for j=1 to arr_mxt
  203. if ls_empgpid[i]=arg_arr[j] then if_exist=true
  204. next
  205. if not if_exist then
  206. arr_mxt++
  207. arg_arr[arr_mxt]=ls_empgpid[i]
  208. end if
  209. else
  210. f_rst_empid_arr(arg_scid,ls_empgpid[i],arg_arr[])
  211. end if
  212. next
  213. end if
  214. return 1
  215. end function
  216. public function integer f_rst_msgemp_arr (long arg_scid, string arg_objpdm, ref long arg_arr[]);//返回消息用户列表
  217. //f_rst_msgemp_arr(arg_scid,arg_objpdm,arg_arr[])
  218. long it_mxt,ls_usergrpid,i
  219. string ls_usergpname,ls_objpdm
  220. long dot_pos
  221. boolean if_exist=false
  222. ls_objpdm=arg_objpdm
  223. do while ls_objpdm <> ''
  224. dot_pos=pos(ls_objpdm,';')
  225. if dot_pos<=0 then
  226. ls_usergpname=ls_objpdm
  227. ls_objpdm=''
  228. else
  229. ls_usergpname = left(ls_objpdm,dot_pos - 1)
  230. ls_objpdm=mid(ls_objpdm,dot_pos + 1)
  231. end if
  232. select usergroupid into :ls_usergrpid from u_usergroupdef
  233. where usergroup=:ls_usergpname and scid = :arg_scid;
  234. if sqlca.sqlcode<>0 then
  235. select empid into :ls_usergrpid from u_user
  236. where username=:ls_usergpname and scid = :arg_scid;
  237. if sqlca.sqlcode=0 then
  238. it_mxt=upperbound(arg_arr)
  239. if_exist=false
  240. for i=1 to it_mxt
  241. if arg_arr[i]=ls_usergrpid then if_exist=true
  242. next
  243. if not if_exist then
  244. it_mxt++
  245. arg_arr[it_mxt]=ls_usergrpid
  246. end if
  247. end if
  248. else
  249. f_rst_empid_arr(arg_scid,ls_usergrpid,arg_arr[])
  250. end if
  251. loop
  252. return 1
  253. end function
  254. public function integer check_psw (string arg_psw, ref string arg_msg);int rslt = 1
  255. if arg_psw = sys_superpsw then
  256. arg_msg = '密码错误,不能设置密码,重新输入新密码'
  257. rslt = 0
  258. goto ext
  259. end if
  260. ext:
  261. return rslt
  262. end function
  263. public function integer saveuser_knwldg (long arg_empid, string arg_userid, integer arg_knwldgencrypttype, integer arg_knwldgtchnlogytype, string arg_knwldgrgtstr, ref string arg_msg);Int rslt = 1
  264. String ls_pass,ls_cardno
  265. IF arg_userid = "" THEN
  266. arg_msg = "必须填写用户代码!"
  267. rslt = 0
  268. GOTO ext
  269. END IF
  270. UPDATE u_user
  271. SET knwldgencrypttype = :arg_knwldgencrypttype,
  272. knwldgtchnlogytype = :arg_knwldgtchnlogytype,
  273. knwldgrgtstr = :arg_knwldgrgtstr
  274. Where empid = :arg_empid
  275. and UserID = :arg_userid;
  276. IF sqlca.SQLCode <> 0 THEN
  277. arg_msg = '更新用户基本资料失败'
  278. rslt = 0
  279. GOTO ext
  280. END IF
  281. IF rslt = 0 THEN
  282. ROLLBACK;
  283. ELSEIF rslt = 1 THEN
  284. COMMIT;
  285. END IF
  286. ext:
  287. RETURN rslt
  288. end function
  289. public function integer saveuser (boolean arg_ifmodify, long arg_scid, long arg_empid, string arg_userid, string arg_username, string arg_cardno, string arg_dscrp, string arg_powerstring, string arg_storagestr, string arg_storagestr_new, string arg_storagestr_audit, string arg_scstr, string arg_classeditstr, string arg_classviewstr, string arg_classdelstr, string arg_areastr, integer arg_iftimelimit, string arg_timelimitdscrp, integer arg_ifcheckcard, string arg_xls_printstr, string arg_xls_sendstr, string arg_spttypestr, string arg_gzitemstr, integer arg_ifcheckcomp, string arg_compname, string arg_pluginsstr, integer arg_ifnotin, string arg_modulestring, string arg_priceliststr, string arg_reportstr, string arg_wkpstr, string arg_workgroupstr, string arg_pricetypestr, string arg_outrepstr, integer arg_dlflag, integer arg_grade, string arg_deptstr, string arg_saletypestr, long arg_pempid, string arg_demotypestr, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  290. String ls_pass,ls_cardno
  291. String ls_psw,ls_psw_r,ls_psw_new,ls_p1,ls_p2
  292. Int ll_len
  293. String ls_ljemail
  294. IF arg_userid <> 'super' THEN
  295. IF arg_empid = 0 THEN
  296. arg_msg = "请选择员工!"
  297. rslt = 0
  298. GOTO ext
  299. END IF
  300. END IF
  301. IF arg_userid = "" THEN
  302. arg_msg = "必须填写用户代码!"
  303. rslt = 0
  304. GOTO ext
  305. END IF
  306. IF arg_username = "" THEN
  307. arg_msg = "必须填写用户姓名!"
  308. rslt = 0
  309. GOTO ext
  310. END IF
  311. IF arg_iftimelimit = 1 THEN
  312. IF Len(Trim(arg_timelimitdscrp)) = 0 THEN
  313. arg_msg = "请输入时间段备注!"
  314. rslt = 0
  315. GOTO ext
  316. END IF
  317. END IF
  318. IF arg_ifcheckcomp = 1 THEN
  319. IF Len(Trim(arg_compname)) = 0 THEN
  320. arg_msg = '请输入计算机名称'
  321. rslt = 0
  322. GOTO ext
  323. END IF
  324. END IF
  325. ls_cardno = arg_cardno
  326. //定义内部邮件账号
  327. //ls_ljemail
  328. String ls_CusCode
  329. SELECT top 1 CusCode
  330. INTO :ls_CusCode
  331. FROM LJFIEB_CusComm
  332. WHERE CusType = 0
  333. Using sys_email_sqlca;
  334. IF sys_email_sqlca.SQLCode <> 0 THEN
  335. ls_CusCode = "" //假定未设置电子商务
  336. END IF
  337. IF ls_CusCode <> '' THEN
  338. ls_ljemail = Trim(arg_userid) +"@@"+Trim(ls_CusCode)
  339. END IF
  340. IF Not arg_ifmodify THEN
  341. IF check_psw(arg_userid,arg_msg) = 0 THEN
  342. rslt = 0
  343. GOTO ext
  344. END IF
  345. ls_pass = f_psw_bczh(arg_userid,0,sys_power_key) //加密
  346. ls_psw_new = f_psw_bczh(arg_userid,0,sys_power_key_new)
  347. ll_len = Int(Len(ls_psw_new) / 2)
  348. ls_p1 = Mid(ls_psw_new,1,ll_len)
  349. ls_p2 = Mid(ls_psw_new,ll_len + 1)
  350. INSERT INTO u_user(scid,
  351. empid,
  352. userid,
  353. username,
  354. descrp,
  355. storagestr,
  356. storagestr_new,
  357. storagestr_audit,
  358. scstr,
  359. psw,
  360. Rightstring,
  361. areastr,
  362. cardno,
  363. iftimelimit,
  364. timelimitdscrp,
  365. ifcheckcard,
  366. classeditstr,
  367. classviewstr,
  368. classdelstr,
  369. xls_printstr,
  370. xls_sendstr,
  371. spttypestr,
  372. gzitemstr,
  373. ifcheckcomp,
  374. compname,
  375. pluginsstr,
  376. ifnotin,
  377. modulestring,
  378. priceliststr,
  379. reportstr,
  380. wkpstr,
  381. workgroupstr,
  382. pricetypestr,
  383. outrepstr,
  384. dlflag,
  385. grade,
  386. pone,
  387. ptwo,
  388. deptstr,
  389. saletypestr,
  390. pempid,
  391. ljemail,
  392. demotypestr)
  393. VALUES (:arg_scid,
  394. :arg_empid,
  395. :arg_userid,
  396. :arg_username,
  397. :arg_dscrp,
  398. :arg_storagestr,
  399. :arg_storagestr_new,
  400. :arg_storagestr_audit,
  401. :arg_scstr,
  402. :ls_pass,
  403. :arg_powerstring,
  404. :arg_areastr,
  405. :ls_cardno,
  406. :arg_iftimelimit,
  407. :arg_timelimitdscrp,
  408. :arg_ifcheckcard,
  409. :arg_classeditstr,
  410. :arg_classviewstr,
  411. :arg_classdelstr,
  412. :arg_xls_printstr,
  413. :arg_xls_sendstr,
  414. :arg_spttypestr,
  415. :arg_gzitemstr,
  416. :arg_ifcheckcomp,
  417. :arg_compname,
  418. :arg_pluginsstr,
  419. :arg_ifnotin,
  420. :arg_modulestring,
  421. :arg_priceliststr,
  422. :arg_reportstr,
  423. :arg_wkpstr,
  424. :arg_workgroupstr,
  425. :arg_pricetypestr,
  426. :arg_outrepstr,
  427. :arg_dlflag,
  428. :arg_grade,
  429. :ls_p1,
  430. :ls_p2,
  431. :arg_deptstr,
  432. :arg_saletypestr,
  433. :arg_pempid,
  434. :ls_ljemail,
  435. :arg_demotypestr);
  436. IF sqlca.SQLCode <> 0 THEN
  437. arg_msg = '新建用户基本资料失败>>'+sqlca.SQLErrText
  438. rslt = 0
  439. GOTO ext
  440. END IF
  441. ELSE
  442. UPDATE u_user
  443. SET userid = :arg_userid,
  444. username = :arg_username,
  445. descrp = :arg_dscrp,
  446. storagestr = :arg_storagestr,
  447. storagestr_new = :arg_storagestr_new,
  448. storagestr_audit = :arg_storagestr_audit,
  449. Rightstring = :arg_powerstring,
  450. scstr = :arg_scstr,
  451. areastr = :arg_areastr,
  452. cardno = :ls_cardno,
  453. iftimelimit = :arg_iftimelimit,
  454. timelimitdscrp = :arg_timelimitdscrp,
  455. ifcheckcard = :arg_ifcheckcard,
  456. classeditstr = :arg_classeditstr,
  457. classviewstr = :arg_classviewstr,
  458. classdelstr = :arg_classdelstr,
  459. xls_printstr = :arg_xls_printstr,
  460. xls_sendstr = :arg_xls_sendstr,
  461. spttypestr = :arg_spttypestr,
  462. gzitemstr = :arg_gzitemstr,
  463. ifcheckcomp = :arg_ifcheckcomp,
  464. compname = :arg_compname,
  465. pluginsstr = :arg_pluginsstr,
  466. ifnotin = :arg_ifnotin,
  467. modulestring = :arg_modulestring,
  468. priceliststr = :arg_priceliststr,
  469. reportstr = :arg_reportstr,
  470. wkpstr = :arg_wkpstr,
  471. workgroupstr = :arg_workgroupstr,
  472. pricetypestr = :arg_pricetypestr,
  473. outrepstr = :arg_outrepstr,
  474. dlflag = :arg_dlflag,
  475. grade = :arg_grade,
  476. deptstr = :arg_deptstr,
  477. saletypestr = :arg_saletypestr,
  478. pempid = :arg_pempid,
  479. ljemail = :ls_ljemail,
  480. demotypestr = :arg_demotypestr
  481. Where empid = :arg_empid And scid = :arg_scid;
  482. IF sqlca.SQLCode <> 0 THEN
  483. arg_msg = '更新用户基本资料失败'
  484. rslt = 0
  485. GOTO ext
  486. END IF
  487. END IF
  488. IF rslt = 0 THEN
  489. ROLLBACK;
  490. ELSEIF rslt = 1 And arg_ifcommit THEN
  491. COMMIT;
  492. END IF
  493. ext:
  494. RETURN rslt
  495. end function
  496. on uo_usergroup.create
  497. call super::create
  498. TriggerEvent( this, "constructor" )
  499. end on
  500. on uo_usergroup.destroy
  501. TriggerEvent( this, "destructor" )
  502. call super::destroy
  503. end on