$PBExportHeader$w_report_style_edit.srw
forward
global type w_report_style_edit from w_publ_base
end type
type sle_name from singlelineedit within w_report_style_edit
end type
type st_1 from statictext within w_report_style_edit
end type
type cbx_ifshare from checkbox within w_report_style_edit
end type
type cb_1 from uo_imflatbutton within w_report_style_edit
end type
end forward

global type w_report_style_edit from w_publ_base
integer width = 1710
integer height = 516
string title = "报表解决方案"
boolean minbox = false
windowtype windowtype = response!
sle_name sle_name
st_1 st_1
cbx_ifshare cbx_ifshare
cb_1 cb_1
end type
global w_report_style_edit w_report_style_edit

type variables
long ins_empid
string ins_dwname,ins_stylename
long ins_ifshare
long ins_edittype = 0 // 0 - 新建 1 - 修改
string ins_dwnSyntax_sort,ins_dwnSyntax_filter
string ins_dwnSyntax_layout_column_visible
string ins_dwnSyntax_layout_column_width
string ins_dwnSyntax_layout_column_x
end variables

on w_report_style_edit.create
int iCurrent
call super::create
this.sle_name=create sle_name
this.st_1=create st_1
this.cbx_ifshare=create cbx_ifshare
this.cb_1=create cb_1
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.sle_name
this.Control[iCurrent+2]=this.st_1
this.Control[iCurrent+3]=this.cbx_ifshare
this.Control[iCurrent+4]=this.cb_1
end on

on w_report_style_edit.destroy
call super::destroy
destroy(this.sle_name)
destroy(this.st_1)
destroy(this.cbx_ifshare)
destroy(this.cb_1)
end on

event open;call super::open;s_user_report_style s_style

s_style = Message.PowerObjectParm

ins_empid = s_style.empid
ins_dwname = s_style.dwname
ins_stylename = s_style.stylename
ins_ifshare = s_style.ifshare
ins_edittype = s_style.edittype
ins_dwnSyntax_sort = s_style.sort
ins_dwnSyntax_filter = s_style.filter
ins_dwnSyntax_layout_column_visible = s_style.visible
ins_dwnSyntax_layout_column_width = s_style.width
ins_dwnSyntax_layout_column_x = s_style.column_x

IF ins_edittype = 1 THEN
	sle_name.Text = ins_stylename
	
	IF ins_ifshare = 0 THEN
		cbx_ifshare.Checked = FALSE
	ELSE
		cbx_ifshare.Checked = TRUE
	END IF
END IF

end event

type cb_func from w_publ_base`cb_func within w_report_style_edit
boolean visible = false
integer taborder = 30
end type

type cb_exit from w_publ_base`cb_exit within w_report_style_edit
integer x = 1065
integer y = 256
integer taborder = 50
end type

type sle_name from singlelineedit within w_report_style_edit
integer x = 375
integer y = 48
integer width = 1285
integer height = 84
integer taborder = 10
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type st_1 from statictext within w_report_style_edit
integer x = 23
integer y = 68
integer width = 334
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 = 134217739
string text = "查询方案名称"
alignment alignment = right!
boolean focusrectangle = false
end type

type cbx_ifshare from checkbox within w_report_style_edit
integer x = 229
integer y = 160
integer width = 201
integer height = 60
integer taborder = 20
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 134217739
string text = "公共"
boolean lefttext = true
end type

type cb_1 from uo_imflatbutton within w_report_style_edit
integer x = 361
integer y = 256
integer width = 311
integer height = 96
integer taborder = 40
boolean bringtotop = true
end type

event clicked;call super::clicked;String ls_stylename
Int li_ifshare
Long cnt

ls_stylename = Trim(sle_name.Text)

IF ls_stylename = '' THEN
	MessageBox('系统提示','请先填写查询方案名称')
	sle_name.SetFocus()
	RETURN
END IF

