$PBExportHeader$w_login_fx.srw
$PBExportComments$分销系统门店客户端登陆窗口
forward
global type w_login_fx from window
end type
type st_5 from statictext within w_login_fx
end type
type cb_setting from uo_imflatbutton within w_login_fx
end type
type cb_2 from uo_imflatbutton within w_login_fx
end type
type cb_1 from uo_imflatbutton within w_login_fx
end type
type cbx_remember from checkbox within w_login_fx
end type
type cb_test from commandbutton within w_login_fx
end type
type em_port from editmask within w_login_fx
end type
type st_4 from statictext within w_login_fx
end type
type p_setting from picture within w_login_fx
end type
type st_3 from statictext within w_login_fx
end type
type p_1 from picture within w_login_fx
end type
type sle_1 from singlelineedit within w_login_fx
end type
type sle_2 from singlelineedit within w_login_fx
end type
type st_1 from statictext within w_login_fx
end type
type st_2 from statictext within w_login_fx
end type
type ln_1 from line within w_login_fx
end type
type sle_ip from singlelineedit within w_login_fx
end type
end forward

global type w_login_fx from window
integer width = 1842
integer height = 1180
boolean titlebar = true
string title = "用户登录"
boolean controlmenu = true
windowtype windowtype = response!
long backcolor = 16777215
string icon = "graphics\chain_link_128px.ico"
boolean center = true
event ue_setting ( )
st_5 st_5
cb_setting cb_setting
cb_2 cb_2
cb_1 cb_1
cbx_remember cbx_remember
cb_test cb_test
em_port em_port
st_4 st_4
p_setting p_setting
st_3 st_3
p_1 p_1
sle_1 sle_1
sle_2 sle_2
st_1 st_1
st_2 st_2
ln_1 ln_1
sle_ip sle_ip
end type
global w_login_fx w_login_fx

type variables
long ins_height_ori = 932
long ins_height_setting = 1096

end variables

forward prototypes
public function integer wf_add_setting ()
end prototypes

event ue_setting();if (cb_setting.Text = '︾') then // 展开
	this.Height = this.Height - this.workspaceheight( ) + ins_height_setting
	cb_setting.Text = '︽'
	
	sle_ip.Enabled = true
	p_setting.Enabled = true
	em_port.Enabled = true
	cb_test.Enabled = true
else // 隐藏
	this.Height = this.Height - this.workspaceheight( ) + ins_height_ori
	cb_setting.Text = '︾'
	
	sle_ip.Enabled = false
	p_setting.Enabled = false
	em_port.Enabled = false
	cb_test.Enabled = false
end if

cb_setting.of_init_draw()
cb_setting.of_paint()
cb_setting.TriggerEvent('ue_textchange')
end event

public function integer wf_add_setting ();int rslt = 1

long i
string temp_ip, temp_port, ip, port
boolean ifFound = false
ip = Trim(sle_ip.Text)
port = em_port.Text
for i = 1 to 9
	temp_ip = Trim(ProfileString(sys_fx_ini, 'server_' + string(i), 'ip', ''))
	temp_port = Trim(ProfileString(sys_fx_ini, 'server_' + string(i), 'port', ''))
	if (temp_ip = ip and temp_port = port) then
		ifFound = true
		exit
	end if
next

if (not ifFound) then
	for i = 1 to 9
		temp_ip = Trim(ProfileString(sys_fx_ini, 'server_' + string(i), 'ip', ''))
		if (temp_ip = '') then
			SetProfileString(sys_fx_ini, 'server_' + string(i), 'ip', ip)
			SetProfileString(sys_fx_ini, 'server_' + string(i), 'port', port)
			exit
		end if
	next
end if

return rslt
end function

