⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqlplusdoc.cpp

📁 用C++编写的数据库软件
💻 CPP
字号:
// MySqlPlusDoc.cpp : implementation of the CMySqlPlusDoc class
//

#include "stdafx.h"
#include "MySqlPlus.h"

#include "MySqlPlusDoc.h"
#include "SqlInputView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMySqlPlusDoc

IMPLEMENT_DYNCREATE(CMySqlPlusDoc, CDocument)

BEGIN_MESSAGE_MAP(CMySqlPlusDoc, CDocument)
	//{{AFX_MSG_MAP(CMySqlPlusDoc)
	ON_COMMAND(ID_MY_FILE_OPEN, OnMyFileOpen)
	ON_COMMAND(ID_MY_FILE_NEW, OnMyFileNew)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMySqlPlusDoc construction/destruction

CMySqlPlusDoc::CMySqlPlusDoc()
{
	m_myfile = "New File";
	m_strPathName = "New File";
}

CMySqlPlusDoc::~CMySqlPlusDoc()
{
}


/////////////////////////////////////////////////////////////////////////////
// CMySqlPlusDoc serialization

void CMySqlPlusDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		
	}
	else
	{
		// TODO: add loading code here
	}
	//head is CShowResultView
	CSqlInputView* View = (CSqlInputView*)m_viewList.GetTail();
	ASSERT(View->IsKindOf(RUNTIME_CLASS(CSqlInputView)));
	View->SerializeRaw (ar);
}

/////////////////////////////////////////////////////////////////////////////
// CMySqlPlusDoc diagnostics

#ifdef _DEBUG
void CMySqlPlusDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CMySqlPlusDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMySqlPlusDoc commands

void CMySqlPlusDoc::OnMyFileOpen() 
{
	
	if (OnMyFileNew() != 2)	//cancel
	{
		CSqlInputView* View = (CSqlInputView*)m_viewList.GetTail();
		ASSERT(View->IsKindOf(RUNTIME_CLASS(CSqlInputView)));
		
		CFileDialog fileDlg(TRUE, "sql", "*.sql", NULL, "MySql Gaochun(*.sql)", NULL);
		if (fileDlg.DoModal ()==IDOK)
		{
			m_myfile = fileDlg.GetPathName();
			CFile file;
			if(!file.Open(m_myfile, CFile::modeReadWrite))
			{
				View->MessageBox("File Read Error");
				return;
			}

			CArchive ar(&file,CArchive::load);
			Serialize(ar);

			m_strPathName = m_myfile;

			CString fileTemp;
			fileTemp.Format ("%s - MySqlPlus",m_myfile);
			View->GetParent ()->GetParent ()->SetWindowText (fileTemp);
			SetModifiedFlag(FALSE);     // make clean
		}
	}

}

int CMySqlPlusDoc::OnMyFileNew() 
{
	CSqlInputView* View = (CSqlInputView*)m_viewList.GetTail();
	ASSERT(View->IsKindOf(RUNTIME_CLASS(CSqlInputView)));
	
	CString fileTemp;
	fileTemp.Format ("%s has been changed,are you saved?",m_myfile);

	int state =2; //2 cancel;6 yes ; 7 no
	int fileSave = IDOK;
	if (IsModified())
	{
		state = View->MessageBox(fileTemp,NULL,MB_YESNOCANCEL);;
	}
	else   //when not modify then direct new file
	{
		state = 7;
	}

	if (state != 2)
	{
		if (state == 6)
		{
			if (m_myfile == "New File")
			{
				CFileDialog fileDlg(FALSE, "sql", m_myfile, NULL, "MySql Gaochun(*.sql)", NULL);
				if ((fileSave = fileDlg.DoModal ())==IDOK)
				{
					OnSaveDocument (fileDlg.GetPathName());
				}
			}
			else	//use current filename
			{
				OnSaveDocument (m_myfile);
			}
		}
		if (fileSave ==IDOK)
		{
			m_strPathName = "New File";
			View->GetParent ()->GetParent ()->SetWindowText ("New File - MySqlPlus");
			View->GetEditCtrl ().SetWindowText(NULL);
			SetModifiedFlag(FALSE);     // make clean
		}
	}
	return state;
}

BOOL CMySqlPlusDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	m_myfile = 	lpszPathName;
	return CDocument::OnSaveDocument(lpszPathName);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -