Пример #1
0
void CItemCommerceSearchView::OnExcelOut(CString filepath, CString filename)
{
	CSpreadSheet sOutFile(filepath, "ListSheet");

	CStringArray readArray;
	CGridCellCheck *pCell;
	BOOL bCheck;

	sOutFile.BeginTransaction();
  // 加入标题
	int iCol = m_cDisplay.GetColumnCount();
	int iRow = m_cDisplay.GetRowCount();
    readArray.RemoveAll();
	int i,j;
	CString str;
    for(i =0; i< iCol;i++)
	{
        str = m_cDisplay.GetItemText(0,i);
		if(str =="")
			str= "0";
	     readArray.Add(str);
	}
	sOutFile.AddHeaders(readArray);

	// 加入数据

	for(i = 1; i < iRow; i++)
	{
		readArray.RemoveAll();
        for(j=0;j<iCol;j++) 
		{
			if(j>=1 && m_iName[j-1].tType == 4)
			{
				 pCell = (CGridCellCheck*)m_cDisplay.GetCell(i,j);
                bCheck = pCell->GetCheck();
				if(bCheck)
					str = "TRUE";
				else
					str = "FALSE";
			}
			else
			{
			   str = m_cDisplay.GetItemText(i,j);
			   if(str=="")
				   str = "/";
			}

			readArray.Add(str);
		}
		sOutFile.AddRow(readArray,i+1);
	}
  
	sOutFile.Commit();	

	AfxMessageBox("查询结果已经保存为文件:\n "+filename);
    
}
HRESULT STDMETHODCALLTYPE CG_CConsole::genConsoleForLibrary(
    IUnknown*  pIUnkFront,           
    BSTR       sTargetTypeName,
    long*      plErrors,
    long*      plWarnings
)
{
    HRESULT hr;
    
    m_sTargetInstName = NULL;
    m_sResourceName   = NULL;
    m_sWebServerAddr  = NULL;
    m_sControlAddr    = NULL;
    m_sTargetTypeName = sTargetTypeName;

    //init outputs:
    *plErrors   = 0;
    *plWarnings = 0;

    hr = pIUnkFront->QueryInterface(IID_ICG_IECFront, (void**)&m_pIFront);
    if(FAILED(hr))
    {
        assert(!"QueryInterface(IID_ICG_IECFront");
        return E_FAIL;
    }

    initErrMsgSink();

    const CG_Symtab*           pSymTab;
    const CG_POU4CPInfo*const* ppInf;
    bool                       bEntryHasCustomAsp;
    bool                       bIsEntrySFC;
    const TCHAR*               pszAspFileName;
    FC_CString                 sOutFile(MAX_PATH);
    FC_CString                 sOutPath(MAX_PATH);
    FC_CString                 sImportedFile(MAX_PATH);
    const TCHAR*const*         pzpszSecs;


    sOutPath.load(m_pIFront->FCPgetPrjPath()) << _T("\\gen\\.") << m_sTargetTypeName << _T("\\.link\\");

    for (ppInf = m_pIFront->FCPgetAllPOUs(); *ppInf; ppInf++)
    {
        pSymTab = m_pIFront->loadHeader((*ppInf)->pszId);

        if (pSymTab->pLibCtx || pSymTab->pouTyp == CG_POU_PRG)  // ignore library POUs and prgs
            continue; 
        
        sOutFile.load(pSymTab->edp.pszFile) << _T(".link");

        if (FC_FileExists(sOutPath, sOutFile) != 1)             // do not append something if the file does not exist
            continue;
        
        bIsEntrySFC = pSymTab->srcTyp == CG_SRC_TYPE_4GR && 
                      (pSymTab->flags & CG_STAB_BDY_IS_SFC) && 
                      !pSymTab->pLibCtx;

        bEntryHasCustomAsp = (checkOutAspFiles(pSymTab, &pszAspFileName) == S_OK);
        if (bEntryHasCustomAsp)
        {
            sImportedFile.load(m_pIFront->FCPgetPrjPath()) << _T("\\") 
                << FC_StringGetFilePart(pszAspFileName);
        }
        else if (bIsEntrySFC)
        {
            if (FAILED(gen4grvFile(pSymTab->edp.pszFile)))
                continue;
            sImportedFile.load(m_pIFront->FCPgetPrjPath()) << _T("\\gen\\.") << m_sTargetTypeName 
                << _T("\\.classes\\") << pSymTab->edp.pszFile;
            sImportedFile.changeFileExt("4grv");
        }

        if (bEntryHasCustomAsp || bIsEntrySFC)
        {
            CGT_CDmp  dmp;

            dmp << CG_LINK_LIB_PUT _T(";") << sImportedFile << _T("\n");

            if (!CGT_DmpToFile(&m_dm, sOutPath, sOutFile, dmp, true))
            {
                return E_FAIL;
            }
        }
    }

    addCustomFilesToConsoleLinkFile(m_pIFront->FCPgetSection(CG_SEC_4CP_CONSOLE));

    for(pzpszSecs = m_pIFront->FCPgetSectionNames(); *pzpszSecs; pzpszSecs++)
    {
        if (FC_StringStartsWithI(*pzpszSecs, CG_SEC_4CP_CONSOLE_BEG) >= 0)
        {
            const CG_AttribList* al = m_pIFront->FCPgetSection(*pzpszSecs);
            if (al && al->nAttribs)
                m_dm.msg1(CG_W_TEXT, &(al->pairs[0].edpKey), 
                    m_dm.jot1() << _T("ignoring section '") << *pzpszSecs 
                    << _T("'; no resource associated while creating library") );
        }
    }
        
    //set front to NULL, this way we get the sum of newly created diags, not also 
    //the previously submitted error counters:
    m_dm.setFront(NULL);

    *plErrors   = m_dm.getDisplayedErrors();
    *plWarnings = m_dm.getDisplayedWarnings();
    
    m_pIFront->Release();

    return *plErrors? E_FAIL: S_OK;
}