📄 docreport.cpp
字号:
m_strReport << "</body>\n";
m_strReport << "</HTML>\n";
m_strReport.close();
return !m_strReport.fail();
};
///////////////////////////////////////////////////////////////////////////////
//
// BOOL CDocReport::CreateReport()
//
BOOL CDocReport::CreateReport()
{
BeginWaitCursor();
BeginReport();
BOOL bOK = WriteReport();
EndReport();
EndWaitCursor();
return bOK;
};
///////////////////////////////////////////////////////////////////////////////
//
// CDocReport::Write()
//
void CDocReport::Write(CString string, int nFlags)
{
// String out reserved characters from string
if (nFlags != FLG_HTML)
{
// Nb: Must change ampersand first as contained in reserved characters
int i=0;
while ((i = string.Find('&',i)) != -1)
{
string = string.Left(i) + "&" + string.Mid(i+1);
i++;
}
while ((i = string.Find('<')) != -1)
{
string = string.Left(i) + "<" + string.Mid(i+1);
}
while ((i = string.Find('>')) != -1)
{
string = string.Left(i) + ">" + string.Mid(i+1);
}
while ((i = string.Find('\"')) != -1)
{
string = string.Left(i) + """ + string.Mid(i+1);
}
};
m_strReport << string;
};
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::Write(double, int nDecPlace = 0)
//
void CDocReport::Write(double dValue, int nDecPlace)
{
BOOL bOK = TRUE;
m_strReport.flags(ios::left);
if (_snprintf(m_sBuffer, sizeof(m_sBuffer), "%-.*lf", nDecPlace, dValue) <= 0)
{
bOK = FALSE;
}
m_strReport << m_sBuffer;
// Ensure output to stream okay
if (m_strReport.fail() || !bOK)
{
AfxThrowUserException();
bOK = FALSE;
}
};
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::Write(long)
//
void CDocReport::Write(long lValue)
{
m_strReport.flags(ios::left);
m_strReport << lValue;
// Ensure output to stream okay
if (m_strReport.fail())
{
AfxThrowUserException();
}
};
///////////////////////////////////////////////////////////////////////////////
void CDocReport::BeginTable(int nCols)
{
m_nCols = nCols;
m_nRow = 0;
m_strReport << "<TABLE class=\"body\" border=\"1\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#000000\" WIDTH=\"100%\">\n";
}
///////////////////////////////////////////////////////////////////////////////
void CDocReport::EndTable()
{
m_nCols = 0;
m_strReport << "</TABLE>\n";
}
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::SetFont(int nFont)
//
// Changes the font used to display
//
void CDocReport::SetFont(int nFont, int iFlag)
{
// Clear previous settings
if (iFlag & fontoff)
{
if (m_nFont & FONT_BOLD) m_strReport << "</B>";
if (m_nFont & FONT_ITALIC) m_strReport << "</I>";
if (m_nFont & FONT_FIXED) m_strReport << "</FONT>";
if (m_nFont & FONT_SMALL) m_strReport << "</FONT>";
};
// Set new settings
m_nFont = nFont;
if (iFlag & fonton)
{
if (m_nFont & FONT_BOLD) m_strReport << "<B>";
if (m_nFont & FONT_ITALIC) m_strReport << "<I>";
if (nFont & FONT_FIXED) m_strReport << "<FONT FACE=\"Courier New\">";
if (nFont & FONT_SMALL) m_strReport << "<FONT SIZE=2>";
};
};
///////////////////////////////////////////////////////////////////////////////
void CDocReport::SetStyle(int nStyle, int iFlag)
{
// Clear previous settings
if (iFlag & fontoff)
{
m_nStyle = 0;
} else
{
m_nStyle = nStyle;
}
};
///////////////////////////////////////////////////////////////////////////////
//
// Adds string to a list of values to be displayed as column headings
//
void CDocReport::AddTableCell(LPCSTR lpString, CString sClass, int nFlags)
{
int nWidth = 100 / max(1,m_nCols);
m_strReport << "<TD WIDTH=" << nWidth << "%>";
SetFont(m_nFont, fonton);
NewPara(sClass);
Write(lpString, nFlags);
EndPara();
SetFont(m_nFont, fontoff);
m_strReport << " </TD>\n";
}
///////////////////////////////////////////////////////////////////////////////
void CDocReport::BeginTableRow()
{
if (m_nRow == 0) m_strReport << "<TR class=\"header\">";
else if (m_nRow%2) m_strReport << "<TR class=\"odd\">";
else m_strReport << "<TR class=\"even\">";
m_nRow++;
}
///////////////////////////////////////////////////////////////////////////////
//
// Outputs the column headings, splitting them onto multiple lines as necessary
//
void CDocReport::EndTableRow()
{
m_strReport << "</TR>\n";
};
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::Bold()
//
void CDocReport::Bold()
{
SetFont(FONT_BOLD);
}
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::Italic()
//
void CDocReport::Italic()
{
SetFont(FONT_ITALIC);
};
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::Plain()
//
void CDocReport::Plain()
{
SetFont(FONT_PLAIN);
};
///////////////////////////////////////////////////////////////////////////////
//
// void CDocReport::SetAlignment(int nAlign)
//
// Sets the allignment (justification) for columns
//
void CDocReport::SetAlignment(int nAlign)
{
// Reset previous alignment
if (m_nAlign & RIGHT) m_strReport << "</RIGHT>";
if (m_nAlign & CENTRE) m_strReport << "</CENTER>";
if (m_nAlign & LEFT) m_strReport << "</LEFT>";
m_nAlign = nAlign;
if (m_nAlign & RIGHT) m_strReport << "<RIGHT>";
if (m_nAlign & CENTRE) m_strReport << "<CENTER>";
if (m_nAlign & LEFT) m_strReport << "<LEFT>";
};
///////////////////////////////////////////////////////////////////////////////
void CDocReport::Divider()
{
}
///////////////////////////////////////////////////////////////////////////////
void CDocReport::OnFileSaveAs()
{
BOOL bOK = TRUE;
CFileDialog dlg(FALSE, "htm",NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Report (*.htm)|*.htm||");
if (dlg.DoModal() == IDOK)
{
BeginWaitCursor();
// Open files
FILE* pFile = fopen(dlg.GetPathName(), "w");
FILE* pFileIn = fopen(m_sFileName, "r");
// Copy one file to the other
if (pFile != NULL && pFileIn != NULL)
{
char ch = fgetc(pFileIn);
while (ch != EOF && bOK)
{
if (fputc(ch, pFile) == EOF)
{
bOK = FALSE;
}
ch = fgetc(pFileIn);
}
} else
{
bOK = FALSE;
}
// Tidy up
if (pFile != NULL) fclose(pFile);
if (pFileIn != NULL) fclose(pFileIn);
EndWaitCursor();
if (!bOK)
{
AfxMessageBox(BDString(IDS_ERRORWRITE) + ": " + dlg.GetPathName());
}
}
}
///////////////////////////////////////////////////////////////////////////////
void CDocReport::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
pCmdUI->Enable(FALSE);
}
///////////////////////////////////////////////////////////////////////////////
//
// Before closing give the html view time to close any embedded windows
//
BOOL CDocReport::SaveModified()
{
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CBDHtmlView* pView = (CBDHtmlView*)GetNextView(pos);
if (pView->IsKindOf(RUNTIME_CLASS(CBDHtmlView)))
{
if (!pView->PreCloseView())
{
return FALSE;
}
};
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
void CDocReport::OnCloseDocument()
{
CDocument::OnCloseDocument();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -