uo_custdef.sru 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. $PBExportHeader$uo_custdef.sru
  2. forward
  3. global type uo_custdef from nonvisualobject
  4. end type
  5. type s_cust_rep from structure within uo_custdef
  6. end type
  7. end forward
  8. type s_cust_rep from structure
  9. long repid
  10. long cusid
  11. string repname
  12. string duty
  13. string sex
  14. string officetel
  15. string handtel
  16. string faxno
  17. string email
  18. string dscrp
  19. end type
  20. global type uo_custdef from nonvisualobject
  21. end type
  22. global uo_custdef uo_custdef
  23. type variables
  24. public protectedwrite long cusid //进仓单表自动增量id
  25. public protectedwrite datetime opdate //建立时间,自动
  26. public protectedwrite string opemp //建立操作员
  27. s_custom s_cust
  28. boolean if_getid_ture=false
  29. transaction commit_transaction //数据commit事务
  30. PRIVATE:
  31. s_cust_rep custmx[] //明细结构数组
  32. long it_mxbt=0 //明细结构数组末指针
  33. boolean it_newbegin=false //新建标志
  34. boolean it_updatebegin=false //修改标志
  35. end variables
  36. forward prototypes
  37. public function integer p_reset ()
  38. public function integer p_getinfo (long arg_cusid, ref string arg_msg)
  39. public function integer save (boolean arg_ifcommit, ref string arg_msg)
  40. public function integer newbegin (long arg_cusid)
  41. public function integer updatebegin (long arg_cusid, ref string arg_msg)
  42. public function integer del (long arg_cusid, string arg_cuscode, ref string arg_msg, boolean arg_ifcommit)
  43. public function integer p_clearmx ()
  44. public function integer getinfo (long arg_cusid, ref string arg_msg)
  45. public function integer uof_cust_score (long arg_cusid, decimal arg_score, ref string arg_msg, boolean arg_ifcommit)
  46. public function integer uof_update_member (long arg_cusid, ref string arg_msg, boolean arg_ifcommit)
  47. public function integer uof_update_state (long arg_cusid, integer arg_state, ref string arg_msg, boolean arg_ifcommit)
  48. public function integer uof_audit_cust_rq (long arg_rqid, ref string arg_msg, boolean arg_ifcommit)
  49. public function integer uof_c_audit_cust_rq (long arg_rqid, ref string arg_msg, boolean arg_ifcommit)
  50. public function integer uof_add_cust_rq (long arg_cusid, string arg_custype, datetime arg_rqdate, string arg_dscrp, ref string arg_msg, boolean arg_ifcommit)
  51. public function integer acceptmx (long arg_repid, long arg_cusid, string arg_repname, string arg_duty, string arg_sex, string arg_officetel, string arg_handtel, string arg_faxno, string arg_email, string arg_dscrp, ref string arg_msg)
  52. end prototypes
  53. public function integer p_reset ();//int p_reset()
  54. s_cust.cuscode = ''
  55. s_cust.name = ''
  56. s_cust.custype = ''
  57. s_cust.rep = ''
  58. s_cust.tele = ''
  59. s_cust.tele1 = ''
  60. s_cust.bank = ''
  61. s_cust.cunt = ''
  62. s_cust.address = ''
  63. s_cust.code = ''
  64. s_cust.dscrp = ''
  65. s_cust.faxno = ''
  66. s_cust.maxmtnum = 0
  67. s_cust.pricelistid =0
  68. s_cust.inuse =1
  69. s_cust.cusareaid = 0
  70. s_cust.cusareaname = ''
  71. s_cust.areaname = ''
  72. s_cust.email = ''
  73. s_cust.givebackrate = 0
  74. s_cust.freight = ''
  75. s_cust.freight_tele = ''
  76. it_newbegin=false
  77. it_updatebegin=false
  78. //清除明细
  79. p_clearmx()
  80. return 1
  81. end function
  82. public function integer p_getinfo (long arg_cusid, ref string arg_msg);//p_getinfo(arg_scid,arg_inwareid,arg_msg)
  83. //0 失败 1成功
  84. Int rslt = 1
  85. IF arg_cusid <= 0 THEN
  86. rslt = 0
  87. arG_MSG = "非法客户唯一码"
  88. GOTO ext
  89. END IF
  90. SELECT cuscode,
  91. name,
  92. custype,
  93. rep,
  94. tele,
  95. tele1,
  96. bank,
  97. cunt,
  98. address,
  99. code,
  100. dscrp,
  101. faxno,
  102. maxmtnum,
  103. pricelistid,
  104. inuse,
  105. cusareaid,
  106. cusareaname,
  107. areaname,
  108. email,
  109. givebackrate,
  110. freight,
  111. freight_tele,
  112. lsflag,
  113. bhflag
  114. INTO :s_cust.cuscode,
  115. :s_cust.name,
  116. :s_cust.custype,
  117. :s_cust.rep,
  118. :s_cust.tele,
  119. :s_cust.tele1,
  120. :s_cust.bank,
  121. :s_cust.cunt,
  122. :s_cust.address,
  123. :s_cust.code,
  124. :s_cust.dscrp,
  125. :s_cust.faxno,
  126. :s_cust.maxmtnum,
  127. :s_cust.pricelistid,
  128. :s_cust.inuse,
  129. :s_cust.cusareaid,
  130. :s_cust.cusareaname,
  131. :s_cust.areaname,
  132. :s_cust.email,
  133. :s_cust.givebackrate,
  134. :s_cust.freight,
  135. :s_cust.freight_tele,
  136. :s_cust.lsflag,
  137. :s_cust.bhflag
  138. FROM u_cust
  139. Where cusid = :arg_cusid Using commit_transaction;
  140. IF commit_transaction.SQLCode <> 0 THEN
  141. rslt = 0
  142. IF Pos(Lower(commit_transaction.SQLErrText),'more than') > 0 THEN
  143. arG_MSG = '查询操作失败,查询数据返回值多于一个'
  144. ELSE
  145. arG_MSG = "查询操作失败(错误客户唯一码)"
  146. END IF
  147. GOTO ext
  148. END IF
  149. cusid = arg_cusid
  150. ext:
  151. IF rslt = 0 THEN p_reset()
  152. RETURN rslt
  153. end function
  154. public function integer save (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,i
  155. DateTime server_dt
  156. Long ls_newid
  157. Long ls_cusid
  158. IF IsNull(s_cust.cuscode) THEN s_cust.cuscode = ''
  159. IF IsNull(s_cust.Name) THEN s_cust.Name = ''
  160. IF IsNull(s_cust.custype) THEN s_cust.custype = ''
  161. IF IsNull(s_cust.rep) THEN s_cust.rep = ''
  162. IF IsNull(s_cust.tele) THEN s_cust.tele = ''
  163. IF IsNull(s_cust.bank) THEN s_cust.bank = ''
  164. IF IsNull(s_cust.tele1) THEN s_cust.tele1 = ''
  165. IF IsNull(s_cust.cunt) THEN s_cust.cunt = ''
  166. IF IsNull(s_cust.Address) THEN s_cust.Address = ''
  167. IF IsNull(s_cust.code) THEN s_cust.code = ''
  168. IF IsNull(s_cust.dscrp) THEN s_cust.dscrp = ''
  169. IF IsNull(s_cust.faxno) THEN s_cust.faxno = ''
  170. IF IsNull(s_cust.maxmtnum) THEN s_cust.maxmtnum = 0
  171. IF IsNull(s_cust.pricelistid) THEN s_cust.pricelistid = 0
  172. IF IsNull(s_cust.inuse) THEN s_cust.inuse = 1
  173. IF IsNull(s_cust.cusareaid) THEN s_cust.cusareaid = 0
  174. IF IsNull(s_cust.cusareaname) THEN s_cust.cusareaname = ''
  175. IF IsNull(s_cust.areaname) THEN s_cust.areaname = ''
  176. IF IsNull(s_cust.email) THEN s_cust.email = ''
  177. IF IsNull(s_cust.givebackrate) THEN s_cust.givebackrate = 0
  178. IF IsNull(s_cust.freight) THEN s_cust.freight = ''
  179. IF IsNull(s_cust.freight_tele) THEN s_cust.freight_tele = ''
  180. IF IsNull(s_cust.freight_address) THEN s_cust.freight_address = ''
  181. IF IsNull(s_cust.lsflag) THEN s_cust.lsflag = 0
  182. IF IsNull(s_cust.grade) THEN s_cust.grade = ''
  183. IF IsNull(s_cust.memberid) THEN s_cust.memberid = 0
  184. IF IsNull(s_cust.score) THEN s_cust.score = 0
  185. IF IsNull(s_cust.pricelistid) THEN s_cust.pricelistid = 0
  186. IF IsNull(s_cust.upname) THEN s_cust.upname = ''
  187. IF IsNull(s_cust.industry) THEN s_cust.industry = ''
  188. IF IsNull(s_cust.bhflag) THEN s_cust.bhflag = 0
  189. IF IsNull(s_cust.tele_sms) THEN s_cust.tele_sms = ''
  190. IF IsNull(s_cust.banktypeid) THEN s_cust.banktypeid = 0
  191. IF IsNull(s_cust.tax) THEN s_cust.tax = 0
  192. IF IsNull(s_cust.bmstday) THEN s_cust.bmstday = 0
  193. IF it_newbegin = False And it_updatebegin = False THEN
  194. rslt = 0
  195. arg_msg = "非编辑状态不可以提交"
  196. GOTO ext
  197. END IF
  198. SELECT Top 1 getdate() Into :server_dt From u_user Using commit_transaction ;
  199. //取得系统时间,借用操作员表
  200. IF commit_transaction.SQLCode <> 0 THEN
  201. rslt = 0
  202. arg_msg = "查询操作失败,日期 "
  203. GOTO ext
  204. END IF
  205. ////////////////////////////////////////////// //开始区分:新建/更新 处理
  206. IF cusid = 0 THEN //新建
  207. ls_newid = f_sys_scidentity(0,"u_Cust","cusid",arg_msg,if_getid_ture,commit_transaction)
  208. IF ls_newid <= 0 THEN
  209. rslt = 0
  210. GOTO ext
  211. END IF
  212. INSERT INTO u_cust
  213. (cusid,
  214. cuscode,
  215. name,
  216. custype,
  217. rep,
  218. tele,
  219. tele1,
  220. bank,
  221. cunt,
  222. address,
  223. code,
  224. dscrp,
  225. faxno,
  226. maxmtnum,
  227. inuse,
  228. opdate,
  229. opemp,
  230. cusareaid,
  231. cusareaname,
  232. areaname,
  233. email,
  234. givebackrate,
  235. freight,
  236. freight_tele,
  237. freight_address,
  238. lsflag,
  239. memberid,
  240. score,
  241. pricelistid,
  242. banktypeid,
  243. tele_sms ,
  244. upname,
  245. industry,
  246. grade,
  247. bhflag,
  248. tax,
  249. bmstday)
  250. VALUES
  251. (:ls_newid,
  252. :s_cust.cuscode,
  253. :s_cust.name,
  254. :s_cust.custype,
  255. :s_cust.rep,
  256. :s_cust.tele,
  257. :s_cust.tele1,
  258. :s_cust.bank,
  259. :s_cust.cunt,
  260. :s_cust.address,
  261. :s_cust.code,
  262. :s_cust.dscrp,
  263. :s_cust.faxno,
  264. :s_cust.maxmtnum,
  265. :s_cust.inuse,
  266. :server_dt,
  267. :publ_operator,
  268. :s_cust.cusareaid,
  269. :s_cust.cusareaname,
  270. :s_cust.areaname,
  271. :s_cust.email,
  272. :s_cust.givebackrate,
  273. :s_cust.freight,
  274. :s_cust.freight_tele,
  275. :s_cust.freight_address,
  276. :s_cust.lsflag,
  277. :s_cust.memberid,
  278. :s_cust.score,
  279. :s_cust.pricelistid,
  280. :s_cust.banktypeid,
  281. :s_cust.tele_sms ,
  282. :s_cust.upname,
  283. :s_cust.industry,
  284. :s_cust.grade,
  285. :s_cust.bhflag,
  286. :s_cust.tax,
  287. :s_cust.bmstday) Using commit_transaction ;
  288. IF commit_transaction.SQLCode <> 0 THEN
  289. rslt = 0
  290. IF Pos(Lower(commit_transaction.SQLErrText),'pk_u_cust') > 0 THEN
  291. arg_msg = '插入操作失败,关键字客户ID重复'
  292. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'ix_u_cust') > 0 THEN
  293. arg_msg = '插入操作失败,客户名称重复'
  294. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'i_cus_code') > 0 THEN
  295. arg_msg = '插入操作失败,客户编号重复'
  296. ELSE
  297. arg_msg = "因网络或其它原因导致插入操作失败"+"~n"+commit_transaction.SQLErrText
  298. END IF
  299. GOTO ext
  300. END IF
  301. //读取新cusid
  302. cusid = ls_newid
  303. ELSE //////////////////////////////////////////////// //更新
  304. UPDATE u_cust
  305. SET cuscode = :s_cust.cuscode,
  306. name = :s_cust.name,
  307. custype = :s_cust.custype,
  308. rep = :s_cust.rep,
  309. tele = :s_cust.tele,
  310. tele1 = :s_cust.tele1,
  311. bank = :s_cust.bank,
  312. cunt = :s_cust.cunt,
  313. address = :s_cust.address,
  314. code = :s_cust.code,
  315. dscrp = :s_cust.dscrp,
  316. faxno = :s_cust.faxno,
  317. maxmtnum = :s_cust.maxmtnum,
  318. inuse = :s_cust.inuse,
  319. cusareaid = :s_cust.cusareaid,
  320. cusareaname = :s_cust.cusareaname,
  321. areaname = :s_cust.areaname,
  322. email = :s_cust.email,
  323. givebackrate = :s_cust.givebackrate,
  324. freight = :s_cust.freight,
  325. freight_tele = :s_cust.freight_tele,
  326. freight_address = :s_cust.freight_address,
  327. lsflag = :s_cust.lsflag,
  328. memberid = :s_cust.memberid,
  329. score = :s_cust.score,
  330. pricelistid = :s_cust.pricelistid,
  331. banktypeid = :s_cust.banktypeid,
  332. tele_sms = :s_cust.tele_sms ,
  333. upname = :s_cust.upname,
  334. industry = :s_cust.industry,
  335. grade = :s_cust.grade,
  336. bhflag = :s_cust.bhflag,
  337. tax = :s_cust.tax,
  338. moddate=:server_dt,
  339. modemp=:publ_operator,
  340. bmstday=:s_cust.bmstday
  341. Where cusid = :cusid Using commit_transaction;
  342. IF commit_transaction.SQLCode <> 0 Or commit_transaction.SQLNRows <= 0 THEN
  343. rslt = 0
  344. IF Pos(Lower(commit_transaction.SQLErrText),'pk_u_cust') > 0 THEN
  345. arg_msg = '更新操作失败,关键字客户ID重复'
  346. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'ix_u_cust') > 0 THEN
  347. arg_msg = '更新操作失败,客户名称重复'
  348. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'i_cus_code') > 0 THEN
  349. arg_msg = '更新操作失败,客户编号重复'
  350. ELSE
  351. arg_msg = "因网络或其它原因导致更新操作失败"+"~n"+commit_transaction.SQLErrText
  352. END IF
  353. GOTO ext
  354. END IF
  355. //删除原有明细
  356. DELETE FROM u_cust_rep
  357. Where u_cust_rep.cusid = :cusid Using commit_transaction;
  358. IF commit_transaction.SQLCode <> 0 THEN
  359. rslt = 0
  360. arg_msg = "删除客户联系人明细操作失败"+"~n"+commit_transaction.SQLErrText
  361. GOTO ext
  362. END IF
  363. END IF
  364. FOR i = 1 To it_mxbt
  365. INSERT INTO u_cust_rep
  366. (repid,
  367. cusid,
  368. repname,
  369. duty,
  370. sex,
  371. officetel,
  372. handtel,
  373. faxno,
  374. email,
  375. dscrp)
  376. VALUES (
  377. :custmx[i].repid,
  378. :cusid,
  379. :custmx[i].repname,
  380. :custmx[i].duty,
  381. :custmx[i].sex,
  382. :custmx[i].officetel,
  383. :custmx[i].handtel,
  384. :custmx[i].faxno,
  385. :custmx[i].email,
  386. :custmx[i].dscrp
  387. ) Using commit_transaction;
  388. IF commit_transaction.SQLCode <> 0 THEN
  389. IF it_newbegin THEN cusid = 0 //cusid
  390. rslt = 0
  391. IF Pos(Lower(commit_transaction.SQLErrText),'pk_u_cust_rep') > 0 THEN
  392. arg_msg = '插入明细操作失败,关键字客户ID、联系人ID重复'
  393. ELSEIF Pos(Lower(commit_transaction.SQLErrText),'ix_u_cust_rep') > 0 THEN
  394. arg_msg = '插入明细操作失败,联系人名称重复'
  395. ELSE
  396. arg_msg = "因网络或其它原因导致插入明细操作失败"+"~n"+commit_transaction.SQLErrText
  397. END IF
  398. GOTO ext
  399. END IF
  400. NEXT
  401. it_newbegin = False
  402. it_updatebegin = False
  403. ext:
  404. IF rslt = 0 THEN
  405. ROLLBACK Using commit_transaction;
  406. ELSEIF rslt = 1 And arg_ifcommit THEN
  407. COMMIT Using commit_transaction;
  408. END IF
  409. arg_msg = '客户资料,'+ arg_msg
  410. RETURN rslt
  411. end function
  412. public function integer newbegin (long arg_cusid);long rslt = 1
  413. it_newbegin =true
  414. it_updatebegin =false
  415. cusid = arg_cusid
  416. return rslt
  417. end function
  418. public function integer updatebegin (long arg_cusid, ref string arg_msg);long rslt=1
  419. if arg_cusid<=0 then
  420. rslt=0
  421. arg_msg = '错误客户唯一码'
  422. goto ext
  423. end if
  424. rslt=p_getinfo(arg_cusid,arg_msg)
  425. if rslt=0 then goto ext
  426. cusid=arg_cusid
  427. it_newbegin=false
  428. it_updatebegin=true
  429. p_clearmx() //清除明细
  430. ext:
  431. if rslt=0 then p_reset()
  432. arg_msg = '客户资料,'+ arg_msg
  433. return rslt
  434. end function
  435. public function integer del (long arg_cusid, string arg_cuscode, ref string arg_msg, boolean arg_ifcommit);
  436. Int rslt = 1
  437. Long ls_long
  438. IF arg_cusid = 0 THEN
  439. rslt = 0
  440. arg_msg = "没有删除对象,操作取消"
  441. GOTO ext
  442. END IF
  443. ls_long = 0
  444. SELECT count(*) Into :ls_long From u_saletask Where cusid = :arg_cusid Using commit_transaction;
  445. IF commit_transaction.SQLCode <> 0 THEN
  446. rslt = 0
  447. arg_msg = "数据查询操作失败!(请重试!)"
  448. GOTO ext
  449. END IF
  450. IF ls_long > 0 THEN
  451. rslt = 0
  452. arg_msg = "该资料已经使用于订货单记录,不可以删除!"
  453. GOTO ext
  454. END IF
  455. ls_long = 0
  456. SELECT COUNT(*) Into :ls_long From u_outware Where u_outware.cusid = :arg_cusid Using commit_transaction;
  457. IF commit_transaction.SQLCode <> 0 THEN
  458. rslt = 0
  459. arg_msg = "数据查询操作失败!(请重试!)"
  460. GOTO ext
  461. END IF
  462. IF ls_long > 0 THEN
  463. rslt = 0
  464. arg_msg = "该资料已经使用于出仓记录,不可以删除!"
  465. GOTO ext
  466. END IF
  467. ls_long = 0
  468. SELECT COUNT(*) Into :ls_long From u_bmsttake Where cusid = :arg_cusid Using commit_transaction;
  469. IF commit_transaction.SQLCode <> 0 THEN
  470. rslt = 0
  471. arg_msg = "数据查询操作失败!(请重试!)"
  472. GOTO ext
  473. END IF
  474. IF ls_long > 0 THEN
  475. rslt = 0
  476. arg_msg = "该资料已经使用于应收帐,不可以删除!"
  477. GOTO ext
  478. END IF
  479. DELETE FROM u_cust
  480. Where cusid = :arg_cusid Using commit_transaction;
  481. IF commit_transaction.SQLCode <> 0 THEN
  482. rslt = 0
  483. arg_msg = "删除客户操作失败"+"~n"+commit_transaction.SQLErrText
  484. GOTO ext
  485. END IF
  486. DELETE FROM u_cust_rep
  487. Where cusid = :arg_cusid Using commit_transaction;
  488. IF commit_transaction.SQLCode <> 0 THEN
  489. rslt = 0
  490. arg_msg = "删除客户联系人操作失败"+"~n"+commit_transaction.SQLErrText
  491. GOTO ext
  492. END IF
  493. IF f_setsysoplog('定义资料','客户定义资料删除,id:'+String(arg_cusid)+',code:'+arg_cuscode,arg_msg,False) = 0 THEN
  494. rslt = 0
  495. GOTO ext
  496. END IF
  497. it_newbegin = False
  498. it_updatebegin = False
  499. ext:
  500. IF rslt = 0 THEN
  501. ROLLBACK Using commit_transaction;
  502. ELSEIF rslt = 1 And arg_ifcommit THEN
  503. COMMIT Using commit_transaction;
  504. END IF
  505. p_reset()
  506. arg_msg = '客户资料,'+ arg_msg
  507. RETURN rslt
  508. end function
  509. public function integer p_clearmx ();//int p_clearmx()
  510. //清除明细
  511. it_mxbt=0
  512. return 1
  513. end function
  514. public function integer getinfo (long arg_cusid, ref string arg_msg);//getinfo(arg_scid,arg_cusid,arg_msg)
  515. //0 失败 1成功
  516. Int rslt = 1,i = 1,no_mxcheck = 0
  517. IF arg_cusid <= 0 THEN
  518. rslt = 0
  519. arg_msg = "非法客户唯一码"
  520. GOTO ext
  521. END IF
  522. rslt = p_getinfo(arg_cusid,arg_msg)
  523. IF rslt = 0 THEN GOTO ext
  524. //用游标读取明细
  525. DECLARE cur_inwaermx CURSOR FOR
  526. SELECT repid, cusid, repname, duty, sex, officetel, handtel, faxno, email, dscrp
  527. FROM u_cust_rep
  528. WHERE u_cust_rep.cusid = :arg_cusid USING commit_transaction;
  529. OPEN cur_inwaermx;
  530. FETCH cur_inwaermx INTO :custmx[i].repid,:custmx[i].cusid,
  531. :custmx[i].repname,:custmx[i].duty,:custmx[i].sex,
  532. :custmx[i].officetel,:custmx[i].handtel,:custmx[i].faxno,
  533. :custmx[i].email,:custmx[i].dscrp;
  534. DO WHILE commit_transaction.SQLCode = 0
  535. i++
  536. FETCH cur_inwaermx INTO :custmx[i].repid,:custmx[i].cusid,
  537. :custmx[i].repname,:custmx[i].duty,:custmx[i].sex,
  538. :custmx[i].officetel,:custmx[i].handtel,:custmx[i].faxno,
  539. :custmx[i].email,:custmx[i].dscrp;
  540. LOOP
  541. CLOSE cur_inwaermx;
  542. //检验明细是否读入完整
  543. SELECT count(*) INTO :no_mxcheck
  544. FROM u_cust_rep
  545. WHERE u_cust_rep.cusid = :arg_cusid USING commit_transaction;
  546. IF commit_transaction.SQLCode <> 0 THEN
  547. rslt = 0
  548. arg_msg = "查询操作失败,客户表联系人明细"
  549. GOTO ext
  550. END IF
  551. IF i <> (no_mxcheck+1) THEN
  552. rslt = 0
  553. arg_msg = "查询操作失败,客户表联系人明细"
  554. GOTO ext
  555. END IF
  556. cusid = arg_cusid
  557. it_mxbt = i - 1
  558. it_newbegin = FALSE
  559. it_updatebegin = FALSE
  560. ext:
  561. IF rslt = 0 THEN p_reset()
  562. RETURN rslt
  563. end function
  564. public function integer uof_cust_score (long arg_cusid, decimal arg_score, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  565. Decimal ld_score
  566. IF arg_score < 0 THEN
  567. SELECT score - exchangescore INTO :ld_score
  568. FROM u_cust
  569. Where cusid = :arg_cusid;
  570. IF commit_transaction.SQLCode <> 0 THEN
  571. IF Pos(Lower(commit_transaction.SQLErrText),'more than') > 0 THEN
  572. arg_msg = '查询客户积分失败,查询数据返回值多于一个'
  573. ELSE
  574. arg_msg = '查询客户积分失败,'+commit_transaction.SQLErrText
  575. END IF
  576. rslt = 0
  577. GOTO ext
  578. END IF
  579. IF arg_score + ld_score < 0 THEN
  580. arg_msg = '客户积分只有:'+String(ld_score,'#,##0.##')+',不能兑换:'+String(Abs(arg_score),'#,##0.##')
  581. rslt = 0
  582. GOTO ext
  583. END IF
  584. UPDATE u_cust
  585. SET exchangescore = exchangescore + :arg_score
  586. Where cusid = :arg_cusid;
  587. IF commit_transaction.SQLCode <> 0 THEN
  588. arg_msg = '更新客户积分失败,'+commit_transaction.SQLErrText
  589. rslt = 0
  590. GOTO ext
  591. END IF
  592. ELSE
  593. UPDATE u_cust
  594. SET score = score + :arg_score
  595. Where cusid = :arg_cusid;
  596. IF commit_transaction.SQLCode <> 0 THEN
  597. arg_msg = '更新客户积分失败,'+commit_transaction.SQLErrText
  598. rslt = 0
  599. GOTO ext
  600. END IF
  601. IF sys_autoupdate_member = 1 THEN
  602. ////会员自动升级
  603. IF uof_update_member(arg_cusid,arg_msg,arg_ifcommit) = 0 THEN
  604. rslt = 0
  605. GOTO ext
  606. END IF
  607. END IF
  608. END IF
  609. ext:
  610. IF rslt = 0 THEN
  611. ROLLBACK;
  612. ELSEIF rslt = 1 AND arg_ifcommit THEN
  613. COMMIT;
  614. END IF
  615. arg_msg = '客户资料,'+ arg_msg
  616. RETURN rslt
  617. end function
  618. public function integer uof_update_member (long arg_cusid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  619. Long ll_memberid
  620. Dec ld_cusscore
  621. SELECT memberid ,
  622. score
  623. INTO :ll_memberid,
  624. :ld_cusscore
  625. FROM u_cust
  626. Where cusid = :arg_cusid;
  627. IF commit_transaction.SQLCode <> 0 THEN
  628. IF Pos(Lower(commit_transaction.SQLErrText),'more than') > 0 THEN
  629. arg_msg = '查询客户会员类型失败,查询数据返回值多于一个'
  630. ELSE
  631. arg_msg = '查询客户会员类型失败,'+commit_transaction.SQLErrText
  632. END IF
  633. rslt = 0
  634. GOTO ext
  635. END IF
  636. if ll_memberid = 0 then goto ext
  637. Decimal ld_score[]
  638. Long ld_memberid[]
  639. long ld_Pricelistid[]
  640. Long i = 1,NO_MXCHECK
  641. DECLARE CUR_member CURSOR FOR
  642. SELECT u_cust_member.updatescore,
  643. u_cust_member.memberid,
  644. u_cust_member.Pricelistid
  645. FROM u_cust_member
  646. Order By updatescore Desc;
  647. OPEN CUR_member;
  648. FETCH CUR_member INTO :ld_score[i],:ld_memberid[i],:ld_Pricelistid[i];
  649. DO WHILE commit_transaction.SQLCode = 0
  650. i++
  651. FETCH CUR_member INTO :ld_score[i],:ld_memberid[i],:ld_Pricelistid[i];
  652. LOOP
  653. CLOSE CUR_member;
  654. //检验明细是否读入完整
  655. SELECT COUNT(*) INTO :NO_MXCHECK
  656. FROM u_cust_member ;
  657. IF commit_transaction.SQLCode <> 0 THEN
  658. rslt = 0
  659. arg_msg = "查询操作失败,会员类型数量"
  660. GOTO ext
  661. END IF
  662. IF i <> (NO_MXCHECK+1) THEN
  663. rslt = 0
  664. arg_msg = "查询操作失败,会员类型数量"
  665. GOTO ext
  666. END IF
  667. FOR i = 1 TO NO_MXCHECK
  668. IF ld_score[i] > 0 AND ld_cusscore >= ld_score[i] THEN
  669. UPDATE u_cust
  670. SET memberid = :ld_memberid[i],
  671. Pricelistid = :ld_Pricelistid[i]
  672. Where u_cust.cusid = :arg_cusid;
  673. IF commit_transaction.SQLCode <> 0 THEN
  674. rslt = 0
  675. arg_msg = "更新客户会员类型操作失败"
  676. GOTO ext
  677. END IF
  678. EXIT
  679. END IF
  680. NEXT
  681. ext:
  682. IF rslt = 0 THEN
  683. ROLLBACK;
  684. ELSEIF rslt = 1 AND arg_ifcommit THEN
  685. COMMIT;
  686. END IF
  687. arg_msg = '客户资料,'+ arg_msg
  688. RETURN rslt
  689. end function
  690. public function integer uof_update_state (long arg_cusid, integer arg_state, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  691. Int li_state
  692. SELECT state
  693. INTO :li_state
  694. FROM u_cust
  695. Where cusid = :arg_cusid;
  696. IF sqlca.SQLCode <> 0 THEN
  697. rslt = 0
  698. arg_msg = "查询客户类型操作失败"
  699. GOTO ext
  700. END IF
  701. IF arg_state = 1 THEN //申请为正式客户
  702. IF li_state <> 3 THEN
  703. rslt = 0
  704. arg_msg = "非准客户不能审核为正式客户"
  705. GOTO ext
  706. END IF
  707. ELSEIF arg_state = 3 THEN //申请为准客户
  708. IF li_state <> 0 THEN
  709. rslt = 0
  710. arg_msg = "非公共客户不能申请准客户"
  711. GOTO ext
  712. END IF
  713. END IF
  714. UPDATE u_cust
  715. SET state = :arg_state
  716. Where cusid = :arg_cusid;
  717. IF sqlca.SQLCode <> 0 THEN
  718. rslt = 0
  719. arg_msg = "更新客户类型操作失败,"+sqlca.sqlerrtext
  720. GOTO ext
  721. END IF
  722. ext:
  723. IF rslt = 0 THEN
  724. ROLLBACK;
  725. ELSEIF rslt = 1 And arg_ifcommit THEN
  726. COMMIT;
  727. END IF
  728. arg_msg = '客户资料,'+ arg_msg
  729. RETURN rslt
  730. end function
  731. public function integer uof_audit_cust_rq (long arg_rqid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  732. Long cnt
  733. Long ll_cusid
  734. String ls_custype
  735. Int li_flag
  736. SELECT cusid, custype, flag
  737. INTO :ll_cusid, :ls_custype, :li_flag
  738. FROM u_cust_rq
  739. Where rqid = :arg_rqid;
  740. IF sqlca.SQLCode <> 0 THEN
  741. rslt = 0
  742. arg_msg = "查询客户申请状况操作失败"
  743. GOTO ext
  744. END IF
  745. IF li_flag = 1 THEN
  746. rslt = 0
  747. arg_msg = "客户申请已审核"
  748. GOTO ext
  749. END IF
  750. UPDATE u_cust_rq
  751. SET flag = 1,
  752. auditdate = getdate(),
  753. auditemp = :publ_operator
  754. WHERE rqid = :arg_rqid
  755. And flag = 0;
  756. IF sqlca.SQLCode <> 0 THEN
  757. rslt = 0
  758. arg_msg = "审核客户申请状况操作失败"
  759. GOTO ext
  760. ELSEIF sqlca.SQLNRows = 0 THEN
  761. rslt = 0
  762. arg_msg = "审核客户申请状况操作失败,正在审核中......"
  763. GOTO ext
  764. END IF
  765. ext:
  766. IF rslt = 0 THEN
  767. ROLLBACK;
  768. ELSEIF rslt = 1 And arg_ifcommit THEN
  769. COMMIT;
  770. END IF
  771. arg_msg = '客户资料,'+ arg_msg
  772. RETURN rslt
  773. end function
  774. public function integer uof_c_audit_cust_rq (long arg_rqid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  775. Long cnt
  776. Long ll_cusid
  777. String ls_custype
  778. Int li_flag
  779. SELECT cusid, custype, flag
  780. INTO :ll_cusid, :ls_custype, :li_flag
  781. FROM u_cust_rq
  782. Where rqid = :arg_rqid;
  783. IF sqlca.SQLCode <> 0 THEN
  784. rslt = 0
  785. arg_msg = "查询客户申请状况操作失败"
  786. GOTO ext
  787. END IF
  788. IF li_flag = 0 THEN
  789. rslt = 0
  790. arg_msg = "客户申请未审核"
  791. GOTO ext
  792. END IF
  793. UPDATE u_cust_rq
  794. SET flag = 0,
  795. auditdate = null,
  796. auditemp = ''
  797. WHERE rqid = :arg_rqid
  798. And flag = 1;
  799. IF sqlca.SQLCode <> 0 THEN
  800. rslt = 0
  801. arg_msg = "撤审客户申请状况操作失败"
  802. GOTO ext
  803. ELSEIF sqlca.SQLNRows = 0 THEN
  804. rslt = 0
  805. arg_msg = "撤审客户申请状况操作失败,正在撤审中......"
  806. GOTO ext
  807. END IF
  808. ext:
  809. IF rslt = 0 THEN
  810. ROLLBACK;
  811. ELSEIF rslt = 1 And arg_ifcommit THEN
  812. COMMIT;
  813. END IF
  814. arg_msg = '客户资料,'+ arg_msg
  815. RETURN rslt
  816. end function
  817. public function integer uof_add_cust_rq (long arg_cusid, string arg_custype, datetime arg_rqdate, string arg_dscrp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  818. Long cnt
  819. Long ll_newid
  820. SELECT count(*)
  821. INTO :cnt
  822. FROM u_cust_rq
  823. WHERE cusid = :arg_cusid
  824. And flag = 0;
  825. IF sqlca.SQLCode <> 0 THEN
  826. rslt = 0
  827. arg_msg = "查询客户申请状况操作失败,"+sqlca.sqlerrtext
  828. GOTO ext
  829. END IF
  830. IF cnt > 0 THEN //未审批的
  831. rslt = 0
  832. arg_msg = "当前客户还有未审批记录,不能申请"
  833. GOTO ext
  834. END IF
  835. ll_newid = f_sys_scidentity(0,"u_cust_rq","rqid",arg_msg,False,sqlca)
  836. IF ll_newid <= 0 THEN
  837. rslt = 0
  838. GOTO ext
  839. END IF
  840. INSERT INTO u_cust_rq
  841. (rqid, cusid, custype, rqdate, dscrp, opdate, opemp)
  842. VALUES
  843. (:ll_newid, :arg_cusid, :arg_custype, :arg_rqdate, :arg_dscrp, getdate(), :publ_operator);
  844. IF sqlca.SQLCode <> 0 THEN
  845. rslt = 0
  846. arg_msg = "插入客户申请状况操作失败,"+sqlca.sqlerrtext
  847. GOTO ext
  848. END IF
  849. IF uof_update_state(arg_cusid, 3, arg_msg, false) = 0 THEN
  850. rslt = 0
  851. GOTO ext
  852. END IF
  853. ext:
  854. IF rslt = 0 THEN
  855. ROLLBACK;
  856. ELSEIF rslt = 1 And arg_ifcommit THEN
  857. COMMIT;
  858. END IF
  859. arg_msg = '客户资料,'+ arg_msg
  860. RETURN rslt
  861. end function
  862. public function integer acceptmx (long arg_repid, long arg_cusid, string arg_repname, string arg_duty, string arg_sex, string arg_officetel, string arg_handtel, string arg_faxno, string arg_email, string arg_dscrp, ref string arg_msg);Long rslt = 1,cnt = 0,ls_i
  863. IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN
  864. rslt = 0
  865. arg_msg = "非编辑状态不可以使用,操作取消"
  866. GOTO ext
  867. END IF
  868. //清除空值
  869. IF IsNull(arg_repid) THEN arg_repid = 0
  870. IF IsNull(arg_cusid) THEN arg_cusid = 0
  871. IF IsNull(arg_repname) THEN arg_repname = ''
  872. IF IsNull(arg_duty) THEN arg_duty = ''
  873. IF IsNull(arg_sex) THEN arg_sex = ''
  874. IF IsNull(arg_officetel) THEN arg_officetel = ''
  875. IF IsNull(arg_handtel) THEN arg_handtel = ''
  876. IF IsNull(arg_faxno) THEN arg_faxno = ''
  877. IF IsNull(arg_email) THEN arg_email = ''
  878. IF IsNull(arg_dscrp) THEN arg_dscrp = ''
  879. IF arg_repid = 0 THEN
  880. rslt = 1
  881. GOTO ext
  882. END IF
  883. //检查客户id
  884. cnt = 0
  885. SELECT count(*)
  886. INTO :cnt
  887. FROM u_cust
  888. Where cusid = :arg_cusid USING commit_transaction ;
  889. IF commit_transaction.SQLCode <> 0 THEN
  890. rslt = 0
  891. arg_msg = "查询操作失败 "
  892. GOTO ext
  893. END IF
  894. //写入内容
  895. it_mxbt++
  896. custmx[it_mxbt].repid = arg_repid
  897. custmx[it_mxbt].cusid = arg_cusid
  898. custmx[it_mxbt].repname = arg_repname
  899. custmx[it_mxbt].duty = arg_duty
  900. custmx[it_mxbt].sex = arg_sex
  901. custmx[it_mxbt].officetel = arg_officetel
  902. custmx[it_mxbt].handtel = arg_handtel
  903. custmx[it_mxbt].faxno = arg_faxno
  904. custmx[it_mxbt].email = arg_email
  905. custmx[it_mxbt].dscrp = arg_dscrp
  906. ext:
  907. IF rslt = 0 THEN p_clearmx()
  908. arg_msg = '客户资料,'+ arg_msg
  909. Return(rslt)
  910. end function
  911. on uo_custdef.create
  912. call super::create
  913. TriggerEvent( this, "constructor" )
  914. end on
  915. on uo_custdef.destroy
  916. TriggerEvent( this, "destructor" )
  917. call super::destroy
  918. end on