在最近的开发中,发现上一次发的网格部件判断字段不能为空的代码,还存在不足:
如果在保存前将网格中某条数据用下面代码删除:

if showquestion("确定要删除焦点行吗?") then
        采购计划打分详细.DeleteFocusedRow()
end if

那么在执行上一贴中代码时,就会报错。


改进示例:

'提交单元和数据到行
采购计划打分详细.PostEditor()
'提交行数据到DataTable
采购计划打分详细.GridView.UpdateCurrentRow()
'批量添加打分ID
采购计划打分详细.SetColumnValue("打分ID",记录部件1.GetFieldValue("ID"),1)
       
'BeginTrans()
'这儿操作数据库。
记录部件1.SaveData()
采购计划打分详细.SaveData()
'判断事务执行结果
if CommitTrans()=false then
    showerror(GetTransMessage())
end if   

dim A = 0
dim dt=采购计划打分详细.DataTable
'保存前询问“这些年度采购计划是否已经在会上讨论过?”
if ShowQuestion("这些年度采购计划是否已经在会上讨论过?") then
    for each dr in dt.Rows
      if isnull(dr["总分"]) or  isnull(dr["审批情况"]) then
        A = 1
        exit for
      end if
    next
else
    for each dr in dt.Rows
      if isnull(dr["总分"]) then
        A = 2
        exit for
      end if
    next
end if

if A = 1 then
    ShowInformation("请将【审批情况】、【总分】填写完整")
    
    dim b=采购计划打分详细.AddColumnStyleByExpression("审批情况","[审批情况] is null",True)
    b.Appearance.ForeColor=Color.FromArgb(-65536)
    dim c=采购计划打分详细.AddColumnStyleByExpression("总分","[总分] is null",True)
    c.Appearance.ForeColor=Color.FromArgb(-65536)
else if A = 2 then
    ShowInformation("请将【总分】填写完整")
    
    dim d=采购计划打分详细.AddColumnStyleByExpression("总分","[总分] is null",True)
    d.Appearance.ForeColor=Color.FromArgb(-65536)
    
else 
    me.Output1 = "Y"
    ShowInformation("保存成功")
    me.Close()
end if

原文地址:http://bbs.delit.cn/thread-957-1-1.html

转载请注明出处:

撰写人:度量科技http://www.delit.cn