利用数据窗口不同缓冲区的值做用户操作日志

利用数据窗口不同缓冲区的值做用户操作日志。

用户操作主要有三种形式:新增数据,修改数据,删除数据。利用数据窗口的不同缓冲区取值得到用户的实际操作,步骤如下:

1)新建不可视用户对象,添加一个datastore实例变量,用于保存用户操作内容,添加三个事件,记用户的登录,退出,操作,其中修改的操作能记录下用户修改前的值与修改后的值并成对放在一起。新建一个主要的函数取用户操作内容,如下:

//==============================================================================
// 描述: of_get_action()取用户操作内容.
//------------------------------------------------------------------------------
// 参数:
//  value u_dw adw_action  (操作对象,用户面对的操作对象排除DataStore)
//------------------------------------------------------------------------------
// 返回值:  string (操作内容)
//------------------------------------------------------------------------------
// 日期: 2007.10.26
//==============================================================================
String ls_action,ls_old,ls_new,ls_old_str,ls_new_str,ls_column,ls_col_name, &
   ls_new_bill_num,ls_old_bill_num
Int li_row,i,li_column,j
dwitemstatus l_status

li_row = adw_action.RowCount()

For i = 1 To li_row
 l_status = adw_action.GetItemStatus(i, 0, primary!)
 li_column = Integer(adw_action.Object.datawindow.column.count)
 If l_status = datamodified! Then
  For j = 1 To li_column
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'create_by' Then Continue;  //排除不必要的数据
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'create_date' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'update_by' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'update_date' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'password' Then Continue;
   ls_column = adw_action.Describe("#"+String(j)+".name")
   ls_col_name = adw_action.Describe(ls_column+"_t.Text")
   If ls_col_name = '!' Or ls_col_name = '?' Then
    Continue;    //不直观可视的字段退出
//    ls_col_name = ls_column
   End If
   If Right(ls_col_name,1) <> ':' Then ls_col_name += ':'    //末尾为冒号
   ls_old = String(adw_action.Object.Data.original[i,j])
   ls_new = String(adw_action.Object.Data[i,j])
   If IsNull(ls_old) Then ls_old = ''
   If IsNull(ls_new) Then ls_new = ''
   If (adw_action.Describe("#"+String(j)+ ".key") = 'yes') Or ls_old <> ls_new Then
    ls_old_str += '| '+ls_col_name+' '+ ls_old
    ls_new_str += '| '+ls_col_name+' '+ ls_new
   End If
   If ls_column = 'bill_num' Then    //单据编号
    ls_new_bill_num = '| '+ls_col_name+' '+ ls_new
    ls_old_bill_num = '| '+ls_col_name+' '+ ls_old
   End If
  Next
  If Len(ls_old_str) > 0 And Len(ls_new_str) > 0 Then
   If Len(ls_old_bill_num) > 0 Then ls_old_str = ls_old_bill_num +ls_old_str    //如有单号则加上
   If Len(ls_new_bill_num) > 0 Then ls_new_str = ls_new_bill_num +ls_new_str    //如有单号则加上
   ls_action += ' (修改资料)   '+ls_old_str+' |~n' +' (修改资料)   '+ls_new_str+' |~n~n'
  End If
  ls_old_str = ''
  ls_new_str = ''
  ls_new_bill_num = ''
  ls_old_bill_num = ''
 End If
 If l_status = newmodified! Then
  For j = 1 To li_column
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'create_by' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'create_date' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'update_by' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'update_date' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'password' Then Continue;
   ls_column = adw_action.Describe("#"+String(j)+".name")
   ls_col_name = adw_action.Describe(ls_column+"_t.Text")
   If ls_col_name = '!' Or ls_col_name = '?' Then
    Continue;    //不直观可视的字段退出
//    ls_col_name = ls_column
   End If
   If Right(ls_col_name,1) <> ':' Then ls_col_name += ':'    //末尾为冒号
   ls_new = String(adw_action.Object.Data[i,j])
   If IsNull(ls_new) Then ls_new = ''
   ls_new_str += '| '+ls_col_name+' '+ ls_new
  Next
  ls_action += ' (新增资料)   '+ls_new_str+' |~n' 
  ls_new_str = ''
 End If
Next

If adw_action.DeletedCount() > 0 Then
 For i = 1 To adw_action.DeletedCount()
  li_column = Integer(adw_action.Object.datawindow.column.count)
  For j = 1 To li_column
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'create_by' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'create_date' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'update_by' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'update_date' Then Continue;
   If Lower(adw_action.Describe("#"+String(j)+".name")) = 'password' Then Continue;
   ls_column = adw_action.Describe("#"+String(j)+".name")
   ls_col_name = adw_action.Describe(ls_column+"_t.Text")
   If ls_col_name = '!' Or ls_col_name = '?' Then
    Continue;    //不直观可视的字段退出
//    ls_col_name = ls_column
   End If
   If Right(ls_col_name,1) <> ':' Then ls_col_name += ':'    //末尾为冒号
   ls_old = String(adw_action.Object.Data.Delete[i,j])
   If IsNull(ls_old) Then ls_old = ''
   ls_old_str += '| '+ls_col_name+' '+ ls_old
  Next
  ls_action += ' (删除资料)   '+ls_old_str+' |~n'
  ls_old_str = ''
 Next
End If

Return ls_action

2)新建三个事件,ue_login() //登录,ue_exit() //退出,ue_save()  //用户操作

其中用户操作事件记录用户对数据的增、删、改,该事件主要利用数据窗口的各个缓冲区值做记录。

//==============================================================================
// 描述: ue_save()事件,保存操作日志.
//------------------------------------------------------------------------------
// 参数:
//  value string as_object  (程式名称)
//  value u_dw   adw_action  (操作的数据窗囗)
//------------------------------------------------------------------------------
// 返回值:  integer
//------------------------------------------------------------------------------
// 日期: 2007.10.26
//==============================================================================
String ls_object,ls_action
Int li_rtn

ls_object = as_object
ls_action = of_get_action(adw_action)  //取用户操作

li_rtn = ids_syslog.InsertRow(0)

If li_rtn <= 0 Then Return -1

ids_syslog.Object.seq_num[li_rtn] = of_getseq()  //其他记录内容自行添加
ids_syslog.Object.acc_date[li_rtn] = of_get_date()
ids_syslog.Object.co_code[li_rtn] = gs_co_code
ids_syslog.Object.module[li_rtn] = gs_module
ids_syslog.Object.dept_code[li_rtn] = gs_dept_code
ids_syslog.Object.computer[li_rtn] = f_get_computer()
ids_syslog.Object.user_num[li_rtn] = gs_user_num
ids_syslog.Object.acc_object[li_rtn] = ls_object
ids_syslog.Object.acc_detail[li_rtn] = ls_action

Return ids_syslog.Event ue_save()  //保存

总结:功能算是实现了,欠灵活控制,只能做成全局实例而且只能在程序里写死需要监控的内容。

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值