$PBExportHeader$w_fx_check_bill_saletaskmx_choose1.srw
forward
global type w_fx_check_bill_saletaskmx_choose1 from w_pageretr_ch
end type
type cbx_mlselect from checkbox within w_fx_check_bill_saletaskmx_choose1
end type
type cbx_all from checkbox within w_fx_check_bill_saletaskmx_choose1
end type
type dw_choice from datawindow within w_fx_check_bill_saletaskmx_choose1
end type
type cb_ok from uo_imflatbutton within w_fx_check_bill_saletaskmx_choose1
end type
type cb_del from uo_imflatbutton within w_fx_check_bill_saletaskmx_choose1
end type
type cbx_ml from checkbox within w_fx_check_bill_saletaskmx_choose1
end type
end forward

global type w_fx_check_bill_saletaskmx_choose1 from w_pageretr_ch
integer width = 4325
integer height = 2380
string title = "采购订单选择"
boolean center = true
cbx_mlselect cbx_mlselect
cbx_all cbx_all
dw_choice dw_choice
cb_ok cb_ok
cb_del cb_del
cbx_ml cbx_ml
end type
global w_fx_check_bill_saletaskmx_choose1 w_fx_check_bill_saletaskmx_choose1

type variables
//s_mtrldef_buytask_array INS_RT_STRU
boolean  if_changeselect=true
int if_mlselect=0
long cur_sptid
long cur_ifth = 0
long cur_storageid = -1
Long cur_scid = -1

Long ins_cuscomid
long ins_checktype_fx
end variables

forward prototypes
public function integer wf_face_change ()
public subroutine wf_retrieve_mx ()
end prototypes

public function integer wf_face_change ();//wf_face_change()
IF Not cbx_ml.Checked THEN
	dw_pageretr.Height = dw_choice.Y + dw_choice.Height - dw_pageretr.Y
	dw_choice.Visible = False
	cb_ok.Visible = False
	cb_del.Visible = False
ELSE
	dw_pageretr.Height = 1300
	dw_choice.Visible = True
	cb_ok.Visible = True
	cb_del.Visible = True
END IF


RETURN 1


end function

public subroutine wf_retrieve_mx ();string arg_msg
long i,row
oleobject request,response,mxs,item

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('cuscomid',ins_cuscomid)
request.SetInt('billtype',1)
request.SetInt('checktype_fx',ins_checktype_fx)

response = FXAppCom.DoExecute('GetFixCheckBillSaletaskmxSelect', request)
arg_msg = response.GetString('ErrMsg')

if (arg_msg <> '') then
    messagebox('提示', '获取订单明细失败，原因：' + arg_msg)
    return
end if

dw_pageretr.Reset()
dw_pageretr.SetRedraw(false)

mxs = response.GetArrOfPBDictionary('mxs')
Datetime ld_now,requiredate
ld_now = DateTime(Today(),Now())
for i = 1 to mxs.Count
    item = mxs.GetItem(i - 1)
    
    row = dw_pageretr.InsertRow(0)
	
	dw_pageretr.Object.taskcode[row] = item.GetString('taskcode')
    dw_pageretr.Object.fx_saletaskmx_reltaskid[row] = item.GetInt('taskid')
    dw_pageretr.Object.fx_saletaskmx_relprintid[row] = item.GetInt('printid')


    dw_pageretr.Object.mtrlcode[row] = item.GetString('mtrlcode')
    dw_pageretr.Object.mtrlname[row] = item.GetString('mtrlname')
    dw_pageretr.Object.mtrlmode[row] = item.GetString('mtrlmode')
    dw_pageretr.Object.status[row] = item.GetString('status')
    dw_pageretr.Object.woodcode[row] = item.GetString('woodcode')
    dw_pageretr.Object.pcode[row] = item.GetString('pcode')
    dw_pageretr.Object.forqty[row] = item.GetDouble('qty')
 
  
next

dw_pageretr.SetRedraw(true)





end subroutine

on w_fx_check_bill_saletaskmx_choose1.create
int iCurrent
call super::create
this.cbx_mlselect=create cbx_mlselect
this.cbx_all=create cbx_all
this.dw_choice=create dw_choice
this.cb_ok=create cb_ok
this.cb_del=create cb_del
this.cbx_ml=create cbx_ml
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cbx_mlselect
this.Control[iCurrent+2]=this.cbx_all
this.Control[iCurrent+3]=this.dw_choice
this.Control[iCurrent+4]=this.cb_ok
this.Control[iCurrent+5]=this.cb_del
this.Control[iCurrent+6]=this.cbx_ml
end on

