$PBExportHeader$w_buytask_custom_view_fx.srw
$PBExportComments$定制产品销售订单(查看/编辑)
forward
global type w_buytask_custom_view_fx from w_publ_base
end type
type cb_addmx from commandbutton within w_buytask_custom_view_fx
end type
type cb_delmx from commandbutton within w_buytask_custom_view_fx
end type
type uo_tab from uo_fx_saletask_custom_tab within w_buytask_custom_view_fx
end type
type uo_tab from uo_fx_saletask_custom_tab within w_buytask_custom_view_fx
end type
type dw_main from datawindow within w_buytask_custom_view_fx
end type
type dw_mx from u_dw_rbtnfilter within w_buytask_custom_view_fx
end type
end forward

global type w_buytask_custom_view_fx from w_publ_base
integer width = 3666
integer height = 2800
string title = "定制产品销售订单"
boolean minbox = false
windowtype windowtype = response!
long backcolor = 16777215
boolean center = true
event ue_tab_fj_upload ( )
cb_addmx cb_addmx
cb_delmx cb_delmx
uo_tab uo_tab
dw_main dw_main
dw_mx dw_mx
end type
global w_buytask_custom_view_fx w_buytask_custom_view_fx

type variables
s_fx_saletask ins_tran

long ins_mxPrintid = 0 // 新建订单时，记录订单明细当前最大明细数

long ins_ret = 0 // 关闭时，父窗口 0-无需刷新 1-刷新
end variables

forward prototypes
private subroutine wf_address_ch ()
private subroutine wf_add_mx ()
private subroutine wf_taborder ()
private subroutine wf_face ()
public function integer wf_save (s_fx_saletask a_tran, ref string arg_msg)
private subroutine wf_add_saletask (long a_mode)
public subroutine wf_add_saletaskmx ()
public function integer wf_cancel (string a_reason, ref string arg_msg)
end prototypes

event ue_tab_fj_upload();// uo_tab附件页【上传】按钮事件

long ll_row, ll_printid, ll_dftFjtype
ll_row = dw_mx.GetRow()
if (ll_row <= 0) then
	MessageBox('提示', '请选择订单明细以确定上传附件的对应明细项')
	return
end if

ll_printid = dw_mx.Object.printid[ll_row]

if (ins_tran.status <> 4) then // 非待付款状态
	ll_dftFjtype = 2 // 下单附件
else
	ll_dftFjtype = 0 // 付款凭证
end if
OpenWithParm(w_fjtype_ch_fx, ll_dftFjtype)
ll_dftFjtype = Message.DoubleParm
if (ll_dftFjtype = - 1) then return

oleobject parm, ret, fullNamesArr, namesArr, extsArr, md5sArr
parm = FXAppCom.CreatePbDictionary()
parm.SetString('filter', '')
parm.SetString('ifMulti', 1)
ret = FXAppCom.OpenFiles(parm)
long ll_cnt, ll_insertRow, ll_i
datetime ldt_now = DateTime(Today(), Now())
string ls_md5s_arr[], ls_filepaths_arr[]
ll_cnt = ret.GetInt('cnt')
if (ll_cnt > 0) then
	fullNamesArr = ret.GetPBArray('fullNamesArr')
	namesArr = ret.GetPBArray('namesArr')
	extsArr = ret.GetPBArray('extsArr')
	md5sArr = ret.GetPBArray('md5sArr')
	
	uo_tab.tabpage_fj.dw_fj.SetRedraw(false)
	for ll_i = 1 to ll_cnt
		ll_insertRow = uo_tab.tabpage_fj.dw_fj.InsertRow(0)
		
		uo_tab.tabpage_fj.dw_fj.Object.mxprintid[ll_insertRow] = ll_printid
		uo_tab.tabpage_fj.dw_fj.Object.fjtype[ll_insertRow] = ll_dftFjtype
		uo_tab.tabpage_fj.dw_fj.Object.filename[ll_insertRow] = namesArr.GetString(ll_i - 1)
		uo_tab.tabpage_fj.dw_fj.Object.dscrp[ll_insertRow] = ''
		uo_tab.tabpage_fj.dw_fj.Object.opemp[ll_insertRow] = app_username
		uo_tab.tabpage_fj.dw_fj.Object.opdate[ll_insertRow] = ldt_now
		uo_tab.tabpage_fj.dw_fj.Object.ch[ll_insertRow] = 0
		uo_tab.tabpage_fj.dw_fj.Object.fjprintid[ll_insertRow] = 0
		uo_tab.tabpage_fj.dw_fj.Object.fileType[ll_insertRow] = extsArr.GetString(ll_i - 1)
		uo_tab.tabpage_fj.dw_fj.Object.filemd5[ll_insertRow] = md5sArr.GetString(ll_i - 1)
		uo_tab.tabpage_fj.dw_fj.Object.filepath[ll_insertRow] = fullNamesArr.GetString(ll_i - 1)
		
		ls_md5s_arr[ll_i] = md5sArr.GetString(ll_i - 1)
		ls_filepaths_arr[ll_i] = fullNamesArr.GetString(ll_i - 1)
	next
	uo_tab.tabpage_fj.dw_fj.AcceptText()
	uo_tab.tabpage_fj.dw_fj.SetRedraw(true)
	
	ins_ret = 1
