n_dw2xls_progress.sru 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. $PBExportHeader$n_dw2xls_progress.sru
  2. forward
  3. global type n_dw2xls_progress from nonvisualobject
  4. end type
  5. end forward
  6. global type n_dw2xls_progress from nonvisualobject
  7. end type
  8. global n_dw2xls_progress n_dw2xls_progress
  9. type variables
  10. Boolean ib_Cancel
  11. Boolean ib_OpenExcelFile
  12. Boolean ib_WritePictures
  13. Boolean ib_WriteBKColor=TRUE
  14. Boolean ib_FreezeTitles=TRUE
  15. Boolean ib_ProcessSparse=TRUE
  16. Int ii_Result
  17. Long il_Progress_Max
  18. Long il_Progress_Total
  19. Long il_Progress, li_Step_Count
  20. Long il_PriorStep
  21. Int ii_BeginPosition
  22. DateTime idt_start
  23. DateTime idt_last
  24. Boolean ib_CalcRemainTimes =False
  25. PowerObject inv_Requestor
  26. n_dw2xls_Resource inv_Res
  27. w_dw2xls_Progress iw_progress
  28. HProgressBar iu_hpb
  29. end variables
  30. forward prototypes
  31. public subroutine of_stepit ()
  32. public subroutine of_close_progress ()
  33. public subroutine of_intial_progress (readonly long ai_progresstal, integer ai_remain)
  34. public subroutine of_progress (readonly long al_value)
  35. public function LONG of_secondsafter (datetime adtm_start, datetime adtm_end)
  36. public subroutine of_calcremaintimes ()
  37. public subroutine of_open_progress ()
  38. public subroutine of_disablecancel ()
  39. public subroutine of_setrequestor (powerobject anv_requestor, n_dw2xls_resource anv_resource)
  40. end prototypes
  41. public subroutine of_stepit ();
  42. IF Not IsValid(inv_Requestor) Then
  43. Return
  44. END IF
  45. IF Not IsValid(iu_hpb) Then
  46. Return
  47. END IF
  48. IF ib_CalcRemainTimes AND iu_hpb.Position <iu_hpb.MaxPosition Then
  49. OF_CalcRemainTimes()
  50. iu_hpb.StepIt()
  51. END IF
  52. end subroutine
  53. public subroutine of_close_progress ();IF IsValid(iw_progress) Then
  54. iu_hpb.Position = iu_hpb.MaxPosition //保证显示100%处理完毕
  55. Yield()
  56. Close(iw_progress)
  57. END IF
  58. end subroutine
  59. public subroutine of_intial_progress (readonly long ai_progresstal, integer ai_remain);
  60. il_Progress_Total =ai_progresstal
  61. il_Progress =0
  62. il_Progress_Max =100 - ai_remain -iu_hpb.Position
  63. IF il_Progress_Max<=0 THen Return
  64. IF il_Progress_Total<=100 Then
  65. iu_hpb.MaxPosition = il_Progress_Total+1
  66. il_Progress_Max =il_Progress_Total - ai_remain -iu_hpb.Position
  67. li_Step_Count =1
  68. ELSE
  69. li_Step_Count =Ceiling(il_Progress_Total/ il_Progress_Max)
  70. END IF
  71. ib_CalcRemainTimes =TRUE
  72. idt_start = datetime(today(),now())
  73. idt_last = idt_start
  74. ii_BeginPosition = iu_hpb.Position
  75. end subroutine
  76. public subroutine of_progress (readonly long al_value);Int li_Step,li_Secornds
  77. IF al_value<=0 Then
  78. Return
  79. END IF
  80. IF Not IsValid(iu_hpb) Then
  81. Return
  82. END IF
  83. IF li_Step_Count<=1 Then
  84. iu_hpb.Position = iu_hpb.Position + al_value
  85. ELSE
  86. il_Progress +=al_value
  87. IF il_Progress>=il_Progress_Total Then
  88. iu_hpb.Position = iu_hpb.Position + il_Progress_Max - il_PriorStep
  89. ELSE
  90. li_Step =il_Progress /li_Step_Count
  91. IF li_Step>il_PriorStep Then
  92. OF_CalcRemainTimes()
  93. iu_hpb.Position = iu_hpb.Position + li_Step - il_PriorStep
  94. il_PriorStep =li_Step
  95. END IF
  96. END IF
  97. END IF
  98. Yield()
  99. end subroutine
  100. public function LONG of_secondsafter (datetime adtm_start, datetime adtm_end);long ll_total_seconds
  101. long ll_day_adjust
  102. date ld_sdate
  103. date ld_edate
  104. time lt_stime
  105. time lt_etime
  106. long ll_null
  107. ld_sdate = date(adtm_start)
  108. ld_edate = date(adtm_end)
  109. lt_stime = time(adtm_start)
  110. lt_etime = time(adtm_end)
  111. if ld_sdate = ld_edate then
  112. ll_total_seconds = secondsafter(lt_stime,lt_etime)
  113. else
  114. if ld_sdate < ld_edate then
  115. ll_total_seconds = secondsafter(lt_stime,time("23:59:59"))
  116. ll_day_adjust = daysafter(ld_sdate,ld_edate) - 1
  117. if ll_day_adjust > 0 then
  118. ll_total_seconds = ll_total_seconds + 86400 * ll_day_adjust
  119. end if
  120. ll_total_seconds = ll_total_seconds + secondsafter(time("00:00:00"),lt_etime) + 1
  121. else
  122. ll_total_seconds = secondsafter(lt_stime,time("00:00:00"))
  123. ll_day_adjust = daysafter(ld_sdate,ld_edate) + 1
  124. if ll_day_adjust < 0 then
  125. ll_total_seconds = ll_total_seconds + 86400 * ll_day_adjust
  126. end if
  127. ll_total_seconds = ll_total_seconds + secondsafter(time("23:59:59"),lt_etime) - 1
  128. end if
  129. end if
  130. return ll_total_seconds
  131. end function
  132. public subroutine of_calcremaintimes ();long ll_cur_s, li_progress
  133. long ll_total_rem_s
  134. long ll_rem_s
  135. long ll_rem_m
  136. long ll_rem_h
  137. string ls_str
  138. datetime ldt_now
  139. ldt_now = datetime(today(),now())
  140. li_progress=iu_hpb.Position - ii_BeginPosition
  141. IF OF_SecondsAfter(idt_last,ldt_now) >5 Then
  142. IF Not iw_progress.cb_Cancel.Visible Then
  143. iw_progress.cb_Cancel.Visible=TRUE
  144. END IF
  145. idt_last = ldt_now
  146. ll_cur_s =OF_SecondsAfter(idt_start,ldt_now)
  147. IF ll_cur_s > 5 AND li_progress > 0 Then
  148. ll_total_rem_s = truncate(round((ll_cur_s * 100) / li_progress - ll_cur_s,0),0)
  149. ll_total_rem_s = round(ll_total_rem_s / 5,0) * 5
  150. ll_rem_s = mod(ll_total_rem_s,60)
  151. ll_total_rem_s = truncate(ll_total_rem_s / 60,0)
  152. ll_rem_m = mod(ll_total_rem_s,60)
  153. ll_rem_h = truncate(ll_total_rem_s / 60,0)
  154. ls_str = ""
  155. IF ll_rem_s=0 AND ll_rem_m =0 AND ll_rem_h=0 Then
  156. Return
  157. END IF
  158. IF ll_rem_h = 1 Then
  159. ls_str = ls_str + string(ll_rem_h) + " "+inv_Res.Hour+" "
  160. ELSEIF ll_rem_h>1 Then
  161. ls_str = ls_str + string(ll_rem_h) + " "+inv_Res.Hours+" "
  162. END IF
  163. IF ll_rem_m=1 Then
  164. ls_str = ls_str + string(ll_rem_m) + " "+inv_Res.Minute+" "
  165. ELSEIF ((ll_rem_m > 1) or (ll_rem_h > 0)) Then
  166. ls_str = ls_str + string(ll_rem_m) + " "+inv_Res.Minutes+" "
  167. END IF
  168. IF ll_rem_s=1 Then
  169. ls_str = ls_str + string(ll_rem_s) + " "+inv_Res.Second
  170. ELSE
  171. ls_str = ls_str + string(ll_rem_s) + " "+inv_Res.Seconds
  172. END IF
  173. IF ls_str <> "" Then
  174. ls_str =inv_Res.RemainTimes+" "+ ls_str
  175. iw_progress.st_remain.text = ls_str
  176. END IF
  177. END IF
  178. END IF
  179. end subroutine
  180. public subroutine of_open_progress ();IF Not IsValid(inv_Requestor) Then
  181. Return
  182. END IF
  183. IF Not IsValid(iw_progress) Then
  184. OpenWithParm(iw_progress, This, "w_dw2xls_progress" )
  185. END IF
  186. end subroutine
  187. public subroutine of_disablecancel ();IF IsValid(iw_progress) Then
  188. iw_progress.cb_Cancel.Enabled=False
  189. END IF
  190. end subroutine
  191. public subroutine of_setrequestor (powerobject anv_requestor, n_dw2xls_resource anv_resource);inv_Requestor = anv_Requestor
  192. inv_Res = anv_Resource
  193. end subroutine
  194. on n_dw2xls_progress.create
  195. call super::create
  196. TriggerEvent( this, "constructor" )
  197. end on
  198. on n_dw2xls_progress.destroy
  199. TriggerEvent( this, "destructor" )
  200. call super::destroy
  201. end on
  202. event destructor;IF IsValid(iw_progress) Then
  203. Close(iw_progress)
  204. END IF
  205. end event