952 lines
22 KiB
C++
952 lines
22 KiB
C++
// ModelsDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "ModelsDlg.h"
|
|
#include "ModelCatsDlg.h"
|
|
#include "NonClientsDlg.h"
|
|
#include "PM.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CModelsDlg dialog
|
|
|
|
|
|
CModelsDlg::CModelsDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CModelsDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CModelsDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_bAddMode=false;
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
/*
|
|
rs=new GZRset("Error: Unit models dialog");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
|
|
cbrs=new GZRset("Error: Unit models dialog combo box recordset\r\n");
|
|
cbrs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
//Initialize recordset pointer
|
|
|
|
|
|
cbrs=m_pApp->rsPool->GetRS("CModelsDlg (CBRS)");
|
|
rs=m_pApp->rsPool->GetRS("CModelsDlg (RS)");
|
|
|
|
m_pstrReturnValue=NULL;
|
|
m_strSelectedModel.Empty();
|
|
m_bListByDescription=true;
|
|
|
|
}
|
|
|
|
CModelsDlg::~CModelsDlg()
|
|
{
|
|
|
|
m_pApp->rsPool->ReleaseRS(&cbrs->m_nID);
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
}
|
|
|
|
|
|
void CModelsDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CModelsDlg)
|
|
DDX_Control(pDX, IDC_LBLBYDESC, m_lblByDesc);
|
|
DDX_Control(pDX, IDC_LBLBYMODEL, m_lblByModel);
|
|
DDX_Control(pDX, IDC_EDDESCRIPTION, m_edDescription);
|
|
DDX_Control(pDX, IDC_BTNPM, m_btnPM);
|
|
DDX_Control(pDX, IDC_LBLMODELLIST, m_lblModels);
|
|
DDX_Control(pDX, IDC_LBLMANUFACTURER, m_lblManufacturer);
|
|
DDX_Control(pDX, IDC_LBLCATEGORY, m_lblCategory);
|
|
DDX_Control(pDX, IDC_EDWARRANTYTERMS, m_edWarrantyTerms);
|
|
DDX_Control(pDX, IDC_EDWARRANTYMONTHS, m_edWarrantyMonths);
|
|
DDX_Control(pDX, IDC_EDNOTES, m_edNotes);
|
|
DDX_Control(pDX, IDC_EDMODEL, m_edModel);
|
|
DDX_Control(pDX, IDC_DTINTRODUCED, m_dtIntroduced);
|
|
DDX_Control(pDX, IDC_DTDISCONTINUED, m_dtDiscontinued);
|
|
DDX_Control(pDX, IDC_CKLIFETIME, m_ckLifetime);
|
|
DDX_Control(pDX, IDC_CKDISCONTINUED, m_ckDiscontinued);
|
|
DDX_Control(pDX, IDC_CKACTIVE, m_ckActive);
|
|
DDX_Control(pDX, IDC_CBMODELS, m_cbModels);
|
|
DDX_Control(pDX, IDC_CBMANUFACTURERS, m_cbManufacturers);
|
|
DDX_Control(pDX, IDC_CBCATEGORIES, m_cbCategories);
|
|
DDX_Control(pDX, IDC_BTNDONE, m_btnDone);
|
|
DDX_Control(pDX, IDC_BTNDELETE, m_btnDelete);
|
|
DDX_Control(pDX, IDC_BTNADD, m_btnAdd);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CModelsDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CModelsDlg)
|
|
ON_BN_CLICKED(IDC_BTNADD, OnBtnadd)
|
|
ON_BN_CLICKED(IDC_BTNDELETE, OnBtndelete)
|
|
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
|
|
ON_CBN_CLOSEUP(IDC_CBCATEGORIES, OnCloseupCbcategories)
|
|
ON_CBN_CLOSEUP(IDC_CBMANUFACTURERS, OnCloseupCbmanufacturers)
|
|
ON_CBN_CLOSEUP(IDC_CBMODELS, OnCloseupCbmodels)
|
|
ON_BN_CLICKED(IDC_CKDISCONTINUED, OnCkdiscontinued)
|
|
ON_BN_CLICKED(IDC_CKLIFETIME, OnCklifetime)
|
|
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DTDISCONTINUED, OnDatetimechangeDtdiscontinued)
|
|
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DTINTRODUCED, OnDatetimechangeDtintroduced)
|
|
ON_EN_KILLFOCUS(IDC_EDMODEL, OnKillfocusEdmodel)
|
|
ON_EN_KILLFOCUS(IDC_EDNOTES, OnKillfocusEdnotes)
|
|
ON_EN_KILLFOCUS(IDC_EDWARRANTYMONTHS, OnKillfocusEdwarrantymonths)
|
|
ON_EN_KILLFOCUS(IDC_EDWARRANTYTERMS, OnKillfocusEdwarrantyterms)
|
|
ON_BN_CLICKED(IDC_LBLCATEGORY, OnLblcategory)
|
|
ON_BN_CLICKED(IDC_LBLMANUFACTURER, OnLblmanufacturer)
|
|
ON_BN_CLICKED(IDC_BTNPM, OnBtnpm)
|
|
ON_EN_KILLFOCUS(IDC_EDDESCRIPTION, OnKillfocusEddescription)
|
|
ON_BN_CLICKED(IDC_LBLBYMODEL, OnLblbymodel)
|
|
ON_BN_CLICKED(IDC_LBLBYDESC, OnLblbydesc)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CModelsDlg message handlers
|
|
|
|
BOOL CModelsDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
Security();
|
|
//make "hyperlinks"
|
|
m_lblCategory.SetTextColor(RGB(0,0,255));
|
|
m_lblCategory.SetFontUnderline(TRUE);
|
|
m_lblCategory.SetLink(TRUE);
|
|
m_lblCategory.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblCategory.SetLinkURL("");
|
|
|
|
|
|
//make "hyperlinks"
|
|
m_lblManufacturer.SetTextColor(RGB(0,0,255));
|
|
m_lblManufacturer.SetFontUnderline(TRUE);
|
|
m_lblManufacturer.SetLink(TRUE);
|
|
m_lblManufacturer.SetLinkCursor(m_pApp->hcHand);
|
|
m_lblManufacturer.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("");
|
|
|
|
|
|
FillCategoryList();
|
|
FillManufacturerList();
|
|
//this one has to be last because it's going to
|
|
//trigger selections on the other two
|
|
FillModelList();
|
|
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CModelsDlg::OnBtnadd()
|
|
{
|
|
CString strData;
|
|
long lData;
|
|
bool bData;
|
|
COleDateTime dtData;
|
|
CString q;
|
|
|
|
if(!m_bAddMode)
|
|
{
|
|
//Go into add mode
|
|
EnableFields(true);
|
|
m_bAddMode=true;
|
|
m_lblModels.ShowWindow(FALSE);
|
|
m_cbModels.ShowWindow(FALSE);
|
|
m_btnPM.ShowWindow(FALSE);
|
|
m_btnDone.ShowWindow(FALSE);
|
|
m_btnAdd.SetWindowText("SAVE");
|
|
m_btnDelete.SetWindowText("CANCEL");
|
|
m_cbCategories.Select("0");
|
|
m_cbManufacturers.Select("0");
|
|
m_ckDiscontinued.SetCheck(FALSE);
|
|
m_ckLifetime.SetCheck(FALSE);
|
|
m_dtDiscontinued.SetTime(COleDateTime::GetCurrentTime());
|
|
m_dtIntroduced.SetTime(COleDateTime::GetCurrentTime());
|
|
m_edModel.SetWindowText("");
|
|
m_edDescription.SetWindowText("");
|
|
m_edNotes.SetWindowText("");
|
|
m_edWarrantyMonths.SetWindowText("");
|
|
m_edWarrantyTerms.SetWindowText("");
|
|
m_lblByDesc.ShowWindow(FALSE);
|
|
m_lblByModel.ShowWindow(FALSE);
|
|
|
|
}
|
|
else
|
|
{
|
|
//Validate and Save record
|
|
m_edModel.GetWindowText(strData);
|
|
if(strData.IsEmpty())
|
|
{
|
|
AfxMessageBox("A Model number is required to save this record");
|
|
return;
|
|
}
|
|
|
|
//check if duplicate model number
|
|
q.Format("SELECT unitmodels.model FROM unitmodels WHERE (((unitmodels.model)=\"%s\"));",strData);
|
|
rs->QueryReadOnly(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
q.Format("Model number \"%s\" has already been used.\r\n"
|
|
"Each model record must have a unique model number\r\n"
|
|
"Change the model number to save this record.",strData);
|
|
AfxMessageBox(q);
|
|
m_edModel.SetFocus();
|
|
return;
|
|
|
|
}
|
|
rs->Query("SELECT unitmodels.* FROM unitmodels WHERE unitmodels.id = 0;");
|
|
rs->AddNewRecord();
|
|
|
|
//MODEL
|
|
rs->UpdateField("model",&strData);
|
|
|
|
//Description
|
|
m_edDescription.GetWindowText(strData);
|
|
rs->UpdateField("description",&strData);
|
|
|
|
//CATEGORY
|
|
strData=m_cbCategories.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("category",&lData);
|
|
|
|
//LIFETIMEWARRANTY
|
|
bData=(m_ckLifetime.GetCheck() ? true : false);
|
|
rs->UpdateField("lifetimewarranty",&bData);
|
|
|
|
//WARRANTY (months)
|
|
m_edWarrantyMonths.GetWindowText(strData);
|
|
lData=atol(strData);
|
|
rs->UpdateField("warranty",&lData);
|
|
|
|
//WARRANTYTERMS
|
|
m_edWarrantyTerms.GetWindowText(strData);
|
|
rs->UpdateField("warrantyterms",&strData);
|
|
|
|
//MANUFACTURER
|
|
strData=m_cbManufacturers.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("manufacturer",&lData);
|
|
|
|
//DISCONTINUED
|
|
bData=(m_ckDiscontinued.GetCheck() ? true : false);
|
|
rs->UpdateField("discontinued",&bData);
|
|
|
|
//DISCONTINUED DATE
|
|
m_dtDiscontinued.GetTime(dtData);
|
|
rs->UpdateField("discodate",&dtData);
|
|
|
|
//INTRODUCED DATE
|
|
m_dtIntroduced.GetTime(dtData);
|
|
rs->UpdateField("introduced",&dtData);
|
|
|
|
//NOTES
|
|
m_edNotes.GetWindowText(strData);
|
|
rs->UpdateField("notes",&strData);
|
|
|
|
//SAVE NEW RECORD
|
|
rs->SaveRecord();
|
|
|
|
|
|
m_bAddMode=false;
|
|
m_lblByDesc.ShowWindow(TRUE);
|
|
m_lblByModel.ShowWindow(TRUE);
|
|
m_btnPM.ShowWindow(TRUE);
|
|
m_lblModels.ShowWindow(TRUE);
|
|
m_cbModels.ShowWindow(TRUE);
|
|
m_btnDone.ShowWindow(TRUE);
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDelete.SetWindowText("Delete");
|
|
FillModelList();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//Delete
|
|
void CModelsDlg::OnBtndelete()
|
|
{
|
|
CString q;
|
|
|
|
if(m_bAddMode)//then this is the cancel button
|
|
{
|
|
m_bAddMode=false;
|
|
m_btnPM.ShowWindow(TRUE);
|
|
m_lblModels.ShowWindow(TRUE);
|
|
m_cbModels.ShowWindow(TRUE);
|
|
m_btnDone.ShowWindow(TRUE);
|
|
m_lblByDesc.ShowWindow(TRUE);
|
|
m_lblByModel.ShowWindow(TRUE);
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDelete.SetWindowText("Delete");
|
|
FillModelList();
|
|
return;
|
|
}
|
|
|
|
if(m_bNoRecords) return;
|
|
|
|
//Delete the current record
|
|
|
|
//check if safe to delete
|
|
q.Format("SELECT units.id "
|
|
"FROM units WHERE (((units.model)=%s));",m_cbModels.GetCurrentRowID());
|
|
|
|
cbrs->Query(q);
|
|
|
|
if(!cbrs->IsEmpty())
|
|
{
|
|
AfxMessageBox("DATA INTEGRITY PROTECTION!\r\n"
|
|
"There are one or more units that are attached to this model number.\r\n"
|
|
"You can't delete this record at this time.");
|
|
return;
|
|
|
|
}
|
|
|
|
//SAFE TO DELETE
|
|
q.Format("DELETE unitmodels.*, unitmodels.id "
|
|
"FROM unitmodels WHERE (((unitmodels.id)=%s));",m_cbModels.GetCurrentRowID());
|
|
|
|
if(AfxMessageBox("Delete this record permanently?\r\nAre you sure?",MB_YESNO)==IDYES)
|
|
{
|
|
cbrs->Ex(q);
|
|
m_strSelectedModel="";
|
|
FillModelList();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CModelsDlg::OnBtndone()
|
|
{
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
|
|
//********************************
|
|
void CModelsDlg::OnCloseupCbcategories()
|
|
{
|
|
SaveField(&m_cbCategories,"category");
|
|
|
|
}
|
|
|
|
void CModelsDlg::OnCloseupCbmanufacturers()
|
|
{
|
|
SaveField(&m_cbManufacturers,"manufacturer");
|
|
|
|
}
|
|
|
|
|
|
//-****************************
|
|
void CModelsDlg::OnCloseupCbmodels()
|
|
{
|
|
m_strSelectedModel=m_cbModels.GetCurrentRowID();
|
|
|
|
FillFields();
|
|
|
|
}
|
|
|
|
|
|
//*******************************
|
|
void CModelsDlg::OnCkdiscontinued()
|
|
{
|
|
SaveField(&m_ckDiscontinued,"discontinued");
|
|
m_dtDiscontinued.ShowWindow(m_ckDiscontinued.GetCheck());
|
|
if(m_bReadOnly)
|
|
m_dtDiscontinued.EnableWindow(FALSE);
|
|
}
|
|
|
|
|
|
//*******************************
|
|
void CModelsDlg::OnCklifetime()
|
|
{
|
|
SaveField(&m_ckLifetime,"lifetimewarranty");
|
|
|
|
}
|
|
|
|
//************************************************
|
|
void CModelsDlg::OnDatetimechangeDtdiscontinued(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
SaveField(&m_dtDiscontinued,"discodate");
|
|
|
|
|
|
*pResult = 0;
|
|
}
|
|
|
|
//************************************************
|
|
void CModelsDlg::OnDatetimechangeDtintroduced(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
SaveField(&m_dtIntroduced,"introduced");
|
|
*pResult = 0;
|
|
}
|
|
|
|
//*****************************************
|
|
void CModelsDlg::OnKillfocusEdmodel()
|
|
{
|
|
|
|
SaveField(&m_edModel,"model",false);
|
|
if(!m_bAddMode)
|
|
FillModelList();
|
|
}
|
|
|
|
//*********************************************
|
|
void CModelsDlg::OnKillfocusEdnotes()
|
|
{
|
|
SaveField(&m_edNotes,"notes",true);
|
|
|
|
}
|
|
|
|
//************************************************
|
|
void CModelsDlg::OnKillfocusEdwarrantymonths()
|
|
{
|
|
|
|
long lData;
|
|
|
|
CString str;
|
|
//do nothing if not changed
|
|
if(m_edWarrantyMonths.GetModify()!=TRUE) return;
|
|
|
|
m_edWarrantyMonths.GetWindowText(str);
|
|
//lData=atol(str);
|
|
_variant_t vtData(str);
|
|
//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 Warranty Months 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_edWarrantyMonths.Undo();
|
|
m_edWarrantyMonths.SetModify(FALSE);
|
|
m_edWarrantyMonths.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("warranty",&lData);
|
|
rs->SaveRecord();
|
|
UpdateModified();
|
|
|
|
|
|
}
|
|
|
|
void CModelsDlg::OnKillfocusEdwarrantyterms()
|
|
{
|
|
SaveField(&m_edWarrantyTerms,"warrantyterms",true);
|
|
|
|
}
|
|
|
|
|
|
//*******************************
|
|
void CModelsDlg::OnLblcategory()
|
|
{
|
|
CString str,id;
|
|
CModelCatsDlg d;
|
|
d.SetReturnString(&str);
|
|
if(d.DoModal()==IDOK)
|
|
{
|
|
id=m_cbCategories.GetCurrentRowID();
|
|
FillCategoryList();
|
|
m_cbCategories.Select(id);
|
|
}
|
|
//OnCloseupCbcategories();
|
|
|
|
}
|
|
|
|
|
|
//**********************************
|
|
void CModelsDlg::OnLblmanufacturer()
|
|
{
|
|
CString str,id;
|
|
long ldata=3;//manufacturers are type 3
|
|
CNonClientsDlg d;
|
|
d.SetType(&ldata);
|
|
d.SetReturnString(&str);
|
|
if(d.DoModal()==IDOK)
|
|
{
|
|
id=m_cbManufacturers.GetCurrentRowID();
|
|
FillManufacturerList();
|
|
m_cbManufacturers.Select(id);
|
|
//this will save the field change tothe
|
|
//database since the user didn't select
|
|
//the regular way.
|
|
////OnCloseupCbmanufacturers();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void CModelsDlg::FillCategoryList()
|
|
{
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbCategories.Clear();
|
|
|
|
//Set the default
|
|
strData="<No category>";
|
|
strIndex="0";
|
|
m_cbCategories.AddRow(strData,strIndex);
|
|
|
|
cbrs->Query("SELECT unitmodelcats.* FROM unitmodelcats;");
|
|
if(cbrs->IsEmpty())
|
|
return;
|
|
|
|
|
|
cbrs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
cbrs->FetchField("name",&strData);
|
|
cbrs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbCategories.AddRow(strData,strIndex);
|
|
}while(cbrs->MoveForward());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************
|
|
void CModelsDlg::FillModelList()
|
|
{
|
|
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbModels.Clear();
|
|
|
|
|
|
if(m_bListByDescription)
|
|
{
|
|
rs->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
|
|
{
|
|
rs->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(rs->IsEmpty())
|
|
{
|
|
EnableFields(false);
|
|
m_bNoRecords=true;
|
|
return;
|
|
}
|
|
else
|
|
m_bNoRecords=false;
|
|
EnableFields(true);
|
|
|
|
rs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
rs->FetchField("item",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbModels.AddRow(strData,strIndex);
|
|
}while(rs->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);
|
|
|
|
|
|
//trigger selection
|
|
OnCloseupCbmodels();
|
|
}
|
|
|
|
|
|
//********************************************
|
|
void CModelsDlg::FillManufacturerList()
|
|
{
|
|
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbManufacturers.Clear();
|
|
|
|
//set defaults
|
|
strData="<Unknown>";
|
|
strIndex="0";
|
|
m_cbManufacturers.AddRow(strData,strIndex);
|
|
|
|
//type 3 = manufacturers
|
|
cbrs->Query("SELECT nonclients.* "
|
|
"FROM nonclients "
|
|
"WHERE (((nonclients.type)=3)) "
|
|
"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_cbManufacturers.AddRow(strData,strIndex);
|
|
}while(cbrs->MoveForward());
|
|
|
|
}
|
|
|
|
|
|
//*******************************************
|
|
|
|
void CModelsDlg::SetReturnString(CString *strReturn)
|
|
{
|
|
m_pstrReturnValue=strReturn;
|
|
//specific record should be shown?
|
|
if(!m_pstrReturnValue->IsEmpty())
|
|
m_strSelectedModel=*m_pstrReturnValue;
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
void CModelsDlg::FillFields()
|
|
{
|
|
|
|
CString q,strData;
|
|
COleDateTime dtData;
|
|
bool bData;
|
|
long lData;
|
|
//Fill all fields based on current record.
|
|
strData=m_cbModels.GetCurrentRowID();
|
|
if(strData.IsEmpty())
|
|
return;
|
|
|
|
q.Format("SELECT unitmodels.* "
|
|
"FROM unitmodels "
|
|
"WHERE (((unitmodels.id)=%s));",strData);
|
|
|
|
rs->Query(q);
|
|
|
|
if(rs->IsEmpty())
|
|
return;//something very wrong if this ever gets called
|
|
|
|
//FETCHFIELDS AND FILL BOXES
|
|
|
|
//MODEL
|
|
rs->FetchField("model",&strData);
|
|
m_edModel.SetWindowText(strData);
|
|
|
|
//DESCRIPTION
|
|
rs->FetchField("description",&strData);
|
|
m_edDescription.SetWindowText(strData);
|
|
|
|
//CATEGORY
|
|
rs->FetchField("category",&lData);
|
|
strData.Format("%u",lData);
|
|
m_cbCategories.Select(strData);
|
|
|
|
//LIFETIMEWARRANTY
|
|
rs->FetchField("lifetimewarranty",&bData);
|
|
m_ckLifetime.SetCheck(bData ? TRUE : FALSE);
|
|
|
|
//WARRANTY (months)
|
|
rs->FetchField("warranty",&lData);
|
|
strData.Format("%u",lData);
|
|
m_edWarrantyMonths.SetWindowText(strData);
|
|
|
|
//WARRANTYTERMS
|
|
rs->FetchField("warrantyterms",&strData);
|
|
m_edWarrantyTerms.SetWindowText(strData);
|
|
|
|
//MANUFACTURER
|
|
rs->FetchField("manufacturer",&lData);
|
|
strData.Format("%u",lData);
|
|
m_cbManufacturers.Select(strData);
|
|
|
|
//DISCONTINUED
|
|
rs->FetchField("discontinued",&bData);
|
|
m_ckDiscontinued.SetCheck(bData ? TRUE : FALSE);
|
|
m_dtDiscontinued.ShowWindow(bData ? TRUE : FALSE);
|
|
if(m_bReadOnly)
|
|
m_dtDiscontinued.EnableWindow(FALSE);
|
|
//DISCONTINUED DATE (IF APPLICABLE)
|
|
if(bData)
|
|
{
|
|
rs->FetchField("discodate",&dtData);
|
|
m_dtDiscontinued.SetTime(dtData);
|
|
|
|
}
|
|
|
|
//INTRODUCED DATE
|
|
rs->FetchField("introduced",&dtData);
|
|
m_dtIntroduced.SetTime(dtData);
|
|
|
|
//NOTES
|
|
rs->FetchField("notes",&strData);
|
|
m_edNotes.SetWindowText(strData);
|
|
|
|
//
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************************
|
|
//SAVE EDIT CONTROL FIELD
|
|
//************************************************************
|
|
bool CModelsDlg::SaveField(CEdit *edControl,CString fldname,bool AllowEmpty)
|
|
{
|
|
|
|
if(m_bAddMode || m_bNoRecords) 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 CModelsDlg::SaveField(CgzCombo *cbControl,CString fldname)
|
|
{
|
|
|
|
if(m_bAddMode || m_bNoRecords) 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 CModelsDlg::SaveField(CButton *ckControl,CString fldname)
|
|
{
|
|
if(m_bAddMode || m_bNoRecords) 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 CModelsDlg::SaveField(CDateTimeCtrl *dtControl,CString fldname)
|
|
{
|
|
if(m_bAddMode || m_bNoRecords) return true;//dont attempt to update
|
|
COleDateTime dtData;
|
|
dtControl->GetTime(dtData);
|
|
rs->UpdateField(fldname,&dtData);
|
|
rs->SaveRecord();
|
|
UpdateModified();
|
|
return true;
|
|
}
|
|
|
|
|
|
//************************************************
|
|
//UPDATE MODIFIED DATA
|
|
//*************************************************
|
|
bool CModelsDlg::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 CModelsDlg::OnBtnpm()
|
|
{
|
|
|
|
if(m_bNoRecords || m_strSelectedModel.IsEmpty() || m_strSelectedModel=="0") return;
|
|
|
|
|
|
//Open the PM dialog for this model
|
|
CPM d;
|
|
CString prompt;
|
|
CString str;
|
|
str=m_cbModels.GetCurrentRowText();//m_edModel.GetWindowText(str);
|
|
prompt="Preventive maintenance for Model#: " + str;
|
|
|
|
//set criteria serial number
|
|
d.PreInitialize(false,true,m_strSelectedModel,prompt);
|
|
d.DoModal();
|
|
|
|
|
|
}
|
|
|
|
|
|
void CModelsDlg::EnableFields(bool bEnable)
|
|
{
|
|
if(m_bReadOnly)
|
|
return;
|
|
BOOL enable = bEnable ? TRUE : FALSE;
|
|
m_btnDelete.EnableWindow(enable);
|
|
m_btnPM.EnableWindow(enable);
|
|
m_cbCategories.EnableWindow(enable);
|
|
m_cbManufacturers.EnableWindow(enable);
|
|
m_cbModels.EnableWindow(enable);
|
|
m_ckActive.EnableWindow(enable);
|
|
m_ckDiscontinued.EnableWindow(enable);
|
|
m_ckLifetime.EnableWindow(enable);
|
|
m_dtDiscontinued.EnableWindow(enable);
|
|
m_dtIntroduced.EnableWindow(enable);
|
|
m_edModel.EnableWindow(enable);
|
|
m_edNotes.EnableWindow(enable);
|
|
m_lblCategory.EnableWindow(enable);
|
|
m_lblManufacturer.EnableWindow(enable);
|
|
m_lblModels.EnableWindow(enable);
|
|
m_edWarrantyMonths.EnableWindow(enable);
|
|
m_edWarrantyTerms.EnableWindow(enable);
|
|
m_edDescription.EnableWindow(enable);
|
|
|
|
}
|
|
|
|
void CModelsDlg::OnKillfocusEddescription()
|
|
{
|
|
SaveField(&m_edDescription,"description",true);
|
|
if(!m_bAddMode)
|
|
FillModelList();
|
|
}
|
|
|
|
void CModelsDlg::OnLblbymodel()
|
|
{
|
|
m_bListByDescription=false;
|
|
FillModelList();
|
|
}
|
|
|
|
void CModelsDlg::OnLblbydesc()
|
|
{
|
|
m_bListByDescription=true;
|
|
FillModelList();
|
|
}
|
|
|
|
void CModelsDlg::Security()
|
|
{
|
|
m_bReadOnly=false;
|
|
int x=m_pApp->Allowed(RMODELS,true);
|
|
if(x==0)//no access allowed
|
|
{
|
|
m_pApp->SecurityWarning();
|
|
CDialog::OnCancel();
|
|
}
|
|
if(x==2)//read only
|
|
{
|
|
m_bReadOnly=true;
|
|
m_btnAdd.ShowWindow(FALSE);
|
|
m_btnDelete.ShowWindow(FALSE);
|
|
m_cbCategories.EnableWindow(FALSE);
|
|
m_cbManufacturers.EnableWindow(FALSE);
|
|
//m_cbModels.EnableWindow(FALSE);
|
|
m_ckActive.EnableWindow(FALSE);
|
|
m_ckDiscontinued.EnableWindow(FALSE);
|
|
m_ckLifetime.EnableWindow(FALSE);
|
|
m_dtDiscontinued.EnableWindow(FALSE);
|
|
m_dtIntroduced.EnableWindow(FALSE);
|
|
m_edDescription.SetReadOnly(TRUE);
|
|
m_edModel.SetReadOnly(TRUE);
|
|
m_edWarrantyTerms.SetReadOnly(TRUE);
|
|
m_edWarrantyMonths.SetReadOnly(TRUE);
|
|
m_lblCategory.EnableWindow(FALSE);
|
|
m_lblManufacturer.EnableWindow(FALSE);
|
|
|
|
m_lblModels.EnableWindow(FALSE);
|
|
m_edNotes.SetReadOnly(TRUE);
|
|
|
|
}
|
|
}
|