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

📄 oiltransdlg.cpp

📁 本程序是采用VC++和Mysql编写的一款油量换算软件
💻 CPP
字号:
// OilTransDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OilTrans.h"
#include "OilTransDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COilTransDlg dialog

COilTransDlg::COilTransDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COilTransDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COilTransDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	theSys.bDB = FALSE;
	theSys.bInfo = TRUE;
	theSys.bSAVE = FALSE;
	theSys.bSR = FALSE;
	theSys.bTankC =FALSE;
	theSys.nTankNum = 0;
	theSys.sDBName = "NULL";
	for(int i=0;i<8;i++)
	{
		theSys.nTankOil[i]=-1;
	}
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}
COilTransDlg::~COilTransDlg()
{
  Save();
}
void COilTransDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COilTransDlg)
	DDX_Control(pDX, IDC_TAB_MAIN, m_cTab);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(COilTransDlg, CDialog)
	//{{AFX_MSG_MAP(COilTransDlg)
	ON_MESSAGE(WM_OT_TV, OnGetTV)
	ON_MESSAGE(WM_OT_DB, OnGetDB)
	ON_MESSAGE(WM_OT_DBN, OnGetDBN)
	ON_MESSAGE(WM_OT_SR, OnGetSR)
	ON_MESSAGE(WM_OT_SAVE, OnGetSave)
	ON_MESSAGE(WM_OT_NT, OnNewTank)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COilTransDlg message handlers

BOOL COilTransDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_dlgCmp= new CCmpDlg;
	m_dlgCmp->SetCheckO(theSys.bTankC);
	m_dlgCmp->SetTankNum(theSys.nTankNum);
	for(int i=0;i<8;i++)
	{
		m_dlgCmp->SetOil(i,theSys.nTankOil[i]);
	}
	m_dlgCmp->Create(CCmpDlg::IDD,&m_cTab);
	m_cTab.AddItem(m_dlgCmp,"换算");

    m_dlgSet= new CSysSetDlg;
    m_dlgSet->SetWnd(m_hWnd);
	m_dlgSet->SetDB(theSys.bDB);
	m_dlgSet->SetDBN(1);
	m_dlgSet->SetSave(theSys.bSAVE);
	m_dlgSet->SetSR(theSys.bSR);
	m_dlgSet->SetTank(theSys.bTankC);
	m_dlgSet->Create(CSysSetDlg::IDD,&m_cTab);
	m_cTab.AddItem(m_dlgSet,"设置");

	m_dlgTank= new CTankDlg;
	m_dlgTank->SetTankNum(theSys.nTankNum);
	m_dlgTank->SetWnd(m_hWnd);
	m_dlgTank->Create(CTankDlg::IDD,&m_cTab);
	m_cTab.AddItem(m_dlgTank,"容积表");
    m_cTab.m_bMove = FALSE;

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void COilTransDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void COilTransDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR COilTransDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void COilTransDlg::SetCheckO(BOOL bT)
{
  m_dlgCmp->SetCheckO(bT);
}

void COilTransDlg::UpdateDBN(CString s)
{
  theSys.sDBName=s;
  if(s=="NULL")
    UpdateDBB(FALSE);
  else
	UpdateDBB(TRUE);
}

void COilTransDlg::UpdateDBB(BOOL b)
{
  theSys.bDB =b;
}

void COilTransDlg::UpdateTankN(int n)
{
  theSys.nTankNum = n;
}

void COilTransDlg::UpdateOT(int nN, int nO)
{
 theSys.nTankOil[nN] = nO;
}

void COilTransDlg::UpdateTankC(BOOL b)
{
  theSys.bTankC = b;
}



LONG COilTransDlg::OnGetTV(WPARAM ch, LPARAM mark)
{
    if(mark == 0)
        theSys.bTankC = FALSE;
	else
		theSys.bTankC = TRUE;
	m_dlgCmp->UpdateCheckO(theSys.bTankC);
	return 0;
}

LONG COilTransDlg::OnGetDB(WPARAM ch, LPARAM mark)
{
	if(mark == 0)
		theSys.bDB = TRUE;
	else
	{
		theSys.bDB = FALSE;
		theSys.sDBName = "NULL";
	}
	return 0;
}

LONG COilTransDlg::OnGetDBN(WPARAM ch, LPARAM mark)
{
	if(mark == 1)
		theSys.sDBName = "MySql";
	else if(mark == 2)
		theSys.sDBName = "Access";
	else if(mark == 3)
		theSys.sDBName = "Sql Sever";

	return 0;
}

LONG COilTransDlg::OnGetSR(WPARAM ch, LPARAM mark)
{
	if(mark == 0)	
		theSys.bSR = TRUE;
	else
		theSys.bSR = FALSE;

	return 0;
}

LONG COilTransDlg::OnGetSave(WPARAM ch, LPARAM mark)
{
	if(mark == 0)
		theSys.bSAVE = TRUE;
	else
		theSys.bSAVE = FALSE;
	return 0;
}


LONG COilTransDlg::OnNewTank(WPARAM ch, LPARAM mark)
{
	if(mark == 0)
		theSys.nTankNum ++;
	m_dlgCmp->SetTankNum(theSys.nTankNum);
	return 0;
}

LONG  COilTransDlg::OnNewTankOil(WPARAM ch, LPARAM mark)
{
	theSys.nTankOil[theSys.nTankNum]=(int)mark;
	return 0;
}

void COilTransDlg::Save()
{
	
    CString m_sTxt = "./sys.sys";
	CFile fFile(m_sTxt,CFile::modeCreate);
	fFile.Close();
	CFile nFile(m_sTxt,CFile::modeWrite);
	CString strT;

	CString strNew;
	strNew ="START:\n";
	strNew+="DBNAME=";
	strNew+=theSys.sDBName;
	strNew+=";";
	strNew+="\n";

	strNew+="TANKNUM=";
    strT.Format("%d",theSys.nTankNum);
    strNew+=strT;
	strNew+=";";
	strNew+="\n";
	for(int i=0;i<8;i++)
	{
		strNew+="TANKOIL=";
        strT.Format("%d",theSys.nTankOil[i]);
        strNew+=strT;
		strNew+=";";
		strNew+="\n";
	}
	strNew+="TANKCHECH=";
	if(theSys.bTankC)
       strNew+="TRUE";
	else
	   strNew+="FALSE";
	strNew+=";";
	strNew+="\n";

	strNew+="SETUPRUN=";
	if(theSys.bSR)
       strNew+="TRUE";
	else
	   strNew+="FALSE";
	strNew+=";";
	strNew+="\n";

	strNew+="END";
    nFile.Write(strNew,strNew.GetLength());
	nFile.Close();
}

void COilTransDlg::UpdateSR(BOOL b)
{
  theSys.bSR =b;
}

⌨️ 快捷键说明

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