// RptSetDlg.cpp : implementation file // #include "stdafx.h" #include "sp.h" #include "RptSetDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRptSetDlg dialog CRptSetDlg::CRptSetDlg(CWnd* pParent /*=NULL*/) : CDialog(CRptSetDlg::IDD, pParent) , m_strCurrentReportPath(_T("")) { //{{AFX_DATA_INIT(CRptSetDlg) //}}AFX_DATA_INIT m_pApp = (CSpApp*)AfxGetApp(); /* rs=new GZRset("Error: Report settings screen "); rs->SetConnect(m_pApp->strConnectString); */ //Initialize recordset pointer rs=m_pApp->rsPool->GetRS("CRptSetDlg"); cryp=new GZK; m_bNew=false; m_bEditing=false; //indicates run first bFirstRun=true; } CRptSetDlg::~CRptSetDlg() { m_pApp->rsPool->ReleaseRS(&rs->m_nID); delete cryp; } void CRptSetDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRptSetDlg) DDX_Control(pDX, IDC_BTNSELECTREPORT, m_btnSelectReport); DDX_Control(pDX, IDC_BTNSELECTPRINTER, m_btnSelectPrinter); DDX_Control(pDX, IDC_BTNRESET, m_btnReset); DDX_Control(pDX, IDC_BTNDEFAULTREPORT, m_btnDefaultReport); DDX_Control(pDX, IDC_BTNDEFAULTPRINTER, m_btnDefaultPrinter); DDX_Control(pDX, IDC_CKPREVIEW, m_ckPreview); DDX_Control(pDX, IDC_EDPRINTERSELECTED, m_edPrinterSelected); DDX_Control(pDX, IDC_EDCUSTOMREPORTSELECTED, m_edCustomReport); DDX_Control(pDX, IDC_EDCOPIES, m_edCopies); DDX_Control(pDX, IDC_CBREPORTS, m_cbReports); //}}AFX_DATA_MAP DDX_Control(pDX, IDC_LBL_DEFAULT_REPORT_FILE, m_lblDefaultReportFile); } BEGIN_MESSAGE_MAP(CRptSetDlg, CDialog) //{{AFX_MSG_MAP(CRptSetDlg) ON_BN_CLICKED(IDC_BTNDEFAULTPRINTER, OnBtndefaultprinter) ON_BN_CLICKED(IDC_BTNSELECTPRINTER, OnBtnselectprinter) ON_BN_CLICKED(IDC_BTNDEFAULTREPORT, OnBtndefaultreport) ON_BN_CLICKED(IDC_BTNSELECTREPORT, OnBtnselectreport) ON_BN_CLICKED(IDC_BTNDONE, OnBtndone) ON_BN_CLICKED(IDC_BTNRESET, OnBtnreset) ON_CBN_CLOSEUP(IDC_CBREPORTS, OnCloseupCbreports) //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_CKPREVIEW, OnBnClickedCkpreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRptSetDlg message handlers void CRptSetDlg::OnOK() { //enter key override hack } void CRptSetDlg::OnBtndefaultprinter() { m_edPrinterSelected.SetWindowText("< Windows default printer >"); } void CRptSetDlg::OnBtnselectprinter() { CString msg; CString strTemp; CString strPage; try { //m_strSampleReportPath=m_pApp->ReportDirectory() +"clientpb.rpt"; m_Report=m_pApp->pApplication->OpenReport(_bstr_t(m_strCurrentReportPath)); //Set to previous defaults if any m_edPrinterSelected.GetWindowText(strTemp); if(strTemp!="< Windows default printer >") { m_Report->SelectPrinter(_bstr_t(m_strDRIVER),_bstr_t(m_strDEVICE),_bstr_t(m_strPORT)); m_Report->PutPaperOrientation((CRPaperOrientation)m_lPaperOrientation); m_Report->PutPaperSize((CRPaperSize)m_lPaperSize); m_Report->PutPaperSource((CRPaperSource)m_lPaperSource); m_Report->PutPrinterDuplex((CRPrinterDuplexType)m_lDuplexType); } m_Report->PrinterSetup(0); m_strDEVICE=(LPCTSTR) m_Report->GetPrinterName(); m_strDRIVER=(LPCTSTR) m_Report->GetDriverName(); m_strPORT=(LPCTSTR) m_Report->GetPortName(); m_lPaperOrientation=m_Report->GetPaperOrientation(); m_lPaperSize=m_Report->GetPaperSize(); m_lPaperSource=m_Report->GetPaperSource(); m_lDuplexType=m_Report->GetPrinterDuplex(); strPage=FormatPaperSettingsString(); if(m_strDEVICE.IsEmpty())//default printer? strTemp="< Windows default printer >"; else strTemp.Format("%s on %s",m_strDEVICE,m_strPORT); msg.Format("%s\r\nPaper settings: %s",strTemp,strPage); m_edPrinterSelected.SetWindowText(msg); /*CRPaperOrientation crPaperOrientation=m_Report->GetPaperOrientation(); CRPaperSize crPaperSize=m_Report->GetPaperSize(); CRPaperSource crPaperSource=m_Report->GetPaperSource(); CRPrinterDuplexType crDuplexType=m_Report->GetPrinterDuplex(); long lPaperSize=(long)m_Report->GetPaperSize(); m_Report->PaperSize=(CRPaperSize)lPaperSize;*/ } catch(_com_error& e) { CString strErr; _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); strErr.Format( "Error: Crystal Reports RDC printing engine\r\n" "Full error is:\r\n\r\n" "Code = %x\r\n" "Code Meaning = %s\r\n" "Source = %s\r\n" "Description = %s\r\n\r\n" ,e.Error,e.ErrorMessage(),(LPCTSTR) bstrSource,(LPCTSTR) bstrDescription); m_pApp->ShowStuff(strErr); //HandleComError(e,strLocalError); } return; } void CRptSetDlg::OnBtndefaultreport() { m_edCustomReport.SetWindowText("< Default >"); } void CRptSetDlg::OnBtnselectreport() { static char BASED_CODE szFilter[] = "Report files (*.rpt)|*.rpt||"; CString ReportSelected; CFileDialog f(true,"rpt",NULL,OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,szFilter,NULL); //f.m_ofn.lpstrInitialDir=m_pApp->m_WasRunFrom; f.DoModal(); ReportSelected=f.GetPathName(); if(ReportSelected.GetLength()>0) m_edCustomReport.SetWindowText(ReportSelected); } void CRptSetDlg::OnBtndone() { SaveRecord(); CDialog::OnOK(); } void CRptSetDlg::OnCloseupCbreports() { CString q,strTemp; //Save the settings of the previously selected report if(!bFirstRun) SaveRecord(); //Now move on to the newly selected report m_strCurrentReport=m_cbReports.GetCurrentRowID(); q.Format("SELECT rptsmaster.filename " "FROM rptsmaster " "WHERE (((rptsmaster.virtualname)=\"%s\"));",m_strCurrentReport); if(rs->QueryReadOnly(q)) { rs->FetchField("filename",&strTemp); m_strCurrentReportPath=m_pApp->ReportDirectory()+strTemp; } q.Format("SELECT rptsusers.* FROM rptsusers " "WHERE (((rptsusers.virtualname)=\"%s\") AND ((rptsusers.user)=%u));",m_strCurrentReport,m_pApp->m_lusrID); rs->Query(q); if(rs->IsEmpty()) {//making a new record m_bNew=true; m_bEditing=false; ClearFields(); } else {//editing an existing one FillFields(); m_bEditing=true; m_bNew=false; } bFirstRun=false; strTemp.Format("Default file: %s",m_strCurrentReportPath); m_lblDefaultReportFile.SetWindowText(strTemp); } BOOL CRptSetDlg::OnInitDialog() { CDialog::OnInitDialog(); long lData; Security(); CString strData,strRecordSet,strOriginal; strData.Format("%s - Custom report settings",m_pApp->m_strCurrentUserName); SetWindowText(strData); m_cbReports.Clear(); rs->Query("SELECT rptsmaster.* FROM rptsmaster ORDER BY rptsmaster.virtualname;"); ASSERT(!rs->IsEmpty()); do{ //added check for report id 3 as this points //to a "work order list" report which doesn't really //exist any more. //Note this is lazy, properly should have removed it //from the db, but there was no other reason to update the //db for this update and it's always problematic to do so //un-necessarily. rs->FetchField("id",&lData); if(lData!=3) { rs->FetchField("virtualname",&strData); strOriginal=strData; strData.Remove('&'); rs->FetchField("recordset",&strRecordSet); if(strRecordSet=="woquick") strData="Quick WO - " + strData; if(strRecordSet=="wostandard") strData="Standard WO - " + strData; m_cbReports.AddRow(strData,strOriginal); } }while(rs->MoveForward()); m_cbReports.Select(0);//should just go to first one OnCloseupCbreports(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CRptSetDlg::FillFields() { CString str1,str2,msg,strPage,strTemp; bool bData; long lData; //PRINTER SETTINGS rs->FetchField("port",&m_strPORT); rs->FetchField("device",&m_strDEVICE); rs->FetchField("driver",&m_strDRIVER); rs->FetchField("porient",&m_lPaperOrientation); rs->FetchField("psize",&m_lPaperSize); rs->FetchField("psource",&m_lPaperSource); rs->FetchField("pduplex",&m_lDuplexType); rs->FetchField("defaultprtr",&bData); if(bData) m_edPrinterSelected.SetWindowText("< Windows default printer >"); else { strPage=FormatPaperSettingsString(); if(m_strDEVICE.IsEmpty()) strTemp="< Windows default printer >"; else strTemp.Format("%s on %s",m_strDEVICE,m_strPORT); msg.Format("%s\r\nPaper settings: %s",strTemp,strPage); m_edPrinterSelected.SetWindowText(msg); } //CUSTOM REPORT rs->FetchField("filename",&str1); if(str1=="na") m_edCustomReport.SetWindowText("< Default >"); else m_edCustomReport.SetWindowText(str1); //COPIES rs->FetchField("copies",&lData); str1.Format("%u",lData); m_edCopies.SetWindowText(str1); //PREVIEW rs->FetchField("preview",&bData); m_ckPreview.SetCheck(bData ? TRUE:FALSE); if(bData) m_edCopies.EnableWindow(FALSE); else m_edCopies.EnableWindow(TRUE); } void CRptSetDlg::ClearFields() { m_edCustomReport.SetWindowText("< Default >"); m_edPrinterSelected.SetWindowText("< Windows default printer >"); m_ckPreview.SetCheck(TRUE); m_edCopies.EnableWindow(FALSE); m_edCopies.SetWindowText("1"); } void CRptSetDlg::OnBtnreset() { ClearFields(); } void CRptSetDlg::SaveRecord() { CString strData,report,printer,q; bool bData,alldefaults,preview; alldefaults=false; long lData; m_edCopies.GetWindowText(strData); lData=atol(strData); preview=m_ckPreview.GetCheck() ? true:false; m_edCustomReport.GetWindowText(report); m_edPrinterSelected.GetWindowText(printer); //see if user has selected all default settings //in other words, these are the settings that would //be in effect if a user record was not found, //so to be efficient, we can delete if there is one // or not save if there isn't if(report=="< Default >" && printer=="< Windows default printer >" && lData==1 && preview==true) alldefaults=true; if(alldefaults) { if(m_bEditing)//delete this record { q.Format("DELETE rptsusers.*, rptsusers.virtualname, rptsusers.user " "FROM rptsusers WHERE (((rptsusers.virtualname)=\"%s\") " "AND ((rptsusers.user)=%u));",m_strCurrentReport,m_pApp->m_lusrID); rs->Ex(q); } m_bNew=false; m_bEditing=false; return;//bail, our work here is done } //THINGS TO DO WHEN YOU DONT EXIST YET..... if(m_bNew)//make new record rs->AddNewRecord(); //UPDATE each field rs->UpdateField("virtualname",&m_strCurrentReport); rs->UpdateField("user",&m_pApp->m_lusrID); m_edCustomReport.GetWindowText(strData); if(strData=="< Default >") strData="na"; rs->UpdateField("filename",&strData); m_edPrinterSelected.GetWindowText(strData); if(strData=="< Windows default printer >") { m_strDEVICE.Empty(); m_strDRIVER.Empty(); m_strPORT.Empty(); bData=true; } else bData=false; rs->UpdateField("defaultprtr",&bData); m_edCopies.GetWindowText(strData); if(strData.IsEmpty()) strData="1"; lData=atol(strData); if(lData==0) lData=1; rs->UpdateField("copies",&lData); bData=m_ckPreview.GetCheck() ? true:false; rs->UpdateField("preview",&bData); rs->UpdateField("driver",&m_strDRIVER); rs->UpdateField("device",&m_strDEVICE); rs->UpdateField("port",&m_strPORT); rs->UpdateField("porient",&m_lPaperOrientation); rs->UpdateField("psize",&m_lPaperSize); rs->UpdateField("psource",&m_lPaperSource); rs->UpdateField("pduplex",&m_lDuplexType); //SAVE rs->SaveRecord(); m_bNew=false; m_bEditing=false; } void CRptSetDlg::Security() { //m_bReadOnly=false; int x=m_pApp->Allowed(RPRINTSETUP,true); if(x==0)//no access allowed { m_pApp->SecurityWarning(); CDialog::OnCancel(); } if(x==2)//read only { //m_bReadOnly=true; //m_ckCustomDefault.EnableWindow(FALSE); m_ckPreview.EnableWindow(FALSE); m_edCopies.SetReadOnly(TRUE); m_edCustomReport.SetReadOnly(TRUE); m_edPrinterSelected.SetReadOnly(TRUE); m_btnDefaultPrinter.ShowWindow(FALSE); m_btnDefaultReport.ShowWindow(FALSE); m_btnReset.ShowWindow(FALSE); m_btnSelectPrinter.ShowWindow(FALSE); m_btnSelectReport.ShowWindow(FALSE); } } //Generate a string to represent all current paper //settings CString CRptSetDlg::FormatPaperSettingsString(void) { CString strPage; switch(m_lPaperOrientation) { case 0://default paper, say nothing break; case 1://portrait strPage="Portrait, "; break; case 2://landscape strPage="Landscape, "; break; } switch(m_lPaperSize) { case 0://default paper size, say nothing break; case 16://10X14 strPage+="10x14, "; break; case 17: strPage+="11x17, "; break; case 8: strPage+="A3, "; break; case 9: strPage+="A4, "; break; case 10: strPage+="A4 small, "; break; case 11: strPage+="A5, "; break; case 12: strPage+="B4, "; break; case 13: strPage+="B5, "; break; case 24: strPage+="C sheet, "; break; case 25: strPage+="D sheet, "; break; case 20: strPage+="#10 envelope, "; break; case 21: strPage+="#11 envelope, "; break; case 22: strPage+="#12 envelope, "; break; case 23: strPage+="#14 envelope, "; break; case 19: strPage+="#9 envelope, "; break; case 33: strPage+="B4 envelope, "; break; case 34: strPage+="B5 envelope, "; break; case 35: strPage+="B6 envelope, "; break; case 29: strPage+="C3 envelope, "; break; case 30: strPage+="C4 envelope, "; break; case 28: strPage+="C5 envelope, "; break; case 31: strPage+="C6 envelope, "; break; case 32: strPage+="C65 envelope, "; break; case 27: strPage+="DL envelope, "; break; case 36: strPage+="Italy envelope, "; break; case 37: strPage+="Monarch envelope, "; break; case 38: strPage+="Personal envelope, "; break; case 26: strPage+="E sheet, "; break; case 7: strPage+="Executive, "; break; case 41: strPage+="German fanfold legal, "; break; case 40: strPage+="German fanfold standard, "; break; case 39: strPage+="US fanfold, "; break; case 14: strPage+="Folio, "; break; case 4: strPage+="Ledger, "; break; case 5: strPage+="Legal, "; break; case 1: strPage+="Letter, "; break; case 2: strPage+="Letter small, "; break; case 18: strPage+="Note, "; break; case 15: strPage+="Quatro, "; break; case 3: strPage+="Tabloid, "; break; case 6: strPage+="Statement, "; break; case 256: strPage+="Custom size, "; break; } switch(m_lPaperSource) { case 0: break; case 7://default paper source, say nothing break; case 14: strPage+="Cassette tray, "; break; case 5: strPage+="Envelope tray, "; break; case 6: strPage+="Manual envelope tray, "; break; case 15: strPage+="Form source tray, "; break; case 11: strPage+="Large capacity tray, "; break; case 10: strPage+="Large format tray, "; break; case 2: strPage+="Lower tray, "; break; case 4: strPage+="Manual tray, "; break; case 3: strPage+="Middle tray, "; break; case 9: strPage+="Small format tray, "; break; case 8: strPage+="Tractor feed tray, "; break; case 1: strPage+="Upper tray, "; break; } switch(m_lDuplexType) { case 0: break; case 1: //strPage+="Simplex duplex "; break; case 2: strPage+="Vertical duplex, "; break; case 3: strPage+="Horizontal duplex, "; break; } strPage.TrimRight(); strPage.TrimRight(','); return strPage; } void CRptSetDlg::OnBnClickedCkpreview() { if(m_ckPreview.GetCheck()) m_edCopies.EnableWindow(FALSE); else m_edCopies.EnableWindow(TRUE); }