pb数据窗口中设置“员工”子数据窗口并自动匹配部门、职务;如何判断数据窗口中列字段的值是否有输入重复
在数据窗口的设计界面选中需要添加“员工”子窗口的字段,编辑其属性如下:
1 //dw_2 itemchanged() 行有改变时触发 2 Long ll_row,ll_find 3 String ls_no,ls_id,ls_dept,ls_part 4 DataWindowChild ldwc_obj 5 6 if row < 1 then Return 7 Choose Case dwo.Name 8 Case 'emp_id' 9 if IsNull(data) Or Len(Trim(data)) = 0 then 10 of_MessageBox("提示","请输入名字!") 11 Return -1 12 end if 13 if this.GetChild("emp_id",ldwc_obj) = 1 then 14 // 在“员工”子数据窗口中匹配输入的名字 15 ll_row = ldwc_obj.Find("emp_id = '" + Data+"'",1,ldwc_obj.RowCount()) 16 // 没找到 17 if ll_row = 0 then 18 of_MessageBox("提示","人员不存在,请重新选择!") 19 Return -1 20 end if 21 // 找到了,自动匹配部门、职务 22 this.object.dept_name[row]= ldwc_obj.GetItemString(ll_row,"dept_name") 23 this.object.duty_name[row]= ldwc_obj.GetItemString(ll_row,"duty_name") 24 end if 25 26 Case else 27 return 1 28 End Choose
dw_2通知人的数据窗口的for循环代码,如下:
// 设置列对子数据窗口对象的引用 if dw_2.GetChild("emp_id",ldwc_obj) <> 1 then return -1 // 遍历细表数据窗口 For ll_row_detail = 1 To dw_2.RowCount() IF dw_2.GetItemStatus(ll_row_detail,0,Primary!) = NotModified! Then Continue if isnull(dw_1.Object.mes_id[dw_1.getrow()]) then MessageBox("提示", "请先保存消息通知") return -1 end if ll_id = dw_2.Object.id[ll_row_detail] ls_emp_id = dw_2.Object.emp_id[ll_row_detail] ll_mes_id = dw_2.Object.mes_id[ll_row_detail] // 先在“员工”子数据窗口中查找(判合法),返回找到的行数 ll_find = ldwc_obj.find("emp_id = '"+ls_emp_id+"'",1,ldwc_obj.rowcount()) // 查到,输入合法 if ll_find >0 then // 再在数据窗口中查找(判重复) ll_find = dw_2.find("emp_id = '"+ls_emp_id+"'",1,dw_2.rowcount()) // 查找到的不是最后一行,说明在此之前已存在(如是新增只能在最后一行找到) if ll_find < dw_2.rowcount() then //从找到行的下一行开始再找,找到了说明有两行 ll_find = dw_2.find("emp_id = '"+ls_emp_id+"'",ll_find+1,dw_2.rowcount()) if ll_find > 0 then dw_2.SetRow(ll_row_detail) dw_2.ScrollToRow(ll_row_detail) dw_2.SetColumn('emp_id') dw_2.SetFocus() MessageBox("提示", "通知人重复!") Return -1 end if end if // 没找到该“员工” else dw_2.SetRow(ll_row_detail) dw_2.ScrollToRow(ll_row_detail) dw_2.SetColumn('emp_id') dw_2.SetFocus() MessageBox("提示","非法用户!") Return -1 end if IF IsNull(ls_emp_id) Or Len(Trim(ls_emp_id)) = 0 Then dw_2.SetRow(ll_row_detail) dw_2.ScrollToRow(ll_row_detail) dw_2.SetColumn('emp_id') dw_2.SetFocus() MessageBox("提示","请输入通知人!") Return -1 End IF IF dw_2.GetItemStatus(ll_row_detail,0,Primary!) = New! Or & dw_2.GetItemStatus(ll_row_detail,0,Primary!) = NewModified! Then IF isnull(dw_2.Object.create_user[ll_row_detail]) Then dw_2.Object.create_time[ll_row_detail] = gf_Get_SysDateTime() dw_2.Object.create_user[ll_row_detail] = gs_empname dw_2.Object.trans_time[ll_row_detail] = gf_Get_SysDateTime() dw_2.Object.trans_user[ll_row_detail] = gs_empname else dw_2.Object.trans_time[ll_row_detail] = gf_Get_SysDateTime() dw_2.Object.trans_user[ll_row_detail] = gs_empname End IF End IF // 行内容有改动时只更新修改人和修改时间 if dw_2.of_updatespEnding() = 1 then dw_2.Object.trans_time[ll_row_detail] = gf_Get_SysDateTime() dw_2.Object.trans_user[ll_row_detail] = gs_empname end if End For