思路 更改 数据窗口的sql 通过sql拼接字符串
参考代码
string temp_string
string where_string
string ls_old_sql,ls_new_sql
long ll_all
Date ls_start_date,ls_end_date
Boolean start_is_date,end_is_date
start_is_date = FALSE
end_is_date = FALSE
if IsDate(em_startdate.Text) and em_startdate.Text<>"0000-01-01"then
ls_start_date=date(em_startdate.Text)
start_is_date = TRUE
end if
if IsDate(em_enddate.Text) and em_enddate.Text<>"0000-01-01" then
ls_end_date=date(em_enddate.Text)
ls_end_date=RelativeDate(ls_end_date, 1)
end_is_date = TRUE
end if
IF start_is_date AND end_is_date THEN
IF ls_end_date < ls_start_date THEN
messagebox("错误信息","起始时间不能大于终止时间")
em_startdate.SetFocus()
return
END IF
END IF
IF NOT(start_is_date) THEN
em_startdate.text = "0000-01-01"
END IF
IF NOT(end_is_date) THEN
em_enddate.text = "0000-01-01"
END IF
temp_string = Trim(sle_rcpt_no.Text)
if len(temp_string)>1 then
where_string = " and RCPT_NO='"+temp_string+"'"
end if
temp_string = Trim(sle_name.Text)
if len(temp_string)>1 then
where_string = where_string + " and NAME like '%"+temp_string+"%'"
end if
temp_string = Trim(sle_oper.Text)
if len(temp_string)>1 then
where_string = where_string + " and OPERATOR_NO='"+temp_string+"'"
end if
temp_string = trim(sle_patient_id.Text)
if len(temp_string)>1 then
where_string = where_string + " and PATIENT_ID='"+temp_string+"'"
end if
IF start_is_date THEN
where_string = where_string + " and VISIT_DATE>=to_DATE('"+em_startdate.Text+"','YYYY-MM-DD')"
END IF
IF end_is_date THEN
where_string = where_string + " and VISIT_DATE<=to_DATE('"+STRING(LS_END_DATE,'YYYY-MM-DD')+"','YYYY-MM-DD')"
END IF
ls_old_sql=dw_main.getsqlselect( )
IF where_string<>"" THEN
ls_new_sql = ls_old_sql + " WHERE 1=1 " + where_string
dw_main.setsqlselect(ls_new_sql)
end if
ll_all = dw_main.retrieve( )
dw_main.setsqlselect(ls_old_sql)
IF ll_all<=0 THEN
MessageBox("数据为空","没有满足查询条件的收据")
sle_rcpt_no.SetFocus()
Return
END IF
dw_main.SetFocus()