end if




end event

private subroutine wf_address_ch ();// 收货人地址选择

long ll_row
ll_row = dw_main.GetRow()
if (ll_row <= 0) then return

s_fx_address s_tran
Open(w_address_ch_fx)
s_tran = Message.PowerObjectParm
if (not IsNull(s_tran)) then
	if (IsValid(s_tran)) then
		if (s_tran.addressid > 0) then
			dw_main.Object.addressid[ll_row] = s_tran.addressid
			dw_main.Object.cus_rep[ll_row] = s_tran.cus_rep
			dw_main.Object.cus_tele[ll_row] = s_tran.cus_tele
			dw_main.Object.cus_address[ll_row] = s_tran.cus_address
			
			dw_main.AcceptText()
		end if
	end if
end if
end subroutine

private subroutine wf_add_mx ();// 添加明细

if (not if_modify_mode) then return
if (ins_tran.taskid > 0 and dw_mx.RowCount() >= 1) then return

s_fx_mtrldef s_tran
Open(w_mtrl_custom_ch_by_sptcomid_fx)
s_tran = Message.PowerObjectParm
if (IsNull(s_tran)) then return
if (not IsValid(s_tran)) then return
if (not s_tran.ifselect) then return

long ll_i, ll_insertRow
dw_mx.SetRedraw(false)
for ll_i = 1 to UpperBound(s_tran.fxmtrlid)
	ll_insertRow = dw_mx.InsertRow(0)
	
	ins_mxPrintid++
	dw_mx.Object.printid[ll_insertRow] = ins_mxPrintid
	dw_mx.Object.mb_mtrlcode[ll_insertRow] = s_tran.mtrlcode[ll_i]
	dw_mx.Object.mb_mtrlname[ll_insertRow] = s_tran.mtrlname[ll_i]
	dw_mx.Object.mb_mtrlmode[ll_insertRow] = s_tran.mtrlmode[ll_i]
	dw_mx.Object.qty[ll_insertRow] = 1
	dw_mx.Object.requiredate[ll_insertRow] = DateTime(Today(), Now())
	dw_mx.Object.mxdscrp[ll_insertRow] = ''
	dw_mx.Object.mxdscrp2[ll_insertRow] = ''
	dw_mx.Object.fxmtrlid_ori[ll_insertRow] = s_tran.fxmtrlid[ll_i]
	dw_mx.Object.fxmtrlid[ll_insertRow] = s_tran.fxmtrlid[ll_i]
	dw_mx.Object.mtrlid_ori[ll_insertRow] = s_tran.mtrlid[ll_i]
	dw_mx.Object.mtrlid[ll_insertRow] = s_tran.mtrlid[ll_i]
//	dw_mx.Object.status[ll_insertRow] = ''
//	dw_mx.Object.woodcode[ll_insertRow] = ''
//	dw_mx.Object.pcode[ll_insertRow] = ''
next
dw_mx.AcceptText()
dw_mx.SetRedraw(true)
end subroutine

private subroutine wf_taborder ();//

long ll_i, ll_step
if (if_modify_mode) then
	ll_step = 10
else
	ll_step = 0
end if

ll_i = 0

ll_i += ll_step
dw_mx.SetTaborder('qty', ll_i)
ll_i += ll_step
dw_mx.SetTaborder('requiredate', ll_i)
ll_i += ll_step
dw_mx.SetTaborder('mxdscrp', ll_i)
ll_i += ll_step
dw_mx.SetTaborder('mxdscrp2', ll_i)
end subroutine

private subroutine wf_face ();if (if_modify_mode) then
	cb_addmx.Visible = true
	cb_addmx.Enabled = true
	cb_delmx.Visible = true
	cb_delmx.Enabled = true
else
	cb_addmx.Visible = false
	cb_addmx.Enabled = false
	cb_delmx.Visible = false
	cb_delmx.Enabled = false
end if

if (ins_tran.taskid <= 0) then
	cb_func.Text = '新建'
	cb_func.normalpicname = 'new.bmp'
elseif (ins_tran.status = 0) then
	cb_func.Text = '退回'
	cb_func.normalpicname = 'Undo.bmp'
elseif (ins_tran.status = 2) then
	cb_func.Text = '重建'
	cb_func.normalpicname = 'new.bmp'
elseif (ins_tran.status = 4) then // 待付款[4]
	cb_func.Text = '审核'
	cb_func.normalpicname = 'audit.bmp'
elseif (ins_tran.status = 8) then // 已发货[8]
	cb_func.Text = '收货'
	cb_func.normalpicname = 'audit.bmp'
else
	cb_func.Visible = false
	cb_func.Enabled = false
end if

cb_func.of_init_draw()
cb_func.of_paint()
cb_func.TriggerEvent('ue_textchange')

end subroutine

public function integer wf_save (s_fx_saletask a_tran, ref string arg_msg);// 新建/退回订单保存
int rslt = 1
arg_msg = ''

if (IsNull(a_tran.cus_rep)) then a_tran.cus_rep = ''
if (IsNull(a_tran.cus_tele)) then a_tran.cus_tele = ''
if (IsNull(a_tran.cus_address)) then a_tran.cus_address = ''
if (IsNull(a_tran.temp1)) then a_tran.temp1 = ''
if (IsNull(a_tran.temp2)) then a_tran.temp2 = ''
if (IsNull(a_tran.temp3)) then a_tran.temp3 = ''

if (a_tran.cus_rep = '' &
		or a_tran.cus_rep = '' &
		or a_tran.cus_rep = '') then
	rslt = 0
	arg_msg = '收货人/联系电话/收货地址不能为空'
	goto ext
end if

long ll_i
if (IsNull(a_tran.mx)) then
	rslt = 0
	arg_msg = '没有订单明细(null)'
	goto ext
end if
if (UpperBound(a_tran.mx) <= 0) then
	rslt = 0
	arg_msg = '没有订单明细(0)'
	goto ext
end if
for ll_i = 1 to UpperBound(a_tran.mx)
	if (a_tran.mx[ll_i].qty <= 0) then
		rslt = 0
		arg_msg += '明细行:' + string(ll_i) + '数量有误;~r~n'
	end if
next
if (rslt <> 1) then goto ext

// 1-先上传新增附件的md5，与服务器对比，2-返回服务器没有的md5，再上传附件数据
long ll_index = 0
string ls_arr_1_md5[], ls_arr_1_filepath[]
if (not IsNull(a_tran.fj)) then
	for ll_i = 1 to UpperBound(a_tran.fj)
		if (a_tran.fj[ll_i].fjprintid <= 0) then
			ll_index++
			ls_arr_1_md5[ll_index] = a_tran.fj[ll_i].filemd5
			ls_arr_1_filepath[ll_index] = a_tran.fj[ll_i].filepath
		end if
	next
end if
if (UpperBound(ls_arr_1_md5) > 0) then
	if (f_chkfxfilemapwithmd5andupload(ls_arr_1_md5, ls_arr_1_filepath, ref arg_msg) <> 1) then
		rslt = 0
		goto ext
	end if
end if

// 保存订单
oleobject req, rsp
oleobject taskinfo, items, fjs, item
oleobject mtrlitem
// 主表
taskinfo = FXAppCom.CreatePbDictionary()
taskinfo.SetInt('taskid', a_tran.taskid)
taskinfo.SetInt('billtype', a_tran.billtype)
taskinfo.SetString('cus_rep', a_tran.cus_rep)
taskinfo.SetString('cus_tele', a_tran.cus_tele)
taskinfo.SetString('cus_address', a_tran.cus_address)
taskinfo.SetString('temp1', a_tran.temp1)
taskinfo.SetString('temp2', a_tran.temp2)
taskinfo.SetString('temp3', a_tran.temp3)
// 订单明细
items = FXAppCom.NewPBArray()
for ll_i = 1 to UpperBound(a_tran.mx)
	item = FXAppCom.CreatePbDictionary()
	item.SetInt('printid', a_tran.mx[ll_i].printid)
	item.SetDouble('num', a_tran.mx[ll_i].qty)
	item.SetInt('cartitemid', 0)
	item.SetString('status', '')
	item.SetString('woodcode', '')
	item.SetString('pcode', '')
	item.SetString('mxdscrp', a_tran.mx[ll_i].mxdscrp)
	item.SetString('mxdscrp2', a_tran.mx[ll_i].mxdscrp2)
	//mtrlitem
	mtrlitem = FXAppCom.CreatePbDictionary()
	mtrlitem.SetInt('fxmtrlid', a_tran.mx[ll_i].fxmtrlid)
	mtrlitem.SetInt('fxmtrlid_ori', a_tran.mx[ll_i].fxmtrlid_ori)
	mtrlitem.SetInt('mtrlid_ori', a_tran.mx[ll_i].mtrlid_ori)
	mtrlitem.SetInt('mtrlid_erp', a_tran.mx[ll_i].mtrlid)
	mtrlitem.SetDateTime('requiredate', a_tran.mx[ll_i].requiredate)
	
	item.SetObject('mtrlitem', mtrlitem)
	
	items.AddObject(item)
next
// 订单附件
fjs = FXAppCom.NewPBArray()
for ll_i = 1 to UpperBound(a_tran.fj)
	item = FXAppCom.CreatePbDictionary()
	item.SetInt('fjprintid', a_tran.fj[ll_i].fjprintid)
	item.SetInt('mxprintid', a_tran.fj[ll_i].mxprintid)
	item.SetInt('fjType', a_tran.fj[ll_i].fjType)
	item.SetString('dscrp', a_tran.fj[ll_i].dscrp)
	item.SetString('fileName', a_tran.fj[ll_i].fileName)
	item.SetString('fileType', a_tran.fj[ll_i].fileType)
	item.SetString('filemd5', a_tran.fj[ll_i].filemd5)
	//item.SetString('filepath', a_tran.fj[ll_i].filepath)
	
	fjs.AddObject(item)
next
// 提交
req = FXAppCom.CreatePbDictionary()
req.SetString('token', app_token_fx)
req.SetObject('taskinfo', taskinfo)
req.SetObject('items', items)
req.SetObject('fjs', fjs)
rsp = FXAppCom.DoExecute('SaveTask', req)
arg_msg = rsp.GetString('ErrMsg')
if (arg_msg <> '') then
	rslt = 0
	goto ext
end if



ext:
return rslt

end function

private subroutine wf_add_saletask (long a_mode);// 新建/查看退回订单
// a_mode 0-新建 1-查看/退回
dw_main.Reset()

long ll_insertRow
ll_insertRow = dw_main.InsertRow(0)
if (a_mode = 0) then // 新建
	dw_main.Object.status[ll_insertRow] = 0
	dw_main.Object.cus_rep[ll_insertRow] = ''
	dw_main.Object.cus_tele[ll_insertRow] = ''
	dw_main.Object.cus_address[ll_insertRow] = ''
	dw_main.Object.temp1[ll_insertRow] = ''
	dw_main.Object.temp2[ll_insertRow] = ''
	dw_main.Object.temp3[ll_insertRow] = ''
	dw_main.Object.opemp[ll_insertRow] = app_username
	dw_main.Object.opdate[ll_insertRow] = DateTime(Today(), Now())
else // 查看/退回
	dw_main.Object.gpCode[ll_insertRow] = ins_tran.gpCode
	dw_main.Object.tid[ll_insertRow] = ins_tran.tid
	dw_main.Object.status[ll_insertRow] = ins_tran.status
	dw_main.Object.cus_rep[ll_insertRow] = ins_tran.cus_rep
	dw_main.Object.cus_tele[ll_insertRow] = ins_tran.cus_tele
	dw_main.Object.cus_address[ll_insertRow] = ins_tran.cus_address
	dw_main.Object.temp1[ll_insertRow] = ins_tran.temp1
	dw_main.Object.temp2[ll_insertRow] = ins_tran.temp2
	dw_main.Object.temp3[ll_insertRow] = ins_tran.temp3
	dw_main.Object.opemp[ll_insertRow] = ins_tran.opemp
	dw_main.Object.opdate[ll_insertRow] = ins_tran.opdate
	dw_main.Object.modemp[ll_insertRow] = ins_tran.modemp
	dw_main.Object.moddate[ll_insertRow] = ins_tran.moddate
	
	dw_main.Object.erpstatus[ll_insertRow] = ins_tran.erpstatus
	dw_main.Object.freight[ll_insertRow] = ins_tran.freight
	dw_main.Object.freight_tele[ll_insertRow] = ins_tran.freight_tele
	dw_main.Object.replyrqdate[ll_insertRow] = ins_tran.replyrqdate
	dw_main.Object.addCost[ll_insertRow] = ins_tran.addCost
	dw_main.Object.erpConfirmEmp[ll_insertRow] = ins_tran.erpConfirmEmp
	dw_main.Object.erpConfirmDate[ll_insertRow] = ins_tran.erpConfirmDate
	dw_main.Object.splitEmp[ll_insertRow] = ins_tran.splitEmp
	dw_main.Object.splitDate[ll_insertRow] = ins_tran.splitDate
	dw_main.Object.splitConfirmEmp[ll_insertRow] = ins_tran.splitConfirmEmp
	dw_main.Object.splitConfirmDate[ll_insertRow] = ins_tran.splitConfirmDate
	dw_main.Object.price_emp[ll_insertRow] = ins_tran.price_emp
	dw_main.Object.priceDate[ll_insertRow] = ins_tran.priceDate
	dw_main.Object.priceConfirmEmp[ll_insertRow] = ins_tran.priceConfirmEmp
	dw_main.Object.priceConfirmDate[ll_insertRow] = ins_tran.priceConfirmDate
	dw_main.Object.payConfirmEmp[ll_insertRow] = ins_tran.payConfirmEmp
	dw_main.Object.payConfirmDate[ll_insertRow] = ins_tran.payConfirmDate
	
	dw_main.Object.taskid[ll_insertRow] = ins_tran.taskid
	dw_main.Object.sptcomid[ll_insertRow] = ins_tran.sptcomid
	dw_main.Object.cuscomid[ll_insertRow] = ins_tran.cuscomid
	dw_main.Object.buyer_name[ll_insertRow] = ins_tran.buyer_name
	dw_main.Object.buyer_tele[ll_insertRow] = ins_tran.buyer_tele
//	dw_main.Object.temp4[ll_insertRow] = ins_tran.temp4
//	dw_main.Object.temp5[ll_insertRow] = ins_tran.temp5
//	dw_main.Object.temp6[ll_insertRow] = ins_tran.temp6
//	dw_main.Object.replydscrp[ll_insertRow] = ins_tran.replydscrp
//	dw_main.Object.replydate[ll_insertRow] = ins_tran.replydate
//	dw_main.Object.confirmemp[ll_insertRow] = ins_tran.confirmemp
//	dw_main.Object.confirmdate[ll_insertRow] = ins_tran.confirmdate
//	dw_main.Object.outwarecode[ll_insertRow] = ins_tran.outwarecode
//	dw_main.Object.fstatus[ll_insertRow] = ins_tran.fstatus
	dw_main.Object.billtype[ll_insertRow] = ins_tran.billtype
	dw_main.Object.taskdate[ll_insertRow] = ins_tran.taskdate
	dw_main.Object.taskcode[ll_insertRow] = ins_tran.taskcode
	dw_main.Object.requiredate[ll_insertRow] = ins_tran.requiredate
	dw_main.Object.addressid[ll_insertRow] = 0
end if
dw_main.AcceptText()

end subroutine

public subroutine wf_add_saletaskmx ();// 获取订单明细
dw_mx.Reset()

string arg_msg
oleobject req, rsp
req = FXAppCom.CreatePbDictionary()
req.SetString('token', app_token_fx)
req.SetInt('taskid', ins_tran.taskid)
rsp = FXAppCom.DoExecute('GetBuytaskmx', req)
arg_msg = rsp.GetString('ErrMsg')
if (arg_msg <> '') then
	MessageBox('提示', arg_msg)
	return
end if

