// CPageReport.cpp: 实现文件
|
//
|
|
#include "stdafx.h"
|
#include "Servo.h"
|
#include "CPageReport.h"
|
#include "afxdialogex.h"
|
|
|
// CPageReport 对话框
|
|
IMPLEMENT_DYNAMIC(CPageReport, CHMPropertyPage)
|
|
CPageReport::CPageReport(CWnd* pParent /*=nullptr*/)
|
: CHMPropertyPage(IDD_PAGE_REPORT, pParent)
|
{
|
|
}
|
|
CPageReport::~CPageReport()
|
{
|
}
|
|
void CPageReport::DoDataExchange(CDataExchange* pDX)
|
{
|
CHMPropertyPage::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_LIST1, m_listCtrl);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CPageReport, CHMPropertyPage)
|
ON_WM_CTLCOLOR()
|
ON_WM_DESTROY()
|
ON_WM_SIZE()
|
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CPageReport::OnLvnItemchangedList1)
|
END_MESSAGE_MAP()
|
|
|
// CPageReport 消息处理程序
|
|
|
BOOL CPageReport::OnInitDialog()
|
{
|
CHMPropertyPage::OnInitDialog();
|
|
|
// 读出列宽
|
CString strIniFile, strItem;
|
strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
|
int width[8] = { 0, 218, 180, 180, 180, 180, 180, 180 };
|
for (int i = 0; i < 8; i++) {
|
strItem.Format(_T("Col_%d_Width"), i);
|
width[i] = GetPrivateProfileInt("PageReportListCtrl", strItem, width[i], strIniFile);
|
}
|
|
|
// 报表控件
|
DWORD dwStyle = m_listCtrl.GetExtendedStyle();
|
dwStyle |= LVS_EX_FULLROWSELECT;
|
dwStyle |= LVS_EX_GRIDLINES;
|
m_listCtrl.SetExtendedStyle(dwStyle);
|
|
HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
|
ListView_SetImageList(m_listCtrl.GetSafeHwnd(), imageList, LVSIL_SMALL);
|
m_listCtrl.InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
|
m_listCtrl.InsertColumn(1, _T("RPT ID"), LVCFMT_LEFT, width[1]);
|
m_listCtrl.InsertColumn(2, _T("VID"), LVCFMT_LEFT, width[2]);
|
loadReports();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
|
HBRUSH CPageReport::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CHMPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
// TODO: 在此更改 DC 的任何特性
|
|
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
|
return hbr;
|
}
|
|
|
void CPageReport::OnDestroy()
|
{
|
CHMPropertyPage::OnDestroy();
|
|
// 保存列宽
|
CString strIniFile, strItem, strTemp;
|
strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
|
CHeaderCtrl* pHeader = m_listCtrl.GetHeaderCtrl();
|
for (int i = 0; i < pHeader->GetItemCount(); i++) {
|
RECT rect;
|
pHeader->GetItemRect(i, &rect);
|
strItem.Format(_T("Col_%d_Width"), i);
|
strTemp.Format(_T("%d"), rect.right - rect.left);
|
WritePrivateProfileString("PageReportListCtrl", strItem, strTemp, strIniFile);
|
}
|
}
|
|
|
void CPageReport::OnSize(UINT nType, int cx, int cy)
|
{
|
CHMPropertyPage::OnSize(nType, cx, cy);
|
if (GetDlgItem(IDC_LIST1) == nullptr) return;
|
|
CRect rcClient, rcItem;
|
GetClientRect(&rcClient);
|
m_listCtrl.MoveWindow(12, 12, rcClient.Width() - 24, rcClient.Height() - 24);
|
}
|
|
void CPageReport::loadReports()
|
{
|
auto& reports = theApp.m_model.m_hsmsPassive.getReports();
|
for (auto item : reports) {
|
int index = m_listCtrl.InsertItem(m_listCtrl.GetItemCount(), _T(""));
|
m_listCtrl.SetItemData(index, (DWORD_PTR)item);
|
m_listCtrl.SetItemText(index, 1, std::to_string(item->getReportId()).c_str());
|
m_listCtrl.SetItemText(index, 2, item->getVariablesIdsText().c_str());
|
}
|
}
|
|
void CPageReport::OnCreateBtns()
|
{
|
const int BTN_W = 80;
|
const int BTN_H = 28;
|
CreateBtn(_T("新增"), BTN_W, BTN_H, 2001);
|
CreateBtn(_T("删除"), BTN_W, BTN_H, 2002)->EnableWindow(FALSE);
|
CreateBtn(_T("编辑"), BTN_W, BTN_H, 2003)->EnableWindow(FALSE);
|
}
|
|
void CPageReport::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
|
{
|
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
|
int nSelCount = m_listCtrl.GetSelectedCount();
|
|
if (CButton* pDel = GetBtnByName("删除")) {
|
pDel->EnableWindow(nSelCount > 0);
|
}
|
if (CButton* pEdit = GetBtnByName("编辑")) {
|
pEdit->EnableWindow(nSelCount > 0);
|
}
|
|
*pResult = 0;
|
}
|
|
void CPageReport::OnClickedBtn(const char* btnName)
|
{
|
ASSERT(btnName);
|
if (_strcmpi(btnName, "删除") == 0) {
|
POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
|
if (pos == nullptr) return;
|
int nItem = m_listCtrl.GetNextSelectedItem(pos);
|
auto pRpt = reinterpret_cast<SERVO::CReport*>(m_listCtrl.GetItemData(nItem));
|
if (pRpt == nullptr) return;
|
|
int rc = UX_CanExecute(L"delReports");
|
if (rc != 1) {
|
AfxMessageBox("操作权限不足,请联系管理人员!");
|
return;
|
}
|
|
int ret = theApp.m_model.m_hsmsPassive.deleteReport((int)pRpt->getReportId());
|
if (ret == 0) {
|
UX_RecordAction(L"delReports");
|
m_listCtrl.DeleteAllItems();
|
loadReports();
|
if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE);
|
if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE);
|
}
|
else {
|
AfxMessageBox(_T("删除报告失败"));
|
}
|
}
|
}
|