📄 depotmgrdlg.cpp
字号:
// DepotMgrDlg.cpp : implementation file
//
#include "stdafx.h"
#include "gasstation.h"
#include "DepotMgrDlg.h"
#include "DepotInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDepotMgrDlg dialog
CDepotMgrDlg::CDepotMgrDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDepotMgrDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDepotMgrDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDepotMgrDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDepotMgrDlg)
DDX_Control(pDX, IDC_LIST_DEPOT, m_listDepot);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDepotMgrDlg, CDialog)
//{{AFX_MSG_MAP(CDepotMgrDlg)
ON_WM_SHOWWINDOW()
ON_BN_CLICKED(ID_ADD, OnAdd)
ON_BN_CLICKED(ID_MODIFY, OnModify)
ON_BN_CLICKED(ID_REMOVE, OnRemove)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_DEPOT, OnDblclkListDepot)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDepotMgrDlg message handlers
BOOL CDepotMgrDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//设置列表框控件
const char *list_column[] =
{
"编号",
"名称",
"位置",
"容量",
""
};
int i=0;
while (*list_column[i] != 0x00) {
m_listDepot.InsertColumn(i, list_column[i++], LVCFMT_LEFT, 100);
}
m_listDepot.SetExtendedStyle(LVS_EX_FULLROWSELECT);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDepotMgrDlg::OnAdd()
{
// TODO: Add your control notification handler code here
int nNumber = -1;
if (!ADOSQLServer.AutoAssignNumber("Depot", nNumber)) {
MB_ERROR(" 无法添加油库信息,可能是数据库已满!");
return ;
}
CDepotInfoDlg depotInfoDlg;
depotInfoDlg.m_nNumber = nNumber;
if (depotInfoDlg.DoModal() == IDOK) {
if (!ADOSQLServer.AddNewDepot(
depotInfoDlg.m_nNumber,
depotInfoDlg.m_strName,
depotInfoDlg.m_strLocation,
depotInfoDlg.m_fCapacity ))
{
MB_ERROR("添加油库信息失败!");
}
RefreshList();
}
}
void CDepotMgrDlg::OnModify()
{
// TODO: Add your control notification handler code here
int nItem = m_listDepot.GetSelectionMark();
if (nItem == -1)
return ;
CDepotInfoDlg depotInfoDlg;
CString strNumber = m_listDepot.GetItemText(nItem, 0);
GET_INT(depotInfoDlg.m_nNumber, strNumber);
ADOSQLServer.GetDepot(
depotInfoDlg.m_nNumber,
depotInfoDlg.m_strName,
depotInfoDlg.m_strLocation,
depotInfoDlg.m_fCapacity );
if (depotInfoDlg.DoModal() == IDOK) {
if (!ADOSQLServer.ModifyDepot(
depotInfoDlg.m_nNumber,
depotInfoDlg.m_strName,
depotInfoDlg.m_strLocation,
depotInfoDlg.m_fCapacity ))
{
MB_ERROR("修改油库信息失败!");
}
RefreshList();
}
}
void CDepotMgrDlg::OnRemove()
{
// TODO: Add your control notification handler code here
int nItem = m_listDepot.GetSelectionMark();
if (nItem == -1)
return ;
int nNumber;
CString strNumber = m_listDepot.GetItemText(nItem, 0);
GET_INT(nNumber, strNumber);
if (MB_QUERY("确定要删除此项么?") == IDYES) {
if (!ADOSQLServer.RemoveDepot(
nNumber))
{
MB_ERROR("删除油库信息失败!");
}
RefreshList();
}
}
void CDepotMgrDlg::RefreshList()
{
m_listDepot.DeleteAllItems();
CStringArray strNumber, strName, strLocation, strCapacity;
ADOSQLServer.GetDepots(strNumber, strName, strLocation, strCapacity);
for (int i=0;i<strNumber.GetSize();i ++) {
m_listDepot.InsertItem(i, strNumber.GetAt(i));
m_listDepot.SetItemText(i, 1, strName.GetAt(i));
m_listDepot.SetItemText(i, 2, strLocation.GetAt(i));
m_listDepot.SetItemText(i, 3, strCapacity.GetAt(i));
}
}
void CDepotMgrDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
RefreshList();
}
void CDepotMgrDlg::OnDblclkListDepot(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 + -