on w_login_fx.create
this.st_5=create st_5
this.cb_setting=create cb_setting
this.cb_2=create cb_2
this.cb_1=create cb_1
this.cbx_remember=create cbx_remember
this.cb_test=create cb_test
this.em_port=create em_port
this.st_4=create st_4
this.p_setting=create p_setting
this.st_3=create st_3
this.p_1=create p_1
this.sle_1=create sle_1
this.sle_2=create sle_2
this.st_1=create st_1
this.st_2=create st_2
this.ln_1=create ln_1
this.sle_ip=create sle_ip
this.Control[]={this.st_5,&
this.cb_setting,&
this.cb_2,&
this.cb_1,&
this.cbx_remember,&
this.cb_test,&
this.em_port,&
this.st_4,&
this.p_setting,&
this.st_3,&
this.p_1,&
this.sle_1,&
this.sle_2,&
this.st_1,&
this.st_2,&
this.ln_1,&
this.sle_ip}
end on

on w_login_fx.destroy
destroy(this.st_5)
destroy(this.cb_setting)
destroy(this.cb_2)
destroy(this.cb_1)
destroy(this.cbx_remember)
destroy(this.cb_test)
destroy(this.em_port)
destroy(this.st_4)
destroy(this.p_setting)
destroy(this.st_3)
destroy(this.p_1)
destroy(this.sle_1)
destroy(this.sle_2)
destroy(this.st_1)
destroy(this.st_2)
destroy(this.ln_1)
destroy(this.sle_ip)
end on

event open;this.post event ue_setting()

string ip
long port
ip = ProfileString('fx_server.ini', 'server', 'ip', '223.4.178.191')
port = ProfileInt('fx_server.ini', 'server', 'port', 30040)

sle_ip.Text = ip
em_port.Text = string(port)

long ifRemember
ifRemember = ProfileInt(sys_fx_ini, 'myfxinfo', 'remember', 0)
if (ifRemember = 1) then
	cbx_remember.Checked = true
	sle_1.Text = Trim(ProfileString(sys_fx_ini, 'myfxinfo', 'lastname', ''))
	if (sle_1.Text <> '') then
		sle_2.SetFocus()
	end if
else
	cbx_remember.Checked = false
end if
end event

type st_5 from statictext within w_login_fx
integer x = 1477
integer y = 552
integer width = 247
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
boolean underline = true
string pointer = "HyperLink!"
long textcolor = 134217856
long backcolor = 16777215
string text = "注册企业"
end type

event clicked;Open(w_fx_regcompany)
end event

type cb_setting from uo_imflatbutton within w_login_fx
integer x = 1669
integer y = 768
integer width = 101
integer height = 96
integer taborder = 30
string text = "︽"
end type

event clicked;call super::clicked;parent.post event ue_setting()
end event

type cb_2 from uo_imflatbutton within w_login_fx
integer x = 1074
integer y = 768
integer width = 357
integer height = 96
integer taborder = 40
string text = "退出"
end type

event clicked;call super::clicked;if (not cbx_remember.Checked) then
	SetProfileString(sys_fx_ini, 'myfxinfo', 'lastname', '')
end if

close(parent)
end event

type cb_1 from uo_imflatbutton within w_login_fx
integer x = 507
integer y = 768
integer width = 357
integer height = 96
integer taborder = 40
string text = "登录"
end type

event clicked;call super::clicked;Int rslt = 1
String arg_msg
long ll_iferpuser

IF Trim(sle_1.Text) = '' THEN
	rslt = 0
	arg_Msg = '请输入用户名'
	sle_1.SetFocus()
	GOTO ext
END IF

IF Trim(sle_2.Text) = '' THEN
	rslt = 0
	arg_Msg = '请输入密码'
	sle_2.SetFocus()
	GOTO ext
END IF

oleobject obj, pwrList, item, request

request = FXAppCom.CreatePbDictionary()
request.SetString('usercode', sle_1.Text)
request.SetString('psw', sle_2.Text)

obj = FXAppCom.DoExecute('Login', request)
arg_msg = obj.GetString('ErrMsg')

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

