uo_email_box.sru 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. $PBExportHeader$uo_email_box.sru
  2. forward
  3. global type uo_email_box from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_email_box from nonvisualobject
  7. end type
  8. global uo_email_box uo_email_box
  9. type variables
  10. long boxid
  11. string boxname
  12. long isdefault
  13. long mailid
  14. string boxtype
  15. long parentid
  16. long picindex
  17. Transaction commit_tran
  18. Transaction fj_tran
  19. PROTECTEDWRITE string C_inbox = '收件箱'
  20. PROTECTEDWRITE string C_outbox = '发件箱'
  21. PROTECTEDWRITE string C_sentbox = '已发件箱'
  22. PROTECTEDWRITE string C_trunkbox = '废件箱'
  23. PROTECTEDWRITE string C_userDefine = '新邮箱'
  24. end variables
  25. forward prototypes
  26. public function integer uf_newbox (long arg_mailid, long arg_parentid, string arg_name, boolean arg_if_commit, ref string arg_msg)
  27. public function integer p_getinfo (long arg_boxid, ref string arg_msg)
  28. public function integer uf_rename (long arg_boxid, string arg_newname, ref string arg_msg)
  29. public function integer uf_del (long arg_boxid, ref string arg_msg)
  30. end prototypes
  31. public function integer uf_newbox (long arg_mailid, long arg_parentid, string arg_name, boolean arg_if_commit, ref string arg_msg);int rslt = 1
  32. long ll_boxid
  33. ll_boxid = f_sys_scidentity(0,"u_email_box","boxid",arG_MSG,False, commit_tran)
  34. if ll_boxid <= 0 then
  35. rslt = 0
  36. goto ext
  37. end if
  38. long ll_ifdefault
  39. string ls_boxtype
  40. long ll_picindex
  41. if arg_name = C_inbox OR arg_name = C_outbox OR arg_name = C_sentbox OR arg_name = C_trunkbox then
  42. ll_ifdefault = 1
  43. ls_boxtype = arg_name
  44. if arg_name = C_inbox then
  45. ll_picindex = 3
  46. elseif arg_name = C_outbox then
  47. ll_picindex = 4
  48. elseif arg_name = C_sentbox then
  49. ll_picindex = 5
  50. elseif arg_name = C_trunkbox then
  51. ll_picindex = 6
  52. end if
  53. else
  54. ll_ifdefault = 0
  55. ls_boxtype = C_userDefine
  56. ll_picindex = 9
  57. end if
  58. INSERT INTO u_email_box
  59. (boxid
  60. ,boxname
  61. ,isdefault
  62. ,mailid
  63. ,boxtype
  64. ,parentid
  65. ,picindex)
  66. VALUES
  67. (:ll_boxid
  68. ,:arg_name
  69. ,:ll_ifdefault
  70. ,:arg_mailid
  71. ,:ls_boxtype
  72. ,:arg_parentid
  73. ,:ll_picindex) using commit_tran;
  74. if commit_tran.sqlcode <> 0 then
  75. rslt = 0
  76. arg_msg = '新建子目录失败,' + commit_tran.sqlerrtext
  77. goto ext
  78. end if
  79. boxid = ll_boxid
  80. boxname = arg_name
  81. isdefault = ll_ifdefault
  82. mailid = arg_mailid
  83. boxtype = ls_boxtype
  84. parentid = arg_parentid
  85. picindex = ll_picindex
  86. ext:
  87. if rslt = 0 then
  88. rollback using commit_tran;
  89. elseif arg_if_commit then
  90. commit using commit_tran;
  91. end if
  92. return rslt
  93. end function
  94. public function integer p_getinfo (long arg_boxid, ref string arg_msg);int rslt = 1
  95. if arg_boxid <= 0 then
  96. rslt = 0
  97. arg_msg = '非法唯一码'
  98. goto ext
  99. end if
  100. long ll_cnt
  101. SELECT COUNT(0) INTO :ll_cnt FROM u_email_box WHERE boxid = :arg_boxid using commit_tran;
  102. if commit_tran.sqlcode <> 0 then
  103. rslt = 0
  104. arg_msg = '查询邮箱数量失败,' + commit_tran.sqlerrtext
  105. goto ext
  106. end if
  107. if ll_cnt = 0 then
  108. rslt = 0
  109. arg_msg = '邮箱不存在'
  110. goto ext
  111. end if
  112. SELECT boxid
  113. ,boxname
  114. ,isdefault
  115. ,mailid
  116. ,boxtype
  117. ,parentid
  118. ,picindex
  119. INTO :boxid,
  120. :boxname,
  121. :isdefault,
  122. :mailid,
  123. :boxtype,
  124. :parentid,
  125. :picindex
  126. FROM u_email_box
  127. WHERE boxid = :arg_boxid using commit_tran;
  128. if commit_tran.sqlcode <> 0 then
  129. rslt = 0
  130. arg_msg = '查询邮箱资料失败,' + commit_tran.sqlerrtext
  131. goto ext
  132. end if
  133. ext:
  134. return rslt
  135. end function
  136. public function integer uf_rename (long arg_boxid, string arg_newname, ref string arg_msg);int rslt = 1
  137. if p_getinfo(arg_boxid, arg_msg) <> 1 then
  138. rslt = 0
  139. goto ext
  140. end if
  141. if isdefault = 1 then
  142. rslt = 0
  143. arg_msg = '默认邮箱不能重命名'
  144. goto ext
  145. end if
  146. UPDATE u_email_box SET boxname = :arg_newname WHERE boxid = :arg_boxid using commit_tran;
  147. if commit_tran.sqlcode <> 0 then
  148. rslt = 0
  149. arg_msg = '目录重命名失败,' + commit_tran.sqlerrtext
  150. goto ext
  151. end if
  152. boxname = arg_newname
  153. ext:
  154. if rslt = 0 then
  155. rollback using commit_tran;
  156. else
  157. commit using commit_tran;
  158. end if
  159. return rslt
  160. end function
  161. public function integer uf_del (long arg_boxid, ref string arg_msg);int rslt = 1
  162. if p_getinfo(arg_boxid, arg_msg) <> 1 then
  163. rslt = 0
  164. goto ext
  165. end if
  166. long ll_cnt
  167. SELECT COUNT(0) INTO :ll_cnt FROM u_email_msg WHERE boxid = :arg_boxid using fj_tran;
  168. if fj_tran.sqlcode <> 0 then
  169. rslt = 0
  170. arg_msg = '查询邮箱内邮件数量失败,' + fj_tran.sqlerrtext
  171. goto ext
  172. end if
  173. if ll_cnt > 0 then
  174. rslt = 0
  175. arg_msg = '邮箱内含有邮件,不能删除'
  176. goto ext
  177. end if
  178. SELECT COUNT(0) INTO :ll_cnt FROM u_email_box WHERE parentid = :arg_boxid using commit_tran;
  179. if commit_tran.sqlcode <> 0 then
  180. rslt = 0
  181. arg_msg = '查询子邮箱数量失败,' + commit_tran.sqlerrtext
  182. goto ext
  183. end if
  184. if ll_cnt > 0 then
  185. rslt = 0
  186. arg_msg = '邮箱内包含子邮箱,不能删除'
  187. goto ext
  188. end if
  189. if isdefault = 1 then
  190. rslt = 0
  191. arg_msg = '默认邮箱不能删除'
  192. goto ext
  193. end if
  194. DELETE FROM u_email_box WHERE boxid = :arg_boxid using commit_tran;
  195. if commit_tran.sqlcode <> 0 then
  196. rslt = 0
  197. arg_msg = '删除邮箱失败,' + commit_tran.sqlerrtext
  198. goto ext
  199. end if
  200. ext:
  201. if rslt = 0 then
  202. rollback using commit_tran;
  203. else
  204. commit using commit_tran;
  205. end if
  206. return rslt
  207. end function
  208. on uo_email_box.create
  209. call super::create
  210. TriggerEvent( this, "constructor" )
  211. end on
  212. on uo_email_box.destroy
  213. TriggerEvent( this, "destructor" )
  214. call super::destroy
  215. end on