📄 databaselist.cpp
字号:
// Written by JHCC
// DatabaseList.cpp : implementation file
//
#include "stdafx.h"
#include "DatabaseList.h"
#include "JHHBDoc.h"
#include "JHHBView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CColumnInfo
{
public:
static int m_nPHColumnWidth;
LPTSTR m_lpDisp;
int m_nColumnWidth;
};
int CColumnInfo::m_nPHColumnWidth = 60;
CColumnInfo columnInfo[] =
{
// {_T("序号"), 50},
{_T("时间"), 60},
};
/////////////////////////////////////////////////////////////////////////////
// CDatabaseList
CDatabaseList::CDatabaseList()
{
m_bUseDao = TRUE;
m_pDaoStationInfoSet = NULL;
m_pStationInfoSet = NULL;
m_pDaoHBDateDataSet = NULL;
m_pHBDateDataSet = NULL;
}
CDatabaseList::~CDatabaseList()
{
}
void CDatabaseList::Set(BOOL bUseDao, CDaoStationInfoSet* pDaoStationInfoSet,
CStationInfoSet* pStationInfoSet,
CDaoHBDateDataSet* pDaoHBDateDataSet,
CHBDateDataSet* pHBDateDataSet)
{
m_bUseDao = bUseDao;
m_pDaoStationInfoSet = pDaoStationInfoSet;
m_pStationInfoSet = pStationInfoSet;
m_pDaoHBDateDataSet = pDaoHBDateDataSet;
m_pHBDateDataSet = pHBDateDataSet;
}
void CDatabaseList::EraseList(void)
{
DeleteAllItems();
while(DeleteColumn(0));
UpdateWindow();
}
//#include "JHHB.h"
//#include "DataListView.h"
BOOL CDatabaseList::DisplayColumnHeadings(void)
{
EraseList();
/*
CFont* pFont = GetFont();
LOGFONT logFont;
pFont->GetLogFont(&logFont);
logFont.lfHeight = 20;
logFont.lfWidth = 20;
logFont.lfWeight = 900;
logFont.lfItalic = TRUE;
CFont m_font;
VERIFY(m_font.CreateFontIndirect(&logFont));
SetFont(&m_font);
*/
LV_COLUMN lvColumn; // list view column structure
// Now initialize the columns you will need.
// Initialize the LV_COLUMN structure.
// The mask specifies that the fmt, width, pszText, and subitem members
// of the structure are valid.
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT; // left-align column
// Add the columns.
for (int index = 0; index < sizeof(columnInfo) / sizeof(columnInfo[0]); ++ index)
{
lvColumn.cx = columnInfo[index].m_nColumnWidth; // width of column in pixels
lvColumn.iSubItem = index;
lvColumn.pszText = columnInfo[index].m_lpDisp;
if (InsertColumn(index, &lvColumn) == -1)
return FALSE;
}
// CJHHBView* pView = (CJHHBView*)GetParent();
// CJHHBView* pView = ((CDataListDlg*)GetParent())->GetDocument()->GetJHHBView();
// GetParentFrame()->GetActiveDocument()
if (m_bUseDao) // DAO
{
ASSERT(m_pDaoStationInfoSet != NULL);
lvColumn.cx = CColumnInfo::m_nPHColumnWidth;
ASSERT(m_pDaoStationInfoSet->GetRecordCount() != 0);
m_pDaoStationInfoSet->MoveFirst();
index = sizeof(columnInfo) / sizeof(columnInfo[0]);
while (!m_pDaoStationInfoSet->IsEOF())
{
lvColumn.iSubItem = index ++;
lvColumn.pszText = (LPTSTR)(LPCTSTR)m_pDaoStationInfoSet->m_STATION;
if (InsertColumn(index, &lvColumn) == -1)
return FALSE;
m_pDaoStationInfoSet->MoveNext();
}
}
else // ODBC
{
ASSERT(m_pStationInfoSet != NULL);
lvColumn.cx = CColumnInfo::m_nPHColumnWidth;
ASSERT(m_pStationInfoSet->GetRecordCount() != 0);
m_pStationInfoSet->MoveFirst();
index = sizeof(columnInfo) / sizeof(columnInfo[0]);
while (!m_pStationInfoSet->IsEOF())
{
lvColumn.iSubItem = index ++;
lvColumn.pszText = (LPTSTR)(LPCTSTR)m_pStationInfoSet->m_STATION;
if (InsertColumn(index, &lvColumn) == -1)
return FALSE;
m_pStationInfoSet->MoveNext();
}
}
return TRUE;
}
BOOL CDatabaseList::Create(const RECT& rect, CWnd* pParentWnd, UINT nID)
{
if (CListCtrl::Create(WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | LVS_EDITLABELS, // styles
rect, pParentWnd, nID) == FALSE)
return FALSE;
/*
CFont* pFont = GetFont();
LOGFONT logFont;
pFont->GetLogFont(&logFont);
logFont.lfHeight = 20;
logFont.lfWidth = 20;
logFont.lfWeight = 900;
logFont.lfItalic = TRUE;
CFont m_font;
VERIFY(m_font.CreateFontIndirect(&logFont));
SetFont(&m_font);
LV_COLUMN lvColumn; // list view column structure
// Now initialize the columns you will need.
// Initialize the LV_COLUMN structure.
// The mask specifies that the fmt, width, pszText, and subitem members
// of the structure are valid.
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT; // left-align column
// Add the columns.
for (int index = 0; index < sizeof(columnInfo) / sizeof(columnInfo[0]); ++ index)
{
lvColumn.cx = columnInfo[index].m_nColumnWidth; // width of column in pixels
lvColumn.iSubItem = index;
lvColumn.pszText = columnInfo[index].m_lpDisp;
if (InsertColumn(index, &lvColumn) == -1)
return FALSE;
}
CJHHBView* pView = (CJHHBView*)GetParent();
if (pView->m_bUseDao) // DAO
{
ASSERT(m_pDaoStationInfoSet != NULL);
lvColumn.cx = CColumnInfo::m_nPHColumnWidth;
ASSERT(m_pDaoStationInfoSet->GetRecordCount() != 0);
m_pDaoStationInfoSet->MoveFirst();
index = sizeof(columnInfo) / sizeof(columnInfo[0]);
while (!m_pDaoStationInfoSet->IsEOF())
{
lvColumn.iSubItem = index ++;
lvColumn.pszText = (LPTSTR)(LPCTSTR)m_pDaoStationInfoSet->m_STATION;
if (InsertColumn(index, &lvColumn) == -1)
return FALSE;
m_pDaoStationInfoSet->MoveNext();
}
}
else // ODBC
{
CStationInfoSet* m_pStationInfoSet = pView->m_pStationInfoSet;
ASSERT(m_pStationInfoSet != NULL);
lvColumn.cx = CColumnInfo::m_nPHColumnWidth;
ASSERT(m_pStationInfoSet->GetRecordCount() != 0);
m_pStationInfoSet->MoveFirst();
index = sizeof(columnInfo) / sizeof(columnInfo[0]);
while (!m_pStationInfoSet->IsEOF())
{
lvColumn.iSubItem = index ++;
lvColumn.pszText = (LPTSTR)(LPCTSTR)m_pStationInfoSet->m_STATION;
if (InsertColumn(index, &lvColumn) == -1)
return FALSE;
m_pStationInfoSet->MoveNext();
}
}*/
return TRUE;
}
//----------FieldToStr 未用--------- ljh
static CString FieldToStr(CDaoRecordset* pSet, int iSubItem)
{
COleVariant var ;//= pSet->GetFieldValue(field[iSubItem].iField);
CString strRet;
switch (var.vt)
{
case VT_EMPTY:
case VT_NULL:
strRet = _T("NULL");
break;
case VT_I2:
strRet.Format(_T("%hd"),V_I2(&var));
break;
case VT_I4:
strRet.Format(_T("%d"),V_I4(&var));
break;
case VT_R4:
strRet.Format(_T("%e"),(double)V_R4(&var));
break;
/*
case VT_R8:
switch (field[iSubItem].ftType)
{
case FT_INT:
{
int iVal = (int)V_R8(&var);
strRet.Format(_T("%d"), iVal);
break;
}
case FT_NONE:
strRet.Format(_T("%5.2f"),V_R8(&var));
break;
default:
ASSERT(FALSE);
}
break;
*/
case VT_CY:
strRet = COleCurrency(var).Format();
break;
case VT_DATE:
strRet = COleDateTime(var).Format(_T("%Y/%m/%d"));
break;
case VT_BSTR:
strRet = V_BSTRT(&var);
break;
case VT_DISPATCH:
strRet = _T("VT_DISPATCH");
break;
case VT_ERROR:
strRet = _T("VT_ERROR");
break;
// case VT_BOOL:
// return strBOOL(V_BOOL(&var));
case VT_VARIANT:
strRet = _T("VT_VARIANT");
break;
case VT_UNKNOWN:
strRet = _T("VT_UNKNOWN");
break;
case VT_I1:
strRet = _T("VT_I1");
break;
case VT_UI1:
strRet.Format(_T("0x%02hX"),(unsigned short)V_UI1(&var));
break;
case VT_UI2:
strRet = _T("VT_UI2");
break;
case VT_UI4:
strRet = _T("VT_UI4");
break;
case VT_I8:
strRet = _T("VT_I8");
break;
case VT_UI8:
strRet = _T("VT_UI8");
break;
case VT_INT:
strRet = _T("VT_INT");
break;
case VT_UINT:
strRet = _T("VT_UINT");
break;
case VT_VOID:
strRet = _T("VT_VOID");
break;
case VT_HRESULT:
strRet = _T("VT_HRESULT");
break;
case VT_PTR:
strRet = _T("VT_PTR");
break;
case VT_SAFEARRAY:
strRet = _T("VT_SAFEARRAY");
break;
case VT_CARRAY:
strRet = _T("VT_CARRAY");
break;
case VT_USERDEFINED:
strRet = _T("VT_USERDEFINED");
break;
case VT_LPSTR:
strRet = _T("VT_LPSTR");
break;
case VT_LPWSTR:
strRet = _T("VT_LPWSTR");
break;
case VT_FILETIME:
strRet = _T("VT_FILETIME");
break;
case VT_BLOB:
strRet = _T("VT_BLOB");
break;
case VT_STREAM:
strRet = _T("VT_STREAM");
break;
case VT_STORAGE:
strRet = _T("VT_STORAGE");
break;
case VT_STREAMED_OBJECT:
strRet = _T("VT_STREAMED_OBJECT");
break;
case VT_STORED_OBJECT:
strRet = _T("VT_STORED_OBJECT");
break;
case VT_BLOB_OBJECT:
strRet = _T("VT_BLOB_OBJECT");
break;
case VT_CF:
strRet = _T("VT_CF");
break;
case VT_CLSID:
strRet = _T("VT_CLSID");
break;
default:
ASSERT(FALSE);
}
return strRet;
}
//-----------以上功能未用------------ ljh
BOOL CDatabaseList::AddRecord(int nNO, LPCTSTR strTime,
double nPHVal, int nStation,
double nCODVal, double nFLOWVal, double nNH4NVal) // ljh add
{
LV_ITEM lvItem; // list view item structure
// Finally, add the actual items to the control.
// Fill out the LV_ITEM structure for each item to add to the list.
// The mask specifies that the pszText, iImage, lParam and state
// members of the LV_ITEM structure are valid.
lvItem.mask = LVIF_TEXT;
lvItem.state = 0;
lvItem.stateMask = 0;
int nIndex = 0;
while (nNO - 1 > GetItemCount())
{
TCHAR pNOStringBuf[5];
lvItem.iItem = nNO - 1 - 1;
nIndex=GetItemCount();
lvItem.iSubItem = 0;
::sprintf(pNOStringBuf,"%2.2d:%2.2d",nIndex/6,(nIndex % 6)*10);
lvItem.pszText=(LPTSTR)pNOStringBuf;
InsertItem(&lvItem);
}
lvItem.iItem = nNO - 1;
if (lvItem.iItem >= GetItemCount()) // new
{
TCHAR pNOStringBuf[5];
int c=GetItemCount();
ASSERT(lvItem.iItem == GetItemCount());
// lvItem.iSubItem = 0;
// lvItem.pszText = ::itoa(lvItem.iItem + 1, pNOStringBuf, 10);
lvItem.iSubItem = 0;
lvItem.pszText = (LPTSTR)strTime;
InsertItem(&lvItem);
}
SetItem(&lvItem);
CString strPHData;
strPHData.Format("%5.2f", nPHVal);
lvItem.iSubItem = nStation - 1 + sizeof(columnInfo) / sizeof(columnInfo[0]);
lvItem.pszText = (LPTSTR)(LPCTSTR)strPHData;
SetItem(&lvItem);
/*
int iActualItem;
for (int iSubItem = 0; iSubItem < sizeof(field) / sizeof(CField); ++ iSubItem)
{
lvItem.iItem = (iSubItem == 0)? GetItemCount() : iActualItem;
lvItem.iSubItem = iSubItem;
CString str = ::FieldToStr(pSet, iSubItem);
lvItem.pszText = (LPTSTR)(LPCTSTR)str;
if (iSubItem == 0)
iActualItem = InsertItem(&lvItem);
else
SetItem(&lvItem);
}*/
return TRUE;
}
BOOL CDatabaseList::AddAllRecord(void)
{
DisplayColumnHeadings();
CDocument* pActiveDoc = GetParentFrame()->GetActiveDocument();
POSITION pos = pActiveDoc->GetFirstViewPosition();
CJHHBView* pView = (CJHHBView*)(pActiveDoc->GetNextView(pos));
if (m_bUseDao) // DAO
{
ASSERT(m_pDaoHBDateDataSet != NULL);
if (m_pDaoHBDateDataSet->GetRecordCount() == 0)
goto LABEL_NORECORD;
m_pDaoHBDateDataSet->MoveFirst();
while (!m_pDaoHBDateDataSet->IsEOF())
{
if (AddRecord(m_pDaoHBDateDataSet->m_NO, m_pDaoHBDateDataSet->m_PHTIME,
m_pDaoHBDateDataSet->m_PH, m_pDaoHBDateDataSet->m_STATION,
m_pDaoHBDateDataSet->m_COD, m_pDaoHBDateDataSet->m_FLOW, //ljh add
m_pDaoHBDateDataSet->m_NH4N) == FALSE) //ljh add
return FALSE;
m_pDaoHBDateDataSet->MoveNext();
}
}
else // ODBC
{
ASSERT(m_pHBDateDataSet != NULL);
if (m_pHBDateDataSet->GetRecordCount() == 0)
goto LABEL_NORECORD;
m_pHBDateDataSet->MoveFirst();
while (!m_pHBDateDataSet->IsEOF())
{
if (AddRecord(m_pHBDateDataSet->m_NO, m_pHBDateDataSet->m_PHTIME,
m_pHBDateDataSet->m_PH, m_pHBDateDataSet->m_STATION,
m_pHBDateDataSet->m_COD, m_pHBDateDataSet->m_FLOW, //ljh add
m_pHBDateDataSet->m_NH4N) == FALSE) //ljh add
return FALSE;
m_pHBDateDataSet->MoveNext();
}
}
LABEL_NORECORD:
CRect rtLastItem;
GetItemRect(GetItemCount() - 1, &rtLastItem, LVIR_LABEL);
Scroll(CSize(0, rtLastItem.bottom));
return TRUE;
}
BEGIN_MESSAGE_MAP(CDatabaseList, CListCtrl)
//{{AFX_MSG_MAP(CDatabaseList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -