uo_string.sru 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. $PBExportHeader$uo_string.sru
  2. forward
  3. global type uo_string from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_string from nonvisualobject
  7. end type
  8. global uo_string uo_string
  9. forward prototypes
  10. public function string uf_right (string arg_str, long arg_lena)
  11. public subroutine uof_split (string arg_source, string arg_spliter, ref string arg_return[])
  12. public function string uof_replace (string arg_str, string arg_old, string arg_new)
  13. public function string uof_replace_sql (string arg_input)
  14. public function string uof_replace_sql_like (string arg_input)
  15. public function string uof_replace_sql_code (string arg_str)
  16. public function string uof_replace_trim_name (string arg_str)
  17. public function string uof_getitemstring (datastore arg_ds, long arg_row, string arg_colname)
  18. public function string uof_getitemname (datastore arg_ds, long arg_row, string arg_colname)
  19. public function string uof_getitemname (datawindow arg_ds, long arg_row, string arg_colname)
  20. public function string uf_add_single_quotes (string arg_str)
  21. public function string uof_getitemformattedstring (datawindow arg_dw, long arg_row, string arg_colname)
  22. public function string uof_dw_getsortname (datawindow arg_dw)
  23. public function integer uof_dw_append_filter (datawindow arg_dw, ref string arg_filter)
  24. public function integer uof_dw_append_sort (datawindow arg_dw, ref string arg_sort)
  25. end prototypes
  26. public function string uf_right (string arg_str, long arg_lena);//====================================================================
  27. // 事件: uo_string.uf_right()
  28. //--------------------------------------------------------------------
  29. // 描述: 返回字符串右边指定长度内容,不截断中文
  30. //--------------------------------------------------------------------
  31. // 参数:
  32. // value string arg_str
  33. // value long arg_lena
  34. //--------------------------------------------------------------------
  35. // 返回: string
  36. //--------------------------------------------------------------------
  37. // 作者: lwl 日期: 2018年03月29日
  38. //--------------------------------------------------------------------
  39. // LONGJOE
  40. //--------------------------------------------------------------------
  41. // 修改历史:
  42. //
  43. //====================================================================
  44. string ls_rslt
  45. long ll_lena
  46. long i = 0
  47. ls_rslt = right(arg_str, arg_lena)
  48. ll_lena = lena(ls_rslt)
  49. do while ll_lena > arg_lena
  50. i ++
  51. ls_rslt = right(arg_str, arg_lena - i)
  52. ll_lena = lena(ls_rslt)
  53. loop
  54. return ls_rslt
  55. end function
  56. public subroutine uof_split (string arg_source, string arg_spliter, ref string arg_return[]);string arg_rslt[]
  57. long ll_cnt = 0
  58. long ll_pos = 0
  59. do while len(arg_source) > 0
  60. ll_pos = pos(arg_source, arg_spliter)
  61. if ll_pos > 0 then
  62. ll_cnt++
  63. arg_rslt[ll_cnt] = mid(arg_source, 1, ll_pos - 1)
  64. arg_source = mid(arg_source, ll_pos + len(arg_spliter))
  65. else
  66. ll_cnt++
  67. arg_rslt[ll_cnt] = arg_source
  68. arg_source = ''
  69. end if
  70. loop
  71. arg_return = arg_rslt
  72. end subroutine
  73. public function string uof_replace (string arg_str, string arg_old, string arg_new);
  74. long ll_pos = 1, ll_find
  75. ll_find = pos(arg_str, arg_old, ll_pos)
  76. do while ll_find > 0
  77. arg_str = Replace(arg_str, ll_find, len(arg_old), arg_new)
  78. ll_pos = ll_find + len(arg_new)
  79. ll_find = pos(arg_str, arg_old, ll_pos)
  80. loop
  81. return arg_str
  82. end function
  83. public function string uof_replace_sql (string arg_input);return uof_replace(arg_input, "'", "''")
  84. end function
  85. public function string uof_replace_sql_like (string arg_input);arg_input = uof_replace(arg_input, "'", "''")
  86. arg_input = uof_replace(arg_input, "[", "[[]")
  87. arg_input = uof_replace(arg_input, "_", "[_]")
  88. arg_input = uof_replace(arg_input, "%", "[%]")
  89. arg_input = uof_replace(arg_input, "^", "[^]")
  90. return arg_input
  91. end function
  92. public function string uof_replace_sql_code (string arg_str);// 将 u_orderrqwp.empCN_QC 转换成 CASE WHEN CHARINDEX(':',u_orderrqwp.empCN_QC,1) > 0 THEN LEFT(u_orderrqwp.empCN_QC,CHARINDEX(':',u_orderrqwp.empCN_QC,1)-1) ELSE u_orderrqwp.empCN_QC END
  93. string ls_sql
  94. ls_sql = "CASE WHEN CHARINDEX(':',"+arg_str+",1) > 0 "&
  95. +" THEN LEFT("+arg_str+",CHARINDEX(':',"+arg_str+",1)-1) "&
  96. +" ELSE "+arg_str+" END"
  97. RETURN ls_sql
  98. end function
  99. public function string uof_replace_trim_name (string arg_str);// 将'A:B','B:C','C:D'转换成'A','B','C'
  100. Long ll_pos = 1, ll_find, ll_pos2
  101. ll_find = Pos(arg_str, ":", ll_pos)
  102. DO WHILE ll_find > 0
  103. ll_pos2 = Pos(arg_str, "'", ll_find)
  104. IF ll_pos2 > 0 THEN
  105. arg_str = Replace(arg_str, ll_find, ll_pos2 - ll_find, "")
  106. ll_pos = ll_find
  107. ELSE
  108. EXIT
  109. END IF
  110. ll_find = Pos(arg_str, ":", ll_pos)
  111. LOOP
  112. RETURN arg_str
  113. end function
  114. public function string uof_getitemstring (datastore arg_ds, long arg_row, string arg_colname);string ls_coltype
  115. ls_coltype = lower(arg_ds.Describe(arg_colname+".ColType"))
  116. IF ls_coltype = '!' OR ls_coltype = '' THEN
  117. return "''"
  118. END IF
  119. IF pos(ls_coltype, 'char') > 0 THEN
  120. return "'"+arg_ds.GetItemString(arg_row, arg_colname)+"'"
  121. END IF
  122. IF pos(ls_coltype, 'dec') > 0 THEN
  123. return string(arg_ds.GetItemDecimal(arg_row, arg_colname))
  124. END IF
  125. IF pos(ls_coltype, 'datetime') > 0 THEN
  126. return string(arg_ds.GetItemDateTime(arg_row, arg_colname), 'yyyy-MM-dd')
  127. END IF
  128. IF pos(ls_coltype, 'date') > 0 THEN
  129. return string(arg_ds.GetItemDate(arg_row, arg_colname), 'yyyy-MM-dd')
  130. END IF
  131. IF pos(ls_coltype, 'time') > 0 THEN
  132. return string(arg_ds.GetItemTime(arg_row, arg_colname), 'HH:mm:ss')
  133. END IF
  134. IF pos(ls_coltype, 'long') > 0 OR pos(ls_coltype, 'num') > 0 OR pos(ls_coltype, 'int') > 0 THEN
  135. return string(arg_ds.GetItemNumber(arg_row, arg_colname))
  136. END IF
  137. return "''"
  138. end function
  139. public function string uof_getitemname (datastore arg_ds, long arg_row, string arg_colname);string ls_style
  140. ls_style = lower(arg_ds.Describe(arg_colname + ".Edit.Style"))
  141. if ls_style = 'checkbox' then
  142. IF arg_ds.GetItemNumber(arg_row, arg_colname) = 1 THEN
  143. return '✔'
  144. ELSE
  145. return '❌'
  146. END IF
  147. else
  148. return arg_ds.Describe("Evaluate('lookupdisplay("+arg_colname+")',"+String(arg_row)+")")
  149. end if
  150. end function
  151. public function string uof_getitemname (datawindow arg_ds, long arg_row, string arg_colname);string ls_style
  152. ls_style = lower(arg_ds.Describe(arg_colname + ".Edit.Style"))
  153. if ls_style = 'checkbox' then
  154. IF arg_ds.GetItemNumber(arg_row, arg_colname) = 1 THEN
  155. return '✔'
  156. ELSE
  157. return '❌'
  158. END IF
  159. else
  160. return arg_ds.Describe("Evaluate('lookupdisplay("+arg_colname+")',"+String(arg_row)+")")
  161. end if
  162. end function
  163. public function string uf_add_single_quotes (string arg_str);string reslt = ''
  164. string arr_ids[]
  165. long i
  166. uof_split(arg_str, ',', Ref arr_ids)
  167. FOR i = 1 To UpperBound(arr_ids)
  168. IF reslt <> '' THEN reslt += ','
  169. reslt += "'"+arr_ids[i] + "'"
  170. NEXT
  171. return reslt
  172. end function
  173. public function string uof_getitemformattedstring (datawindow arg_dw, long arg_row, string arg_colname);return arg_dw.Describe("Evaluate('lookupdisplay("+ arg_colname+")',"+String(arg_row)+")")
  174. end function
  175. public function string uof_dw_getsortname (datawindow arg_dw);String ls_sort
  176. ls_sort = arg_dw.Describe("DataWindow.Table.Sort")
  177. IF Len(ls_sort) < 3 THEN
  178. RETURN ""
  179. END IF
  180. String arr_col[]
  181. uof_split(ls_sort, ",", Ref arr_col)
  182. Long i, ll_pos
  183. String ls_colname, ls_s, ls_rslt = '', ls_tmp
  184. FOR i = 1 To UpperBound(arr_col)
  185. ls_colname = Trim(Lower(arr_col[i]))
  186. ll_pos = Pos(ls_colname, ' ')
  187. IF ll_pos > 0 THEN
  188. ls_s = Trim(Mid(ls_colname, ll_pos + 1))
  189. ls_colname = Left(ls_colname, ll_pos - 1)
  190. ELSE
  191. ls_s = 'a'
  192. END IF
  193. ls_tmp = Trim(arg_dw.Describe(ls_colname+"_t.Text"))
  194. IF ls_tmp = '!' Or ls_tmp = '?' THEN
  195. ls_rslt += ls_colname
  196. ELSE
  197. ls_rslt += ls_tmp
  198. END IF
  199. IF mid(ls_s, 1, 1) = 'a' THEN
  200. ls_rslt += "▲"
  201. ELSE
  202. ls_rslt += "▼"
  203. END IF
  204. ls_rslt += ","
  205. NEXT
  206. return ls_rslt
  207. end function
  208. public function integer uof_dw_append_filter (datawindow arg_dw, ref string arg_filter);String ls_filter
  209. ls_filter = arg_dw.Describe("DataWindow.Table.Filter")
  210. ls_filter = uof_replace(ls_filter, "~~~~", "~~")
  211. ls_filter = uof_replace(ls_filter, "~~~"", "~"")
  212. arg_filter = "("+arg_filter+")"
  213. IF len(ls_filter) > 1 THEN
  214. ls_filter += " AND " + arg_filter
  215. ELSE
  216. ls_filter = arg_filter
  217. END IF
  218. arg_filter = ls_filter
  219. RETURN arg_dw.SetFilter(ls_filter)
  220. end function
  221. public function integer uof_dw_append_sort (datawindow arg_dw, ref string arg_sort);String ls_sort
  222. ls_sort = arg_dw.Describe("DataWindow.Table.Sort")
  223. IF Len(ls_sort) < 3 THEN
  224. ls_sort = arg_sort
  225. ELSE
  226. ls_sort += ","+arg_sort
  227. END IF
  228. arg_sort = ls_sort
  229. return arg_dw.SetSort(ls_sort)
  230. end function
  231. on uo_string.create
  232. call super::create
  233. TriggerEvent( this, "constructor" )
  234. end on
  235. on uo_string.destroy
  236. TriggerEvent( this, "destructor" )
  237. call super::destroy
  238. end on