Files

246 lines
5.7 KiB
C++

// DefaultsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "DefaultsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDefaultsDlg dialog
CDefaultsDlg::CDefaultsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDefaultsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDefaultsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pApp= (CSpApp*)AfxGetApp();
//Initialize recordset pointer
rs=m_pApp->rsPool->GetRS("CDefaultsDlg");
}
void CDefaultsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDefaultsDlg)
DDX_Control(pDX, IDC_EDSCHEDWINDOW, m_edSchedWindow);
DDX_Control(pDX, IDC_EDAUTOREFRESHSECS, m_edAutoRefresh);
DDX_Control(pDX, IDC_CBREOPENSTATUS, m_cbStatusReopen);
DDX_Control(pDX, IDC_CBNEWSTATUS, m_cbStatusNew);
DDX_Control(pDX, IDC_CBCLOSEDSTATUS, m_cbStatusClosed);
DDX_Control(pDX, IDC_CKESTIMATES, m_ckEstimates);
DDX_Control(pDX, IDC_EDPROVSTATE, m_edProvState);
DDX_Control(pDX, IDC_EDPOSTAL, m_edPostal);
DDX_Control(pDX, IDC_EDCOUNTRY, m_edCountry);
DDX_Control(pDX, IDC_EDCITY, m_edCity);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDefaultsDlg, CDialog)
//{{AFX_MSG_MAP(CDefaultsDlg)
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
ON_BN_CLICKED(IDC_CKESTIMATES, OnCkestimates)
ON_EN_KILLFOCUS(IDC_EDAUTOREFRESHSECS, OnKillfocusEdautorefreshsecs)
ON_EN_KILLFOCUS(IDC_EDSCHEDWINDOW, OnKillfocusEdschedwindow)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDefaultsDlg message handlers
BOOL CDefaultsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString strData;
bool bEstimates;
//rs->SetConnect(m_pApp->strConnectString);
CString q,strIndex;
long lData;
//FILL STATUS LIST
m_cbStatusClosed.Clear();
m_cbStatusClosed.AddRow(" <No default status>","0");
m_cbStatusNew.Clear();
m_cbStatusNew.AddRow(" <No default status>","0");
m_cbStatusReopen.Clear();
m_cbStatusReopen.AddRow(" <No default status>","0");
rs->QueryReadOnly("SELECT probstat.id, probstat.notes FROM probstat ORDER BY probstat.id;");
if(!rs->IsEmpty())
{
do
{
rs->FetchField("notes",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbStatusClosed.AddRow(strData,strIndex);
m_cbStatusNew.AddRow(strData,strIndex);
m_cbStatusReopen.AddRow(strData,strIndex);
}while(rs->MoveForward());
}
rs->Query("SELECT * FROM defaults;");
rs->FetchField("city",&strData);
m_edCity.SetWindowText(strData);
rs->FetchField("stateprov",&strData);
m_edProvState.SetWindowText(strData);
rs->FetchField("postal",&strData);
m_edPostal.SetWindowText(strData);
rs->FetchField("country",&strData);
m_edCountry.SetWindowText(strData);
rs->FetchField("woestimate",&bEstimates);
m_ckEstimates.SetCheck(bEstimates ? TRUE : FALSE);
rs->FetchField("wonewstat",&lData);
m_cbStatusNew.Select(lData);
rs->FetchField("woclosestat",&lData);
m_cbStatusClosed.Select(lData);
rs->FetchField("woreopenstat",&lData);
m_cbStatusReopen.Select(lData);
rs->FetchField("schedrfrshsecs",&lData);//m_pApp->m_nSchedRefreshSecs);
strData.Format("%u",lData);
m_edAutoRefresh.SetWindowText(strData);
rs->FetchField("schedwindow",&lData);//m_pApp->m_nSchedRefreshSecs);
strData.Format("%u",lData);
m_edSchedWindow.SetWindowText(strData);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
CDefaultsDlg::~CDefaultsDlg()
{
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
}
void CDefaultsDlg::OnBtndone()
{
CString strData;
bool bEstimates;
long lData;
m_edCity.GetWindowText(strData);
rs->UpdateField("city",&strData);
m_edProvState.GetWindowText(strData);
rs->UpdateField("stateprov",&strData);
m_edPostal.GetWindowText(strData);
rs->UpdateField("postal",&strData);
m_edCountry.GetWindowText(strData);
rs->UpdateField("country",&strData);
bEstimates=m_ckEstimates.GetCheck() ? true : false;
rs->UpdateField("woestimate",&bEstimates);
lData=atol(m_cbStatusNew.GetCurrentRowID());
rs->UpdateField("wonewstat",&lData);
m_pApp->m_lDefNewWOStatus=lData;
lData=atol(m_cbStatusClosed.GetCurrentRowID());
rs->UpdateField("woclosestat",&lData);
m_pApp->m_lDefClosedWOStatus=lData;
lData=atol(m_cbStatusReopen.GetCurrentRowID());
rs->UpdateField("woreopenstat",&lData);
m_pApp->m_lDefReOpenWOStatus=lData;
m_edAutoRefresh.GetWindowText(strData);
lData=atol(strData);
rs->UpdateField("schedrfrshsecs",&lData);
m_pApp->m_lSchedRefreshSecs=lData;
m_edSchedWindow.GetWindowText(strData);
lData=atol(strData);
rs->UpdateField("schedwindow",&lData);
m_pApp->m_lSchedWindowDays=lData;
rs->SaveRecord();
CDialog::OnOK();
}
void CDefaultsDlg::OnCkestimates()
{
// TODO: Add your control notification handler code here
}
void CDefaultsDlg::OnKillfocusEdautorefreshsecs()
{
long x;
CString str;
m_edAutoRefresh.GetWindowText(str);
x=atol(str);
if(x!=0)
{
if(x<60)
{
AfxMessageBox("Must be at least one minute (60 seconds)");
m_edAutoRefresh.SetWindowText("60");
}
}
}
void CDefaultsDlg::OnKillfocusEdschedwindow()
{
long x;
CString str;
m_edSchedWindow.GetWindowText(str);
x=atol(str);
if(x<4)
{
AfxMessageBox("Must be at least 4 days");
m_edAutoRefresh.SetWindowText("30");
}
if(x>60)
{
AfxMessageBox("Caution: too high a setting may result in slow updates on schedule screen");
}
}