$PBExportHeader$w_buytask_fx.srw
$PBExportComments$分销系统窗体(采购订单)
forward
global type w_buytask_fx from w_publ_base_style
end type
type cb_retrieve from uo_imflatbutton within w_buytask_fx
end type
type cb_neworsave from uo_imflatbutton within w_buytask_fx
end type
type cb_editorundo from uo_imflatbutton within w_buytask_fx
end type
type cb_del from uo_imflatbutton within w_buytask_fx
end type
type em_pagesize from editmask within w_buytask_fx
end type
type cb_toppage from uo_imflatbutton within w_buytask_fx
end type
type st_1 from statictext within w_buytask_fx
end type
type ddlb_status from dropdownlistbox within w_buytask_fx
end type
type st_2 from statictext within w_buytask_fx
end type
type em_datea from editmask within w_buytask_fx
end type
type st_3 from statictext within w_buytask_fx
end type
type em_datez from editmask within w_buytask_fx
end type
type cb_page_ch from uo_imflatbutton within w_buytask_fx
end type
type st_4 from statictext within w_buytask_fx
end type
type sle_likestr from u_sleedit within w_buytask_fx
end type
type dw_buytask from datawindow within w_buytask_fx
end type
type dw_buytask_list from u_dw_rbtnfilter within w_buytask_fx
end type
type tab_1 from tab within w_buytask_fx
end type
type tabpage_1 from userobject within tab_1
end type
type cb_delmx from commandbutton within tabpage_1
end type
type cb_addmx from commandbutton within tabpage_1
end type
type dw_buytaskmx from u_dw_rbtnfilter within tabpage_1
end type
type tabpage_1 from userobject within tab_1
cb_delmx cb_delmx
cb_addmx cb_addmx
dw_buytaskmx dw_buytaskmx
end type
type tab_1 from tab within w_buytask_fx
tabpage_1 tabpage_1
end type
type cb_send from uo_imflatbutton within w_buytask_fx
end type
end forward

global type w_buytask_fx from w_publ_base_style
integer width = 4119
integer height = 2660
string title = "采购订单"
boolean maxbox = true
boolean resizable = true
long backcolor = 16777215
string icon = "graphics\chain_link_128px.ico"
event ue_page_next ( )
event ue_page_before ( )
event ue_page_end ( )
cb_retrieve cb_retrieve
cb_neworsave cb_neworsave
cb_editorundo cb_editorundo
cb_del cb_del
em_pagesize em_pagesize
cb_toppage cb_toppage
st_1 st_1
ddlb_status ddlb_status
st_2 st_2
em_datea em_datea
st_3 st_3
em_datez em_datez
cb_page_ch cb_page_ch
st_4 st_4
sle_likestr sle_likestr
dw_buytask dw_buytask
dw_buytask_list dw_buytask_list
tab_1 tab_1
cb_send cb_send
end type
global w_buytask_fx w_buytask_fx

type variables
boolean if_edit_mode = false

long ins_cur_pageNum = 1 // 用于记录当前页码
long ins_totalPages = 1 // 用于记录总页数

datawindow dw_buytaskmx

uo_fx_pz uo_pz // 协同配置UO
end variables

forward prototypes
public subroutine wf_face_btn ()
public function integer wf_retrieve_saletask ()
public function integer wf_retrieve_saletaskmx (readonly long arg_taskid)
public subroutine wf_taborder ()
public subroutine wf_add_saletask ()
public function integer wf_save_saletask (ref string arg_msg)
public function long wf_del_saletask (readonly long arg_taskid)
end prototypes

event ue_page_next();if (ins_cur_pageNum + 1 > ins_totalPages) then
	MessageBox('提示', '已到最后一页')
	return
end if

ins_cur_pageNum ++
wf_retrieve_saletask( )
end event

event ue_page_before();if (ins_cur_pageNum = 1) then
	MessageBox('提示', '已经是第一页')
	return
end if

ins_cur_pageNum --
wf_retrieve_saletask( )
end event

event ue_page_end();if (ins_cur_pageNum = ins_totalPages) then
	MessageBox('提示', '已到最后一页')
	return
end if

ins_cur_pageNum = ins_totalPages
wf_retrieve_saletask( )
end event

public subroutine wf_face_btn ();if if_edit_mode then // 修改状态
	cb_retrieve.Enabled = false
	
	cb_neworsave.Enabled = true // 保存
	cb_neworsave.Text = '保存&S'
	cb_neworsave.normalpicname = 'Save.bmp'
	
	//cb_editorundo.Enabled = true // 撤销
	cb_editorundo.Text = '放弃&E'
	cb_editorundo.normalpicname = 'Undo.bmp'
	
	cb_del.Enabled = false
	
	cb_send.Enabled = false
	
	cb_exit.Enabled = false
	
	em_pagesize.Enabled = false
	
	cb_toppage.Enabled = false
	
	cb_page_ch.Enabled = false
	
	ddlb_status.Enabled = false
	
	em_datea.Enabled = false
	
	em_datez.Enabled = false
	
	tab_1.tabpage_1.cb_addmx.Enabled = true // 增明细
	tab_1.tabpage_1.cb_delmx.Enabled = true // 删明细
