📄 unitdlg.cpp
字号:
// UnitDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SM.h"
#include "UnitDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUnitDlg dialog
//##ModelId=40A481F001E4
CUnitDlg::CUnitDlg(Unit * data, CWnd* pParent /*=NULL*/)
: CDialog(CUnitDlg::IDD, pParent), Table(&theDatabase)
{
//{{AFX_DATA_INIT(CUnitDlg)
m_Title = _T("");
m_ID = _T("");
//}}AFX_DATA_INIT
pData = data;
iMode = 1;
// m_SuperiorID = ID;
m_ID.Format("%d", pData->ID);
m_Title = pData->Title;
m_SuperiorID = pData->SuperiorID;
Table.Open(_T("Unit"));
RS.Open(&Table);
}
//##ModelId=40A481F00222
void CUnitDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUnitDlg)
DDX_Control(pDX, IDC_TREE1, m_Tree);
DDX_Text(pDX, IDC_EDIT_NAME, m_Title);
DDX_Text(pDX, IDC_ID, m_ID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUnitDlg, CDialog)
//{{AFX_MSG_MAP(CUnitDlg)
ON_WM_CANCELMODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUnitDlg message handlers
//##ModelId=40A481F001D9
bool CUnitDlg::StoreData()
{
UpdateData(true);
//pData->ID = atol(m_ID);
pData->Title = m_Title;
pData->SuperiorID = pTree->GetSelcetUnit().ID;
if(m_ID=="1")
pData->SuperiorID = -1;
if(pData->ID == pData->SuperiorID)
{
AfxMessageBox("上级单位不可以为本单位相同!!");
return false;
}
if(pTree->IsChild(pData->ID, pData->SuperiorID))
{
AfxMessageBox("上级单位不可以为该单位的子单位!!");
return false;
}
if(iMode)
{
pData->Update(&RS);
}
else
{
pData->AddNew(&RS);
}
return true;
}
//##ModelId=40A481F001BA
CUnitDlg::CUnitDlg(int ID, CWnd *pParent)//新增模式
: CDialog(CUnitDlg::IDD, pParent), Table(&theDatabase)
{
iMode = 0;
m_SuperiorID = ID;
pData = new Unit();
Table.Open(_T("Unit"));
m_ID = _T("0");
m_Title = _T("");
RS.Open(&Table);
}
//##ModelId=40A481F00213
BOOL CUnitDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if(!iMode)//新增模式 call new
delete pData;
delete pTree;
RS.Close();
Table.Close();
return CDialog::DestroyWindow();
}
//##ModelId=40A481F00232
void CUnitDlg::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
// TODO: Add your specialized code here and/or call the base class
CDialog::CalcWindowRect(lpClientRect, nAdjustType);
}
//##ModelId=40A481F00243
BOOL CUnitDlg::OnInitDialog()
{
CDialog::OnInitDialog();
pTree = new UnitTree(&m_Tree);
pTree->Load();
if(m_SuperiorID==-1)
pTree->SetSelectUnit(1);
else
pTree->SetSelectUnit(m_SuperiorID);
UpdateData(false);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//##ModelId=40A481F00245
void CUnitDlg::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
//##ModelId=40A481F00252
void CUnitDlg::OnOK()
{
// TODO: Add extra validation here
StoreData();
// CDialog::OnOK();
CDialog::EndDialog(pData->ID);
}
//##ModelId=40A481F00254
void CUnitDlg::OnCancel()
{
// TODO: Add extra cleanup here
// CDialog::OnCancel();
CDialog::EndDialog(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -