$PBExportHeader$w_cmpl_balc.srw forward global type w_cmpl_balc from window end type type st_4 from statictext within w_cmpl_balc end type type sle_balcdateint_next from singlelineedit within w_cmpl_balc end type type st_3 from statictext within w_cmpl_balc end type type st_2 from statictext within w_cmpl_balc end type type st_1 from statictext within w_cmpl_balc end type type sle_balcdateint from singlelineedit within w_cmpl_balc end type type sle_storageid from singlelineedit within w_cmpl_balc end type type cb_1 from commandbutton within w_cmpl_balc end type end forward global type w_cmpl_balc from window integer width = 1797 integer height = 964 boolean titlebar = true string title = "Untitled" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true st_4 st_4 sle_balcdateint_next sle_balcdateint_next st_3 st_3 st_2 st_2 st_1 st_1 sle_balcdateint sle_balcdateint sle_storageid sle_storageid cb_1 cb_1 end type global w_cmpl_balc w_cmpl_balc on w_cmpl_balc.create this.st_4=create st_4 this.sle_balcdateint_next=create sle_balcdateint_next this.st_3=create st_3 this.st_2=create st_2 this.st_1=create st_1 this.sle_balcdateint=create sle_balcdateint this.sle_storageid=create sle_storageid this.cb_1=create cb_1 this.Control[]={this.st_4,& this.sle_balcdateint_next,& this.st_3,& this.st_2,& this.st_1,& this.sle_balcdateint,& this.sle_storageid,& this.cb_1} end on on w_cmpl_balc.destroy destroy(this.st_4) destroy(this.sle_balcdateint_next) destroy(this.st_3) destroy(this.st_2) destroy(this.st_1) destroy(this.sle_balcdateint) destroy(this.sle_storageid) destroy(this.cb_1) end on type st_4 from statictext within w_cmpl_balc integer x = 155 integer y = 412 integer width = 457 integer height = 72 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "下月结存日" boolean focusrectangle = false end type type sle_balcdateint_next from singlelineedit within w_cmpl_balc integer x = 640 integer y = 376 integer width = 457 integer height = 128 integer taborder = 30 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type st_3 from statictext within w_cmpl_balc integer x = 155 integer y = 272 integer width = 457 integer height = 72 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "本月结存日" boolean focusrectangle = false end type type st_2 from statictext within w_cmpl_balc integer x = 155 integer y = 128 integer width = 457 integer height = 72 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "仓库ID" boolean focusrectangle = false end type type st_1 from statictext within w_cmpl_balc integer x = 46 integer y = 544 integer width = 873 integer height = 72 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 67108864 string text = "none" boolean focusrectangle = false end type type sle_balcdateint from singlelineedit within w_cmpl_balc integer x = 640 integer y = 240 integer width = 457 integer height = 128 integer taborder = 20 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type sle_storageid from singlelineedit within w_cmpl_balc integer x = 640 integer y = 104 integer width = 457 integer height = 128 integer taborder = 10 integer textsize = -12 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 string text = "11" borderstyle borderstyle = stylelowered! end type type cb_1 from commandbutton within w_cmpl_balc integer x = 1207 integer y = 72 integer width = 494 integer height = 104 integer taborder = 10 integer textsize = -9 integer weight = 400 fontcharset fontcharset = gb2312charset! fontpitch fontpitch = variable! string facename = "宋体" string text = "计算结存" end type event clicked;Int rslt = 1 String ls_msg Long ll_storageid Long ll_balcdateint,ll_balcdateint_next datetime ldt_balcdate ll_storageid = Long(sle_storageid.Text) ll_balcdateint = Long(sle_balcdateint.Text) ll_balcdateint_next = Long(sle_balcdateint_next.Text) ldt_balcdate = datetime(date(mid(sle_balcdateint.Text,1,4)+'-'+mid(sle_balcdateint.Text,5,2)+'-'+right(sle_balcdateint.Text,2)),time('23:59:59')) messagebox('',string(ldt_balcdate)) DELETE FROM u_warebalc WHERE balcdateint = :ll_balcdateint AND storageid = :ll_storageid; IF sqlca.SQLCode <> 0 THEN ls_msg = '删除结存失败,'+sqlca.SQLErrText rslt = 0 GOTO ext END IF IF ll_balcdateint = 0 THEN INSERT INTO u_warebalc (balcdateint, mtrlid, storageid, status, woodcode, pcode, balcqty, balcamt, scid ) SELECT :ll_balcdateint, mtrlid, u_mtrlware.storageid, status, woodcode, pcode, sum(noallocqty), sum(wareamt), u_storage.scid FROM u_mtrlware inner join u_storage on u_mtrlware.storageid = u_storage.storageid WHERE u_mtrlware.storageid = :ll_storageid GROUP BY mtrlid, u_mtrlware.storageid, status, woodcode, pcode, u_storage.scid ; IF sqlca.SQLCode <> 0 THEN ls_msg = '库存->结存失败,'+sqlca.SQLErrText rslt = 0 GOTO ext END IF ELSE INSERT INTO u_warebalc (balcdateint, balcdate, mtrlid, storageid, status, woodcode, pcode, balcqty, balcamt, scid ) SELECT :ll_balcdateint, :ldt_balcdate, mtrlid, u_warebalc.storageid, status, woodcode, pcode, bgqty, bgamt, u_warebalc.scid FROM u_warebalc WHERE u_warebalc.storageid = :ll_storageid and u_warebalc.balcdateint = :ll_balcdateint_next; IF sqlca.SQLCode <> 0 THEN ls_msg = '结存->结存失败,'+sqlca.SQLErrText rslt = 0 GOTO ext END IF END IF COMMIT; Long ll_i,ll_count Long ll_mtrlid String ls_status,ls_woodcode,ls_pcode Decimal ld_balcqty,ld_balcamt Decimal ld_inqty,ld_inamt Decimal ld_decqty,ld_decamt Decimal ld_bgqty,ld_bgamt long ll_sptid datastore ds ds = CREATE datastore ds.DataObject = 'ds_balc' ds.SetTransObject(sqlca) ll_count = ds.Retrieve(ll_storageid,ll_balcdateint) MessageBox('',ll_count) FOR ll_i = 1 TO ll_count st_1.Text = String(ll_i)+'/'+String(ll_count) ll_mtrlid = ds.Object.mtrlid[ll_i] ls_status = ds.Object.status[ll_i] ls_woodcode = ds.Object.woodcode[ll_i] ls_pcode = ds.Object.pcode[ll_i] ld_balcqty = ds.Object.balcqty[ll_i] ld_balcamt = ds.Object.balcamt[ll_i] SELECT isnull(sum(qty),0),isnull(sum(round(cost * qty,2)),0) INTO :ld_inqty,:ld_inamt FROM u_inware,u_inwaremx WHERE u_inware.inwareid = u_inwaremx.inwareid AND u_inwaremx.mtrlid = :ll_mtrlid AND u_inwaremx.status = :ls_status AND u_inwaremx.woodcode = :ls_woodcode AND u_inwaremx.pcode = :ls_pcode AND u_inware.storageid = :ll_storageid AND u_inware.balcdateint = :ll_balcdateint AND u_inware.flag = 1; IF sqlca.SQLCode <> 0 THEN ls_msg = '进仓失败,'+sqlca.SQLErrText rslt = 0 GOTO ext END IF SELECT isnull(sum(qty),0),isnull(sum(costamt),0) INTO :ld_decqty,:ld_decamt FROM u_outware,u_outwaremx WHERE u_outware.outwareid = u_outwaremx.outwareid AND u_outwaremx.mtrlid = :ll_mtrlid AND u_outwaremx.status = :ls_status AND u_outwaremx.woodcode = :ls_woodcode AND u_outwaremx.pcode = :ls_pcode AND u_outware.storageid = :ll_storageid AND u_outware.balcdateint = :ll_balcdateint AND u_outware.flag = 1; IF sqlca.SQLCode <> 0 THEN ls_msg = '出仓失败,'+sqlca.SQLErrText rslt = 0 GOTO ext END IF ld_bgqty = ld_balcqty + ld_decqty - ld_inqty ld_bgamt = ld_balcamt + ld_decamt - ld_inamt UPDATE u_warebalc SET bgqty = :ld_bgqty, bgamt = :ld_bgamt, incqty = :ld_inqty, incamt = :ld_inamt, desqty = :ld_decqty, desamt = :ld_decamt WHERE balcdateint = :ll_balcdateint AND mtrlid = :ll_mtrlid AND storageid = :ll_storageid AND status = :ls_status and woodcode = :ls_woodcode and pcode = :ls_pcode; IF sqlca.SQLCode <> 0 THEN ls_msg = 'u结存失败,'+sqlca.SQLErrText rslt = 0 GOTO ext END IF NEXT ls_msg = 'ok' ext: IF rslt = 0 THEN ROLLBACK; ELSE COMMIT; END IF MessageBox('',ls_msg) end event