512 lines
11 KiB
C++
512 lines
11 KiB
C++
// MailReaderDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "MailReaderDlg.h"
|
|
#include "MailMsgDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CMailReaderDlg dialog
|
|
|
|
|
|
CMailReaderDlg::CMailReaderDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CMailReaderDlg::IDD, pParent)
|
|
, m_bReadOnly(false)
|
|
{
|
|
//{{AFX_DATA_INIT(CMailReaderDlg)
|
|
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
|
|
k=new GZK;
|
|
k->GZSetUniqueKey(40);
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
|
|
rs=m_pApp->rsPool->GetRS("CMailReaderDlg");
|
|
}
|
|
|
|
CMailReaderDlg::~CMailReaderDlg()
|
|
{
|
|
delete k;
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
}
|
|
|
|
|
|
void CMailReaderDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CMailReaderDlg)
|
|
DDX_Control(pDX, IDC_MAIL_REPORT, m_rcMail);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CMailReaderDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CMailReaderDlg)
|
|
ON_NOTIFY(RVN_ITEMDRAWPREVIEW, IDC_MAIL_REPORT, OnRvnItemDrawPreview)
|
|
ON_NOTIFY(RVN_ITEMDBCLICK, IDC_MAIL_REPORT, OnRvnItemDbClick)
|
|
//}}AFX_MSG_MAP
|
|
ON_COMMAND(ID_MAIL_NEWMESSAGE, OnMailNewmessage)
|
|
ON_COMMAND(ID_MAIL_REPLY, OnMailReply)
|
|
ON_COMMAND(ID_MAIL_DELETE, OnMailDelete)
|
|
ON_COMMAND(ID_MAIL_CLOSETHISSCREEN, OnMailClosethisscreen)
|
|
ON_COMMAND(ID_MAIL_HELP, OnMailHelp)
|
|
ON_COMMAND(ID_MAIL_CHECKFORNEWMAIL, OnMailCheckfornewmail)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CMailReaderDlg message handlers
|
|
|
|
BOOL CMailReaderDlg::OnInitDialog()
|
|
{
|
|
|
|
|
|
CDialog::OnInitDialog();
|
|
m_resize.Create( this );
|
|
Security();
|
|
|
|
m_resize.Add(IDC_MAIL_REPORT,0,0,100,100);
|
|
//Use the current width and height as the minimum size
|
|
m_resize.SetMinimumTrackingSize();
|
|
|
|
CString profile,q;
|
|
q.Format("SELECT users.mailprofile "
|
|
"FROM users WHERE (((users.id)=%u));",m_pApp->m_lusrID);
|
|
rs->Query(q);
|
|
rs->FetchField("mailprofile",&profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//m_rcMail.ModifyStyle(0,RVS_SHOWVGRID);
|
|
m_ilReport.Create(IDB_REPORT, 16, 1, RGB(255,0,255));
|
|
m_rcMail.SetImageList(&m_ilReport);
|
|
|
|
ShowWindow(SW_MAXIMIZE);
|
|
|
|
m_rcMail.InsertColor(0, 0x00C0D8C0);
|
|
m_rcMail.InsertColor(1, ::GetSysColor(COLOR_GRAYTEXT));
|
|
m_rcMail.InsertColor(2, 0x00D0C0C0);
|
|
m_rcMail.InsertColor(3, 0x00804000);
|
|
|
|
/*
|
|
|
|
RVCOLUMN rvc;
|
|
rvc.lpszText = "Field";
|
|
rvc.iWidth = 100;
|
|
m_rcAbout.DefineColumn(0, &rvc);
|
|
|
|
rvc.lpszText = "Data";
|
|
rvc.iWidth = 320;
|
|
m_rcAbout.DefineColumn(1, &rvc);
|
|
|
|
m_rcAbout.ActivateColumn(0, 0);
|
|
m_rcAbout.ActivateColumn(1, 1);
|
|
|
|
m_rcAbout.SetItemCount(100);
|
|
*/
|
|
|
|
RVCOLUMN rvc;
|
|
|
|
rvc.nFormat = RVCF_IMAGE|RVCF_EX_AUTOWIDTH|RVCF_EX_FIXEDWIDTH|RVCF_SUBITEM_IMAGE;
|
|
rvc.iImage = 0;
|
|
rvc.lpszText = _T("Icon");
|
|
m_rcMail.DefineColumn(0, &rvc);
|
|
|
|
rvc.nFormat = RVCF_TEXT;
|
|
rvc.lpszText = "From:";
|
|
rvc.iWidth = 175;
|
|
m_rcMail.DefineColumn(1, &rvc);
|
|
|
|
rvc.lpszText = "Subject:";
|
|
rvc.iWidth = 325;
|
|
m_rcMail.DefineColumn(2, &rvc);
|
|
|
|
rvc.lpszText = "Date:";
|
|
rvc.iWidth = 175;
|
|
m_rcMail.DefineColumn(3, &rvc);
|
|
|
|
//setup according to users preferences
|
|
if(!profile.IsEmpty())
|
|
m_rcMail.GetProfile(&profile);
|
|
else
|
|
{
|
|
|
|
//not needed when setting by pref
|
|
//but if there are no preferences then you would need it
|
|
|
|
m_rcMail.ActivateColumn(0, 0);
|
|
m_rcMail.ActivateColumn(1, 1);
|
|
m_rcMail.ActivateColumn(2, 2);
|
|
m_rcMail.ActivateColumn(3, 3);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_rcMail.ModifyStyle(0, RVS_SINGLESELECT);
|
|
//m_rcMail.ModifyStyle(0, RVS_SHOWCOLORALTERNATE);
|
|
|
|
|
|
//turn off the grids
|
|
m_rcMail.ModifyStyle(RVS_SHOWVGRID, 0);
|
|
m_rcMail.ModifyStyle(RVS_SHOWHGRID, 0);
|
|
|
|
|
|
|
|
//retrieve the mail and display it
|
|
FillView();
|
|
|
|
|
|
|
|
//===================================================
|
|
// SET WINDOW SIZE TO MATCH WORK AREA
|
|
ShowWindow(SW_SHOWMAXIMIZED);
|
|
CRect workarea;
|
|
SystemParametersInfo(SPI_GETWORKAREA,0,&workarea,0);
|
|
SetWindowPos(NULL,workarea.left,workarea.top,workarea.Width(),workarea.Height(),SWP_NOZORDER);
|
|
//===================================================
|
|
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CMailReaderDlg::OnRvnItemDrawPreview(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
|
|
CString strText;
|
|
LPNMRVDRAWPREVIEW lpnmrvdp = (LPNMRVDRAWPREVIEW)pNMHDR;
|
|
|
|
strText=m_Messages[0].GetAt(m_Messages[0].FindIndex(lpnmrvdp->iItem));
|
|
|
|
CReportCtrl& rc = m_rcMail;
|
|
|
|
CDC dc;
|
|
dc.Attach(lpnmrvdp->hDC);
|
|
if(lpnmrvdp->nState&RVIS_SELECTED)
|
|
dc.SetTextColor(::GetFocus()==rc.m_hWnd ? GetSysColor(COLOR_HIGHLIGHTTEXT):GetSysColor(COLOR_HIGHLIGHT));
|
|
else
|
|
dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHT));
|
|
|
|
lpnmrvdp->rect.left += 40;
|
|
lpnmrvdp->rect.top += 2;
|
|
lpnmrvdp->rect.bottom -= 2;
|
|
dc.DrawText(strText, &lpnmrvdp->rect, DT_LEFT|DT_END_ELLIPSIS|DT_WORDBREAK|DT_NOPREFIX|DT_EXPANDTABS);
|
|
|
|
dc.Detach();
|
|
*pResult = FALSE;
|
|
|
|
|
|
}
|
|
|
|
void CMailReaderDlg::OnRvnItemDbClick(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
|
|
LPNMREPORTVIEW lpnmrv = (LPNMREPORTVIEW)pNMHDR;
|
|
|
|
|
|
|
|
if(lpnmrv->iItem >=0)//-1 if clicked on invalid
|
|
{
|
|
|
|
int x=lpnmrv->iItem;
|
|
CString temp,msg,sub,strdate,sender,q;
|
|
temp=m_Messages[0].GetAt(m_Messages[0].FindIndex(x));
|
|
sub=m_rcMail.GetItemText(x,2);
|
|
strdate=m_rcMail.GetItemText(x,3);
|
|
sender=m_rcMail.GetItemText(x,1);
|
|
|
|
//Now format with header info
|
|
msg.Format("From: %s\r\n"
|
|
"Sent: %s\r\n"
|
|
"Subject: %s\r\n\r\nMessage:\r\n%s",sender,strdate,sub,temp);
|
|
|
|
m_pApp->ShowStuff(msg);
|
|
//AfxMessageBox(msg,MB_ICONINFORMATION|MB_OK);
|
|
|
|
//FLAG MAIL MESSAGE AS BEING READ
|
|
q.Format("UPDATE mailroute SET mailroute.remind = False "
|
|
"WHERE (((mailroute.maillink)=%s) AND ((mailroute.recipient)=%u));"
|
|
,m_Messages[1].GetAt(m_Messages[1].FindIndex(lpnmrv->iItem)),m_pApp->m_lusrID);
|
|
|
|
rs->Ex(q);
|
|
|
|
|
|
|
|
RVITEM rvi;
|
|
rvi.iItem = lpnmrv->iItem;
|
|
rvi.iSubItem = 0;
|
|
rvi.nMask = RVIM_IMAGE|RVIM_PREVIEW|RVIM_STATE;
|
|
rvi.iImage = 4;
|
|
rvi.nPreview = 0;
|
|
rvi.nState = 0;
|
|
m_rcMail.SetItem(&rvi);
|
|
|
|
}
|
|
|
|
*pResult = FALSE;
|
|
}
|
|
|
|
|
|
void CMailReaderDlg::FillView()
|
|
{
|
|
|
|
CString q;
|
|
bool bUnread;
|
|
int x=0;
|
|
|
|
m_Messages[0].RemoveAll();
|
|
m_Messages[1].RemoveAll();
|
|
m_rcMail.DeleteAllItems();
|
|
|
|
q.Format("SELECT mail.*, [last] & \", \" & [first] AS fromname, mailroute.remind "
|
|
"FROM (mail INNER JOIN mailroute ON mail.id = mailroute.maillink) "
|
|
"LEFT JOIN users ON mail.from = users.id "
|
|
"WHERE (((mailroute.recipient)=%u) AND ((mail.deliverydate)<Date()+1)) "
|
|
"ORDER BY mail.date DESC;"
|
|
,m_pApp->m_lusrID);
|
|
|
|
|
|
rs->Query(q);
|
|
|
|
if(rs->IsEmpty())
|
|
return;
|
|
|
|
|
|
|
|
CString strFrom,strSubject,strMessage,strDate,strID;
|
|
COleDateTime dtDate;
|
|
long lData;
|
|
|
|
|
|
rs->MoveFirst();
|
|
|
|
|
|
do
|
|
{
|
|
|
|
rs->FetchField("fromname",&strFrom);
|
|
//fix if a deleted user sent the message
|
|
if(strFrom.Compare(", ")==0)
|
|
strFrom="<Unknown>";
|
|
|
|
rs->FetchField("subject",&strSubject);
|
|
k->GZDecrypt(&strSubject,false);
|
|
rs->FetchField("message",&strMessage);
|
|
k->GZDecrypt(&strMessage,false);
|
|
m_Messages[0].AddTail(strMessage);
|
|
rs->FetchField("deliverydate",&dtDate);
|
|
//keep track of the ID numbers
|
|
rs->FetchField("id",&lData);
|
|
strID.Format("%u",lData);
|
|
m_Messages[1].AddTail(strID);
|
|
rs->FetchField("remind",&bUnread);
|
|
|
|
//Set the look of the row and insert it
|
|
RVITEM rvi;
|
|
rvi.iItem = x;
|
|
rvi.iSubItem = 0;
|
|
rvi.nMask = RVIM_IMAGE|RVIM_PREVIEW|RVIM_STATE|RVIM_LPARAM;
|
|
if(bUnread==false)
|
|
{
|
|
rvi.nState = 0;
|
|
rvi.iImage = 4;//Opened envelope
|
|
rvi.nPreview = 0;//no preview necessary
|
|
}
|
|
else
|
|
{
|
|
rvi.nState = RVIS_BOLD;
|
|
rvi.iImage = 3;//closed envelope
|
|
if(!strMessage.IsEmpty())
|
|
rvi.nPreview = 17;//hmmm?
|
|
else
|
|
rvi.nPreview=0;//nothing to show
|
|
}
|
|
|
|
rvi.lParam = x;
|
|
m_rcMail.InsertItem(&rvi);
|
|
|
|
|
|
//RVS_OWNERDATA<---this is causing an assert
|
|
|
|
//FROM
|
|
rvi.iSubItem = 1;
|
|
rvi.nMask = RVIM_TEXT;
|
|
rvi.lpszText = strFrom.GetBuffer(strFrom.GetLength());
|
|
m_rcMail.SetItem(&rvi);
|
|
|
|
//SUBJECT
|
|
rvi.iSubItem = 2;
|
|
rvi.lpszText = strSubject.GetBuffer(strSubject.GetLength());
|
|
m_rcMail.SetItem(&rvi);
|
|
|
|
//DATE
|
|
rvi.iSubItem = 3;
|
|
strDate=dtDate.Format();
|
|
rvi.lpszText = strDate.GetBuffer(strDate.GetLength());
|
|
m_rcMail.SetItem(&rvi);
|
|
|
|
x++;
|
|
|
|
}while(rs->MoveForward());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CMailReaderDlg::OnOk()
|
|
{}
|
|
|
|
|
|
|
|
|
|
void CMailReaderDlg::Security()
|
|
{
|
|
m_bReadOnly=false;
|
|
int x=m_pApp->Allowed(REMAIL,true);
|
|
|
|
if(x==2)//read only
|
|
{
|
|
m_bReadOnly=true;
|
|
//m_btnNew.ShowWindow(FALSE);
|
|
//m_btnDelete.ShowWindow(FALSE);
|
|
//m_btnForward.ShowWindow(FALSE);
|
|
|
|
}
|
|
|
|
|
|
if(x==0)
|
|
{
|
|
m_bReadOnly=true;
|
|
m_pApp->SecurityWarning();
|
|
CDialog::OnCancel();
|
|
}
|
|
}
|
|
|
|
void CMailReaderDlg::OnMailNewmessage()
|
|
{
|
|
// New message
|
|
if(m_bReadOnly==true)
|
|
{
|
|
AfxMessageBox("Your AyaNova administrator has given you\r\n"
|
|
"read-only access to mail.");
|
|
return;
|
|
|
|
}
|
|
CMailMsgDlg d;
|
|
|
|
d.DoModal();
|
|
FillView();
|
|
}
|
|
|
|
void CMailReaderDlg::OnMailReply()
|
|
{
|
|
if(m_bReadOnly==true)
|
|
{
|
|
AfxMessageBox("Your AyaNova administrator has given you\r\n"
|
|
"read-only access to mail.");
|
|
return;
|
|
|
|
}
|
|
CString temp,msg,sub,strdate,sender;
|
|
int x=m_rcMail.GetFirstSelectedItem();
|
|
//validate there is a selection
|
|
if(x<0)
|
|
return;
|
|
|
|
temp=m_Messages[0].GetAt(m_Messages[0].FindIndex(x));
|
|
sub=m_rcMail.GetItemText(x,2);
|
|
strdate=m_rcMail.GetItemText(x,3);
|
|
sender=m_rcMail.GetItemText(x,1);
|
|
msg.Empty();
|
|
//Now format with header info
|
|
msg.Format("-----Original Message-----\r\n"
|
|
"From: %s\r\n"
|
|
"Sent: %s\r\n"
|
|
"Subject: %s\r\n\r\n%s",sender,strdate,sub,temp);
|
|
|
|
|
|
|
|
//---Original Message-----
|
|
//From: MCC First Aid [mailto:mccfirstaid@suncor.com]
|
|
//Sent: Friday, May 12, 2000 8:00 AM
|
|
//To: 'J Cardinal'
|
|
//Subject: RE: Update for database program
|
|
//
|
|
|
|
|
|
|
|
CMailMsgDlg d;
|
|
d.SetForwardInfo(&sub,&msg);
|
|
d.DoModal();
|
|
|
|
FillView();
|
|
}
|
|
|
|
void CMailReaderDlg::OnMailDelete()
|
|
{
|
|
CString q;
|
|
int x=m_rcMail.GetFirstSelectedItem();
|
|
//validate there is a selection
|
|
if(x<0)
|
|
return;
|
|
if(AfxMessageBox("Permanently delete this message?",MB_YESNO)==IDYES)
|
|
{
|
|
q.Format("DELETE mailroute.*, mailroute.maillink, mailroute.recipient "
|
|
"FROM mailroute WHERE (((mailroute.maillink)=%s) AND ((mailroute.recipient)=%u));"
|
|
,m_Messages[1].GetAt(m_Messages[1].FindIndex(x)),m_pApp->m_lusrID);
|
|
|
|
rs->Ex(q);
|
|
rs->Close();
|
|
FillView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void CMailReaderDlg::OnMailClosethisscreen()
|
|
{
|
|
CString profile,q;
|
|
|
|
//save to user prefs.
|
|
m_rcMail.WriteProfile(&profile);
|
|
q.Format("UPDATE users SET users.mailprofile = \"%s\" "
|
|
"WHERE (((users.id)=%u));",profile,m_pApp->m_lusrID);
|
|
rs->Ex(q);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CMailReaderDlg::OnMailHelp()
|
|
{
|
|
WinHelp(0x2008E);
|
|
}
|
|
|
|
void CMailReaderDlg::OnMailCheckfornewmail()
|
|
{
|
|
CWaitCursor cw;
|
|
FillView();
|
|
}
|