$PBExportHeader$uo_ddlb_scid.sru
forward
global type uo_ddlb_scid from dropdownlistbox
end type
end forward

global type uo_ddlb_scid from dropdownlistbox
integer width = 247
integer height = 228
integer taborder = 10
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
boolean sorted = false
boolean vscrollbar = true
borderstyle borderstyle = stylelowered!
end type
global uo_ddlb_scid uo_ddlb_scid

type variables
long uo_scid
long uo_scid_arr[]

end variables

forward prototypes
public function integer p_update_mtrlware (long arg_mtrlid, string arg_mtrlcode, long arg_storageid, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_addqty, decimal arg_price, decimal arg_planprice, long arg_sptid, integer arg_dxflag, string arg_woodcode, string arg_pcode, ref string arg_msg, string arg_waredscrp, datetime arg_inworkdate, decimal dftsptprice, decimal bootqty)
end prototypes

public function integer p_update_mtrlware (long arg_mtrlid, string arg_mtrlcode, long arg_storageid, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_addqty, decimal arg_price, decimal arg_planprice, long arg_sptid, integer arg_dxflag, string arg_woodcode, string arg_pcode, ref string arg_msg, string arg_waredscrp, datetime arg_inworkdate, decimal dftsptprice, decimal bootqty);Int rslt = 1
//Long ls_newid
//String or_err_part
//Decimal ld_cost
////-------------------------------------------更新库存
////仓库调拨单，拆装单生成的进出仓单不更新库存表的最近进出时间 090925
//IF billtype = 12 OR billtype = 15 THEN
//	UPDATE u_mtrlware
//		SET noallocqty = noallocqty + :arg_qty ,
//		noallocaddqty = noallocaddqty + :arg_addqty ,
//		wareamt = wareamt + round(:arg_qty * :arg_price,2),
//		newprice = :arg_price,
//		cost = case noallocqty + :arg_qty when 0 then cost else round((wareamt + round(:arg_qty * :arg_price,10)) / ( noallocqty + :arg_qty ),:sys_option_cost_dec) END
//		WHERE ( mtrlid = :arg_mtrlid ) AND
//		( plancode = :arg_plancode ) AND
//		( storageid = :arg_storageid ) AND
//		( scid = :scid ) AND
//		( status = :arg_status ) AND
//		( sptid = :arg_sptid) AND
//		( dxflag = :arg_dxflag) AND
//		( woodcode = :arg_woodcode) AND
//		( pcode = :arg_pcode) USING commit_transaction  ;
//		
//ELSE
//	UPDATE u_mtrlware
//		SET noallocqty = noallocqty + :arg_qty ,
//		noallocaddqty = noallocaddqty + :arg_addqty ,
//		wareamt = wareamt + Round(:arg_qty * :arg_price,2),
//		waredate = getdate(),
//		newprice = :arg_price,
//		cost = CASE noallocqty + :arg_qty when 0 THEN cost ELSE Round((wareamt + Round(:arg_qty * :arg_price,10)) / ( noallocqty + :arg_qty ),:sys_option_cost_dec) END,
//		waredscrp = :arg_waredscrp,
//		inworkdate = :arg_inworkdate
//		WHERE ( mtrlid = :arg_mtrlid ) AND
//		( plancode = :arg_plancode ) AND
//		( storageid = :arg_storageid ) AND
//		( scid = :scid ) AND
//		( status = :arg_status ) AND
//		( sptid = :arg_sptid) AND
//		( dxflag = :arg_dxflag) AND
//		( woodcode = :arg_woodcode) AND
//		( pcode = :arg_pcode) USING commit_transaction  ;
//		
//END IF
//
//
//
//IF commit_transaction.SQLCode = 0 THEN
//	IF commit_transaction.SQLNRows = 0 THEN
//		///////////////////////////
//		ls_newid = f_sys_scidentity(scid,"u_mtrlware","mtrlwareid",arg_msg,FALSE,commit_transaction)
//		IF ls_newid <= 0 THEN
//			rslt = 0
//			GOTO ext
//		END IF
//		///////////////////////////
//		ld_cost = Round(arg_price,sys_option_cost_dec)
//		INSERT INTO u_mtrlware
//			( scid,
//			mtrlwareid,
//			mtrlid,
//			storageid,
//			plancode,
//			status,
//			noallocqty,
//			noallocaddqty,
//			allocqty,
//			wareamt,
//			planprice,
//			sptid,
//			dxflag,
//			woodcode,
//			pcode,
//			cost,
//			newprice,
//			waredscrp ,
//			inworkdate)
//			VALUES (
//			:scid,
//			:ls_newid,
//			:arg_mtrlid,
//			:arg_storageid,
//			:arg_plancode,
//			:arg_status,
//			:arg_qty,
//			:arg_addqty,
//			0,
//			round(:arg_price * :arg_qty,2),
//			:arg_planprice,
//			:arg_sptid,
//			:arg_dxflag,
//			:arg_woodcode,
//			:arg_pcode,
//			:ld_cost,
//			:arg_price,
//			:arg_waredscrp,
//			:arg_inworkdate) USING commit_transaction ;
//		IF commit_transaction.SQLCode <> 0 THEN
//			rslt = 0
//			arg_msg = "因网络或其它原因导致编码["+arg_mtrlcode+"]库存建立操作失败"+"~n"+commit_transaction.SQLErrText
//			GOTO ext
//		END IF
//		
//	END IF
//ELSE
//	or_err_part = 'create rule'
//	String ls_str
//	rslt = 0
//	IF commit_transaction.SQLCode = 513 OR Pos(Lower(commit_transaction.SQLErrText),or_err_part) > 0 THEN
//		ls_str = commit_transaction.SQLErrText
//		
//		IF Pos(Lower(commit_transaction.SQLErrText),"noallocqty") > 0 THEN
//			arg_msg = "编码["+arg_mtrlcode+"]同仓库内同批号没有足够的库存支持冲减"
//		ELSEIF Pos(Lower(commit_transaction.SQLErrText),"noallocaddqty") > 0 THEN
//			arg_msg = "编码["+arg_mtrlcode+"]同仓库内同批号没有足够的库存辅数支持冲减"
//		END IF
//	ELSE
//		arg_msg = "因网络或其它原因导致编码["+arg_mtrlcode+"]库存更新操作失败"+"~n"+commit_transaction.SQLErrText
//	END IF
//	GOTO ext
//END IF
//
////-----------------------------------更新结存
//Decimal ld_pypkqty,ld_pypkaddqty
//Decimal ld_buyinqty,ld_buyinamt,ld_buyinaddqty
//Decimal ld_cpinqty,ld_cpinamt,ld_cpinaddqty
//Decimal ld_jginqty,ld_jginamt,ld_jginaddqty
//Decimal ld_diinqty,ld_diinamt,ld_diinaddqty
//Decimal ld_mvinqty,ld_mvinamt,ld_mvinaddqty
//Decimal ld_otinqty,ld_otinamt,ld_otinaddqty
//Decimal ld_pyinqty,ld_pyinamt,ld_pyinaddqty
//Decimal ld_recinqty,ld_recinamt,ld_recinaddqty
//Decimal ld_recinqty_th,ld_recinamt_th,ld_recinaddqty_th
//
//CHOOSE CASE billtype
//	CASE 1
//		ld_buyinqty = arg_qty
//		ld_buyinaddqty = arg_addqty
//		ld_buyinamt = Round(arg_qty * arg_price,2)
//	CASE 3
//		ld_cpinqty = arg_qty
//		ld_cpinaddqty = arg_addqty
//		ld_cpinamt = Round(arg_qty * arg_price,2)
//	CASE 4
//		ld_jginqty = arg_qty
//		ld_jginaddqty = arg_addqty
//		ld_jginamt = Round(arg_qty * arg_price,2)
//	CASE 8
//		ld_otinqty = arg_qty
//		ld_otinaddqty = arg_addqty
//		ld_otinamt = Round(arg_qty * arg_price,2)
//	CASE 9
//		ld_pyinqty = arg_qty
//		ld_pyinaddqty = arg_addqty
//		ld_pyinamt = Round(arg_qty * arg_price,2)
//		ld_pypkqty = arg_qty
//		ld_pypkaddqty = arg_addqty
//	CASE 12
//		ld_mvinqty = arg_qty
//		ld_mvinaddqty = arg_addqty
//		ld_mvinamt = Round(arg_qty * arg_price,2)
//	CASE 15
//		ld_diinqty = arg_qty
//		ld_diinaddqty = arg_addqty
//		ld_diinamt = Round(arg_qty * arg_price,2)
//	CASE 20
//		IF thflag = 1 THEN
//			ld_recinqty_th = Abs(arg_qty)
//			ld_recinamt_th = Abs(Round(arg_qty * arg_price,2))
//			ld_recinaddqty_th = Abs(arg_addqty)
//			ld_recinqty = 0
//			ld_recinamt = 0
//			ld_recinaddqty = 0
//		ELSE
//			ld_recinqty = arg_qty
//			ld_recinaddqty = arg_addqty
//			ld_recinamt = Round(arg_qty * arg_price,2)
//			ld_recinqty_th = 0
//			ld_recinamt_th = 0
//			ld_recinaddqty_th = 0
//		END IF
//		
//END CHOOSE
//
//
//UPDATE u_warebalc
//	SET incqty = incqty + :arg_qty ,
//	incaddqty = incaddqty + :arg_addqty ,
//	incamt  = incamt + round(:arg_qty * :arg_price,2),
//	
//	balcqty = balcqty + :arg_qty,
//	balcaddqty = balcaddqty + :arg_addqty,
//	balcamt = balcamt + round(:arg_qty * :arg_price,2),
//	
//	pypk = pypk + :ld_pypkqty,
//	pypkaddqty = pypkaddqty + :ld_pypkaddqty,
//	
//	
//	buyinqty = buyinqty + :ld_buyinqty,
//	buyinaddqty = buyinaddqty + :ld_buyinaddqty,
//	buyinamt = buyinamt + :ld_buyinamt,
//	
//	cpinqty = cpinqty + :ld_cpinqty,
//	cpinaddqty = cpinaddqty + :ld_cpinaddqty,
//	cpinamt = cpinamt + :ld_cpinamt,
//	
//	jginqty = jginqty + :ld_jginqty,
//	jginaddqty = jginaddqty + :ld_jginaddqty,
//	jginamt = jginamt + :ld_jginamt,
//	
//	otinqty = otinqty + :ld_otinqty,
//	otinaddqty = otinaddqty + :ld_otinaddqty,
//	otinamt = otinamt + :ld_otinamt,
//	
//	mvinqty = mvinqty + :ld_mvinqty,
//	mvinaddqty = mvinaddqty + :ld_mvinaddqty,
//	mvinamt = mvinamt + :ld_mvinamt,
//	
//	diinqty = diinqty + :ld_diinqty,
//	diinaddqty = diinaddqty + :ld_diinaddqty,
//	diinamt = diinamt + :ld_diinamt,
//	
//	pyinqty = pyinqty + :ld_pyinqty,
//	pyinaddqty = pyinaddqty + :ld_pyinaddqty,
//	pyinamt = pyinamt + :ld_pyinamt,
//	
//	recinqty = recinqty+:ld_recinqty,
//	recinaddqty = recinaddqty+:ld_recinaddqty,
//	recinamt = recinamt+:ld_recinamt,
//	
//	recinqty_th = recinqty_th+:ld_recinqty_th,
//	recinaddqty_th = recinaddqty_th+:ld_recinaddqty_th,
//	recinamt_th = recinamt_th+:ld_recinamt_th
//	
//	WHERE ( mtrlid = :arg_mtrlid ) AND
//	( storageid = :arg_storageid ) AND
//	( balcdateint  = 0) AND
//	( status = :arg_status )  AND
//	(woodcode = :arg_woodcode) AND
//	(pcode = :arg_pcode)  AND
//	(sptid_cusid = :arg_sptid) USING commit_transaction  ;
//IF commit_transaction.SQLCode = 0 THEN
//	IF commit_transaction.SQLNRows = 0 THEN
//		INSERT INTO u_warebalc
//			( balcdateint,
//			sptid_cusid,
//			mtrlid,
//			storageid,
//			bgqty,
//			bgamt,
//			incqty,
//			incaddqty,
//			incamt,
//			desqty,
//			desaddqty,
//			desamt,
//			balcqty,
//			balcaddqty,
//			balcamt,
//			pypk,
//			pypkaddqty,
//			status,
//			woodcode,
//			pcode,
//			scid,
//			buyinqty,
//			buyinaddqty,
//			buyinamt,
//			cpinqty,
//			cpinaddqty,
//			cpinamt,
//			jginqty,
//			jginaddqty,
//			jginamt,
//			diinqty,
//			diinaddqty,
//			diinamt,
//			mvinqty,
//			mvinaddqty,
//			mvinamt,
//			otinqty,
//			otinaddqty,
//			otinamt,
//			pyinqty,
//			pyinaddqty,
//			pyinamt,
//			recinqty,
//			recinaddqty,
//			recinamt,
//			recinqty_th,
//			recinaddqty_th,
//			recinamt_th)
//			VALUES (
//			0,
//			:arg_sptid,
//			:arg_mtrlid,
//			:arg_storageid,
//			0,
//			0,
//			:arg_qty,
//			:arg_addqty,
//			round(:arg_qty * :arg_price,2),
//			0,
//			0,
//			0,
//			:arg_qty,
//			:arg_addqty,
//			round(:arg_qty * :arg_price,2),
//			:ld_pypkqty,
//			:ld_pypkaddqty,
//			:arg_status,
//			:arg_woodcode,
//			:arg_pcode,
//			:scid,
//			:ld_buyinqty,
//			:ld_buyinaddqty,
//			:ld_buyinamt,
//			:ld_cpinqty,
//			:ld_cpinaddqty,
//			:ld_cpinamt,
//			:ld_jginqty,
//			:ld_jginaddqty,
//			:ld_jginamt,
//			:ld_diinqty,
//			:ld_diinaddqty,
//			:ld_diinamt,
//			:ld_mvinqty,
//			:ld_mvinaddqty,
//			:ld_mvinamt,
//			:ld_otinqty,
//			:ld_otinaddqty,
//			:ld_otinamt,
//			:ld_pyinqty,
//			:ld_pyinaddqty,
//			:ld_pyinamt,
//			:ld_recinqty,
//			:ld_recinaddqty,
//			:ld_recinamt,
//			:ld_recinqty_th,
//			:ld_recinaddqty_th,
//			:ld_recinamt_th
//			) USING commit_transaction ;
//		IF commit_transaction.SQLCode <> 0 THEN
//			rslt = 0
//			arg_msg = "因网络或其它原因导致编码["+arg_mtrlcode+"]结存建立操作失败"+"~n"+commit_transaction.SQLErrText
//			GOTO ext
//		END IF
//	END IF
//ELSE
//	rslt = 0
//	or_err_part = 'create rule'
//	IF commit_transaction.SQLCode = 513 OR Pos(Lower(commit_transaction.SQLErrText),or_err_part) > 0 THEN
//		arg_msg = "编码["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减"
//	ELSE
//		arg_msg = "因网络或其它原因导致编码["+arg_mtrlcode+"]结存更新操作失败"+"~n"+commit_transaction.SQLErrText
//	END IF
//	GOTO ext
//END IF
//
//ext:
//IF rslt = 0 THEN
//	ROLLBACK;
//END IF
RETURN rslt





