532 lines
14 KiB
C++
532 lines
14 KiB
C++
// WODlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "WODlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
//memory leak debugging help
|
|
#define _CRTDBG_MAP_ALLOC
|
|
#include <stdlib.h>
|
|
#include <crtdbg.h>
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CWODlg dialog
|
|
|
|
|
|
CWODlg::CWODlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CWODlg::IDD, pParent)
|
|
{
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"OPENING STANDARD WORKORDER SCREEN\r\n"
|
|
"*****************************\r\n\r\n");
|
|
|
|
//{{AFX_DATA_INIT(CWODlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_strWorkorderID.Empty();
|
|
m_strProblemID.Empty();
|
|
m_bAddMode=false;
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
/*
|
|
rs = new GZRset("Error: Standard workorder problem dialog - RS");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
|
|
//Initialize recordset pointer
|
|
|
|
rs=m_pApp->rsPool->GetRS("CWODlg (init)");
|
|
}
|
|
|
|
|
|
CWODlg::~CWODlg()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
delete m_pTabLabour;
|
|
delete m_pTabParts;
|
|
delete m_pTabProblem;
|
|
delete m_pTabSubRepair;
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"LEAVING STANDARD WORKORDER SCREEN\r\n"
|
|
"*****************************\r\n\r\n");
|
|
}
|
|
|
|
void CWODlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CWODlg)
|
|
DDX_Control(pDX, IDC_WOTAB, m_tab);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CWODlg, CDialog)
|
|
//{{AFX_MSG_MAP(CWODlg)
|
|
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
|
|
ON_BN_CLICKED(IDC_BTNCANCEL, OnBtncancel)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CWODlg message handlers
|
|
|
|
BOOL CWODlg::OnInitDialog()
|
|
{
|
|
CString q;
|
|
long lData;
|
|
|
|
|
|
|
|
|
|
|
|
CDialog::OnInitDialog();
|
|
ShowWindow(FALSE);
|
|
CWaitCursor dummy;
|
|
ASSERT(!m_strWorkorderID.IsEmpty());
|
|
|
|
Security();
|
|
|
|
|
|
|
|
//CREATE NEW RECORD IF ADD MODE
|
|
if(m_bAddMode)
|
|
{
|
|
//start a new problem record:
|
|
rs->Query("SELECT probs.* FROM probs WHERE (((probs.id)=0));");//
|
|
|
|
//now add the new record
|
|
rs->pTheConnection->BeginTrans();
|
|
rs->AddNewRecord();
|
|
rs->UpdateField("wolink",&m_strWorkorderID);
|
|
rs->UpdateField("creator",&m_pApp->m_lusrID);
|
|
COleDateTime dtData;
|
|
dtData=COleDateTime::GetCurrentTime();
|
|
rs->UpdateField("created",&dtData);
|
|
rs->SaveRecord();
|
|
rs->pTheConnection->CommitTrans();
|
|
|
|
//now go back and find the record just created to get the id number
|
|
//by using some unique variables for the query
|
|
q.Format("SELECT probs.* FROM probs WHERE (((probs.creator)=%u) "
|
|
"AND ((probs.created)=#%s#) AND ((probs.wolink)=%s));",
|
|
m_pApp->m_lusrID,dtData.Format(_T("%m/%d/%Y %H:%M:%S")),m_strWorkorderID);
|
|
rs->Query(q);
|
|
rs->FetchField("id",&lData);
|
|
m_strProblemID.Format("%u",lData);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
//PROBLEM TAB
|
|
m_pTabProblem = new CWOTABProblem;
|
|
m_pTabProblem->m_pstrProblemID=&m_strProblemID;
|
|
m_pTabProblem->m_pstrWorkorderID=&m_strWorkorderID;
|
|
m_pTabProblem->m_pstrClientID=&m_strClientID;
|
|
m_pTabProblem->Create(CWOTABProblem::IDD, &m_tab);
|
|
m_tab.AddTab(m_pTabProblem, "Problem / Unit", 0);
|
|
m_pTabProblem->m_pTab = &m_tab;
|
|
//----------------------------------------------
|
|
|
|
//PARTS
|
|
m_pTabParts = new CWOTABParts;
|
|
m_pTabParts->m_pstrProblemID=&m_strProblemID;
|
|
m_pTabParts->m_pstrWorkorderID=&m_strWorkorderID;
|
|
m_pTabParts->Create(CWOTABParts::IDD, &m_tab);
|
|
m_tab.AddTab(m_pTabParts, "Parts / supplies", 1);
|
|
m_pTabParts->m_pTab = &m_tab;
|
|
//----------------------------------------------
|
|
|
|
//LABOUR
|
|
m_pTabLabour = new CWOTABLabour;
|
|
m_pTabLabour->m_pstrProblemID=&m_strProblemID;
|
|
m_pTabLabour->m_pstrWorkorderID=&m_strWorkorderID;
|
|
m_pTabLabour->m_pstrClientID=&m_strClientID;
|
|
m_pTabLabour->Create(CWOTABLabour::IDD, &m_tab);
|
|
m_tab.AddTab(m_pTabLabour, "Labor", 2);
|
|
m_pTabLabour->m_pTab = &m_tab;
|
|
//----------------------------------------------
|
|
|
|
//WARRANTY 3RD PARTY
|
|
m_pTabSubRepair = new CWOTABSubRepair;
|
|
m_pTabSubRepair->m_pstrProblemID=&m_strProblemID;
|
|
m_pTabSubRepair->m_pstrWorkorderID=&m_strWorkorderID;
|
|
m_pTabSubRepair->Create(CWOTABSubRepair::IDD, &m_tab);
|
|
m_tab.AddTab(m_pTabSubRepair, "Warranty / 3rd party", 3);
|
|
m_pTabSubRepair->m_pTab = &m_tab;
|
|
//----------------------------------------------
|
|
|
|
|
|
|
|
|
|
m_tab.SelectTab(0);
|
|
|
|
q.Format("Problem / service item for workorder #: %s",m_strWorkorderID);
|
|
SetWindowText(q);
|
|
|
|
|
|
ShowWindow(SW_MAXIMIZE);
|
|
|
|
|
|
//added 06062001 to find and fix another user problem
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
|
|
//#ifdef _DEBUG
|
|
//===================================================
|
|
// 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);
|
|
//===================================================
|
|
//#endif
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
|
|
void CWODlg::SetIDValues(CString strWO, CString strPROB, CString strClient, bool * modified)
|
|
{
|
|
|
|
m_strWorkorderID=strWO;
|
|
m_strProblemID=strPROB;
|
|
m_strClientID=strClient;
|
|
if(strPROB=="0")
|
|
m_bAddMode=true;
|
|
bModified=modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CWODlg::OnBtndone()
|
|
{
|
|
CString profile,q,strData;
|
|
COleDateTime dtData;
|
|
COleCurrency crData;
|
|
bool bData,bNewSubRepair;
|
|
long lData;
|
|
float fData;
|
|
|
|
//1.9.4.2
|
|
//was not saving updated meter count to unit record
|
|
bool bUpdateMeterCountInUnitRecord=false;
|
|
long lUnitToUpdateMeterCount=0;
|
|
long lUpdatedMeterCount=0;
|
|
|
|
//Save whatever needs to be saved
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() TOP\r\n"
|
|
"*****************************\r\n\r\n");
|
|
//set modified flag
|
|
if(m_pTabLabour->bModified || m_pTabParts->bModified
|
|
|| m_pTabProblem->bModified || m_pTabSubRepair->bModified)
|
|
*bModified=true;
|
|
|
|
rs=m_pApp->rsPool->GetRS("CWODlg (save/done)");
|
|
|
|
|
|
/*
|
|
|
|
|
|
*/
|
|
|
|
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() MIDDLE\r\n"
|
|
"*****************************\r\n\r\n");
|
|
|
|
|
|
//SAVE EACH TAB THAT DOESN'T SAVE ITSELF
|
|
|
|
//Problem tab
|
|
//Fetch problem description and values for partnum pm item, unit and probstat
|
|
q.Format("SELECT probs.* FROM probs "
|
|
"WHERE (((probs.id)=%s));",m_strProblemID);
|
|
rs->Query(q);
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() Problem tab TOP\r\n"
|
|
"*****************************\r\n\r\n");
|
|
ASSERT(!rs->IsEmpty());
|
|
|
|
rs->pTheConnection->BeginTrans();
|
|
m_pTabProblem->m_edProblemBrief.GetWindowText(strData);
|
|
if(strData.IsEmpty())
|
|
strData="<No description>";
|
|
rs->UpdateField("brief",&strData);
|
|
|
|
|
|
|
|
m_pTabProblem->m_edProblem.GetWindowText(strData);
|
|
rs->UpdateField("notes",&strData);
|
|
|
|
strData=m_pTabProblem->m_cbProbStat.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("status",&lData);
|
|
|
|
lData=atol(m_strWorkorderID);
|
|
rs->UpdateField("wolink",&lData);
|
|
|
|
strData=m_pTabProblem->m_cbPMList.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("pmscheduleid",&lData);
|
|
|
|
strData=m_pTabProblem->m_cbSNUnits.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("unit",&lData);
|
|
|
|
//1.9.4.2 save unit id in case needed to update meter count
|
|
lUnitToUpdateMeterCount=lData;
|
|
|
|
//METER COUNT
|
|
m_pTabProblem->m_edMeter.GetWindowText(strData);
|
|
//max size 2,147,483,647
|
|
lData=atol(strData);
|
|
rs->UpdateField("meter",&lData);
|
|
|
|
//1.9.4.2 fix for updated meter count not being saved to unit record
|
|
if(lData>0)
|
|
{
|
|
lUpdatedMeterCount=lData;
|
|
bUpdateMeterCountInUnitRecord=true;
|
|
}
|
|
|
|
|
|
//08/21/2001 each tab sets it's own indexed status now
|
|
if(*bModified)
|
|
{
|
|
bData=false;
|
|
rs->UpdateField("indexed",&bData);
|
|
}
|
|
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() Problem tab SAVING RECORD\r\n"
|
|
"*****************************\r\n\r\n");
|
|
|
|
|
|
rs->SaveRecord();
|
|
rs->pTheConnection->CommitTrans();
|
|
rs->Close();
|
|
//******************************************************************************
|
|
//1.9.4.2 update meter count fix
|
|
if(bUpdateMeterCountInUnitRecord)
|
|
{
|
|
q.Format("UPDATE units SET units.lastmeter = %u WHERE (((units.id)=%u));",
|
|
lUpdatedMeterCount,lUnitToUpdateMeterCount);
|
|
rs->Ex(q);
|
|
|
|
|
|
}
|
|
|
|
|
|
//SUBREPAIRS
|
|
if(m_pTabSubRepair->bModified)
|
|
{
|
|
|
|
bNewSubRepair=true;
|
|
//subrepair tab
|
|
//try to open existing
|
|
q.Format("SELECT subrepair.* FROM subrepair "
|
|
"WHERE (((subrepair.link)=%s));",m_strProblemID);
|
|
rs->Query(q);
|
|
//not there?
|
|
if(rs->IsEmpty())
|
|
{
|
|
bNewSubRepair=true;
|
|
q.Format("INSERT INTO subrepair ( link ) SELECT %s;",m_strProblemID);
|
|
rs->Ex(q);
|
|
rs->Close();
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 8\r\n"
|
|
"*****************************\r\n\r\n");
|
|
|
|
q.Format("SELECT subrepair.* FROM subrepair "
|
|
"WHERE (((subrepair.link)=%s));",m_strProblemID);
|
|
rs->Query(q);
|
|
|
|
}
|
|
|
|
rs->pTheConnection->BeginTrans();
|
|
strData=m_pTabSubRepair->m_cbSentTo.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("where",&lData);
|
|
|
|
m_pTabSubRepair->m_dtSent.GetTime(dtData);
|
|
rs->UpdateField("sent",&dtData);
|
|
|
|
bData=(m_pTabSubRepair->m_ckReceived.GetCheck() ? true : false);
|
|
//1.9.3.0
|
|
//rs->UpdateField("received",&bData);
|
|
rs->UpdateField("isback",&bData);
|
|
|
|
m_pTabSubRepair->m_dtRecEta.GetTime(dtData);
|
|
if(bData)
|
|
rs->UpdateField("received",&dtData);
|
|
else
|
|
rs->UpdateField("eta",&dtData);
|
|
|
|
strData=m_pTabSubRepair->m_cbSentVia.GetCurrentRowID();
|
|
lData=atol(strData);
|
|
rs->UpdateField("sentvia",&lData);
|
|
|
|
m_pTabSubRepair->m_edWaybill.GetWindowText(strData);
|
|
rs->UpdateField("waybill",&strData);
|
|
|
|
m_pTabSubRepair->m_edRMA.GetWindowText(strData);
|
|
rs->UpdateField("rma",&strData);
|
|
|
|
m_pTabSubRepair->m_edNotes.GetWindowText(strData);
|
|
rs->UpdateField("notes",&strData);
|
|
|
|
m_pTabSubRepair->m_edCost.GetWindowText(strData);
|
|
crData.ParseCurrency(strData);
|
|
rs->UpdateField("cost",&crData);
|
|
|
|
m_pTabSubRepair->m_edCharge.GetWindowText(strData);
|
|
crData.ParseCurrency(strData);
|
|
rs->UpdateField("charge",&crData);
|
|
|
|
dtData=COleDateTime::GetCurrentTime();
|
|
if(bNewSubRepair)
|
|
{
|
|
rs->UpdateField("creator",&m_pApp->m_lusrID);
|
|
|
|
rs->UpdateField("created",&dtData);
|
|
rs->SaveRecord();
|
|
}
|
|
|
|
rs->UpdateField("modifier",&m_pApp->m_lusrID);
|
|
|
|
rs->UpdateField("modified",&dtData);
|
|
|
|
//08/21/2001 each tab sets it's own indexed status now
|
|
|
|
bData=false;
|
|
rs->UpdateField("indexed",&bData);
|
|
rs->SaveRecord();
|
|
rs->pTheConnection->CommitTrans();
|
|
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 9\r\n"
|
|
"*****************************\r\n\r\n");
|
|
rs->Close();
|
|
//rs->SaveRecord();
|
|
|
|
}
|
|
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 10\r\n"
|
|
"*****************************\r\n\r\n");
|
|
|
|
//FLUSH THE CHANGES
|
|
//rs->Query("SELECT probs.* FROM probs WHERE (((probs.id)=0));");
|
|
rs->Close();
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
//MODIFIED / INDEXED BLOCK
|
|
|
|
//SET NOT INDEXED FOR ALL TABLES ASSOCIATED WITH THIS PROBLEM RECORD
|
|
//BECAUSE....WELL...IT'S JUST EASIER THAT WAY
|
|
|
|
//SHOULDN'T EACH TABLE JUST SET THE INDEXED WHILE SAVING INSTEAD OF
|
|
//DOING IT SEPARATELY HERE????????
|
|
/* TODO
|
|
if(*bModified)
|
|
{
|
|
|
|
//PROBLEMS table
|
|
q.Format("UPDATE probs SET probs.indexed = False "
|
|
"WHERE (((probs.id)=%s));",m_strProblemID);
|
|
rs->Ex(q);
|
|
//added 06062001 to get rid of "another user changed this record" error
|
|
//rs->Close();
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 2\r\n"
|
|
"*****************************\r\n\r\n");
|
|
|
|
//SUBREPAIRS
|
|
q.Format("UPDATE subrepair INNER JOIN probs ON subrepair.link = probs.id SET subrepair.indexed = False "
|
|
"WHERE (((probs.id)=%s));",m_strProblemID);
|
|
|
|
rs->Ex(q);
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 3\r\n"
|
|
"*****************************\r\n\r\n");
|
|
//added 06062001 to get rid of "another user changed this record" error
|
|
//rs->Close();
|
|
|
|
//LABOUR
|
|
q.Format("UPDATE probs INNER JOIN labor ON probs.id = labor.link SET labor.indexed = False "
|
|
"WHERE (((probs.id)=%s));",m_strProblemID);
|
|
rs->Ex(q);
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 4\r\n"
|
|
"*****************************\r\n\r\n");
|
|
rs->Close();
|
|
|
|
}
|
|
*/
|
|
|
|
//WOLabour dialog user prefs
|
|
//dont save if 4th character in string
|
|
//is = to zero.
|
|
|
|
m_pTabLabour->m_rcLabour.WriteProfile(&profile);
|
|
|
|
if(profile.Mid(3,1)!='0')
|
|
{
|
|
q.Format("UPDATE users SET users.wotablaborprofile = \"%s\" "
|
|
"WHERE (((users.id)=%u));",profile,m_pApp->m_lusrID);
|
|
rs->Ex(q);
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() 5\r\n"
|
|
"*****************************\r\n\r\n");
|
|
//added 06062001 to get rid of "another user changed this record" error
|
|
//rs->Close();
|
|
}
|
|
//=====================================================================
|
|
|
|
CDialog::OnOK();
|
|
TRACE("\r\n\r\n*****************************\r\n"
|
|
"CWODlg::OnBtndone() BOTTOM\r\n"
|
|
"*****************************\r\n\r\n");
|
|
}
|
|
|
|
|
|
void CWODlg::OnBtncancel()
|
|
{
|
|
|
|
|
|
CDialog::OnCancel();
|
|
}
|
|
|
|
void CWODlg::OnOK()
|
|
{
|
|
|
|
}
|
|
|
|
void CWODlg::Security()
|
|
{
|
|
//m_bReadOnly=false;
|
|
int x=m_pApp->Allowed(RWORKORDER,true);
|
|
if(x==0)//no access allowed
|
|
{
|
|
m_pApp->SecurityWarning();
|
|
CDialog::OnCancel();
|
|
}
|
|
|
|
}
|