uo_import_mtrlname.sru 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. $PBExportHeader$uo_import_mtrlname.sru
  2. forward
  3. global type uo_import_mtrlname from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_import_mtrlname from nonvisualobject
  7. end type
  8. global uo_import_mtrlname uo_import_mtrlname
  9. forward prototypes
  10. private function string pf_getid (string arg_ctg, datetime arg_dt, boolean if_commit, transaction arg_transaction)
  11. public function integer uf_reset (ref s_import_mtrlname arg_s_import, ref string arg_msg)
  12. public function integer uf_del (long arg_im_type, string arg_im_id, ref string arg_msg, boolean arg_if_commit)
  13. public function integer uf_getinfo (long arg_im_type, string arg_im_id, ref s_import_mtrlname arg_s_import, ref string arg_msg)
  14. public function integer uf_getinfo_dscrp (long arg_im_type, string arg_im_id, ref string arg_dscrp, ref string arg_msg)
  15. public function integer uf_save_dscrp (s_import_mtrlname arg_s_import, ref string arg_msg, boolean arg_if_commit)
  16. public function integer uf_xls_to_import_mtrlcode (string arg_filepath, ref string arg_msg, boolean arg_ifcommit, boolean arg_ignore)
  17. public function integer uf_savemx (long arg_im_type, string arg_im_id, s_import_mtrlnamemx arg_mx[], ref string arg_msg)
  18. public function integer uf_csv_to_import_mtrlcode (string arg_filepath, ref s_import_mtrlname arg_import[], ref string arg_msg)
  19. public function integer uf_save_from_web (s_import_mtrlname arg_s_import, ref string arg_msg, boolean arg_if_commit)
  20. public function integer uf_save (s_import_mtrlname arg_s_import, ref string arg_msg, boolean arg_if_commit)
  21. end prototypes
  22. private function string pf_getid (string arg_ctg, datetime arg_dt, boolean if_commit, transaction arg_transaction);String rslt = ''
  23. Long ll_nmbr
  24. arg_ctg = Upper(arg_ctg)
  25. arg_dt = DateTime(Date(arg_dt), Time(0))
  26. UPDATE u_bsnno_aps
  27. SET nmbr = nmbr + 1
  28. WHERE opDate = :arg_dt
  29. AND typecode = :arg_ctg
  30. AND scid = 0
  31. And status = 0 Using arg_transaction;
  32. IF arg_transaction.SQLCode <> 0 THEN
  33. ROLLBACK Using arg_transaction ;
  34. rslt = "err"
  35. GOTO ext
  36. END IF
  37. IF arg_transaction.SQLNRows = 0 THEN
  38. INSERT INTO u_bsnno_aps(scid, opdate, typecode, nmbr, status)
  39. Values (0, :arg_dt, :arg_ctg, 1, 0) Using arg_transaction;
  40. IF arg_transaction.SQLCode <> 0 THEN
  41. ROLLBACK Using arg_transaction ;
  42. rslt = "err"
  43. GOTO ext
  44. END IF
  45. END IF
  46. SELECT nmbr
  47. INTO :ll_nmbr
  48. FROM u_bsnno_aps
  49. WHERE opDate = :arg_dt
  50. AND typecode = :arg_ctg
  51. AND scid = 0
  52. And status = 0 Using arg_transaction;
  53. IF arg_transaction.SQLCode <> 0 THEN
  54. ROLLBACK Using arg_transaction ;
  55. rslt = "err"
  56. GOTO ext
  57. END IF
  58. rslt = arg_ctg + String(arg_dt, 'yyMMdd') + String(ll_nmbr, '000')
  59. IF rslt = '' THEN rslt = 'err'
  60. IF if_commit And rslt <> "err" THEN
  61. COMMIT Using arg_transaction;
  62. END IF
  63. ext:
  64. RETURN rslt
  65. end function
  66. public function integer uf_reset (ref s_import_mtrlname arg_s_import, ref string arg_msg);Int rslt = 1
  67. IF IsNull(arg_s_import.im_type) THEN arg_s_import.im_type = 0
  68. IF IsNull(arg_s_import.im_id) THEN arg_s_import.im_id = ''
  69. IF IsNull(arg_s_import.mtrlid) THEN arg_s_import.mtrlid = 0
  70. IF IsNull(arg_s_import.eb_num) THEN arg_s_import.eb_num = 0
  71. IF IsNull(arg_s_import.eb_price) THEN arg_s_import.eb_price = 0
  72. IF IsNull(arg_s_import.eb_type) THEN arg_s_import.eb_type = ''
  73. IF IsNull(arg_s_import.eb_stuffStatus) THEN arg_s_import.eb_stuffStatus = ''
  74. IF IsNull(arg_s_import.eb_title) THEN arg_s_import.eb_title = ''
  75. IF IsNull(arg_s_import.eb_dscrp) THEN arg_s_import.eb_dscrp = ''
  76. IF IsNull(arg_s_import.eb_locationstate) THEN arg_s_import.eb_locationstate = ''
  77. IF IsNull(arg_s_import.eb_locationcity) THEN arg_s_import.eb_locationcity = ''
  78. IF IsNull(arg_s_import.eb_cid) THEN arg_s_import.eb_cid = ''
  79. IF IsNull(arg_s_import.numIid) THEN arg_s_import.numIid = ''
  80. IF IsNull(arg_s_import.props) THEN arg_s_import.props = ''
  81. IF IsNull(arg_s_import.im_userid) THEN arg_s_import.im_userid = ''
  82. RETURN rslt
  83. end function
  84. public function integer uf_del (long arg_im_type, string arg_im_id, ref string arg_msg, boolean arg_if_commit);Int rslt = 1
  85. DELETE FROM eb_import_mtrlname
  86. Where im_id = :arg_im_id And im_type = :arg_im_type;
  87. IF sqlca.SQLCode <> 0 THEN
  88. rslt = 0
  89. arg_msg = '删除失败,' + sqlca.SQLErrText
  90. GOTO ext
  91. END IF
  92. ext:
  93. IF arg_if_commit THEN
  94. IF rslt = 1 THEN
  95. COMMIT;
  96. ELSE
  97. ROLLBACK;
  98. END IF
  99. END IF
  100. RETURN rslt
  101. end function
  102. public function integer uf_getinfo (long arg_im_type, string arg_im_id, ref s_import_mtrlname arg_s_import, ref string arg_msg);Int rslt = 1
  103. s_import_mtrlname s_empty
  104. arg_s_import = s_empty
  105. SELECT im_type,
  106. im_id,
  107. mtrlid,
  108. eb_num,
  109. eb_price,
  110. eb_type,
  111. eb_stuffStatus,
  112. eb_title,
  113. eb_dscrp,
  114. eb_locationstate,
  115. eb_locationcity,
  116. eb_cid,
  117. numIid,
  118. props,
  119. im_userid
  120. INTO
  121. :arg_s_import.im_type,
  122. :arg_s_import.im_id,
  123. :arg_s_import.mtrlid,
  124. :arg_s_import.eb_num,
  125. :arg_s_import.eb_price,
  126. :arg_s_import.eb_type,
  127. :arg_s_import.eb_stuffStatus,
  128. :arg_s_import.eb_title,
  129. :arg_s_import.eb_dscrp,
  130. :arg_s_import.eb_locationstate,
  131. :arg_s_import.eb_locationcity,
  132. :arg_s_import.eb_cid,
  133. :arg_s_import.numIid,
  134. :arg_s_import.props,
  135. :arg_s_import.im_userid
  136. FROM eb_import_mtrlname
  137. WHERE im_type = :arg_im_type
  138. And im_id = :arg_im_id;
  139. IF sqlca.SQLCode <> 0 THEN
  140. rslt = 0
  141. arg_msg = '查询商品信息失败,' + sqlca.SQLErrText
  142. GOTO ext
  143. END IF
  144. ext:
  145. RETURN rslt
  146. end function
  147. public function integer uf_getinfo_dscrp (long arg_im_type, string arg_im_id, ref string arg_dscrp, ref string arg_msg);Int rslt = 1
  148. SELECT eb_dscrp
  149. INTO :arg_dscrp
  150. FROM eb_import_mtrlname
  151. WHERE im_type = :arg_im_type
  152. And im_id = :arg_im_id;
  153. IF sqlca.SQLCode <> 0 THEN
  154. rslt = 0
  155. arg_msg = '查询商品信息失败,' + sqlca.SQLErrText
  156. GOTO ext
  157. END IF
  158. ext:
  159. RETURN rslt
  160. end function
  161. public function integer uf_save_dscrp (s_import_mtrlname arg_s_import, ref string arg_msg, boolean arg_if_commit);Int rslt = 1
  162. UPDATE eb_import_mtrlname
  163. SET eb_dscrp = :arg_s_import.eb_dscrp
  164. WHERE im_type = :arg_s_import.im_type
  165. And im_id = :arg_s_import.im_id;
  166. IF sqlca.SQLCode <> 0 THEN
  167. rslt = 0
  168. arg_msg = '更新外部物料对应描述失败,' + sqlca.SQLErrText
  169. GOTO ext
  170. END IF
  171. ext:
  172. IF arg_if_commit THEN
  173. IF rslt = 1 THEN
  174. COMMIT;
  175. ELSE
  176. ROLLBACK;
  177. END IF
  178. END IF
  179. RETURN rslt
  180. end function
  181. public function integer uf_xls_to_import_mtrlcode (string arg_filepath, ref string arg_msg, boolean arg_ifcommit, boolean arg_ignore);Int rslt = 1
  182. datastore arg_dw
  183. arg_dw = Create datastore
  184. arg_dw.DataObject = 'dw_import_mtrlname_xls'
  185. IF f_xls_import_to_dw(arg_filepath, arg_dw, arg_msg) <> 1 THEN
  186. rslt = 0
  187. GOTO ext
  188. END IF
  189. Long i
  190. Long im_type
  191. String im_id
  192. String mtrlcode
  193. Long mtrlid
  194. FOR i = 1 To arg_dw.RowCount()
  195. im_type = arg_dw.Object.im_type[i]
  196. im_id = Trim(arg_dw.Object.im_id[i])
  197. mtrlcode = Trim(arg_dw.Object.mtrlcode[i])
  198. IF im_id = '' Or mtrlcode = '' THEN CONTINUE
  199. SELECT mtrlid
  200. INTO :mtrlid
  201. FROM u_mtrldef
  202. Where mtrlcode = :mtrlcode;
  203. IF sqlca.SQLCode <> 0 THEN
  204. IF arg_ignore THEN CONTINUE
  205. rslt = 0
  206. arg_msg = '查询物料编码['+mtrlcode+']失败,' + sqlca.SQLErrText
  207. GOTO ext
  208. END IF
  209. UPDATE eb_import_mtrlname
  210. SET mtrlid = :mtrlid
  211. Where im_id = :im_id;
  212. IF sqlca.SQLCode <> 0 THEN
  213. IF arg_ignore THEN CONTINUE
  214. rslt = 0
  215. arg_msg = '更新网店产品定义['+im_id+']失败,' + sqlca.SQLErrText
  216. GOTO ext
  217. END IF
  218. NEXT
  219. ext:
  220. Destroy arg_dw
  221. IF arg_ifcommit THEN
  222. IF rslt = 1 THEN
  223. COMMIT;
  224. ELSE
  225. ROLLBACK;
  226. END IF
  227. END IF
  228. RETURN rslt
  229. end function
  230. public function integer uf_savemx (long arg_im_type, string arg_im_id, s_import_mtrlnamemx arg_mx[], ref string arg_msg);Int rslt = 1
  231. DELETE From eb_import_mtrlnamemx Where im_type = :arg_im_type And im_id = :arg_im_id;
  232. IF sqlca.SQLCode <> 0 THEN
  233. rslt = 0
  234. arg_msg = '删除旧的网店产品定义明细失败,' + sqlca.SQLErrText
  235. GOTO ext
  236. END IF
  237. Long i
  238. FOR i = 1 To UpperBound(arg_mx)
  239. INSERT INTO eb_import_mtrlnamemx(im_type, im_id, pros, mtrlid, status_name, woodcode_name, pcode_name)
  240. Values(:arg_im_type, :arg_im_id, :arg_mx[i].pros, :arg_mx[i].mtrlid, :arg_mx[i].status_name, :arg_mx[i].woodcode_name, :arg_mx[i].pcode_name);
  241. IF sqlca.SQLCode <> 0 THEN
  242. rslt = 0
  243. arg_msg = '插入网店产品定义明细失败,' + sqlca.SQLErrText
  244. GOTO ext
  245. END IF
  246. NEXT
  247. ext:
  248. IF rslt = 1 THEN
  249. COMMIT;
  250. ELSE
  251. ROLLBACK;
  252. END IF
  253. RETURN rslt
  254. end function
  255. public function integer uf_csv_to_import_mtrlcode (string arg_filepath, ref s_import_mtrlname arg_import[], ref string arg_msg);Int rslt = 1
  256. String ls_dscrp
  257. IF Not FileExists(arg_filepath) THEN
  258. rslt = 0
  259. arg_msg = '文件' + arg_filepath + '不存在'
  260. GOTO ext
  261. END IF
  262. Long ll_pos, ll_pos2
  263. ll_pos = Pos(arg_filepath, '\')
  264. IF ll_pos > 0 THEN
  265. ll_pos2 = Pos(arg_filepath, '\', ll_pos + 1)
  266. DO WHILE ll_pos2 > 0
  267. ll_pos = ll_pos2
  268. ll_pos2 = Pos(arg_filepath, '\', ll_pos + 1)
  269. LOOP
  270. ls_dscrp = Mid(arg_filepath, ll_pos + 1)
  271. ELSE
  272. ls_dscrp = arg_filepath
  273. END IF
  274. datastore ds_col100
  275. /////////////建立映射//////////////////// //
  276. ds_col100 = Create datastore
  277. ds_col100.DataObject = 'dw_col100'
  278. ds_col100.ImportFile(CSV!, arg_filepath)
  279. datastore arg_dw
  280. arg_dw = Create datastore
  281. arg_dw.DataObject = 'dw_saletask_import_xls_taobao'
  282. Long ll_s_col_count = 100
  283. Long ll_d_col_count
  284. ll_d_col_count = Long(arg_dw.Object.datawindow.Column.Count)
  285. Long ll_map[] // 目标表与原表的映射,0为没有映射
  286. String ls_colType[] // 目标表列类型
  287. Long col_d, col_s
  288. FOR col_d = 1 To ll_d_col_count
  289. String ls_col_title, ls_col_name
  290. ls_col_name = arg_dw.Describe('#' + String(col_d) + '.Name')
  291. ls_colType[col_d] = arg_dw.Describe('#' + String(col_d) + '.ColType')
  292. ls_col_title = arg_dw.Describe(ls_col_name + '_t.Text')
  293. ll_map[col_d] = 0
  294. FOR col_s = 1 To ll_s_col_count
  295. String ls_s_title
  296. ls_s_title = ds_col100.GetItemString(1, col_s)
  297. IF Lower(Trim(ls_col_title)) = Lower(Trim(ls_s_title)) THEN
  298. ll_map[col_d] = col_s
  299. EXIT
  300. END IF
  301. NEXT
  302. NEXT
  303. Long row_s, row_d
  304. FOR row_s = 2 To ds_col100.RowCount( )
  305. IF Trim(ds_col100.GetItemString(row_s, 1),True) <> Trim(ds_col100.GetItemString(row_s - 1, 1),True) Or Trim(ds_col100.GetItemString(row_s, 2),True) <> Trim(ds_col100.GetItemString(row_s - 1, 2),True) THEN
  306. row_d = arg_dw.InsertRow(0)
  307. END IF
  308. FOR col_d = 1 To ll_d_col_count
  309. IF ll_map[col_d] = 0 THEN CONTINUE
  310. Any Value
  311. String ls_value
  312. ls_value = Trim(ds_col100.GetItemString(row_s, ll_map[col_d]),True)
  313. IF ls_value = '' Or ls_value = '-' THEN CONTINUE
  314. IF Lower(Left(ls_colType[col_d], 4)) = 'char' THEN
  315. Value = ls_value
  316. ELSEIF Lower(Left(ls_colType[col_d], 4)) = 'long' Or Lower(Left(ls_colType[col_d], 3)) = 'int' Or Lower(Left(ls_colType[col_d], 3)) = 'num' Or Lower(Left(ls_colType[col_d], 5)) = 'ulong' THEN
  317. Value = Long(ls_value)
  318. ELSEIF Lower(Left(ls_colType[col_d], 4)) = 'deci' Or Lower(Left(ls_colType[col_d], 4)) = 'real' THEN
  319. Value = Dec(ls_value)
  320. ELSEIF Lower(Left(ls_colType[col_d], 4)) = 'date' THEN
  321. Value = DateTime(Date(Left(ls_value, 10)), Time(Mid(ls_value, 12)))
  322. END IF
  323. arg_dw.SetItem(row_d, col_d, Value)
  324. NEXT
  325. NEXT
  326. Destroy ds_col100
  327. Long i, j, k = 0, cnt
  328. Long ll_im_type
  329. String ls_im_id
  330. s_import_mtrlname s_empty
  331. FOR i = 1 To arg_dw.RowCount()
  332. IF arg_dw.Object.mtrlcode[i] = '' Or IsNull(arg_dw.Object.mtrlcode[i]) THEN CONTINUE
  333. FOR j = 1 To UpperBound(arg_import)
  334. IF arg_dw.Object.mtrlcode[i] = arg_import[j].im_id THEN
  335. EXIT
  336. END IF
  337. NEXT
  338. IF j <= UpperBound(arg_import) THEN CONTINUE
  339. ll_im_type = 0
  340. ls_im_id = arg_dw.Object.mtrlcode[i]
  341. SELECT COUNT(0)
  342. INTO :cnt
  343. FROM eb_import_mtrlname
  344. WHERE im_type = :ll_im_type
  345. And im_id = :ls_im_id;
  346. IF sqlca.SQLCode <> 0 THEN
  347. rslt = 0
  348. arg_msg = '查询物料是否已定义失败,' + sqlca.SQLErrText
  349. GOTO ext
  350. END IF
  351. IF cnt > 0 THEN CONTINUE
  352. k++
  353. arg_import[k].im_type = 0
  354. arg_import[k].im_id = arg_dw.Object.mtrlcode[i]
  355. arg_import[k].eb_title = arg_dw.Object.mtrlname[i]
  356. arg_import[k].eb_price = arg_dw.Object.enprice[i]
  357. arg_import[k].numiid = arg_dw.Object.mtrlcode[i]
  358. arg_import[k].props = arg_dw.Object.props[i]
  359. arg_import[k].eb_locationcity = ls_dscrp
  360. NEXT
  361. Destroy arg_dw
  362. ext:
  363. RETURN rslt
  364. end function
  365. public function integer uf_save_from_web (s_import_mtrlname arg_s_import, ref string arg_msg, boolean arg_if_commit);Int rslt = 1
  366. //
  367. String ls_newid
  368. String ls_ctg
  369. Long ll_cnt
  370. IF uf_reset(arg_s_import, arg_msg) <> 1 THEN
  371. rslt = 0
  372. GOTO ext
  373. END IF
  374. IF arg_s_import.im_id = '' Or arg_s_import.im_id = '0' THEN
  375. CHOOSE CASE arg_s_import.im_type
  376. CASE 0
  377. ls_ctg = 'MD'
  378. CASE ELSE
  379. rslt = 0
  380. arg_msg = '未定义类型' + String(arg_s_import.im_type)
  381. GOTO ext
  382. END CHOOSE
  383. ls_newid = pf_getid(ls_ctg, DateTime(Today(), Now()), False, sqlca)
  384. IF ls_newid = 'err' THEN
  385. rslt = 0
  386. arg_msg = '获取唯一码失败'
  387. GOTO ext
  388. END IF
  389. arg_s_import.im_id = ls_newid
  390. END IF
  391. SELECT COUNT(0)
  392. INTO :ll_cnt
  393. FROM eb_import_mtrlname
  394. WHERE im_type = :arg_s_import.im_type
  395. And im_id = :arg_s_import.im_id;
  396. IF sqlca.SQLCode <> 0 THEN
  397. rslt = 0
  398. arg_msg = '查询商品导入的数量失败,' + sqlca.SQLErrText
  399. GOTO ext
  400. END IF
  401. IF ll_cnt = 0 THEN
  402. INSERT INTO eb_import_mtrlname
  403. (
  404. im_type,
  405. im_id,
  406. mtrlid,
  407. eb_num,
  408. eb_price,
  409. eb_type,
  410. eb_stuffStatus,
  411. eb_title,
  412. eb_dscrp,
  413. eb_locationstate,
  414. eb_locationcity,
  415. eb_cid,
  416. numIid,
  417. props,
  418. im_userid,
  419. status_name,
  420. woodcode_name,
  421. pcode_name,
  422. mx_flag)
  423. VALUES (
  424. :arg_s_import.im_type,
  425. :arg_s_import.im_id,
  426. :arg_s_import.mtrlid,
  427. :arg_s_import.eb_num,
  428. :arg_s_import.eb_price,
  429. :arg_s_import.eb_type,
  430. :arg_s_import.eb_stuffStatus,
  431. :arg_s_import.eb_title,
  432. :arg_s_import.eb_dscrp,
  433. :arg_s_import.eb_locationstate,
  434. :arg_s_import.eb_locationcity,
  435. :arg_s_import.eb_cid,
  436. :arg_s_import.numIid,
  437. :arg_s_import.props,
  438. :arg_s_import.im_userid,
  439. :arg_s_import.status_name,
  440. :arg_s_import.woodcode_name,
  441. :arg_s_import.pcode_name,
  442. :arg_s_import.mx_flag);
  443. IF sqlca.SQLCode <> 0 THEN
  444. rslt = 0
  445. arg_msg = '插入商品导入表失败,' + sqlca.SQLErrText
  446. GOTO ext
  447. END IF
  448. ELSE
  449. UPDATE eb_import_mtrlname
  450. SET
  451. eb_num = :arg_s_import.eb_num,
  452. eb_price = :arg_s_import.eb_price,
  453. eb_type = :arg_s_import.eb_type,
  454. eb_stuffStatus = :arg_s_import.eb_stuffStatus,
  455. eb_title = :arg_s_import.eb_title,
  456. eb_locationstate = :arg_s_import.eb_locationstate,
  457. eb_locationcity = :arg_s_import.eb_locationcity,
  458. eb_cid = :arg_s_import.eb_cid,
  459. props = :arg_s_import.props
  460. WHERE (im_type = :arg_s_import.im_type)
  461. And (im_id = :arg_s_import.im_id);
  462. IF sqlca.SQLCode <> 0 THEN
  463. rslt = 0
  464. arg_msg = '更新商品导入表失败,' + sqlca.SQLErrText
  465. GOTO ext
  466. END IF
  467. END IF
  468. ext:
  469. IF arg_if_commit THEN
  470. IF rslt = 1 THEN
  471. COMMIT;
  472. ELSE
  473. ROLLBACK;
  474. END IF
  475. END IF
  476. RETURN rslt
  477. end function
  478. public function integer uf_save (s_import_mtrlname arg_s_import, ref string arg_msg, boolean arg_if_commit);Int rslt = 1
  479. //
  480. String ls_newid
  481. String ls_ctg
  482. Long ll_cnt
  483. IF uf_reset(arg_s_import, arg_msg) <> 1 THEN
  484. rslt = 0
  485. GOTO ext
  486. END IF
  487. IF arg_s_import.im_id = '' Or arg_s_import.im_id = '0' THEN
  488. CHOOSE CASE arg_s_import.im_type
  489. CASE 0
  490. ls_ctg = 'MD'
  491. CASE ELSE
  492. rslt = 0
  493. arg_msg = '未定义类型' + String(arg_s_import.im_type)
  494. GOTO ext
  495. END CHOOSE
  496. ls_newid = pf_getid(ls_ctg, DateTime(Today(), Now()), False, sqlca)
  497. IF ls_newid = 'err' THEN
  498. rslt = 0
  499. arg_msg = '获取唯一码失败'
  500. GOTO ext
  501. END IF
  502. arg_s_import.im_id = ls_newid
  503. END IF
  504. SELECT COUNT(0)
  505. INTO :ll_cnt
  506. FROM eb_import_mtrlname
  507. WHERE im_type = :arg_s_import.im_type
  508. And im_id = :arg_s_import.im_id;
  509. IF sqlca.SQLCode <> 0 THEN
  510. rslt = 0
  511. arg_msg = '查询商品导入的数量失败,' + sqlca.SQLErrText
  512. GOTO ext
  513. END IF
  514. IF ll_cnt = 0 THEN
  515. INSERT INTO eb_import_mtrlname
  516. (
  517. im_type,
  518. im_id,
  519. mtrlid,
  520. eb_num,
  521. eb_price,
  522. eb_type,
  523. eb_stuffStatus,
  524. eb_title,
  525. eb_dscrp,
  526. eb_locationstate,
  527. eb_locationcity,
  528. eb_cid,
  529. numIid,
  530. props,
  531. im_userid,
  532. status_name,
  533. woodcode_name,
  534. pcode_name,
  535. mx_flag)
  536. VALUES (
  537. :arg_s_import.im_type,
  538. :arg_s_import.im_id,
  539. :arg_s_import.mtrlid,
  540. :arg_s_import.eb_num,
  541. :arg_s_import.eb_price,
  542. :arg_s_import.eb_type,
  543. :arg_s_import.eb_stuffStatus,
  544. :arg_s_import.eb_title,
  545. :arg_s_import.eb_dscrp,
  546. :arg_s_import.eb_locationstate,
  547. :arg_s_import.eb_locationcity,
  548. :arg_s_import.eb_cid,
  549. :arg_s_import.numIid,
  550. :arg_s_import.props,
  551. :arg_s_import.im_userid,
  552. :arg_s_import.status_name,
  553. :arg_s_import.woodcode_name,
  554. :arg_s_import.pcode_name,
  555. :arg_s_import.mx_flag);
  556. IF sqlca.SQLCode <> 0 THEN
  557. rslt = 0
  558. arg_msg = '插入商品导入表失败,' + sqlca.SQLErrText
  559. GOTO ext
  560. END IF
  561. ELSE
  562. UPDATE eb_import_mtrlname
  563. SET
  564. mtrlid = :arg_s_import.mtrlid,
  565. eb_num = :arg_s_import.eb_num,
  566. eb_price = :arg_s_import.eb_price,
  567. eb_type = :arg_s_import.eb_type,
  568. eb_stuffStatus = :arg_s_import.eb_stuffStatus,
  569. eb_title = :arg_s_import.eb_title,
  570. eb_locationstate = :arg_s_import.eb_locationstate,
  571. eb_locationcity = :arg_s_import.eb_locationcity,
  572. eb_cid = :arg_s_import.eb_cid,
  573. props = :arg_s_import.props,
  574. status_name = :arg_s_import.status_name,
  575. woodcode_name = :arg_s_import.woodcode_name,
  576. pcode_name = :arg_s_import.pcode_name,
  577. mx_flag = :arg_s_import.mx_flag
  578. WHERE (im_type = :arg_s_import.im_type)
  579. And (im_id = :arg_s_import.im_id);
  580. IF sqlca.SQLCode <> 0 THEN
  581. rslt = 0
  582. arg_msg = '更新商品导入表失败,' + sqlca.SQLErrText
  583. GOTO ext
  584. END IF
  585. END IF
  586. ext:
  587. IF arg_if_commit THEN
  588. IF rslt = 1 THEN
  589. COMMIT;
  590. ELSE
  591. ROLLBACK;
  592. END IF
  593. END IF
  594. RETURN rslt
  595. end function
  596. on uo_import_mtrlname.create
  597. call super::create
  598. TriggerEvent( this, "constructor" )
  599. end on
  600. on uo_import_mtrlname.destroy
  601. TriggerEvent( this, "destructor" )
  602. call super::destroy
  603. end on