原创实用代码(二)

一、人民币大写转换

//====================================================================
// 事件: .f_amount_upper()
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 參數:
//  value double ad_amout 
//--------------------------------------------------------------------
// 返回:  string
//--------------------------------------------------------------------
// 作者: woyor  日期: 2009年05月20日
//--------------------------------------------------------------------
// Copyright (c) 2006-2007 wy(TM), All rights reserved.
//--------------------------------------------------------------------
// 修改歷史:
//
//====================================================================
//2009.05.20 wy
// f_amount_upper( double ad_amout ) return string
// 小寫金額轉換為大寫金額
// 轉換成功返回大寫金額, 否則返回空串

string ls_hz1[] , ls_hz2[] , ls_return , ls_temp , ls_argument

int li_1 , li_len

boolean lb_first_zero

ls_hz1[1] = "分"

ls_hz1[2] = "角"

ls_hz1[3] = ""

ls_hz1[4] = "元"

ls_hz1[5] = "拾"

ls_hz1[6] = "佰"

ls_hz1[7] = "仟"

ls_hz1[8] = "万"

ls_hz1[9] = "拾"

ls_hz1[10] = "佰"

ls_hz1[11] = "仟"

ls_hz1[12] = "亿"

ls_hz1[13] = "拾"

ls_hz1[14] = "佰"

ls_hz1[15] = "仟"

ls_hz2[1] = "壹"

ls_hz2[2] = "贰"

ls_hz2[3] = "叁"

ls_hz2[4] = "肆"

ls_hz2[5] = "伍"

ls_hz2[6] = "陆"

ls_hz2[7] = "柒"

ls_hz2[8] = "捌"

ls_hz2[9] = "玖"

ls_hz2[10] = "零"

If ad_amout = 0 Then

 Return ''

End If

ls_argument = string( ad_amout ,"############0.00")

// 數值不能大於千億

If len( ls_argument ) > 15 Then

 Return ''

End If

If right(ls_argument,1) = '0' Then ls_return = '整'

Do While True

 li_1 += 1

 li_len = len( ls_argument )

 ls_temp = right( ls_argument , 1 ) //提取最低位

 ls_argument = left( ls_argument , li_len - 1 ) //去掉最低位

 If ls_temp = '' Or isnull( ls_temp ) Then

  Exit //最高位已被取出則退出迴圈

 End If

 If ls_temp = '.' Then

  Continue //遇見小數點繼續向高位迴圈

 End If

 If ls_temp = '-' Then

  ls_return = '负' + ls_return

  Continue

 End If

 If ls_temp <> '0' Then

  ls_return = ls_hz2[integer(ls_temp)] + ls_hz1[ li_1 ] + ls_return //加對應的大寫數額和單位

  lb_first_zero = True

 Else

  If lb_first_zero Then

   if (li_1 <> 4 And li_1 <> 2) Or dec(ls_argument) <> 0 Then

    ls_return = '零' + ls_return //如果第一次遇見'0',除元、角

   End If //外,前面加'零'

   lb_first_zero = False

  End If

  If li_1 = 12 Or li_1 = 8 Then

   If right(ls_argument, 3) <> '000' Then ls_return = ls_hz1[ li_1] + ls_return

  End If //如果'萬'、'億'前不為零則

  If li_1 = 4 Then //加'萬'、'億'

   If dec(ls_argument) <> 0 Then ls_return = ls_hz1[ li_1 ] + ls_return

  End If

 End If

Loop

Return ls_return

二、PB身份证号码正确性校验

//*-------------------------------------------------------------------------------
//* 函数名称:Boolean gf_check_identity(string as_identity)
//* 函数功能: 验证身份证号输入的正确性
//* 参数说明: string      as_identity    身份证号
//* 返 回 值: True  成功
//*            False 失败
//* 调用举例: gf_check_identity('410101650101101')  //* 尚未完善:没有对身份证号码的第18位校验位进行判断。因为我暂时没有找到第18位
//* 的校验算法,等找到了我再加上。应该比较简单。
//*--------------------------------------------------------------------------------*/
string ls_identity_no
string ls_year,ls_month,ls_day,ls_date
string ls_today
long ll_year
long ll_identity_no_len  

ls_identity_no = as_identity
ls_today = string(today(),'yyyy/mm/dd')

ll_identity_no_len=LEN(ls_identity_no)

if ls_identity_no = ''  then
     MessageBox("系统提示","身份证号码不能为空!!",StopSign!,ok!)
    return False
elseif ll_identity_no_len <> 15 AND ll_identity_no_len <> 18 then
    MessageBox("系统提示","身份证号码位数不足,请检查输入情况!!",StopSign!,ok!)
    return False
end if

if ll_identity_no_len = 15 then //身份证为 15 处理,  认为15位的年 = 19**
    ls_year = mid(ls_identity_no, 7, 2)
    ls_month = mid(ls_identity_no, 9, 2)
    ls_day = mid(ls_identity_no, 11, 2)
    ls_year = '19' + ls_year//year is only 20 century
    ls_date = ls_year +'/' + ls_month +'/' + ls_day
else
    ls_year = mid(ls_identity_no, 7, 4)
    if Left(ls_year,2) <> '19' and left(ls_year,2) <> '20' then
    MessageBox("系统提示","身份证号码中的出生年份不正确, 请您重新输入! ",StopSign!,ok!)
    return False
end if
    ls_month = mid(ls_identity_no, 11, 2)
    ls_day = mid(ls_identity_no, 13, 2)
    ls_date = ls_year +'/' + ls_month +'/' + ls_day
end if

