$PBExportHeader$w_fx_saletaskmx_sel.srw
forward
global type w_fx_saletaskmx_sel from w_publ_base_style
end type
type cb_refresh from uo_imflatbutton within w_fx_saletaskmx_sel
end type
type cb_select from uo_imflatbutton within w_fx_saletaskmx_sel
end type
type st_1 from statictext within w_fx_saletaskmx_sel
end type
type dw_fx_saletaskmx from u_dw_rbtnfilter within w_fx_saletaskmx_sel
end type
type cbx_all from checkbox within w_fx_saletaskmx_sel
end type
end forward

global type w_fx_saletaskmx_sel from w_publ_base_style
integer x = 2002
integer y = 500
integer width = 3511
integer height = 2428
string title = "订单明细选择"
boolean minbox = false
windowtype windowtype = response!
string icon = "AppIcon!"
boolean if_ue_retr = true
boolean if_ue_filter = true
boolean if_ue_sort = true
boolean if_ue_sentdataout = true
cb_refresh cb_refresh
cb_select cb_select
st_1 st_1
dw_fx_saletaskmx dw_fx_saletaskmx
cbx_all cbx_all
end type
global w_fx_saletaskmx_sel w_fx_saletaskmx_sel

type variables
Long ins_cuscomid
end variables

forward prototypes
public subroutine wf_retrieve_mx ()
end prototypes

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)

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

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

dw_fx_saletaskmx.Reset()
dw_fx_saletaskmx.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_fx_saletaskmx.InsertRow(0)
	
    dw_fx_saletaskmx.Object.taskid[row] = item.GetInt('taskid')
    dw_fx_saletaskmx.Object.printid[row] = item.GetInt('printid')
    dw_fx_saletaskmx.Object.mxcode[row] = item.GetString('mxcode')
    dw_fx_saletaskmx.Object.fxmtrlid[row] = item.GetInt('fxmtrlid')
    dw_fx_saletaskmx.Object.mtrlid[row] = item.GetInt('mtrlid')
    dw_fx_saletaskmx.Object.mtrlcode[row] = item.GetString('mtrlcode')
    dw_fx_saletaskmx.Object.mtrlname[row] = item.GetString('mtrlname')
    dw_fx_saletaskmx.Object.mtrlmode[row] = item.GetString('mtrlmode')
    dw_fx_saletaskmx.Object.status[row] = item.GetString('status')
    dw_fx_saletaskmx.Object.woodcode[row] = item.GetString('woodcode')
    dw_fx_saletaskmx.Object.pcode[row] = item.GetString('pcode')
    dw_fx_saletaskmx.Object.qty[row] = item.GetDouble('qty')
    dw_fx_saletaskmx.Object.qty_wait[row] = item.GetDouble('qtyWait')
    dw_fx_saletaskmx.Object.cus_receiveqty[row] = item.GetDouble('cus_receiveqty')
    dw_fx_saletaskmx.Object.price[row] = item.GetDouble('price')
    dw_fx_saletaskmx.Object.mxdscrp[row] = item.GetString('mxdscrp')
    dw_fx_saletaskmx.Object.mxdscrp2[row] = item.GetString('mxdscrp2')
    dw_fx_saletaskmx.Object.mtrlcuscode[row] = item.GetString('mtrlcuscode')
    dw_fx_saletaskmx.Object.plancode[row] = item.GetString('plancode')
    dw_fx_saletaskmx.Object.cus_mtrldef_senddays[row] = item.GetDouble('cus_mtrldef_senddays')
    dw_fx_saletaskmx.SetItem(i, 'earliestsenddate', item.GetDateTime('earliestSendDate'))
	dw_fx_saletaskmx.Object.saletask_mxid[row] = item.GetInt('saletask_mxid')
    requiredate = item.GetDateTime('requiredate')
    if (not IsNull(requiredate)) then
        dw_fx_saletaskmx.Object.requiredate[row] = requiredate
    end if
    dw_fx_saletaskmx.Object.qty_ready[row] = item.GetDouble('qty_ready')
    
    dw_fx_saletaskmx.Object.outqty[row] = item.GetDouble('qty') - item.GetDouble('cus_receiveqty') - item.GetDouble('qtyWait') - item.GetDouble('stopQty')
	
    dw_fx_saletaskmx.Object.tid[row] = item.GetString('tid')
    dw_fx_saletaskmx.Object.taskcode[row] = item.GetString('taskcode')
	dw_fx_saletaskmx.Object.unit[row] = item.GetString("unit")
	dw_fx_saletaskmx.Object.advanceday[row] = item.GetInt("advanceday")
	dw_fx_saletaskmx.Object.date_confirm_flag[row] = item.GetInt("date_confirm_flag")
	dw_fx_saletaskmx.Object.billtype[row] = item.GetInt('billtype')
	dw_fx_saletaskmx.Object.storagename[row] = item.GetString('storagename')
	dw_fx_saletaskmx.Object.relcodestr[row] = item.GetString('relcodestr')
	dw_fx_saletaskmx.Object.taskcodestr[row] = item.GetString('taskcodestr')
	dw_fx_saletaskmx.Object.sys_option_taskplancode[row] = item.GetInt('sys_option_taskplancode')
	dw_fx_saletaskmx.Object.ifplancode_ware[row] = item.GetInt('ifplancode_ware')
	dw_fx_saletaskmx.Object.storage_plancode_rule_buy[row] = item.GetInt('storage_plancode_rule_buy')
	dw_fx_saletaskmx.Object.mtrldef_plancode_rule_buy[row] = item.GetInt('mtrldef_plancode_rule_buy')
//	dw_fx_saletaskmx.Modify("DataWindow.Color = 23")
next

dw_fx_saletaskmx.SetRedraw(true)
end subroutine

on w_fx_saletaskmx_sel.create
int iCurrent
call super::create
this.cb_refresh=create cb_refresh
this.cb_select=create cb_select
this.st_1=create st_1
this.dw_fx_saletaskmx=create dw_fx_saletaskmx
this.cbx_all=create cbx_all
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_refresh
this.Control[iCurrent+2]=this.cb_select
this.Control[iCurrent+3]=this.st_1
this.Control[iCurrent+4]=this.dw_fx_saletaskmx
this.Control[iCurrent+5]=this.cbx_all
end on

on w_fx_saletaskmx_sel.destroy
call super::destroy
destroy(this.cb_refresh)
destroy(this.cb_select)
destroy(this.st_1)
destroy(this.dw_fx_saletaskmx)
destroy(this.cbx_all)
end on

event resize;call super::resize;r_bar.height = this.height
dw_fx_saletaskmx.width = this.workspacewidth()
dw_fx_saletaskmx.height = this.workspaceheight() - dw_fx_saletaskmx.y
end event

event open;call super::open;ins_cuscomid = Message.DoubleParm
wf_movetocenter()

wf_retrieve_mx()
end event

type cb_func from w_publ_base_style`cb_func within w_fx_saletaskmx_sel
boolean visible = false
end type

type cb_exit from w_publ_base_style`cb_exit within w_fx_saletaskmx_sel
integer x = 343
end type

type ln_bar from w_publ_base_style`ln_bar within w_fx_saletaskmx_sel
end type

type ln_bar2 from w_publ_base_style`ln_bar2 within w_fx_saletaskmx_sel
end type

type r_bar from w_publ_base_style`r_bar within w_fx_saletaskmx_sel
end type

type cb_refresh from uo_imflatbutton within w_fx_saletaskmx_sel
integer width = 151
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "刷新"
string normalpicname = "refresh.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;wf_retrieve_mx()
end event

type cb_select from uo_imflatbutton within w_fx_saletaskmx_sel
integer x = 165
integer width = 165
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "选定"
string normalpicname = "ok.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;datastore ds
ds = create datastore
ds.DataObject = 'dw_fx_saletaskmx_sel'

//返回选择数据
long i,row
string ls_findstr

ds.Reset()
dw_fx_saletaskmx.AcceptText()

for i = 1 to dw_fx_saletaskmx.RowCount()
	row = 0
	if dw_fx_saletaskmx.Object.ch[i] = 1 then
		
//		ls_findstr = " requiredate < DateTime('" + string (dw_fx_saletaskmx.Object.requiredate[i]) + "') AND ch = 0 AND mtrlcode = '" + string(dw_fx_saletaskmx.Object.mtrlcode[i]) + "'"
//		IF dw_fx_saletaskmx.Find(ls_findstr,1,dw_fx_saletaskmx.RowCount()) > 0 THEN 
//			MessageBox('提示', '物料:【'+ string(dw_fx_saletaskmx.Object.mtrlname[i]) +'】存在更早的要求交期批次, 请按先后顺序选择发货!')
//			return
//		END IF
		
		row++
		dw_fx_saletaskmx.RowsCopy(i, i, Primary!, ds, row, Primary!)
	end if
next


CloseWithReturn(PARENT, ds)
end event

type st_1 from statictext within w_fx_saletaskmx_sel
integer x = 818
integer y = 48
integer width = 1440
integer height = 68
boolean bringtotop = true
integer textsize = -9
integer weight = 700
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 16711680
long backcolor = 67108864
string text = "提示：红色表示最早交货日期大于当前日期或交期未定"
boolean focusrectangle = false
end type

type dw_fx_saletaskmx from u_dw_rbtnfilter within w_fx_saletaskmx_sel
integer y = 188
integer width = 3515
integer height = 2140
integer taborder = 20
boolean bringtotop = true
string dataobject = "dw_fx_saletaskmx_sel"
boolean hscrollbar = true
boolean vscrollbar = true
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
end type

event clicked;call super::clicked;if (row > 0) then
	this.SelectRow(0, false)
	this.SelectRow(row, true)
end if
end event

type cbx_all from checkbox within w_fx_saletaskmx_sel
integer x = 517
integer y = 48
integer width = 251
integer height = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long backcolor = 67108864
string text = "全选"
end type

event clicked;long ll_i, ll_checked
IF cbx_all.Checked THEN
	ll_checked = 1
ELSE
	ll_checked = 0
END IF

FOR ll_i = 1 TO dw_fx_saletaskmx.RowCount()
	IF dw_fx_saletaskmx.Object.earliestsenddate[ll_i] > DateTime(today(), now()) OR dw_fx_saletaskmx.Object.date_confirm_flag[ll_i] = 0 THEN CONTINUE
	dw_fx_saletaskmx.Object.ch[ll_i] = ll_checked
NEXT
	
end event