oleobject item, list
list = rsp.GetPBArray('mxs')
long ll_i, ll_insertRow
for ll_i = 1 to list.Count
	item = list.GetPBDictionary(ll_i - 1)
	ll_insertRow = dw_mx.InsertRow(0)
	
	dw_mx.Object.printid[ll_insertRow] = item.GetInt('printid')
	dw_mx.Object.mb_mtrlcode[ll_insertRow] = item.GetString('mb_mtrlcode')
	dw_mx.Object.mb_mtrlname[ll_insertRow] = item.GetString('mb_mtrlname')
	dw_mx.Object.mb_mtrlmode[ll_insertRow] = item.GetString('mb_mtrlmode')
	dw_mx.Object.qty[ll_insertRow] = item.GetDouble('qty')
	if (not IsNull(item.GetDateTime('requiredate'))) then
		dw_mx.Object.requiredate[ll_insertRow] = item.GetDateTime('requiredate')
	end if
	dw_mx.Object.mxdscrp[ll_insertRow] = item.GetString('mxdscrp')
	dw_mx.Object.mxdscrp2[ll_insertRow] = item.GetString('mxdscrp2')
	dw_mx.Object.price[ll_insertRow] = item.GetDouble('price')
	dw_mx.Object.mtrlcode[ll_insertRow] = item.GetString('mtrlcode')
	dw_mx.Object.mtrlname[ll_insertRow] = item.GetString('mtrlname')
	dw_mx.Object.mtrlmode[ll_insertRow] = item.GetString('mtrlmode')
	dw_mx.Object.plancode[ll_insertRow] = item.GetString('plancode')
	dw_mx.Object.mtrlcuscode[ll_insertRow] = item.GetString('mtrlcuscode')
	dw_mx.Object.cus_receiveqty[ll_insertRow] = item.GetDouble('cus_receiveqty')
	dw_mx.Object.qty_ready[ll_insertRow] = item.GetDouble('qty_ready')
	dw_mx.Object.outQty[ll_insertRow] = item.GetDouble('outQty')
	if (not IsNull(item.GetDateTime('outDate'))) then
		dw_mx.Object.outDate[ll_insertRow] = item.GetDateTime('outDate')
	end if
	dw_mx.Object.stopQty[ll_insertRow] = item.GetDouble('stopQty')
	dw_mx.Object.stopEmp[ll_insertRow] = item.GetString('stopEmp')
	if (not IsNull(item.GetDateTime('stopDate'))) then
		dw_mx.Object.stopDate[ll_insertRow] = item.GetDateTime('stopDate')
	end if
	dw_mx.Object.stopReason[ll_insertRow] = item.GetString('stopReason')
	
	dw_mx.Object.status[ll_insertRow] = item.GetString('status')
	dw_mx.Object.woodcode[ll_insertRow] = item.GetString('woodcode')
	dw_mx.Object.pcode[ll_insertRow] = item.GetString('pcode')
	if (not IsNull(item.GetDateTime('qty_ready_opdate'))) then
		dw_mx.Object.qty_ready_opdate[ll_insertRow] = item.GetDateTime('qty_ready_opdate')
	end if
	dw_mx.Object.taskid[ll_insertRow] = item.GetInt('taskid')
	dw_mx.Object.mxcode[ll_insertRow] = item.GetString('mxcode')
	dw_mx.Object.mtrlid[ll_insertRow] = item.GetInt('mtrlid')
	dw_mx.Object.fxmtrlid[ll_insertRow] = item.GetInt('fxmtrlid')
	dw_mx.Object.qty_ready_userid[ll_insertRow] = item.GetInt('qty_ready_userid')
	dw_mx.Object.fxmtrlid_ori[ll_insertRow] = item.GetInt('fxmtrlid_ori')
	dw_mx.Object.mtrlid_ori[ll_insertRow] = item.GetInt('mtrlid_ori')
next


end subroutine

public function integer wf_cancel (string a_reason, ref string arg_msg);// 取消(退回)订单
int rslt = 1
arg_msg = ''

if (IsNull(a_reason)) then a_reason = ''

if (a_reason = '') then
	rslt = 0
	arg_msg = '订单取消原因不能为空'
	goto ext
end if

oleobject req, rsp
req = FXAppCom.CreatePbDictionary()
req.SetString('token', app_token_fx)
req.SetInt('taskid', ins_tran.taskid)
req.SetString('reason', a_reason)
rsp = FXAppCom.DoExecute('CancelTask', req)
arg_msg = rsp.GetString('ErrMsg')
if (arg_msg <> '') then
	rslt = 0
	goto ext
end if

ext:
return rslt

end function

on w_buytask_custom_view_fx.create
int iCurrent
call super::create
this.cb_addmx=create cb_addmx
this.cb_delmx=create cb_delmx
this.uo_tab=create uo_tab
this.dw_main=create dw_main
this.dw_mx=create dw_mx
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_addmx
this.Control[iCurrent+2]=this.cb_delmx
this.Control[iCurrent+3]=this.uo_tab
this.Control[iCurrent+4]=this.dw_main
this.Control[iCurrent+5]=this.dw_mx
end on

on w_buytask_custom_view_fx.destroy
call super::destroy
destroy(this.cb_addmx)
destroy(this.cb_delmx)
destroy(this.uo_tab)
destroy(this.dw_main)
destroy(this.dw_mx)
end on

event open;call super::open;ins_tran = Message.PowerObjectParm
if (IsNull(ins_tran)) then
	Close(this)
	return
end if
if (not IsValid(ins_tran)) then
	Close(this)
	return
end if

if ((ins_tran.taskid <= 0 and ins_tran.status = 0) or (ins_tran.status = 2)) then // 编辑状态
	if_modify_mode = true
	
	dw_main.DataObject = 'dw_fx_buytask_custom_new'
	if (ins_tran.taskid <= 0) then // 新建
		wf_add_saletask(0)
	else // 退回
		wf_add_saletask(1)
		wf_add_saletaskmx()
	end if
else
	if_modify_mode = false
	
	dw_main.DataObject = 'dw_fx_buytask_custom_view'
	wf_add_saletask(1)
	wf_add_saletaskmx()