IF cbx_ifshare.Checked THEN
	li_ifshare = 1
ELSE
	li_ifshare = 0
END IF

SELECT count(*) INTO :cnt
	FROM u_user_report_style
	WHERE empid = :ins_empid
	AND dwname = :ins_dwname
	AND stylename = :ls_stylename;
IF sqlca.SQLCode <> 0 THEN
	MessageBox('Error','查询操作失败,'+sqlca.SQLErrText)
	RETURN
END IF

IF cnt > 0 THEN
	
	IF ls_stylename <> ins_stylename THEN
		IF MessageBox('询问','查询方案:'+ls_stylename+' 已存在,是否确认要覆盖原有的方案?',question!,yesno!) = 2 THEN RETURN
	END IF
	
END IF

IF ins_edittype = 1 THEN
	IF cnt > 0 THEN
		DELETE FROM u_user_report_style
			WHERE empid = :ins_empid
			AND dwname = :ins_dwname
			AND stylename = :ls_stylename;
		IF sqlca.SQLCode <> 0 THEN
			ROLLBACK;
			MessageBox('Error','删除原方案操作失败,'+sqlca.SQLErrText)
			RETURN
		END IF
		
		UPDATE u_user_report_style
			SET stylename = :ls_stylename,
			ifshare = :li_ifshare
			WHERE empid = :ins_empid
			AND dwname = :ins_dwname
			AND stylename = :ins_stylename;
		IF sqlca.SQLCode <> 0 THEN
			ROLLBACK;
			MessageBox('Error','更新操作失败,'+sqlca.SQLErrText)
			RETURN
		END IF
	ELSE
		UPDATE u_user_report_style
			SET stylename = :ls_stylename,
			ifshare = :li_ifshare
			WHERE empid = :ins_empid
			AND dwname = :ins_dwname
			AND stylename = :ins_stylename;
		IF sqlca.SQLCode <> 0 THEN
			ROLLBACK;
			MessageBox('Error','更新操作失败,'+sqlca.SQLErrText)
			RETURN
		END IF
	END IF
	
ELSE
	IF cnt > 0 THEN
		UPDATE u_user_report_style
			SET ifshare = :li_ifshare,
			dwnSyntax_filter = :ins_dwnSyntax_filter,
			dwnSyntax_sort = :ins_dwnSyntax_sort,
			dwnSyntax_layout_column_visible = :ins_dwnSyntax_layout_column_visible,
			dwnSyntax_layout_column_width = :ins_dwnSyntax_layout_column_width,
			dwnSyntax_layout_column_x = :ins_dwnSyntax_layout_column_x
			WHERE empid = :ins_empid
			AND dwname = :ins_dwname
			AND stylename = :ls_stylename;
		IF sqlca.SQLCode <> 0 THEN
			ROLLBACK;
			MessageBox('Error','更新操作失败,'+sqlca.SQLErrText)
			RETURN
		END IF
	ELSE
		INSERT INTO u_user_report_style
			(empid,
			dwname,
			stylename,
			ifshare,
			dwnSyntax_filter,
			dwnSyntax_sort,
			dwnSyntax_layout_column_visible,
			dwnSyntax_layout_column_width,
			dwnSyntax_layout_column_x)
			VALUES
			(:ins_empid,
			:ins_dwname,
			:ls_stylename,
			:li_ifshare,
			:ins_dwnSyntax_filter,
			:ins_dwnSyntax_sort,
			:ins_dwnSyntax_layout_column_visible,
			:ins_dwnSyntax_layout_column_width,
			:ins_dwnSyntax_layout_column_x);
		IF sqlca.SQLCode <> 0 THEN
			ROLLBACK;
			MessageBox('Error','插入操作失败,'+sqlca.SQLErrText)
			RETURN
		END IF
	END IF
END IF

COMMIT;
MessageBox('系统提示','操作成功!')
Close(PARENT)







end event

