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

📄 gastypemgrdlg.cpp

📁 这是一个加油站管理系统
💻 CPP
字号:
// GasTypeMgrDlg.cpp : implementation file
//

#include "stdafx.h"
#include "gasstation.h"
#include "GasTypeMgrDlg.h"
#include "GasTypeInfoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGasTypeMgrDlg dialog


CGasTypeMgrDlg::CGasTypeMgrDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGasTypeMgrDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGasTypeMgrDlg)
		// NOTE: the ClassWizard will add gasType initialization here
	//}}AFX_DATA_INIT
}


void CGasTypeMgrDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGasTypeMgrDlg)
	DDX_Control(pDX, IDC_LIST_GAS_TYPE, m_listGasType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGasTypeMgrDlg, CDialog)
	//{{AFX_MSG_MAP(CGasTypeMgrDlg)
	ON_BN_CLICKED(ID_ADD, OnAdd)
	ON_BN_CLICKED(ID_MODIFY, OnModify)
	ON_BN_CLICKED(ID_REMOVE, OnRemove)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_GAS_TYPE, OnDblclkListGasType)
	ON_WM_SHOWWINDOW()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGasTypeMgrDlg message handlers

BOOL CGasTypeMgrDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	//设置列表框控件
	const char *list_column[] = 
	{
		"编号",
		"名称",
		"价格",
		""
	};
	int i=0;
	while (*list_column[i] != 0x00) {
		m_listGasType.InsertColumn(i, list_column[i++], LVCFMT_LEFT, 100);
	}
	m_listGasType.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGasTypeMgrDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	int nNumber = -1;
	if (!ADOSQLServer.AutoAssignNumber("GasType", nNumber)) {
		MB_ERROR(" 无法添加油品信息,可能是数据库已满!");
		return ;
	}

	CGasTypeInfoDlg gasTypeInfoDlg;
	gasTypeInfoDlg.m_nNumber = nNumber;
	if (gasTypeInfoDlg.DoModal() == IDOK) {
		if (!ADOSQLServer.AddNewGasType(
			gasTypeInfoDlg.m_nNumber,
			gasTypeInfoDlg.m_strName,
			gasTypeInfoDlg.m_fPrice )) 
		{
			MB_ERROR("添加油品信息失败!");
		}
		RefreshList();
	}
}

void CGasTypeMgrDlg::OnModify() 
{
	// TODO: Add your control notification handler code here
	int nItem = m_listGasType.GetSelectionMark();
	if (nItem == -1)
		return ;

	CGasTypeInfoDlg gasTypeInfoDlg;
	CString strNumber = m_listGasType.GetItemText(nItem, 0);
	GET_INT(gasTypeInfoDlg.m_nNumber, strNumber);
	ADOSQLServer.GetGasType(
		gasTypeInfoDlg.m_nNumber, 
		gasTypeInfoDlg.m_strName,
		gasTypeInfoDlg.m_fPrice );
	if (gasTypeInfoDlg.DoModal() == IDOK) {
		if (!ADOSQLServer.ModifyGasType(
			gasTypeInfoDlg.m_nNumber,
			gasTypeInfoDlg.m_strName,
			gasTypeInfoDlg.m_fPrice )) 
		{
			MB_ERROR("修改油品信息失败!");
		}
		RefreshList();
	}
}

void CGasTypeMgrDlg::OnRemove() 
{
	// TODO: Add your control notification handler code here
	int nItem = m_listGasType.GetSelectionMark();
	if (nItem == -1)
		return ;

	int nNumber;
	CString strNumber = m_listGasType.GetItemText(nItem, 0);
	GET_INT(nNumber, strNumber);

	if (MB_QUERY("确定要删除此项么?") == IDYES) {
		if (!ADOSQLServer.RemoveGasType(
			nNumber)) 
		{
			MB_ERROR("删除油品信息失败!");
		}
		RefreshList();
	}
}

void CGasTypeMgrDlg::RefreshList()
{
	m_listGasType.DeleteAllItems();
	CStringArray strNumber, strName, strPrice;
	ADOSQLServer.GetGasTypes(strNumber, strName, strPrice);
	for (int i=0;i<strNumber.GetSize();i ++) {
		m_listGasType.InsertItem(i, strNumber.GetAt(i));
		m_listGasType.SetItemText(i, 1, strName.GetAt(i));
		m_listGasType.SetItemText(i, 2, strPrice.GetAt(i));
	}
}

void CGasTypeMgrDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	RefreshList();
}

void CGasTypeMgrDlg::OnDblclkListGasType(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	OnModify();
	
	*pResult = 0;
}

⌨️ 快捷键说明

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