📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "ChooseBookTool.h"
#include "MainFrm.h"
#include "BookListView.h"
#include "TabPageView.h"
#include "WaitDlg.h"
#include "ADOConnection/ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
/*static UINT indicators[] =
{
ID_SEPARATOR,
ID_BOOKNUM,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};*/
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_EXPORT_TXT, OnExportTxt)
ON_COMMAND(ID_EXPORT_ACCESS, OnExportAccess)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_BOOKNUM,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
VERIFY(m_wndSplitter.CreateStatic(this,1,2));
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CTabPageView),CSize(0,0),pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CBookListView),CSize(0,0),pContext);
CTabPageView* pTabView = (CTabPageView*)m_wndSplitter.GetPane(0,0);
CSize TabSize = pTabView->GetTotalSize();
m_wndSplitter.SetColumnInfo(0,TabSize.cx,0);
CBookListView* pListView = (CBookListView*)m_wndSplitter.GetPane(0,0);
CSize ListSize = pListView->GetTotalSize();
m_wndSplitter.SetColumnInfo(0,ListSize.cx,0);
return TRUE;
/*return m_wndSplitter.Create(this,
2, 2, // TODO: adjust the number of rows, columns
CSize(10, 10), // TODO: adjust the minimum pane size
pContext);*/
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
CWnd* CMainFrame::GetPaneView(int nCol, int nPos)
{
return m_wndSplitter.GetPane(nCol,nPos);
}
void CMainFrame::OnExportTxt()
{
// TODO: Add your command handler code here
CString PathName = _T("");
CWaitDlg* m_pRunDlg;
MSG message;
BOOL m_bFile = FALSE;
static char BASED_CODE txtFilter[] = "图书数据文件(*.txt)|*.txt|";
CFileDialog dlgFile(FALSE,".txt",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,txtFilter,NULL);
CStdioFile BookFile;
if (dlgFile.DoModal() == IDOK)
{
PathName = dlgFile.GetPathName();
if (BookFile.Open(PathName,CFile::modeWrite|CFile::modeCreate))
{
m_pRunDlg = new CWaitDlg(this);
m_pRunDlg->Create();
m_pRunDlg->SetCycleStatus(FALSE);
m_pRunDlg->SetWindowText("正在导出,请稍后.....");
m_pRunDlg->Running();
m_pRunDlg->CenterWindow(this);
m_pRunDlg->ShowWindow(SW_SHOW);
//CMainFrame *pFrame = (CMainFrame*)this->GetParent()->GetParent();
CBookListView* pBookList = (CBookListView*)this->GetPaneView(0,1);
CString strOut=_T("");
for (int i=0;i<pBookList->m_CtrBookList.GetItemCount()&&(m_pRunDlg->GetCycleStatus()==FALSE);i++)
{
while(::PeekMessage(&message,NULL,0,0,PM_REMOVE))
{
//解解释窗口消息
::TranslateMessage(&message);
//分发窗口消息
::DispatchMessage(&message);
}
if (pBookList->m_CtrBookList.GetCheck(i))
{
strOut = pBookList->m_CtrBookList.GetItemText(i,0)+"\t"+
pBookList->m_CtrBookList.GetItemText(i,1)+"\t"+
pBookList->m_CtrBookList.GetItemText(i,2)+"\t"+
pBookList->m_CtrBookList.GetItemText(i,3)+"\t"+
pBookList->m_CtrBookList.GetItemText(i,4)+"\t"+
pBookList->m_CtrBookList.GetItemText(i,5)+"\t"+
pBookList->m_CtrBookList.GetItemText(i,6)+"\t"+"\r\n";
BookFile.WriteString(strOut);
}
}
BookFile.Close();
m_pRunDlg->StopRunning();
m_pRunDlg->SetCycleStatus(TRUE);
m_pRunDlg->ShowWindow(SW_HIDE);
m_pRunDlg->DestroyWindow();
delete m_pRunDlg;
MessageBox("保存完毕!","提示",MB_ICONINFORMATION);
}
else
{
AfxMessageBox("保存失败!");
}
}
}
void CMainFrame::OnExportAccess()
{
// TODO: Add your command handler code here
ADOConn mydb;
_RecordsetPtr m_pRecordSet;
CString SQLComm = "SELECT * FROM selected";
CString PathName = _T("");
CWaitDlg* m_pRunDlg;
CString Bookid = _T("");
MSG message;
mydb.DeleteRecord();
if (!mydb.OpenTargerDB())
{
AfxMessageBox("没有打开Selected库,请确认库文件是否存在!");
return;
}
m_pRecordSet = mydb.GetRecordSet((LPCSTR)SQLComm);
if (m_pRecordSet->State != adStateOpen)
{
AfxMessageBox("没有打开selected表,请确认表是否存在!");
return;
}
try
{
m_pRunDlg = new CWaitDlg(this);
m_pRunDlg->Create();
m_pRunDlg->SetCycleStatus(FALSE);
m_pRunDlg->SetRunMessage("正在导出到,Access库.......");
m_pRunDlg->Running();
m_pRunDlg->CenterWindow(this);
m_pRunDlg->ShowWindow(SW_SHOW);
CBookListView* pBookView = (CBookListView*)this->GetPaneView(0,1);
for (int i=0;i<pBookView->m_CtrBookList.GetItemCount()&&
(m_pRunDlg->GetCycleStatus()==FALSE);i++)
{
while(::PeekMessage(&message,NULL,0,0,PM_REMOVE))
{
//解解释窗口消息
::TranslateMessage(&message);
//分发窗口消息
::DispatchMessage(&message);
}
Bookid = pBookView->m_CtrBookList.GetItemText(i,0);
if (m_pRecordSet->Supports(adAddNew)||m_pRecordSet->Supports(adUpdate)&&
(pBookView->m_CtrBookList.GetCheck(i)))
{
m_pRecordSet->AddNew();
m_pRecordSet->GetFields()->GetItem("BOOKID")->Value = (_variant_t)Bookid;
}
}
//m_pRecordSet->Close();
mydb.ExitConnect();
}
catch (_com_error e)
{
mydb.LogWrite((LPCSTR)e.Description());
}
m_pRunDlg->StopRunning();
m_pRunDlg->SetCycleStatus(TRUE);
m_pRunDlg->ShowWindow(SW_HIDE);
m_pRunDlg->DestroyWindow();
delete m_pRunDlg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -