uo_sendtoexcel.sru 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. $PBExportHeader$uo_sendtoexcel.sru
  2. forward
  3. global type uo_sendtoexcel from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_sendtoexcel from nonvisualobject
  7. event oe_invoke_ouerevent ( long arg_tid, long arg_actionid, uo_sendtoexcel obj_sendtoexcel )
  8. event oe_sendtoexcel ( s_xls_billlist str_billlist )
  9. end type
  10. global uo_sendtoexcel uo_sendtoexcel
  11. type variables
  12. Transaction commit_transaction //数据commit事务
  13. datastore ds
  14. string userpwd = ''
  15. int use_userpwd = 0
  16. uo_xls_constant uo_const
  17. powerobject TriggerEventObject
  18. string TriggerEventName
  19. string cur_biltype = ''
  20. private:
  21. boolean ifsetting = false
  22. //s_xls_bill s_bill_info
  23. s_xls_templates s_tem
  24. uo_xlsmanager obj_xls
  25. long actionid
  26. boolean allowedit
  27. boolean ifclose
  28. end variables
  29. forward prototypes
  30. private function integer of_gettemplatesdata (ref s_xls_templates arg_tem, ref string arg_msg)
  31. private function integer of_getcolumninfo (ref s_xls_bill arg_bill_info, s_xls_templates arg_tem, ref string arg_msg)
  32. public function s_xls_billlist of_getbillinfo (long arg_templateid, ref string arg_msg)
  33. public function datastore of_getbillinfo_ds (long arg_billid, ref string arg_msg)
  34. public function datastore of_getbillcolumninfo_ds (long arg_billid, ref string arg_msg)
  35. private function integer of_activetemplate (ref string arg_msg)
  36. public function integer of_setxlsmax (ref string arg_msg)
  37. public function integer of_set_screenupdating (boolean ifupdate, ref string arg_msg)
  38. public function integer of_setsign (string arg_signname, integer arg_flag, integer arg_type, string arg_billflag, string arg_billname, boolean arg_chk, boolean arg_addchk, ref string arg_msg)
  39. public function integer of_templateedit_init (olecontrol arg_ole, long arg_templateid, ref string arg_msg)
  40. public function integer of_lock_xls (boolean iflock, ref string arg_msg)
  41. public function integer of_check_sign (ref string arg_msg)
  42. public function integer of_updatetemplate (boolean arg_ifcommit, ref string arg_msg)
  43. public function integer of_setexcelwindowsize (integer arg_windowstate, string arg_msg)
  44. public function s_xls_templates of_gettemplatedata (long arg_billid, long arg_templatesid, ref string arg_msg)
  45. public function integer of_delete_template (long arg_billid, long arg_templatesid, boolean ifcommint, string arg_msg)
  46. public function integer of_disconnect (ref string arg_msg)
  47. public function integer of_setoption (long arg_actionid, boolean arg_allowedit, boolean arg_ifclose, ref string arg_msg)
  48. protected function menu of_createitembytype (string arg_billtype, string arg_allow_print_tpidlist, string arg_allow_send_tpidlist)
  49. public function menu of_createmenu (string arg_billtype, string arg_allow_print_tpidlist, string arg_allow_send_tpidlist)
  50. public function integer of_inserttemplate (long arg_tid, blob arg_template, string arg_templatename, integer arg_ifpic, ref string arg_msg, boolean ifcommint)
  51. public function integer of_updatetemp_ifpic (long arg_tid, long arg_templatesid, string arg_templatesname, integer arg_ifpic, ref string arg_msg, boolean arg_ifcommit)
  52. public function datastore of_getbillinfo_ds_panel (long arg_billid, ref string arg_msg)
  53. end prototypes
  54. event oe_invoke_ouerevent(long arg_tid, long arg_actionid, uo_sendtoexcel obj_sendtoexcel);if IsValid(TriggerEventObject) then TriggerEventObject.triggerevent( TriggerEventName,arg_tid,arg_actionid)
  55. end event
  56. event oe_sendtoexcel(s_xls_billlist str_billlist);
  57. IF Not ifsetting THEN RETURN
  58. String arg_msg
  59. //uo_const.create_new_pwd( )
  60. s_tem.templatesid = str_billlist.templateid
  61. IF of_gettemplatesdata(s_tem,arg_msg) <> 1 THEN RETURN
  62. ///////////// //
  63. s_tem.templates = str_billlist.templates
  64. s_tem.templatesname = str_billlist.templatesname
  65. s_tem.tid = str_billlist.billid
  66. s_tem.templatesid = str_billlist.templateid
  67. w_xls w_ole
  68. Open(w_ole)
  69. w_ole.ole_1.DisplayName = s_tem.templatesname +String(Today(),'yyyy-mm-dd hh:mm:ss')+String(Rand(30000))
  70. w_ole.ole_1.ObjectData = s_tem.templates
  71. obj_xls.str_billlist = str_billlist
  72. obj_xls.s_tem = s_tem
  73. obj_xls.uo_const = uo_const
  74. obj_xls.ole_con = w_ole.ole_1
  75. obj_xls.ins_w_ole=w_ole
  76. obj_xls.AllowEdit = AllowEdit
  77. obj_xls.ifclose = ifclose
  78. obj_xls.actionid = actionid
  79. IF obj_xls.of_sendtoexcel(arg_msg) <> 1 THEN
  80. MessageBox('错误',arg_msg)
  81. END IF
  82. end event
  83. private function integer of_gettemplatesdata (ref s_xls_templates arg_tem, ref string arg_msg);TRY
  84. if isnull(arg_msg) then arg_msg = ''
  85. SELECT TemplatesName,id,tid
  86. INTO
  87. :arg_tem.TemplatesName,
  88. :arg_tem.templatesid,
  89. :arg_tem.tid
  90. FROM U_XLS_Templates
  91. Where id = :arg_tem.templatesid USING commit_transaction;
  92. IF commit_transaction.SQLCode <> 0 THEN
  93. arg_msg = " 查询模版失败"
  94. RETURN 0
  95. END IF
  96. SELECTBLOB Templates
  97. INTO
  98. :arg_tem.Templates
  99. FROM U_XLS_Templates
  100. Where id = :arg_tem.templatesid USING commit_transaction;
  101. IF commit_transaction.SQLCode <> 0 THEN
  102. arg_msg = " 查询模版失败"
  103. RETURN 0
  104. END IF
  105. IF IsNull(s_tem.Templates) THEN
  106. arg_msg = '模版不存在'
  107. RETURN 0
  108. END IF
  109. Catch(runtimeerror err)
  110. arg_msg = err.Text
  111. RETURN 0
  112. END TRY
  113. RETURN 1
  114. end function
  115. private function integer of_getcolumninfo (ref s_xls_bill arg_bill_info, s_xls_templates arg_tem, ref string arg_msg);Long rslt = 1,i = 0,cnt = 0
  116. //arg_bill_info.billid = 0
  117. arg_bill_info.billname = ''
  118. arg_bill_info.datawindow = ''
  119. arg_bill_info.count = 0
  120. SELECT
  121. billid,
  122. billname,
  123. DefaultDataWindow
  124. INTO
  125. :arg_bill_info.billid,
  126. :arg_bill_info.billname,
  127. :arg_bill_info.datawindow
  128. FROM U_XLS_BillList
  129. Where billid = :arg_tem.tid USING commit_transaction;
  130. IF commit_transaction.SQLCode <> 0 THEN
  131. rslt = 0
  132. arg_msg = "读取单据信息失败"
  133. GOTO ext
  134. END IF
  135. i = 1
  136. cnt = 0
  137. SELECT count(*) INTO :cnt
  138. FROM U_XLS_BillColumn_Def
  139. Where billid = :arg_tem.tid USING commit_transaction;
  140. IF commit_transaction.SQLCode <> 0 THEN
  141. rslt = 0
  142. arg_msg = "查询操作失败,单据字段数量"
  143. GOTO ext
  144. END IF
  145. open(w_xls_sys_wait_jdt) //初始化进度条
  146. w_xls_sys_wait_jdt.show()
  147. w_xls_sys_wait_jdt.wf_accepttol(cnt)
  148. w_xls_sys_wait_jdt.wf_inc(0)
  149. w_xls_sys_wait_jdt.st_msg.text="正在获取字段信息..."
  150. s_xls_bill_column column[]
  151. DECLARE cur_column CURSOR FOR
  152. SELECT
  153. ColumnID,
  154. ColumnName ,
  155. SignNAME,
  156. ColumnType
  157. FROM U_XLS_BillColumn_Def
  158. Where billid = :arg_tem.tid USING commit_transaction;
  159. OPEN cur_column;
  160. FETCH cur_column INTO
  161. :column[i].ColumnID,
  162. :column[i].ColumnName,
  163. :column[i].SignNAME,
  164. :column[i].ColumnType;
  165. DO WHILE commit_transaction.SQLCode = 0
  166. column[i].SignNAME = uo_const.sign_begin+ column[i].SignNAME + uo_const.sign_end
  167. w_xls_sys_wait_jdt.wf_inc(i)
  168. i++
  169. FETCH cur_column INTO
  170. :column[i].ColumnID,
  171. :column[i].ColumnName,
  172. :column[i].SignNAME,
  173. :column[i].ColumnType;
  174. LOOP
  175. CLOSE cur_column;
  176. IF i <> (cnt+1) THEN
  177. rslt = 0
  178. arg_msg = "查询操作失败,单据字段数量"
  179. GOTO ext
  180. END IF
  181. arg_bill_info.count = cnt
  182. arg_bill_info.column = column
  183. ext:
  184. close(w_xls_sys_wait_jdt)
  185. RETURN rslt
  186. end function
  187. public function s_xls_billlist of_getbillinfo (long arg_templateid, ref string arg_msg);s_xls_billlist str_billlist,null_billlist
  188. Long rslt = 1
  189. //Long ll_billid
  190. //IF IsNull(arg_msg) THEN arg_msg = ''
  191. //SELECT billid
  192. // INTO :ll_billid
  193. // FROM U_XLS_BillList INNER JOIN
  194. // U_XLS_Templates ON U_XLS_BillList.BillID = U_XLS_Templates.tid
  195. // WHERE (U_XLS_Templates.id = :arg_templateid)
  196. // Using commit_transaction;
  197. //IF commit_transaction.SQLCode <> 0 THEN
  198. // arg_msg += '~n查询单据ID失败~n'+commit_transaction.SQLErrText
  199. // rslt = 0
  200. // GOTO ext
  201. //END IF
  202. //str_billlist.billid = ll_billid
  203. str_billlist.templateid = arg_templateid
  204. str_billlist.count = 0
  205. s_tem.templatesid = str_billlist.templateid
  206. IF of_gettemplatesdata(s_tem,arg_msg) <> 1 THEN
  207. rslt = 0
  208. GOTO ext
  209. END IF
  210. str_billlist.billid = s_tem.tid
  211. str_billlist.templates = s_tem.templates
  212. str_billlist.templatesname = s_tem.templatesname
  213. datastore ds_bill,ds_column
  214. ds_bill = THIS.of_getbillinfo_ds( str_billlist.billid, arg_msg)
  215. IF IsNull( ds_bill) THEN
  216. rslt = 0
  217. GOTO ext
  218. END IF
  219. IF ds_bill.RowCount( ) <= 0 THEN
  220. rslt = 0
  221. arg_msg += '该单据还没有定义字段标记'
  222. GOTO ext
  223. END IF
  224. s_xls_bill_column s_column
  225. s_xls_bill s_bill
  226. Long i,j
  227. FOR i = 1 TO ds_bill.RowCount( )
  228. s_bill.billid = ds_bill.Object.billid[i]
  229. s_bill.billname = ds_bill.Object.billname[i]
  230. s_bill.datawindow = ds_bill.Object.defaultdatawindow[i]
  231. s_bill.billtype = ds_bill.Object.billtype[i]
  232. s_bill.Sign = ds_bill.Object.u_xls_billlist_sign[i]
  233. s_bill.billflag = ds_bill.Object.billflag[i]
  234. s_bill.parentid = ds_bill.Object.parentid[i]
  235. s_bill.ds_data = CREATE datastore
  236. s_bill.ds_data.DataObject = s_bill.datawindow
  237. s_bill.ds_data.SetTransObject(commit_transaction)
  238. s_bill.count = 0
  239. ds_column = THIS.of_getbillcolumninfo_ds( str_billlist.billid, arg_msg)
  240. IF IsNull( ds_column) THEN
  241. rslt = 0
  242. GOTO ext
  243. END IF
  244. FOR j = 1 TO ds_column.RowCount( )
  245. IF ds_column.Object.u_xls_billcolumn_def_columnid[j] = 0 THEN CONTINUE
  246. IF ds_column.Object.u_xls_billcolumn_def_billid[j] <> s_bill.billid THEN CONTINUE
  247. s_column.columnid = ds_column.Object.u_xls_billcolumn_def_columnid[j]
  248. s_column.columnname = ds_column.Object.u_xls_billcolumn_def_columnname[j]
  249. s_column.signname = ds_column.Object.u_xls_billcolumn_def_signname[j]
  250. s_column.signnameformat = ds_column.Object.efname[j]
  251. s_column.columntype = ds_column.Object.u_xls_billcolumn_def_columntype[j]
  252. s_bill.count++
  253. s_bill.column[s_bill.count] = s_column
  254. NEXT
  255. str_billlist.count++
  256. str_billlist.bill[str_billlist.count] = s_bill
  257. NEXT
  258. ext:
  259. IF rslt = 1 THEN
  260. RETURN str_billlist
  261. ELSE
  262. RETURN null_billlist
  263. END IF
  264. end function
  265. public function datastore of_getbillinfo_ds (long arg_billid, ref string arg_msg);datastore ids_bill
  266. ids_bill = create datastore
  267. ids_bill.dataobject = 'ds_xls_bill'
  268. ids_bill.settransobject(commit_transaction)
  269. if isnull(arg_msg) then arg_msg = ''
  270. if ids_bill.retrieve(arg_billid,uo_const.sign_begin ,uo_const.sign_end) < 0 then
  271. arg_msg+="~n查询单据列表失败~n"+commit_transaction.sqlerrtext
  272. setnull(ids_bill)
  273. end if
  274. return ids_bill
  275. end function
  276. public function datastore of_getbillcolumninfo_ds (long arg_billid, ref string arg_msg);datastore ids_bill
  277. ids_bill = create datastore
  278. ids_bill.dataobject = 'ds_xls_billcolumn'
  279. ids_bill.settransobject(commit_transaction)
  280. if isnull(arg_msg) then arg_msg = ''
  281. if ids_bill.retrieve(arg_billid,uo_const.sign_begin ,uo_const.sign_end) < 0 then
  282. arg_msg+="~n查询单据列表失败~n"+commit_transaction.sqlerrtext
  283. setnull(ids_bill)
  284. end if
  285. return ids_bill
  286. end function
  287. private function integer of_activetemplate (ref string arg_msg);long rslt = 1
  288. try
  289. if IsValid(obj_xls) then
  290. obj_xls.of_activetemplate()
  291. obj_xls.of_set_caption(False)
  292. end if
  293. catch(runtimeerror err)
  294. arg_msg +=err.text
  295. rslt = 0
  296. end try
  297. return rslt
  298. end function
  299. public function integer of_setxlsmax (ref string arg_msg);long rslt = 1
  300. try
  301. if IsValid (obj_xls) then obj_xls.of_setxlsmax()
  302. catch(runtimeerror err)
  303. arg_msg +=err.text
  304. rslt = 0
  305. end try
  306. return rslt
  307. end function
  308. public function integer of_set_screenupdating (boolean ifupdate, ref string arg_msg);TRY
  309. if IsValid(obj_xls) then obj_xls.of_set_screenupdating(ifupdate )
  310. Catch(runtimeerror err)
  311. arg_msg = err.Text
  312. RETURN 0
  313. END TRY
  314. RETURN 1
  315. end function
  316. public function integer of_setsign (string arg_signname, integer arg_flag, integer arg_type, string arg_billflag, string arg_billname, boolean arg_chk, boolean arg_addchk, ref string arg_msg);try
  317. if IsValid(obj_xls) then obj_xls.of_setsign(arg_signname,arg_flag,arg_type,arg_billflag,arg_billname,arg_chk,arg_addchk)
  318. catch(runtimeerror err)
  319. arg_msg = err.text
  320. return 0
  321. end try
  322. return 1
  323. end function
  324. public function integer of_templateedit_init (olecontrol arg_ole, long arg_templateid, ref string arg_msg);Long rslt = 1
  325. IF IsNull(arg_msg) THEN arg_msg = ''
  326. IF IsNull(arg_templateid) THEN arg_templateid = 0
  327. IF Not IsValid(arg_ole) THEN
  328. arg_msg += '连接olecontrol失败!'
  329. rslt = 0
  330. GOTO ext
  331. END IF
  332. Long ll_billid
  333. SELECT billid
  334. INTO :ll_billid
  335. FROM U_XLS_BillList INNER JOIN
  336. U_XLS_Templates ON U_XLS_BillList.BillID = U_XLS_Templates.tid
  337. WHERE (U_XLS_Templates.id = :arg_templateid)
  338. Using commit_transaction;
  339. IF commit_transaction.SQLCode <> 0 THEN
  340. arg_msg += '~n查询单据ID失败~n'+commit_transaction.SQLErrText
  341. rslt = 0
  342. GOTO ext
  343. END IF
  344. s_tem = of_gettemplatedata(ll_billid,arg_templateid,arg_msg)
  345. IF IsNull(s_tem.templates ) Or s_tem.templatesname = '' THEN
  346. arg_msg += '查询相应模版失败,模版可能不存在'
  347. rslt = 0
  348. GOTO ext
  349. END IF
  350. arg_ole.DisplayName = s_tem.templatesname +String(Today(),'yyyy-mm-dd hh:mm:ss')+String(Rand(30000))
  351. arg_ole.ObjectData = s_tem.templates
  352. obj_xls.s_tem = s_tem
  353. obj_xls.uo_const = uo_const
  354. obj_xls.ole_con = arg_ole
  355. IF of_activetemplate(arg_msg) <> 1 THEN
  356. rslt = 0
  357. GOTO ext
  358. END IF
  359. ext:
  360. RETURN rslt
  361. end function
  362. public function integer of_lock_xls (boolean iflock, ref string arg_msg);TRY
  363. if not IsValid(obj_xls) then return 1
  364. IF iflock THEN
  365. obj_xls.of_workbooklock( )
  366. ELSE
  367. obj_xls.of_workbookunlock( )
  368. END IF
  369. Catch(runtimeerror err)
  370. arg_msg = err.Text
  371. RETURN 0
  372. END TRY
  373. RETURN 1
  374. end function
  375. public function integer of_check_sign (ref string arg_msg);return 1
  376. end function
  377. public function integer of_updatetemplate (boolean arg_ifcommit, ref string arg_msg);
  378. IF IsNull(s_tem.templates ) THEN
  379. arg_msg = '模版内容为空!'
  380. RETURN 0;
  381. END IF
  382. if of_check_sign(arg_msg) <> 1 then return 0
  383. s_tem.templates = obj_xls.ole_con.ObjectData
  384. TRY
  385. UPDATEBLOB U_XLS_Templates Set templates = :s_tem.templates
  386. Where U_XLS_Templates.tid = :s_tem.tid AND U_XLS_Templates.ID = :s_tem.templatesid using commit_transaction;
  387. IF commit_transaction.SQLDBCode = 0 THEN
  388. IF arg_ifcommit THEN
  389. COMMIT USING commit_transaction;
  390. END IF
  391. RETURN 1
  392. ELSE
  393. ROLLBACK USING commit_transaction;
  394. arg_msg = "更新模版失败"
  395. RETURN 0
  396. END IF
  397. Catch(runtimeerror err)
  398. arg_msg = err.Text
  399. ROLLBACK USING commit_transaction;
  400. RETURN 0
  401. END TRY
  402. //commit_transaction.AutoCommit = false
  403. RETURN 1
  404. end function
  405. public function integer of_setexcelwindowsize (integer arg_windowstate, string arg_msg);try
  406. obj_xls.of_setexcelwindowsize( arg_WindowState)
  407. catch(runtimeerror err)
  408. arg_msg = err.text
  409. return 0
  410. end try
  411. return 1
  412. end function
  413. public function s_xls_templates of_gettemplatedata (long arg_billid, long arg_templatesid, ref string arg_msg);
  414. s_xls_templates tem
  415. s_tem = tem
  416. s_tem.tid = arg_billid
  417. s_tem.templatesid = arg_templatesid
  418. TRY
  419. SELECT TemplatesName
  420. INTO
  421. :s_tem.TemplatesName
  422. FROM U_XLS_Templates
  423. Where ID = :arg_templatesid AND tid = :arg_billid USING commit_transaction;
  424. IF commit_transaction.SQLCode <> 0 THEN
  425. arg_msg = " 查询模版失败"
  426. s_tem.templatesname = ''
  427. RETURN s_tem
  428. END IF
  429. SELECTBLOB templates
  430. INTO
  431. :s_tem.templates
  432. FROM U_XLS_Templates
  433. Where ID = :arg_templatesid AND tid = :arg_billid USING commit_transaction;
  434. IF commit_transaction.SQLCode <> 0 THEN
  435. arg_msg = " 查询模版失败"
  436. SetNull(s_tem.templates )
  437. RETURN s_tem
  438. END IF
  439. Catch(runtimeerror err)
  440. arg_msg = err.Text
  441. s_tem.templatesname = ''
  442. SetNull(s_tem.templates )
  443. RETURN s_tem
  444. END TRY
  445. RETURN s_tem
  446. end function
  447. public function integer of_delete_template (long arg_billid, long arg_templatesid, boolean ifcommint, string arg_msg);
  448. UPDATEBLOB U_XLS_Templates Set U_XLS_Templates.templates = ''
  449. Where U_XLS_Templates.tid = :arg_billid AND
  450. U_XLS_Templates.ID = :arg_templatesid;
  451. IF commit_transaction.SQLDBCode <> 0 THEN
  452. ROLLBACK USING commit_transaction;
  453. arg_msg = '删除模版失败'
  454. RETURN 0
  455. END IF
  456. DELETE FROM U_XLS_Templates
  457. Where U_XLS_Templates.tid = :arg_billid AND U_XLS_Templates.ID = :arg_templatesid using commit_transaction;
  458. IF commit_transaction.SQLDBCode = 0 THEN
  459. IF ifcommint THEN
  460. COMMIT USING commit_transaction;
  461. END IF
  462. arg_msg = '模版删除成功!'
  463. ELSE
  464. ROLLBACK USING commit_transaction;
  465. arg_msg = '模版删除失败'
  466. RETURN 0
  467. END IF
  468. RETURN 1
  469. end function
  470. public function integer of_disconnect (ref string arg_msg);long rslt = 1
  471. try
  472. if IsValid(obj_xls) then
  473. obj_xls.of_set_caption(false)
  474. // obj_xls.DisconnectObject()
  475. // Destroy obj_xls
  476. // SetNull(obj_xls)
  477. end if
  478. catch(runtimeerror err)
  479. arg_msg +=err.text
  480. rslt = 0
  481. end try
  482. return rslt
  483. end function
  484. public function integer of_setoption (long arg_actionid, boolean arg_allowedit, boolean arg_ifclose, ref string arg_msg);Long rslt = 1
  485. IF IsNull(arg_msg) THEN arg_msg = ''
  486. actionid = arg_actionid
  487. AllowEdit = arg_allowedit
  488. ifclose = arg_ifclose
  489. IF rslt = 0 THEN
  490. ifsetting = False
  491. ELSE
  492. ifsetting = True
  493. END IF
  494. RETURN rslt
  495. end function
  496. protected function menu of_createitembytype (string arg_billtype, string arg_allow_print_tpidlist, string arg_allow_send_tpidlist);menu arg_menu,xls_item
  497. //
  498. arg_menu = CREATE xls_menuitem
  499. //if not IsValid(arg_menu) then arg_menu = Create xls_menu
  500. Long i,cnt,j = 0,k
  501. Integer iiPos
  502. Long ls_Templatesid
  503. String ls_TemplatesName
  504. String ls_billname
  505. Long tid[]
  506. String tname[]
  507. arg_menu.Tag = arg_billtype
  508. SELECT billname
  509. INTO :ls_billname
  510. FROM U_XLS_BillList
  511. WHERE U_XLS_BillList.BillType = :arg_billtype
  512. USING commit_transaction;
  513. IF commit_transaction.SQLCode <> 0 THEN
  514. ls_billname = ''
  515. END IF
  516. arg_menu.Text = ls_billname
  517. DECLARE dft_xls CURSOR FOR
  518. SELECT U_XLS_Templates.id,U_XLS_Templates.TemplatesName
  519. FROM U_XLS_BillList,U_XLS_Templates
  520. WHERE U_XLS_BillList.billid = U_XLS_Templates.tid
  521. AND U_XLS_BillList.BillType = :arg_billtype
  522. USING commit_transaction;
  523. OPEN dft_xls;
  524. cnt = 0
  525. FETCH dft_xls INTO :ls_Templatesid,:ls_TemplatesName;
  526. DO WHILE commit_transaction.SQLCode = 0
  527. cnt ++
  528. tid[cnt] = ls_Templatesid
  529. tname[cnt] = ls_TemplatesName
  530. FETCH dft_xls INTO :ls_Templatesid,:ls_TemplatesName;
  531. LOOP
  532. CLOSE dft_xls;
  533. String qik = ''
  534. FOR i = 1 TO cnt
  535. IF Pos(arg_allow_print_tpidlist,String(tid[i])+',') > 0 OR arg_allow_print_tpidlist = '0' THEN
  536. xls_item = CREATE xls_menuitem
  537. iiPos = UpperBound(arg_menu.Item)+1
  538. arg_menu.Item[iiPos] = xls_item.Item[2]
  539. IF j < 10 THEN
  540. qik = '[&'+String( j )+']'
  541. ELSE
  542. qik = ''
  543. END IF
  544. arg_menu.Item[iiPos].Text = '[预览]'+tname[i]+qik
  545. j++
  546. arg_menu.Item[iiPos].Tag = String(tid[i])
  547. arg_menu.Item[iiPos].Visible = TRUE
  548. arg_menu.Item[iiPos].Enabled = TRUE
  549. END IF
  550. NEXT
  551. IF cnt > 0 And (Len(arg_allow_send_tpidlist) > 1 OR arg_allow_send_tpidlist = '0') THEN
  552. xls_item = CREATE menu
  553. iiPos = UpperBound(arg_menu.Item)+1
  554. arg_menu.Item[iiPos] = xls_item
  555. arg_menu.Item[iiPos].Text = '-'
  556. arg_menu.Item[iiPos].Visible = TRUE
  557. arg_menu.Item[iiPos].Enabled = TRUE
  558. FOR i = 1 TO cnt
  559. IF Pos(arg_allow_send_tpidlist,String(tid[i])+',') > 0 OR arg_allow_send_tpidlist = '0' THEN
  560. xls_item = CREATE xls_menuitem
  561. iiPos = UpperBound(arg_menu.Item)+1
  562. arg_menu.Item[iiPos] = xls_item.Item[1]
  563. IF j < 10 THEN
  564. qik = '[&'+String( j )+']'
  565. ELSE
  566. qik = ''
  567. END IF
  568. arg_menu.Item[iiPos].Text = tname[i]+qik
  569. j++
  570. arg_menu.Item[iiPos].Tag = String(tid[i])
  571. arg_menu.Item[iiPos].Visible = TRUE
  572. arg_menu.Item[iiPos].Enabled = TRUE
  573. END IF
  574. NEXT
  575. END IF
  576. RETURN arg_menu
  577. end function
  578. public function menu of_createmenu (string arg_billtype, string arg_allow_print_tpidlist, string arg_allow_send_tpidlist);
  579. IF arg_billTYPE = '' THEN
  580. menu arg_menu,xls_item
  581. arg_menu = Create menu
  582. setnull(arg_menu)
  583. // Integer iiPos
  584. // String bulltype[]
  585. // DECLARE dft_xls CURSOR FOR
  586. // SELECT U_XLS_BillList.billtype
  587. // FROM U_XLS_BillList
  588. // Using commit_transaction;
  589. // OPEN dft_xls;
  590. // FETCH dft_xls Into :arg_billTYPE;
  591. // DO WHILE commit_transaction.SQLCode = 0
  592. // bulltype[ UpperBound(bulltype)+1] = arg_billTYPE
  593. // FETCH dft_xls Into :arg_billTYPE;
  594. // LOOP
  595. // CLOSE dft_xls;
  596. //
  597. // Long i
  598. // FOR iiPos = 1 To UpperBound(bulltype)
  599. // xls_item = This.of_createitembytype( bulltype[iiPos])
  600. // arg_menu.Item[iiPos] = xls_item
  601. // NEXT
  602. RETURN arg_menu
  603. ELSE
  604. RETURN This.of_createitembytype( arg_billTYPE,arg_allow_print_tpidlist,arg_allow_send_tpidlist)
  605. END IF
  606. end function
  607. public function integer of_inserttemplate (long arg_tid, blob arg_template, string arg_templatename, integer arg_ifpic, ref string arg_msg, boolean ifcommint);
  608. s_tem.templates = arg_template
  609. s_tem.tid = arg_tid
  610. s_tem.templatesname = arg_templatename
  611. SELECT Max(ID) INTO :s_tem.templatesid FROM U_XLS_Templates USING commit_transaction;
  612. IF commit_transaction.SQLCode <> 0 THEN
  613. arg_msg = "插入新纪录失败" + commit_transaction.SQLErrText
  614. RETURN 0
  615. END IF
  616. IF IsNull(s_tem.templatesid) THEN s_tem.templatesid = 10
  617. IF s_tem.templatesid < 10 THEN s_tem.templatesid = 10
  618. s_tem.templatesid++
  619. INSERT INTO U_XLS_Templates
  620. (TID,
  621. ID,
  622. TemplatesName,
  623. ifpic)
  624. VALUES
  625. (:s_tem.tid ,
  626. :s_tem.templatesid ,
  627. :s_tem.TemplatesName,
  628. :arg_ifpic
  629. ) USING commit_transaction;
  630. IF commit_transaction.SQLCode <> 0 THEN
  631. ROLLBACK USING commit_transaction;
  632. arg_msg = "插入模版失败" + commit_transaction.SQLErrText
  633. RETURN 0
  634. END IF
  635. //commit_transaction.autocommit=true
  636. UPDATEBLOB U_XLS_Templates Set templates = :s_tem.templates
  637. Where U_XLS_Templates.tid = :s_tem.tid AND U_XLS_Templates.ID = :s_tem.templatesid USING commit_transaction;
  638. IF commit_transaction.SQLDBCode = 0 THEN
  639. IF ifcommint THEN
  640. COMMIT USING commit_transaction;
  641. END IF
  642. RETURN 1
  643. ELSE
  644. arg_msg = "上传模版失败"
  645. ROLLBACK USING commit_transaction;
  646. RETURN 0
  647. END IF
  648. RETURN 1
  649. end function
  650. public function integer of_updatetemp_ifpic (long arg_tid, long arg_templatesid, string arg_templatesname, integer arg_ifpic, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  651. IF IsNull(arg_tid) THEN arg_tid = 0
  652. IF IsNull(arg_templatesid) THEN arg_templatesid = 0
  653. IF IsNull(arg_templatesname) THEN arg_templatesname = ''
  654. IF IsNull(arg_ifpic) THEN arg_ifpic = 0
  655. IF arg_tid <= 0 THEN
  656. rslt = 0
  657. arg_msg = '错误的单据ID'
  658. GOTO ext
  659. END IF
  660. IF arg_templatesid <= 0 THEN
  661. rslt = 0
  662. arg_msg = '错误的模版ID'
  663. GOTO ext
  664. END IF
  665. IF Trim(arg_templatesname) = '' THEN
  666. rslt = 0
  667. arg_msg = '必须输入模版名称'
  668. GOTO ext
  669. END IF
  670. UPDATE U_XLS_Templates
  671. SET TemplatesName = :arg_templatesname,
  672. ifpic = :arg_ifpic
  673. WHERE tid = :arg_tid
  674. AND id = :arg_templatesid
  675. USING commit_transaction;
  676. IF commit_transaction.SQLCode <> 0 THEN
  677. rslt = 0
  678. arg_msg = '更新模版信息失败'
  679. GOTO ext
  680. END IF
  681. ext:
  682. IF rslt = 0 THEN
  683. ROLLBACK USING commit_transaction;
  684. ELSEIF arg_ifcommit AND rslt = 1 THEN
  685. COMMIT USING commit_transaction;
  686. END IF
  687. RETURN rslt
  688. end function
  689. public function datastore of_getbillinfo_ds_panel (long arg_billid, ref string arg_msg);datastore ids_bill
  690. ids_bill = create datastore
  691. ids_bill.dataobject = 'ds_xls_bill_panel'
  692. ids_bill.settransobject(commit_transaction)
  693. if isnull(arg_msg) then arg_msg = ''
  694. if ids_bill.retrieve(arg_billid,uo_const.sign_begin ,uo_const.sign_end) < 0 then
  695. arg_msg+="~n查询单据列表失败~n"+commit_transaction.sqlerrtext
  696. setnull(ids_bill)
  697. end if
  698. return ids_bill
  699. end function
  700. on uo_sendtoexcel.create
  701. call super::create
  702. TriggerEvent( this, "constructor" )
  703. end on
  704. on uo_sendtoexcel.destroy
  705. TriggerEvent( this, "destructor" )
  706. call super::destroy
  707. end on
  708. event destructor;//if isvalid(w_ole ) then close(w_ole)
  709. //
  710. //if IsValid(w_ole) then
  711. // close(w_ole)
  712. //end if
  713. //
  714. end event
  715. event constructor;// w_ole = create w_xls_ole
  716. obj_xls = Create uo_xlsmanager
  717. commit_transaction = sqlca
  718. //uo_const = create uo_xls_constant
  719. end event