$PBExportHeader$w_ljmail_send_fx.srw
$PBExportComments$(协同)发送邮件
forward
global type w_ljmail_send_fx from w_publ_base_style
end type
type uo_1 from uo_html_editor within w_ljmail_send_fx
end type
type st_1 from statictext within w_ljmail_send_fx
end type
type sle_contact from singlelineedit within w_ljmail_send_fx
end type
type pb_contact from picturebutton within w_ljmail_send_fx
end type
type st_2 from statictext within w_ljmail_send_fx
end type
type sle_subject from singlelineedit within w_ljmail_send_fx
end type
type cb_send from uo_imflatbutton within w_ljmail_send_fx
end type
type cb_save from uo_imflatbutton within w_ljmail_send_fx
end type
end forward

global type w_ljmail_send_fx from w_publ_base_style
integer width = 4037
integer height = 2404
string title = "发送邮件"
boolean maxbox = true
boolean resizable = true
long backcolor = 16777215
string icon = "graphics\chain_link_128px.ico"
uo_1 uo_1
st_1 st_1
sle_contact sle_contact
pb_contact pb_contact
st_2 st_2
sle_subject sle_subject
cb_send cb_send
cb_save cb_save
end type
global w_ljmail_send_fx w_ljmail_send_fx

type variables
s_fx_ljmail_contact ins_contacts // 收件人信息

long ins_msgid
end variables

forward prototypes
public function integer wf_chk ()
public function integer wf_save ()
public function integer wf_send ()
public function integer wf_get_contact (long arg_commid, string arg_ljmail)
end prototypes

public function integer wf_chk ();// 发送前检查(保存不需要检查)
int rslt = 1

string msg
if UpperBound(ins_contacts.revljmail) <= 0 then
	rslt = 0
	msg += '请选择收件人~r~n'
end if

if (Trim(sle_subject.Text) = '') then
	rslt = 0
	msg += '请填写主题~r~n'
end if

if (Trim(uo_1.uf_gethtml()) = '') then
	rslt = 0
	msg += '请填写正文内容~r~n'
end if

if (rslt = 0) then
	MessageBox('提示', msg)
end if
return rslt
end function

public function integer wf_save ();int rslt = 1

oleobject mxs, mxItem
mxs = FXAppCom.CreArrOfPbDictionary()
long i
for i = 1 to UpperBound(ins_contacts.revljmail)
	mxItem = FXAppCom.CreatePbDictionary()
	
	mxItem.SetString('comname', ins_contacts.revname[i])
	mxItem.SetString('empid', ins_contacts.revempid[i])
	mxItem.SetString('empname', ins_contacts.revname[i])
	mxItem.SetString('reltype', ins_contacts.reltype[i])
	mxItem.SetString('relid', 0)
	mxItem.SetString('ljmail', ins_contacts.revljmail[i])
	
	mxs.Add(mxItem)
next

oleobject msg
msg = FXAppCom.CreatePbDictionary()
msg.SetInt('msgid', ins_msgid)
msg.SetString('subject', Trim(sle_subject.Text))
msg.SetString('htmlbody', Trim(uo_1.uf_gethtml()))

string arg_msg
long msgid
msgid = FXAppCom.AddLjmail(app_token_fx, msg, mxs, ref arg_msg)
if (arg_msg <> '' or msgid <= 0) then
	rslt = 0
	MessageBox('提示', '保存操作失败~r~n' + arg_msg)
else
	ins_msgid = msgid
end if

return rslt
end function

public function integer wf_send ();int rslt = 1

if (wf_chk() <> 1) then
	rslt = 0
	goto ext
end if

if (wf_save() <> 1) then
	rslt = 0
	goto ext
end if

if (ins_msgid <= 0) then
	rslt = 0
	MessageBox('提示', '请先进行保存操作')
	goto ext
end if

string arg_msg
FXAppCom.SendLjmail(app_token_fx, ins_msgid, ref arg_msg)
if (arg_msg <> '') then
	rslt = 0
	MessageBox('提示', '发送失败:' + arg_msg)
else
	MessageBox('提示', '发送成功')
end if

ext:
return rslt
end function

public function integer wf_get_contact (long arg_commid, string arg_ljmail);// 使用回复邮件功能
// 传入发件人在本地邮件服务的CusCommID和发件人龙嘉邮箱地址
int rslt = 1

string arg_msg
oleobject obj, parm
parm = FXAppCom.CreatePbDictionary()
parm.SetInt('Commid', arg_commid)
parm.SetString('Ljmail', arg_ljmail)
FXAppCom.GetContactByLjmail(app_token_fx, parm, ref arg_msg)
if (arg_msg <> '') then
	rslt = 0
	MessageBox('提示', '获取联系人信息失败:' + arg_msg)
	goto ext
end if

s_fx_ljmail_contact contacts_empty
ins_contacts = contacts_empty

obj = parm.GetPBDictionary('Contact')

ins_contacts.cid[1] = obj.GetInt('cid')
ins_contacts.userid[1] = obj.GetInt('userid')
ins_contacts.reltype[1] = obj.GetInt('relType')
ins_contacts.revcuscommid[1] = obj.GetInt('revCusCommID')
ins_contacts.revname[1] = obj.GetString('revName')
ins_contacts.revempid[1] = obj.GetInt('revEmpid')
ins_contacts.revljmail[1] = obj.GetString('revLjmail')
//ins_contacts.revrep[1] = obj.GetString('revRep')

sle_contact.Text += ins_contacts.revname[1] + '<' + ins_contacts.revljmail[1] + '>;'

ext:
return rslt
end function

on w_ljmail_send_fx.create
int iCurrent
call super::create
this.uo_1=create uo_1
this.st_1=create st_1
this.sle_contact=create sle_contact
this.pb_contact=create pb_contact
this.st_2=create st_2
this.sle_subject=create sle_subject
this.cb_send=create cb_send
this.cb_save=create cb_save
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.uo_1
this.Control[iCurrent+2]=this.st_1
this.Control[iCurrent+3]=this.sle_contact
this.Control[iCurrent+4]=this.pb_contact
this.Control[iCurrent+5]=this.st_2
this.Control[iCurrent+6]=this.sle_subject
this.Control[iCurrent+7]=this.cb_send
this.Control[iCurrent+8]=this.cb_save
end on

on w_ljmail_send_fx.destroy
call super::destroy
destroy(this.uo_1)
destroy(this.st_1)
destroy(this.sle_contact)
destroy(this.pb_contact)
destroy(this.st_2)
destroy(this.sle_subject)
destroy(this.cb_send)
destroy(this.cb_save)
end on

event open;call super::open;uo_1.pb_picture.Visible = False

s_ljmail_msg temp
temp = Message.PowerObjectParm

if not IsValid(temp) then return
if IsNull(temp) then return

if (temp.msgid > 0) then // 使用编辑功能--编辑邮件
	
else // 使用回复功能--回复邮件
	sle_subject.Text = '回复:' + temp.subject
	string html
	html = '<br/><P>####################原始邮件####################</P>' + temp.htmlbody
	uo_1.uf_sethtml(html)
	
	wf_get_contact(temp.revcomid, temp.revljmail)
end if

end event

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

sle_contact.Width = this.workspacewidth( ) - sle_contact.X - pb_contact.Width - 20
pb_contact.X = sle_contact.X + sle_contact.Width + 10
sle_subject.Width = sle_contact.Width

uo_1.Width = this.workspacewidth( )
uo_1.Height = this.workspaceheight( ) - uo_1.Y

cb_exit.X = this.workspacewidth( ) - cb_exit.Width
end event

type cb_func from w_publ_base_style`cb_func within w_ljmail_send_fx
boolean visible = false
integer taborder = 0
boolean enabled = false
end type

type cb_exit from w_publ_base_style`cb_exit within w_ljmail_send_fx
integer x = 1234
integer taborder = 70
end type

type ln_bar from w_publ_base_style`ln_bar within w_ljmail_send_fx
end type

type ln_bar2 from w_publ_base_style`ln_bar2 within w_ljmail_send_fx
end type

type r_bar from w_publ_base_style`r_bar within w_ljmail_send_fx
end type

type uo_1 from uo_html_editor within w_ljmail_send_fx
integer y = 368
integer width = 2542
integer height = 748
integer taborder = 40
boolean bringtotop = true
end type

on uo_1.destroy
call uo_html_editor::destroy
end on

type st_1 from statictext within w_ljmail_send_fx
integer x = 18
integer y = 192
integer width = 210
integer height = 56
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 = "收件人:"
boolean focusrectangle = false
end type

type sle_contact from singlelineedit within w_ljmail_send_fx
event ue_doubleclk pbm_lbuttondblclk
integer x = 219
integer y = 180
integer width = 2075
integer height = 80
integer taborder = 10
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string pointer = "HyperLink!"
long textcolor = 33554432
boolean displayonly = true
borderstyle borderstyle = stylelowered!
end type

event ue_doubleclk;pb_contact.post event clicked()
end event

type pb_contact from picturebutton within w_ljmail_send_fx
integer x = 2304
integer y = 180
integer width = 82
integer height = 80
integer taborder = 20
boolean bringtotop = true
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string pointer = "HyperLink!"
string picturename = "people.bmp"
alignment htextalign = left!
string powertiptext = "通信录"
end type

event clicked;s_fx_ljmail_contact temp

OpenWithParm(w_ljmail_contact_ch_fx, ins_contacts)

temp = Message.PowerObjectParm
if (IsValid(temp) and not IsNull(temp)) then
	if (temp.ifch = 1) then
		ins_contacts = temp
		sle_contact.Text = ''
		
		long i
		for i = 1 to UpperBound(ins_contacts.revljmail)
			sle_contact.Text += ins_contacts.revname[i] + '<' + ins_contacts.revljmail[i] + '>;'
		next
	end if
end if
end event

type st_2 from statictext within w_ljmail_send_fx
integer x = 18
integer y = 288
integer width = 210
integer height = 56
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 = "主题:"
boolean focusrectangle = false
end type

type sle_subject from singlelineedit within w_ljmail_send_fx
integer x = 219
integer y = 276
integer width = 2075
integer height = 80
integer taborder = 30
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 cb_send from uo_imflatbutton within w_ljmail_send_fx
integer width = 151
integer height = 164
integer taborder = 50
boolean bringtotop = true
string text = "发送"
string normalpicname = "graphics\fx_send.bmp"
integer picsize = 16
toolbaralignment pic_align = alignattop!
boolean border = false
end type

event clicked;call super::clicked;if (wf_send() = 1) then
	Close(parent)
end if
end event

type cb_save from uo_imflatbutton within w_ljmail_send_fx
boolean visible = false
integer x = 430
integer width = 165
integer height = 164
integer taborder = 60
boolean bringtotop = true
boolean enabled = false
string text = "保存"
boolean border = false
end type