else // 浏览状态
	cb_retrieve.Enabled = true
	
	cb_neworsave.Enabled = true
	cb_neworsave.Text = '新建&S'
	cb_neworsave.normalpicname = 'new.bmp'
	
	//cb_editorundo.Enabled = true
	cb_editorundo.Text = '修改&E'
	cb_editorundo.normalpicname = 'open.bmp'
	
	//cb_del.Enabled = true
	
	cb_exit.Enabled = true
	
	em_pagesize.Enabled = true
	
	cb_toppage.Enabled = true
	
	cb_page_ch.Enabled = true
	
	ddlb_status.Enabled = true
	
	em_datea.Enabled = true
	
	em_datez.Enabled = true
	
	tab_1.tabpage_1.cb_addmx.Enabled = false
	tab_1.tabpage_1.cb_delmx.Enabled = false
end if

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

cb_editorundo.of_init_draw()
cb_editorundo.of_paint()
cb_editorundo.TriggerEvent('ue_textchange')
end subroutine

public function integer wf_retrieve_saletask ();int rslt = 1

string arg_msg
long pageSize
pageSize = Integer(em_pagesize.Text)
if (pageSize <= 0) then
	rslt = 0
	arg_msg = '每页显示行数必须大于0'
	em_pagesize.SetFocus( )
	em_pagesize.SelectText(1, Len(em_pagesize.Text))
	goto ext
end if

long pageNum
pageNum = ins_cur_pageNum

long status
long ll_pos
ll_pos = Pos(ddlb_status.Text, '[')
if (ll_pos <= 0) then
	status = -1