end if

uo_tab.post event ue_init_with_tid(ins_tran.taskid, ins_tran.status, ins_tran.tid, this)

wf_face()
wf_taborder()
this.post event resize(0, 0, 0)

end event

event resize;call super::resize;dw_main.Width = this.workspacewidth()
dw_mx.Width = this.workspacewidth()
uo_tab.Width = this.workspacewidth()

if (if_modify_mode) then
	dw_main.Height = 724
	
	dw_mx.Y = cb_addmx.Y + 100
	dw_mx.Height = 600
else
	dw_main.Height = 1088
	
	dw_mx.Y = dw_main.Y + dw_main.Height + 2
	dw_mx.Height = 360
end if

uo_tab.Y = dw_mx.Y + dw_mx.Height + 10
uo_tab.Height = this.workspaceheight() - uo_tab.Y - 160
uo_tab.post event ue_resize()

end event

event close;call super::close;CloseWithReturn(this, ins_ret)
end event

type cb_func from w_publ_base`cb_func within w_buytask_custom_view_fx
integer x = 2999
integer y = 2596
integer taborder = 60
string normalpicname = "new.bmp"
integer picsize = 16
end type

event cb_func::clicked;call super::clicked;s_fx_saletask s_main
s_fx_saletaskmx s_mx, s_empty_mx
s_fx_saletask_fj s_fj, s_empty_fj

s_inputbox s_input
string ls_ret

long ll_row, ll_i
string arg_msg

if ((ins_tran.taskid <= 0 and ins_tran.status = 0) or (ins_tran.status = 2)) then // 新建/重新下单
	dw_main.AcceptText()
	dw_mx.SetFilter('')
	dw_mx.Filter()
	dw_mx.AcceptText()
	uo_tab.tabpage_fj.dw_fj.SetFilter('')
	uo_tab.tabpage_fj.dw_fj.Filter()
	uo_tab.tabpage_fj.dw_fj.AcceptText()
	
	ll_row = dw_main.GetRow()
	if (ll_row <= 0) then
		MessageBox('提示', '获取当前单据信息失败,请联系开发人员')
		return
	end if
	s_main.taskid = ins_tran.taskid
	s_main.billtype = 1 // 定制产品订单
	s_main.cus_rep = Trim(dw_main.Object.cus_rep[ll_row])
	s_main.cus_tele = Trim(dw_main.Object.cus_tele[ll_row])
	s_main.cus_address = Trim(dw_main.Object.cus_address[ll_row])
	s_main.temp1 = Trim(dw_main.Object.temp1[ll_row])
	s_main.temp2 = Trim(dw_main.Object.temp2[ll_row])
	s_main.temp3 = Trim(dw_main.Object.temp3[ll_row])
	
	if (dw_mx.RowCount() <= 0) then
		MessageBox('提示', '没有订单明细')
		return
	end if
	for ll_i = 1 to dw_mx.RowCount()
		s_mx = s_empty_mx
		
		s_mx.printid = dw_mx.Object.printid[ll_i]
		s_mx.qty = dw_mx.Object.qty[ll_i]
		s_mx.requiredate = dw_mx.Object.requiredate[ll_i]
		s_mx.fxmtrlid_ori = dw_mx.Object.fxmtrlid_ori[ll_i]
		s_mx.fxmtrlid = dw_mx.Object.fxmtrlid[ll_i]
		s_mx.mtrlid_ori = dw_mx.Object.mtrlid_ori[ll_i]
		s_mx.mtrlid = dw_mx.Object.mtrlid[ll_i]
		s_mx.mxdscrp = Trim(dw_mx.Object.mxdscrp[ll_i])
		s_mx.mxdscrp2 = Trim(dw_mx.Object.mxdscrp2[ll_i])
//		s_mx.status = dw_mx.Object.status[ll_i]
//		s_mx.woodcode = dw_mx.Object.woodcode[ll_i]
//		s_mx.pcode = dw_mx.Object.pcode[ll_i]
		
		s_main.mx[ll_i] = s_mx
	next
	
	for ll_i = 1 to uo_tab.tabpage_fj.dw_fj.RowCount()
		s_fj = s_empty_fj
		
		s_fj.fjprintid = uo_tab.tabpage_fj.dw_fj.Object.fjprintid[ll_i]
		s_fj.mxprintid = uo_tab.tabpage_fj.dw_fj.Object.mxprintid[ll_i]
		s_fj.fjType = uo_tab.tabpage_fj.dw_fj.Object.fjType[ll_i]
		s_fj.dscrp = Trim(uo_tab.tabpage_fj.dw_fj.Object.dscrp[ll_i])
		s_fj.fileName = uo_tab.tabpage_fj.dw_fj.Object.fileName[ll_i]
		s_fj.fileType = uo_tab.tabpage_fj.dw_fj.Object.fileType[ll_i]
		s_fj.filemd5 = uo_tab.tabpage_fj.dw_fj.Object.filemd5[ll_i]
		s_fj.filepath = uo_tab.tabpage_fj.dw_fj.Object.filepath[ll_i]
		
		s_main.fj[ll_i] = s_fj
	next
	
	if (wf_save(s_main, ref arg_msg) <> 1) then
		MessageBox('提示', '订单保存失败:' + arg_msg)
	else
		ins_ret = 1
		MessageBox('提示', '订单保存成功')
		Close(parent)
	end if
elseif (ins_tran.taskid > 0 and ins_tran.status = 0) then // 退回
	s_input.title = '取消原因'
	s_input.old_text = '退回订单'
	OpenWithParm(w_inputbox, s_input)
	ls_ret = Message.StringParm
	if (ls_ret = '') then
		MessageBox('提示', '请填写退回原因')
		return
	end if
	if (MessageBox('提示', '确认退回当前订单？', Question!, YesNo!) <> 1) then return
	if (wf_cancel(ls_ret, ref arg_msg) <> 1) then
		MessageBox('提示', '订单退回失败:' + arg_msg)
	else
		ins_ret = 1
		MessageBox('提示', '订单退回成功')
		Close(parent)
	end if
elseif (ins_tran.status = 4) then // 审核
	// TODO:检查付款凭证
	//wf_audit()
elseif (ins_tran.status = 8) then // 收货
	
end if

end event

type cb_exit from w_publ_base`cb_exit within w_buytask_custom_view_fx
integer x = 3314
integer y = 2596
integer taborder = 70
end type

