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

2571 lines
65 KiB
C++

// ClientsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "ClientsDlg.h"
#include "ClientsRA.h"
#include "ZonesDlg.h"
#include "contractsdlg.h"
#include "PM.h"
#include "ContactsViewDlg.h"
#include "ConsolidateDlg.h"
#include "UnitsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClientsDlg dialog
CClientsDlg::CClientsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClientsDlg::IDD, pParent)
, m_bPMAllowed(false)
, m_strDefaultCity(_T(""))
, m_strDefaultStateProv(_T(""))
, m_strDefaultPostal(_T(""))
, m_strDefaultCountry(_T(""))
{
//{{AFX_DATA_INIT(CClientsDlg)
//}}AFX_DATA_INIT
m_pApp= (CSpApp*)AfxGetApp();
/*
rs=new GZRset("Error: Clients dialog");
rs->SetConnect(m_pApp->strConnectString);
rs2=new GZRset("Error: Clients dialog defaults r.s.");
rs2->SetConnect(m_pApp->strConnectString);
*/
rs=m_pApp->rsPool->GetRS("CClientsDlg (RS)");
rs2=m_pApp->rsPool->GetRS("CClientsDlg (RS2)");
m_pstrReturnValue=NULL;
m_strForceSelection.Empty();
//Added 8/28/00 prompt on very first edit
//and as long as you say yes to edit prompt
//used by savefield functions
m_bEditPrompt=true;
//v1.9.4.5
lPreferredTech=0;
}
CClientsDlg::~CClientsDlg()
{
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
m_pApp->rsPool->ReleaseRS(&rs2->m_nID);
}
void CClientsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClientsDlg)
DDX_Control(pDX, IDC_BTNNOTES, m_btnNotes);
DDX_Control(pDX, IDC_BTNDONE, m_btnDone);
DDX_Control(pDX, IDC_EDACCTNUM, m_edAcctNum);
DDX_Control(pDX, IDC_CBDEFTRAVEL, m_cbDefTravelRate);
DDX_Control(pDX, IDC_CBDEFRATE, m_cbRate);
DDX_Control(pDX, IDC_BTNPM, m_btnPM);
DDX_Control(pDX, IDC_HISTORY, m_lblHist);
DDX_Control(pDX, IDC_ZONELABEL, m_lblZone);
DDX_Control(pDX, IDC_ZONE, m_cbZone);
DDX_Control(pDX, IDC_BILLHEAD, m_ckBillHead);
DDX_Control(pDX, IDC_ALERTLABEL, m_lblAlert);
DDX_Control(pDX, IDC_ALERT, m_edAlert);
DDX_Control(pDX, IDC_TECHNOTESLABEL, m_lblTechNotes);
DDX_Control(pDX, IDC_TECHNOTES, m_edTechNotes);
DDX_Control(pDX, IDC_STREETLABEL, m_lblStreet);
DDX_Control(pDX, IDC_STREET, m_edStreet);
DDX_Control(pDX, IDC_STATEPROVINCELABEL, m_lblStateProv);
DDX_Control(pDX, IDC_STATEPROVINCE, m_edStateProv);
DDX_Control(pDX, IDC_PREFERTECHLABEL, m_lblPreferTech);
DDX_Control(pDX, IDC_PREFERTECH, m_cbPreferTech);
DDX_Control(pDX, IDC_POSTALLABEL, m_lblPostal);
DDX_Control(pDX, IDC_POSTAL, m_edPostal);
DDX_Control(pDX, IDC_PHONELABEL, m_lblPhone);
DDX_Control(pDX, IDC_PHONE, m_edPhone);
DDX_Control(pDX, IDC_MAILADDRESSLABEL, m_lblMail);
DDX_Control(pDX, IDC_MAILADDRESS, m_edMail);
DDX_Control(pDX, IDC_LASTNAMELABEL, m_lblLast);
DDX_Control(pDX, IDC_LASTNAME, m_edLast);
DDX_Control(pDX, IDC_HEADOFFICEPICKERLABEL, m_lblHeadOffice);
DDX_Control(pDX, IDC_HEADOFFICEPICKER, m_cbHeadOffice);
DDX_Control(pDX, IDC_GENERALNOTESLABEL, m_lblGenNotes);
DDX_Control(pDX, IDC_GENERALNOTES, m_edGenNotes);
DDX_Control(pDX, IDC_FIRSTNAMELABEL, m_lblFirst);
DDX_Control(pDX, IDC_FIRSTNAME, m_edFirst);
DDX_Control(pDX, IDC_FAXLABEL, m_lblFax);
DDX_Control(pDX, IDC_FAX, m_edFax);
DDX_Control(pDX, IDC_EXTENSIONLABEL, m_lblExtension);
DDX_Control(pDX, IDC_EXTENSION, m_edExtension);
DDX_Control(pDX, IDC_EMAILLABEL, m_lblEmail);
DDX_Control(pDX, IDC_EMAIL, m_edEmail);
DDX_Control(pDX, IDC_DELETE, m_btnDelete);
DDX_Control(pDX, IDC_COUNTRYLABEL, m_lblCountry);
DDX_Control(pDX, IDC_COUNTRY, m_edCountry);
DDX_Control(pDX, IDC_CONTRACTLABEL, m_lblContract);
DDX_Control(pDX, IDC_CONTRACTEXPIRYLABEL, m_lblContractExpiry);
DDX_Control(pDX, IDC_CONTRACTEXPIRYDATE, m_dtContractExpiryDate);
DDX_Control(pDX, IDC_CONTRACT, m_cbContract);
DDX_Control(pDX, IDC_CONSOLIDATE, m_btnConsolidate);
DDX_Control(pDX, IDC_COMPANY_LABEL, m_lblCompany);
DDX_Control(pDX, IDC_COMPANY, m_edCompany);
DDX_Control(pDX, IDC_CITYLABEL, m_lblCity);
DDX_Control(pDX, IDC_CITY, m_edCity);
DDX_Control(pDX, IDC_ADDHEAD, m_btnAddHead);
DDX_Control(pDX, IDC_ADD, m_btnAdd);
DDX_Control(pDX, IDC_HEADOFFICE, m_ckShowHeadOfficeCheck);
DDX_Control(pDX, IDC_CLIENTLIST_LABEL, m_lblClientListLabel);
DDX_Control(pDX, IDC_CLIENTLIST, m_cbClientList);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_PHONE2, m_edPhone2);
DDX_Control(pDX, IDC_PHONE3, m_edPhone3);
/*DDX_Control(pDX, IDC_CK_INACTIVE, m_ckInactive);*/
DDX_Control(pDX, IDC_CB_UNITS, m_cbUnits);
DDX_Control(pDX, IDC_LBL_UNITS, m_lblUnits);
}
BEGIN_MESSAGE_MAP(CClientsDlg, CDialog)
//{{AFX_MSG_MAP(CClientsDlg)
ON_CBN_CLOSEUP(IDC_CLIENTLIST, OnCloseupClientlist)
ON_BN_CLICKED(IDC_HEADOFFICE, OnHeadoffice)
ON_CBN_CLOSEUP(IDC_CONTRACT, OnCloseupContract)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_ADDHEAD, OnAddhead)
ON_EN_KILLFOCUS(IDC_FIRSTNAME, OnKillfocusFirstname)
ON_EN_KILLFOCUS(IDC_COMPANY, OnKillfocusCompany)
ON_EN_KILLFOCUS(IDC_LASTNAME, OnKillfocusLastname)
ON_EN_KILLFOCUS(IDC_MAILADDRESS, OnKillfocusMailaddress)
ON_EN_KILLFOCUS(IDC_STREET, OnKillfocusStreet)
ON_EN_KILLFOCUS(IDC_CITY, OnKillfocusCity)
ON_EN_KILLFOCUS(IDC_STATEPROVINCE, OnKillfocusStateprovince)
ON_EN_KILLFOCUS(IDC_POSTAL, OnKillfocusPostal)
ON_EN_KILLFOCUS(IDC_COUNTRY, OnKillfocusCountry)
ON_EN_KILLFOCUS(IDC_PHONE, OnKillfocusPhone)
ON_EN_KILLFOCUS(IDC_EXTENSION, OnKillfocusExtension)
ON_EN_KILLFOCUS(IDC_EMAIL, OnKillfocusEmail)
ON_EN_KILLFOCUS(IDC_FAX, OnKillfocusFax)
ON_CBN_CLOSEUP(IDC_HEADOFFICEPICKER, OnCloseupHeadofficepicker)
ON_BN_CLICKED(IDC_BILLHEAD, OnBillhead)
ON_EN_KILLFOCUS(IDC_TECHNOTES, OnKillfocusTechnotes)
ON_EN_KILLFOCUS(IDC_GENERALNOTES, OnKillfocusGeneralnotes)
ON_CBN_CLOSEUP(IDC_ZONE, OnCloseupZone)
ON_CBN_CLOSEUP(IDC_PREFERTECH, OnCloseupPrefertech)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_CONTRACTEXPIRYDATE, OnDatetimechangeContractexpirydate)
ON_EN_KILLFOCUS(IDC_ALERT, OnKillfocusAlert)
ON_BN_CLICKED(IDC_ZONELABEL, OnZonelabel)
ON_BN_CLICKED(IDC_CONTRACTLABEL, OnContractlabel)
ON_BN_CLICKED(IDC_HISTORY, OnHistory)
ON_BN_CLICKED(IDC_BTNPM, OnBtnpm)
ON_CBN_CLOSEUP(IDC_CBDEFRATE, OnCloseupCbdefrate)
ON_CBN_CLOSEUP(IDC_CBDEFTRAVEL, OnCloseupCbdeftravel)
ON_BN_CLICKED(IDC_BTNNOTES, OnBtnnotes)
ON_BN_CLICKED(IDC_CONSOLIDATE, OnConsolidate)
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
ON_EN_KILLFOCUS(IDC_EDACCTNUM, OnKillfocusEdacctnum)
ON_COMMAND(ID_CLIENTS_ARAS, OnClientsAras)
//}}AFX_MSG_MAP
ON_WM_INITMENUPOPUP()
ON_COMMAND(ID_NEW_CLIENTRECORD, OnNewClientrecord)
ON_UPDATE_COMMAND_UI(ID_NEW_CLIENTRECORD, OnUpdateNewClientrecord)
ON_COMMAND(ID_NEW_HEADOFFICERECORD, OnNewHeadofficerecord)
ON_UPDATE_COMMAND_UI(ID_NEW_HEADOFFICERECORD, OnUpdateNewHeadofficerecord)
ON_COMMAND(ID_EDIT_DELETETHISRECORD, OnEditDeletethisrecord)
ON_UPDATE_COMMAND_UI(ID_EDIT_DELETETHISRECORD, OnUpdateEditDeletethisrecord)
ON_COMMAND(ID_EDIT_CONSOLIDATETWOCLIENTSTOGETHER, OnEditConsolidatetwoclientstogether)
ON_UPDATE_COMMAND_UI(ID_EDIT_CONSOLIDATETWOCLIENTSTOGETHER, OnUpdateEditConsolidatetwoclientstogether)
ON_UPDATE_COMMAND_UI(ID_CLIENTS_ARAS, OnUpdateClientsAras)
ON_COMMAND(ID_TOOLS_OPENCLIENTNOTEBOOK, OnToolsOpenclientnotebook)
ON_UPDATE_COMMAND_UI(ID_TOOLS_OPENCLIENTNOTEBOOK, OnUpdateToolsOpenclientnotebook)
ON_COMMAND(ID_TOOLS_SCHEDULEPREVENTIVEMAINTENANCEFORTHISCLIENT, OnToolsSchedulepreventivemaintenanceforthisclient)
ON_UPDATE_COMMAND_UI(ID_TOOLS_SCHEDULEPREVENTIVEMAINTENANCEFORTHISCLIENT, OnUpdateToolsSchedulepreventivemaintenanceforthisclient)
ON_COMMAND(ID_TOOLS_DISPLAYRECORDHISTORY, OnToolsDisplayrecordhistory)
ON_UPDATE_COMMAND_UI(ID_TOOLS_DISPLAYRECORDHISTORY, OnUpdateToolsDisplayrecordhistory)
ON_COMMAND(ID_CLOSETHISSCREEN, OnClosethisscreen)
ON_UPDATE_COMMAND_UI(ID_CLOSETHISSCREEN, OnUpdateClosethisscreen)
ON_COMMAND(ID_CLIENT_MENU_HELP, OnClientMenuHelp)
ON_EN_KILLFOCUS(IDC_PHONE2, OnEnKillfocusPhone2)
ON_EN_KILLFOCUS(IDC_PHONE3, OnEnKillfocusPhone3)
ON_BN_CLICKED(IDC_EMAILLABEL, OnEmaillabel)
ON_COMMAND(ID_TOOLS_SETADDRESSDEFAULTS, OnToolsSetaddressdefaults)
/*ON_BN_CLICKED(IDC_CK_INACTIVE, OnBnClickedCkInactive)*/
ON_STN_CLICKED(IDC_LBL_UNITS, OnStnClickedLblUnits)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientsDlg message handlers
void CClientsDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{
ASSERT(pPopupMenu != NULL);
// Check the enabled state of various menu items.
CCmdUI state;
state.m_pMenu = pPopupMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
// Determine if menu is popup in top-level menu and set m_pOther to
// it if so (m_pParentMenu == NULL indicates that it is secondary popup).
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup.
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = this;
// Child windows don't have menus--need to go to the top!
if (pParent != NULL &&
(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
{
// When popup is found, m_pParentMenu is containing menu.
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue; // Menu separator or invalid cmd - ignore it.
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
// Possibly a popup menu, route to first item of that popup.
state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL ||
(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue; // First item of popup can't be routed to.
}
state.DoUpdate(this, TRUE); // Popups are never auto disabled.
}
else
{
// Normal menu item.
// Auto enable/disable if frame window has m_bAutoMenuEnable
// set and command is _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(this, FALSE);
}
// Adjust for menu deletions and additions.
UINT nCount = pPopupMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
BOOL CClientsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Create the control
m_resize.Create( this );
int nVertFactor;//used to scale vertically
int nDelta=0;//change in vertical height
nVertFactor=0;
nDelta=5;
//top row
m_resize.Add(IDC_CLIENTLIST,0,0,100,0);
m_resize.Add(IDC_HEADOFFICE,100,0,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_COMPANY_LABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_COMPANY,0,nVertFactor,100,0);
m_resize.Add(IDC_BILLHEAD,100,nVertFactor,0,0);
m_resize.Add(IDC_HEADOFFICEPICKER,100,nVertFactor,0,0);
m_resize.Add(IDC_HEADOFFICEPICKERLABEL,100,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_FIRSTNAMELABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_FIRSTNAME,0,nVertFactor,28,0);
m_resize.Add(IDC_LASTNAME, 28,nVertFactor,28,0);
m_resize.Add(IDC_LASTNAMELABEL,28,nVertFactor,0,0);
m_resize.Add(IDC_CB_UNITS,50,nVertFactor,50,0);
m_resize.Add(IDC_LBL_UNITS,50,nVertFactor,0,0);
m_resize.Add(IDC_TECHNOTES,50,nVertFactor,50,10);
m_resize.Add(IDC_TECHNOTESLABEL,50,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_MAILADDRESSLABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_MAILADDRESS,0,nVertFactor,28,0);
m_resize.Add(IDC_STREET, 28,nVertFactor,28,0);
m_resize.Add(IDC_STREETLABEL,28,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_CITYLABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_CITY,0,nVertFactor,28,0);
m_resize.Add(IDC_STATEPROVINCE, 28,nVertFactor,28,0);
m_resize.Add(IDC_STATEPROVINCELABEL,28,nVertFactor,0,0);
m_resize.Add(IDC_GENERALNOTES,50,nVertFactor,50,10);
m_resize.Add(IDC_GENERALNOTESLABEL,50,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_POSTALLABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_POSTAL,0,nVertFactor,28,0);
m_resize.Add(IDC_COUNTRY, 28,nVertFactor,28,0);
m_resize.Add(IDC_COUNTRYLABEL,28,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_PHONELABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_PHONE,0,nVertFactor,20,0);
m_resize.Add(IDC_EXTENSION, 20,nVertFactor,0,0);
m_resize.Add(IDC_EXTENSIONLABEL,20,nVertFactor,0,0);
m_resize.Add(IDC_FAX, 20,nVertFactor,37,0);
m_resize.Add(IDC_FAXLABEL,20,nVertFactor,0,0);
m_resize.Add(IDC_ZONE, 50,nVertFactor,20,0);
m_resize.Add(IDC_ZONELABEL,50,nVertFactor,0,0);
m_resize.Add(IDC_EDACCTNUM, 70,nVertFactor,20,0);
m_resize.Add(IDC_LBLACCTNUMBER,70,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_PHONELABEL2,0,nVertFactor,0,0);
m_resize.Add(IDC_PHONE2,0,nVertFactor,28,0);
m_resize.Add(IDC_PHONE3, 28,nVertFactor,28,0);
m_resize.Add(IDC_PHONELABEL3,28,nVertFactor,0,0);
m_resize.Add(IDC_PREFERTECH,50,nVertFactor,50,0);
m_resize.Add(IDC_PREFERTECHLABEL,50,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_EMAILLABEL,0,nVertFactor,0,0);
m_resize.Add(IDC_EMAIL,0,nVertFactor,57,0);
m_resize.Add(IDC_CONTRACT, 50,nVertFactor,20,0);
m_resize.Add(IDC_CONTRACTLABEL,50,nVertFactor,0,0);
m_resize.Add(IDC_CONTRACTEXPIRYDATE,70,nVertFactor,0,0);
m_resize.Add(IDC_CONTRACTEXPIRYLABEL,70,nVertFactor,0,0);
nVertFactor+=nDelta;
m_resize.Add(IDC_LBLDEFRATE,0,nVertFactor,0,0);
m_resize.Add(IDC_CBDEFRATE,0,nVertFactor,57,0);
m_resize.Add(IDC_ALERT, 50,nVertFactor,50,0);
m_resize.Add(IDC_ALERTLABEL,50,nVertFactor,0,0);
m_resize.Add(IDC_LBLTRAVRATE,0,nVertFactor,0,0);
m_resize.Add(IDC_CBDEFTRAVEL,0,nVertFactor,57,0);
//Use the current width and height as the minimum size
m_resize.SetMinimumTrackingSize();
Security();
if(m_pApp->m_strDataVersion=="146")
{
AfxMessageBox(
"Database update 146 has not completed due to duplicate contact names\r\n"
"in the non-company client records\r\n\r\n"
"Only the duplicates that need to be fixed will be shown until the update has completed\r\n\r\n"
"It is recommended that you put a unique number as the last character \r\n"
"of the last name of each duplicate so that they are all unique from each other.\r\n\r\n"
"Once the update has completed you can then go back in and consolidate the duplicates\r\n"
"or delete the extra un-needed clients\r\n\r\n"
"Once you've made this change to all duplicates, restart AyaNova so that the\r\n"
"update can complete. (make sure all other users stay out during this process)");
//m_btnConsolidate.ShowWindow(FALSE);
}
// changes to an hourglass and
// switches back automatically when out of scope
CWaitCursor Wait;
ShowWindow(FALSE);
m_strSelectedClient.Empty();
//make a EMAIL "hyperlink"
m_lblEmail.SetTextColor(RGB(0,0,255));
m_lblEmail.SetFontUnderline(TRUE);
m_lblEmail.SetLink(TRUE);
m_lblEmail.SetLinkCursor(m_pApp->hcHand);
m_lblEmail.SetLinkURL("");
//make a units "hyperlink"
m_lblUnits.SetTextColor(RGB(0,0,255));
m_lblUnits.SetFontUnderline(TRUE);
m_lblUnits.SetLink(TRUE);
m_lblUnits.SetLinkCursor(m_pApp->hcHand);
m_lblUnits.SetLinkURL("");
m_lblAlert.SetFontName("MS Sans Serif");
m_lblAlert.SetFontSize(8);
m_lblAlert.SetFontBold(FALSE);
m_lblAlert.SetTextColor(RGB(255,0,0));
//make a "hyperlink"
m_lblZone.SetTextColor(RGB(0,0,255));
m_lblZone.SetFontUnderline(TRUE);
m_lblZone.SetLink(TRUE);
m_lblZone.SetLinkCursor(m_pApp->hcHand);
//empty url means it will not launch explorer
//and can be used as a button instead
m_lblZone.SetLinkURL("");
m_lblContract.SetTextColor(RGB(0,0,255));
m_lblContract.SetFontUnderline(TRUE);
m_lblContract.SetLink(TRUE);
m_lblContract.SetLinkCursor(m_pApp->hcHand);
m_lblContract.SetLinkURL("");
m_lblHist.SetTextColor(RGB(0,0,255));
m_lblHist.SetFontUnderline(TRUE);
m_lblHist.SetLink(TRUE);
m_lblHist.SetLinkURL("");
m_lblHist.SetLinkCursor(m_pApp->hcHand);
RefreshDisplay(0);//0=client 1=head office.
m_bAddMode=false;
ShowWindow(SW_SHOWMAXIMIZED);
if(!m_strForceSelection.IsEmpty())
{
m_cbClientList.Select(m_strForceSelection);
OnCloseupClientlist();
}
//===================================================
// 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);
//===================================================
//SET DATA ENTRY LIMITS
m_edAcctNum.SetLimitText(40);
m_edAlert.SetLimitText(255);
//m_edTechNotes.SetLimitText(65535);
m_edStreet.SetLimitText(255);
m_edStateProv.SetLimitText(30);
m_edPostal.SetLimitText(20);
m_edPhone.SetLimitText(20);
m_edPhone2.SetLimitText(40);
m_edPhone3.SetLimitText(40);
m_edMail.SetLimitText(100);
m_edLast.SetLimitText(50);
//m_edGenNotes
m_edFirst.SetLimitText(50);
m_edFax.SetLimitText(20);
m_edExtension.SetLimitText(10);
m_edCountry.SetLimitText(30);
m_edCompany.SetLimitText(80);
m_edCity.SetLimitText(30);
//ShowWindow(TRUE);
m_edGenNotes.SetFocus();
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
bool CClientsDlg::FillClientList()
{
CString strData,strTemp;
CString strIndex;
CString strHead,q;
if(m_ckShowHeadOfficeCheck.GetCheck()==TRUE)
strHead="True";
else
strHead="False";
long lData;
m_cbClientList.Clear();
//added 08/03/2001 to handle client change
if(m_pApp->m_strDataVersion=="146")
{
q.Format("SELECT clients.last, clients.first, clients.id, clients.company as compname "
"FROM clients "
"WHERE (((clients.last) In (SELECT [last] FROM [clients] As Tmp GROUP BY [last],[first] HAVING Count(*)>1 And [first] = [clients].[first])) AND ((clients.isheadoffice)=%s) AND ((clients.company) Is Null)) "
"ORDER BY clients.last, clients.first;",strHead);
/*
q.Format("SELECT clients.id, clients.first, clients.last, clients.company AS compname FROM clients WHERE (((clients.isheadoffice)=%s)) "
"AND (((clients.company) Is Null)) ORDER BY clients.last, clients.first;",strHead);
*/
}
else
{
q.Format("SELECT clients.id, clients.company AS compname FROM clients WHERE (((clients.isheadoffice)=%s)) "
"ORDER BY clients.company;",strHead);
}
rs->Close();
rs->Query(q);
if(!rs->IsEmpty())
{
//fill combo box with available clients
//added 08/03/2001 to handle client change
if(m_pApp->m_strDataVersion=="146")
{
rs->FetchField("last",&strTemp);
strData=strTemp;
rs->FetchField("first",&strTemp);
strData+=", " + strTemp;
}
else
rs->FetchField("compname",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbClientList.AddRow(strData,strIndex);
while(rs->MoveForward())
{
//added 08/03/2001 to handle client change
if(m_pApp->m_strDataVersion=="146")
{
rs->FetchField("last",&strTemp);
strData=strTemp;
rs->FetchField("first",&strTemp);
strData+=", " + strTemp;
}
else
rs->FetchField("compname",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbClientList.AddRow(strData,strIndex);
}
//pretend user has selected so that other fields get filled in
if(m_strSelectedClient.IsEmpty()) //first time in
{
m_cbClientList.SetCurSel(0);
m_strSelectedClient=m_cbClientList.GetCurrentRowID();
if(m_pstrReturnValue!=NULL)
m_pstrReturnValue->Format("%s",m_strSelectedClient);
}
else//something valid was selected before so stick with it
m_cbClientList.Select(m_strSelectedClient);
FillFields();
//FillUnitList();
}//is no records?
else//nope
{
BlankAllFields(false,false);
}
return true;
}
//*****************************************************
bool CClientsDlg::RefreshDisplay(int dMode/*0=standard 1=headoffice 2=add*/)
{
switch(dMode)
{
case 0://standard client edit mode
//m_strSelectedClient="";
m_cbClientList.ShowWindow(TRUE);
m_lblClientListLabel.ShowWindow(TRUE);
//m_btnPM.ShowWindow(TRUE);
//m_btnAdd.SetWindowText("Add");
if(!m_bReadOnly)
{
//m_btnAdd.ShowWindow(TRUE);
//m_btnDelete.ShowWindow(TRUE);
//m_btnConsolidate.ShowWindow(TRUE);
//m_btnAddHead.ShowWindow(TRUE);
}
//m_btnDone.SetWindowText("Close");
//m_btnNotes.ShowWindow(TRUE);
//m_btnAddHead.SetWindowText("Add head office");
m_ckShowHeadOfficeCheck.ShowWindow(TRUE);
m_cbHeadOffice.ShowWindow(TRUE);
m_lblHeadOffice.ShowWindow(TRUE);
m_ckBillHead.ShowWindow(TRUE);
m_edTechNotes.ShowWindow(TRUE);
m_lblTechNotes.ShowWindow(TRUE);
m_lblGenNotes.ShowWindow(TRUE);
m_edGenNotes.ShowWindow(TRUE);
m_lblZone.ShowWindow(TRUE);
m_lblUnits.ShowWindow(TRUE);
m_cbUnits.ShowWindow(TRUE);
m_cbZone.ShowWindow(TRUE);
m_lblPreferTech.ShowWindow(TRUE);
m_cbPreferTech.ShowWindow(TRUE);
//m_lblContractNotes.ShowWindow(FALSE);
m_lblCompany.SetWindowText("Client: (Person or company. Required.)");
FillHeadOfficeList();
FillTechList();
FillZoneList();
FillContractList();
FillRatesLists();
FillClientList();
FillUnitList();
break;
case 1://headoffices only mode
//m_strSelectedClient="";
m_lblCompany.SetWindowText("Head office:");
//m_btnAdd.ShowWindow(FALSE);
//m_btnPM.ShowWindow(FALSE);
m_cbClientList.ShowWindow(TRUE);
m_lblClientListLabel.ShowWindow(TRUE);
//m_btnAdd.SetWindowText("Add");
//m_btnDone.SetWindowText("Close");
if(!m_bReadOnly)
{
//m_btnDelete.ShowWindow(TRUE);
//m_btnAddHead.ShowWindow(TRUE);
//m_btnConsolidate.ShowWindow(TRUE);
}
//m_btnAddHead.SetWindowText("Add head office");
m_ckShowHeadOfficeCheck.ShowWindow(TRUE);
//m_btnNotes.ShowWindow(TRUE);
//m_btnConsolidate.ShowWindow(FALSE);
m_cbHeadOffice.ShowWindow(FALSE);
m_lblHeadOffice.ShowWindow(FALSE);
m_ckBillHead.ShowWindow(FALSE);
m_edTechNotes.ShowWindow(FALSE);
m_lblTechNotes.ShowWindow(FALSE);
m_lblGenNotes.ShowWindow(FALSE);
m_edGenNotes.ShowWindow(FALSE);
m_lblZone.ShowWindow(FALSE);
m_cbZone.ShowWindow(FALSE);
m_lblUnits.ShowWindow(FALSE);
m_cbUnits.ShowWindow(FALSE);
m_lblPreferTech.ShowWindow(FALSE);
m_cbPreferTech.ShowWindow(FALSE);
//m_lblContractNotes.ShowWindow(TRUE);
FillClientList();
break;
case 2://add client mode
m_lblCompany.SetWindowText("Client: (Person or company. Required.)");
m_cbClientList.ShowWindow(FALSE);
m_lblClientListLabel.ShowWindow(FALSE);
//m_btnPM.ShowWindow(FALSE);
//m_btnAdd.SetWindowText("SAVE");
//m_btnDone.SetWindowText("Cancel");
//m_btnDelete.ShowWindow(FALSE);
//m_btnNotes.ShowWindow(FALSE);
//m_btnConsolidate.ShowWindow(FALSE);
//m_btnAddHead.ShowWindow(FALSE);
m_ckShowHeadOfficeCheck.ShowWindow(FALSE);
BlankAllFields(true,true);
break;
case 3://add head office mode
m_lblCompany.SetWindowText("Head office:");
m_cbClientList.ShowWindow(FALSE);
//m_btnPM.ShowWindow(FALSE);
m_lblClientListLabel.ShowWindow(FALSE);
//m_btnAddHead.SetWindowText("SAVE");
//m_btnDone.SetWindowText("Cancel");
//m_btnDelete.ShowWindow(FALSE);
//m_btnNotes.ShowWindow(FALSE);
//m_btnConsolidate.ShowWindow(FALSE);
//m_btnAdd.ShowWindow(FALSE);
m_ckShowHeadOfficeCheck.ShowWindow(FALSE);
BlankAllFields(true,true);
//m_btnAddHead.ShowWindow(TRUE);
m_cbHeadOffice.ShowWindow(FALSE);
m_lblHeadOffice.ShowWindow(FALSE);
m_ckBillHead.ShowWindow(FALSE);
m_edTechNotes.ShowWindow(FALSE);
m_lblTechNotes.ShowWindow(FALSE);
m_lblGenNotes.ShowWindow(FALSE);
m_edGenNotes.ShowWindow(FALSE);
m_lblZone.ShowWindow(FALSE);
m_cbZone.ShowWindow(FALSE);
m_lblPreferTech.ShowWindow(FALSE);
m_cbPreferTech.ShowWindow(FALSE);
//m_lblContractNotes.ShowWindow(TRUE);
break;
}
if(m_bReadOnly)
{
//m_btnAdd.ShowWindow(FALSE);
//m_btnAddHead.ShowWindow(FALSE);
//m_btnConsolidate.ShowWindow(FALSE);
//m_btnDelete.ShowWindow(FALSE);
//m_btnNotes.ShowWindow(FALSE);
m_ckBillHead.EnableWindow(FALSE);
m_cbRate.EnableWindow(FALSE);
m_cbDefTravelRate.EnableWindow(FALSE);
//m_ckShowHeadOfficeCheck.EnableWindow(FALSE);
m_dtContractExpiryDate.EnableWindow(FALSE);
m_edAlert.SetReadOnly(TRUE);
m_edCity.SetReadOnly(TRUE);
m_edCompany.SetReadOnly(TRUE);
m_edCountry.SetReadOnly(TRUE);
m_edEmail.SetReadOnly(TRUE);
m_edExtension.SetReadOnly(TRUE);
m_edFax.SetReadOnly(TRUE);
m_edFirst.SetReadOnly(TRUE);
m_edGenNotes.SetReadOnly(TRUE);
m_edLast.SetReadOnly(TRUE);
m_edMail.SetReadOnly(TRUE);
m_edPhone.SetReadOnly(TRUE);
m_edPostal.SetReadOnly(TRUE);
m_edStateProv.SetReadOnly(TRUE);
m_edStreet.SetReadOnly(TRUE);
m_edTechNotes.SetReadOnly(TRUE);
m_edAcctNum.EnableWindow(FALSE);
}
return true;
}
void CClientsDlg::OnCloseupClientlist()
{
CString strTemp;
strTemp=m_cbClientList.GetCurrentRowID();
//jump back if same client
if(strTemp==m_strSelectedClient) return;
//save current selection so that updates and changes
//will still show what was last selected
m_strSelectedClient=strTemp;
if(m_pstrReturnValue!=NULL)
m_pstrReturnValue->Format("%s",m_strSelectedClient);
FillFields();
//v1.9.4.4 moved to fill fields function
//FillUnitList();
}
void CClientsDlg::OnHeadoffice()
{
//user clicked the head office only checkbox
if(m_ckShowHeadOfficeCheck.GetCheck()==TRUE)
RefreshDisplay(1);//head office mode
else
RefreshDisplay(0);//normal mode
}
bool CClientsDlg::FillFields()
{
CString q;
CString strData,strRecStatus;
bool bData;
BOOL intbData;
long lData;
COleDateTime dtData;
//v1.9.4.5
bool bRefreshTechList=false;
q=m_cbClientList.GetCurrentRowID();
if(q.IsEmpty()) //then there is no record to display, show blanks instead
{
BlankAllFields(false,false);
return false;
}
BlankAllFields(false,true);
rs->Close();
q.Format("SELECT clients.* FROM clients WHERE (((clients.id)=%s));",m_cbClientList.GetCurrentRowID());
rs->Query(q);
if(!rs->IsEmpty())
{
rs->FetchField("first",&strData);
m_edFirst.SetWindowText(strData);
rs->FetchField("czone",&lData);
strData.Format("%u",lData);
m_cbZone.Select(strData);
rs->FetchField("defrate",&lData);
strData.Format("%u",lData);
m_cbRate.Select(strData);
rs->FetchField("deftravelrate",&lData);
strData.Format("%u",lData);
m_cbDefTravelRate.Select(strData);
rs->FetchField("headoffice",&lData);
strData.Format("%u",lData);
m_cbHeadOffice.Select(strData);
rs->FetchField("billheadoffice",&bData);
intbData=TRUE;
if(bData==false) intbData=FALSE;
m_ckBillHead.SetCheck(intbData);
rs->FetchField("alert",&strData);
m_edAlert.SetWindowText(strData);
rs->FetchField("technotes",&strData);
m_edTechNotes.SetWindowText(strData);
rs->FetchField("streetaddress",&strData);
m_edStreet.SetWindowText(strData);
rs->FetchField("stateprov",&strData);
m_edStateProv.SetWindowText(strData);
rs->FetchField("prefertech",&lData);
//v1.9.4.5, now sets in fill tech list
if(lData!=lPreferredTech)
{
lPreferredTech=lData;
bRefreshTechList=true;
}
//strData.Format("%u",lData);
//m_cbPreferTech.Select(strData);
rs->FetchField("postal",&strData);
m_edPostal.SetWindowText(strData);
rs->FetchField("bizphone",&strData);
m_edPhone.SetWindowText(strData);
rs->FetchField("phone2",&strData);
m_edPhone2.SetWindowText(strData);
rs->FetchField("phone3",&strData);
m_edPhone3.SetWindowText(strData);
rs->FetchField("mailaddress",&strData);
m_edMail.SetWindowText(strData);
rs->FetchField("last",&strData);
m_edLast.SetWindowText(strData);
//m_cbHeadOffice;
rs->FetchField("generalnotes",&strData);
m_edGenNotes.SetWindowText(strData);
rs->FetchField("fax",&strData);
m_edFax.SetWindowText(strData);
rs->FetchField("extension",&strData);
m_edExtension.SetWindowText(strData);
rs->FetchField("email",&strData);
m_edEmail.SetWindowText(strData);
rs->FetchField("acctnumber",&strData);
m_edAcctNum.SetWindowText(strData);
rs->FetchField("country",&strData);
m_edCountry.SetWindowText(strData);
rs->FetchField("contract",&lData);
strData.Format("%u",lData);
m_cbContract.Select(strData);
if(lData==0) //means no contract
{
m_dtContractExpiryDate.ShowWindow(FALSE);
m_lblContractExpiry.ShowWindow(FALSE);
}
else
{
m_dtContractExpiryDate.ShowWindow(TRUE);
m_lblContractExpiry.ShowWindow(TRUE);
}
if(rs->FetchField("contractexpires",&dtData)==0)
dtData=COleDateTime::GetCurrentTime();//set to today if no value
m_dtContractExpiryDate.SetTime(dtData);
rs->FetchField("company",&strData);
m_edCompany.SetWindowText(strData);
rs->FetchField("city",&strData);
m_edCity.SetWindowText(strData);
//Set recordset back to original
q.Format("SELECT clients.* FROM clients WHERE (((clients.id)=%s));",m_cbClientList.GetCurrentRowID());
rs->Query(q);
}
//v1.9.4.4 added and removed from wherever it was called separately
//since it should always go hand in hand with fillfields
FillUnitList();
//v1.9.4.5
if(bRefreshTechList)
FillTechList();
return true;
}
bool CClientsDlg::FillZoneList()
{
CString strData;
CString strIndex;
long lData;
m_cbZone.Clear();
m_cbZone.AddRow("<No Zone>","0");
rs->Query("SELECT zones.* FROM zones ORDER BY zones.name;");
if(!rs->IsEmpty())
{
//fill combo box with available zones
//rs->MoveFirst();
rs->FetchField("name",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbZone.AddRow(strData,strIndex);
while(rs->MoveForward())
{
rs->FetchField("name",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbZone.AddRow(strData,strIndex);
}
}
return true;
}
bool CClientsDlg::FillTechList()
{
CString strData;
CString strIndex;
long lData;
m_cbPreferTech.Clear();
CString q;
//----------
//v1.9.4.5
//If there is a selected client,
//Get preferred tech and see if inactive, if so
//add to the list manually
if(lPreferredTech!=0)
{
q.Format("SELECT users.id, [last] & \", \" & [first] AS fullname "
"FROM users "
"WHERE (((users.id)=%u) AND ((users.active)=False));",lPreferredTech);
rs2->QueryReadOnly(q);
if(!rs2->IsEmpty()) //it's an inactive tech put them in the list "manually"
{
rs2->FetchField("fullname",&strData);
rs2->FetchField("id",&lData);
strIndex.Format("%u",lData);
q="<NA> " + strData;
m_cbPreferTech.AddRow(q,strIndex);
}
}
//1.9.4.4 was: rs2->QueryReadOnly("SELECT users.id, [last] & \", \" & [first] AS fullname FROM users WHERE (((users.tech)=True)) ORDER BY users.last;");
//1.9.4.5 is now:
rs2->QueryReadOnly("SELECT users.id, [last] & \", \" & [first] AS fullname FROM users "
"WHERE (((users.id)<>1) AND ((users.tech)=True) AND ((users.active)=True)) "
"ORDER BY users.last;");
//v1.9.4.5 changed query above so inactive techs are not displayed in the
//preferred tech list
m_cbPreferTech.AddRow("<Any Tech>","0");
if(!rs2->IsEmpty())
{
do
{
rs2->FetchField("fullname",&strData);
rs2->FetchField("id",&lData);
if(lData!=1)
{
strIndex.Format("%u",lData);
m_cbPreferTech.AddRow(strData,strIndex);
}
}while(rs2->MoveForward());
}
m_cbPreferTech.Select(lPreferredTech);
return true;
}
bool CClientsDlg::FillContractList()
{
CString strData;
CString strIndex;
long lData;
m_cbContract.Clear();
m_cbContract.AddRow("<No Contract>","0");
rs->Query("SELECT contracts.* FROM contracts ORDER BY contracts.name;");
if(!rs->IsEmpty())
{
//fill combo box with available contracts
//rs->MoveFirst();
rs->FetchField("name",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbContract.AddRow(strData,strIndex);
while(rs->MoveForward())
{
rs->FetchField("name",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbContract.AddRow(strData,strIndex);
}
}
return true;
}
//************************************************************
//SAVE EDIT CONTROL FIELD
//************************************************************
bool CClientsDlg::SaveField(CEdit *edControl,CString fldname,bool AllowEmpty)
{
if(m_bAddMode) return true;//dont attempt to update
CString str;
//do nothing if not changed
if(edControl->GetModify()!=TRUE) return true;
if(!EditPrompt()) return true;
edControl->GetWindowText(str);
//dont save empty fields if not allowed to
if(!AllowEmpty)
{
if(str.IsEmpty())
{
edControl->Undo();
return false;
}
}
rs->pTheConnection->BeginTrans();
rs->UpdateField(fldname,&str);
if(!rs->SaveRecord())
{
rs->pTheConnection->RollbackTrans();
edControl->Undo();
edControl->SetModify(FALSE);
return false;
}
rs->pTheConnection->CommitTrans();
UpdateModified();
return true;
}
//************************************************************
//SAVE GZCOMBO CONTROL FIELD
//************************************************************
bool CClientsDlg::SaveField(CgzCombo *cbControl,CString fldname)
{
if(m_bAddMode) return true;//dont attempt to update
if(!EditPrompt()) return false;
CString str;
long lData;
str=cbControl->GetCurrentRowID();
if(str.IsEmpty()) return false;//shouldn't happen but...
lData=atol(str);
rs->pTheConnection->BeginTrans();
rs->UpdateField(fldname,&lData);
rs->SaveRecord();
rs->pTheConnection->CommitTrans();
UpdateModified();
return true;
}
//************************************************************
//SAVE CheckBox CONTROL FIELD
//************************************************************
bool CClientsDlg::SaveField(CButton *ckControl,CString fldname)
{
if(m_bAddMode) return true;//dont attempt to update
if(!EditPrompt()) return false;
bool bData=false;
BOOL BData;
BData=ckControl->GetCheck();
if(BData==TRUE) bData=true;
rs->pTheConnection->BeginTrans();
rs->UpdateField(fldname,&bData);
rs->SaveRecord();
rs->pTheConnection->CommitTrans();
UpdateModified();
return true;
}
//************************************************************
//SAVE DateTimePicker CONTROL FIELD
//************************************************************
bool CClientsDlg::SaveField(CDateTimeCtrl *dtControl,CString fldname)
{
if(m_bAddMode) return true;//dont attempt to update
if(!EditPrompt()) return false;
COleDateTime dtData;
dtControl->GetTime(dtData);
rs->pTheConnection->BeginTrans();
rs->UpdateField(fldname,&dtData);
rs->SaveRecord();
rs->pTheConnection->CommitTrans();
UpdateModified();
return true;
}
//************************************************
//UPDATE MODIFIED DATA
//*************************************************
bool CClientsDlg::UpdateModified()
{
bool bIndexed=false;
//updates modified by and modified on fields
rs->UpdateField("modifier",&m_pApp->m_lusrID);
COleDateTime dtData;
dtData=COleDateTime::GetCurrentTime();
rs->UpdateField("modified",&dtData);
//flag for indexing
rs->pTheConnection->BeginTrans();
rs->UpdateField("indexed",&bIndexed);
rs->SaveRecord();
rs->pTheConnection->CommitTrans();
return true;
}
//*************************************************
//DELETE RECORD
//*************************************************
void CClientsDlg::OnDelete()
{
}
//********************************************************
void CClientsDlg::OnAdd()
{
// Add/save client record
if(m_bAddMode)//then user has clicked SAVE
{
//validate and save
if(!AddRecord(false))
return;
if(m_ckShowHeadOfficeCheck.GetCheck()==TRUE)
RefreshDisplay(1);//head office mode
else
RefreshDisplay(0);//normal mode
m_bAddMode=false;
}
else //user has just clicked add
{
//switch to add client mode
m_bAddMode=true;
RefreshDisplay(2);//add client mode
SetDefaults();
}
}
//***********************************************************
void CClientsDlg::OnAddhead()
{
// Add head office record
// Add/save client record
if(m_bAddMode)//then we user has clicked SAVE
{
//validate and save
AddRecord(true);
if(m_ckShowHeadOfficeCheck.GetCheck()==TRUE)
RefreshDisplay(1);//head office mode
else
RefreshDisplay(0);//normal mode
m_bAddMode=false;
}
else //user has just clicked add
{
//switch to add client mode
m_bAddMode=true;
RefreshDisplay(3);//add head mode
SetDefaults();
}
}
//**********************************************************
void CClientsDlg::OnOK()
{
/*
if(m_bAddMode)//then user has pressed cancel button
{
//revert to previous view and save changes
if(m_ckShowHeadOfficeCheck.GetCheck()==TRUE)
RefreshDisplay(1);//head office mode
else
RefreshDisplay(0);//normal mode
m_bAddMode=false;
}
else
{
if(m_pstrReturnValue!=NULL)
m_pstrReturnValue->Format("%s",m_strSelectedClient);
CDialog::OnOK();
}
*/
}
//****************************************************
void CClientsDlg::BlankAllFields(bool bSetDefaults,bool bEnable)
{
BOOL e=FALSE;
if(bEnable) e=TRUE;
m_edPhone2.SetWindowText("");
m_edPhone2.EnableWindow(e);
m_edPhone3.SetWindowText("");
m_edPhone3.EnableWindow(e);
m_cbUnits.Clear();
m_edAcctNum.SetWindowText("");
m_edAcctNum.EnableWindow(e);
m_cbZone.Select("0");//any zone
m_cbZone.EnableWindow(e);
m_cbRate.Select("0");
m_cbDefTravelRate.Select("0");
m_cbRate.EnableWindow(e);
m_cbDefTravelRate.EnableWindow(e);
m_ckBillHead.SetCheck(FALSE);
m_ckBillHead.EnableWindow(e);
m_edAlert.SetWindowText("");
m_edAlert.EnableWindow(e);
m_edTechNotes.SetWindowText("");
m_edTechNotes.EnableWindow(e);
m_edStreet.SetWindowText("");
m_edStreet.EnableWindow(e);
m_cbPreferTech.Select("0");
m_cbPreferTech.EnableWindow(e);
m_edPhone.SetWindowText("");
m_edPhone.EnableWindow(e);
m_edMail.SetWindowText("");
m_edMail.EnableWindow(e);
m_edLast.SetWindowText("");
m_edLast.EnableWindow(e);
m_cbHeadOffice.Select("0");
m_cbHeadOffice.EnableWindow(e);
m_edGenNotes.SetWindowText("");
m_edGenNotes.EnableWindow(e);
m_edFirst.SetWindowText("");
m_edFirst.EnableWindow(e);
m_edFax.SetWindowText("");
m_edFax.EnableWindow(e);
m_edExtension.SetWindowText("");
m_edExtension.EnableWindow(e);
m_edEmail.SetWindowText("");
m_edEmail.EnableWindow(e);
m_cbContract.Select("0");
m_cbContract.EnableWindow(e);
m_edCompany.SetWindowText("");
m_edCompany.EnableWindow(e);
m_dtContractExpiryDate.SetTime( COleDateTime::GetCurrentTime());
m_dtContractExpiryDate.EnableWindow(e);
if(bSetDefaults)
{
//set the defaultable fields to their defaults
rs->Query("SELECT defaults.* FROM defaults;");
CString data;
rs->FetchField("city",&data);
m_edCity.SetWindowText(data);
rs->FetchField("country",&data);
m_edCountry.SetWindowText(data);
rs->FetchField("postal",&data);
m_edPostal.SetWindowText(data);
rs->FetchField("stateprov",&data);
m_edStateProv.SetWindowText(data);
}
else
{
m_edCity.SetWindowText("");
m_edCountry.SetWindowText("");
m_edPostal.SetWindowText("");
m_edStateProv.SetWindowText("");
}
m_edCity.EnableWindow(e);
m_edCountry.EnableWindow(e);
m_edPostal.EnableWindow(e);
m_edStateProv.EnableWindow(e);
}
//*********************************************************
bool CClientsDlg::AddRecord(bool bIsHeadOffice)
{
CString q;
CString strData;
bool bData;
BOOL intbData;
long lData,lNewID;
COleDateTime dtData;
// m_edLast.GetWindowText(strData);
m_edCompany.GetWindowText(q);
//make sure there is at least a company or last name
if(q.IsEmpty())
{
AfxMessageBox("You must enter a client name to proceed");
return false;
}
dtData=COleDateTime::GetCurrentTime();
q.Format("INSERT INTO clients ( creator, created, modifier, modified ) "
"SELECT %u, #%s#, %u, #%s#;",
m_pApp->m_lusrID,dtData.Format(_T("%m/%d/%Y %H:%M:%S")),
m_pApp->m_lusrID,dtData.Format(_T("%m/%d/%Y %H:%M:%S")));
rs->Ex(q,&lNewID);
rs->Close();
q.Format("SELECT clients.* FROM clients WHERE (((clients.id)=%u));",lNewID);
rs->Query(q);
ASSERT(!rs->IsEmpty());
m_strSelectedClient.Format("%u",lNewID);
//go through the fields one by one
rs->pTheConnection->BeginTrans();
//first set non-visible fields
bData=false;
if(bIsHeadOffice)
bData=true;
rs->UpdateField("isheadoffice",&bData);
//now set visible items
m_edFirst.GetWindowText(strData);
rs->UpdateField("first",&strData);
strData=m_cbZone.GetCurrentRowID();
lData=atol(strData);
rs->UpdateField("czone",&lData);
bData=true;
intbData=m_ckBillHead.GetCheck();
if(intbData==FALSE)
bData=false;
rs->UpdateField("billheadoffice",&bData);
m_edAlert.GetWindowText(strData);
rs->UpdateField("alert",&strData);
m_edTechNotes.GetWindowText(strData);
rs->UpdateField("technotes",&strData);
m_edStreet.GetWindowText(strData);
rs->UpdateField("streetaddress",&strData);
m_edStateProv.GetWindowText(strData);
rs->UpdateField("stateprov",&strData);
strData=m_cbPreferTech.GetCurrentRowID();
lData=atol(strData);
rs->UpdateField("prefertech",&lData);
m_edPostal.GetWindowText(strData);
rs->UpdateField("postal",&strData);
m_edPhone.GetWindowText(strData);
rs->UpdateField("bizphone",&strData);
m_edMail.GetWindowText(strData);
rs->UpdateField("mailaddress",&strData);
m_edLast.GetWindowText(strData);
rs->UpdateField("last",&strData);
strData=m_cbHeadOffice.GetCurrentRowID();
lData=atol(strData);
rs->UpdateField("prefertech",&lData);
m_edGenNotes.GetWindowText(strData);
rs->UpdateField("generalnotes",&strData);
m_edFax.GetWindowText(strData);
rs->UpdateField("fax",&strData);
m_edExtension.GetWindowText(strData);
rs->UpdateField("extension",&strData);
m_edEmail.GetWindowText(strData);
rs->UpdateField("email",&strData);
m_edCountry.GetWindowText(strData);
rs->UpdateField("country",&strData);
strData=m_cbContract.GetCurrentRowID();
lData=atol(strData);
rs->UpdateField("contract",&lData);
m_dtContractExpiryDate.GetTime(dtData);
rs->UpdateField("contractexpires",&dtData);
m_edCompany.GetWindowText(strData);
rs->UpdateField("company",&strData);
m_edCity.GetWindowText(strData);
rs->UpdateField("city",&strData);
//account number...whoops! about 20 releases overdue
m_edAcctNum.GetWindowText(strData);
rs->UpdateField("acctnumber",&strData);
if(!rs->SaveRecord())
{
rs->RecordSetPointer()->CancelUpdate();
rs->pTheConnection->RollbackTrans();
m_strSelectedClient="0";
}
rs->pTheConnection->CommitTrans();
//q.Format("SELECT clients.* FROM clients;");
//rs->Query(q);
rs->Close();
return true;
}
//*******************************************
void CClientsDlg::OnKillfocusFirstname()
{
SaveField(&m_edFirst,"first",true);
}
//*****************************************8
void CClientsDlg::OnKillfocusCompany()
{
//bool allowblank=false;
/*
CString str;
m_edLast.GetWindowText(str);
if(str.IsEmpty()) allowblank=false;
*/
if(m_edCompany.GetModify()==false) return;
//Check for duplicate before saving
CString q;
CString str;
m_edCompany.GetWindowText(str);
if(str.IsEmpty()) return;
//check if it's just the same as before
m_cbClientList.GetWindowText(q);
if(q==str) return;
q.Format("SELECT clients.company "
"FROM clients WHERE (((clients.company)=\"%s\"));",str);
rs2->QueryReadOnly(q);
if(!rs2->IsEmpty())
{
q.Format("Client %s is already in the database\r\n"
"Every client name must be unique in AyaNova.",str);
AfxMessageBox(q);
m_edCompany.Undo();
m_edCompany.SetModify(FALSE);
m_edCompany.SetFocus();
return;
}
SaveField(&m_edCompany,"company",false);
m_edCompany.SetModify(FALSE);
if(!m_bAddMode) FillClientList();
}
void CClientsDlg::OnKillfocusLastname()
{
bool allowblank=true;
CString str;
m_edCompany.GetWindowText(str);
if(str.IsEmpty()) allowblank=false;
SaveField(&m_edLast,"last",allowblank);
}
void CClientsDlg::OnKillfocusMailaddress()
{
SaveField(&m_edMail,"mailaddress",true);
}
void CClientsDlg::OnKillfocusStreet()
{
SaveField(&m_edStreet,"streetaddress",true);
}
void CClientsDlg::OnKillfocusCity()
{
SaveField(&m_edCity,"city",true);
}
void CClientsDlg::OnKillfocusStateprovince()
{
SaveField(&m_edStateProv,"stateprov",true);
}
void CClientsDlg::OnKillfocusPostal()
{
SaveField(&m_edPostal,"postal",true);
}
void CClientsDlg::OnKillfocusCountry()
{
SaveField(&m_edCountry,"country",true);
}
void CClientsDlg::OnKillfocusPhone()
{
SaveField(&m_edPhone,"bizphone",true);
}
void CClientsDlg::OnKillfocusExtension()
{
SaveField(&m_edExtension,"extension",true);
}
void CClientsDlg::OnKillfocusEmail()
{
SaveField(&m_edEmail,"email",true);
}
void CClientsDlg::OnKillfocusFax()
{
SaveField(&m_edFax,"fax",true);
}
void CClientsDlg::OnCloseupHeadofficepicker()
{
SaveField(&m_cbHeadOffice,"headoffice");
}
void CClientsDlg::OnBillhead()
{
SaveField(&m_ckBillHead,"billheadoffice");
}
void CClientsDlg::OnKillfocusTechnotes()
{
SaveField(&m_edTechNotes,"technotes",true);
}
void CClientsDlg::OnKillfocusGeneralnotes()
{
SaveField(&m_edGenNotes,"generalnotes",true);
}
//**********************************************
void CClientsDlg::OnCloseupContract()
{
if(m_cbContract.GetCurrentRowID()=="0") //means no contract
{
m_dtContractExpiryDate.ShowWindow(FALSE);
m_lblContractExpiry.ShowWindow(FALSE);
}
else
{
m_dtContractExpiryDate.ShowWindow(TRUE);
m_lblContractExpiry.ShowWindow(TRUE);
}
SaveField(&m_cbContract,"contract");
}
void CClientsDlg::OnCloseupZone()
{
SaveField(&m_cbZone,"czone");
}
void CClientsDlg::OnCloseupPrefertech()
{
SaveField(&m_cbPreferTech,"prefertech");
}
void CClientsDlg::OnDatetimechangeContractexpirydate(NMHDR* pNMHDR, LRESULT* pResult)
{
SaveField(&m_dtContractExpiryDate,"contractexpires");
*pResult = 0;
}
void CClientsDlg::OnKillfocusAlert()
{
SaveField(&m_edAlert,"alert",true);
}
bool CClientsDlg::FillHeadOfficeList()
{
CString strData;
CString strIndex;
long lData;
m_cbHeadOffice.Clear();
m_cbHeadOffice.AddRow("<No head-office>","0");
if(!rs->Query("SELECT clients.* FROM clients WHERE (((clients.isheadoffice)=True)) "
"ORDER BY clients.company;"))
return false;
if(!rs->IsEmpty())
{
//fill combo box with available headoffices
//rs->MoveFirst();
rs->FetchField("company",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbHeadOffice.AddRow(strData,strIndex);
while(rs->MoveForward())
{
rs->FetchField("company",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbHeadOffice.AddRow(strData,strIndex);
}
}
return true;
}
void CClientsDlg::OnZonelabel()
{
CString s;
s=m_cbZone.GetCurrentRowID();
CZonesDlg d;
if(d.DoModal()==IDOK)
{
FillZoneList();
m_cbZone.Select(s);
if(!m_bAddMode)
FillFields();
}
}
void CClientsDlg::OnContractlabel()
{
CString s;
s=m_cbContract.GetCurrentRowID();
CContractsDlg dlg;
if(dlg.DoModal()==IDOK)
{
FillContractList();
m_cbContract.Select(s);
FillFields();
}
}
void CClientsDlg::SetReturnString(CString *ret)
{
m_pstrReturnValue=ret;
}
void CClientsDlg::OnHistory()
{
}
//Preventative maintenance scheduling
void CClientsDlg::OnBtnpm()
{
}
void CClientsDlg::SetDefaults()
{
CString strData;
rs2->Query("SELECT * FROM defaults;");
rs2->FetchField("city",&m_strDefaultCity);
if(m_strDefaultCity.IsEmpty())
m_strDefaultCity=" ";
//m_edCity.SetWindowText(strData);
rs2->FetchField("stateprov",&m_strDefaultStateProv);
if(m_strDefaultStateProv.IsEmpty())
m_strDefaultStateProv=" ";
//m_edStateProv.SetWindowText(strData);
rs2->FetchField("postal",&m_strDefaultPostal);
if(m_strDefaultPostal.IsEmpty())
m_strDefaultPostal=" ";
//m_edPostal.SetWindowText(strData);
rs2->FetchField("country",&m_strDefaultCountry);
if(m_strDefaultCountry.IsEmpty())
m_strDefaultCountry=" ";
//m_edCountry.SetWindowText(strData);
}
void CClientsDlg::Security()
{
int x=m_pApp->Allowed(RCLIENTS,true);
if(x==0)
{
m_pApp->SecurityWarning();
CDialog::OnCancel();
}
if(x==2)
m_bReadOnly=true;
else
m_bReadOnly=false;
//disable PM button?
m_bPMAllowed=true;
x=m_pApp->Allowed(RPM,true);
if(x==0)//no access allowed
{
m_bPMAllowed=false;
//m_btnPM.EnableWindow(FALSE);
}
}
void CClientsDlg::OnCloseupCbdefrate()
{
SaveField(&m_cbRate,"defrate");
}
void CClientsDlg::OnCloseupCbdeftravel()
{
SaveField(&m_cbDefTravelRate,"deftravelrate");
}
void CClientsDlg::FillRatesLists()
{
//fill travel and regular rates list boxes
CString strData;
CString strIndex;
long lData;
bool bData;
m_cbDefTravelRate.Clear();
m_cbRate.Clear();
m_cbDefTravelRate.AddRow(" <no default>","0");
m_cbRate.AddRow(" <no default>","0");
rs->Query("SELECT rates.* FROM rates ORDER BY rates.name;");
if(!rs->IsEmpty())
{
//fill combo box with available categories
rs->MoveFirst();
rs->FetchField("travelrate",&bData);
rs->FetchField("name",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
if(bData==true)//it's a travel rate
m_cbDefTravelRate.AddRow(strData,strIndex);
else
m_cbRate.AddRow(strData,strIndex);
while(rs->MoveForward())
{
rs->FetchField("travelrate",&bData);
rs->FetchField("name",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
if(bData==true)//it's a travel rate
m_cbDefTravelRate.AddRow(strData,strIndex);
else
m_cbRate.AddRow(strData,strIndex);
}
//select default rate
m_cbRate.SetCurSel(0);
m_cbDefTravelRate.SetCurSel(0);
}
}
bool CClientsDlg::EditPrompt()
{
if(m_bEditPrompt)
{
if(AfxMessageBox("Warning: you are about to change this existing client record\r\n\r\n"
"If you want to add a new client use the ADD NEW CLIENT button instead\r\n\r\n"
"Change this client record and continue to allow other changes?",MB_YESNO)==IDYES)
{
m_bEditPrompt=false;
return true;
}
else
return false;
}
else
return true;
}
void CClientsDlg::OnBtnnotes()
{
}
//09/20/00 long awaited consolidation routines
void CClientsDlg::OnConsolidate()
{
}
void CClientsDlg::OnBtndone()
{
//if(m_bAddMode)//then user has pressed cancel button
//{
// //revert to previous view and save changes
// if(m_ckShowHeadOfficeCheck.GetCheck()==TRUE)
// RefreshDisplay(1);//head office mode
// else
// RefreshDisplay(0);//normal mode
// m_bAddMode=false;
//}
//else
//{
//
// if(m_pstrReturnValue!=NULL)
// m_pstrReturnValue->Format("%s",m_strSelectedClient);
// CDialog::OnOK();
//}
}
void CClientsDlg::OnKillfocusEdacctnum()
{
SaveField(&m_edAcctNum,"acctnumber",true);
}
//*****************************************************
//Menu commands added Oct 2 2002 to clean up things.
//*****************************************************
void CClientsDlg::OnNewClientrecord()
{
CString q;
CString strTemp;
CString strTemp2;
COleDateTime dtData;
long lData;
dtData=COleDateTime::GetCurrentTime();
strTemp.Format("New record %s",dtData.Format("%H%M%S"));
//Get the address default strings set
SetDefaults();
q.Format("INSERT INTO clients ( company ) SELECT \"%s\";",strTemp);
if(!rs->Ex(q,&lData))
{
AfxMessageBox("The new record could not be created due to\r\n"
"the error previously indicated.\r\n\r\n"
"If this problem persists and you require technical support\r\n"
"take a screenshot of the error message displayed before\r\n"
"and email it to support@ayanova.com with any other information\r\n"
"that might help.");
return;
}
//change the newly added client to include the ID number
//why? Looks cleaner in case it gets somehow left behind
//and is guranteed unique where the temporary name is not
strTemp2.Format("New record %u",lData);
q.Format("UPDATE clients SET clients.company = \"%s\", "
"clients.city = \"%s\", clients.stateprov = \"%s\", clients.postal = \"%s\", clients.country = \"%s\" "
"WHERE (((clients.company)=\"%s\"));",strTemp2,
m_strDefaultCity,m_strDefaultStateProv,m_strDefaultPostal,m_strDefaultCountry,strTemp);
if(!rs->Ex(q))
{
AfxMessageBox("The new record could not be created due to\r\n"
"the error previously indicated.\r\n\r\n"
"If this problem persists and you require technical support\r\n"
"take a screenshot of the error message displayed before\r\n"
"and email it to support@ayanova.com with any other information\r\n"
"that might help.");
return;
}
//Set this record current
m_strSelectedClient.Format("%u",lData);
//ensure it's not set to head office mode
if(m_ckShowHeadOfficeCheck.GetCheck())
{
m_ckShowHeadOfficeCheck.SetCheck(FALSE);
RefreshDisplay(0);
}
else
{
//display it
FillClientList();
}
//Highlight the client name for editing
m_edCompany.SetFocus();
m_edCompany.SetSel(0,-1);
m_bEditPrompt=false;
}
void CClientsDlg::OnNewHeadofficerecord()
{
CString q;
CString strTemp;
CString strTemp2;
COleDateTime dtData;
long lData;
dtData=COleDateTime::GetCurrentTime();
strTemp.Format("New record %s",dtData.Format("%H%M%S"));
//Get the address default strings set
SetDefaults();
q.Format("INSERT INTO clients ( company, isheadoffice ) SELECT \"%s\",True;",strTemp);
if(!rs->Ex(q,&lData))
{
AfxMessageBox("The new record could not be created due to\r\n"
"the error previously indicated.\r\n\r\n"
"If this problem persists and you require technical support\r\n"
"take a screenshot of the error message displayed before\r\n"
"and email it to support@ayanova.com with any other information\r\n"
"that might help.");
return;
}
//change the newly added client to include the ID number
//why? Looks cleaner in case it gets somehow left behind
//and is guranteed unique where the temporary name is not
strTemp2.Format("New record %u",lData);
q.Format("UPDATE clients SET clients.company = \"%s\", "
"clients.city = \"%s\", clients.stateprov = \"%s\", clients.postal = \"%s\", clients.country = \"%s\" "
"WHERE (((clients.company)=\"%s\"));",strTemp2,
m_strDefaultCity,m_strDefaultStateProv,m_strDefaultPostal,m_strDefaultCountry,strTemp);
/*strTemp2.Format("New record %u",lData);
q.Format("UPDATE clients SET clients.company = \"%s\" "
"WHERE (((clients.company)=\"%s\"));",strTemp2,strTemp);*/
if(!rs->Ex(q))
{
AfxMessageBox("The new record could not be created due to\r\n"
"the error previously indicated.\r\n\r\n"
"If this problem persists and you require technical support\r\n"
"take a screenshot of the error message displayed before\r\n"
"and email it to support@ayanova.com with any other information\r\n"
"that might help.");
return;
}
//Set this record current
m_strSelectedClient.Format("%u",lData);
//ensure it's not set to client mode
if(!m_ckShowHeadOfficeCheck.GetCheck())
{
m_ckShowHeadOfficeCheck.SetCheck(TRUE);
RefreshDisplay(1);
}
else
{
//display it
FillClientList();
}
//Highlight the client name for editing
m_edCompany.SetFocus();
m_edCompany.SetSel(0,-1);
m_bEditPrompt=false;
}
void CClientsDlg::OnUpdateNewClientrecord(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bReadOnly?FALSE:TRUE);
}
void CClientsDlg::OnUpdateNewHeadofficerecord(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bReadOnly?FALSE:TRUE);
}
void CClientsDlg::OnEditDeletethisrecord()
{
// Delete current record
CString q,strData;
bool bFail=false;
long lrecs;
CString strWarning;
CString strTemp;
CString strClient=m_cbClientList.GetCurrentRowID();
q.Format("SELECT wo.id FROM wo WHERE (((wo.client)=%s));",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("Work orders: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT rentals.clientlink FROM rentals WHERE (((rentals.clientlink)=%s));",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("Rental / loaner records: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT units.client FROM units WHERE (((units.client)=%s));",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("Unit (equipment) records: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT pmhead.link FROM pmhead WHERE (((pmhead.isclient)=True) "
"AND ((pmhead.link)=%s));",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("Preventive maintenance schedule records: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT contacts.clientlink FROM contacts WHERE (((contacts.clientlink)=%s)); ",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("Client notebook records: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT clients.company FROM clients WHERE (((clients.headoffice)=%s)); ",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("By %u clients as their head office\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT client_requests.clientlink FROM client_requests "
"WHERE (((client_requests.clientlink)=%s));",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("ARAS service requests: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
q.Format("SELECT clients_aras.clientlink FROM clients_aras WHERE "
"(((clients_aras.clientlink)=%s));",strClient);
if(!rs->QueryReadOnly(q)) return;
if(!rs->IsEmpty())
{
bFail=true;
strTemp.Format("ARAS login account records: %u\r\n",rs->FetchRecordCount());
strWarning+=strTemp;
}
if(!bFail)//Safe to delete
{
q.Format("DELETE clients.*, clients.id FROM clients WHERE (((clients.id)=%s));",m_cbClientList.GetCurrentRowID());
rs->Ex(q);
//a deleted client can't be selected
m_strSelectedClient="";
}
else
{
//fill combo box with available zones
//rs->MoveFirst();
lrecs=1;
while(rs->MoveForward())
lrecs++;
q.Format(
"This client can not be deleted right now:\r\n\r\n"
"You can only delete a client record if it is not in use\r\n"
"anywhere else in AyaNova to protect the integrity of the\r\n"
"AyaNova database.\r\n\r\n"
"This client record is currently in use in the following places:\r\n"
"%s"
"\r\n"
"You have three options:\r\n"
"1) Leave this client as is (recommended)\r\n"
"2) Move all this clients data to another client\r\n"
" (use the Edit->Consolidate menu option)\r\n"
"3) Delete or change the areas listed above\r\n"
" to use a different client, then delete this client\r\n",strWarning);
m_pApp->ShowStuff(q);
}
FillClientList();
}
void CClientsDlg::OnUpdateEditDeletethisrecord(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bReadOnly?FALSE:TRUE);
}
void CClientsDlg::OnEditConsolidatetwoclientstogether()
{
CConsolidateDlg d;
d.DoModal();
FillFields();
}
void CClientsDlg::OnUpdateEditConsolidatetwoclientstogether(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bReadOnly?FALSE:TRUE);
}
void CClientsDlg::OnClientsAras()
{
CClientsRA d;
d.m_strCurrentClient=m_strSelectedClient;
d.DoModal();
}
void CClientsDlg::OnUpdateClientsAras(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CClientsDlg::OnToolsOpenclientnotebook()
{
rs->Close();
CContactsViewDlg d;
d.Setup(m_strSelectedClient);
d.DoModal();
FillFields();
}
void CClientsDlg::OnUpdateToolsOpenclientnotebook(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CClientsDlg::OnToolsSchedulepreventivemaintenanceforthisclient()
{
CString str,prompt;
m_edCompany.GetWindowText(str);
if(str.IsEmpty())
{
m_edFirst.GetWindowText(str);
prompt="Schedule preventive maintenance for client: " + str + " ";
m_edLast.GetWindowText(str);
prompt=prompt+ str;
}
else
prompt="Schedule preventive maintenance for client: " + str;
//Open the PM dialog for this client
CPM d;
//set criteria serial number
d.PreInitialize(true,false,m_strSelectedClient, prompt);
d.DoModal();
//added to refresh main recordset
FillFields();
}
void CClientsDlg::OnUpdateToolsSchedulepreventivemaintenanceforthisclient(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bPMAllowed?TRUE:FALSE);
}
void CClientsDlg::OnToolsDisplayrecordhistory()
{
CString test;
rs->FetchField("company",&test);
COleDateTime dtCreated,dtModified;
CString modifier,creator;
long m,c;
//GET RECORD STATUS FIELDS
rs->FetchField("created",&dtCreated);
rs->FetchField("modified",&dtModified);
rs->FetchField("creator",&c);
rs->FetchField("modifier",&m);
creator.Format("%u",c);
modifier.Format("%u",m);
CStatusDlg d;
d.SetValues(&creator,&modifier,&dtCreated,&dtModified);
d.DoModal();
}
void CClientsDlg::OnUpdateToolsDisplayrecordhistory(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CClientsDlg::OnClosethisscreen()
{
if(m_pstrReturnValue!=NULL)
m_pstrReturnValue->Format("%s",m_strSelectedClient);
CDialog::OnOK();
}
void CClientsDlg::OnUpdateClosethisscreen(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CClientsDlg::OnClientMenuHelp()
{
WinHelp(0x20083);
}
void CClientsDlg::OnEnKillfocusPhone2()
{
SaveField(&m_edPhone2,"phone2",true);
}
void CClientsDlg::OnEnKillfocusPhone3()
{
SaveField(&m_edPhone3,"phone3",true);
}
void CClientsDlg::OnEmaillabel()
{
CString strURL;
m_edEmail.GetWindowText(strURL);
if(!strURL.IsEmpty())//do this only if there was an url
{
strURL="mailto:" + strURL;
ShellExecute(NULL,"open",strURL,NULL,NULL,SW_SHOWNORMAL);
}
}
void CClientsDlg::OnToolsSetaddressdefaults()
{
CDefaultsDlg d;
d.DoModal();
}
void CClientsDlg::FillUnitList(void)
{
CString q,strData,strIndex;
long lData;
//FILL UNIT LIST:
m_cbUnits.Clear();
if(m_strSelectedClient.IsEmpty()) return;
q.Format("SELECT units.id, [sn] & \" - \" & IIf(IsNull([company_person]),\" "
"\",[company_person]) & \" \" & IIf(IsNull([unitmodels].[description]),\" "
"\",[unitmodels].[description]) "
"& \" \" & IIf(IsNull([unitmodels].[model]),\" "
"\",[unitmodels].[model]) AS name FROM (units LEFT "
"JOIN unitmodels ON units.model = unitmodels.id) "
"LEFT JOIN nonclients ON unitmodels.manufacturer = "
"nonclients.id WHERE (((units.client)=%s)) ORDER BY "
"units.sn;",m_strSelectedClient);
#ifdef _DEBUG
//m_pApp->ShowStuff(q);
#endif
rs2->QueryReadOnly(q);
if(!rs2->IsEmpty())
{
do
{
rs2->FetchField("name",&strData);
strData.TrimRight();
strData.TrimRight('-');
rs2->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbUnits.AddRow(strData,strIndex);
}while(rs2->MoveForward());
}
else
m_cbUnits.AddRow(" < No units >","0");
m_cbUnits.Select(0);
}
void CClientsDlg::OnStnClickedLblUnits()
{
CString strUnit=m_cbUnits.GetCurrentRowID();
CUnitsDlg d;
if(strUnit!="0" && !strUnit.IsEmpty())
d.m_strSelectedUnit=strUnit;
d.DoModal();
//added v1.9.4.5
//not refreshing unit list when new one added or old one removed
FillFields();
}