if ls_month > '12' then
    MessageBox("系统提示","身份证号码中的出生月份大于12, 请您重新输入 ",StopSign!,ok!)
    return False
elseif ls_month < '1' then
    MessageBox("系统提示","身份证号码中的出生月份小于01, 请您重新输入 ",StopSign!,ok!)
    return False
end if

if ls_day < '01' then
    MessageBox("系统提示","身份证号码的出生日小于01, 请您重新输入 !",StopSign!,ok!)
    return False
end if

CHOOSE CASE ls_month
    CASE '01','03','05','07','08','10','12'//大月的处理
        if ls_day > '31' then
            MessageBox("系统提示","身份证号码的出生日大于31, 请您重新输入 !",StopSign!,ok!)
            return False
        end if

    CASE '04','06','05','09','11' //小月的处理
        if ls_day > '30' then
            MessageBox("系统提示","身份证号码的出生日大于30, 请您重新输入 !",StopSign!,ok!)
            return False
        end if
    CASE '02'  //平年和闰年的处理
        ll_year = long(ls_year)
        if (mod(ll_year,4) = 0 and Mod(ll_year,100)<>0) or (Mod(ll_year,400) = 0) then   //闰年,二月份不能多于29天
            if ls_day > '29' then
                MessageBox("系统提示","闰年的二月份没有" + ls_day + "日,请重新输入出生日期!",StopSign!,ok!)
                return False
            end if
        else//平年二月份不能大于28天
            if ls_day > '28' then
                MessageBox("系统提示","平年的二月份没有" + ls_day + "日,请重新输入出生日期!",StopSign!,ok!)
                return 提lse
            end if
        end if
    END CHOOSE

if ls_date > ls_today then
    MessageBox("系统提示","身份证号码的出生日期小于登记日期,不合理请您重新输入 !",StopSign!,ok!)
    return False
end if

return True

三、从数据库中取数据添加到DDLB控件中的通用函数

/**********************************************************************************/
// 从数据库中取数据添加到DDLB控件中的通用函数
// 同时适用于listbox控件
// 变量设置:return typeinteger
// Pass By                Argument Type                Function Name
//  value                   string                      table_name
//  value                   string                      column_name
//  value                   dropdownlistbox             ddlb_parm
//  value                   string                      where_clause
//  value                   any                         where_variable
//
// 调用格式:
//   uf_ddlb_from_db(table_name,column_name,ddlb_parm,where_clause,where_variable)
// 例如:uf_ddlb_from_db("专业表,院系表","专业名称",ddlb_1,"(专业表.院系名称 = 院系表.院系代码) AND 院系表.院系名称 = ?",yx_name)
//       uf_ddlb_from_db("t_city_dictionary","cd_city",tab_1.tabpage_1.ddlb_76,"cd_province = ?","辽宁")
/***********************************************************************************/
string ls_add_string,ls_select_string
string where_var_string
real where_var_num
int li_pos

//根据传递的参数设置select语句
if len(trim(where_clause)) = 0 then
    ls_select_string = "SELECT DISTINCT " + column_name + " FROM " + table_name
else
    ls_select_string = "SELECT DISTINCT " + column_name + " FROM " + table_name + " WHERE " + where_clause
end if

DECLARE dyn_cursor DYNAMIC CURSOR FOR sqlsa;
PREPARE sqlsa FROM :ls_select_string;
/* OPEN DYNAMIC dyn_cursor using :where_variable; */
/* 根据where_variable的类型,分别处理。其他类型可以在此添加 */
if len(trim(where_clause)) > 0 then
    if classname(where_variable) = 'string' then
        /* 判断where_variable是否有值 */
        if len(trim(where_variable)) = 0 then
            OPEN DYNAMIC dyn_cursor;
        else
            where_var_string = where_variable
            OPEN DYNAMIC dyn_cursor using :where_var_string;
        end if
    end if
    if classname(where_variable) = 'real' then
        where_var_string = where_variable
        OPEN DYNAMIC dyn_cursor using :where_var_num;
    end if
else
    OPEN DYNAMIC dyn_cursor;
end if
if sqlca.sqlcode < 0 then
    MessageBox("数据库错误!",sqlca.sqlerrtext)
    return sqlca.sqlcode
end if

ddlb_parm.SetRedraw(false)
ddlb_parm.reset()
/* 将数据取出并添加到DDLB控件 */
Do While sqlca.sqlcode = 0
    Fetch dyn_cursor into :ls_add_string;
    if sqlca.sqlcode = 0 then
        ddlb_parm.AddItem(ls_add_string)
    elseif sqlca.sqlcode < 0 then
        MessageBox("数据库错误!",sqlca.sqlerrtext)
        return sqlca.sqlcode
    else
        exit
    end
 if
Loop
ddlb_parm.SetRedraw(true)
Close dyn_cursor;
return 0

四、数据窗口列名轮询代码

//*********************************************************
//轮询数据窗口列名
//*********************************************************
String ls_display
String ls_column_name[] //存放列名
String ls_column_text[] //存放列标题名称
Integer i,li_column_count 
//得到数据窗口的总列数 
li_column_count = long(ds_1.Describe("DataWindow.Column.Count"))

//循环依次读取 
for i = 1 to li_column_count
    ls_column_name[i] = ds_1.Describe("#"+string(i)+".name") 
    ls_column_text[i] = ds_1.Describe(ls_column_name[i] + "_t.text")
    ls_display += '列名:' + ls_column_name[i] + ';  存放列标题名称:' + ls_column_text[i] + '~r~n'
next
messagebox('显示',ls_display)

//*********************************************************
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值