app_token_fx = obj.GetString('token')
app_username = obj.GetString('username')
app_tele = obj.GetString('usertele')
app_address = obj.GetString('address')
app_freight = obj.GetString('freight')
app_freight_tele = obj.GetString('freight_tele')
app_comname = obj.GetString('comname')
app_comtele = obj.GetString('comtele')
//app_myrelcode = obj.GetString('relcode')
//app_relationtype = obj.GetInt('relationtype')
app_usertype = obj.GetInt('usertype') // 1-采购人员 2-销售人员 3-管理人员
app_fx_title_erp = obj.GetString('fx_title_erp')
ll_iferpuser = obj.GetInt('ifERPUser')

if (not IsNull(obj.GetInt('interval'))) then
	if (obj.GetInt('interval') >= 20) then // 刷新频率大于20秒保护
		app_retrieve_interval = obj.GetInt('interval')
	end if
end if

pwrList = obj.GetArrOfPBDictionary('PwrList')

// sys_func_pwr 存放当前用户的权限树
sys_func_pwr = create datastore
sys_func_pwr.DataObject = 'ds_menu_fx'
sys_func_pwr.Reset()
// 协同系统全部权限的权限树
sys_func_all = create datastore
sys_func_all.DataObject = 'ds_menu_fx'
sys_func_all.RowsCopy(1, sys_func_all.RowCount(), Primary!, sys_func_pwr, 1, Primary!)
//long i, row, funcid
//for i = 1 to pwrList.Count
//	item = pwrList.GetItem(i - 1)
//	
//	funcid = item.GetInt('funcid')
//	row = sys_func_all.Find('funcid = ' + string(funcid), 1, sys_func_all.RowCount())
//	if (row > 0) then
//		sys_func_all.RowsCopy(row, row, Primary!, sys_func_pwr, 1, Primary!)
//	end if
//next

ext:
IF rslt = 1 THEN
	parent.Hide()
	//open(w_main_fx)
	// 记录用户名
	if (cbx_remember.Checked) then
		SetProfileString(sys_fx_ini, 'myfxinfo', 'lastname', sle_1.Text)
	else
		SetProfileString(sys_fx_ini, 'myfxinfo', 'lastname', '')
	end if
	// 自动升级界面
	app_iferpuser = ll_iferpuser
	IF ll_iferpuser = 1 THEN 
		Open(w_company_choose)
		long ll_comid = 0
		ll_comid = Message.DoubleParm	
		If (NOT ISNULL(ll_comid) AND ll_comid <> 0) THEN
			//DONE:切换用户	
			oleobject req,rsp

			req = FXAppCom.CreatePbDictionary()
			req.SetString('token', app_token_fx)
			req.SetInt('comid', ll_comid)
			
			rsp = FXAppCom.DoExecute('SwitchOperatingCompany', req)
			arg_msg = rsp.GetString('ErrMsg')
			
			if (arg_msg <> '') then
				rslt = 0
				goto ext
			end if
			
			Open(w_fx_welcome)
		END IF
	ELSE
		Open(w_fx_welcome)
	END IF

ELSE
	if (Pos(Lower(arg_msg), 'system.net.sockets.socketexception') > 0) then
		MessageBox('提示', '出现网络异常问题，详细信息：~r~n~r~n' + arg_msg)
	else
		MessageBox('登陆失败', arg_msg)
	end if
END IF



end event

type cbx_remember from checkbox within w_login_fx
integer x = 507
integer y = 644
integer width = 357
integer height = 60
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "记住用户名"
end type

event clicked;if (this.Checked) then
	SetProfileString(sys_fx_ini, 'myfxinfo', 'remember', '1')
else
	SetProfileString(sys_fx_ini, 'myfxinfo', 'remember', '0')
end if
end event