type cb_addmx from commandbutton within w_buytask_custom_view_fx
integer x = 23
integer y = 744
integer width = 288
integer height = 80
integer taborder = 20
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string text = "添加"
end type

event clicked;wf_add_mx()
end event

type cb_delmx from commandbutton within w_buytask_custom_view_fx
integer x = 325
integer y = 744
integer width = 288
integer height = 80
integer taborder = 30
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string text = "删除"
end type

event clicked;if (not if_modify_mode) then return

long ll_row, ll_printid
ll_row = dw_mx.GetRow()
if (ll_row <= 0) then
	Messagebox('提示', '请选择需要删除的明细行')
	return
end if

ll_printid = dw_mx.Object.printid[ll_row]
dw_mx.DeleteRow(ll_row)

// 删除相应的附件
uo_tab.post event ue_tab_fj_del(ll_printid)

if (dw_mx.RowCount() > 0 and ll_row <= dw_mx.RowCount()) then
	dw_mx.SetRow(ll_row)
	dw_mx.SelectRow(0, false)
	dw_mx.SelectRow(ll_row, true)
end if
end event

type uo_tab from uo_fx_saletask_custom_tab within w_buytask_custom_view_fx
integer y = 1456
integer width = 3653
integer height = 1116
integer taborder = 50
boolean bringtotop = true
end type

type dw_main from datawindow within w_buytask_custom_view_fx
integer width = 3657
integer height = 724
integer taborder = 10
boolean bringtotop = true
string title = "none"
string dataobject = "dw_fx_buytask_custom_new"
boolean livescroll = true
end type

event clicked;if (if_modify_mode) then
	if (dwo.Name = 'b_cus') then // 收货人地址管理
		wf_address_ch()
	end if
end if
end event

event doubleclicked;if (if_modify_mode) then
	if (dwo.Name = 'cus_rep' &
			or dwo.Name = 'cus_tele' &
			or dwo.Name = 'cus_address') then // 收货人地址管理
		wf_address_ch()
	end if
end if
end event

type dw_mx from u_dw_rbtnfilter within w_buytask_custom_view_fx
integer y = 844
integer width = 3657
integer height = 360
integer taborder = 40
boolean bringtotop = true
string dataobject = "dw_fx_buytaskmx_custom"
boolean hscrollbar = true
boolean vscrollbar = true
boolean hsplitscroll = true
borderstyle borderstyle = stylebox!
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
end type

event doubleclicked;call super::doubleclicked;if (if_modify_mode and dwo.Type = 'datawindow') then
	wf_add_mx()
end if
end event

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

event rowfocuschanged;call super::rowfocuschanged;if (currentrow > 0) then
	this.SetRow(currentrow)
	this.SelectRow(0, false)
	this.SelectRow(currentrow, true)
end if
end event

