// WOTABLabour.cpp : implementation file // #include "stdafx.h" #include "sp.h" #include "WOTABLabour.h" #include "WoTabLabourEntryDlg.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 #include ///////////////////////////////////////////////////////////////////////////// // CWOTABLabour dialog CWOTABLabour::CWOTABLabour(CWnd* pParent /*=NULL*/) : CDialog(CWOTABLabour::IDD, pParent) { //{{AFX_DATA_INIT(CWOTABLabour) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_pApp= (CSpApp*)AfxGetApp(); /* rs = new GZRset("Error: WOTABLabour - RS"); rs->SetConnect(m_pApp->strConnectString); */ //Initialize recordset pointer rs=m_pApp->rsPool->GetRS("CWOTABLabour"); m_bIsItemsInList=false; //used to indicate a modified workorder bModified=false; } CWOTABLabour::~CWOTABLabour() { //10/03/00 (ack!) //12/07/00 (double ack!) m_pApp->rsPool->ReleaseRS(&rs->m_nID); } void CWOTABLabour::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWOTABLabour) DDX_Control(pDX, IDC_BTNDELETE, m_btnDelete); DDX_Control(pDX, IDC_BTNADD, m_btnAdd); DDX_Control(pDX, IDC_CKDetails, m_ckShowDetails); DDX_Control(pDX, IDC_RPTLABOUR, m_rcLabour); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWOTABLabour, CDialog) //{{AFX_MSG_MAP(CWOTABLabour) ON_BN_CLICKED(IDC_BTNADD, OnBtnadd) ON_WM_CLOSE() ON_BN_CLICKED(IDC_CKDetails, OnCKDetails) ON_BN_CLICKED(IDC_BTNDELETE, OnBtndelete) ON_BN_CLICKED(IDC_BTNEDIT, OnBtnedit) ON_NOTIFY(RVN_ITEMDRAWPREVIEW, IDC_RPTLABOUR, OnRvnItemDrawPreview) ON_NOTIFY(RVN_ITEMDBCLICK, IDC_RPTLABOUR, OnRvnItemDbClick) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWOTABLabour message handlers BOOL CWOTABLabour::OnInitDialog() { CDialog::OnInitDialog(); m_ckShowDetails.SetCheck(TRUE); Security(); CString profile,q; q.Format("SELECT users.wotablaborprofile " "FROM users WHERE (((users.id)=%u));",m_pApp->m_lusrID); rs->QueryReadOnly(q); rs->FetchField("wotablaborprofile",&profile); RVCOLUMN rvc; rvc.nFormat = RVCF_TEXT; rvc.lpszText = "Tech:"; rvc.iWidth = 75; m_rcLabour.DefineColumn(0, &rvc); rvc.lpszText = "Date:"; rvc.iWidth = 75; m_rcLabour.DefineColumn(1, &rvc); rvc.lpszText = "Start:"; rvc.iWidth = 75; m_rcLabour.DefineColumn(2, &rvc); rvc.lpszText = "Stop:"; rvc.iWidth = 75; m_rcLabour.DefineColumn(3, &rvc); rvc.lpszText = "Hours:"; rvc.iWidth = 75; m_rcLabour.DefineColumn(4, &rvc); rvc.lpszText = "Rate:"; rvc.iWidth = 175; m_rcLabour.DefineColumn(5, &rvc); //HIDDEN ID COLUMN rvc.nFormat = RVCF_TEXT | RVCF_EX_FIXEDWIDTH; rvc.lpszText = "ID"; rvc.iWidth = 0; m_rcLabour.DefineColumn(6, &rvc); //setup according to users preferences if(!profile.IsEmpty()) m_rcLabour.GetProfile(&profile); else { //not needed when setting by pref //but if there are no preferences then you would need it m_rcLabour.ActivateColumn(0, 0); m_rcLabour.ActivateColumn(1, 1); m_rcLabour.ActivateColumn(2, 2); m_rcLabour.ActivateColumn(3, 3); m_rcLabour.ActivateColumn(4, 4); m_rcLabour.ActivateColumn(5, 5); m_rcLabour.ActivateColumn(6, 6); } m_rcLabour.InsertColor(0, 0x00C0D8C0); m_rcLabour.InsertColor(1, 0x00D0C0C0); m_rcLabour.InsertColor(2, 0x00804000); m_rcLabour.ModifyStyle(0, RVS_SINGLESELECT); //m_rcLabour.ModifyStyle(0, RVS_SHOWCOLORALTERNATE); //turn off the grids m_rcLabour.ModifyStyle(RVS_SHOWVGRID, 0); m_rcLabour.ModifyStyle(RVS_SHOWHGRID, 0); FillList(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } //*********************************************** void CWOTABLabour::OnBtnadd() { CWoTabLabourEntryDlg d; CString LabourID; LabourID="0";//represent add mode! d.SetUp(m_pstrClientID,m_pstrProblemID,&LabourID,&bModified); d.DoModal(); bModified=true; FillList(); } //************************************************ void CWOTABLabour::OnClose() { CDialog::OnClose(); } //FIll the labour items list void CWOTABLabour::FillList() { CString q,details,date,start,stop,hours,tech,rate,index; COleDateTime dtstart,dtstop; float fHours; long lData; int x=0; float lines=0; bool bShow=(m_ckShowDetails.GetCheck() ? true:false); q.Format("SELECT labor.start, labor.stop, [last] & \", \" & " "[first] AS techname, labor.hours, rates.name, labor.details, labor.id " "FROM (labor LEFT JOIN users ON labor.tech = users.id) LEFT JOIN " "rates ON labor.rate = rates.id WHERE (((labor.link)=%s)) ORDER BY labor.start DESC;",*m_pstrProblemID); rs->QueryReadOnly(q); m_bIsItemsInList=false; //9.21.00 next two lines moved up above //if(rs->isemp....) statement to ensure that //if a single item was deleted the list would empty. lsNotes.RemoveAll(); m_rcLabour.DeleteAllItems(); if(rs->IsEmpty()) return; //used by wo dialog to determine //if view of labour list should be saved or not //if no items and it is saved causes gpf on //next entry if there are items m_bIsItemsInList=true; do { rs->FetchField("techname",&tech); rs->FetchField("details",&details); rs->FetchField("name",&rate); rs->FetchField("start",&dtstart); start=dtstart.Format(VAR_TIMEVALUEONLY); rs->FetchField("stop",&dtstop); stop=dtstop.Format(VAR_TIMEVALUEONLY); date=dtstart.Format(VAR_DATEVALUEONLY); rs->FetchField("hours",&fHours); //01/31/2003 localization fix for floats //convert float to localized string hours=FtoA(fHours);/* _variant_t vItem(fHours); vItem.ChangeType(VT_BSTR,NULL); hours=vItem.bstrVal;*/ //hours.Format("%g",fHours); rs->FetchField("id",&lData); index.Format("%u",lData); details.Replace('\r',' '); details.Remove('\n'); lines=(float)details.GetLength(); if(lines!=0) { if(lines > 150) lines=(lines/150)+1;//+1 because anything over needs a whole line even if it's just a bit else lines=1; } if(x==0) lsNotes.AddHead(details); else lsNotes.AddTail(details); //Set the look of the row and insert it //TECH RVITEM rvi; rvi.iItem = x; rvi.iSubItem = 0; rvi.nMask = RVIM_PREVIEW|RVIM_TEXT|RVIM_LPARAM; if(bShow) rvi.nPreview = 17*(UINT)lines;//hmmm? else rvi.nPreview = 0; rvi.lParam = x; rvi.lpszText = tech.GetBuffer(tech.GetLength()); m_rcLabour.InsertItem(&rvi); //DATE rvi.iSubItem = 1; rvi.nMask = RVIM_TEXT; rvi.lpszText = date.GetBuffer(date.GetLength()); m_rcLabour.SetItem(&rvi); //START rvi.iSubItem = 2; rvi.nMask = RVIM_TEXT; rvi.lpszText = start.GetBuffer(start.GetLength()); m_rcLabour.SetItem(&rvi); //STOP rvi.iSubItem = 3; rvi.nMask = RVIM_TEXT; rvi.lpszText = stop.GetBuffer(stop.GetLength()); m_rcLabour.SetItem(&rvi); //HOURS rvi.iSubItem = 4; rvi.nMask = RVIM_TEXT; rvi.lpszText = hours.GetBuffer(hours.GetLength()); m_rcLabour.SetItem(&rvi); //RATE rvi.iSubItem = 5; rvi.nMask = RVIM_TEXT; rvi.lpszText = rate.GetBuffer(rate.GetLength()); m_rcLabour.SetItem(&rvi); //ID rvi.iSubItem = 6; rvi.nMask = RVIM_TEXT; rvi.lpszText = index.GetBuffer(index.GetLength()); m_rcLabour.SetItem(&rvi); x++; }while(rs->MoveForward()); } void CWOTABLabour::OnRvnItemDrawPreview(NMHDR* pNMHDR, LRESULT* pResult) { CString strText; LPNMRVDRAWPREVIEW lpnmrvdp = (LPNMRVDRAWPREVIEW)pNMHDR; strText=lsNotes.GetAt(lsNotes.FindIndex(lpnmrvdp->iItem)); CReportCtrl& rc = m_rcLabour; 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 CWOTABLabour::OnRvnItemDbClick(NMHDR* pNMHDR, LRESULT* pResult) { OnBtnedit(); return; *pResult = FALSE; } void CWOTABLabour::OnCKDetails() { FillList(); } void CWOTABLabour::OnBtndelete() { int x; CString q,LabourID; x=m_rcLabour.GetFirstSelectedItem(); if(x<0) return;//no selection if(AfxMessageBox("Delete the highlighted labor item? Are you sure?",MB_YESNO)==IDNO) return; LabourID=m_rcLabour.GetItemText(x,6); q.Format("DELETE labor.*, labor.id FROM labor WHERE (((labor.id)=%s));",LabourID); rs->Ex(q); FillList(); bModified=true; } void CWOTABLabour::OnBtnedit() { CWoTabLabourEntryDlg d; CString LabourID; int x; x=m_rcLabour.GetFirstSelectedItem(); if(x<0) return;//no selection LabourID=m_rcLabour.GetItemText(x,6); d.SetUp(m_pstrClientID, m_pstrProblemID,&LabourID,&bModified); d.DoModal(); //AfxMessageBox("this is a delay"); FillList(); } void CWOTABLabour::Security() { int x=m_pApp->Allowed(RWORKORDER,false); if(x==0)//no access allowed { m_pApp->SecurityWarning(); CDialog::OnCancel(); } if(x==2)//read only { m_btnAdd.ShowWindow(FALSE); m_btnDelete.ShowWindow(FALSE); } } void CWOTABLabour::OnOK() { //enter key hack }