on w_fx_check_bill_saletaskmx_choose1.destroy
call super::destroy
destroy(this.cbx_mlselect)
destroy(this.cbx_all)
destroy(this.dw_choice)
destroy(this.cb_ok)
destroy(this.cb_del)
destroy(this.cbx_ml)
end on

event ue_usual_query_filt;call super::ue_usual_query_filt;string obj_expr=''  
if trim(sle_usual_query.text)<>'' then 
	if pos(trim(sle_usual_query.text),'%')=0 then
		obj_expr=obj_expr+'( u_mtrldef_mtrlcode like "%'+trim(sle_usual_query.text)+'%" )'
	else
		obj_expr=obj_expr+'( u_mtrldef_mtrlcode like "'+trim(sle_usual_query.text)+'" )'
	end if 
end if

dw_pageretr.setfilter(obj_expr)

dw_pageretr.setredraw(false)
dw_pageretr.filter()
if dw_pageretr.rowcount()>=1 then
	dw_pageretr.selectrow(0,false)
	dw_pageretr.selectrow(1,true)
end if
dw_pageretr.setredraw(true)
end event

event ue_usual_query_retr;call super::ue_usual_query_retr;string ls_querystrpart=''
ls_newselect=lower(ori_oldselect)
if trim(sle_usual_query.text)<>'' then
	if pos(trim(sle_usual_query.text),'%')=0 then
		ls_querystrpart="(u_mtrldef.mtrlcode like '%"+trim(sle_usual_query.text)+"%')"
	else
		ls_querystrpart="(u_mtrldef.mtrlcode like '"+trim(sle_usual_query.text)+"')"
	end if

	if pos(ls_newselect," where ") <> 0 then
	   ls_newselect=ls_newselect+" and ("+ls_querystrpart+')'
	else
		ls_newselect=ls_newselect+" where ("+ls_querystrpart+')'
	end if
end if
wf_retrieveuc(dw_pageretr,ls_newselect,1)  
this.triggerevent('retrieve_pageretr')

end event

event close;//CLOSEWITHRETURN(THIS,INS_RT_STRU)
//<INS_RT_STRU> 窗体级子定义结构变量,用于返回
end event

event open;
s_edit_index_tran s_ch_tran //传递参数使用
s_ch_tran = Message.PowerObjectParm
ins_cuscomid =s_ch_tran.b_long
ins_checktype_fx=s_ch_tran.c_long
wf_movetocenter()

wf_retrieve_mx()
end event

event ue_before_open;call super::ue_before_open;if_ue_sort=true
end event

event retrieve_pageretr;//Boolean cb_firstpage_enabled,cb_nextpage_enabled,cb_retrieveall_enabled
//Boolean cb_priorpage_enabled,cb_func_enabled,cb_retrieve_enabled
//
//cb_nextpage_enabled = cb_nextpage.Enabled
//cb_retrieveall_enabled = cb_retrieveall.Enabled
//cb_func_enabled = cb_func.Enabled
//
//cb_nextpage.Enabled = FALSE
//cb_retrieveall.Enabled = FALSE
//cb_func.Enabled = FALSE
//
//String ls_plancode
//
//
//SetPointer(HourGlass!)
//dw_pageretr.Retrieve(cur_scid,cur_sptid,cur_ifth,cur_storageid,ls_plancode)
//IF dw_pageretr.RowCount() > 0 AND dw_pageretr.GetRow() = 0 THEN dw_pageretr.SetRow(1)
//SetPointer(Arrow!)
//
//cb_nextpage.Enabled = cb_nextpage_enabled
//cb_retrieveall.Enabled = cb_retrieveall_enabled
//cb_func.Enabled = cb_func_enabled
//
//
end event

type cb_func from w_pageretr_ch`cb_func within w_fx_check_bill_saletaskmx_choose1
end type

type cb_exit from w_pageretr_ch`cb_exit within w_fx_check_bill_saletaskmx_choose1
end type

type sle_usual_query from w_pageretr_ch`sle_usual_query within w_fx_check_bill_saletaskmx_choose1
boolean visible = false
integer x = 347
end type

type cb_retrieveall from w_pageretr_ch`cb_retrieveall within w_fx_check_bill_saletaskmx_choose1
boolean visible = false
end type

type em_pagerowno from w_pageretr_ch`em_pagerowno within w_fx_check_bill_saletaskmx_choose1
boolean visible = false
end type

type dw_pageretr from w_pageretr_ch`dw_pageretr within w_fx_check_bill_saletaskmx_choose1
integer width = 4302
integer height = 1300
string dataobject = "dw_fx_check_bill_saletaskmx_choose"
boolean rbutton_filter_use = true
boolean titleclick_sort_use = true
end type

event dw_pageretr::clicked;if row>0 then
	this.setrow(row)	
	if if_mlselect=1 then
		if if_changeselect then
			this.selectrow(row,not this.IsSelected(row))
		else
			if_changeselect=true
		end if
	else
		this.selectrow(0,false)
		this.selectrow(row,true)
	end if
end if
end event

event dw_pageretr::rowfocuschanged;if if_mlselect=1 then
	if currentrow <=0 then return
	if keydown(keycontrol!) then 
		if this.isselected(currentrow) then
			this.selectrow(currentrow,false)
			if_changeselect=false
		else
			if_changeselect=true
		end if
	else
		if not this.isselected(currentrow) then
			this.selectrow(currentrow,true)
			if_changeselect=false
		else
			if_changeselect=true
		end if
	end if
else
	if dw_edit_mode then return
	if currentrow <=0 then return
	this.selectrow(0,false)
	this.selectrow(currentrow,true)
end if

end event

event dw_pageretr::dwnkey;call super::dwnkey;if keydown(keyenter!) then return 1
end event

event dw_pageretr::doubleclicked;IF NOT cbx_ml.Checked THEN
	cb_choice.TriggerEvent(Clicked!)
ELSE
	cb_ok.TriggerEvent(Clicked!)
END IF

end event

type st_1 from w_pageretr_ch`st_1 within w_fx_check_bill_saletaskmx_choose1
boolean visible = false
integer width = 315
string text = "物料编码含:"
end type

type cb_nextpage from w_pageretr_ch`cb_nextpage within w_fx_check_bill_saletaskmx_choose1
boolean visible = false
integer width = 64
string normalpicname = ""
end type

type cb_choice from w_pageretr_ch`cb_choice within w_fx_check_bill_saletaskmx_choose1
end type

event cb_choice::clicked;call super::clicked;Long ROW,ls_i = 0,chC = 0
Int li_buydec_w2u

datastore ds
ds = Create datastore
ds.DataObject = 'dw_fx_check_bill_saletaskmx_choose'

ds.Reset()
dw_pageretr.AcceptText()
dw_choice.AcceptText()

IF Not cbx_ml.Checked THEN
	ROW = dw_pageretr.GetRow()
	IF ROW <= 0 THEN
		MessageBox('系统提示','请先选择目标行!',StopSign!)
		RETURN
	END IF
	FOR ls_i = 1 To dw_pageretr.RowCount()
		IF dw_pageretr.IsSelected(ls_i) THEN
			
			chC++
			dw_pageretr.RowsCopy(ls_i, ls_i, Primary!, ds, chC, Primary!)
			
			
		END IF
	NEXT
	IF chC = 0 THEN
		MessageBox('系统提示','请至少选择一个目标行!',StopSign!)
		RETURN
	END IF
ELSE
	dw_choice.AcceptText()
	ROW = dw_choice.RowCount()
	IF ROW <= 0 THEN
		MessageBox('系统提示','请先选择目标行!',StopSign!)
		RETURN
	END IF
	
	FOR ls_i = 1 To dw_choice.RowCount()
		
		
		chC++
		dw_choice.RowsCopy(ls_i, ls_i, Primary!, ds, chC, Primary!)
		
	NEXT
END IF


CloseWithReturn(PARENT, ds)





//
//
//
//


end event

type cb_refresh from w_pageretr_ch`cb_refresh within w_fx_check_bill_saletaskmx_choose1
end type

event cb_refresh::clicked;wf_retrieve_mx()
end event

type ln_bar from w_pageretr_ch`ln_bar within w_fx_check_bill_saletaskmx_choose1
end type

type ln_bar2 from w_pageretr_ch`ln_bar2 within w_fx_check_bill_saletaskmx_choose1
end type

type r_bar from w_pageretr_ch`r_bar within w_fx_check_bill_saletaskmx_choose1
end type

type ln_1 from w_pageretr_ch`ln_1 within w_fx_check_bill_saletaskmx_choose1
end type

type ln_2 from w_pageretr_ch`ln_2 within w_fx_check_bill_saletaskmx_choose1
end type

type cbx_mlselect from checkbox within w_fx_check_bill_saletaskmx_choose1
integer x = 23
integer y = 200
integer width = 229
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long backcolor = 134217739
string text = "多选"
end type

event clicked;IF THIS.Checked THEN
	if_mlselect = 1
	cbx_all.Enabled = TRUE
ELSE
	if_mlselect = 0
	cbx_all.Enabled = FALSE
	cbx_all.Checked = FALSE
	
	Long li
	FOR li = 1 TO dw_pageretr.RowCount()
		dw_pageretr.SelectRow(li,FALSE)
	NEXT
	
END IF
f_SetProfileString (sys_empid,dw_pageretr.DATAOBJECT, "if_mlselect", string(if_mlselect))

end event

event constructor;if_mlselect=integer(f_ProfileString (sys_empid,dw_pageretr.DATAOBJECT, "if_mlselect", '0'))
if if_mlselect	=0 then
	this.checked=false
	cbx_all.enabled = false
else
	this.checked=true
	cbx_all.enabled = true
end if
end event

type cbx_all from checkbox within w_fx_check_bill_saletaskmx_choose1
integer x = 233
integer y = 200
integer width = 210
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 134217739
boolean enabled = false
string text = "全选"
end type

event clicked;IF dw_pageretr.RowCount() <= 0 THEN RETURN
Long li
IF THIS.Checked THEN
	FOR li = 1 TO dw_pageretr.RowCount()
		dw_pageretr.SelectRow(li,TRUE)
	NEXT
ELSE
	FOR li = 1 TO dw_pageretr.RowCount()
		dw_pageretr.SelectRow(li,FALSE)
	NEXT
END IF

end event

type dw_choice from datawindow within w_fx_check_bill_saletaskmx_choose1
integer y = 1692
integer width = 4302
integer height = 576
integer taborder = 50
boolean bringtotop = true
string title = "none"
string dataobject = "dw_fx_check_bill_saletaskmx_choose"
boolean hscrollbar = true
boolean vscrollbar = true
boolean hsplitscroll = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event rowfocuschanged;IF currentrow <=0 THEN RETURN
this.selectrow(0,false)
this.selectrow(currentrow,true)
end event

event doubleclicked;cb_del.TriggerEvent(Clicked!)
end event

type cb_ok from uo_imflatbutton within w_fx_check_bill_saletaskmx_choose1
integer y = 1588
integer width = 411
integer height = 96
integer taborder = 80
boolean bringtotop = true
string text = "↓选择[Enter]"
end type

event clicked;call super::clicked;Long ROW,ls_i,chC = 0
ROW = dw_pageretr.GetRow()
IF ROW <= 0 THEN
	MessageBox('系统提示','请先选择目标行!',StopSign!)
	RETURN
END IF
dw_choice.SetRedraw(FALSE)
FOR ls_i = 1 TO dw_pageretr.RowCount()
	IF dw_pageretr.IsSelected(ls_i) THEN
		IF dw_choice.Find('fx_saletaskmx_reltaskid ='+String(dw_pageretr.Object.fx_saletaskmx_reltaskid[ls_i])+' and fx_saletaskmx_relprintid = '+String(dw_pageretr.Object.fx_saletaskmx_relprintid[ls_i]),1,dw_choice.RowCount()) = 0 THEN
			chC++
			dw_pageretr.RowsCopy(ls_i, ls_i, Primary!, dw_choice, dw_choice.RowCount() + 1, Primary!)
		END IF
	END IF
NEXT
dw_choice.SetRedraw(TRUE) 







end event

type cb_del from uo_imflatbutton within w_fx_check_bill_saletaskmx_choose1
integer x = 416
integer y = 1588
integer width = 334
integer height = 96
integer taborder = 90
boolean bringtotop = true
string text = "↑删除"
end type

event clicked;call super::clicked;IF dw_choice.GETROW()=0 THEN 
	MESSAGEBOX('NO','请选择删除的行对象!')
	RETURN
END IF
dw_choice.DeleteRow (0)
dw_choice.TriggerEvent (rowfocuschanged!)
end event

type cbx_ml from checkbox within w_fx_check_bill_saletaskmx_choose1
integer x = 471
integer y = 200
integer width = 352
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 700
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 16711680
long backcolor = 134217739
string text = "缓冲选择"
end type

event clicked;wf_face_change()
Int use_ml
IF THIS.Checked THEN
	use_ml = 0
ELSE
	use_ml = 1
END IF

f_SetProfileString (sys_empid,dw_pageretr.DataObject, "use_ml", String(use_ml))

end event

event constructor;Int use_ml
use_ml = Integer(f_ProfileString (sys_empid,dw_pageretr.DataObject, "use_ml", '0'))
IF use_ml = 0 THEN
	THIS.Checked = TRUE
ELSE
	THIS.Checked = FALSE
END IF


end event

