/***********************************	****************************************
**
**    $Header:   D:/PICSLDV/SRC/LOG/DIAGNO/DIAGNRES.CPP   1.14   09 Jan 1997 14:28:00   ZJRD  $
**
**    $Log:   D:/PICSLDV/SRC/LOG/DIAGNO/DIAGNRES.CPP  $
** 
**    Rev 1.14   09 Jan 1997 14:28:00   ZJRD
** No change.
** 
**    Rev 1.13   13 Dec 1996 11:23:16   ZJRD
** No change.
** 
**    Rev 1.12   22 Nov 1996 11:04:12   ZJRD
** No change.
** 
**    Rev 1.11   11 Nov 1996 12:51:30   ZJRD
** PIC/SLD Version 0.96
** 
**    Rev 1.10   06 Nov 1996 13:03:06   ZJRD
** No change.
** 
**    Rev 1.9   02 Nov 1996 09:50:42   ZJRD
** No change.
** 
**    Rev 1.8   30 Oct 1996 12:53:20   ZJRD
** No change.
** 
**    Rev 1.7   28 Oct 1996 09:45:54   ZJRD
** PIC/SLD Version 0.92
** 
**    Rev 1.4   23 Sep 1996 10:40:08   ZJRD
** No change.
** 
**    Rev 1.3   06 Sep 1996 13:56:10   ZJRD
** PIC/SLD Version 0.60
** 
**    Rev 1.4.1.0   12 Aug 1996 11:06:20   ZJRD
** EasyPack/SLD Version 1.98
** 
**    Rev 1.2   05 Jun 1996 15:01:02   ZJRD
** No change.
** 
**    Rev 1.1   29 May 1996 09:43:02   ZJRD
** EasyPack/SLD Version 1.95
** 
**    Rev 1.0   16 May 1996 09:12:44   ZJRD
** Initial revision.
** 
****************************************************************************/
// diagnres.cpp : implementation file
//
//john chow 96.3
#include "stdafx.h"
#include "diagnres.h"
#include "resource.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDiagnResultBox dialog


CDiagnResultBox::CDiagnResultBox(CWnd* pParent /*=NULL*/)
	: CDialog(CDiagnResultBox::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDiagnResultBox)
	//}}AFX_DATA_INIT
}

void CDiagnResultBox::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDiagnResultBox)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDiagnResultBox, CDialog)
	//{{AFX_MSG_MAP(CDiagnResultBox)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CDiagnResultBox message handlers

void CDiagnResultBox::OnButtonSave()
{
	// TODO: Add your control notification handler code here
	static char BASED_CODE szFilter[] = "Normal Files (*.dgn) |*.dgn | All Files"
	                                    " (*.*) | *.*||";
	
    CFileDialog* tmpDialog = new CFileDialog(FALSE,"dgn",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
     										 szFilter,NULL);
    tmpDialog->m_ofn.lpstrTitle = "Save Diagnostics Detail Information";
    if (tmpDialog->DoModal() == IDOK) {
        CString pFileName = tmpDialog->GetPathName();
        
        CFile saveFile;                   
        //OPEN FILE
        if( !saveFile.Open( pFileName, CFile::modeCreate ) ) {
            AfxMessageBox("Diagnostics Save File Creating Error!");
            return;	
	    }          
        saveFile.Close();           
        if( !saveFile.Open( pFileName, CFile::modeReadWrite ) ) {
            AfxMessageBox("Diagnostics Save File Openning Error!"); 
            return;	
        }    
        //save information            
        for (int i=0;i<m_InfoShow.m_pContain->GetValidContainLen();i++) {
        	void * pTmp = (*m_InfoShow.m_pContain)[i];
        	char * pcTmp = (char*)pTmp;
        	int nLenTmp = strlen(pcTmp);
        	CString strTmp = "";
        	for(int i2=0;i2<nLenTmp;i2++) {
				if('\n' != pcTmp[i2]) strTmp += pcTmp[i2];
			}                                           
			strTmp += '\n';
        	saveFile.Write( strTmp.GetBuffer(strTmp.GetLength()+2),strTmp.GetLength());	
        	strTmp.ReleaseBuffer();
        }
        
        saveFile.Close(); 
    }        
    delete tmpDialog;
	
}

BOOL CDiagnResultBox::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	CenterWindow();
	
	
	//bind the infoedit
	VERIFY(m_InfoShow.SubclassDlgItem(IDC_LISTBOX,this));
	
	for (int i=0;i<m_InfoShow.m_pContain->GetValidContainLen();i++) {
    	void * pTmp = (*(m_InfoShow.m_pContain))[i];
    	char * pcTmp = (char*)pTmp;
    	m_InfoShow.AddLine(pcTmp);
    } 
    //MARKED FOR FOOLIST CHEERSON
    //m_InfoShow.SetHorizontalExtent(1000);
	return TRUE;  // return TRUE  unless you set the focus to a control
}
