📄 seattypesetview.cpp
字号:
// SeattypesetView.cpp : implementation file
//
#include "stdafx.h"
#include "StationManage.h"
#include "SeattypesetView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSeattypesetView
IMPLEMENT_DYNCREATE(CSeattypesetView, CRecordView)
CSeattypesetView::CSeattypesetView()
: CRecordView(CSeattypesetView::IDD)
{
//{{AFX_DATA_INIT(CSeattypesetView)
m_pSet = NULL;
m_seattype = _T("");
m_seattypeid = 0;
//}}AFX_DATA_INIT
curiItem = 0;
operation = 0;
}
CSeattypesetView::~CSeattypesetView()
{
if (!((CStationManageApp*)AfxGetApp())->m_seattypesettingcontrol)
{
((CStationManageApp*)AfxGetApp())->m_seattypesetting=0;
}
if (m_pSet)
delete m_pSet;
}
void CSeattypesetView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSeattypesetView)
DDX_Control(pDX, IDC_SEATTYPEID, m_seattypeidcontrol);
DDX_Control(pDX, IDC_SEATTYPE, m_seattypecontrol);
DDX_Control(pDX, IDC_SAVE, m_save);
DDX_Control(pDX, IDC_RETURN, m_return);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_DELETE, m_delete);
DDX_Control(pDX, IDC_CHANGE, m_change);
DDX_Control(pDX, IDC_ADD, m_add);
DDX_Text(pDX, IDC_SEATTYPE, m_seattype);
DDX_Text(pDX, IDC_SEATTYPEID, m_seattypeid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSeattypesetView, CRecordView)
//{{AFX_MSG_MAP(CSeattypesetView)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_CHANGE, OnChange)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_RETURN, OnReturn)
ON_BN_CLICKED(IDC_REFURBISH, OnRefurbish)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSeattypesetView diagnostics
#ifdef _DEBUG
void CSeattypesetView::AssertValid() const
{
CRecordView::AssertValid();
}
void CSeattypesetView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSeattypesetView message handlers
CRecordset* CSeattypesetView::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet;
m_pSet = new CSeattypeSet(NULL);
m_pSet->Open();
return m_pSet;
}
CSeattypeSet* CSeattypesetView::GetRecordset()
{
CSeattypeSet* pData = (CSeattypeSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CSeattypeSet)));
return pData;
}
void CSeattypesetView::OnInitialUpdate()
{
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
GetDocument()->SetTitle("座位类型设置");
GetParent()->SetWindowText("座位类型设置");
EndWaitCursor();
RECT rectlist;
m_list.GetWindowRect(&rectlist);
int listwidth=rectlist.right-rectlist.left;
DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
m_list.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
m_list.InsertColumn(0,"类型ID",LVCFMT_LEFT,listwidth/2-10);
m_list.InsertColumn(1,"座位类型",LVCFMT_LEFT,listwidth/2-10);
Showlist();
curiItem = 0;
operation = 0;
Getvalue();
EnableView(true);
UpdateData(FALSE);
}
void CSeattypesetView::Showlist()
{
if (!m_pSet->IsOpen())
m_pSet->Open();
m_list.DeleteAllItems();
m_pSet->MoveFirst();
while(!m_pSet->IsEOF())
m_pSet->MoveNext();
int cout=m_pSet->GetRecordCount();
m_pSet->MoveFirst();
while(!m_pSet->IsEOF())
{
CString str;
str.Format("%d",m_pSet->m_type_id);
int nCount=m_list.GetItemCount();
LV_ITEM lv_item;
lv_item.mask=LVIF_TEXT;
lv_item.iItem=nCount;
lv_item.iSubItem=0;
lv_item.pszText=str.GetBuffer(str.GetLength());
m_list.InsertItem(&lv_item);
m_list.SetItemText(nCount,0,str);
m_pSet->m_type.TrimRight();
m_list.SetItemText(nCount,1,m_pSet->m_type);
m_pSet->MoveNext();
}
}
void CSeattypesetView::Getvalue()
{
m_seattypeid = atoi(m_list.GetItemText(curiItem,0));
m_seattype = m_list.GetItemText(curiItem,1);
}
void CSeattypesetView::EnableView(bool b)
{
m_seattypeidcontrol.SetReadOnly(b);
m_seattypecontrol.SetReadOnly(b);
m_add.EnableWindow(b);
m_delete.EnableWindow(b);
m_change.EnableWindow(b);
m_save.EnableWindow(!b);
m_return.EnableWindow(!b);
}
void CSeattypesetView::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
curiItem = pNMListView->iItem;
if(curiItem != -1)
{
EnableView(true);
Getvalue();
}
UpdateData(FALSE);
*pResult = 0;
}
void CSeattypesetView::OnAdd()
{
// TODO: Add your control notification handler code here
EnableView(false);
operation = 1;
m_seattypeid=0;
m_seattype.Empty();
curiItem=m_list.GetItemCount();
UpdateData(FALSE);
}
void CSeattypesetView::OnDelete()
{
// TODO: Add your control notification handler code here
if (curiItem==m_list.GetItemCount())
{
MessageBox("请选择您要删除的行!","警告",MB_OK|MB_ICONEXCLAMATION);
return;
}
if (IDOK==MessageBox("确认删除?","提示",MB_OKCANCEL|MB_ICONQUESTION))
{
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
m_pSet->MoveFirst();
int i=curiItem;
while (i>0)
{
m_pSet->MoveNext();
i--;
}
m_pSet->Delete();
m_pSet->Requery();
m_list.DeleteItem(curiItem);
curiItem=0;
Getvalue();
MessageBox("路线已经删除!","删除成功",MB_OK|MB_ICONINFORMATION);
UpdateData(FALSE);
}
}
void CSeattypesetView::OnChange()
{
// TODO: Add your control notification handler code here
if (curiItem==m_list.GetItemCount())
{
MessageBox("请选择您要修改的行!","警告",MB_OK|MB_ICONEXCLAMATION);
return;
}
EnableView(false);
operation = 2;
}
void CSeattypesetView::OnSave()
{
// TODO: Add your control notification handler code here
UpdateData();
if (operation==0)
{
return;
}
if (operation==1) //增加数据
{
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
m_pSet->AddNew(); //在表的末尾添加新记录
m_pSet->m_type_id=m_seattypeid;
m_pSet->m_type=m_seattype;
m_pSet->Update();
m_pSet->Requery();
Showlist();
m_pSet->MoveFirst();
while (!m_pSet->IsEOF())
{
m_pSet->MoveNext();
}
curiItem=m_pSet->GetRecordCount()-1;
EnableView(true);
operation=0;
MessageBox("增加成功!","增加成功",MB_OK|MB_ICONINFORMATION);
return;
}
if (operation==2)
{
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
m_pSet->MoveFirst();
int i=curiItem;
while (i>0)
{
m_pSet->MoveNext();
i--;
}
m_pSet->Edit();
m_pSet->m_type_id=m_seattypeid;
m_pSet->m_type=m_seattype;
m_pSet->Update();
m_pSet->Requery();
Showlist();
UpdateData(FALSE);
EnableView(true);
MessageBox("修改成功!","修改成功",MB_OK|MB_ICONINFORMATION);
operation=0;
return;
}
}
void CSeattypesetView::OnReturn()
{
// TODO: Add your control notification handler code here
EnableView(true);
Getvalue();
UpdateData(FALSE);
}
void CSeattypesetView::OnRefurbish()
{
// TODO: Add your control notification handler code here
EnableView(true);
curiItem = 0;
Getvalue();
operation = 0;
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -