$PBExportHeader$w_fx_finish.srw
forward
global type w_fx_finish from w_publ_base_style
end type
type cb_refresh from uo_imflatbutton within w_fx_finish
end type
type cb_new from uo_imflatbutton within w_fx_finish
end type
type cb_delete from uo_imflatbutton within w_fx_finish
end type
type cb_audit from uo_imflatbutton within w_fx_finish
end type
type cb_cancle_audit from uo_imflatbutton within w_fx_finish
end type
type cb_print from uo_imflatbutton within w_fx_finish
end type
type ddlb_status from dropdownlistbox within w_fx_finish
end type
type st_2 from statictext within w_fx_finish
end type
type em_datea from editmask within w_fx_finish
end type
type em_datez from editmask within w_fx_finish
end type
type st_3 from statictext within w_fx_finish
end type
type dw_fx_finish_free from datawindow within w_fx_finish
end type
type cb_add_mx from commandbutton within w_fx_finish
end type
type cb_delete_mx from commandbutton within w_fx_finish
end type
type cb_modify from uo_imflatbutton within w_fx_finish
end type
type dw_fx_finish from u_dw_rbtnfilter within w_fx_finish
end type
type dw_fx_finish_mx from u_dw_rbtnfilter within w_fx_finish
end type
end forward

global type w_fx_finish from w_publ_base_style
integer width = 4608
integer height = 2880
string title = "外协完工单"
boolean maxbox = true
event ue_print_finishmx ( )
cb_refresh cb_refresh
cb_new cb_new
cb_delete cb_delete
cb_audit cb_audit
cb_cancle_audit cb_cancle_audit
cb_print cb_print
ddlb_status ddlb_status
st_2 st_2
em_datea em_datea
em_datez em_datez
st_3 st_3
dw_fx_finish_free dw_fx_finish_free
cb_add_mx cb_add_mx
cb_delete_mx cb_delete_mx
cb_modify cb_modify
dw_fx_finish dw_fx_finish
dw_fx_finish_mx dw_fx_finish_mx
end type
global w_fx_finish w_fx_finish

type variables

end variables

forward prototypes
public subroutine wf_btn_enabled ()
public function integer wf_change_taborder (integer arg_taborder)
public function integer wf_cus_select ()
public subroutine wf_retrieve_finish ()
public subroutine wf_retrieve_finish_mx (long arg_finishid)
public function integer wf_send_finish (ref string arg_msg)
end prototypes

event ue_print_finishmx();long ll_row

ll_row = dw_fx_finish.GetRow()

if ll_row <= 0 then
	MessageBox('提示', '请先选择要打印的单据')
	return
end if

string ls_finishcode, ls_cusname, ls_sptname

ls_finishcode = dw_fx_finish.Object.fxfinishcode[ll_row]
ls_cusname = dw_fx_finish.Object.cusname[ll_row]
ls_sptname = dw_fx_finish.Object.sptname[ll_row]

datastore ds_report
ds_report = create datastore
ds_report.dataobject = 'dw_print_fx_finish_data'

long mx_row, i

for i = 1 to dw_fx_finish_mx.rowcount()

	mx_row = ds_report.InsertRow(0)
	
	ds_report.Object.cusname[mx_row] = ls_cusname //客户名称
	ds_report.Object.sptname[mx_row] = trim(ls_sptname) //供应商名称
	ds_report.Object.fxfinishcode[mx_row] = ls_finishcode
	ds_report.Object.fx_finish_mx_printid[mx_row] = dw_fx_finish_mx.Object.fx_finish_mx_printid[i]
	ds_report.Object.fx_sc_task_erptaskcode[mx_row] = dw_fx_finish_mx.Object.fx_sc_task_erptaskcode[i]
	ds_report.Object.fx_sc_task_procode[mx_row] = dw_fx_finish_mx.Object.fx_sc_task_procode[i]
	ds_report.Object.fx_sc_task_proname[mx_row] = dw_fx_finish_mx.Object.fx_sc_task_proname[i]
	ds_report.Object.fx_finish_mx_qty[mx_row] = dw_fx_finish_mx.Object.fx_finish_mx_qty[i]	
	ds_report.Object.fx_finish_mx_mxdscrp[mx_row] = dw_fx_finish_mx.Object.fx_finish_mx_mxdscrp[i]
	ds_report.Object.recqty[mx_row] = ''

next

S_print_MSG LS_PRMSG

LS_PRMSG.obj_dwNAME='dw_print_fx_finish'
LS_PRMSG.SHARE_DW=ds_report
LS_PRMSG.TAG_TEXT='外协完工单'
LS_PRMSG.SETUP_FLAG=0
LS_PRMSG.PAGECH_FLAG=1

Openwithparm(w_publ_preview,LS_PRMSG)





end event

public subroutine wf_btn_enabled ();if dw_edit_mode OR if_modify_mode then
	cb_refresh.enabled = false
	cb_new.text = '保存'
	cb_new.normalpicname = "save.bmp"
	cb_modify.text = '放弃'
	cb_modify.normalpicname = "undo.bmp"
	cb_delete.enabled = false
	cb_audit.enabled = false
	cb_cancle_audit.enabled = false
	cb_print.enabled = false
	cb_add_mx.enabled = true
	cb_delete_mx.enabled = true
else
	cb_refresh.enabled = true
	cb_new.text = '新建'
	cb_new.normalpicname = "new.bmp"
	cb_modify.text = '修改'
	cb_modify.normalpicname = "open.bmp"
	cb_delete.enabled = true
	cb_audit.enabled = true
	cb_cancle_audit.enabled = true
	cb_print.enabled = true
	cb_add_mx.enabled = false
	cb_delete_mx.enabled = false
end if

cb_new.of_init_draw()
cb_new.of_paint()
cb_new.TriggerEvent('ue_textchange')
cb_modify.of_init_draw()
cb_modify.of_paint()
cb_modify.TriggerEvent('ue_textchange')
end subroutine

public function integer wf_change_taborder (integer arg_taborder);IF arg_taborder = 0 THEN
    dw_fx_finish_mx.SetTaborder('fx_finish_mx_qty', 0)
    dw_fx_finish_mx.SetTaborder('fx_finish_mx_mxdscrp', 0)
ELSE
    dw_fx_finish_mx.SetTaborder('fx_finish_mx_qty', 20)
    dw_fx_finish_mx.SetTaborder('fx_finish_mx_mxdscrp', 30)
END IF

return 1
end function

public function integer wf_cus_select ();IF NOT dw_edit_mode THEN RETURN 0
long ori_cuscomid, new_cuscomid, row
row = dw_fx_finish_free.GetRow()
ori_cuscomid = dw_fx_finish_free.Object.cuscomid[row]
IF ori_cuscomid > 0 THEN
      IF dw_fx_finish_mx.RowCount() > 0 THEN
            MessageBox('','修改客户前需要先清除派工明细')
            RETURN 0
      END IF
END IF

s_fx_company s_tran, s_ret
OpenWithParm(w_cus_ch_fx, s_tran)
s_ret = Message.PowerObjectParm
IF not IsNull(s_ret) then
    IF (s_ret.ifselect) then
        new_cuscomid = s_ret.comid[1]
        IF (ori_cuscomid <> new_cuscomid) then
            dw_fx_finish_mx.Reset() // 重选客户，清空明细
        END IF
        
        dw_fx_finish_free.Object.cuscomid[row] = new_cuscomid
        dw_fx_finish_free.Object.cusname[row] = s_ret.comname[1]
        
        dw_fx_finish_free.AcceptText()
        RETURN 1
    END IF
END IF
RETURN 0
end function

public subroutine wf_retrieve_finish ();long status
string ls_status

ls_status = Trim(ddlb_status.Text)

IF ls_status = '待接收' THEN
	status = 0
ELSEIF ls_status = '在进行' THEN
	status = 1
ELSEIF ls_status = '已完成' THEN
	status = 2
ELSE
	status = -1
END IF

datetime dateA, dateZ
dateA = DateTime(Date(em_dateA.Text), Time(0))
dateZ = DateTime(Date(em_dateZ.Text), Time('23:59:59'))

string arg_msg
oleobject request,response,FxFinishes,item

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('status', status)
request.SetDateTime('begindate', dateA)
request.SetDateTime('enddate', dateZ)

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