else
	status = Long(Mid(ddlb_status.Text, ll_pos + 1, Len(ddlb_status.Text) - ll_pos - 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 likeStr
likeStr = Trim(sle_likestr.Text)

oleobject rsp
rsp = FXAppCom.GetBuytask(app_token_fx, pageSize, pageNum, status, String(dateA), String(dateZ), likeStr, ref arg_msg)

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

dw_buytask_list.Reset( )
dw_buytask.Reset( )
dw_buytaskmx.Reset( )

dw_buytask_list.SetRedraw(false)
long i, row
ins_totalPages = rsp.GetInt('totalpages')
oleobject list, item
list = rsp.GetArrOfPBDictionary('list')
for i = 1 to list.Count
	item = list.GetItem(i - 1)
	
	row = dw_buytask_list.InsertRow(0)
	long taskidd
	taskidd = item.GetInt('taskid')
	dw_buytask_list.Object.taskid[row] = item.GetInt('taskid') // 订单ID int
	dw_buytask_list.Object.tid[row] = item.GetString('tid') // 云端订单编号 varchar(50)
	dw_buytask_list.Object.taskdate[row] = item.GetDateTime('taskdate') // 下单日期 datetime
	dw_buytask_list.Object.sptcomid[row] = item.GetInt('sptcomid') // 卖方企业ID int
	dw_buytask_list.Object.cuscomid[row] = item.GetInt('cuscomid') // 买方企业ID int
	dw_buytask_list.Object.cus_rep[row] = item.GetString('cus_rep') // 收货人 varchar(30)
	dw_buytask_list.Object.cus_tele[row] = item.GetString('cus_tele') // 联系电话 varchar(100)
	dw_buytask_list.Object.cus_address[row] = item.GetString('cus_address') // 收货地址 varchar(255)
	dw_buytask_list.Object.freight[row] = item.GetString('freight') // 货运部 varchar(50)
	dw_buytask_list.Object.freight_tele[row] = item.GetString('freight_tele') // 货运部电话 varchar(50)
	dw_buytask_list.Object.opemp[row] = item.GetString('opemp') // 建立人 varchar(255)
	dw_buytask_list.Object.opdate[row] = item.GetDateTime('opdate') // 建立时间 datetime
	dw_buytask_list.Object.modemp[row] = item.GetString('modemp') // 修改人 varchar(255)
	if (not IsNull(item.GetDateTime('moddate'))) then
		dw_buytask_list.Object.moddate[row] = item.GetDateTime('moddate') // 修改时间 datetime
	end if
	dw_buytask_list.Object.buyer_name[row] = item.GetString('buyer_name') // 客户名称 varchar(30)
	dw_buytask_list.Object.buyer_tele[row] = item.GetString('buyer_tele') // 客户电话 varchar(100)
	if (not IsNull(item.GetDateTime('requiredate'))) then
		dw_buytask_list.Object.requiredate[row] = item.GetDateTime('requiredate') // 要求交期 datetime
	end if
	dw_buytask_list.Object.temp1[row] = item.GetString('temp1') // 备注 dscrp varchar(255)
	dw_buytask_list.Object.temp2[row] = item.GetString('temp2') // 生产备注 dscrp2 varchar(255)
	dw_buytask_list.Object.temp3[row] = item.GetString('temp3') // 辅助备注 dscrp3 varchar(255)
	dw_buytask_list.Object.temp4[row] = item.GetString('temp4') // 自定义4 varchar(255)
	dw_buytask_list.Object.temp5[row] = item.GetString('temp5') // 自定义5 varchar(255)
	dw_buytask_list.Object.temp6[row] = item.GetString('temp6') // 自定义6 varchar(255)
	dw_buytask_list.Object.price_emp[row] = item.GetString('price_emp') // 报价人 varchar(255)
	if (not IsNull(item.GetDateTime('replyrqdate'))) then
		dw_buytask_list.Object.replyrqdate[row] = item.GetDateTime('replyrqdate') // 回复交期 datetime
	end if
	dw_buytask_list.Object.replydscrp[row] = item.GetString('replydscrp') // 审核意见 varchar(255)
	if (not IsNull(item.GetDateTime('replydate'))) then
		dw_buytask_list.Object.replydate[row] = item.GetDateTime('replydate') // 回复时间 datetime
	end if
	dw_buytask_list.Object.confirmemp[row] = item.GetString('confirmemp') // 下单人 varchar(255)
	if (not IsNull(item.GetDateTime('confirmdate'))) then
		dw_buytask_list.Object.confirmdate[row] = item.GetDateTime('confirmdate') // 下单时间 datetime
	end if
	dw_buytask_list.Object.status[row] = item.GetInt('status') // 订单状态 tinyint
	dw_buytask_list.Object.taskcode[row] = item.GetString('taskcode') // ERP订单编号 varchar(30)
	dw_buytask_list.Object.outwarecode[row] = item.GetString('outwarecode') // ERP发货单编号 varchar(30)
	dw_buytask_list.Object.fstatus[row] = item.GetInt('fstatus') // 工厂进度 int
	dw_buytask_list.Object.myrelcode[row] = item.GetString('relcode')
	dw_buytask_list.Object.sptname[row] = item.GetString('comname')
next
dw_buytask_list.SetRedraw(true)

ext:
if (rslt = 1) then
	if (dw_buytask_list.RowCount() > 0) then
		dw_buytask_list.SelectRow(0, false)
		dw_buytask_list.SelectRow(1, true)
		dw_buytask_list.SetRow(1)
		dw_buytask_list.Trigger Event RowFocusChanged(1)
	end if
else
	MessageBox('提示', arg_msg)
end if

return rslt


end function

public function integer wf_retrieve_saletaskmx (readonly long arg_taskid);int rslt = 1

if (IsNull(arg_taskid)) then return 0

string arg_msg = ''
oleobject list
list = FXAppCom.GetBuytaskmx(app_token_fx, arg_taskid, ref arg_msg)

if (arg_msg <> '') then
	rslt = 0
	MessageBox('提示', '获取订单明细有误:' + arg_msg)
	goto ext
end if

dw_buytaskmx.SetRedraw(false)
dw_buytaskmx.Reset( )
long i
oleobject item
for i = 1 to list.Count
	item = list.GetItem(i - 1)
	
	dw_buytaskmx.Object.taskid[i] = item.GetInt('taskid')
	dw_buytaskmx.Object.printid[i] = item.GetInt('printid')
	dw_buytaskmx.Object.mxcode[i] = item.GetString('mxcode')
	dw_buytaskmx.Object.fxmtrlid[i] = item.GetInt('fxmtrlid')
	dw_buytaskmx.Object.mtrlid[i] = item.GetInt('mtrlid')
	dw_buytaskmx.Object.mtrlcode[i] = item.GetString('mtrlcode')
	dw_buytaskmx.Object.mtrlname[i] = item.GetString('mtrlname')
	dw_buytaskmx.Object.status[i] = item.GetString('status')
	dw_buytaskmx.Object.woodcode[i] = item.GetString('woodcode')
	dw_buytaskmx.Object.pcode[i] = item.GetString('pcode')
	dw_buytaskmx.Object.qty[i] = item.GetDouble('qty')
	dw_buytaskmx.Object.cus_receiveqty[i] = item.GetDouble('cus_receiveqty')
	dw_buytaskmx.Object.price[i] = item.GetDouble('price')
	dw_buytaskmx.Object.mxdscrp[i] = item.GetString('mxdscrp')
	dw_buytaskmx.Object.mxdscrp2[i] = item.GetString('mxdscrp2')
	dw_buytaskmx.Object.mtrlcuscode[i] = item.GetString('mtrlcuscode')
next
dw_buytaskmx.SetRedraw(true)

ext:
return rslt


end function

public subroutine wf_taborder ();if if_edit_mode then
	dw_buytask.SetTabOrder('requiredate', 10)
	dw_buytask.SetTabOrder('cus_rep', 20)
	dw_buytask.SetTabOrder('cus_tele', 30)
	dw_buytask.SetTabOrder('cus_address', 40)
	dw_buytask.SetTabOrder('freight', 50)
	dw_buytask.SetTabOrder('freight_tele', 60)
	dw_buytask.SetTabOrder('buyer_name', 70)
	dw_buytask.SetTabOrder('buyer_tele', 80)
	dw_buytask.SetTabOrder('temp1', 90)
	dw_buytask.SetTabOrder('temp2', 100)
	dw_buytask.SetTabOrder('temp3', 110)
	
	dw_buytaskmx.SetTabOrder('qty', 10)
	dw_buytaskmx.SetTabOrder('price', 10)
	dw_buytaskmx.SetTabOrder('mxdscrp', 10)
	dw_buytaskmx.SetTabOrder('mxdscrp2', 10)
	dw_buytaskmx.SetTabOrder('mtrlcuscode', 10)
else
	dw_buytask.SetTabOrder('requiredate', 0)
	dw_buytask.SetTabOrder('cus_rep', 0)
	dw_buytask.SetTabOrder('cus_tele', 0)
	dw_buytask.SetTabOrder('cus_address', 0)
	dw_buytask.SetTabOrder('freight', 0)
	dw_buytask.SetTabOrder('freight_tele', 0)
	dw_buytask.SetTabOrder('buyer_name', 0)
	dw_buytask.SetTabOrder('buyer_tele', 0)
	dw_buytask.SetTabOrder('temp1', 0)
	dw_buytask.SetTabOrder('temp2', 0)
	dw_buytask.SetTabOrder('temp3', 0)
	
	dw_buytaskmx.SetTabOrder('qty', 0)
	dw_buytaskmx.SetTabOrder('price', 0)
	dw_buytaskmx.SetTabOrder('mxdscrp', 0)
	dw_buytaskmx.SetTabOrder('mxdscrp2', 0)
	dw_buytaskmx.SetTabOrder('mtrlcuscode', 0)
end if
end subroutine

public subroutine wf_add_saletask ();long row
dw_buytask_list.SelectRow(0, false)
row = dw_buytask_list.InsertRow(0)
//dw_buytask_list.Trigger Event RowFocusChanged(row)
dw_buytask.Reset( )
dw_buytaskmx.Reset( )

long row_main
row_main = dw_buytask.InsertRow(0)

dw_buytask.Object.taskid[row_main] = 0
dw_buytask.Object.tid[row_main] = ''
dw_buytask.Object.taskdate[row_main] = Today()
dw_buytask.Object.sptcomid[row_main] = 0
dw_buytask.Object.cuscomid[row_main] = 0
dw_buytask.Object.cus_rep[row_main] = app_username
dw_buytask.Object.cus_tele[row_main] = app_tele
dw_buytask.Object.cus_address[row_main] = app_address
dw_buytask.Object.freight[row_main] = app_freight
dw_buytask.Object.freight_tele[row_main] = app_freight_tele
dw_buytask.Object.opemp[row_main] = app_username
dw_buytask.Object.opdate[row_main] = Datetime(Today(), Now())
dw_buytask.Object.modemp[row_main] = ''
//dw_buytask.Object.moddate[row_main] = null
dw_buytask.Object.buyer_name[row_main] = app_comname
dw_buytask.Object.buyer_tele[row_main] = app_comtele
dw_buytask.Object.requiredate[row_main] = Today()
dw_buytask.Object.temp1[row_main] = ''
dw_buytask.Object.temp2[row_main] = ''
dw_buytask.Object.temp3[row_main] = ''
dw_buytask.Object.temp4[row_main] = ''
dw_buytask.Object.temp5[row_main] = ''
dw_buytask.Object.temp6[row_main] = ''
dw_buytask.Object.price_emp[row_main] = ''
//dw_buytask.Object.replyrqdate[row_main] = ''
dw_buytask.Object.replydscrp[row_main] = ''
//dw_buytask.Object.replydate[row_main] = ''
dw_buytask.Object.confirmemp[row_main] = app_username
dw_buytask.Object.confirmdate[row_main] = Datetime(Today(), Now())
dw_buytask.Object.status[row_main] = 0
dw_buytask.Object.taskcode[row_main] = ''
dw_buytask.Object.outwarecode[row_main] = ''
dw_buytask.Object.fstatus[row_main] = 0
dw_buytask.Object.myrelcode[row_main] = app_myrelcode

cb_editorundo.Enabled = true
end subroutine

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

rslt = dw_buytask.AcceptText()
rslt = dw_buytaskmx.AcceptText()

// 检查
long row_main
row_main = dw_buytask.GetRow( )
if (row_main <= 0) then
	rslt = 0
	arg_msg = '没有新建订单'
	goto ext
end if

long mxCnt
mxCnt = dw_buytaskmx.RowCount()
if (mxCnt <= 0) then
	rslt = 0
	arg_msg = '没有订单明细内容'
	goto ext
end if

if (Trim(dw_buytask.Object.cus_rep[row_main]) = '') then
	rslt = 0
	arg_msg = '请填写收货人'
	goto ext
end if

long i
for i = 1 to mxCnt
	if (dw_buytaskmx.Object.qty[i] <= 0) or (dw_buytaskmx.Object.price[i] <= 0) then
		rslt = 0
		arg_msg += '订单明细第' + string(i) + '行,数量 或 单价<=0,请检查~r~n'
	end if
next
if (rslt = 0) then goto ext

// 检查通过，对明细的printid进行赋值
for i = 1 to mxCnt
	dw_buytaskmx.Object.printid[i] = i
next

// 保存
oleobject task
task = FXAppCom.CreatePbDictionary()

task.SetInt('taskid', dw_buytask.Object.taskid[row_main]) //订单ID int
task.SetString('tid', dw_buytask.Object.tid[row_main]) //云端订单编号 varchar(50)
task.SetDateTime('taskdate', dw_buytask.Object.taskdate[row_main]) //下单日期 datetime
task.SetInt('sptcomid', dw_buytask.Object.sptcomid[row_main]) //卖方企业ID int
task.SetInt('cuscomid', dw_buytask.Object.cuscomid[row_main]) //买方企业ID int
task.SetString('cus_rep', dw_buytask.Object.cus_rep[row_main]) //收货人 varchar(30)
task.SetString('cus_tele', dw_buytask.Object.cus_tele[row_main]) //联系电话 varchar(100)
task.SetString('cus_address', dw_buytask.Object.cus_address[row_main]) //收货地址 varchar(255)
task.SetString('freight', dw_buytask.Object.freight[row_main]) //货运部 varchar(50)
task.SetString('freight_tele', dw_buytask.Object.freight_tele[row_main]) //货运部电话 varchar(50)
task.SetString('opemp', dw_buytask.Object.opemp[row_main]) //建立人 varchar(255)
task.SetDateTime('opdate', dw_buytask.Object.opdate[row_main]) //建立时间 datetime
task.SetString('modemp', dw_buytask.Object.modemp[row_main]) //修改人 varchar(255)
task.SetDateTime('moddate', dw_buytask.Object.moddate[row_main]) //修改时间 datetime
task.SetString('buyer_name', dw_buytask.Object.buyer_name[row_main]) //客户名称 varchar(30)
task.SetString('buyer_tele', dw_buytask.Object.buyer_tele[row_main]) //客户电话 varchar(100)
task.SetDateTime('requiredate', dw_buytask.Object.requiredate[row_main]) //要求交期 datetime
task.SetString('temp1', dw_buytask.Object.temp1[row_main]) //备注 dscrp varchar(255)
task.SetString('temp2', dw_buytask.Object.temp2[row_main]) //生产备注 dscrp2 varchar(255)
task.SetString('temp3', dw_buytask.Object.temp3[row_main]) //辅助备注 dscrp3 varchar(255)
task.SetString('temp4', dw_buytask.Object.temp4[row_main]) //自定义4 varchar(255)
task.SetString('temp5', dw_buytask.Object.temp5[row_main]) //自定义5 varchar(255)
task.SetString('temp6', dw_buytask.Object.temp6[row_main]) //自定义6 varchar(255)
task.SetString('price_emp', dw_buytask.Object.price_emp[row_main]) //报价人 varchar(255)
task.SetDateTime('replyrqdate', dw_buytask.Object.replyrqdate[row_main]) //回复交期 datetime
task.SetString('replydscrp', dw_buytask.Object.replydscrp[row_main]) //审核意见 varchar(255)
task.SetDateTime('replydate', dw_buytask.Object.replydate[row_main]) //回复时间 datetime
task.SetString('confirmemp', dw_buytask.Object.confirmemp[row_main]) //下单人 varchar(255)
task.SetDateTime('confirmdate', dw_buytask.Object.confirmdate[row_main]) //下单时间 datetime
task.SetInt('status', dw_buytask.Object.status[row_main]) //订单状态 tinyint
task.SetString('taskcode', dw_buytask.Object.taskcode[row_main]) //ERP订单编号 varchar(30)
task.SetString('outwarecode', dw_buytask.Object.outwarecode[row_main]) //ERP发货单编号 varchar(30)
task.SetInt('fstatus', dw_buytask.Object.fstatus[row_main]) //工厂进度 int

oleobject taskmxs, taskmx
taskmxs = FXAppCom.CreArrOfPbDictionary()
for i = 1 to mxCnt
	taskmx = FXAppCom.CreatePbDictionary()
	
	taskmx.SetInt('taskid', dw_buytask.Object.taskid[row_main]) //订单ID int
	taskmx.SetInt('printid', dw_buytaskmx.Object.printid[i]) //附件ID int
	taskmx.SetString('mxcode', dw_buytaskmx.Object.mxcode[i]) //XS150703001_01 varchar(50)
	taskmx.SetInt('fxmtrlid', dw_buytaskmx.Object.fxmtrlid[i]) //平台唯一物料ID int
	taskmx.SetInt('mtrlid', dw_buytaskmx.Object.mtrlid[i]) //卖方物料ID int
	taskmx.SetString('mtrlcode', dw_buytaskmx.Object.mtrlcode[i]) //卖方物料编码 varchar(255)
	taskmx.SetString('mtrlname', dw_buytaskmx.Object.mtrlname[i]) //卖方物料名称 varchar(255)
	taskmx.SetString('status', dw_buytaskmx.Object.status[i]) //卖方物料配置 varchar(255)
	taskmx.SetString('woodcode', dw_buytaskmx.Object.woodcode[i]) //卖方物料配置1 varchar(255)
	taskmx.SetString('pcode', dw_buytaskmx.Object.pcode[i]) //卖方物料配置2 varchar(255)
	taskmx.SetDouble('qty', dw_buytaskmx.Object.qty[i]) //数量 decimal(18,5)
	taskmx.SetDouble('price', dw_buytaskmx.Object.price[i]) //单价 decimal(18,5)
	taskmx.SetInt('cus_mtrlid', 0) //买方物料ID int dw_buytaskmx.Object.cus_mtrlid[i]
	taskmx.SetString('cus_mtrlcode', '') //买方物料编码 varchar(255) dw_buytaskmx.Object.cus_mtrlcode[i]
	taskmx.SetString('cus_mtrlname', '') //买方物料名称 varchar(255) dw_buytaskmx.Object.cus_mtrlname[i]
	taskmx.SetString('cus_status', '') //买方物料配置 varchar(255) dw_buytaskmx.Object.cus_status[i]
	taskmx.SetString('cus_woodcode', '') //买方物料配置1 varchar(255) dw_buytaskmx.Object.cus_woodcode[i]
	taskmx.SetString('cus_pcode', '') //买方物料配置2 varchar(255) dw_buytaskmx.Object.cus_pcode[i]
	taskmx.SetString('mxdscrp', dw_buytaskmx.Object.mxdscrp[i]) //明细备注 varchar(255)
	taskmx.SetString('mxdscrp2', dw_buytaskmx.Object.mxdscrp2[i]) //明细备注2 varchar(255)
	taskmx.SetString('mtrlcuscode', dw_buytaskmx.Object.mtrlcuscode[i]) //生产批号 varchar(255)
	
	taskmxs.Add(taskmx)
next

FXAppCom.AddBuytask(app_token_fx, task, taskmxs, ref arg_msg)

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

ext:
return rslt



end function

public function long wf_del_saletask (readonly long arg_taskid);int rslt = 1

string arg_msg
FXAppCom.DelBuytask(app_token_fx, arg_taskid, ref arg_msg)
if (arg_msg <> '') then
	rslt = 0
	MessageBox('提示', '删除订单失败:' + arg_msg)
else
	MessageBox('提示', '删除成功')
end if

return rslt
end function

on w_buytask_fx.create
int iCurrent
call super::create
this.cb_retrieve=create cb_retrieve
this.cb_neworsave=create cb_neworsave
this.cb_editorundo=create cb_editorundo
this.cb_del=create cb_del
this.em_pagesize=create em_pagesize
this.cb_toppage=create cb_toppage
this.st_1=create st_1
this.ddlb_status=create ddlb_status
this.st_2=create st_2
this.em_datea=create em_datea
this.st_3=create st_3
this.em_datez=create em_datez
this.cb_page_ch=create cb_page_ch
this.st_4=create st_4
this.sle_likestr=create sle_likestr
this.dw_buytask=create dw_buytask
this.dw_buytask_list=create dw_buytask_list
this.tab_1=create tab_1
this.cb_send=create cb_send
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_retrieve
this.Control[iCurrent+2]=this.cb_neworsave
this.Control[iCurrent+3]=this.cb_editorundo
this.Control[iCurrent+4]=this.cb_del
this.Control[iCurrent+5]=this.em_pagesize
this.Control[iCurrent+6]=this.cb_toppage
this.Control[iCurrent+7]=this.st_1
this.Control[iCurrent+8]=this.ddlb_status
this.Control[iCurrent+9]=this.st_2
this.Control[iCurrent+10]=this.em_datea
this.Control[iCurrent+11]=this.st_3
this.Control[iCurrent+12]=this.em_datez
this.Control[iCurrent+13]=this.cb_page_ch
this.Control[iCurrent+14]=this.st_4
this.Control[iCurrent+15]=this.sle_likestr
this.Control[iCurrent+16]=this.dw_buytask
this.Control[iCurrent+17]=this.dw_buytask_list
this.Control[iCurrent+18]=this.tab_1
this.Control[iCurrent+19]=this.cb_send
end on

on w_buytask_fx.destroy
call super::destroy
destroy(this.cb_retrieve)
destroy(this.cb_neworsave)
destroy(this.cb_editorundo)
destroy(this.cb_del)
destroy(this.em_pagesize)
destroy(this.cb_toppage)
destroy(this.st_1)
destroy(this.ddlb_status)
destroy(this.st_2)
destroy(this.em_datea)
destroy(this.st_3)
destroy(this.em_datez)
destroy(this.cb_page_ch)
destroy(this.st_4)
destroy(this.sle_likestr)
destroy(this.dw_buytask)
destroy(this.dw_buytask_list)
destroy(this.tab_1)
destroy(this.cb_send)
end on

event ue_before_open;call super::ue_before_open;em_datea.Text = String(RelativeDate(Today(), - 30))
em_datez.Text = String(Today())

ddlb_status.SelectItem(6)

dw_buytaskmx = tab_1.tabpage_1.dw_buytaskmx

uo_pz = create uo_fx_pz

wf_retrieve_saletask( )
end event

event closequery;call super::closequery;if if_edit_mode then return 1
end event

event resize;call super::resize;if (this.Width < 4082) then this.Width = 4082
if (this.Height < 2548) then this.Height = 2548

dw_buytask_list.Width = this.workspacewidth( ) - dw_buytask.Width - 14
tab_1.Width = this.workspacewidth( )
dw_buytaskmx.Width = tab_1.Width - 40

tab_1.Height = this.workspaceheight( ) - tab_1.Y
dw_buytaskmx.Height = tab_1.Height - tab_1.tabpage_1.cb_addmx.Height - 118
end event

event close;call super::close;destroy uo_pz
end event

type cb_func from w_publ_base_style`cb_func within w_buytask_fx
boolean visible = false
integer x = 2295
boolean enabled = false
end type

type cb_exit from w_publ_base_style`cb_exit within w_buytask_fx
integer x = 1038
end type

event cb_exit::clicked;if not if_edit_mode then close(parent)
end event

type ln_bar from w_publ_base_style`ln_bar within w_buytask_fx
end type

type ln_bar2 from w_publ_base_style`ln_bar2 within w_buytask_fx
end type

type r_bar from w_publ_base_style`r_bar within w_buytask_fx
end type

type cb_retrieve from uo_imflatbutton within w_buytask_fx
integer width = 151
integer height = 164
integer taborder = 30
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;ins_cur_pageNum = 1
wf_retrieve_saletask( )
end event

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

event clicked;call super::clicked;dw_edit_mode = not dw_edit_mode

string arg_msg
if if_edit_mode then // 保存功能
	if (wf_save_saletask(ref arg_msg) = 0) then
		MessageBox('提示', '操作失败:~r~n' + arg_msg)
		return
	else
		MessageBox('提示', '订单保存成功')
		wf_retrieve_saletask( )
	end if
else // 新建功能
	wf_add_saletask( )
end if

if_edit_mode = not if_edit_mode
wf_face_btn( )
wf_taborder( )
end event

type cb_editorundo from uo_imflatbutton within w_buytask_fx
integer x = 352
integer width = 192
integer height = 164
integer taborder = 40
boolean bringtotop = true
string text = "修改&E"
string normalpicname = "open.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;dw_edit_mode = not dw_edit_mode

if if_edit_mode then // 放弃
	if (MessageBox('提示', '确定要放弃保存当前单据的修改?', Question!, YesNoCancel!) <> 1) then return
end if

if_edit_mode = not if_edit_mode
wf_face_btn( )
wf_taborder( )

if (not if_edit_mode) and (dw_buytask_list.GetRow() > 0) then
	dw_buytask_list.Trigger Event RowFocusChanged(dw_buytask_list.GetRow())
end if
end event

type cb_del from uo_imflatbutton within w_buytask_fx
integer x = 549
integer width = 151
integer height = 164
integer taborder = 20
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;if if_edit_mode then return

long row
row = dw_buytask_list.GetRow()
if (row <= 0) then
	MessageBox('提示', '请选择要删除的订单')
	return
end if

if (MessageBox('提示', '确定要删除当前订单?', Question!, YesNoCancel!) <> 1) then return

long taskid
taskid = dw_buytask_list.Object.taskid[row]

if wf_del_saletask(taskid) = 1 then
	wf_retrieve_saletask( )
end if
end event

type em_pagesize from editmask within w_buytask_fx
integer x = 1202
integer y = 44
integer width = 302
integer height = 84
integer taborder = 30
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "100"
alignment alignment = right!
borderstyle borderstyle = stylelowered!
string mask = "#####0"
boolean spin = true
double increment = 1
string minmax = "1~~"
end type

type cb_toppage from uo_imflatbutton within w_buytask_fx
integer x = 1509
integer width = 151
integer height = 164
integer taborder = 40
boolean bringtotop = true
string text = "首页"
boolean border = false
end type

event clicked;call super::clicked;ins_cur_pageNum = 1
wf_retrieve_saletask( )
end event

type st_1 from statictext within w_buytask_fx
integer x = 5
integer y = 204
integer width = 288
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 ddlb_status from dropdownlistbox within w_buytask_fx
integer x = 279
integer y = 188
integer width = 416
integer height = 496
integer taborder = 40
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[] = {"已下单[3]","新建[0]","已退回[2]","进行中[6]","完成[7]","全部"}
borderstyle borderstyle = stylelowered!
end type

event selectionchanged;wf_retrieve_saletask( )
end event

type st_2 from statictext within w_buytask_fx
integer x = 754
integer y = 204
integer width = 288
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 em_datea from editmask within w_buytask_fx
integer x = 1047
integer y = 188
integer width = 389
integer height = 84
integer taborder = 50
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_buytask_fx
integer x = 1440
integer y = 204
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 em_datez from editmask within w_buytask_fx
integer x = 1531
integer y = 188
integer width = 389
integer height = 84
integer taborder = 50
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 cb_page_ch from uo_imflatbutton within w_buytask_fx
integer x = 1659
integer width = 82
integer height = 164
integer taborder = 10
boolean bringtotop = true
string text = "▼"
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;m_Dfc_Control_PopupMenu dmPopupMenu
string menustr

menustr="Text=下页~tEvent=ue_page_next"
menustr = menustr + "|" + "Text=上页~tEvent=ue_page_before"
menustr = menustr + "|" + "Text=末页~tEvent=ue_page_end"
	
if len(trim(menustr))<>0 then
	dmPopupMenu = Create m_Dfc_Control_PopupMenu
	dmPopupMenu.mf_BuildMenu(This, menustr)
	dmPopupMenu.mf_PopMenu()
	Destroy dmPopupMenu
end if
end event

type st_4 from statictext within w_buytask_fx
integer x = 1970
integer y = 204
integer width = 224
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 sle_likestr from u_sleedit within w_buytask_fx
integer x = 2181
integer y = 188
integer height = 84
integer taborder = 20
boolean bringtotop = true
end type

event keydown;call super::keydown;if (key = KeyEnter!) then
	ins_cur_pageNum = 1
	wf_retrieve_saletask( )
end if
end event

type dw_buytask from datawindow within w_buytask_fx
integer y = 284
integer width = 2117
integer height = 1312
integer taborder = 50
boolean bringtotop = true
string title = "none"
string dataobject = "dw_fx_buytask_ff"
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 = 'sptname') or (dwo.Type = 'text' and dwo.Name = 'sptname_t')) then
	long ori_sptcomid, new_sptcomid
	ori_sptcomid = this.Object.sptcomid[row]
	
	s_fx_company s_ret
	Open(w_spt_ch_fx)
	s_ret = Message.PowerObjectParm
	if not IsNull(s_ret) then
		if (s_ret.ifselect) then
			new_sptcomid = s_ret.comid[1]
			if (ori_sptcomid <> new_sptcomid) then
				dw_buytaskmx.Reset() // 重选供应商，清空明细物料
				if (new_sptcomid > 0) then
					uo_pz.init()
					uo_pz.ins_comid = new_sptcomid
					string arg_msg
					if (uo_pz.uof_before_ready(ref arg_msg) <> 1) then
						MessageBox('提示', arg_msg)
					end if
				end if
			end if
			
			this.Object.sptcomid[row] = new_sptcomid
			this.Object.sptname[row] = s_ret.comname[1]
		end if
	end if
end if
end event

type dw_buytask_list from u_dw_rbtnfilter within w_buytask_fx
integer x = 2121
integer y = 284
integer width = 1947
integer height = 1312
integer taborder = 20
boolean bringtotop = true
boolean titlebar = true
string title = "采购订单"
string dataobject = "dw_fx_buytask"
boolean controlmenu = true
boolean maxbox = true
boolean hscrollbar = true
boolean vscrollbar = true
boolean resizable = true
boolean border = false
boolean hsplitscroll = true
boolean rbutton_filter_use = true
boolean rbutton_setposition_use = true
boolean titleclick_sort_use = true
end type

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

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

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

if (this.Object.status[currentrow] <> 0) then
	cb_send.Enabled = false
	cb_editorundo.Enabled = false
	cb_del.Enabled = false
else
	// 待询价的订单才可以使用下单、修改、删除按钮
	cb_send.Enabled = true
	cb_editorundo.Enabled = true
	cb_del.Enabled = true
end if

if (this.Object.status[currentrow] = 2) then
	// 已退回状态可修改、删除
	cb_editorundo.Enabled = true
	cb_del.Enabled = true
end if

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

long taskid
taskid = this.Object.taskid[currentrow]
wf_retrieve_saletaskmx(taskid)


end event

type tab_1 from tab within w_buytask_fx
integer y = 1600
integer width = 3671
integer height = 876
integer taborder = 60
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long backcolor = 16777215
boolean raggedright = true
boolean focusonbuttondown = true
integer selectedtab = 1
tabpage_1 tabpage_1
end type

on tab_1.create
this.tabpage_1=create tabpage_1
this.Control[]={this.tabpage_1}
end on

on tab_1.destroy
destroy(this.tabpage_1)
end on

type tabpage_1 from userobject within tab_1
integer x = 18
integer y = 96
integer width = 3634
integer height = 764
long backcolor = 16777215
string text = "订单明细"
long tabtextcolor = 33554432
long tabbackcolor = 16777215
long picturemaskcolor = 536870912
cb_delmx cb_delmx
cb_addmx cb_addmx
dw_buytaskmx dw_buytaskmx
end type

on tabpage_1.create
this.cb_delmx=create cb_delmx
this.cb_addmx=create cb_addmx
this.dw_buytaskmx=create dw_buytaskmx
this.Control[]={this.cb_delmx,&
this.cb_addmx,&
this.dw_buytaskmx}
end on

on tabpage_1.destroy
destroy(this.cb_delmx)
destroy(this.cb_addmx)
destroy(this.dw_buytaskmx)
end on

type cb_delmx from commandbutton within tabpage_1
integer x = 251
integer width = 242
integer height = 84
integer taborder = 50
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_buytaskmx.GetRow() <= 0) then
	MessageBox('提示', '请选择需要删除的明细项')
	return
end if

dw_buytaskmx.DeleteRow(dw_buytaskmx.GetRow())
end event

type cb_addmx from commandbutton within tabpage_1
integer width = 242
integer height = 84
integer taborder = 40
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean enabled = false
string text = "增明细"
end type

event clicked;open(w_mtrl_ch_fx)

s_fx_mtrldef s_tran
s_tran = Message.PowerObjectParm

long row, i
if IsValid(s_tran) then
	for i = 1 to UpperBound(s_tran.fxmtrlid)
		row = dw_buytaskmx.InsertRow(0)
		
		dw_buytaskmx.Object.fxmtrlid[row] = s_tran.fxmtrlid[i]
		dw_buytaskmx.Object.mtrlid[row] = s_tran.mtrlid[i]
		dw_buytaskmx.Object.mtrlcode[row] = s_tran.mtrlcode[i]
		dw_buytaskmx.Object.mtrlname[row] = s_tran.mtrlname[i]
		dw_buytaskmx.Object.status[row] = '规格[' + s_tran.mtrlmode[i] + '],[' + s_tran.mtrlsectype[i] + '],[' + s_tran.zxmtrlmode[i] + '],[' + s_tran.usermtrlmode[i] + ']'
		dw_buytaskmx.Object.woodcode[row] = ''
		dw_buytaskmx.Object.pcode[row] = ''
		dw_buytaskmx.Object.qty[row] = 1
		dw_buytaskmx.Object.cus_receiveqty[row] = 0
		dw_buytaskmx.Object.price[row] = 1
		dw_buytaskmx.Object.mxdscrp[row] = ''
		dw_buytaskmx.Object.mxdscrp2[row] = ''
		dw_buytaskmx.Object.mtrlcuscode[row] = ''
	next
end if
end event

type dw_buytaskmx from u_dw_rbtnfilter within tabpage_1
integer y = 88
integer width = 3497
integer height = 648
integer taborder = 20
string dataobject = "dw_fx_saletaskmx"
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 return

this.SelectRow(0, false)
this.SelectRow(row, true)
end event

type cb_send from uo_imflatbutton within w_buytask_fx
integer x = 704
integer width = 329
integer height = 164
integer taborder = 40
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;if if_edit_mode then return

long row
row = dw_buytask_list.GetRow()
if (row <= 0) then
	MessageBox('提示', '请选择需要发送的订单')
	return
end if

if (dw_buytask_list.Object.status[row] <> 0) then
	MessageBox('提示', '订单非待询价状态,不能发送')
	return
end if

string arg_msg
long taskid
taskid = dw_buytask_list.Object.taskid[row]

if (IsNull(taskid)) then return

FXAppCom.SendBuyTask(app_token_fx, taskid, ref arg_msg)
if (arg_msg <> '') then
	MessageBox('提示', '下单操作失败:~r~n' + arg_msg)
	return
end if

MessageBox('提示', '操作成功')
wf_retrieve_saletask( )
end event

