319 lines
7.0 KiB
C++
319 lines
7.0 KiB
C++
// MailMsgDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "MailMsgDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CMailMsgDlg dialog
|
|
|
|
|
|
CMailMsgDlg::CMailMsgDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CMailMsgDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CMailMsgDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
k=new GZK;
|
|
k->GZSetUniqueKey(40);
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
/*
|
|
rs=new GZRset("Mail message entry screen error:");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
//Initialize recordset pointer
|
|
rs=m_pApp->rsPool->GetRS("CMailMsgDlg");
|
|
|
|
m_strMessage.Empty();
|
|
m_strSubject.Empty();
|
|
m_bNoRE=false;
|
|
}
|
|
|
|
|
|
void CMailMsgDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CMailMsgDlg)
|
|
DDX_Control(pDX, IDC_USERS, m_lbUsers);
|
|
DDX_Control(pDX, IDC_SUBJECT, m_edSubject);
|
|
DDX_Control(pDX, IDC_SEND, m_btnSend);
|
|
DDX_Control(pDX, IDC_POPUP, m_ckPopup);
|
|
DDX_Control(pDX, IDC_MESSAGE, m_edMessage);
|
|
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_dtDate);
|
|
DDX_Control(pDX, IDC_CANCEL, m_btnCancel);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CMailMsgDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CMailMsgDlg)
|
|
ON_BN_CLICKED(IDC_SEND, OnSend)
|
|
ON_BN_CLICKED(IDC_CANCEL, OnCancel)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CMailMsgDlg message handlers
|
|
|
|
void CMailMsgDlg::OnOK()
|
|
{
|
|
|
|
//CDialog::OnOK();
|
|
}
|
|
|
|
void CMailMsgDlg::OnCancel()
|
|
{
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CMailMsgDlg::OnSend()
|
|
{
|
|
CString strMsg,strSubject,q;
|
|
COleDateTime dtData,dtData2,dtData3;
|
|
long lData;
|
|
bool bData;
|
|
int nRecipients=m_lbUsers.SelectionCount();
|
|
//Ensure there is at least one selected user
|
|
if(nRecipients==0)
|
|
{
|
|
AfxMessageBox("You must select at least one person\r\n"
|
|
"to send this message to.");
|
|
return;
|
|
|
|
}
|
|
|
|
//encrypt the subject and message
|
|
//
|
|
m_edMessage.GetWindowText(strMsg);
|
|
m_edSubject.GetWindowText(strSubject);
|
|
|
|
if(strSubject.IsEmpty())
|
|
{
|
|
AfxMessageBox("A subject is required");
|
|
return;
|
|
}
|
|
|
|
k->GZEncrypt(&strMsg,false);
|
|
k->GZEncrypt(&strSubject,false);
|
|
|
|
//save the message
|
|
|
|
|
|
//open the recordset without returning a record (no id=0)
|
|
rs->Query("SELECT mail.* FROM mail;");
|
|
rs->AddNewRecord();
|
|
|
|
|
|
//********************************
|
|
// START SAVING FIELDS
|
|
//********************************
|
|
//FROM
|
|
rs->UpdateField("from",&m_pApp->m_lusrID);
|
|
//rs->SaveRecord();
|
|
|
|
//DATE:
|
|
dtData=COleDateTime::GetCurrentTime();
|
|
rs->UpdateField("date",&dtData);
|
|
//rs->SaveRecord();
|
|
|
|
|
|
//POPUP
|
|
bData = m_ckPopup.GetCheck() ? true:false;
|
|
rs->UpdateField("popup",&bData);
|
|
//rs->SaveRecord();
|
|
|
|
|
|
//SUBJECT
|
|
rs->UpdateField("subject",&strSubject);
|
|
// rs->SaveRecord();
|
|
|
|
//MESSAGE
|
|
rs->UpdateField("message",&strMsg);
|
|
//rs->SaveRecord();
|
|
|
|
//DELIVERY DATE
|
|
//get the date, remove on the date portion which
|
|
//sets the time to 0:0:0 (midnight)
|
|
m_dtDate.GetTime(dtData3);
|
|
dtData2.SetDate(dtData3.GetYear(),dtData3.GetMonth(),dtData3.GetDay());
|
|
|
|
rs->UpdateField("deliverydate",&dtData2);
|
|
rs->SaveRecord();
|
|
|
|
|
|
//****************** DONE SAVING FIELDS *************
|
|
//***************************************************
|
|
|
|
//retrieve the id number
|
|
q.Format("SELECT mail.* FROM mail "
|
|
"WHERE (((mail.from)=%u) AND ((mail.date)=#%s#));"
|
|
,m_pApp->m_lusrID,dtData.Format(_T("%m/%d/%Y %H:%M:%S")));
|
|
|
|
rs->Query(q);
|
|
|
|
|
|
//should work but....
|
|
ASSERT(!rs->IsEmpty());
|
|
|
|
rs->FetchField("id",&lData);
|
|
|
|
|
|
//save the recipient records
|
|
for(int x=0;x<nRecipients;x++)
|
|
{
|
|
q.Format("INSERT INTO mailroute ( maillink, recipient, remind ) "
|
|
"SELECT %u , %s , True;",lData,m_lbUsers.GetSelectedItem(x));
|
|
|
|
rs->Ex(q);
|
|
|
|
}
|
|
|
|
rs->Close();
|
|
CDialog::OnOK();
|
|
|
|
}
|
|
|
|
BOOL CMailMsgDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
rs->Query("SELECT users.id, users.mail, [last] & \", \" & [first] AS name "
|
|
"FROM users WHERE (((users.active)=True) AND (users.mail)=True) "
|
|
"ORDER BY [last] & \", \" & [first];");
|
|
|
|
if(rs->IsEmpty())//bail
|
|
{
|
|
AfxMessageBox("No users could be found for you to send mail to");
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
//fill the list box
|
|
|
|
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_lbUsers.Clear();
|
|
//fill combo box with available zones
|
|
rs->MoveFirst();
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_lbUsers.AddRow(strData,strIndex);
|
|
while(rs->MoveForward())
|
|
{
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_lbUsers.AddRow(strData,strIndex);
|
|
}
|
|
|
|
|
|
if(!m_strSubject.IsEmpty())
|
|
{
|
|
if(m_bNoRE)
|
|
{
|
|
m_edSubject.SetWindowText(m_strSubject);
|
|
m_edMessage.SetWindowText(m_strMessage);
|
|
}
|
|
else
|
|
{
|
|
//if replying/forwarding, set previous message
|
|
if(m_strSubject.Left(3)!="Re:")
|
|
m_strSubject="Re: " + m_strSubject;
|
|
m_strMessage=">" + m_strMessage;
|
|
m_strMessage.Replace("\r\n","\r\n> ");
|
|
m_edSubject.SetWindowText(m_strSubject);
|
|
m_edMessage.SetWindowText(m_strMessage);
|
|
}
|
|
}
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
//***********************88
|
|
CMailMsgDlg::~CMailMsgDlg()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
delete k;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************************
|
|
//SAVE EDIT CONTROL FIELD
|
|
//************************************************************
|
|
bool CMailMsgDlg::SaveField(CEdit *edControl,CString fldname,bool AllowEmpty)
|
|
{
|
|
|
|
|
|
CString str;
|
|
//do nothing if not changed
|
|
if(edControl->GetModify()!=TRUE) return true;
|
|
|
|
edControl->GetWindowText(str);
|
|
//dont save empty fields if not allowed to
|
|
if(!AllowEmpty)
|
|
{
|
|
|
|
if(str.IsEmpty())
|
|
{
|
|
edControl->Undo();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
rs->UpdateField(fldname,&str);
|
|
rs->SaveRecord();
|
|
|
|
edControl->SetModify(FALSE);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
//************************************************************
|
|
//SAVE CheckBox CONTROL FIELD
|
|
//************************************************************
|
|
bool CMailMsgDlg::SaveField(CButton *ckControl,CString fldname)
|
|
{
|
|
|
|
bool bData=false;
|
|
BOOL BData;
|
|
BData=ckControl->GetCheck();
|
|
if(BData==TRUE) bData=true;
|
|
rs->UpdateField(fldname,&bData);
|
|
rs->SaveRecord();
|
|
|
|
return true;
|
|
}
|
|
//************************************************************
|
|
//SAVE DateTimePicker CONTROL FIELD
|
|
//************************************************************
|
|
bool CMailMsgDlg::SaveField(CDateTimeCtrl *dtControl,CString fldname)
|
|
{
|
|
|
|
COleDateTime dtData;
|
|
dtControl->GetTime(dtData);
|
|
rs->UpdateField(fldname,&dtData);
|
|
rs->SaveRecord();
|
|
|
|
return true;
|
|
}
|
|
|
|
void CMailMsgDlg::SetForwardInfo(CString *pSubject, CString *pMessage)
|
|
{
|
|
m_strMessage=*pMessage;
|
|
m_strSubject=*pSubject;
|
|
}
|