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

226 lines
4.7 KiB
C++

// ContactsViewDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "ContactsViewDlg.h"
#include "ContactDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContactsViewDlg dialog
CContactsViewDlg::CContactsViewDlg(CWnd* pParent /*=NULL*/)
: CDialog(CContactsViewDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CContactsViewDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pApp= (CSpApp*)AfxGetApp();
//Initialize recordset pointer
rs=m_pApp->rsPool->GetRS("CContactsViewDlg");
}
CContactsViewDlg::~CContactsViewDlg()
{
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
}
void CContactsViewDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CContactsViewDlg)
DDX_Control(pDX, IDC_LSTNBRECS, m_lstNBRecs);
DDX_Control(pDX, IDC_EDNOTES, m_edNotes);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CContactsViewDlg, CDialog)
//{{AFX_MSG_MAP(CContactsViewDlg)
ON_BN_CLICKED(IDC_BTNADD, OnBtnadd)
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
ON_LBN_SELCHANGE(IDC_LSTNBRECS, OnSelchangeLstnbrecs)
ON_BN_CLICKED(IDC_BTNEDIT, OnBtnedit)
ON_BN_CLICKED(IDC_BTNDEL, OnBtndel)
ON_LBN_DBLCLK(IDC_LSTNBRECS, OnDblclkLstnbrecs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CContactsViewDlg message handlers
void CContactsViewDlg::OnBtnadd()
{
CContactDlg d;
d.Setup(m_strClientID,"0");
d.DoModal();
rs->Close();
FillView();
}
void CContactsViewDlg::Setup(CString strClientID)
{
if(strClientID.IsEmpty())
{
AfxMessageBox("Invalid client ID");
CDialog::OnOK();
}
m_strClientID=strClientID;
}
void CContactsViewDlg::FillView()
{
CString q,username,notes,allnotes,header,strID;
COleDateTime dtData;
long lData;
m_lstNBRecs.Clear();
q.Format("SELECT contacts.id, contacts.date "
"FROM contacts "
"WHERE (((contacts.clientlink)=%s)) ORDER BY contacts.date DESC;",m_strClientID);
//m_pApp->ShowStuff(q);
rs->QueryReadOnly(q);
if(rs->IsEmpty())
{
m_edNotes.SetWindowText("No items to display");
}
else
{
rs->MoveFirst();
do
{
rs->FetchField("date",&dtData);
rs->FetchField("id",&lData);
strID.Format("%u",lData);
m_lstNBRecs.AddRow(dtData.Format(),strID);
}while(rs->MoveForward());
m_lstNBRecs.SetCurSel(0);
OnSelchangeLstnbrecs();
}
}
BOOL CContactsViewDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString q;
q.Format("SELECT IIf(IsNull([clients].[company]),[clients].[first] & \" \" & [clients].[last],[clients].[company]) AS clientname "
"FROM clients WHERE (((clients.id)=%s));",m_strClientID);
rs->QueryReadOnly(q);
if(!rs->IsEmpty())
{
rs->FetchField("clientname",&q);
q="Client notes for: " + q;
SetWindowText(q);
}
FillView();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CContactsViewDlg::OnBtndone()
{
CDialog::OnOK();
}
//sc.exe gpf here somewhere
void CContactsViewDlg::OnSelchangeLstnbrecs()
{
CString q,username,notes,allnotes,header,strID;
COleDateTime dtData;
/*
if(m_bJustOpened)
strID=m_strFirstRecordID;
else
{*/
//AfxMessageBox("Calling: GetSelectedItem");
m_lstNBRecs.RebuildIndex();//<--------FIXES PROBLEM
strID=m_lstNBRecs.GetSelectedItem(0);//<-------problem
//}
q.Format("SELECT contacts.id, [users].[first] & \" \" & [users].[last] AS username, contacts.date, contacts.notes "
"FROM contacts LEFT JOIN users ON contacts.staff = users.id "
"WHERE (((contacts.id)=%s));",strID);
rs->QueryReadOnly(q);
if(rs->IsEmpty())
{
m_edNotes.SetWindowText("No data");
return;
}
rs->FetchField("username",&username);
rs->FetchField("notes",&notes);
rs->FetchField("date",&dtData);
header=dtData.Format() + " - " + username;
allnotes=allnotes+"--< "+header+" >--\r\n"+notes+"\r\n\r\n";
m_edNotes.SetWindowText(allnotes);
}
void CContactsViewDlg::OnBtnedit()
{
CContactDlg d;
d.Setup(m_strClientID,m_lstNBRecs.GetSelectedItem(0));
d.DoModal();
rs->Close();
FillView();
}
void CContactsViewDlg::OnBtndel()
{
CString q;
if(AfxMessageBox("Delete selected record?",MB_YESNO)==IDYES)
{
q.Format("DELETE contacts.*, contacts.id "
"FROM contacts "
"WHERE (((contacts.id)=%s));",m_lstNBRecs.GetSelectedItem(0));
rs->Ex(q);
rs->Close();
FillView();
}
}
void CContactsViewDlg::OnDblclkLstnbrecs()
{
OnBtnedit();
}
void CContactsViewDlg::OnOK()
{
}