1679 lines
39 KiB
C++
1679 lines
39 KiB
C++
// UnitsDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "UnitsDlg.h"
|
|
#include "NonClientsDlg.h"
|
|
#include "ModelsDlg.h"
|
|
#include "ClientsDlg.h"
|
|
#include "PM.h"
|
|
#include "SimpleDate.h"
|
|
#include "GenericPopupList.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CUnitsDlg dialog
|
|
|
|
|
|
CUnitsDlg::CUnitsDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CUnitsDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CUnitsDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_bAddMode=false;
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
|
|
/*
|
|
rs=new GZRset("Error: Units dialog");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
|
|
cbrs=new GZRset("Error: Units dialog combo box recordset\r\n");
|
|
cbrs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
//Initialize recordset pointer
|
|
|
|
|
|
rs=m_pApp->rsPool->GetRS("CUnitsDlg (RS)");
|
|
cbrs=m_pApp->rsPool->GetRS("CUnitsDlg (CBRS)");
|
|
|
|
m_pstrReturnUnit=NULL;
|
|
m_pstrReturnClient=NULL;
|
|
m_strSelectedUnit.Empty();
|
|
m_strSelectedClient.Empty();
|
|
m_strSelectedModel.Empty();
|
|
|
|
m_bListByDescription=true;
|
|
m_bIniting=true;
|
|
m_bSubUnitSelected=false;
|
|
m_bAddIsDuplicate=false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//*****************************
|
|
CUnitsDlg::~CUnitsDlg()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
m_pApp->rsPool->ReleaseRS(&cbrs->m_nID);
|
|
}
|
|
|
|
|
|
|
|
|
|
//*************************************
|
|
void CUnitsDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CUnitsDlg)
|
|
DDX_Control(pDX, IDC_LBL_SUB_UNITS, m_lblSubUnits);
|
|
DDX_Control(pDX, IDC_CBSN2, m_cbSubSn);
|
|
DDX_Control(pDX, IDC_BTNADDDUPLICATE, m_btnAddDuplicate);
|
|
DDX_Control(pDX, IDC_EDLASTMETERREADING, m_edLastMeterReading);
|
|
DDX_Control(pDX, IDC_BTNPM, m_btnPM);
|
|
DDX_Control(pDX, IDC_LBLBYMODEL, m_lblByModel);
|
|
DDX_Control(pDX, IDC_LBLBYDESC, m_lblByDesc);
|
|
DDX_Control(pDX, IDC_CKRENTAL, m_ckRental);
|
|
DDX_Control(pDX, IDC_EDID3, m_edID3);
|
|
DDX_Control(pDX, IDC_EDID2, m_edID2);
|
|
DDX_Control(pDX, IDC_EDID1, m_edID1);
|
|
DDX_Control(pDX, IDC_CKPM, m_ckPM);
|
|
DDX_Control(pDX, IDC_LBLSNLIST, m_lblSNList);
|
|
DDX_Control(pDX, IDC_LBLRESELLERS, m_lblResellers);
|
|
DDX_Control(pDX, IDC_LBLMODEL, m_lblModel);
|
|
DDX_Control(pDX, IDC_LBLCLIENT, m_lblClient);
|
|
DDX_Control(pDX, IDC_EDWARRANTYTERMS, m_edWarrantyTerms);
|
|
DDX_Control(pDX, IDC_EDSN, m_edSN);
|
|
DDX_Control(pDX, IDC_EDRECEIPT, m_edReceipt);
|
|
DDX_Control(pDX, IDC_EDNOTES, m_edNotes);
|
|
DDX_Control(pDX, IDC_EDDESCRIPTION, m_edDescription);
|
|
DDX_Control(pDX, IDC_DTPURCHASED, m_dtPurchased);
|
|
DDX_Control(pDX, IDC_DONE, m_btnDone);
|
|
DDX_Control(pDX, IDC_CKBOUGHTHERE, m_ckBoughtHere);
|
|
DDX_Control(pDX, IDC_CBSN, m_cbSN);
|
|
DDX_Control(pDX, IDC_CBRESELLERS, m_cbResellers);
|
|
DDX_Control(pDX, IDC_CBMODELS, m_cbModels);
|
|
DDX_Control(pDX, IDC_CBCLIENTS, m_cbClients);
|
|
DDX_Control(pDX, IDC_BTNADD, m_btnAdd);
|
|
DDX_Control(pDX, IDC_BTNDELETE, m_btnDelete);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CUnitsDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CUnitsDlg)
|
|
ON_CBN_CLOSEUP(IDC_CBSN, OnCloseupCbsn)
|
|
ON_CBN_CLOSEUP(IDC_CBMODELS, OnCloseupCbmodels)
|
|
ON_CBN_CLOSEUP(IDC_CBCLIENTS, OnCloseupCbclients)
|
|
ON_BN_CLICKED(IDC_DONE, OnDone)
|
|
ON_BN_CLICKED(IDC_LBLRESELLERS, OnLblresellers)
|
|
ON_BN_CLICKED(IDC_LBLMODEL, OnLblmodel)
|
|
ON_BN_CLICKED(IDC_LBLCLIENT, OnLblclient)
|
|
ON_EN_KILLFOCUS(IDC_EDWARRANTYTERMS, OnKillfocusEdwarrantyterms)
|
|
ON_EN_KILLFOCUS(IDC_EDSN, OnKillfocusEdsn)
|
|
ON_EN_KILLFOCUS(IDC_EDRECEIPT, OnKillfocusEdreceipt)
|
|
ON_EN_KILLFOCUS(IDC_EDNOTES, OnKillfocusEdnotes)
|
|
ON_EN_KILLFOCUS(IDC_EDDESCRIPTION, OnKillfocusEddescription)
|
|
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DTPURCHASED, OnDatetimechangeDtpurchased)
|
|
ON_BN_CLICKED(IDC_CKPM, OnCkpm)
|
|
ON_BN_CLICKED(IDC_CKBOUGHTHERE, OnCkboughthere)
|
|
ON_CBN_CLOSEUP(IDC_CBRESELLERS, OnCloseupCbresellers)
|
|
ON_BN_CLICKED(IDC_BTNDELETE, OnBtndelete)
|
|
ON_BN_CLICKED(IDC_BTNADD, OnBtnadd)
|
|
ON_BN_CLICKED(IDC_CKRENTAL, OnCkrental)
|
|
ON_BN_CLICKED(IDC_LBLBYDESC, OnLblbydesc)
|
|
ON_BN_CLICKED(IDC_LBLBYMODEL, OnLblbymodel)
|
|
ON_EN_KILLFOCUS(IDC_EDID1, OnKillfocusEdid1)
|
|
ON_EN_KILLFOCUS(IDC_EDID2, OnKillfocusEdid2)
|
|
ON_EN_KILLFOCUS(IDC_EDID3, OnKillfocusEdid3)
|
|
ON_BN_CLICKED(IDC_BTNPM, OnBtnpm)
|
|
ON_EN_KILLFOCUS(IDC_EDLASTMETERREADING, OnKillfocusEdlastmeterreading)
|
|
ON_BN_CLICKED(IDC_BTNADDDUPLICATE, OnBtnaddduplicate)
|
|
ON_CBN_CLOSEUP(IDC_CBSN2, OnCloseupCbsn2)
|
|
ON_BN_CLICKED(IDC_LBL_SUB_UNITS, OnLblSubUnits)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CUnitsDlg message handlers
|
|
void CUnitsDlg::SetReturnStrings(CString *sn,CString *client)
|
|
{
|
|
m_pstrReturnUnit=sn;
|
|
m_pstrReturnClient=client;
|
|
|
|
//specific sn requested?
|
|
if(!m_pstrReturnUnit->IsEmpty())
|
|
m_strSelectedUnit=*m_pstrReturnUnit;
|
|
|
|
//specific client requested?
|
|
if(!m_pstrReturnClient->IsEmpty())
|
|
m_strSelectedClient=*m_pstrReturnClient;
|
|
}
|
|
|
|
|
|
//***********************************
|
|
BOOL CUnitsDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
CWaitCursor wait;
|
|
ShowWindow(SW_HIDE);
|
|
Security();
|
|
//make "hyperlinks"
|
|
m_lblClient.SetTextColor(RGB(0,0,255));
|
|
m_lblClient.SetFontUnderline(TRUE);
|
|
m_lblClient.SetLink(TRUE);
|
|
m_lblClient.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblClient.SetLinkURL("");
|
|
|
|
m_lblModel.SetTextColor(RGB(0,0,255));
|
|
m_lblModel.SetFontUnderline(TRUE);
|
|
m_lblModel.SetLink(TRUE);
|
|
m_lblModel.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblModel.SetLinkURL("");
|
|
|
|
m_lblResellers.SetTextColor(RGB(0,0,255));
|
|
m_lblResellers.SetFontUnderline(TRUE);
|
|
m_lblResellers.SetLink(TRUE);
|
|
m_lblResellers.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblResellers.SetLinkURL("");
|
|
|
|
m_lblByDesc.SetTextColor(RGB(0,0,255));
|
|
m_lblByDesc.SetFontUnderline(TRUE);
|
|
m_lblByDesc.SetLink(TRUE);
|
|
m_lblByDesc.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblByDesc.SetLinkURL("");
|
|
|
|
m_lblByModel.SetTextColor(RGB(0,0,255));
|
|
m_lblByModel.SetFontUnderline(TRUE);
|
|
m_lblByModel.SetLink(TRUE);
|
|
m_lblByModel.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblByModel.SetLinkURL("");
|
|
|
|
m_lblSubUnits.SetTextColor(RGB(0,0,255));
|
|
m_lblSubUnits.SetFontUnderline(TRUE);
|
|
m_lblSubUnits.SetLink(TRUE);
|
|
m_lblSubUnits.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblSubUnits.SetLinkURL("");
|
|
|
|
//SETUP FOR MODE
|
|
|
|
//display clients name at top and
|
|
//filter by passed sn/client
|
|
|
|
FillModelList();
|
|
FillClientList();
|
|
FillResellerList();
|
|
//EnableFields(false);
|
|
//must be called last, as is dependant on other list values
|
|
FillSNList();
|
|
|
|
ShowWindow(SW_MAXIMIZE);
|
|
m_cbSN.SetFocus();
|
|
m_bIniting=false;
|
|
//===================================================
|
|
// 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);
|
|
//===================================================
|
|
return FALSE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
//*****************************************
|
|
//======================================
|
|
void CUnitsDlg::FillSNList()
|
|
{
|
|
|
|
CString q,client,model,strData,strIndex;
|
|
long lData;
|
|
m_cbSN.Clear();
|
|
m_cbSubSn.Clear();
|
|
//client=m_cbClients.GetCurrentRowID();
|
|
//model=m_cbModels.GetCurrentRowID();
|
|
|
|
//No filter
|
|
//if(client=="0" && model == "0")
|
|
q="SELECT units.sn, units.id FROM units ORDER BY units.sn;";
|
|
/*
|
|
//Filter by client
|
|
if(client!="0" && model == "0")
|
|
q.Format("SELECT units.sn, units.id FROM units "
|
|
"WHERE (((units.client)=%s)) ORDER BY units.sn;",client);
|
|
|
|
//Filter by model number
|
|
if(client=="0" && model != "0")
|
|
q.Format(" SELECT units.sn, units.id FROM units "
|
|
"WHERE (((units.model)=%s)) ORDER BY units.sn;",model);
|
|
|
|
//Filter by client and model number
|
|
if(client!="0" && model != "0")
|
|
q.Format("SELECT units.sn, units.id FROM units "
|
|
"WHERE (((units.client)=%s) AND ((units.model)=%s));",client,model);
|
|
*/
|
|
|
|
//Set the default
|
|
strData="<Select Unit>";
|
|
strIndex="0";
|
|
m_cbSN.AddRow(strData,strIndex);
|
|
strData="<No Master Unit>";
|
|
m_cbSubSn.AddRow(strData,strIndex);
|
|
m_cbSubSn.Select("0");
|
|
cbrs->Query(q);
|
|
if(cbrs->IsEmpty())
|
|
{ m_cbSN.Select("0");
|
|
m_strSelectedUnit="0";
|
|
//v1.9.4.4
|
|
EnableFields(false);
|
|
m_ckPM.EnableWindow(FALSE);
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
cbrs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
cbrs->FetchField("sn",&strData);
|
|
cbrs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbSN.AddRow(strData,strIndex);
|
|
m_cbSubSn.AddRow(strData,strIndex);
|
|
}while(cbrs->MoveForward());
|
|
|
|
|
|
|
|
//pretend user has selected so that other fields get filled in
|
|
if(m_strSelectedUnit.IsEmpty()) //first time in
|
|
{
|
|
m_cbSN.SetCurSel(0);
|
|
m_strSelectedUnit=m_cbSN.GetCurrentRowID();
|
|
|
|
}
|
|
else//something valid was selected before so stick with it
|
|
m_cbSN.Select(m_strSelectedUnit);
|
|
|
|
|
|
//trigger selection
|
|
OnCloseupCbsn();
|
|
|
|
}
|
|
|
|
|
|
//*********************************************
|
|
void CUnitsDlg::OnCloseupCbsn()
|
|
{
|
|
if(!m_bIniting && m_bSubUnitSelected==false)
|
|
m_strSelectedUnit=m_cbSN.GetCurrentRowID();
|
|
if(m_strSelectedUnit=="0")
|
|
EnableFields(false);
|
|
else
|
|
EnableFields(true);
|
|
FillFields();
|
|
}
|
|
|
|
|
|
|
|
//***********************************
|
|
void CUnitsDlg::FillModelList()
|
|
{
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbModels.Clear();
|
|
|
|
//Set the default
|
|
strData="< Any model >";
|
|
strIndex="0";
|
|
m_cbModels.AddRow(strData,strIndex);
|
|
|
|
|
|
if(m_bListByDescription)
|
|
{
|
|
cbrs->Query("SELECT [company_person] & \" \" & [description] & \" \" & [model] AS item, unitmodels.id "
|
|
"FROM unitmodels LEFT JOIN nonclients ON unitmodels.manufacturer = nonclients.id "
|
|
"ORDER BY [company_person] & \" \" & [description] & \" \" & [model];");
|
|
|
|
}
|
|
else
|
|
{
|
|
cbrs->Query("SELECT [model] & \" \" & [company_person] & \" \" & [description] AS item, unitmodels.id "
|
|
"FROM unitmodels LEFT JOIN nonclients ON unitmodels.manufacturer = nonclients.id "
|
|
"ORDER BY [company_person] & \" \" & [description] & \" \" & [model];");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(cbrs->IsEmpty())
|
|
return;
|
|
|
|
|
|
cbrs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
cbrs->FetchField("item",&strData);
|
|
cbrs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbModels.AddRow(strData,strIndex);
|
|
}while(cbrs->MoveForward());
|
|
|
|
|
|
//pretend user has selected so that other fields get filled in
|
|
if(m_strSelectedModel.IsEmpty()) //first time in
|
|
{
|
|
m_cbModels.SetCurSel(0);
|
|
m_strSelectedModel=m_cbModels.GetCurrentRowID();
|
|
|
|
}
|
|
else//something valid was selected before so stick with it
|
|
m_cbModels.Select(m_strSelectedModel);
|
|
|
|
//added 02/21/2003
|
|
DisplayModelPMCheckBox();
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnCloseupCbmodels()
|
|
{
|
|
|
|
|
|
SaveField(&m_cbModels,"model");
|
|
m_strSelectedModel=m_cbModels.GetCurrentRowID();
|
|
//added 02/21/2003
|
|
DisplayModelPMCheckBox();
|
|
|
|
}
|
|
|
|
void CUnitsDlg::FillClientList()
|
|
{
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbClients.Clear();
|
|
|
|
//Set the default
|
|
strData="< Select owner >";
|
|
strIndex="0";
|
|
m_cbClients.AddRow(strData,strIndex);
|
|
|
|
cbrs->Query("SELECT clients.id,clients.isheadoffice, IIf(IsNull([company]), "
|
|
"[last] & \", \" & [first],[company]) AS name "
|
|
"FROM clients WHERE (((clients.isheadoffice)=False)) ORDER BY IIf(IsNull([company]), "
|
|
"[last] & \", \" & [first],[company]);");
|
|
|
|
|
|
if(cbrs->IsEmpty())
|
|
return;
|
|
|
|
|
|
cbrs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
cbrs->FetchField("name",&strData);
|
|
cbrs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbClients.AddRow(strData,strIndex);
|
|
}while(cbrs->MoveForward());
|
|
|
|
|
|
//pretend user has selected so that other fields get filled in
|
|
if(m_strSelectedClient.IsEmpty()) //first time in
|
|
{
|
|
m_cbClients.SetCurSel(0);
|
|
m_strSelectedClient=m_cbClients.GetCurrentRowID();
|
|
|
|
}
|
|
else//something valid was selected before so stick with it
|
|
m_cbClients.Select(m_strSelectedClient);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CUnitsDlg::OnCloseupCbclients()
|
|
{
|
|
CString strClient;
|
|
//CLIENT
|
|
strClient=m_cbClients.GetCurrentRowID();
|
|
if(strClient=="0")
|
|
{
|
|
AfxMessageBox("You must choose which client owns this unit.\r\n"
|
|
"This is required to proceed with saving this record");
|
|
return;
|
|
|
|
}
|
|
if(strClient!=strClientOwnerID && !m_bAddMode)
|
|
{
|
|
AfxMessageBox("Warning: you are changing the client owner of this unit\r\n"
|
|
"Make sure you have selected the correct client.");
|
|
|
|
}
|
|
strClientOwnerID=strClient;
|
|
|
|
SaveField(&m_cbClients,"client");
|
|
|
|
|
|
}
|
|
|
|
//**************************************
|
|
//FILL RESELLER LIST
|
|
//**************************************
|
|
void CUnitsDlg::FillResellerList()
|
|
{
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbResellers.Clear();
|
|
|
|
//Set the default
|
|
strData="< None >";
|
|
strIndex="0";
|
|
m_cbResellers.AddRow(strData,strIndex);
|
|
|
|
cbrs->Query("SELECT nonclients.id, nonclients.company_person "
|
|
"FROM nonclients WHERE (((nonclients.type)=5)) "
|
|
"ORDER BY nonclients.company_person;");
|
|
|
|
|
|
if(cbrs->IsEmpty())
|
|
return;
|
|
|
|
|
|
cbrs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
cbrs->FetchField("company_person",&strData);
|
|
cbrs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbResellers.AddRow(strData,strIndex);
|
|
}while(cbrs->MoveForward());
|
|
|
|
|
|
m_cbResellers.Select("0");
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnDone()
|
|
{
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
|
|
//******************************************
|
|
void CUnitsDlg::FillFields()
|
|
{
|
|
CString q,strData;
|
|
long lData;
|
|
COleDateTime dtData;
|
|
bool bData;
|
|
|
|
//Enable sub unit hyperlink if there are any
|
|
q.Format("SELECT subunits.unitid FROM subunits "
|
|
"WHERE (((subunits.masterunitid)=%s));",m_strSelectedUnit);
|
|
rs->QueryReadOnly(q);
|
|
if(rs->IsEmpty())
|
|
m_lblSubUnits.EnableWindow(FALSE);//no sub units so disable hyperlink to view
|
|
else
|
|
m_lblSubUnits.EnableWindow(TRUE);//Are sub units so enabled hyperlink to view them
|
|
|
|
|
|
//Display master unit if any
|
|
q.Format("SELECT subunits.masterunitid FROM subunits "
|
|
"WHERE (((subunits.unitid)=%s));",m_strSelectedUnit);
|
|
rs->QueryReadOnly(q);
|
|
if(rs->IsEmpty())
|
|
m_cbSubSn.Select(0);//no master so reflect that
|
|
else
|
|
{
|
|
rs->FetchField("masterunitid",&lData);//is master unit so select it
|
|
m_cbSubSn.Select(lData);
|
|
|
|
}
|
|
|
|
|
|
|
|
q.Format("SELECT units.* FROM units WHERE (((units.id)=%s));",m_strSelectedUnit);
|
|
rs->Query(q);
|
|
|
|
if(rs->IsEmpty())
|
|
{
|
|
ClearFields();
|
|
return;
|
|
}
|
|
|
|
|
|
//FETCHFIELDS AND FILL BOXES
|
|
|
|
//MODEL
|
|
rs->FetchField("model",&lData);
|
|
strData.Format("%u",lData);
|
|
m_cbModels.Select(strData);
|
|
m_strSelectedModel=strData;
|
|
|
|
//SERIAL NUMBER
|
|
rs->FetchField("sn",&strData);
|
|
m_edSN.SetWindowText(strData);
|
|
|
|
|
|
//BOUGHTHERE
|
|
rs->FetchField("boughthere",&bData);
|
|
m_ckBoughtHere.SetCheck(bData ? TRUE : FALSE);
|
|
m_lblResellers.ShowWindow(bData ? FALSE : TRUE);
|
|
m_cbResellers.ShowWindow(bData ? FALSE : TRUE);
|
|
|
|
|
|
//PURCHASED FROM
|
|
rs->FetchField("purchasedfrom",&lData);
|
|
strData.Format("%u",lData);
|
|
m_cbResellers.Select(strData);
|
|
|
|
//RECEIPT
|
|
rs->FetchField("receipt",&strData);
|
|
m_edReceipt.SetWindowText(strData);
|
|
|
|
|
|
//PURCHASED DATE
|
|
rs->FetchField("purchasedate",&dtData);
|
|
m_dtPurchased.SetTime(dtData);
|
|
|
|
//CLIENT
|
|
rs->FetchField("client",&lData);
|
|
strData.Format("%u",lData);
|
|
strClientOwnerID=strData;
|
|
m_cbClients.Select(strData);
|
|
|
|
//SPECIAL WARRANTY
|
|
rs->FetchField("specialwarranty",&strData);
|
|
m_edWarrantyTerms.SetWindowText(strData);
|
|
|
|
|
|
//NOTES
|
|
rs->FetchField("notes",&strData);
|
|
m_edNotes.SetWindowText(strData);
|
|
|
|
|
|
//DESCRIPTION
|
|
rs->FetchField("description",&strData);
|
|
m_edDescription.SetWindowText(strData);
|
|
|
|
//ID#1
|
|
rs->FetchField("id1",&strData);
|
|
m_edID1.SetWindowText(strData);
|
|
|
|
//ID#2
|
|
rs->FetchField("id2",&strData);
|
|
m_edID2.SetWindowText(strData);
|
|
|
|
//ID#3
|
|
rs->FetchField("id3",&strData);
|
|
m_edID3.SetWindowText(strData);
|
|
|
|
|
|
//RETIRED
|
|
rs->FetchField("pmreport",&bData);
|
|
m_ckPM.SetCheck(bData ? TRUE : FALSE);
|
|
|
|
rs->FetchField("loaner",&bData);
|
|
m_ckRental.SetCheck(bData ? TRUE : FALSE);
|
|
m_bRentalItem=bData;
|
|
m_cbClients.ShowWindow((m_bRentalItem ? FALSE : TRUE));
|
|
m_lblClient.ShowWindow((m_bRentalItem ? FALSE : TRUE));
|
|
|
|
//LAST METER READING
|
|
rs->FetchField("lastmeter",&lData);
|
|
strData.Format("%u",lData);
|
|
m_edLastMeterReading.SetWindowText(strData);
|
|
|
|
//Added 02/21/2003
|
|
DisplayModelPMCheckBox();
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnLblresellers()
|
|
{
|
|
CNonClientsDlg d;
|
|
long l=5;
|
|
d.SetType(&l);
|
|
if(d.DoModal())
|
|
FillResellerList();
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnLblmodel()
|
|
{
|
|
CModelsDlg d;
|
|
if(d.DoModal()==IDOK)
|
|
FillModelList();
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnLblclient()
|
|
{
|
|
CClientsDlg d;
|
|
if(d.DoModal()==IDOK)
|
|
FillClientList();
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdwarrantyterms()
|
|
{
|
|
SaveField(&m_edWarrantyTerms,"specialwarranty",true);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdsn()
|
|
{
|
|
SaveField(&m_edSN,"sn",false);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdreceipt()
|
|
{
|
|
SaveField(&m_edReceipt,"receipt",true);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdnotes()
|
|
{
|
|
SaveField(&m_edNotes,"notes",true);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEddescription()
|
|
{
|
|
SaveField(&m_edDescription,"description",true);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnDatetimechangeDtpurchased(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
SaveField(&m_dtPurchased,"purchasedate");
|
|
|
|
*pResult = 0;
|
|
}
|
|
|
|
void CUnitsDlg::OnCkpm()
|
|
{
|
|
SaveField(&m_ckPM,"pmreport");
|
|
/*CString strMsg;
|
|
strMsg.Format(
|
|
"The master Preventive Maintenance record\r\n"
|
|
"now needs to be updated.\r\n\r\n"
|
|
|
|
"When you click on OK, the P.M. screen will open\r\n"
|
|
"then automatically update to %s this unit then return\r\n"
|
|
"to this screen.",m_ckPM.GetCheck()?"include":"exclude");
|
|
AfxMessageBox(strMsg,MB_ICONINFORMATION);*/
|
|
//Open the PM dialog for this Model of unit
|
|
CPM d;
|
|
|
|
//set criteria serial number
|
|
CString prompt = "PROMPT";
|
|
d.PreInitialize(false,true,m_cbModels.GetCurrentRowID(),prompt,true);
|
|
d.DoModal();
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnCkboughthere()
|
|
{
|
|
int b=m_ckBoughtHere.GetCheck();
|
|
SaveField(&m_ckBoughtHere,"BoughtHere");
|
|
m_lblResellers.ShowWindow(!b);
|
|
m_cbResellers.ShowWindow(!b);
|
|
|
|
|
|
}
|
|
|
|
//*******************************************
|
|
void CUnitsDlg::OnCloseupCbresellers()
|
|
{
|
|
SaveField(&m_cbResellers,"purchasedfrom");
|
|
|
|
}
|
|
|
|
|
|
//*******************************************
|
|
void CUnitsDlg::OnBtndelete()
|
|
{
|
|
CString q;
|
|
|
|
if(m_bAddMode)
|
|
{ //cancel saving
|
|
m_bAddMode=false;
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDone.ShowWindow(TRUE);
|
|
m_lblSNList.ShowWindow(TRUE);
|
|
m_cbSN.ShowWindow(TRUE);
|
|
m_strSelectedUnit="";
|
|
FillSNList();
|
|
return;
|
|
}
|
|
|
|
//DELETE.....
|
|
|
|
//can't delete the built in sn...
|
|
if(m_strSelectedUnit=="0")
|
|
{
|
|
|
|
return;
|
|
}
|
|
|
|
//check if unused and deletable
|
|
q.Format("SELECT probs.id FROM probs "
|
|
"WHERE (((probs.unit)=%s));",m_strSelectedUnit);
|
|
cbrs->Query(q);
|
|
if(!cbrs->IsEmpty())
|
|
{
|
|
AfxMessageBox("DATA INTEGRITY PROTECTION:\r\n"
|
|
"This unit appears in one or more workorders\r\n"
|
|
"and cannot be deleted at this time.");
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(AfxMessageBox("Permanently delete unit?",MB_YESNO)==IDYES)
|
|
{
|
|
q.Format("DELETE units.*, units.id "
|
|
"FROM units WHERE (((units.id)=%s));",m_strSelectedUnit);
|
|
rs->Ex(q);
|
|
m_strSelectedUnit="";
|
|
FillSNList();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*******************************************************
|
|
void CUnitsDlg::OnBtnadd()
|
|
{
|
|
CString newsn;
|
|
if(!m_bAddMode)
|
|
{//go to add mode
|
|
m_bAddMode=true;
|
|
m_btnDelete.SetWindowText("Cancel");
|
|
m_btnAdd.SetWindowText("Save");
|
|
m_btnAddDuplicate.ShowWindow(FALSE);
|
|
m_btnDone.ShowWindow(FALSE);
|
|
m_lblSNList.ShowWindow(FALSE);
|
|
m_cbSN.ShowWindow(FALSE);
|
|
if(!m_bAddIsDuplicate)
|
|
ClearFields();
|
|
m_bAddIsDuplicate=false;
|
|
EnableFields(true);
|
|
return;
|
|
|
|
|
|
}
|
|
else
|
|
{//Save fields and go to regular mode
|
|
|
|
if(SaveNewRecord()==false)
|
|
return;
|
|
|
|
m_edSN.GetWindowText(newsn);
|
|
m_bAddMode=false;
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnAddDuplicate.ShowWindow(TRUE);
|
|
m_btnDone.ShowWindow(TRUE);
|
|
m_lblSNList.ShowWindow(TRUE);
|
|
m_cbSN.ShowWindow(TRUE);
|
|
m_strSelectedUnit="";
|
|
FillSNList();
|
|
//select the newly added item
|
|
m_cbSN.SelectString(-1,newsn);
|
|
OnCloseupCbsn();
|
|
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************************
|
|
//SAVE EDIT CONTROL FIELD
|
|
//************************************************************
|
|
bool CUnitsDlg::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;
|
|
|
|
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();
|
|
UpdateModified();
|
|
return true;
|
|
}
|
|
|
|
//************************************************************
|
|
//SAVE GZCOMBO CONTROL FIELD
|
|
//************************************************************
|
|
bool CUnitsDlg::SaveField(CgzCombo *cbControl,CString fldname)
|
|
{
|
|
|
|
if(m_bAddMode) return true;//dont attempt to update
|
|
CString str;
|
|
long lData;
|
|
str=cbControl->GetCurrentRowID();
|
|
if(str.IsEmpty()) return false;//shouldn't happen but...
|
|
lData=atol(str);
|
|
rs->UpdateField(fldname,&lData);
|
|
rs->SaveRecord();
|
|
UpdateModified();
|
|
return true;
|
|
}
|
|
|
|
//************************************************************
|
|
//SAVE CheckBox CONTROL FIELD
|
|
//************************************************************
|
|
bool CUnitsDlg::SaveField(CButton *ckControl,CString fldname)
|
|
{
|
|
if(m_bAddMode) return true;//dont attempt to update
|
|
bool bData=false;
|
|
BOOL BData;
|
|
BData=ckControl->GetCheck();
|
|
if(BData==TRUE) bData=true;
|
|
rs->UpdateField(fldname,&bData);
|
|
rs->SaveRecord();
|
|
UpdateModified();
|
|
return true;
|
|
}
|
|
//************************************************************
|
|
//SAVE DateTimePicker CONTROL FIELD
|
|
//************************************************************
|
|
bool CUnitsDlg::SaveField(CDateTimeCtrl *dtControl,CString fldname)
|
|
{
|
|
if(m_bAddMode) return true;//dont attempt to update
|
|
COleDateTime dtData;
|
|
dtControl->GetTime(dtData);
|
|
rs->UpdateField(fldname,&dtData);
|
|
rs->SaveRecord();
|
|
UpdateModified();
|
|
return true;
|
|
}
|
|
|
|
|
|
//************************************************
|
|
//UPDATE MODIFIED DATA
|
|
//*************************************************
|
|
bool CUnitsDlg::UpdateModified()
|
|
{
|
|
//updates modified by and modified on fields
|
|
rs->UpdateField("modifier",&m_pApp->m_lusrID);
|
|
COleDateTime dtData;
|
|
dtData=COleDateTime::GetCurrentTime();
|
|
rs->UpdateField("modified",&dtData);
|
|
rs->SaveRecord();
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CUnitsDlg::ClearFields()
|
|
{
|
|
//then empty the fields
|
|
|
|
m_cbModels.Select("0");
|
|
m_edSN.SetWindowText("");
|
|
m_ckBoughtHere.SetCheck(TRUE);
|
|
m_lblResellers.ShowWindow(FALSE);
|
|
m_cbResellers.ShowWindow(FALSE);
|
|
m_cbResellers.Select("0");
|
|
m_edReceipt.SetWindowText("");
|
|
m_dtPurchased.SetTime(COleDateTime::GetCurrentTime());
|
|
m_cbClients.Select("0");
|
|
m_edWarrantyTerms.SetWindowText("");
|
|
m_edNotes.SetWindowText("");
|
|
m_edDescription.SetWindowText("");
|
|
m_ckPM.SetCheck(FALSE);
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
bool CUnitsDlg::SaveNewRecord()
|
|
{
|
|
//UpdateFieldS AND FILL BOXES
|
|
CString strData, q, strClient;
|
|
long lData;
|
|
COleDateTime dtData,dtToday;
|
|
bool bData,bPM;
|
|
|
|
m_edSN.GetWindowText(strData);
|
|
if(strData.IsEmpty())
|
|
{
|
|
AfxMessageBox("A serial number is required to proceed");
|
|
return false;
|
|
|
|
}
|
|
//VALIDATE PURCHASED DATE
|
|
m_dtPurchased.GetTime(dtData);
|
|
|
|
dtToday=COleDateTime::GetCurrentTime();
|
|
|
|
/*if(dtData.GetYear()==dtToday.GetYear() && dtData.GetMonth()==dtToday.GetMonth() && dtData.GetDay()==dtToday.GetDay())
|
|
{
|
|
if(AfxMessageBox(
|
|
"Warning: The purchase date was not set!\r\n\r\n"
|
|
|
|
|
|
"Unless this unit was purchased today, your ability to schedule\r\n"
|
|
"preventive maintenance based on the *AGE* of this unit\r\n"
|
|
"will be compromised.\r\n\r\n"
|
|
|
|
|
|
"As long as you set the purchase date some time before you schedule\r\n"
|
|
"age based preventive maintenance there will be no problem.\r\n\r\n"
|
|
|
|
|
|
"In other words: if you don't know the purchase date right now, you can set it later."
|
|
|
|
|
|
"\r\n\r\nDo you want to proceed with saving and set it later?",MB_YESNO)==IDNO)
|
|
return false;
|
|
}
|
|
*/
|
|
//CLIENT
|
|
strClient=m_cbClients.GetCurrentRowID();
|
|
if(strClient=="0" && m_ckRental.GetCheck()==FALSE)
|
|
{
|
|
AfxMessageBox("You did not indicate which client owns this unit.\r\n"
|
|
"This is required to proceed with saving this record");
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
//CREATE NEW RECORD
|
|
//SELECT units.* FROM units WHERE (((units.sn)="22"));
|
|
|
|
q.Format("SELECT units.* FROM units WHERE (((units.sn)=\"%s\"));",strData);
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())//duplicate
|
|
{
|
|
q.Format("Error: duplicate serial numbers not allowed\r\nserial number %s is already entered.",strData);
|
|
AfxMessageBox(q);
|
|
return false;
|
|
|
|
}
|
|
|
|
if(rs->AddNewRecord()==false)
|
|
return false;
|
|
|
|
//SERIAL NUMBER
|
|
rs->UpdateField("sn",&strData);
|
|
|
|
//PURCHASE DATE
|
|
rs->UpdateField("purchasedate",&dtData);
|
|
|
|
//MODEL
|
|
strData=m_cbModels.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("model",&lData);
|
|
|
|
//BOUGHTHERE
|
|
bData=(m_ckBoughtHere.GetCheck() ? true : false);
|
|
rs->UpdateField("boughthere",&bData);
|
|
|
|
//PURCHASED FROM
|
|
strData=m_cbResellers.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("purchasedfrom",&lData);
|
|
|
|
//RECEIPT
|
|
m_edReceipt.GetWindowText(strData);
|
|
rs->UpdateField("receipt",&strData);
|
|
|
|
|
|
//CLIENT
|
|
lData=atol(strClient);
|
|
rs->UpdateField("client",&lData);
|
|
|
|
|
|
//SPECIAL WARRANTY
|
|
m_edWarrantyTerms.GetWindowText(strData);
|
|
rs->UpdateField("specialwarranty",&strData);
|
|
|
|
//NOTES
|
|
m_edNotes.GetWindowText(strData);
|
|
rs->UpdateField("notes",&strData);
|
|
|
|
//DESCRIPTION
|
|
m_edDescription.GetWindowText(strData);
|
|
rs->UpdateField("description",&strData);
|
|
|
|
//ID#1
|
|
m_edID1.GetWindowText(strData);
|
|
rs->UpdateField("id1",&strData);
|
|
|
|
//ID#2
|
|
m_edID2.GetWindowText(strData);
|
|
rs->UpdateField("id2",&strData);
|
|
|
|
//ID#3
|
|
m_edID3.GetWindowText(strData);
|
|
rs->UpdateField("id3",&strData);
|
|
|
|
//PMREPORT
|
|
bPM=(m_ckPM.GetCheck() ? true : false);
|
|
rs->UpdateField("pmreport",&bPM);
|
|
|
|
//LOANER
|
|
bData=(m_ckRental.GetCheck() ? true : false);
|
|
rs->UpdateField("loaner",&bData);
|
|
|
|
//LAST METER READING
|
|
m_edLastMeterReading.GetWindowText(strData);
|
|
lData=atol(strData);
|
|
rs->UpdateField("lastmeter",&lData);
|
|
|
|
if(!rs->SaveRecord()) return false;
|
|
rs->FetchField("id",&m_lUnitID);//see top for added bit
|
|
|
|
|
|
//SCHEDULE PM?
|
|
//flush?
|
|
/*
|
|
delete rs;
|
|
|
|
rs=new GZRset("Error: Units dialog");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
rs->Close();
|
|
|
|
//avoid preventative maintenance?
|
|
if(!bPM) return true;
|
|
|
|
|
|
Schedule();
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------
|
|
// +Schedule series or one
|
|
//-------------------------------------------------
|
|
void CUnitsDlg::Schedule()
|
|
{
|
|
long lData,lRepeat,lTech,lMeter,lTempMeter,lMonths=0,lDays=0, lWeeks=0, lClient, lType, lDOW;
|
|
CString strData,strHold,strAutoWO,q,strType,strLink;
|
|
bool bDone=false,bData;
|
|
COleDateTime dtData,dtTemp;
|
|
int nSeries,x,nDOW,d,nTemp;
|
|
CSimpleDate sdTemp;
|
|
|
|
//check if there is a schedule for this MODEL?
|
|
|
|
|
|
q.Format("SELECT pmhead.* "
|
|
"FROM pmhead "
|
|
"WHERE (((pmhead.link)=%s) AND ((pmhead.ismodel)=True));",m_cbModels.GetCurrentRowID());
|
|
|
|
rs->Query(q);
|
|
|
|
if(rs->IsEmpty())//nothing to schedule
|
|
return ;
|
|
|
|
//GET THE DATA
|
|
//not client mode
|
|
strType="False";
|
|
|
|
rs->FetchField("id",&m_lPMID);
|
|
|
|
//Get the technician
|
|
rs->FetchField("tech",&lTech);
|
|
|
|
//Get the DayOfWeek
|
|
rs->FetchField("dow",&lDOW);
|
|
nDOW=(int)lDOW;
|
|
|
|
//Get the hold factor
|
|
rs->FetchField("active",&bData);
|
|
strHold = bData ? "False" : "True";
|
|
|
|
//Get the AutoWO Factor
|
|
rs->FetchField("autowo",&bData);
|
|
strAutoWO = bData ? "True" : "False";
|
|
|
|
rs->FetchField("autorpt",&bData);
|
|
|
|
//Set the number of series to schedule
|
|
if(bData)
|
|
{
|
|
rs->FetchField("series",&lData);
|
|
nSeries=(int)lData;
|
|
}
|
|
else
|
|
nSeries=1;
|
|
|
|
/*PMDAYS*/
|
|
rs->FetchField("type",&lType);
|
|
rs->FetchField("repeatevery",&lRepeat);
|
|
rs->FetchField("rptdays",&lDays);
|
|
rs->FetchField("rptweeks",&lWeeks);
|
|
rs->FetchField("nextsrvdate",&dtData);
|
|
rs->FetchField("nextsrvmeter",&lMeter);
|
|
|
|
//get the repeat value
|
|
switch (lType)
|
|
{
|
|
|
|
case 0://time based
|
|
lMeter=0;
|
|
break;
|
|
|
|
case 1://meter based
|
|
//default date
|
|
dtData.SetDate(1968,3,12);
|
|
break;
|
|
|
|
default://age based
|
|
m_dtPurchased.GetTime(dtData);
|
|
lMeter=0;
|
|
break;
|
|
|
|
}
|
|
|
|
//Set the link
|
|
strLink.Format("%u",m_lUnitID);
|
|
|
|
//Set the client
|
|
lClient=atol(m_cbClients.GetCurrentRowID());
|
|
|
|
|
|
|
|
|
|
//==================================================================
|
|
//do the scheduling
|
|
|
|
|
|
lMonths=0;
|
|
lTempMeter=lMeter;
|
|
|
|
|
|
//EXECUTE
|
|
if(!rs->Ex(q))
|
|
return;
|
|
|
|
//prepare a simpledate class object for multi series
|
|
CSimpleDate sdOriginal(dtData.GetMonth(),dtData.GetDay(),dtData.GetYear());
|
|
|
|
//Loop X series occurences if repeating or once if not
|
|
//if date based, add dates then go up day by day until hit
|
|
//selected weekday
|
|
//If meter based, just add "every meter" to item and create records
|
|
|
|
for(x=0;x<nSeries;x++)
|
|
{
|
|
|
|
|
|
if(lType==1) //calculate next meter mode record
|
|
{
|
|
//this one's easy:
|
|
lTempMeter+=lRepeat;
|
|
dtTemp=dtData;
|
|
|
|
}
|
|
else //calculate next date based pmitem record
|
|
{//this one isn't:
|
|
|
|
//Add the months, then increment to the right
|
|
//day of week if necessary.
|
|
lMonths=lRepeat;
|
|
|
|
//add on the months
|
|
sdTemp=sdOriginal;
|
|
sdTemp.AddDays(lDays*(x+1));
|
|
sdTemp.AddDays((lWeeks*(x+1))*7);
|
|
sdTemp.AddMonths(lMonths*(x+1));
|
|
|
|
//*******************************************************************
|
|
//ADD DAYS HERE
|
|
//*******************************************************************
|
|
|
|
|
|
//Advance to day of week selected.
|
|
//temporary version of nDOW to matchup sunday as first day of week
|
|
//make our desired date numeric base match the one returned by the getdayofweek
|
|
|
|
|
|
|
|
if(nDOW==7) //sunday=0 in CSimpleDate land
|
|
nTemp=0;
|
|
else
|
|
nTemp=nDOW;
|
|
|
|
|
|
// q.Format("Raw date after adding months:%s\r\nDesired day of week:%i",sdTemp.GetFullDateStringLong(),nTemp);
|
|
// AfxMessageBox(q);
|
|
|
|
|
|
d=sdTemp.GetDayOfWeek();
|
|
|
|
if(nDOW==0)//any weekday
|
|
{
|
|
if(d==0)//sunday
|
|
sdTemp.AddDays(1);//move to monday
|
|
|
|
if(d==6)//saturday
|
|
sdTemp.SubtractDays(1);//move to Friday
|
|
}
|
|
else//specific day
|
|
{
|
|
|
|
while(d!=nTemp)
|
|
{
|
|
sdTemp.AddDays(1);
|
|
d=sdTemp.GetDayOfWeek();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
// q.Format("Polished date:%s\r\nNumeric weekday in sdtemp:%i",sdTemp.GetFullDateStringLong(),sdTemp.GetDayOfWeek());
|
|
// AfxMessageBox(q);
|
|
//dtData.Format(_T("%m/%d/%Y"))
|
|
//set dtTemp back again.
|
|
//CSimpleDate sdOriginal(dtData.GetMonth(),dtData.GetDay(),dtData.GetYear());
|
|
dtTemp.SetDate(sdTemp.GetYear(),sdTemp.GetMonth(),sdTemp.GetDay());
|
|
|
|
}
|
|
|
|
q.Format("INSERT INTO pmitems ( pmschedlink, schedate, schedmeter, autowo, hold, schedtech, link, isclient, clientlink) "
|
|
"SELECT %u, #%s#, %u, %s, %s, %u, %s, %s, %u;",
|
|
m_lPMID,dtTemp.Format(_T("%m/%d/%Y")),lTempMeter,strAutoWO,strHold,lTech, strLink, strType, lClient);
|
|
//m_pApp->ShowStuff(q);
|
|
//EXECUTE
|
|
if(!rs->Ex(q))
|
|
return;
|
|
rs->Close();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CUnitsDlg::OnCkrental()
|
|
{
|
|
|
|
m_bRentalItem=m_ckRental.GetCheck() ? true : false;
|
|
m_cbClients.ShowWindow((m_bRentalItem ? FALSE : TRUE));
|
|
m_lblClient.ShowWindow((m_bRentalItem ? FALSE : TRUE));
|
|
SaveField(&m_ckRental,"loaner");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CUnitsDlg::EnableFields(bool bEnable)
|
|
{
|
|
if(m_bReadOnly) return;
|
|
BOOL enable=bEnable ? TRUE : FALSE;
|
|
|
|
|
|
m_btnDelete.EnableWindow(enable);
|
|
m_cbClients.EnableWindow(enable);
|
|
m_cbModels.EnableWindow(enable);
|
|
m_cbResellers.EnableWindow(enable);
|
|
m_ckBoughtHere.EnableWindow(enable);
|
|
|
|
|
|
m_ckRental.EnableWindow(enable);
|
|
m_dtPurchased.EnableWindow(enable);
|
|
m_edDescription.EnableWindow(enable);
|
|
m_edID1.EnableWindow(enable);
|
|
m_edID2.EnableWindow(enable);
|
|
m_edID3.EnableWindow(enable);
|
|
m_edNotes.EnableWindow(enable);
|
|
m_edReceipt.EnableWindow(enable);
|
|
m_edSN.EnableWindow(enable);
|
|
m_edWarrantyTerms.EnableWindow(enable);
|
|
m_lblClient.EnableWindow(enable);
|
|
m_lblResellers.EnableWindow(enable);
|
|
m_lblModel.EnableWindow(enable);
|
|
m_edLastMeterReading.EnableWindow(enable);
|
|
m_cbSubSn.EnableWindow(enable);
|
|
m_lblSubUnits.EnableWindow(enable);
|
|
|
|
//PM allowed?
|
|
if(!m_bNoPMAllowed)
|
|
{
|
|
m_btnPM.EnableWindow(enable);
|
|
//m_ckPM.EnableWindow(enable);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnLblbydesc()
|
|
{
|
|
m_bListByDescription=true;
|
|
FillModelList();
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnLblbymodel()
|
|
{
|
|
m_bListByDescription=false;
|
|
FillModelList();
|
|
}
|
|
|
|
void CUnitsDlg::Security()
|
|
{
|
|
m_bReadOnly=false;
|
|
int x=m_pApp->Allowed(RUNITS,true);
|
|
if(x==0)//no access allowed
|
|
{
|
|
m_pApp->SecurityWarning();
|
|
CDialog::OnCancel();
|
|
}
|
|
if(x==2)//read only
|
|
{
|
|
m_bReadOnly=true;
|
|
m_cbModels.EnableWindow(FALSE);
|
|
m_cbResellers.EnableWindow(FALSE);
|
|
m_cbClients.EnableWindow(FALSE);
|
|
m_ckPM.EnableWindow(FALSE);
|
|
m_ckRental.EnableWindow(FALSE);
|
|
m_ckBoughtHere.EnableWindow(FALSE);
|
|
m_dtPurchased.EnableWindow(FALSE);
|
|
m_edDescription.SetReadOnly(TRUE);
|
|
m_edID1.SetReadOnly(TRUE);
|
|
m_edID2.SetReadOnly(TRUE);
|
|
m_edID3.SetReadOnly(TRUE);
|
|
m_edNotes.SetReadOnly(TRUE);
|
|
m_edReceipt.SetReadOnly(TRUE);
|
|
m_edSN.SetReadOnly(TRUE);
|
|
m_edWarrantyTerms.SetReadOnly(TRUE);
|
|
m_lblClient.EnableWindow(FALSE);
|
|
m_lblModel.EnableWindow(FALSE);
|
|
m_lblResellers.EnableWindow(FALSE);
|
|
m_cbSubSn.EnableWindow(FALSE);
|
|
m_lblSubUnits.EnableWindow(FALSE);
|
|
m_btnAdd.EnableWindow(FALSE);
|
|
m_btnDelete.EnableWindow(FALSE);
|
|
m_btnAddDuplicate.EnableWindow(FALSE);
|
|
m_edLastMeterReading.EnableWindow(FALSE);
|
|
}
|
|
|
|
//disable PM button?
|
|
m_bNoPMAllowed=false;
|
|
x=m_pApp->Allowed(RPM,true);
|
|
if(x==0)//no access allowed
|
|
{
|
|
m_btnPM.EnableWindow(FALSE);
|
|
m_ckPM.EnableWindow(FALSE);
|
|
m_bNoPMAllowed=true;
|
|
|
|
}
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdid1()
|
|
{
|
|
SaveField(&m_edID1,"id1",true);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdid2()
|
|
{
|
|
SaveField(&m_edID2,"id2",true);
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdid3()
|
|
{
|
|
SaveField(&m_edID3,"id3",true);
|
|
}
|
|
|
|
|
|
|
|
//Schedule PM individually
|
|
void CUnitsDlg::OnBtnpm()
|
|
{
|
|
CString str,prompt;
|
|
|
|
|
|
prompt = "Schedule preventive maintenance for Unit: ";
|
|
m_edSN.GetWindowText(str);
|
|
prompt+=str;
|
|
str=m_cbClients.GetCurrentRowID();
|
|
|
|
if(str!="0")
|
|
prompt+=" owned by: " + m_cbClients.GetCurrentRowText();
|
|
|
|
//Open the PM dialog for this serial number unit
|
|
CPM d;
|
|
|
|
//set criteria serial number
|
|
d.PreInitialize(false,false,m_cbSN.GetCurrentRowID(),prompt);
|
|
d.DoModal();
|
|
|
|
//in case meter count has changed inside the PM
|
|
//screen
|
|
FillFields();
|
|
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnKillfocusEdlastmeterreading()
|
|
{
|
|
|
|
CString strData;
|
|
long lData;
|
|
|
|
//do nothing if not changed
|
|
if(m_edLastMeterReading.GetModify()!=TRUE) return;
|
|
|
|
m_edLastMeterReading.GetWindowText(strData);
|
|
//lData=atol(strData);
|
|
|
|
_variant_t vtData(strData);
|
|
//v1.9.4.4 added try / catch mechanism to catch dumb-asses entering text in a numeric field
|
|
try
|
|
{
|
|
lData=(long)vtData;//cast variant to float (locale friendly)
|
|
}
|
|
catch( _com_error &e )
|
|
{
|
|
|
|
AfxMessageBox("I could not interpret your entry in the Last meter reading field\r\n"
|
|
"I can't save this field until a valid entry is made.\r\n"
|
|
"If you want to leave it blank, put a zero in it.");
|
|
m_edLastMeterReading.Undo();
|
|
m_edLastMeterReading.SetModify(FALSE);
|
|
m_edLastMeterReading.SetFocus();
|
|
return;
|
|
}
|
|
//v1.9.4.4 moved down here so validation will run in any mode
|
|
if(m_bAddMode) return;//dont attempt to update
|
|
|
|
rs->UpdateField("lastmeter",&lData);
|
|
|
|
|
|
rs->SaveRecord();
|
|
UpdateModified();
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUnitsDlg::OnBtnaddduplicate()
|
|
{
|
|
m_bAddIsDuplicate=true;
|
|
OnBtnadd();
|
|
|
|
}
|
|
|
|
//add record for this units master unint in subunits table
|
|
void CUnitsDlg::OnCloseupCbsn2()
|
|
{
|
|
CString q;
|
|
//long lData;
|
|
//Delete any old links if exist
|
|
q.Format("DELETE subunits.*, subunits.unitid "
|
|
"FROM subunits "
|
|
"WHERE (((subunits.unitid)=%s));",m_strSelectedUnit);
|
|
rs->Ex(q);
|
|
|
|
//insert new link
|
|
q.Format("INSERT INTO subunits ( masterunitid, unitid ) "
|
|
"SELECT %s, %s;",m_cbSubSn.GetCurrentRowID(),m_strSelectedUnit);
|
|
rs->Ex(q);
|
|
|
|
}
|
|
|
|
void CUnitsDlg::OnLblSubUnits()
|
|
{
|
|
CString q,strData,strTemp,strIndex,strReturnValue,strLbData;
|
|
long lData;
|
|
q.Format("SELECT units.id AS unitid, units.sn AS unitsn, nonclients.company_person AS make, unitmodels.model, unitmodelcats.name AS type "
|
|
"FROM (((subunits LEFT JOIN units ON subunits.unitid = units.id) LEFT JOIN unitmodels ON units.model = unitmodels.id) LEFT JOIN nonclients ON unitmodels.manufacturer = nonclients.id) LEFT JOIN unitmodelcats ON unitmodels.category = unitmodelcats.id "
|
|
"WHERE (((subunits.masterunitid)=%s));",m_strSelectedUnit);
|
|
rs->QueryReadOnly(q);
|
|
if(rs->IsEmpty())
|
|
{
|
|
FillFields();
|
|
return;
|
|
}
|
|
|
|
//ok, here we are with a populated recordset
|
|
CGenericPopupList d;
|
|
strReturnValue.Empty();
|
|
d.m_pSelectedID=&strReturnValue;
|
|
//d.m_lb.Clear();
|
|
|
|
do{
|
|
|
|
rs->FetchField("unitid",&lData);//unit ID
|
|
strIndex.Format("%u",lData);
|
|
|
|
rs->FetchField("unitsn",&strTemp);
|
|
strData=strTemp;
|
|
|
|
rs->FetchField("make",&strTemp);
|
|
if(!strTemp.IsEmpty())
|
|
strData+=" " + strTemp;
|
|
|
|
rs->FetchField("model",&strTemp);
|
|
if(!strTemp.IsEmpty())
|
|
strData+=" " + strTemp;
|
|
|
|
rs->FetchField("type",&strTemp);
|
|
if(!strTemp.IsEmpty())
|
|
strData+=" " + strTemp;
|
|
|
|
strLbData+=strData + "," + strIndex + ",";
|
|
|
|
}while(rs->MoveForward());
|
|
|
|
strLbData.TrimRight(',');
|
|
d.m_strLbData=strLbData;
|
|
d.DoModal();
|
|
|
|
if(!strReturnValue.IsEmpty())
|
|
m_strSelectedUnit=strReturnValue;
|
|
|
|
//refresh the data set
|
|
m_bSubUnitSelected=true;
|
|
FillSNList();
|
|
m_bSubUnitSelected=false;
|
|
|
|
|
|
}
|
|
|
|
// Determines if PM checkbox for model can be displayed or not and sets accordingly
|
|
//added 02/21/2003
|
|
void CUnitsDlg::DisplayModelPMCheckBox(void)
|
|
{
|
|
//check for PM for this model, if so
|
|
//then enable PM checkbox (if allowed)
|
|
//otherwise disable PM checkbox
|
|
|
|
CString q;
|
|
q.Format("SELECT pmhead.ismodel, pmhead.link FROM pmhead WHERE "
|
|
"(((pmhead.ismodel)=True) AND ((pmhead.link)=%s)); ",m_cbModels.GetCurrentRowID());
|
|
if(cbrs->QueryReadOnly(q))
|
|
{
|
|
if(cbrs->IsEmpty())//pm's for this model?
|
|
m_ckPM.EnableWindow(FALSE);//no there are not
|
|
else
|
|
{
|
|
//Yes there are, is user allowed?
|
|
if(!m_bReadOnly && !m_bNoPMAllowed)
|
|
m_ckPM.EnableWindow(TRUE);
|
|
|
|
}
|
|
}
|
|
}
|