// SrchView.cpp : implementation file // #include "stdafx.h" #include "sp.h" #include "SrchView.h" #include "WOHeaderDlg.h" #include "SimpleWODlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSrchView dialog CSrchView::CSrchView(CWnd* pParent /*=NULL*/) : CDialog(CSrchView::IDD, pParent) { //{{AFX_DATA_INIT(CSrchView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_pApp = (CSpApp*)AfxGetApp(); rsPrint=m_pApp->rsPool->GetRSPrint("CSrchView RSPRINT"); } CSrchView::~CSrchView() { m_pApp->rsPool->ReleaseRS(&rsPrint->m_nID); } void CSrchView::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSrchView) DDX_Control(pDX, IDC_RED, m_red); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSrchView, CDialog) //{{AFX_MSG_MAP(CSrchView) ON_BN_CLICKED(IDC_BTNDONE, OnBtndone) ON_BN_CLICKED(IDC_BTNCOPY, OnBtncopy) ON_BN_CLICKED(IDC_BTNEDIT, OnBtnedit) ON_BN_CLICKED(IDC_BTNCOPYALL, OnBtncopyall) ON_BN_CLICKED(IDC_BTNPRINT, OnBtnprint) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSrchView message handlers BOOL CSrchView::OnInitDialog() { CDialog::OnInitDialog(); ShowWindow(SW_MAXIMIZE); m_red.SetWindowText(*m_pstrText); m_pstrText->MakeLower();//for ease of highlighting HiLite(); m_red.SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } //highlight the search words void CSrchView::HiLite() { //FLAG HEADINGS: //lowercase because matching to passed string //which was converted to lowercase for ease of //searching FlagWord("workorder:",false,true,false); FlagWord("invoice#:",false,true,false); FlagWord("client reference#:",false,true,false); FlagWord("client contact:",false,true,false); FlagWord("our reference#:",false,true,false); FlagWord("client:",false,true,false); FlagWord("tech:",false,true,false); FlagWord("problem:",false,true,false); FlagWord("service details:",false,true,false); for(int x=0;xGetAt(m_pslHiWords->FindIndex(x)),true,true,true); } } void CSrchView::OnBtndone() { CDialog::OnOK(); } void CSrchView::FlagWord(CString strWord, bool bUnderline, bool bBold,bool bColour) { CHARFORMAT cf; strWord.TrimLeft(" "); strWord.TrimRight(" "); strWord.Remove('*'); strWord.Remove('%'); int n = m_pstrText->Find(strWord,0); while (n != -1) { m_red.SetSel((long)n, (long)(n+strWord.GetLength())); cf.dwMask = CFM_COLOR | CFM_BOLD | CFM_UNDERLINE; if(bColour) cf.crTextColor=RGB(255,0,0); else cf.crTextColor=RGB(0,0,0); if(bBold) cf.dwEffects = CFE_BOLD; if(bUnderline) cf.dwEffects = cf.dwEffects | CFE_UNDERLINE; m_red.SetSelectionCharFormat(cf); n = m_pstrText->Find(strWord,n+1); } m_red.SetSel(0,0); } void CSrchView::OnBtncopy() { long start,end; m_red.GetSel(start,end); if(end==0)//nothing selected { //select all m_red.SetSel(0,-1); } m_red.Copy(); } void CSrchView::OnBtnedit() { if(m_bQuickWO) { CSimpleWODlg qwo; qwo.SetWorkorderID(&m_strWOID); qwo.DoModal(); } else { CWOHeaderDlg wo; wo.SetWorkorderID(m_strWOID); wo.DoModal(); } } void CSrchView::OnBtncopyall() { //select all m_red.SetSel(0,-1); m_red.Copy(); } void CSrchView::OnBtnprint() { CString q; CString strData; m_red.GetWindowText(strData); strData.Replace("\"","''"); //set the report text to the memo field in the user record //this is a workaround to ensure that reports see this as a memo field q.Format("UPDATE users SET users.rpttext1 = \"%s\" WHERE (((users.id)=%u));",strData,m_pApp->m_lusrID); rsPrint->Ex(q); //fetch the record q.Format("SELECT users.rpttext1 AS srchresults, \"%s\" AS srchuser FROM users " "WHERE (((users.id)= %u));", m_pApp->m_strCurrentUserName, m_pApp->m_lusrID); rsPrint->Query(q); if(!rsPrint->IsEmpty()) { m_pApp->PrintCMReportRDC("Search results",rsPrint->RecordSetPointer()); #ifdef _DEBUG m_pApp->CreateTTX("srch.ttx",rsPrint->RecordSetPointer()); #endif } else AfxMessageBox("There is no data to print"); }