477 lines
11 KiB
C++
477 lines
11 KiB
C++
// LoanersEditDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "LoanersEditDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLoanersEditDlg dialog
|
|
|
|
|
|
CLoanersEditDlg::CLoanersEditDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CLoanersEditDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CLoanersEditDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_pApp = (CSpApp*)AfxGetApp();
|
|
//Initialize recordset pointer
|
|
rs=m_pApp->rsPool->GetRS("CLoanersEditDlg");
|
|
rs2=m_pApp->rsPool->GetRS("CLoanersEditDlg rs2");
|
|
|
|
cfm = new CgzCurrencyFormatter;
|
|
m_strRentalID.Empty();
|
|
m_strSelClient="0";
|
|
m_strSelUnit="0";
|
|
m_strSelPart="0";
|
|
}
|
|
|
|
CLoanersEditDlg::~CLoanersEditDlg()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
m_pApp->rsPool->ReleaseRS(&rs2->m_nID);
|
|
|
|
delete cfm;
|
|
|
|
}
|
|
|
|
void CLoanersEditDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CLoanersEditDlg)
|
|
DDX_Control(pDX, IDC_EDREF, m_edRef);
|
|
DDX_Control(pDX, IDC_BTNCANCEL, m_btnCancel);
|
|
DDX_Control(pDX, IDC_DTDATEDUE, m_dtDateDue);
|
|
DDX_Control(pDX, IDC_EDNOTES, m_edNotes);
|
|
DDX_Control(pDX, IDC_EDLOANEDTO, m_edLoanedTo);
|
|
DDX_Control(pDX, IDC_EDDESCRIPTION, m_edDescription);
|
|
DDX_Control(pDX, IDC_EDCHARGES, m_edCharges);
|
|
DDX_Control(pDX, IDC_DTDATERETURN, m_dtDateReturn);
|
|
DDX_Control(pDX, IDC_DTDATEOUT, m_dtDateOut);
|
|
DDX_Control(pDX, IDC_CKRETURNED, m_ckReturned);
|
|
DDX_Control(pDX, IDC_CBUNIT, m_cbUnits);
|
|
DDX_Control(pDX, IDC_CBPART, m_cbParts);
|
|
DDX_Control(pDX, IDC_CBCLIENT, m_cbClient);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CLoanersEditDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CLoanersEditDlg)
|
|
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
|
|
ON_EN_KILLFOCUS(IDC_EDCHARGES, OnKillfocusEdcharges)
|
|
ON_CBN_CLOSEUP(IDC_CBPART, OnCloseupCbpart)
|
|
ON_CBN_CLOSEUP(IDC_CBUNIT, OnCloseupCbunit)
|
|
ON_EN_KILLFOCUS(IDC_EDDESCRIPTION, OnKillfocusEddescription)
|
|
ON_BN_CLICKED(IDC_BTNCANCEL, OnBtncancel)
|
|
ON_BN_CLICKED(IDC_CKRETURNED, OnCkreturned)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLoanersEditDlg message handlers
|
|
|
|
BOOL CLoanersEditDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
Security();
|
|
FillListBoxes();
|
|
FillFields();
|
|
m_edRef.SetLimitText(80);
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
//pass in rental id to indicate editing:
|
|
void CLoanersEditDlg::SetRentalID(CString *strRentalID)
|
|
{
|
|
if(strRentalID!=NULL)
|
|
m_strRentalID=*strRentalID;
|
|
}
|
|
|
|
|
|
|
|
void CLoanersEditDlg::FillFields()
|
|
{
|
|
COleCurrency crCharges;
|
|
COleDateTime dtOut,dtDue,dtReturned;
|
|
bool bReturned;
|
|
long lPart,lUnit,lClient;
|
|
CString q,strData,strDescription,strLoanedTo,strNotes,strRef;
|
|
|
|
if(m_strRentalID.IsEmpty()) return;
|
|
|
|
q.Format("SELECT rentals.* FROM rentals "
|
|
"WHERE (((rentals.id)=%s));",m_strRentalID);
|
|
rs->Query(q);
|
|
|
|
|
|
//Fetch the fields:
|
|
rs->FetchField("partlink",&lPart);
|
|
rs->FetchField("unitlink",&lUnit);
|
|
rs->FetchField("clientlink",&lClient);
|
|
rs->FetchField("loanedto",&strLoanedTo);
|
|
rs->FetchField("description",&strDescription);
|
|
rs->FetchField("dateout",&dtOut);
|
|
rs->FetchField("datedue",&dtDue);
|
|
rs->FetchField("datereturn",&dtReturned);
|
|
rs->FetchField("charges",&crCharges);
|
|
rs->FetchField("returned",&bReturned);
|
|
rs->FetchField("notes",&strNotes);
|
|
rs->FetchField("ref",&strRef);
|
|
|
|
|
|
//CHARGES
|
|
m_edCharges.SetWindowText(cfm->Format(crCharges));
|
|
|
|
//CLIENT
|
|
m_cbClient.Select(lClient);
|
|
|
|
//LOANED TO
|
|
m_edLoanedTo.SetWindowText(strLoanedTo);
|
|
|
|
//UNIT
|
|
m_cbUnits.Select(lUnit);
|
|
|
|
//PART
|
|
m_cbParts.Select(lPart);
|
|
|
|
//ITEM DESCRIPTION
|
|
m_edDescription.SetWindowText(strDescription);
|
|
|
|
//OUT DATE
|
|
m_dtDateOut.SetTime(dtOut);
|
|
|
|
//DUE DATE
|
|
m_dtDateDue.SetTime(dtDue);
|
|
|
|
//RETURNED DATE
|
|
m_dtDateReturn.SetTime(dtReturned);
|
|
|
|
//RETURNED FLAG
|
|
m_ckReturned.SetCheck(bReturned ? TRUE : FALSE);
|
|
m_dtDateReturn.EnableWindow(bReturned ? TRUE : FALSE);
|
|
|
|
//REFERENCE
|
|
m_edRef.SetWindowText(strRef);
|
|
|
|
//NOTES
|
|
m_edNotes.SetWindowText(strNotes);
|
|
|
|
|
|
}
|
|
|
|
void CLoanersEditDlg::FillListBoxes()
|
|
{
|
|
CString strData;
|
|
CString strIndex;
|
|
CString q;
|
|
|
|
long lData;
|
|
m_cbParts.Clear();
|
|
m_cbParts.AddRow(" <Not a part>","0");
|
|
|
|
rs->QueryReadOnly("SELECT parts.id, [partnumber] & \" - \" "
|
|
"& [description] AS name FROM parts "
|
|
"WHERE (((parts.active)=True)) ORDER BY parts.partnumber;");
|
|
if(!rs->IsEmpty())
|
|
{
|
|
rs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbParts.AddRow(strData,strIndex);
|
|
}while(rs->MoveForward());
|
|
|
|
}
|
|
|
|
m_cbParts.Select(m_strSelPart);
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================
|
|
//CLIENTS LIST
|
|
|
|
m_cbClient.Clear();
|
|
|
|
m_cbClient.AddRow(" <non-database client>","0");
|
|
|
|
rs->QueryReadOnly("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(!rs->IsEmpty())
|
|
{
|
|
do
|
|
{
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbClient.AddRow(strData,strIndex);
|
|
}while(rs->MoveForward());
|
|
}
|
|
m_cbClient.Select(m_strSelClient);
|
|
|
|
//============================================
|
|
//FILL UNIT LIST:
|
|
m_cbUnits.Clear();
|
|
m_cbUnits.AddRow(" < No unit >","0");
|
|
|
|
|
|
|
|
rs->QueryReadOnly("SELECT units.id, [sn] & \" - \" & [company_person] & \" \" & [unitmodels].[description] & \" \" & [unitmodels].[model] AS name "
|
|
"FROM (units LEFT JOIN unitmodels ON units.model = unitmodels.id) LEFT JOIN nonclients ON unitmodels.manufacturer = nonclients.id "
|
|
"WHERE (((units.loaner)=True)) "
|
|
"ORDER BY units.sn;");
|
|
|
|
if(!rs->IsEmpty())
|
|
{
|
|
do
|
|
{
|
|
rs->FetchField("name",&strData);
|
|
strData.TrimRight("- ");
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
|
|
//see if it's out right now
|
|
q.Format("SELECT rentals.unitlink FROM rentals "
|
|
"WHERE (((rentals.returned)=False) AND ((rentals.unitlink)=%u));",lData);
|
|
rs2->QueryReadOnly(q);
|
|
if(!rs2->IsEmpty())//out
|
|
strData="z_Out: " + strData;
|
|
m_cbUnits.AddRow(strData,strIndex);
|
|
}while(rs->MoveForward());
|
|
}
|
|
|
|
m_cbUnits.Select(m_strSelUnit);
|
|
}
|
|
|
|
//****************************************************
|
|
//Saving/updating and exit
|
|
void CLoanersEditDlg::OnBtndone()
|
|
{
|
|
|
|
if(m_bReadOnly)
|
|
CDialog::OnOK();
|
|
COleCurrency crCharges;
|
|
COleDateTime dtOut,dtDue,dtReturned;
|
|
bool bReturned;
|
|
long lPart,lUnit,lClient;
|
|
CString q,strData,strDescription,strLoanedTo,strNotes,strRef;
|
|
|
|
|
|
//CHARGES
|
|
m_edCharges.GetWindowText(strData);
|
|
crCharges.ParseCurrency(strData);
|
|
|
|
//CLIENT
|
|
strData=m_cbClient.GetCurrentRowID();
|
|
lClient=atol(strData);
|
|
|
|
//LOANED TO
|
|
m_edLoanedTo.GetWindowText(strLoanedTo);
|
|
|
|
//UNIT
|
|
strData=m_cbUnits.GetCurrentRowID();
|
|
lUnit=atol(strData);
|
|
|
|
//PART
|
|
strData=m_cbParts.GetCurrentRowID();
|
|
lPart=atol(strData);
|
|
|
|
//ITEM DESCRIPTION
|
|
m_edDescription.GetWindowText(strDescription);
|
|
|
|
//OUT DATE
|
|
m_dtDateOut.GetTime(dtOut);
|
|
|
|
//DUE DATE
|
|
m_dtDateDue.GetTime(dtDue);
|
|
|
|
//RETURNED DATE
|
|
m_dtDateReturn.GetTime(dtReturned);
|
|
|
|
//RETURNED FLAG
|
|
bReturned=m_ckReturned.GetCheck() ? true : false;
|
|
|
|
//REFERENCE
|
|
m_edRef.GetWindowText(strRef);
|
|
|
|
//NOTES
|
|
m_edNotes.GetWindowText(strNotes);
|
|
|
|
|
|
//Validation and judging: "Whose cuisine will reign supreme?"
|
|
if(lClient==0 && strLoanedTo.IsEmpty())
|
|
{
|
|
AfxMessageBox("You need to indicate who has this equipment");
|
|
return;
|
|
}
|
|
|
|
if(lUnit==0 && lPart ==0 && strDescription.IsEmpty())
|
|
{
|
|
AfxMessageBox("You haven't indicated what item this record refers to");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m_strRentalID.IsEmpty())
|
|
{//Add new record
|
|
q="SELECT rentals.* FROM rentals "
|
|
"WHERE (((rentals.id)=0));";
|
|
}
|
|
else
|
|
{
|
|
//update existing record
|
|
q.Format("SELECT rentals.* FROM rentals "
|
|
"WHERE (((rentals.id)=%s));",m_strRentalID);
|
|
|
|
}
|
|
|
|
rs->Query(q);
|
|
//Add a record if necessary
|
|
if(m_strRentalID.IsEmpty())
|
|
rs->AddNewRecord();
|
|
|
|
//Update the fields:
|
|
rs->UpdateField("partlink",&lPart);
|
|
rs->UpdateField("unitlink",&lUnit);
|
|
rs->UpdateField("clientlink",&lClient);
|
|
rs->UpdateField("loanedto",&strLoanedTo);
|
|
rs->UpdateField("description",&strDescription);
|
|
rs->UpdateField("dateout",&dtOut);
|
|
rs->UpdateField("datedue",&dtDue);
|
|
rs->UpdateField("datereturn",&dtReturned);
|
|
rs->UpdateField("charges",&crCharges);
|
|
rs->UpdateField("returned",&bReturned);
|
|
rs->UpdateField("ref",&strRef);
|
|
rs->UpdateField("notes",&strNotes);
|
|
rs->SaveRecord();
|
|
|
|
|
|
|
|
|
|
|
|
//this is just to flush the update through
|
|
//rs->Query("SELECT rentals.* from rentals WHERE rentals.id=0;");
|
|
//modified Jan 10 2000 as proper flush is now
|
|
//guranteed with a close
|
|
rs->Close();
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
|
|
//Validate charges as entered
|
|
void CLoanersEditDlg::OnKillfocusEdcharges()
|
|
{
|
|
CString strData;
|
|
COleCurrency crData;
|
|
m_edCharges.GetWindowText(strData);
|
|
crData.ParseCurrency(strData);
|
|
m_edCharges.SetWindowText(cfm->Format(crData));
|
|
|
|
}
|
|
|
|
void CLoanersEditDlg::OnCloseupCbpart()
|
|
{
|
|
|
|
m_strSelPart=m_cbParts.GetCurrentRowID();
|
|
//erase other two fields
|
|
if(m_strSelPart!="0")
|
|
{
|
|
m_strSelUnit="0";
|
|
m_cbUnits.Select(m_strSelUnit);
|
|
m_edDescription.SetWindowText("");
|
|
}
|
|
}
|
|
|
|
void CLoanersEditDlg::OnCloseupCbunit()
|
|
{
|
|
m_strSelUnit=m_cbUnits.GetCurrentRowID();
|
|
//erase other two fields
|
|
if(m_strSelUnit!="0")
|
|
{
|
|
m_strSelPart="0";
|
|
m_cbParts.Select(m_strSelPart);
|
|
m_edDescription.SetWindowText("");
|
|
}
|
|
}
|
|
|
|
void CLoanersEditDlg::OnKillfocusEddescription()
|
|
{
|
|
CString strData;
|
|
m_edDescription.GetWindowText(strData);
|
|
if(strData.GetLength()>1)
|
|
{
|
|
m_strSelUnit="0";
|
|
m_strSelPart="0";
|
|
m_cbParts.Select(m_strSelPart);
|
|
m_cbUnits.Select(m_strSelUnit);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void CLoanersEditDlg::OnBtncancel()
|
|
{
|
|
CDialog::OnCancel();
|
|
|
|
}
|
|
|
|
void CLoanersEditDlg::OnOK(){}
|
|
|
|
|
|
void CLoanersEditDlg::OnCkreturned()
|
|
{
|
|
m_dtDateReturn.EnableWindow(m_ckReturned.GetCheck());
|
|
|
|
}
|
|
|
|
void CLoanersEditDlg::Security()
|
|
{
|
|
int x=m_pApp->Allowed(RLOANERS,true);
|
|
m_bReadOnly=false;
|
|
if(x==2)//read only
|
|
{
|
|
m_bReadOnly=true;
|
|
m_btnCancel.ShowWindow(FALSE);
|
|
m_cbClient.EnableWindow(FALSE);
|
|
m_cbParts.EnableWindow(FALSE);
|
|
m_cbUnits.EnableWindow(FALSE);
|
|
m_ckReturned.EnableWindow(FALSE);
|
|
m_dtDateDue.EnableWindow(FALSE);
|
|
m_dtDateOut.EnableWindow(FALSE);
|
|
m_dtDateReturn.EnableWindow(FALSE);
|
|
m_edCharges.SetReadOnly(TRUE);
|
|
m_edDescription.SetReadOnly(TRUE);
|
|
m_edLoanedTo.SetReadOnly(TRUE);
|
|
m_edNotes.SetReadOnly(TRUE);
|
|
|
|
}
|
|
|
|
|
|
if(x==0)
|
|
{
|
|
m_pApp->SecurityWarning();
|
|
CDialog::OnCancel();
|
|
}
|
|
}
|
|
|
|
|