type cb_test from commandbutton within w_login_fx
integer x = 1344
integer y = 976
integer width = 288
integer height = 84
integer taborder = 100
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string text = "测试连接"
end type

event clicked;SetProfileString(sys_fx_ini, 'server', 'ip', Trim(sle_ip.Text))
SetProfileString(sys_fx_ini, 'server', 'port', em_port.Text)

string arg_msg
if (f_init_fxappcom() = 1) then
	FXAppCom.TextServerConnection(ref arg_msg)
	if (arg_msg = '') then
		MessageBox('提示', '连接成功')
		wf_add_setting()
		parent.post event ue_setting()
	else
		MessageBox('提示', '连接失败，详细信息：~r~n~r~n' + arg_msg)
	end if
end if
end event

type em_port from editmask within w_login_fx
integer x = 1129
integer y = 976
integer width = 192
integer height = 84
integer taborder = 90
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "30040"
borderstyle borderstyle = stylelowered!
string mask = "#####"
end type

event getfocus;this.SelectText(1, Len(this.Text))
end event

type st_4 from statictext within w_login_fx
integer x = 992
integer y = 992
integer width = 151
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "端口:"
boolean focusrectangle = false
end type

type p_setting from picture within w_login_fx
integer x = 882
integer y = 988
integer width = 73
integer height = 64
integer taborder = 80
string pointer = "HAND.CUR"
boolean originalsize = true
string picturename = "VCRNext!"
boolean focusrectangle = false
string powertiptext = "设置"
end type

event clicked;s_fx_ip_setting s_tran, s_ret
s_tran.x = parent.X + sle_ip.X
s_tran.y = parent.Y + sle_ip.Y + sle_ip.Height + 110
OpenWithParm(w_fx_ip_setting, s_tran)
s_ret = Message.PowerObjectParm
if (not IsNull(s_ret)) then
	if (IsValid(s_ret)) then
		if (s_ret.ip <> '') then
			sle_ip.Text = s_ret.ip
			em_port.Text = string(s_ret.port)
			cb_test.post event clicked()
		end if
	end if
end if
end event

type st_3 from statictext within w_login_fx
integer x = 197
integer y = 992
integer width = 261
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "服务器IP:"
boolean focusrectangle = false
end type

type p_1 from picture within w_login_fx
integer width = 1829
integer height = 284
boolean originalsize = true
string picturename = "graphics\scclogin.jpg"
boolean focusrectangle = false
end type

type sle_1 from singlelineedit within w_login_fx
event ue_dwnkey pbm_keydown
integer x = 503
integer y = 364
integer width = 919
integer height = 84
integer taborder = 10
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

event ue_dwnkey;if keydown(keyenter!) then
	sle_2.SetFocus()
end if
end event

type sle_2 from singlelineedit within w_login_fx
event ue_dwnkey pbm_keydown
integer x = 507
integer y = 528
integer width = 919
integer height = 84
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
boolean password = true
borderstyle borderstyle = stylelowered!
end type

event ue_dwnkey;if keydown(keyenter!) then
	cb_1.TriggerEvent(clicked!)
end if
end event

type st_1 from statictext within w_login_fx
integer x = 256
integer y = 380
integer width = 224
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "用户名"
alignment alignment = right!
boolean focusrectangle = false
end type

type st_2 from statictext within w_login_fx
integer x = 242
integer y = 540
integer width = 238
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 16777215
string text = "密  码"
alignment alignment = right!
boolean focusrectangle = false
end type

type ln_1 from line within w_login_fx
long linecolor = 12632256
integer linethickness = 4
integer beginy = 932
integer endx = 1829
integer endy = 932
end type

type sle_ip from singlelineedit within w_login_fx
integer x = 434
integer y = 976
integer width = 439
integer height = 84
integer taborder = 70
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "255.255.255.255"
borderstyle borderstyle = stylelowered!
end type

event getfocus;this.SelectText(1, Len(this.Text))
end event