end function

event constructor;Long ls_scid
Long cnt = 0
String ls_scname
long ll_i
string ls_space
int li_spacenum

for ll_i =1 to upperbound(sys_user_scid)	
	ls_scid = sys_user_scid[ll_i]
	SELECT scname
	INTO :ls_scname
	FROM u_scdef
	Where scid = :ls_scid;
	if sqlca.sqlcode <> 0 or isnull(ls_scname) then ls_scname = ''
	
	li_spacenum = 50 - len(trim(ls_scname)) - 2 - len(string(ls_scid))
	ls_space = fill(' ',li_spacenum)
	
	THIS.AddItem (ls_scname+ls_space+'['+String(ls_scid)+']')
next

THIS.uo_scid = ls_scid
uo_scid_arr[1] = ls_scid
THIS.Text = ls_scname+ls_space+'['+String(ls_scid)+']'

SELECT count(*) INTO :cnt FROM u_scdef ;
IF cnt > 1 THEN
	THIS.AddItem ('[全部]')
END IF




end event

event selectionchanged;long ll_scid_arr[]

IF THIS.Text = '[全部]' THEN
	uo_scid = -1
	ll_scid_arr =sys_user_scid 
	uo_scid_arr = ll_scid_arr
ELSE
	uo_scid = Long(Mid ( THIS.Text,Pos(THIS.Text,'[') + 1,Len(THIS.Text) - Pos(THIS.Text,'[') - 1 ))
	ll_scid_arr[1] = uo_scid
	uo_scid_arr = ll_scid_arr
END IF


end event

on uo_ddlb_scid.create
end on

on uo_ddlb_scid.destroy
end on

