Files
ayanova7/archive/ayanova 1.9.4 CE final release db schema 171/sp/ContactDlg.cpp

213 lines
4.7 KiB
C++

// ContactDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "ContactDlg.h"
#include "mailmsgdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContactDlg dialog
CContactDlg::CContactDlg(CWnd* pParent /*=NULL*/)
: CDialog(CContactDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CContactDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pApp= (CSpApp*)AfxGetApp();
/*
rs=new GZRset("Error: ContactDlg screen");
rs->SetConnect(m_pApp->strConnectString);
*/
//Initialize recordset pointer
rs=m_pApp->rsPool->GetRS("CContactDlg");
m_bEditMode=false;//add mode by default
}
CContactDlg::~CContactDlg()
{
//delete rs;
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
}
void CContactDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CContactDlg)
DDX_Control(pDX, IDC_EDNOTES, m_edNotes);
DDX_Control(pDX, IDC_DTTIME, m_dtTime);
DDX_Control(pDX, IDC_DTDATE, m_dtDate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CContactDlg, CDialog)
//{{AFX_MSG_MAP(CContactDlg)
ON_BN_CLICKED(IDC_BTNFOLLOWUP, OnBtnfollowup)
ON_BN_CLICKED(IDC_BTNEXITNOSAVE, OnBtnexitnosave)
ON_BN_CLICKED(IDC_BTNEXITSAVE, OnBtnexitsave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CContactDlg message handlers
//*****************************************************
void CContactDlg::Setup(CString strClientID,CString strRecordID)
{
m_strClientID=strClientID;
m_strRecordID=strRecordID;
if(m_strRecordID!="0")
m_bEditMode=true;
}
//****************************************************
BOOL CContactDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(m_bEditMode)
FillFields();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CContactDlg::OnBtnfollowup()
{
CString msg,sub,q,clientname;
COleDateTime dtData;
CString datestring;
m_edNotes.GetWindowText(msg);
if(msg.IsEmpty())
{
AfxMessageBox("There are no notes to send");
return;
}
//1.9.3.0
msg.Replace("\"","''");
//Get date
m_dtDate.GetTime(dtData);
datestring = dtData.Format(VAR_DATEVALUEONLY);
//Get time
m_dtTime.GetTime(dtData);
datestring += " " + dtData.Format(VAR_TIMEVALUEONLY);
//jam together
dtData.ParseDateTime(datestring);
q.Format("SELECT IIf(IsNull([clients].[company]),[clients].[last] & \", \" & [clients].[first],[clients].[company]) AS cname "
"FROM clients WHERE (((clients.id)=%s));",m_strClientID);
rs->Query(q);
if(!rs->IsEmpty())
{
rs->FetchField("cname",&clientname);
sub="Note on client: " + clientname + " " + dtData.Format();
}
else
{
sub="Note on client: <unknown client> " + dtData.Format();
}
CMailMsgDlg d;
d.m_bNoRE=true;//don't put a RE: in front of subject or >'s in front of text lines
d.SetForwardInfo(&sub,&msg);
d.DoModal();
}
void CContactDlg::OnBtnexitnosave()
{
CDialog::OnOK();
}
void CContactDlg::OnBtnexitsave()
{
COleDateTime dtData;
CString datestring,notes;
m_edNotes.GetWindowText(notes);
if(notes.IsEmpty())
{
AfxMessageBox("No data to save");
return;
}
//1.9.3.0
notes.Replace("\"","''");
//Get date
m_dtDate.GetTime(dtData);
datestring = dtData.Format(VAR_DATEVALUEONLY);
//Get time
m_dtTime.GetTime(dtData);
datestring += " " + dtData.Format(VAR_TIMEVALUEONLY);
//jam together
dtData.ParseDateTime(datestring);
CString q;
if(m_bEditMode)
{
q.Format("UPDATE contacts SET contacts.[date] = #%s#, contacts.staff = %u, "
"contacts.notes = \"%s\", contacts.clientlink = %s, contacts.indexed = False "
"WHERE (((contacts.id)=%s));",dtData.Format(_T("%m/%d/%Y %H:%M:%S")),m_pApp->m_lusrID,notes,m_strClientID,
m_strRecordID);
}
else
{
q.Format("INSERT INTO contacts ( [date], staff, notes, clientlink ) "
"SELECT #%s#, %u,\"%s\", %s;",dtData.Format(_T("%m/%d/%Y %H:%M:%S")),m_pApp->m_lusrID,notes,m_strClientID);
}
rs->Ex(q);
rs->Close();
rs->Close();
CDialog::OnOK();
}
//Populate with existing data if in edit mode
void CContactDlg::FillFields()
{
CString q,notes;
COleDateTime dtData;
q.Format("SELECT contacts.date, contacts.notes FROM contacts "
"WHERE (((contacts.id)=%s));",m_strRecordID);
rs->QueryReadOnly(q);
if(!rs->IsEmpty())
{
rs->FetchField("notes",&notes);
rs->FetchField("date",&dtData);
m_dtDate.SetTime(dtData);
m_dtTime.SetTime(dtData);
m_edNotes.SetWindowText(notes);
}
rs->Close();
}