w_xls_backup.srw 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. $PBExportHeader$w_xls_backup.srw
  2. forward
  3. global type w_xls_backup from window
  4. end type
  5. type cb_2 from uo_xls_imflatbutton within w_xls_backup
  6. end type
  7. type cb_cancel from uo_xls_imflatbutton within w_xls_backup
  8. end type
  9. type cb_export from uo_xls_imflatbutton within w_xls_backup
  10. end type
  11. type cb_import from uo_xls_imflatbutton within w_xls_backup
  12. end type
  13. type st_2 from statictext within w_xls_backup
  14. end type
  15. type ddlb_fm from dropdownlistbox within w_xls_backup
  16. end type
  17. type sle_path from singlelineedit within w_xls_backup
  18. end type
  19. type st_1 from statictext within w_xls_backup
  20. end type
  21. end forward
  22. global type w_xls_backup from window
  23. integer width = 2533
  24. integer height = 480
  25. boolean titlebar = true
  26. string title = "Excel模版设置备份与恢复"
  27. boolean controlmenu = true
  28. windowtype windowtype = response!
  29. long backcolor = 134217739
  30. string icon = "AppIcon!"
  31. boolean center = true
  32. cb_2 cb_2
  33. cb_cancel cb_cancel
  34. cb_export cb_export
  35. cb_import cb_import
  36. st_2 st_2
  37. ddlb_fm ddlb_fm
  38. sle_path sle_path
  39. st_1 st_1
  40. end type
  41. global w_xls_backup w_xls_backup
  42. type variables
  43. uo_xls_backup uo_bc
  44. private string savepath = ''
  45. private string savename = ''
  46. long ins_rslt = 0 //0-取消(不刷新)1-导入(刷新)2-导出(不刷新)
  47. uo_win32api uo_api
  48. end variables
  49. on w_xls_backup.create
  50. this.cb_2=create cb_2
  51. this.cb_cancel=create cb_cancel
  52. this.cb_export=create cb_export
  53. this.cb_import=create cb_import
  54. this.st_2=create st_2
  55. this.ddlb_fm=create ddlb_fm
  56. this.sle_path=create sle_path
  57. this.st_1=create st_1
  58. this.Control[]={this.cb_2,&
  59. this.cb_cancel,&
  60. this.cb_export,&
  61. this.cb_import,&
  62. this.st_2,&
  63. this.ddlb_fm,&
  64. this.sle_path,&
  65. this.st_1}
  66. end on
  67. on w_xls_backup.destroy
  68. destroy(this.cb_2)
  69. destroy(this.cb_cancel)
  70. destroy(this.cb_export)
  71. destroy(this.cb_import)
  72. destroy(this.st_2)
  73. destroy(this.ddlb_fm)
  74. destroy(this.sle_path)
  75. destroy(this.st_1)
  76. end on
  77. event open; uo_bc = create uo_xls_backup
  78. uo_api = create uo_win32api
  79. uo_bc.xls_trans = sqlca
  80. sle_path.text = uo_api.u_getcurrentdirectory()+'\XlsExportFolder'
  81. if not DirectoryExists(sle_path.text) then
  82. CreateDirectory(sle_path.text)
  83. end if
  84. end event
  85. event close;closewithreturn(this,ins_rslt)
  86. end event
  87. type cb_2 from uo_xls_imflatbutton within w_xls_backup
  88. integer x = 2368
  89. integer y = 28
  90. integer width = 123
  91. integer height = 84
  92. integer taborder = 60
  93. string text = "..."
  94. end type
  95. event clicked;call super::clicked;
  96. //if GetFileSaveName("请选择备份文件的路径", savepath, savename, "Access", "Access Files(*.mdb),*.mdb") <> 1 then
  97. // sle_path.text = ''
  98. // savepath = ''
  99. // savename = ''
  100. // return
  101. //else
  102. // sle_path.text = savepath
  103. //end if
  104. string directory = ''
  105. if GetFolder ( "请选择备份目录", directory )<> 1 then
  106. directory = ''
  107. return
  108. end if
  109. sle_path.text = directory
  110. end event
  111. type cb_cancel from uo_xls_imflatbutton within w_xls_backup
  112. integer x = 1673
  113. integer y = 264
  114. integer taborder = 50
  115. string text = "取消"
  116. string normalpicname = "exit.bmp"
  117. integer picsize = 16
  118. end type
  119. event clicked;call super::clicked;ins_rslt = 0
  120. close(parent)
  121. end event
  122. type cb_export from uo_xls_imflatbutton within w_xls_backup
  123. integer x = 1134
  124. integer y = 264
  125. integer taborder = 50
  126. string text = "导出"
  127. string normalpicname = "SAVE.BMP"
  128. integer picsize = 16
  129. end type
  130. event clicked;call super::clicked;//if sle_path.text = '' then
  131. // messagebox('系统提示','请选择备份文件的路径')
  132. // return
  133. //end if
  134. //string arg_msg
  135. //string filedir = ''
  136. //savepath = sle_path.text
  137. //
  138. //Long Len = 1
  139. //DO WHILE Pos(Right(savepath,Len),'\') = 0
  140. // Len++
  141. // IF Len >= Len(savepath) THEN EXIT
  142. //LOOP
  143. //Len = Len(savepath)-Len
  144. //IF Len <= 0 THEN
  145. // messagebox('系统提示','保存Access文件的路径不正确')
  146. // RETURN
  147. //END IF
  148. //filedir = Left(savepath,Len)
  149. //IF NOT Directoryexists(filedir) THEN
  150. // messagebox('系统提示','保存Access文件的路径不正确')
  151. // RETURN
  152. //END IF
  153. //savename = right(savepath,len(savepath) - len -1)
  154. ////filedir = Left(savepath,Pos(savepath,savename) - 2)
  155. //
  156. //if uo_bc.exporttoaccess(filedir,savename,true,arg_msg) <>1 then
  157. // messagebox('',arg_msg)
  158. //else
  159. // messagebox('系统提示','导出成功!')
  160. // close(parent)
  161. //end if
  162. IF Not DirectoryExists(sle_path.Text) THEN
  163. MessageBox('系统提示','请选择备份文件存放目录')
  164. RETURN
  165. END IF
  166. datastore ds
  167. ds = Create datastore
  168. Long rslt = 1
  169. String tempname = '',datestr,ls_format_str
  170. //datestr = sle_path.text+'\['+string(today(),'yyyymmddhhmmss')+']'
  171. datestr = sle_path.Text+'\'
  172. if upper(ddlb_fm.text)='XML' then
  173. ls_format_str='XML'
  174. else
  175. ls_format_str='DBF'
  176. end if
  177. /*
  178. ds.DataObject = 'dw_u_xls_table_def'
  179. ds.SetTransObject( sqlca)
  180. ds.Retrieve( )
  181. tempname = datestr + 'u_xls_table_def.'+ls_format_str
  182. IF ds.SaveAs(tempname, XML!, True) <> 1 THEN
  183. rslt = 0
  184. GOTO ext
  185. END IF
  186. ds.DataObject = 'dw_u_xls_column_def'
  187. ds.SetTransObject( sqlca)
  188. ds.Retrieve( )
  189. tempname = datestr + 'u_xls_column_def.'+ls_format_str
  190. IF ds.SaveAs(tempname, XML!, True) <> 1 THEN
  191. rslt = 0
  192. GOTO ext
  193. END IF
  194. */
  195. ds.DataObject = 'dw_u_xls_billlist'
  196. ds.SetTransObject( sqlca)
  197. ds.Retrieve( )
  198. tempname = datestr + 'u_xls_billlist.'+ls_format_str
  199. if ls_format_str="XML" then
  200. IF ds.SaveAs(tempname, XML!, True) <> 1 THEN
  201. rslt = 0
  202. GOTO ext
  203. END IF
  204. else
  205. IF ds.SaveAs(tempname, DBase3!, True) <> 1 THEN
  206. rslt = 0
  207. GOTO ext
  208. END IF
  209. end if
  210. ds.DataObject = 'dw_u_xls_billcolumn_def'
  211. ds.SetTransObject( sqlca)
  212. ds.Retrieve( )
  213. tempname = datestr + 'u_xls_billcolumn_def.'+ls_format_str
  214. if ls_format_str="XML" then
  215. IF ds.SaveAs(tempname, XML!, True) <> 1 THEN
  216. rslt = 0
  217. GOTO ext
  218. END IF
  219. else
  220. IF ds.SaveAs(tempname, DBase3!, True) <> 1 THEN
  221. rslt = 0
  222. GOTO ext
  223. END IF
  224. end if
  225. ext:
  226. IF rslt = 1 THEN
  227. MessageBox('系统提示','导出成功!')
  228. ins_rslt = 2
  229. Close(Parent)
  230. ELSE
  231. MessageBox('系统提示','导出失败!')
  232. END IF
  233. //ds.DataObject = 'dw_u_xls_templates'
  234. //ds.SetTransObject( sqlca)
  235. //ds.retrieve( )
  236. //rslt = ds.SaveAs('blob_1',sle_1.Text, XML!, True)
  237. //rslt = ds.SaveAs('blob_1','C:\aa.xls', CSV!, True)
  238. //messagebox('',string(rslt))
  239. end event
  240. type cb_import from uo_xls_imflatbutton within w_xls_backup
  241. integer x = 594
  242. integer y = 264
  243. integer taborder = 40
  244. string text = "导入"
  245. string normalpicname = "open.bmp"
  246. integer picsize = 16
  247. end type
  248. event clicked;call super::clicked;IF Not DirectoryExists(sle_path.Text) THEN
  249. MessageBox('系统提示','请选择备份文件存放目录')
  250. RETURN
  251. END IF
  252. IF MessageBox ('系统提示',"是否确定要导入数据?(导入之后原有数据将会被删除)",Question!,YesNo! ) = 2 THEN
  253. RETURN
  254. END IF
  255. string arg_msg = ''
  256. datastore ds
  257. ds = Create datastore
  258. Long rslt = 1
  259. String tempname = '',datestr ,ls_format_str
  260. //datestr = sle_path.text+'\['+string(today(),'yyyymmddhhmmss')+']'
  261. datestr = sle_path.Text+'\'
  262. Long i
  263. if upper(ddlb_fm.text)='XML' then
  264. ls_format_str='XML'
  265. else
  266. ls_format_str='DBF'
  267. end if
  268. /*
  269. tempname = datestr + 'u_xls_table_def.xml'
  270. IF FileExists(tempname) THEN
  271. ds.DataObject = 'dw_u_xls_table_def'
  272. ds.SetTransObject( sqlca)
  273. ds.Retrieve( )
  274. FOR i = ds.RowCount( ) To 1 Step -1
  275. ds.DeleteRow( i)
  276. NEXT
  277. ds.ImportFile(XML!,tempname)
  278. IF ds.Update( ) <> 1 THEN
  279. rslt = 0
  280. GOTO ext
  281. END IF
  282. arg_msg+='~n文件"u_xls_table_def.xml"导入成功'
  283. else
  284. rslt = 100
  285. arg_msg+='~n文件"u_xls_table_def.xml"不存在'
  286. END IF
  287. tempname = datestr + 'u_xls_column_def.xml'
  288. IF FileExists(tempname) THEN
  289. ds.DataObject = 'dw_u_xls_column_def'
  290. ds.SetTransObject( sqlca)
  291. ds.Retrieve( )
  292. FOR i = ds.RowCount( ) To 1 Step -1
  293. ds.DeleteRow( i)
  294. NEXT
  295. ds.ImportFile(XML!,tempname)
  296. IF ds.Update( ) <> 1 THEN
  297. rslt = 0
  298. GOTO ext
  299. END IF
  300. arg_msg+='~n文件"u_xls_column_def.xml"导入成功'
  301. else
  302. rslt = 100
  303. arg_msg+='~n文件"u_xls_column_def.xml"不存在'
  304. END IF
  305. */
  306. tempname = datestr + 'u_xls_billlist.'+ls_format_str
  307. IF FileExists(tempname) THEN
  308. ds.DataObject = 'dw_u_xls_billlist'
  309. ds.SetTransObject( sqlca)
  310. ds.Retrieve( )
  311. FOR i = ds.RowCount( ) To 1 Step -1
  312. ds.DeleteRow( i)
  313. NEXT
  314. if ls_format_str="XML" then
  315. ds.ImportFile(XML!,tempname)
  316. else
  317. ds.ImportFile(DBase3!,tempname)
  318. end if
  319. IF ds.Update( ) <> 1 THEN
  320. rslt = 0
  321. GOTO ext
  322. END IF
  323. arg_msg+='~n文件"u_xls_billlist.'+ls_format_str+'" 导入成功('+string(ds.rowcount())+')'
  324. else
  325. rslt = 100
  326. arg_msg+='~n文件"u_xls_billlist.'+ls_format_str+'"不存在'
  327. END IF
  328. tempname = datestr + 'u_xls_billcolumn_def.'+ls_format_str+''
  329. IF FileExists(tempname) THEN
  330. ds.DataObject = 'dw_u_xls_billcolumn_def'
  331. ds.SetTransObject( sqlca)
  332. ds.Retrieve( )
  333. FOR i = ds.RowCount( ) To 1 Step -1
  334. ds.DeleteRow( i)
  335. NEXT
  336. if ls_format_str="XML" then
  337. ds.ImportFile(XML!,tempname)
  338. else
  339. ds.ImportFile(DBase3!,tempname)
  340. end if
  341. IF ds.Update( ) <> 1 THEN
  342. rslt = 0
  343. GOTO ext
  344. END IF
  345. arg_msg+='~n文件"u_xls_billcolumn_def.'+ls_format_str+'"导入成功('+string(ds.rowcount())+')'
  346. else
  347. rslt = 100
  348. arg_msg+='~n文件"u_xls_billcolumn_def.'+ls_format_str+'"不存在'
  349. END IF
  350. ext:
  351. IF rslt = 1 THEN
  352. COMMIT;
  353. MessageBox('系统提示','导入成功:'+arg_msg)
  354. ins_rslt = 1
  355. close(parent)
  356. elseif rslt = 100 then
  357. commit;
  358. MessageBox('系统提示','导入成功:'+arg_msg)
  359. ELSE
  360. ROLLBACK;
  361. MessageBox('系统提示','导入失败!')
  362. END IF
  363. //IF sle_path.text = '' THEN
  364. // MessageBox('系统提示','请选择备份文件的路径')
  365. // RETURN
  366. //END IF
  367. //String arg_msg
  368. //String filedir = ''
  369. //savepath = sle_path.text
  370. //
  371. //Long Len = 1
  372. //DO WHILE Pos(Right(savepath,Len),'\') = 0
  373. // Len++
  374. // IF Len >= Len(savepath) THEN EXIT
  375. //LOOP
  376. //Len = Len(savepath)-Len
  377. //IF Len <= 0 THEN
  378. // messagebox('系统提示','保存Access文件的路径不正确')
  379. // RETURN
  380. //END IF
  381. //filedir = Left(savepath,Len)
  382. //IF NOT Directoryexists(filedir) THEN
  383. // messagebox('系统提示','保存Access文件的路径不正确')
  384. // RETURN
  385. //END IF
  386. //savename = right(savepath,len(savepath) - len -1)
  387. //filedir = Left(savepath,Pos(savepath,savename) - 2)
  388. //IF MessageBox ('系统提示',"将要覆盖原有的数据,是否确定要导入Excel模版设置?",Question!,YesNo! ) = 2 THEN
  389. // RETURN
  390. //END IF
  391. //IF uo_bc.importfromacess(filedir,savename,TRUE,arg_msg) <> 1 THEN
  392. // MessageBox('',arg_msg)
  393. //ELSE
  394. // MessageBox('系统提示','导入成功!')
  395. // close(parent)
  396. //END IF
  397. //
  398. end event
  399. type st_2 from statictext within w_xls_backup
  400. integer x = 23
  401. integer y = 152
  402. integer width = 288
  403. integer height = 64
  404. integer textsize = -9
  405. integer weight = 400
  406. fontcharset fontcharset = gb2312charset!
  407. fontpitch fontpitch = variable!
  408. string facename = "宋体"
  409. long textcolor = 33554432
  410. long backcolor = 134217739
  411. string text = "文件格式:"
  412. boolean focusrectangle = false
  413. end type
  414. type ddlb_fm from dropdownlistbox within w_xls_backup
  415. integer x = 315
  416. integer y = 132
  417. integer width = 361
  418. integer height = 228
  419. integer taborder = 40
  420. integer textsize = -9
  421. integer weight = 400
  422. fontcharset fontcharset = gb2312charset!
  423. fontpitch fontpitch = variable!
  424. string facename = "宋体"
  425. long textcolor = 33554432
  426. string text = "DBF"
  427. boolean vscrollbar = true
  428. string item[] = {"XML","DBF"}
  429. borderstyle borderstyle = stylelowered!
  430. end type
  431. type sle_path from singlelineedit within w_xls_backup
  432. integer x = 315
  433. integer y = 28
  434. integer width = 2043
  435. integer height = 84
  436. integer taborder = 10
  437. integer textsize = -9
  438. integer weight = 400
  439. fontcharset fontcharset = gb2312charset!
  440. fontpitch fontpitch = variable!
  441. string facename = "宋体"
  442. long textcolor = 33554432
  443. borderstyle borderstyle = stylelowered!
  444. end type
  445. type st_1 from statictext within w_xls_backup
  446. integer x = 23
  447. integer y = 44
  448. integer width = 288
  449. integer height = 64
  450. integer textsize = -9
  451. integer weight = 400
  452. fontcharset fontcharset = gb2312charset!
  453. fontpitch fontpitch = variable!
  454. string facename = "宋体"
  455. long textcolor = 33554432
  456. long backcolor = 134217739
  457. string text = "文件路径:"
  458. boolean focusrectangle = false
  459. end type