Files

2217 lines
53 KiB
C++

// STAT.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "STAT.h"
#include "ContactsViewDlg.h"
#include "PerfTimer.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>
/////////////////////////////////////////////////////////////////////////////
// STAT
IMPLEMENT_DYNCREATE(STAT, CFormView)
STAT::STAT()
: CFormView(STAT::IDD)
, m_bFreshStatsAwait(false)
, m_strStats(_T(""))
{
//{{AFX_DATA_INIT(STAT)
//}}AFX_DATA_INIT
m_pApp = (CSpApp*)AfxGetApp();
//Initialize recordset pointer
rs=m_pApp->rsPool->GetRS("STAT RS");
cbrs=m_pApp->rsPool->GetRS("STAT CBRS");
brs=m_pApp->rsPool->GetRS("STAT brs");
rsPrint=m_pApp->rsPool->GetRSPrint("STAT RSPRINT");
m_bShowDescription=true;
m_nFldCount=0;
m_strSelectedView="0";
dv.sqlcriteria="WHERE (((wo.closed)>Date()-45));";
FirstRun=true;//indicates first time filling the view
m_pApp->m_bRefreshStatScreen=true;//refresh stat screen on activate
m_nCX=0;
}
STAT::~STAT()
{
DeActivate();
//AfxMessageBox("STAT::~STAT()");
}
void STAT::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(STAT)
DDX_Control(pDX, IDC_BTNCLIENTNOTES, m_btnClientNotes);
DDX_Control(pDX, IDC_BTNREFRESH, m_btnRefresh);
DDX_Control(pDX, IDC_BTNNEWWO, m_btnNewSTWO);
DDX_Control(pDX, IDC_BTNNEWQWO, m_btnNewQWO);
DDX_Control(pDX, IDC_BTNEDITWONUM, m_btnEditWO);
DDX_Control(pDX, IDC_BTNPRINT, m_btnPrint);
DDX_Control(pDX, IDC_lblContactInfo, m_lblContactInfo);
DDX_Control(pDX, IDC_EDWONUM, m_edWONumber);
DDX_Control(pDX, IDC_CBVIEWS, m_cbViews);
DDX_Control(pDX, IDC_LBLCHOOSEFIELDS, m_lblChooseDisplayFields);
DDX_Control(pDX, IDC_LBLSAVEVIEW, m_lblSaveView);
DDX_Control(pDX, IDC_LBLDELETEVIEW, m_lblDeleteView);
DDX_Control(pDX, IDC_RPTDISPATCH, m_rc);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(STAT, CFormView)
//{{AFX_MSG_MAP(STAT)
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
ON_BN_CLICKED(IDC_LBLSAVEVIEW, OnLblsaveview)
ON_BN_CLICKED(IDC_LBLDELETEVIEW, OnLbldeleteview)
ON_BN_CLICKED(IDC_LBLCHOOSEFIELDS, OnLblchoosefields)
ON_CBN_CLOSEUP(IDC_CBVIEWS, OnCloseupCbviews)
ON_BN_CLICKED(IDC_BTNNEWWO, OnBtnnewwo)
ON_BN_CLICKED(IDC_BTNNEWQWO, OnBtnnewqwo)
ON_BN_CLICKED(IDC_BTNPRINT, OnBtnprint)
ON_BN_CLICKED(IDC_BTNEDITWONUM, OnBtneditwonum)
ON_BN_CLICKED(IDC_BTNREFRESH, OnBtnrefresh)
ON_BN_CLICKED(IDC_BTNCLIENTNOTES, OnBtnclientnotes)
ON_WM_SIZE()
ON_NOTIFY(RVN_ITEMDRAWPREVIEW, IDC_RPTDISPATCH, OnRvnItemDrawPreview)
ON_NOTIFY(RVN_ITEMDBCLICK, IDC_RPTDISPATCH, OnRvnItemDbClick)
ON_NOTIFY(RVN_ITEMCLICK, IDC_RPTDISPATCH, OnRvnItemClick)
ON_NOTIFY(RVN_COLUMNCLICK, IDC_RPTDISPATCH, OnColumnClick)
//}}AFX_MSG_MAP
ON_WM_MOUSEMOVE()
ON_WM_HELPINFO()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// STAT diagnostics
#ifdef _DEBUG
void STAT::AssertValid() const
{
CFormView::AssertValid();
}
void STAT::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// STAT message handlers
void STAT::OnInitialUpdate()
{
CString q;
CFormView::OnInitialUpdate();
//ShowWindow(FALSE);
#ifdef _WTF_
AfxMessageBox("STAT::OnInitialUpdate\r\nTOP. CALLING ALLOWED");
#endif
//no sense doing this if it's not going to be
//accessed
if(m_pApp->Allowed(RSTAT,false)==0) return;
//TEST DEC 5th changed to not refresh above
#ifdef _WTF_
AfxMessageBox("STAT::OnInitialUpdate\r\n1");
#endif
CWaitCursor wait;
//Set the initial sort order for the columns
for(int xx=0;xx<STATCOLUMNCOUNT;xx++)
bColumnSortAsc[xx]=FALSE;
//get users last saved view
q.Format("SELECT users.statview FROM users "
"WHERE (((users.id)=%u));",m_pApp->m_lusrID);
rs->QueryReadOnly(q);
rs->FetchField("statview",&m_strSelectedView);
if(m_strSelectedView.IsEmpty())
{
//some users have deleted the default view
//so make sure it can't be deleted
m_strSelectedView="1";
}
FillViewList();
//"Hyperlink-o-size" labels
m_lblDeleteView.SetTextColor(RGB(0,0,255));
m_lblDeleteView.SetFontUnderline(TRUE);
m_lblDeleteView.SetLink(TRUE);
m_lblDeleteView.SetLinkCursor(m_pApp->hcHand);
m_lblDeleteView.SetLinkURL("");
m_lblSaveView.SetTextColor(RGB(0,0,255));
m_lblSaveView.SetFontUnderline(TRUE);
m_lblSaveView.SetLink(TRUE);
m_lblSaveView.SetLinkCursor(m_pApp->hcHand);
m_lblSaveView.SetLinkURL("");
m_lblChooseDisplayFields.SetTextColor(RGB(0,0,255));
m_lblChooseDisplayFields.SetFontUnderline(TRUE);
m_lblChooseDisplayFields.SetLink(TRUE);
m_lblChooseDisplayFields.SetLinkCursor(m_pApp->hcHand);
m_lblChooseDisplayFields.SetLinkURL("");
//m_lblContactInfo.SetFontSize(6);
// m_lblContactInfo.SetBkColor(RGB(255,255,255));
//m_lblContactInfo.SetFontBold(TRUE);
m_ilReport.Create(IDB_REPORT, 16, 1, RGB(255,0,255));
m_rc.SetImageList(&m_ilReport);
int y=0;
RVCOLUMN rvc;
rvc.iWidth = 120;
rvc.nFormat = RVCF_TEXT|RVCF_LEFT;
rvc.lpszText = "Client";
m_rc.DefineColumn(y, &rvc);
rvc.nFormat = RVCF_TEXT|RVCF_CENTER;//center the dates
rvc.lpszText = "SchedDate";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "SchedEndDate";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "SchedTech";
m_rc.DefineColumn(++y, &rvc);
rvc.nFormat = RVCF_TEXT|RVCF_LEFT;
rvc.lpszText = "EntryDate";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "LastActivity";
m_rc.DefineColumn(++y, &rvc);
//Checkmark
rvc.nFormat = RVCF_TEXT|RVCF_SUBITEM_IMAGE|RVCF_CENTER;
//rvc.iImage = 2;
rvc.lpszText = "Onsite";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Closed";
m_rc.DefineColumn(++y, &rvc);
rvc.nFormat = RVCF_TEXT|RVCF_LEFT;
rvc.lpszText = "ClosedDate";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Postal";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "City";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "WO#";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Zone";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Invoice";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Date";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Status";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "OurRef#";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "ClientRef#";
m_rc.DefineColumn(++y, &rvc);
//Last modified 07/30/2001 - added category/type column
//COLUMNMOD
rvc.lpszText = "Category";
m_rc.DefineColumn(++y, &rvc);
rvc.lpszText = "Project";
m_rc.DefineColumn(++y, &rvc);
//ADD NEW COLUMNS JUST BEFORE HERE IN FUTURE
++y;
m_nFldCount=y;
//did we forget to increment the column count
//defined in the header?
ASSERT(!(m_nFldCount>STATCOLUMNCOUNT));
//DisplayColumns();
//FillView();
/*//removed this code as causing an error when default
//view was deleted
cbrs->Query("SELECT statusviews.id FROM statusviews WHERE (((statusviews.default)=True));");
long lData;
cbrs->FetchField("id",&lData);
m_strSelectedView.Format("%u",lData);
*/
OnCloseupCbviews();
//ShowWindow(TRUE);
//ShowWindow(SW_MAXIMIZE);
FirstRun=false;
//unlock the recordsets
DeActivate();
}
void STAT::OnBtndone()
{
//CDialog::OnOK();
}
//*********************************************
void STAT::FillView()
{
#ifdef _DEBUG
// CPerfTimer pTimer;
// pTimer.Start(TRUE);
#endif
//Added Oct 4th 2002
if(m_pApp->m_bDefShowHGridOnMainScreen)
m_rc.ModifyStyle(0,RVS_SHOWHGRID);
else
m_rc.ModifyStyle(RVS_SHOWHGRID,0);
if(!m_pApp->m_bRefreshStatScreen)
return;
m_pApp->m_bRefreshStatScreen=false;
//Added Oct 5th 2002.
//gets stats if enabled so they can be displayed at top when
//a wo is not selected in the list
GetStats();
//Show stats now so that display is never empty at the top
//safe to do so because the list is just about to be
//refreshed anyway so there is no way a user will have
//a selection from the workorder list at this point (or at least in a few
//milliseconds anyway)
m_bFreshStatsAwait=false;
m_lblContactInfo.SetWindowText(m_strStats);
CString q,qbrs,strData,str,parameters,strBriefs,strWONotes;
long lData,lWOID,T1,T2,T3,T4;/* Added t1 to t4 Oct 10 2002 to more properly format schedtech display*/
COleDateTime dtData,dtClosed,dtScheduled,dtEntry;
bool bData,bHasText,bQuick,bIsScheduled;
bool bAbort=false,bPrompt=true;//abort fetch, prompt if > 250 records
int nContinuePromptChoice;
int x=0;
int y=0;
int probnum,lines;
int x2=0;
CWaitCursor cWait;
//"PARAMETERS" -way to complex to pass parameters, so
//putting them in the datastream instead.
if(dv.preview)
parameters="True AS zShowNotes, ";
else
parameters="False AS zShowNotes, ";
str.Format("\"%s\" AS zCurrentUser, ",m_pApp->m_strCurrentUserName);
parameters = parameters + str;
//TODO: only shows main tech, should it be modified to show all techs?
//Last modified 07/30/2001 - added category/type column
//COLUMNMOD
/*
q.Format("SELECT %s IIf([wo].[anytime]=True,[wo].[created],[wo].[starttime]) AS cdate, wo.notes AS wonotes, wo.invoice, "
"IIf(IsNull([company]),[clients]![last] & \", \" & [clients]![first],[company]) AS clientcompany, "
"wo.anytime, wo.starttime, wo.stoptime, users.initials, wo.created, wo.modified, "
"wo.onsite, wo.closed, wo.prob_found, wo.prob_reported, wo.action_taken, clients.postal, "
"clients.city, zones.name AS zonename, wo.quick, wo.id, wo.ourref, wo.clientrefnum, probstat.notes AS wostatus, wotypes.category, projects.name AS projname "
"FROM (((((wo LEFT JOIN users ON wo.assigntech = users.id) LEFT JOIN clients ON "
"wo.client = clients.id) LEFT JOIN zones ON clients.czone = zones.id) LEFT JOIN "
"projects ON wo.project = projects.id)LEFT JOIN probstat ON wo.status = probstat.id) LEFT JOIN wotypes ON wo.type = wotypes.id %s %s;",parameters, dv.sqlcriteria, dv.sqlorderby);
*/
q.Format("SELECT %s "
"IIf([wo].[anytime]=True,[wo].[created],[wo].[starttime]) AS cdate, wo.notes AS wonotes, "
"wo.invoice, clients.company AS clientcompany, wo.anytime, wo.starttime, wo.stoptime, users.initials, "
"users_1.initials AS INIT2, users_2.initials AS INIT3, users_3.initials AS INIT4, wo.created, wo.modified, wo.onsite, "
"wo.assigntech AS T1, wo.assigntech2 AS T2, wo.assigntech3 AS T3, wo.assigntech4 AS T4, "
"wo.closed, wo.prob_found, wo.prob_reported, wo.action_taken, clients.postal, clients.city, "
"zones.name AS zonename, wo.quick, wo.id, wo.ourref, wo.clientrefnum, probstat.notes AS wostatus, "
"wotypes.category, projects.name AS projname "
"FROM ((((((((wo LEFT JOIN users ON wo.assigntech = users.id) LEFT JOIN clients ON wo.client = "
"clients.id) LEFT JOIN zones ON clients.czone = zones.id) LEFT JOIN projects ON wo.project = projects.id) "
"LEFT JOIN probstat ON wo.status = probstat.id) LEFT JOIN wotypes ON wo.type = wotypes.id) "
"LEFT JOIN users AS users_1 ON wo.assigntech2 = users_1.id) LEFT JOIN users AS users_2 ON wo.assigntech3 = users_2.id) "
"LEFT JOIN users AS users_3 ON wo.assigntech4 = users_3.id "
"%s %s;",parameters, dv.sqlcriteria, dv.sqlorderby);
#ifdef _DEBUG
//m_pApp->ShowStuff(q);
#endif
ASSERT(rs!=NULL);
rs->QueryReadOnly(q);
lsNotes.RemoveAll();
m_rc.DeleteAllItems();
if(rs->IsEmpty())
{
DeActivate();
return;
}
do{
bHasText=false;
y=0;
RVITEM rvi;
//WORKORDER BRIEF DESCRIPTIONS LOOP HERE
//If not quick workorder: Loop through all prob records for current workorder
//gather up all briefs and insert into strData for processing as normal
rs->FetchField("quick",&bQuick);
rs->FetchField("id",&lData);
strData.Format("%u",lData);
strBriefs.Empty();
if(!bQuick)//not quick wo
{
if(!m_pApp->m_bShowProblemActionFields)
{
probnum=0;
rs->FetchField("wonotes",&strWONotes);
if(!strWONotes.IsEmpty())
{
//probnum=1;
//strWONotes.Replace("&","&&");
strBriefs=strWONotes+"\r\n";
//covered in case no problems
bHasText=true;
lines=17;
}
/*
qbrs.Format("SELECT probs.brief FROM probs WHERE "
"(((probs.wolink)=%s) AND ((probs.brief)<>\"<No description>\")) ORDER BY probs.id;",strData);
*/
qbrs.Format("SELECT probs.brief, probstat.notes AS STATUS "
"FROM probs LEFT JOIN probstat ON probs.status = probstat.id "
"WHERE (((probs.brief)<>\"<No description>\") AND ((probs.wolink)=%s)) "
"ORDER BY probs.id;",strData);
#ifdef _DEBUG
//m_pApp->ShowStuff(qbrs);
#endif
brs->QueryReadOnly(qbrs);
if(!brs->IsEmpty())
{
strData.Empty();
do
{
probnum++;
strData.Format(" %i)",probnum);
if(probnum>1)
strBriefs+="\r\n";
strBriefs+=strData;
brs->FetchField("STATUS",&strData);
if(!strData.IsEmpty())
{
strData=" <" + strData + "> ";
}
strBriefs=strBriefs+strData;//+ "\r\n";
brs->FetchField("brief",&strData);
//strData.Replace("&","&&");
strBriefs=strBriefs+strData;//+ "\r\n";
}while(brs->MoveForward());
if(!strBriefs.IsEmpty())
{
bHasText=true;
if(!strWONotes.IsEmpty()) probnum++;
lines=probnum*17;
//lines=(strBriefs.GetLength()/64)*20;
//if(lines<17) lines=17;
}
}
}//alternate view
else//it's a securenet view
{
bHasText=true;
//problem reported
rs->FetchField("prob_reported",&strData);
strData.Replace("&","&&");
strBriefs="Problem reported: " + strData +"\r\n";
//problem found
rs->FetchField("prob_found",&strData);
strData.Replace("&","&&");
strBriefs+="\r\nProblem found: " + strData +"\r\n";
//Action Taken
rs->FetchField("action_taken",&strData);
strData.Replace("&","&&");
strBriefs+="\r\nAction taken: " + strData;
strBriefs.TrimRight('\r');
strBriefs.TrimRight('\n');
x2=0;
lines=0;
while (x2!=-1)
{
x2=strBriefs.Find('\r',x2);
if(x2!=-1)
x2++;
lines+=15;
}
lines = m_rc.PreviewHeight(m_rc.GetFont(), strBriefs);
lines = lines<0 ? 56:lines;
lines+=10;
}//securenet view
}
if(x==0)
lsNotes.AddHead(strBriefs);
else
lsNotes.AddTail(strBriefs);
//CLIENT
if(!rs->FetchField("clientcompany",&strData))
{
DeActivate();
return;
}
strData.Replace("&","&&");
rvi.iItem = x;
rvi.iSubItem = y;
rvi.nMask = RVIM_PREVIEW|RVIM_TEXT|RVIM_LPARAM;
if(dv.preview && bHasText)
rvi.nPreview = lines;//show first line only
else
rvi.nPreview = 0;
//Original with incorrect use of GetBuffer (and missing releasebuffer)
//rvi.lpszText = strData.GetBuffer(strData.GetLength());
//m_rc.InsertItem(&rvi);
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.InsertItem(&rvi);
strData.ReleaseBuffer();
//SCHEDULE DATE AND TIME
rs->FetchField("anytime",&bData);//see if it's scheduled
bIsScheduled=!bData;//added 10/10/2002 for use by sched tech below
if(!bData || bQuick)
{
//start date
if(bQuick)//added 11/03/00
strData="";
else
{
rs->FetchField("starttime",&dtData);
strData=dtData.Format();
}
rvi.iSubItem = ++y;
rvi.lParam = x;
//Original with incorrect use of GetBuffer (and missing releasebuffer)
//rvi.lpszText = strData.GetBuffer(strData.GetLength());
//m_rc.SetItem(&rvi);
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//end date
if(bQuick)
strData="";
else
{
rs->FetchField("stoptime",&dtData);
strData=dtData.Format();
}
rvi.iSubItem = ++y;
rvi.lParam = x;
//Original with incorrect use of GetBuffer (and missing releasebuffer)
//rvi.lpszText = strData.GetBuffer(strData.GetLength());
//m_rc.SetItem(&rvi);
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
}
else
{//anytime, so indicate with a ---
strData=" --- ";
rvi.iSubItem = ++y;
m_rc.SetItem(&rvi);
rvi.iSubItem = ++y;
m_rc.SetItem(&rvi);
}
//SCHED TECH
//modified 8/23/2001 to support multi techs
strData.Empty();
if(bIsScheduled ||bQuick)
{
rs->FetchField("T1",&T1);
rs->FetchField("T2",&T2);
rs->FetchField("T3",&T3);
rs->FetchField("T4",&T4);
if(0==T1)
str="?";
else
{
rs->FetchField("initials",&str);
}
if(!str.IsEmpty())
strData=str;
if(0==T2)
str="?";
else
{
rs->FetchField("INIT2",&str);
}
if(!str.IsEmpty())
strData+=", " + str;
if(0==T3)
str="?";
else
{
rs->FetchField("INIT3",&str);
}
if(!str.IsEmpty())
strData+=", " + str;
if(0==T4)
str="?";
else
{
rs->FetchField("INIT4",&str);
}
if(!str.IsEmpty())
strData+=", " + str;
if(strData.IsEmpty())
strData="---";
if(bQuick)
strData="*"+strData;//indicating it's a quick workorder
strData.TrimLeft(',');
}//if scheduled
else
strData="---";
//rvi.iTextColor
//Original with incorrect use of GetBuffer (and missing releasebuffer)
//rvi.lpszText = strData.GetBuffer(strData.GetLength());
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
rvi.iSubItem = ++y;
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//ENTRY DATE
rs->FetchField("created",&dtData);
strData=dtData.Format();//VAR_DATEVALUEONLY);
rvi.iSubItem = ++y;
rvi.lParam = x;
//Original with incorrect use of GetBuffer (and missing releasebuffer)
//rvi.lpszText = strData.GetBuffer(strData.GetLength());
//m_rc.SetItem(&rvi);
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//Last activity DATE
rs->FetchField("modified",&dtData);
strData=dtData.Format(VAR_DATEVALUEONLY);
rvi.iSubItem = ++y;
rvi.lParam = x;
//Original with incorrect use of GetBuffer (and missing releasebuffer)
//rvi.lpszText = strData.GetBuffer(strData.GetLength());
//m_rc.SetItem(&rvi);
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//ONSITE
rs->FetchField("onsite",&bData);
rvi.nMask = RVIM_IMAGE |RVIM_CHECK;
rvi.nState = 0;//RVIS_BOLD;
rvi.iSubItem = ++y;
rvi.lParam = x;
//rvi.iImage = 2;
rvi.iCheck = bData ? TRUE : FALSE;
rvi.lpszText = "Check";
m_rc.SetItem(&rvi);
//CLOSED CHECK / CLOSED DATE
rs->FetchField("closed",&dtClosed);
if(dtClosed.GetYear()==1968)//still open
{ //isn't closed
rvi.nMask = RVIM_IMAGE |RVIM_CHECK;
rvi.nState = 0;//RVIS_BOLD;
rvi.iSubItem = ++y;
rvi.lParam = x;
//rvi.iImage = 2;
rvi.iCheck = FALSE;
rvi.lpszText = "Check";
m_rc.SetItem(&rvi);
strData="open";
}
else
{ //is closed
rvi.nMask = RVIM_IMAGE |RVIM_CHECK;
rvi.nState = 0;//RVIS_BOLD;
rvi.iSubItem = ++y;
rvi.lParam = x;
//rvi.iImage = 2;
rvi.iCheck = TRUE;
rvi.lpszText = "Check";
m_rc.SetItem(&rvi);
//v1.9.4.4 - apparently an overwhelming majority of people
//want to see the time as well as the date for closed so...
// strData=dtClosed.Format(VAR_DATEVALUEONLY);
strData=dtClosed.Format();
}
//date
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//POSTAL CODE
rs->FetchField("postal",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//CITY
rs->FetchField("city",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//WORKORDER ID
rs->FetchField("quick",&bData);
rs->FetchField("id",&lData);
lWOID=lData;//added 11/20/2002 used by DATE column quick work order query below
strData.Format("%u",lData);
if(bData)
strData=strData+"*";//language neutral depiction of quick workorder
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//CZONE
rs->FetchField("zonename",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//INVOICE
rs->FetchField("invoice",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//DATE- combined entry date for quick or non booked standard
// sched date for open standard
if(!bQuick)
rs->FetchField("cdate",&dtData);
else//added 11/03/00//changed 11/20/2002 (is supposed to be quick work order start date not closed date)
{
//strData=dtClosed.Format(VAR_DATEVALUEONLY);
qbrs.Format("SELECT labor.start FROM labor RIGHT JOIN (probs RIGHT "
"JOIN wo ON probs.wolink = wo.id) ON labor.link "
"= probs.id WHERE (((wo.id)=%u));",lWOID);
brs->QueryReadOnly(qbrs);
if(!brs->IsEmpty())
{
brs->FetchField("start",&dtData);
}
}
strData=dtData.Format(VAR_DATEVALUEONLY);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//STATUS
rs->FetchField("wostatus",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
//rvi.iTextColor
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);
*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//OURREF
rs->FetchField("ourref",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//clientREF
rs->FetchField("clientrefnum",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//Last modified 07/30/2001 - added category/type and project column
//COLUMNMOD
rs->FetchField("category",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//project name
rs->FetchField("projname",&strData);
rvi.nMask = RVIM_TEXT;
rvi.iSubItem = ++y;
rvi.lParam = x;
/*rvi.lpszText = strData.GetBuffer(strData.GetLength());
m_rc.SetItem(&rvi);*/
//02/19/2003 - GetBuffer / ReleaseBuffer change
rvi.lpszText = strData.GetBuffer(0);
m_rc.SetItem(&rvi);
strData.ReleaseBuffer();
//NEW COLUMNS BEFORE HERE
x++;
//overflow handler here
if((x % 250)==0 && bPrompt==true)
{
nContinuePromptChoice=AfxMessageBox(
"There's a lot of data here!\r\n"
"You can configure your view to display less records\r\n\r\n"
"Do you want to be prompted again after another 250 records [Yes/No] ...\r\n"
"or cancel retrieving data now? [Cancel]",MB_YESNOCANCEL);
if(nContinuePromptChoice==IDCANCEL) bAbort=true;
if(nContinuePromptChoice==IDNO) bPrompt=false;
cWait.Restore();//go back to a wait cursor
}
}while(rs->MoveForward() && !bAbort);
#ifdef _DEBUG
/*
CString strPerf;
pTimer.Stop();
strPerf.Format("Time: %.3f",pTimer.Elapsed());
AfxMessageBox(strPerf);
*/
#endif
//clear the recordsets
DeActivate();
}
//************************************************
void STAT::OnRvnItemDbClick(NMHDR* pNMHDR, LRESULT* pResult)
{
CString str;
LPNMREPORTVIEW lpnmrv = (LPNMREPORTVIEW)pNMHDR;
if(lpnmrv->iItem >=0)//-1 if clicked on invalid
{
str=m_rc.GetItemText(lpnmrv->iItem,11);
if(str.Right(1)=='*')//quick workorder
{
str.Remove('*');
CSimpleWODlg qwo;
qwo.SetWorkorderID(&str);
qwo.DoModal();
}
else
{
CWOHeaderDlg wo;
wo.SetWorkorderID(str);
wo.DoModal();
}
}
*pResult = FALSE;
FillView();
}
//************************************************
// USED TO RETRIEVE ADDRESS AND CONTACT INFO
//************************************************
void STAT::OnRvnItemClick(NMHDR* pNMHDR, LRESULT* pResult)
{
CString strWOID,q, strData, strDisplay;
LPNMREPORTVIEW lpnmrv = (LPNMREPORTVIEW)pNMHDR;
if(lpnmrv->iItem >=0)//-1 if clicked on invalid
{
strWOID=m_rc.GetItemText(lpnmrv->iItem,11);
//remove asterisk which is appended to quick workorder
//numbers
strWOID.Remove('*');
//retrieve contact info based on workorder
q.Format(
"SELECT clients.first, clients.last, clients.company, "
"clients.mailaddress, clients.streetaddress, clients.city, "
"clients.stateprov, clients.postal, clients.country, clients.bizphone, "
"clients.extension, clients.fax, clients.email "
"FROM wo LEFT JOIN clients ON wo.client = clients.id "
"WHERE (((wo.id)=%s));",strWOID);
cbrs->QueryReadOnly(q);
strDisplay="[Contact: ";
cbrs->FetchField("first",&strData);
if(!strData.IsEmpty())
strDisplay+=strData + " ";
cbrs->FetchField("last",&strData);
strDisplay+=strData+"]";
cbrs->FetchField("bizphone",&strData);
if(!strData.IsEmpty())
strDisplay+= "[Phone: " + strData;
cbrs->FetchField("extension",&strData);
if(!strData.IsEmpty())
strDisplay+=" ext:" + strData;
strDisplay+="]";
cbrs->FetchField("fax",&strData);
if(!strData.IsEmpty())
strDisplay+="[Fax: " + strData + "]";
cbrs->FetchField("email",&strData);
if(!strData.IsEmpty())
strDisplay+="[Email: " + strData + "]";
//Physical address for Lenny and the lock people
strDisplay+="[Addr: ";
cbrs->FetchField("streetaddress",&strData);
if(!strData.IsEmpty())
strDisplay+= strData + ", ";
cbrs->FetchField("city",&strData);
if(!strData.IsEmpty())
strDisplay+= strData;
strDisplay+="]";
m_lblContactInfo.SetWindowText(strDisplay);
}
//Indicate that stats are available to be displayed
//since this function just overwrote the stats display
m_bFreshStatsAwait=true;
*pResult = FALSE;
}
//********************************************
void STAT::OnRvnItemDrawPreview(NMHDR* pNMHDR, LRESULT* pResult)
{
CString strText;
LPNMRVDRAWPREVIEW lpnmrvdp = (LPNMRVDRAWPREVIEW)pNMHDR;
strText=lsNotes.GetAt(lsNotes.FindIndex(lpnmrvdp->iItem));
CReportCtrl& rc = m_rc;
CDC dc;
dc.Attach(lpnmrvdp->hDC);
if(lpnmrvdp->nState&RVIS_SELECTED)
dc.SetTextColor(::GetFocus()==rc.m_hWnd ? GetSysColor(COLOR_HIGHLIGHTTEXT):GetSysColor(COLOR_HIGHLIGHT));
else
dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHT));
lpnmrvdp->rect.left += 40;
lpnmrvdp->rect.top += 2;
lpnmrvdp->rect.bottom -= 2;
dc.DrawText(strText, &lpnmrvdp->rect, DT_LEFT|DT_END_ELLIPSIS|DT_WORDBREAK|DT_NOPREFIX|DT_EXPANDTABS);
dc.Detach();
*pResult = FALSE;
}
//**************************************
//void STAT::OnOK()
//{}
//SET ORDER BY CLAUSE DEPENDING ON CLICK HERE
void STAT::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
CWaitCursor Wait;
int x;
CString str;
CFlatHeaderCtrl* header;
header=m_rc.GetHeaderCtrl();
dv.sqlorderby.Empty();
//FIND CLICKED COLUMN
str=header->m_szHotItemText;
if(str=="Client")
{
x=0;
goto OUTTAHERE;
}
if(str=="SchedDate")
{
x=1;
goto OUTTAHERE;
}
if(str=="SchedEndDate")
{
x=2;
goto OUTTAHERE;
}
if(str=="Date") //here because it's more common
{
x=14;
goto OUTTAHERE;
}
if(str=="SchedTech")
{
x=3;
goto OUTTAHERE;
}
if(str=="EntryDate")
{
x=4;
goto OUTTAHERE;
}
if(str=="LastActivity")
{
x=5;
goto OUTTAHERE;
}
if(str=="Onsite")
{
x=6;
goto OUTTAHERE;
}
if(str=="Closed")
{
x=7;
goto OUTTAHERE;
}
if(str=="ClosedDate")
{
x=8;
goto OUTTAHERE;
}
if(str=="Postal")
{
x=9;
goto OUTTAHERE;
}
if(str=="City")
{
x=10;
goto OUTTAHERE;
}
if(str=="WO#")
{
x=11;
goto OUTTAHERE;
}
if(str=="Zone")
{
x=12;
goto OUTTAHERE;
}
if(str=="Invoice")
{
x=13;
goto OUTTAHERE;
}
if(str=="Status")
{
x=15;
goto OUTTAHERE;
}
if(str=="OurRef#")
{
x=16;
goto OUTTAHERE;
}
if(str=="OurRef#")
{
x=16;
goto OUTTAHERE;
}
if(str=="ClientRef#")
{
x=17;
goto OUTTAHERE;
}
//Last modified 07/30/2001 - added category/type column
//COLUMNMOD
if(str=="Category")
{
x=18;
goto OUTTAHERE;
}
if(str=="Project")
{
x=19;
goto OUTTAHERE;
}
OUTTAHERE:;
bColumnSortAsc[x]=!bColumnSortAsc[x];
switch(x)
{//DESC
case 0://client
dv.sqlorderby="ORDER BY IIf(IsNull([company]),[clients]![last] & \", \" & [clients]![first],[company])";
break;
case 1://scheddate
dv.sqlorderby="ORDER BY starttime";
break;
case 2://schedenddate
dv.sqlorderby="ORDER BY stoptime";
break;
case 3://schedtech
dv.sqlorderby="ORDER BY users.initials";
break;
case 4://entrydate
dv.sqlorderby="ORDER BY wo.created";
break;
case 5://lastactivity
dv.sqlorderby="ORDER BY wo.modified";
break;
case 6://onsite
dv.sqlorderby="ORDER BY onsite";
break;
case 7://closed
dv.sqlorderby="ORDER BY closed";
break;
case 8://closeddate
dv.sqlorderby="ORDER BY closed";
break;
case 9://postal
dv.sqlorderby="ORDER BY postal";
break;
case 10://city
dv.sqlorderby="ORDER BY city";
break;
case 11://wo#
dv.sqlorderby="ORDER BY wo.id";
break;
case 12://ZONE <-one of the underlying
//tenets of this universe is that the word
//ZONE must be capitalized at all times :)
dv.sqlorderby="ORDER BY zones.name";
break;
case 13://invoice
dv.sqlorderby="ORDER BY invoice";
break;
case 14://DATE Combined date
dv.sqlorderby="ORDER BY IIf([wo].[anytime]=True,[wo].[created],[wo].[starttime])";
break;
case 15://STATUS
dv.sqlorderby="ORDER BY probstat.notes";
break;
case 16://OURREF
dv.sqlorderby="ORDER BY wo.ourref";
break;
//wo.ourref, probstat.notes AS wostatus
case 17://customer REF
dv.sqlorderby="ORDER BY wo.clientrefnum";
break;
//Last modified 07/30/2001 - added category/type and project column
//COLUMNMOD
case 18://CATEGORY
dv.sqlorderby="ORDER BY wotypes.category";
break;
case 19://PROJECT
dv.sqlorderby="ORDER BY projects.name";
break;
}
if(!bColumnSortAsc[x])
dv.sqlorderby+=" DESC";
header->SetSortColumn(header->GetHotIndex(),bColumnSortAsc[x]);
*pResult = TRUE;//TRUE means we handled it here thanks anyway
OnBtnrefresh();
}
//***************************************
void STAT::DisplayColumns()
{
if(dv.client!=0)
m_rc.ActivateColumn(0, 0);
else
m_rc.DeactivateColumn(0);
if(dv.schedstart!=0)
m_rc.ActivateColumn(1, 1);
else
m_rc.DeactivateColumn(1);
if(dv.schedenddate!=0)
m_rc.ActivateColumn(2, 2);
else
m_rc.DeactivateColumn(2);
if(dv.schedtech!=-2)
m_rc.ActivateColumn(3, 3);
else
m_rc.DeactivateColumn(3);
if(dv.wocreateddate!=0)
m_rc.ActivateColumn(4, 4);
else
m_rc.DeactivateColumn(4);
if(dv.lastactivity!=0)
m_rc.ActivateColumn(5, 5);
else
m_rc.DeactivateColumn(5);
if(dv.onsite!=0)
m_rc.ActivateColumn(6, 6);
else
m_rc.DeactivateColumn(6);
if(dv.closed!=0)
m_rc.ActivateColumn(7, 7);
else
m_rc.DeactivateColumn(7);
if(dv.closeddate!=0)
m_rc.ActivateColumn(8, 8);
else
m_rc.DeactivateColumn(8);
if(dv.postal!=0)
m_rc.ActivateColumn(9, 9);
else
m_rc.DeactivateColumn(9);
if(dv.city!=0)
m_rc.ActivateColumn(10, 10);
else
m_rc.DeactivateColumn(10);
if(dv.workorder!=0)
m_rc.ActivateColumn(11, 11);
else
m_rc.DeactivateColumn(11);
if(dv.zone!=0)
m_rc.ActivateColumn(12, 12);
else
m_rc.DeactivateColumn(12);
if(dv.invoice!=0)
m_rc.ActivateColumn(13, 13);
else
m_rc.DeactivateColumn(13);
if(dv.date!=0)
m_rc.ActivateColumn(14, 14);
else
m_rc.DeactivateColumn(14);
if(dv.status!=0)
m_rc.ActivateColumn(15, 15);
else
m_rc.DeactivateColumn(15);
if(dv.ourrefnumber!=0)
m_rc.ActivateColumn(16, 16);
else
m_rc.DeactivateColumn(16);
if(dv.custrefnumber!=0)
m_rc.ActivateColumn(17, 17);
else
m_rc.DeactivateColumn(17);
//Last modified 07/30/2001 - added category/type and project column
//COLUMNMOD
if(dv.category!=0)
m_rc.ActivateColumn(18, 18);
else
m_rc.DeactivateColumn(18);
//project
if(dv.project!=0)
m_rc.ActivateColumn(19, 19);
else
m_rc.DeactivateColumn(19);
}
//************************************
void STAT::OnLblsaveview()
{
CString str,newviewname,q;
CGetStringDlg d;
bool overwrite=false;//indicates if overwriting an existing view or it/s a new view
newviewname=m_cbViews.GetCurrentRowText();
d.Setup("Enter a view name:",&newviewname);
if(d.DoModal()==IDCANCEL)
return;
if(newviewname=="< default >")
{
AfxMessageBox("You can not overwrite the default view");
return;
}
q.Format("SELECT statusviews.viewname FROM statusviews "
"WHERE (((statusviews.viewname)=\"%s\"));",newviewname);
cbrs->QueryReadOnly(q);
if(!cbrs->IsEmpty())
{
str.Format("Overwrite existing \"%s\" view with new settings?",newviewname);
if(AfxMessageBox(str,MB_YESNO)!=IDYES)
{
DeActivate();
return;
}
else
overwrite=true;
}
dv.viewname=newviewname;
//GET PROFILE
m_rc.WriteProfile(&dv.viewprofile);
if(overwrite)
{
q.Format("SELECT statusviews.* FROM statusviews "
"WHERE (((statusviews.viewname)=\"%s\"));",dv.viewname);
cbrs->Query(q);
}
else
{//add new record
q.Format("SELECT statusviews.* FROM statusviews WHERE (((statusviews.id)=0));");
cbrs->Query(q);
cbrs->AddNewRecord();
}
//UPDATE EACH FIELD
cbrs->UpdateField("viewname",&dv.viewname);
cbrs->UpdateField("viewprofile",&dv.viewprofile);
cbrs->UpdateField("client",&dv.client);
cbrs->UpdateField("zone",&dv.zone);
cbrs->UpdateField("postal",&dv.postal);
cbrs->UpdateField("city",&dv.city);
cbrs->UpdateField("workorder",&dv.workorder);
cbrs->UpdateField("invoice",&dv.invoice);
cbrs->UpdateField("closed",&dv.closed);
cbrs->UpdateField("closeddate",&dv.closeddate);
cbrs->UpdateField("date",&dv.date);
cbrs->UpdateField("ourref",&dv.ourrefnumber);
cbrs->UpdateField("status",&dv.status);
cbrs->UpdateField("onsite",&dv.onsite);
cbrs->UpdateField("schedstart",&dv.schedstart);
cbrs->UpdateField("scheddatestart",&dv.scheddatestart);
cbrs->UpdateField("scheddateend",&dv.scheddateend);
cbrs->UpdateField("schedenddate",&dv.schedenddate);
cbrs->UpdateField("schedtech",&dv.schedtech);
cbrs->UpdateField("wocreatedate",&dv.wocreateddate);
cbrs->UpdateField("woentrydate",&dv.woentrydate);
cbrs->UpdateField("woentrydatetype",&dv.woentrydatetype);
cbrs->UpdateField("lastactivity",&dv.lastactivity);
cbrs->UpdateField("sqlcriteria",&dv.sqlcriteria);
cbrs->UpdateField("sqlorderby",&dv.sqlorderby);
cbrs->UpdateField("preview",&dv.preview);
//Last modified 07/30/2001 - added category/type and project column
//COLUMNMOD
cbrs->UpdateField("category",&dv.category);
cbrs->UpdateField("project",&dv.project);
//created days
cbrs->UpdateField("createddays",&dv.lCreatedDays);
//SAVE
cbrs->SaveRecord();
//REFRESH PICK LIST
FillViewList();
if(!overwrite)
{
q.Format("SELECT statusviews.id FROM statusviews "
"WHERE (((statusviews.viewname)=\"%s\"));",dv.viewname);
cbrs->QueryReadOnly(q);
cbrs->FetchField("id",&dv.id);
//CENTRE ON NEW VIEW
m_cbViews.Select(dv.id);
}
DeActivate();
}
//******************************************
void STAT::OnLbldeleteview()
{
CString q;
q=m_cbViews.GetCurrentRowText();
if(q=="< default >")
{
AfxMessageBox("You can not delete the default view");
return;
}
q.Format("DELETE statusviews.*, statusviews.id "
"FROM statusviews "
"WHERE (((statusviews.id)=%s));",m_cbViews.GetCurrentRowID());
cbrs->Ex(q);
cbrs->Close();
///cbrs=NULL;
FillViewList();
OnCloseupCbviews();
}
//******************************************
void STAT::OnLblchoosefields()
{
CDispatchFieldsDlg d;
d.SetReturnVariable(&dv);
if(d.DoModal()==IDOK)
{
m_pApp->m_bRefreshStatScreen=true;
DisplayColumns();
FillView();
}
if(AfxMessageBox("Do you want to save changes to this view?",MB_YESNO) ==IDYES)
OnLblsaveview();
}
//================================
void STAT::FillViewList()
{
CString strData,strIndex;
long lData;
m_cbViews.Clear();
cbrs->QueryReadOnly("SELECT statusviews.* FROM statusviews ORDER BY statusviews.viewname;");
if(cbrs->IsEmpty())
{
DeActivate();
return;
}
do{
cbrs->FetchField("id",&lData);
cbrs->FetchField("viewname",&strData);
strIndex.Format("%u",lData);
m_cbViews.AddRow(strData,strIndex);
}while(cbrs->MoveForward());
//user may have deleted view one
//so select first in list instead
if(m_strSelectedView=="1")
m_cbViews.SetCurSel(0);
else
m_cbViews.Select(m_strSelectedView);
DeActivate();
}
//===============================
void STAT::OnCloseupCbviews()
{
CString str,q;
str=m_cbViews.GetCurrentRowID();
if(!FirstRun && str==m_strSelectedView)
{
return;//no change
}
//save users new view preference
m_strSelectedView=str;
q.Format("UPDATE users SET users.statview = \"%s\" "
"WHERE (((users.id)=%u));",str,m_pApp->m_lusrID);
cbrs->Ex(q);
//load settings for this view then
q.Format("SELECT statusviews.* FROM statusviews WHERE (((statusviews.id)=%s));",m_strSelectedView);
cbrs->QueryReadOnly(q);
if(cbrs->IsEmpty())
{
DeActivate();
return;
}
//UPDATE EACH FIELD
cbrs->FetchField("viewname",&dv.viewname);
cbrs->FetchField("viewprofile",&dv.viewprofile);
cbrs->FetchField("client",&dv.client);
cbrs->FetchField("zone",&dv.zone);
cbrs->FetchField("postal",&dv.postal);
cbrs->FetchField("city",&dv.city);
cbrs->FetchField("workorder",&dv.workorder);
cbrs->FetchField("invoice",&dv.invoice);
cbrs->FetchField("closed",&dv.closed);
cbrs->FetchField("closeddate",&dv.closeddate);
cbrs->FetchField("onsite",&dv.onsite);
cbrs->FetchField("schedstart",&dv.schedstart);
cbrs->FetchField("date",&dv.date);
cbrs->FetchField("ourref",&dv.ourrefnumber);
cbrs->FetchField("custref",&dv.custrefnumber);
cbrs->FetchField("status",&dv.status);
cbrs->FetchField("scheddatestart",&dv.scheddatestart);
cbrs->FetchField("scheddateend",&dv.scheddateend);
cbrs->FetchField("woentrydate",&dv.woentrydate);
cbrs->FetchField("woentrydatetype",&dv.woentrydatetype);
cbrs->FetchField("schedenddate",&dv.schedenddate);
cbrs->FetchField("schedtech",&dv.schedtech);
cbrs->FetchField("wocreatedate",&dv.wocreateddate);
cbrs->FetchField("lastactivity",&dv.lastactivity);
cbrs->FetchField("sqlcriteria",&dv.sqlcriteria);
cbrs->FetchField("sqlorderby",&dv.sqlorderby);
cbrs->FetchField("preview",&dv.preview);
cbrs->FetchField("virtualreport",&dv.virtualreport);
//Last modified 07/30/2001 - added category/type column
//COLUMNMOD
cbrs->FetchField("category",&dv.category);
cbrs->FetchField("project",&dv.project);
// created days 10/11/2002
cbrs->FetchField("createddays",&dv.lCreatedDays);
DeActivate();
//modified 07/30/2001 was set to x<17 explicitly changed to STATCOLUMNCOUNT
for(int x=0;x<STATCOLUMNCOUNT;x++)
m_rc.DeactivateColumn(x);
m_rc.GetProfile(&dv.viewprofile);
//redisplay
if(!FirstRun)
OnBtnrefresh();
//DisplayColumns();
//m_lblSaveView.ShowWindow(FALSE);
dv.IsModified=false;
}
void STAT::OnBtnnewwo()
{
int x=m_pApp->Allowed(RWORKORDER,true);
if(x!=1)//no write allowed
{
m_pApp->SecurityWarning();
return;
}
CWOHeaderDlg wo;
wo.SetWorkorderID("0");
if(wo.DoModal()==IDOK)
{
m_pApp->m_bRefreshStatScreen=true;
FillView();
}
}
void STAT::OnBtnnewqwo()
{
int x=m_pApp->Allowed(RWORKORDER,true);
if(x!=1)//no write allowed
{
m_pApp->SecurityWarning();
return;
}
CString temp="0";
//This is to work around a bug, if previous
//qwo deleted a workorder
//the next save goes gibberish for some reason?
//Recordset corruption probably, this fixes
CSimpleWODlg qwo;
qwo.SetWorkorderID(&temp);
if(qwo.DoModal()==IDOK)
{
m_pApp->m_bRefreshStatScreen=true;
FillView();
}
}
void STAT::OnBtnprint()
{
CString q,parameters,str;
if(dv.preview)
parameters="True AS zShowNotes, ";
else
parameters="False AS zShowNotes, ";
str.Format("\"%s\" AS zCurrentUser, ",m_pApp->m_strCurrentUserName);
parameters = parameters + str;
/*PRISTINE VERSION OF 1.9.3.0 query
q.Format("SELECT %s "
"IIf([wo].[anytime]=True,[wo].[created],[wo].[starttime]) AS cdate, probs.id AS PROBID, "
"probs.brief, probs.notes AS PROBDETAILS, wo.clientcontact, wo.notes AS wonotes, wo.invoice, "
"IIf(IsNull([company]),[clients]![last] & \", \" & [clients]![first],[company]) AS clientcompany, "
"wo.anytime, wo.starttime, wo.stoptime, users.initials, users_1.initials AS INIT2, "
"users_2.initials AS INIT3, users_3.initials AS INIT4, wo.created, wo.modified, wo.onsite, "
"wo.closed, wo.prob_found, wo.prob_reported, wo.action_taken, clients.postal, clients.city, "
"clients.technotes, clients.generalnotes, clients.acctnumber, zones.name AS zonename, wo.quick, "
"wo.id, wo.ourref, wo.clientrefnum, probstat.notes AS wostatus "
"FROM (((probs RIGHT JOIN (((((wo LEFT JOIN users ON wo.assigntech = users.id) LEFT JOIN "
"clients ON wo.client = clients.id) LEFT JOIN zones ON clients.czone = zones.id) LEFT JOIN "
"projects ON wo.project = projects.id) LEFT JOIN probstat ON wo.status = probstat.id) ON probs.wolink = wo.id) "
"LEFT JOIN users AS users_1 ON wo.assigntech2 = users_1.id) LEFT JOIN users AS users_2 "
"ON wo.assigntech3 = users_2.id) LEFT JOIN users AS users_3 ON wo.assigntech4 = users_3.id %s %s;",parameters, dv.sqlcriteria, dv.sqlorderby);
*/
q.Format("SELECT %s "
"IIf([wo].[anytime]=True,[wo].[created],[wo].[starttime]) AS cdate, probs.id AS PROBID, "
"probs.brief, probs.notes AS PROBDETAILS, wo.clientcontact, wo.notes AS wonotes, wo.invoice, "
"IIf(IsNull([company]),[clients]![last] & \", \" & [clients]![first],[company]) AS clientcompany, "
"wo.anytime, wo.starttime, wo.stoptime, users.initials, users_1.initials AS INIT2, "
"users_2.initials AS INIT3, users_3.initials AS INIT4, wo.created, wo.modified, wo.onsite, "
"wo.closed, wo.prob_found, wo.prob_reported, wo.action_taken, clients.postal, clients.city, "
"clients.technotes, clients.generalnotes, clients.acctnumber, zones.name AS zonename, wo.quick, "
"wo.id, wo.ourref, wo.clientrefnum, probstat.notes AS wostatus "
"FROM wotypes RIGHT JOIN ((((probs RIGHT JOIN (((((wo LEFT JOIN users ON wo.assigntech = users.id) LEFT JOIN "
"clients ON wo.client = clients.id) LEFT JOIN zones ON clients.czone = zones.id) LEFT JOIN "
"projects ON wo.project = projects.id) LEFT JOIN probstat ON wo.status = probstat.id) ON probs.wolink = wo.id) "
"LEFT JOIN users AS users_1 ON wo.assigntech2 = users_1.id) LEFT JOIN users AS users_2 "
"ON wo.assigntech3 = users_2.id) LEFT JOIN users AS users_3 ON wo.assigntech4 = users_3.id) ON wotypes.id=wo.type "
"%s %s;",parameters, dv.sqlcriteria, dv.sqlorderby);
#ifdef _DEBUG
m_pApp->ShowStuff(q);
#endif
rsPrint->Close();
rsPrint->QueryReadOnly(q);
rsPrint->QueryReadOnly(q);
m_pApp->PrintCMReportRDC(dv.virtualreport,rsPrint->RecordSetPointer());
#ifdef _DEBUG
m_pApp->CreateTTX("wostatus.ttx",rsPrint->RecordSetPointer());
#endif
//
DeActivate();
}
void STAT::Activate()
{
#ifdef _WTF_
AfxMessageBox("STAT activate");
#endif
rs=m_pApp->rsPool->GetRS("STAT RS");
cbrs=m_pApp->rsPool->GetRS("STAT CBRS");
brs=m_pApp->rsPool->GetRS("STAT brs");
rsPrint=m_pApp->rsPool->GetRSPrint("STAT RSPRINT");
//AfxMessageBox("Activate");
//ShowWindow(SW_MAXIMIZE);
//if were supposed to refresh the stat screen then..
FillView();
//Hide add wo buttons if not allowed
int x=m_pApp->Allowed(RWORKORDER,true);
if(x!=1)//no write allowed
{
m_btnNewQWO.EnableWindow(FALSE);
m_btnNewSTWO.EnableWindow(FALSE);
}
}
void STAT::DeActivate()
{
//AfxMessageBox("Deactivate");
#ifdef _WTF_
AfxMessageBox("STAT activate");
#endif
//AfxMessageBox("STAT::DeActivate()");
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
m_pApp->rsPool->ReleaseRS(&cbrs->m_nID);
m_pApp->rsPool->ReleaseRS(&brs->m_nID);
m_pApp->rsPool->ReleaseRS(&rsPrint->m_nID);
//AfxMessageBox("DONE: STAT::DeActivate()");
}
void STAT::OnBtneditwonum()
{
CString q;
CString strWO;
bool bquick;
m_edWONumber.GetWindowText(strWO);
if(strWO.IsEmpty()) return;
q.Format("SELECT wo.quick FROM wo WHERE (((wo.id)=%s));",strWO);
cbrs->QueryReadOnly(q);
if(cbrs->IsEmpty())
{
q.Format("There is no workorder %s",strWO);
AfxMessageBox(q);
DeActivate();
return;
}
cbrs->FetchField("quick",&bquick);
cbrs->Close();
if(bquick)
{
CSimpleWODlg qwo;
qwo.SetWorkorderID(&strWO);
qwo.DoModal();
}
else
{
CWOHeaderDlg wo;
wo.SetWorkorderID(strWO);
wo.DoModal();
}
FillView();
}
void STAT::OnBtnrefresh()
{
m_pApp->m_bRefreshStatScreen=true;
FillView();
}
void STAT::DoHelp()
{
//AfxGetApp()->WinHelp(IDD_STAT_FORM);
//AfxMessageBox("here's your help.");
}
void STAT::OnBtnclientnotes()
{
CString strWorkorderID,q;
int x;
long lClient;
x=m_rc.GetFirstSelectedItem();
if(x<0)
{
AfxMessageBox("No list item is selected");
return;//no selection
}
strWorkorderID=m_rc.GetItemText(x,11);
strWorkorderID.Remove('*');
q.Format("SELECT wo.client FROM wo "
"WHERE (((wo.id)=%s));",strWorkorderID);
brs->Query(q);
if(brs->IsEmpty())
{
AfxMessageBox("Can't locate a client for that workorder");
DeActivate();
return;
}
brs->FetchField("client",&lClient);
DeActivate();
q.Format("%u",lClient);
CContactsViewDlg d;
d.Setup(q);
d.DoModal();
}
void STAT::LayoutControls()
{
CRect rectCtl;
GetWindowRect(rectStat);
int nOffset=rectStat.top;
int nLastBottom,nRight,nLeft;
int nHeight,nWidth;
m_rc.GetWindowRect(rectCtl);
rectCtl.right=rectStat.right-73;
rectCtl.top-=nOffset;
rectCtl.left=13;
rectCtl.bottom=rectStat.bottom-70-nOffset;
m_rc.MoveWindow(rectCtl,TRUE);
nLastBottom=rectCtl.bottom;
nRight=rectCtl.right;
m_btnEditWO.GetWindowRect(rectCtl);
nWidth=rectCtl.Width();
rectCtl.right=nRight;
rectCtl.left=nRight-nWidth;
rectCtl.top-=nOffset;
rectCtl.bottom-=nOffset;
m_btnEditWO.MoveWindow(rectCtl,TRUE);
m_edWONumber.GetWindowRect(rectCtl);
nWidth=rectCtl.Width();
rectCtl.right=nRight;
rectCtl.left=nRight-nWidth;
rectCtl.top-=nOffset;
rectCtl.bottom-=nOffset;
m_edWONumber.MoveWindow(rectCtl,TRUE);
nLeft=rectCtl.left;
//set contact field to grow to the right
m_lblContactInfo.GetWindowRect(rectCtl);
//nWidth=rectCtl.Width();
rectCtl.right=nLeft-5;
//rectCtl.left=nRight-nWidth;
rectCtl.top-=nOffset;
rectCtl.bottom-=nOffset;
m_lblContactInfo.MoveWindow(rectCtl,TRUE);
m_btnNewQWO.GetWindowRect(rectCtl);
nHeight=rectCtl.Height();
rectCtl.bottom=nLastBottom+25;
rectCtl.top=rectCtl.bottom-nHeight;
m_btnNewQWO.MoveWindow(rectCtl,TRUE);
nLastBottom=rectCtl.bottom;
m_btnNewSTWO.GetWindowRect(rectCtl);
nHeight=rectCtl.Height();
rectCtl.bottom=nLastBottom;
rectCtl.top=rectCtl.bottom-nHeight;
m_btnNewSTWO.MoveWindow(rectCtl,TRUE);
m_btnRefresh.GetWindowRect(rectCtl);
nHeight=rectCtl.Height();
rectCtl.bottom=nLastBottom;
rectCtl.top=rectCtl.bottom-nHeight;
m_btnRefresh.MoveWindow(rectCtl,TRUE);
m_btnClientNotes.GetWindowRect(rectCtl);
nHeight=rectCtl.Height();
rectCtl.bottom=nLastBottom;
rectCtl.top=rectCtl.bottom-nHeight;
m_btnClientNotes.MoveWindow(rectCtl,TRUE);
m_btnPrint.GetWindowRect(rectCtl);
nHeight=rectCtl.Height();
rectCtl.bottom=nLastBottom;
rectCtl.top=rectCtl.bottom-nHeight;
m_btnPrint.MoveWindow(rectCtl,TRUE);
}
void STAT::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
if(cx>m_nCX)//to cut down on number of times called
{
m_nCX=cx;
if(m_btnPrint.m_hWnd)
{
LayoutControls();
}
}
}
void STAT::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_bFreshStatsAwait)
{ m_bFreshStatsAwait=false;
m_lblContactInfo.SetWindowText(m_strStats);
}
CFormView::OnMouseMove(nFlags, point);
}
// Fetches useful stats from database do display at top
//called by FillView when there is a refresh required in the view only
void STAT::GetStats(void)
{
long lWOCount=0;
long lOpenCount=0;
if(rs->QueryReadOnly("SELECT Count(wo.id) AS WOCOUNT FROM wo;"))
{
rs->FetchField("WOCOUNT",&lWOCount);
if(lWOCount<1)
{
m_strStats.Format("\t There are no work orders entered in AyaNova. Stats not available");
m_bFreshStatsAwait=true;
return;
}
if(rs->QueryReadOnly("SELECT Count(wo.id) AS OPENCOUNT FROM wo GROUP BY wo.closed HAVING (((wo.closed)=#3/12/1968#));"))
{
if(rs->IsEmpty())
lOpenCount=0;
else
rs->FetchField("OPENCOUNT", &lOpenCount);
}
}
m_strStats.Format("\t%u total workorders in AyaNova, %u are open",lWOCount,lOpenCount);
m_bFreshStatsAwait=true;
}
BOOL STAT::OnHelpInfo(HELPINFO* pHelpInfo)
{
WinHelp (0x00020000 + IDD_STAT_FORM,HELP_CONTEXT);
return TRUE;
}