if (arg_msg <> '') then
    messagebox('提示', '获取发货单列表失败，原因：' + arg_msg)
    return
end if

dw_fx_finish.Reset()
dw_fx_finish_mx.Reset()
dw_fx_finish.SetRedraw(false)

FxFinishes = response.GetArrOfPBDictionary('FxFinishes')
long i,row
for i = 1 to FxFinishes.Count
    item = FxFinishes.GetItem(i - 1)
    
    row = dw_fx_finish.InsertRow(0)
	 
    dw_fx_finish.SetItem(row, 'fxfinishid', item.GetInt('fxfinishid'))
	dw_fx_finish.SetItem(row, 'fxfinishcode', item.GetString('fxfinishcode'))
	dw_fx_finish.SetItem(row, 'cuscomid', item.GetInt('cuscomid'))
	dw_fx_finish.SetItem(row, 'sptcomid', item.GetInt('sptcomid'))
	dw_fx_finish.SetItem(row, 'status', item.GetInt('status'))
	dw_fx_finish.SetItem(row, 'statusstr', item.GetString('statusstr'))
	dw_fx_finish.SetItem(row, 'opemp', item.GetString('opemp'))
	dw_fx_finish.SetItem(row, 'opdate', item.GetDatetime('opdate'))
	dw_fx_finish.SetItem(row, 'modemp', item.GetString('modemp'))
	dw_fx_finish.SetItem(row, 'moddate', item.GetDatetime('moddate'))
	dw_fx_finish.SetItem(row, 'cusname', item.GetString('cusname'))
	dw_fx_finish.SetItem(row, 'auditemp', item.GetString('auditemp'))
	dw_fx_finish.SetItem(row, 'auditdate', item.GetDatetime('auditdate'))
	dw_fx_finish.SetItem(row, 'accomplishemp', item.GetString('accomplishemp'))
	dw_fx_finish.SetItem(row, 'accomplishdate', item.GetDatetime('accomplishdate'))
	dw_fx_finish.SetItem(row, 'sptname', item.GetString('sptname'))
	
next

dw_fx_finish.SetRedraw(true)

if (dw_fx_finish.RowCount() > 0) then
	dw_fx_finish.SelectRow(0, false)
	dw_fx_finish.SelectRow(1, true)
	dw_fx_finish.SetRow(1)
	dw_fx_finish.post event RowFocusChanged(1)
ELSE
	dw_fx_finish_free.Reset()
	dw_fx_finish_free.InsertRow(0)
end if
end subroutine

public subroutine wf_retrieve_finish_mx (long arg_finishid);if isnull(arg_finishid) or arg_finishid <= 0 then
    return 
end if

string arg_msg
oleobject request, response
oleobject list, item

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('fxfinishid', arg_finishid)

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

if (arg_msg <> '') then
    MessageBox('提示', '获取完工明细失败:' + arg_msg)
    return
end if

list = response.GetPBArray('FxFinishMxes')

dw_fx_finish_mx.Reset()
dw_fx_finish_mx.SetRedraw(false)
long i,row
for i = 1 to list.Count
    item = list.GetPBDictionary(i - 1)
    
    row = dw_fx_finish_mx.InsertRow(0)

    dw_fx_finish_mx.SetItem(row, 'fxtaskid', item.GetInt('fxtaskid'))
    dw_fx_finish_mx.SetItem(row, 'fx_finish_mx_fxfinishid', item.GetInt('fxfinishid'))
    dw_fx_finish_mx.SetItem(row, 'fx_finish_mx_printid', item.GetInt('printid'))
    dw_fx_finish_mx.SetItem(row, 'iffg', item.GetInt('iffg'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_procode', item.GetString('procode'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_proname', item.GetString('proname'))
    dw_fx_finish_mx.SetItem(row, 'taskqty', item.GetDouble('taskqty'))
    dw_fx_finish_mx.SetItem(row, 'fx_finish_mx_qty', item.GetDouble('qty'))
    dw_fx_finish_mx.SetItem(row, 'fx_finish_mx_comqty', item.GetDouble('comqty'))
    dw_fx_finish_mx.SetItem(row, 'fx_finish_mx_backqty', item.GetDouble('backqty'))
    dw_fx_finish_mx.SetItem(row, 'fx_finish_mx_mxdscrp', item.GetString('mxdscrp'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_mtrlcode', item.GetString('mtrlcode'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_mtrlname', item.GetString('mtrlname'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_mtrlmode', item.GetString('mtrlmode'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_unit', item.GetString('unit'))
    dw_fx_finish_mx.SetItem(row, 'fx_sc_task_erptaskcode', item.GetString('erptaskcode'))

next
dw_fx_finish_mx.SetRedraw(true)
end subroutine

public function integer wf_send_finish (ref string arg_msg);int rslt = 1

if (dw_fx_finish_mx.RowCount() <= 0) then
    rslt = 0
    arg_msg = '没有完工明细'
    goto ext
end if

long ll_getrow, ll_finishid
ll_getrow = dw_fx_finish_free.GetRow()

dw_fx_finish_free.AcceptText()

if if_modify_mode then
    ll_finishid = dw_fx_finish_free.Object.fxfinishid[ll_getrow]
else
    ll_finishid = 0
end if

IF ISNULL(dw_fx_finish_free.Object.cuscomid[ll_getrow]) OR dw_fx_finish_free.Object.cuscomid[ll_getrow] = 0 THEN
    rslt = 0
    arg_msg = '请选择客户！'
    goto ext
END IF

dw_fx_finish_free.AcceptText()
dw_fx_finish_mx.AcceptText()

oleobject item, outware, mxs
outware = FXAppCom.CreatePbDictionary()
outware.SetInt('fxfinishid', ll_finishid)
outware.SetInt('cuscomid', dw_fx_finish_free.Object.cuscomid[ll_getrow])

mxs = FXAppCom.CreArrOfPbDictionary()
long i, cnt = 0
DateTime ld_now
ld_now = DateTime(Today(),Now())
for i = 1 to dw_fx_finish_mx.RowCount()
    if (dw_fx_finish_mx.Object.fx_finish_mx_qty[i] <= 0) then continue
    
    cnt ++
    item = FXAppCom.CreatePbDictionary()
    item.SetInt('fxtaskid', dw_fx_finish_mx.Object.fxtaskid[i])
    item.SetString('erptaskcode', dw_fx_finish_mx.Object.fx_sc_task_erptaskcode[i])
    item.SetDouble('qty', dw_fx_finish_mx.Object.fx_finish_mx_qty[i])
    item.SetString('mxdscrp', dw_fx_finish_mx.Object.fx_finish_mx_mxdscrp[i]) 
    
    mxs.Add(item)
next

if (cnt <= 0) then
    rslt = 0
    arg_msg = '没有发货数大于0的明细'
    goto ext
end if

oleobject request,response

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetObject('FxFinish', outware)
request.SetObject('FxFinishMxes', mxs)

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

if (arg_msg <> '') then
    rslt = 0
    goto ext
end if

ext:
return rslt
end function

on w_fx_finish.create
int iCurrent
call super::create
this.cb_refresh=create cb_refresh
this.cb_new=create cb_new
this.cb_delete=create cb_delete
this.cb_audit=create cb_audit
this.cb_cancle_audit=create cb_cancle_audit
this.cb_print=create cb_print
this.ddlb_status=create ddlb_status
this.st_2=create st_2
this.em_datea=create em_datea
this.em_datez=create em_datez
this.st_3=create st_3
this.dw_fx_finish_free=create dw_fx_finish_free
this.cb_add_mx=create cb_add_mx
this.cb_delete_mx=create cb_delete_mx
this.cb_modify=create cb_modify
this.dw_fx_finish=create dw_fx_finish
this.dw_fx_finish_mx=create dw_fx_finish_mx
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_refresh
this.Control[iCurrent+2]=this.cb_new
this.Control[iCurrent+3]=this.cb_delete
this.Control[iCurrent+4]=this.cb_audit
this.Control[iCurrent+5]=this.cb_cancle_audit
this.Control[iCurrent+6]=this.cb_print
this.Control[iCurrent+7]=this.ddlb_status
this.Control[iCurrent+8]=this.st_2
this.Control[iCurrent+9]=this.em_datea
this.Control[iCurrent+10]=this.em_datez
this.Control[iCurrent+11]=this.st_3
this.Control[iCurrent+12]=this.dw_fx_finish_free
this.Control[iCurrent+13]=this.cb_add_mx
this.Control[iCurrent+14]=this.cb_delete_mx
this.Control[iCurrent+15]=this.cb_modify
this.Control[iCurrent+16]=this.dw_fx_finish
this.Control[iCurrent+17]=this.dw_fx_finish_mx
end on

on w_fx_finish.destroy
call super::destroy
destroy(this.cb_refresh)
destroy(this.cb_new)
destroy(this.cb_delete)
destroy(this.cb_audit)
destroy(this.cb_cancle_audit)
destroy(this.cb_print)
destroy(this.ddlb_status)
destroy(this.st_2)
destroy(this.em_datea)
destroy(this.em_datez)
destroy(this.st_3)
destroy(this.dw_fx_finish_free)
destroy(this.cb_add_mx)
destroy(this.cb_delete_mx)
destroy(this.cb_modify)
destroy(this.dw_fx_finish)
destroy(this.dw_fx_finish_mx)
end on

event resize;call super::resize;int li_free_width,li_free_height

li_free_width = 1426 //dw_fx_outwar_free宽度 
li_free_height = 1048 //dw_fx_finish_free高度

//dw_fx_finish_free
dw_fx_finish_free.width =  li_free_width
dw_fx_finish_free.height =   li_free_height
//dw_fx_finish
dw_fx_finish.x = li_free_width + 30
dw_fx_finish.y = dw_fx_finish_free.y
dw_fx_finish.width = this.workspacewidth() - li_free_width
dw_fx_finish.height = dw_fx_finish_free.height
//cb_add_mx, cb_delete_mx
cb_add_mx.x = 40
cb_add_mx.y = dw_fx_finish_free.y + li_free_height + 20
cb_delete_mx.x = cb_add_mx.width + 30
cb_delete_mx.y = cb_add_mx.y
//dw_fx_finish_mx
dw_fx_finish_mx.y = cb_add_mx.y + cb_add_mx.height + 30
dw_fx_finish_mx.width = this.workspacewidth()
dw_fx_finish_mx.height = this.workspaceheight() - cb_add_mx.y - cb_add_mx.height - 30

end event

event open;call super::open;wf_movetocenter()

dw_fx_finish_free.insertrow(0)

ddlb_status.SelectItem(4)

em_dateA.Text = String(RelativeDate(Today(), - 30))
em_dateZ.Text = String(Today())

wf_retrieve_finish()
end event

type cb_func from w_publ_base_style`cb_func within w_fx_finish
boolean visible = false
integer x = 1618
end type

type cb_exit from w_publ_base_style`cb_exit within w_fx_finish
integer x = 1170
end type

event cb_exit::clicked;if dw_edit_mode or if_modify_mode then
	IF MessageBox('提示','是否放弃新建/修改,并退出?',Question! ,OKCancel! , 1 ) = 2 THEN
		return
	END IF
end if 

close(parent)
end event

type ln_bar from w_publ_base_style`ln_bar within w_fx_finish
end type

type ln_bar2 from w_publ_base_style`ln_bar2 within w_fx_finish
end type

type r_bar from w_publ_base_style`r_bar within w_fx_finish
integer x = 2135
end type

type cb_refresh from uo_imflatbutton within w_fx_finish
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_finish()
end event

type cb_new from uo_imflatbutton within w_fx_finish
integer x = 155
integer width = 165
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "新建"
string normalpicname = "new.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;long rslt = 1
string arg_msg
if dw_edit_mode then // 新建/修改保存
    if wf_send_finish(ref arg_msg) = 0 then
        messagebox('提示', '保存失败,原因:' + arg_msg)
        rslt = 0
        goto ext
    end if
    wf_change_taborder(0)
    
    Messagebox('提示', '保存成功')
    wf_retrieve_finish()
else
    long li_row
    dw_fx_finish.reset()
    li_row = dw_fx_finish.insertrow(0)

    dw_fx_finish_mx.reset()
    dw_fx_finish_free.Reset()
    dw_fx_finish.RowsCopy(li_row, li_row, Primary!, dw_fx_finish_free, 1, Primary!)
    wf_change_taborder(1)

end if

ext:
if rslt = 1 then 
    dw_edit_mode = Not dw_edit_mode
    if_modify_mode = false
    wf_btn_enabled()
end if
end event

type cb_delete from uo_imflatbutton within w_fx_finish
integer x = 494
integer width = 165
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "删除"
string normalpicname = "delete.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;long ll_row, ll_status,ll_finishid
    
ll_row = dw_fx_finish.GetRow()

IF ll_row <= 0 THEN
    messagebox('提示', '请选择当前行,不能删除!')
	RETURN
end if  

ll_status = dw_fx_finish.Object.status[ll_row]
ll_finishid = dw_fx_finish.Object.fxfinishid[ll_row]
if ll_status <> 0 then
    messagebox('提示', '不是待审核单据,不能删除!')
    return
end if

IF MessageBox ("IF","是否确定要删除当前选中的外协完工单吗",Question!,YesNo! ) = 2 THEN RETURN

oleobject request,response

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('dotype', 0) //删除
request.SetInt('fxfinishid', ll_finishid)

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

if (arg_msg <> '') then
    messagebox('提示', '删除失败,' + arg_msg)
else
    messagebox('提示', '删除成功！')
    wf_retrieve_finish()
end if
end event

type cb_audit from uo_imflatbutton within w_fx_finish
integer x = 663
integer width = 165
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "审核"
string normalpicname = "audit.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;long ll_row, ll_status, ll_finishid
    
ll_row = dw_fx_finish.GetRow()

IF ll_row <= 0 THEN
    messagebox('提示', '请选择当前行,不能审核!')
	return
end if  

ll_status = dw_fx_finish.Object.status[ll_row]
ll_finishid = dw_fx_finish.Object.fxfinishid[ll_row]

if ll_status <> 0 then
    messagebox('提示', '不是待审核单据,不能审核!')
    return
end if

IF MessageBox ("IF","是否确定要审核当前选中的外协完工单吗",Question!,YesNo! ) = 2 THEN RETURN

oleobject request,response

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('dotype', 1) //审核
request.SetInt('fxfinishid', ll_finishid)

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

if (arg_msg <> '') then
    messagebox('提示', '审核失败,' + arg_msg)
	 return
else
    messagebox('提示', '审核成功！')
    wf_retrieve_finish()
	return
end if


end event

type cb_cancle_audit from uo_imflatbutton within w_fx_finish
integer x = 832
integer width = 165
integer height = 164
integer taborder = 20
boolean bringtotop = true
string text = "撤审"
string normalpicname = "caudit.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;long ll_row, ll_status, ll_finishid
    
ll_row = dw_fx_finish.GetRow()

IF ll_row <= 0 THEN
    messagebox('提示', '请选择当前行,不能撤审!')
	return
end if  

ll_status = dw_fx_finish.Object.status[ll_row]
ll_finishid = dw_fx_finish.Object.fxfinishid[ll_row]

if ll_status <> 1 then
    messagebox('提示', '不是已审核单据,不能撤审!')
    return
end if

IF MessageBox ("IF","是否确定要撤审当前选中的外协完工单吗",Question!,YesNo! ) = 2 THEN RETURN

oleobject request,response

request = FXAppCom.CreatePbDictionary()
request.SetString('token', app_token_fx)
request.SetInt('dotype', 2) //删除
request.SetInt('fxfinishid', ll_finishid)

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

if (arg_msg <> '') then
    messagebox('提示', '撤审失败,' + arg_msg)
else
    messagebox('提示', '撤审成功！')
    wf_retrieve_finish()
end if
end event

type cb_print from uo_imflatbutton within w_fx_finish
integer x = 1001
integer width = 165
integer height = 164
integer taborder = 20
boolean bringtotop = true
string text = "打印"
string normalpicname = "print.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;if (dw_edit_mode) then return

long ll_row, ll_status
    
ll_row = dw_fx_finish.GetRow()
IF ll_row <= 0 THEN
    messagebox('提示', '请选择当前行,不能打印!')
end if  

ll_status = dw_fx_finish.Object.status[ll_row]


if ll_status = 0 then
    messagebox('提示', '待审核单据,不能打印！')
    return
end if

Parent.TriggerEvent('ue_print_finishmx')

end event

type ddlb_status from dropdownlistbox within w_fx_finish
integer x = 41
integer y = 192
integer width = 306
integer height = 496
integer taborder = 80
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
boolean sorted = false
boolean vscrollbar = true
string item[] = {"待审","在途","已完成","全部"}
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within w_fx_finish
integer x = 366
integer y = 204
integer width = 288
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 = 16777215
string text = "发货日期从"
alignment alignment = center!
boolean focusrectangle = false
end type

type em_datea from editmask within w_fx_finish
integer x = 681
integer y = 192
integer width = 389
integer height = 84
integer taborder = 90
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "0000-00-00"
borderstyle borderstyle = stylelowered!
maskdatatype maskdatatype = datemask!
string mask = "yyyy-mm-dd"
boolean spin = true
end type

type em_datez from editmask within w_fx_finish
integer x = 1175
integer y = 192
integer width = 389
integer height = 84
integer taborder = 100
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "0000-00-00"
borderstyle borderstyle = stylelowered!
maskdatatype maskdatatype = datemask!
string mask = "yyyy-mm-dd"
boolean spin = true
end type

type st_3 from statictext within w_fx_finish
integer x = 1070
integer y = 208
integer width = 96
integer height = 48
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "到"
alignment alignment = center!
boolean focusrectangle = false
end type

type dw_fx_finish_free from datawindow within w_fx_finish
integer x = 37
integer y = 288
integer width = 1426
integer height = 1048
integer taborder = 30
boolean bringtotop = true
string title = "none"
string dataobject = "dw_fx_finish_free"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event doubleclicked;if (not dw_edit_mode) then return

if (row <= 0) then return

if dwo.Type = 'column' and dwo.Name = 'cusname' then
	wf_cus_select()
end if
end event

type cb_add_mx from commandbutton within w_fx_finish
integer x = 32
integer y = 1356
integer width = 306
integer height = 84
integer taborder = 30
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean enabled = false
string text = "增明细"
end type

event clicked;Long currow, cuscomid
currow = dw_fx_finish_free.GetRow()
cuscomid = dw_fx_finish_free.Object.cuscomid[currow]
IF IsNull(cuscomid) OR cuscomid = 0 THEN
    MessageBox('','请先选择发货客户')
    IF wf_cus_select() = 0 THEN RETURN
    cuscomid = dw_fx_finish_free.Object.cuscomid[currow]
END IF
datastore arg_ds
arg_ds = create datastore
arg_ds.DataObject = 'dw_fx_sctask_sel'

OpenWithParm(w_fx_sctask_sel, cuscomid)
arg_ds = Message.PowerObjectParm
IF IsValid(arg_ds) THEN
    dw_fx_finish_mx.SetRedraw(false)
    long row, i
    string ls_findstr
    Datetime ld_now
    ld_now = DateTime(Today(),Now())
    for i = arg_ds.RowCount() TO 1 STEP -1

        //DONE:已选择过滤
        ls_findstr = 'fxtaskid=' + string(arg_ds.Object.fxtaskid[i])
        IF dw_fx_finish_mx.Find(ls_findstr,1,dw_fx_finish_mx.RowCount()) > 0 THEN 
            continue
        END IF
    
        row = dw_fx_finish_mx.InsertRow(0)
        dw_fx_finish_mx.Object.fxtaskid[row] = arg_ds.Object.fxtaskid[i]
        dw_fx_finish_mx.Object.iffg[row] = arg_ds.Object.fx_sc_task_billtype[i]
        dw_fx_finish_mx.Object.fx_sc_task_procode[row] = arg_ds.Object.fx_sc_task_procode[i]
        dw_fx_finish_mx.Object.fx_sc_task_proname[row] = arg_ds.Object.fx_sc_task_proname[i]
        dw_fx_finish_mx.Object.taskqty[row] = arg_ds.Object.fx_sc_task_qty[i]
        dw_fx_finish_mx.Object.fx_finish_mx_qty[row] = arg_ds.Object.unfqty[i]
        dw_fx_finish_mx.Object.fx_sc_task_mtrlcode[row] = arg_ds.Object.fx_sc_task_mtrlcode[i]
        dw_fx_finish_mx.Object.fx_sc_task_mtrlname[row] = arg_ds.Object.fx_sc_task_mtrlname[i]
        dw_fx_finish_mx.Object.fx_sc_task_mtrlmode[row] = arg_ds.Object.fx_sc_task_mtrlmode[i]
        dw_fx_finish_mx.Object.fx_sc_task_unit[row] = arg_ds.Object.fx_sc_task_unit[i]
        dw_fx_finish_mx.Object.fx_sc_task_erptaskcode[row] = arg_ds.Object.fx_sc_task_erptaskcode[i]

    next
    dw_fx_finish_mx.SetRedraw(true)
END IF
end event

type cb_delete_mx from commandbutton within w_fx_finish
integer x = 347
integer y = 1356
integer width = 306
integer height = 84
integer taborder = 40
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean enabled = false
string text = "删明细"
end type

event clicked;if dw_fx_finish_mx.RowCount() <= 0 then
    Messagebox('提示', '请先添加明细！')
    return
end if

long i, index
index = 0
FOR i = dw_fx_finish_mx.RowCount() TO 1 STEP -1
    IF  dw_fx_finish_mx.Object.ch[i] = 1 THEN
    index++
    dw_fx_finish_mx.DeleteRow(0)
    END IF
NEXT
IF index = 0 THEN
    MessageBox('提示', '请先勾选要删除的发货明细!')
END IF
end event

type cb_modify from uo_imflatbutton within w_fx_finish
integer x = 325
integer width = 165
integer height = 164
integer taborder = 20
boolean bringtotop = true
string text = "修改"
string normalpicname = "open.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;if dw_edit_mode then
    if MessageBox('提示','是否放弃新建/修改操作?',Question! ,OKCancel! , 1 ) = 1 then
        wf_change_taborder(0)
        
        dw_edit_mode = false
         if_modify_mode = false   
        wf_btn_enabled()
        wf_retrieve_finish()
    end if
else
    long ll_row, ll_status
    
    ll_row = dw_fx_finish.GetRow()
    IF ll_row <= 0 THEN
        messagebox('提示', '请选择当前行,不能修改!')
    end if  
    
    ll_status = dw_fx_finish.Object.status[ll_row]
    
    if ll_status <> 0 then
        messagebox('提示', '不是待审核单据,不能修改!')
        return
    end if
    
    wf_change_taborder(1)
    dw_edit_mode = true
    if_modify_mode = true
    wf_btn_enabled()
end if


end event

type dw_fx_finish from u_dw_rbtnfilter within w_fx_finish
integer x = 1472
integer y = 272
integer width = 2409
integer height = 1064
integer taborder = 20
boolean bringtotop = true
boolean titlebar = true
string title = "外协完工单"
string dataobject = "dw_fx_finish"
boolean controlmenu = true
boolean maxbox = true
boolean hscrollbar = true
boolean vscrollbar = true
boolean resizable = true
boolean border = false
boolean hsplitscroll = true
borderstyle borderstyle = styleshadowbox!
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
boolean autosave_setlayout_use = false
boolean autosave_columnvisible_use = false
end type

event rowfocuschanged;call super::rowfocuschanged;if dw_edit_mode then return

if IsNull(currentrow) then
	IF THIS.rowcount() > 0 then
		THIS.SelectRow(0,FALSE)
		THIS.SelectRow(1,TRUE)
		THIS.setrow(1)
		currentrow =1
	end if
end if


if IsNull(currentrow) then return
if (currentrow <= 0) then return

this.SelectRow(0, false)
this.SelectRow(currentrow, true)

dw_fx_finish_free.Reset( )
this.RowsCopy(currentrow, currentrow, Primary!, dw_fx_finish_free, 1, Primary!)

long ll_finishid
ll_finishid = this.Object.fxfinishid[currentrow]

wf_retrieve_finish_mx(ll_finishid)
end event

type dw_fx_finish_mx from u_dw_rbtnfilter within w_fx_finish
integer x = 27
integer y = 1452
integer width = 3845
integer height = 948
integer taborder = 20
boolean bringtotop = true
string dataobject = "dw_fx_finishmx"
boolean hscrollbar = true
boolean vscrollbar = true
boolean hsplitscroll = 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

