123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- // lyfzBranchInfoCfgDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "lyfzBranchInfoCfg.h"
- #include "lyfzBranchInfoCfgDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // ClyfzBranchInfoCfgDlg 对话框
- ClyfzBranchInfoCfgDlg::ClyfzBranchInfoCfgDlg(CWnd* pParent /*=NULL*/)
- : CDialog(ClyfzBranchInfoCfgDlg::IDD, pParent)
- , m_strFilePath(_T(""))
- , m_nCurrSel(-1)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void ClyfzBranchInfoCfgDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_BranchInfo_LIST, m_BranchInfoList);
- }
- BEGIN_MESSAGE_MAP(ClyfzBranchInfoCfgDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_Edit_BUTTON, &ClyfzBranchInfoCfgDlg::OnBnClickedEditButton)
- ON_BN_CLICKED(IDC_Save_BUTTON, &ClyfzBranchInfoCfgDlg::OnBnClickedSaveButton)
- ON_NOTIFY(NM_CLICK, IDC_BranchInfo_LIST, &ClyfzBranchInfoCfgDlg::OnNMClickBranchinfoList)
- ON_NOTIFY(LVN_ITEMCHANGED, IDC_BranchInfo_LIST, &ClyfzBranchInfoCfgDlg::OnLvnItemchangedBranchinfoList)
- ON_BN_CLICKED(IDC_ADD_BUTTON, &ClyfzBranchInfoCfgDlg::OnBnClickedAddButton)
- ON_BN_CLICKED(IDC_DEL_BUTTON, &ClyfzBranchInfoCfgDlg::OnBnClickedDelButton)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // ClyfzBranchInfoCfgDlg 消息处理程序
- BOOL ClyfzBranchInfoCfgDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- BOOL bNameValid;
- CString strAboutMenu;
- bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
- ASSERT(bNameValid);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- m_strFilePath = _T("branchinfocfg.dat");
- ReadInfo(m_strFilePath, m_InfoArr);
- InitListCtrl(m_InfoArr);
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void ClyfzBranchInfoCfgDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void ClyfzBranchInfoCfgDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作区矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标
- //显示。
- HCURSOR ClyfzBranchInfoCfgDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void ClyfzBranchInfoCfgDlg::InitListCtrl(CArray<CStringArray, CStringArray>& infoArr)
- {
- int nIndex = 0;
- m_BranchInfoList.InsertColumn(nIndex, _T("分店域名"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 140);
- m_BranchInfoList.InsertColumn(nIndex, _T("店名"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 80);
- m_BranchInfoList.InsertColumn(nIndex, _T("IP地址"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 100);
- m_BranchInfoList.InsertColumn(nIndex, _T("是否总店"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 60);
- m_BranchInfoList.InsertColumn(nIndex, _T("企业名"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 80);
- m_BranchInfoList.InsertColumn(nIndex, _T("连接权限"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 140);
- m_BranchInfoList.InsertColumn(nIndex, _T("可访问界面"));
- m_BranchInfoList.SetColumnWidth(nIndex++, 120);
- m_BranchInfoList.SetExtendedStyle(m_BranchInfoList.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- for(int i=0; i<infoArr.GetSize(); i++)
- {
- int nidx = 1;
- int nRow = m_BranchInfoList.InsertItem(i, infoArr.ElementAt(i).ElementAt(0));
- m_BranchInfoList.SetItemText(nRow, nidx++, infoArr.ElementAt(i).ElementAt(1));
- m_BranchInfoList.SetItemText(nRow, nidx++, infoArr.ElementAt(i).ElementAt(2));
- m_BranchInfoList.SetItemText(nRow, nidx++, infoArr.ElementAt(i).ElementAt(3));
- m_BranchInfoList.SetItemText(nRow, nidx++, infoArr.ElementAt(i).ElementAt(4));
- m_BranchInfoList.SetItemText(nRow, nidx++, infoArr.ElementAt(i).ElementAt(5));
- m_BranchInfoList.SetItemText(nRow, nidx++, infoArr.ElementAt(i).ElementAt(6));
- }
- }
- void ClyfzBranchInfoCfgDlg::ReadInfo(LPCTSTR lpFile, CArray<CStringArray, CStringArray>& infoArr)
- {
- if(lpFile == NULL)
- return;
- CFile fp;
- if( PathFileExists(lpFile) == 0)
- return;
- fp.Open(lpFile, CFile::modeRead);
- DWORD leng = fp.GetLength();
- if (leng < sizeof(DWORD) * 2)
- {
- fp.Close();
- return;
- }
- DWORD flag = 0;
- //fp.Seek(-sizeof(DWORD), CFile::end);
- fp.Seek(-(int)sizeof(DWORD), CFile::end);
- fp.Read(&flag, sizeof(DWORD));
- if (flag != 889900)
- {
- fp.Close();
- return;
- }
- fp.SeekToBegin();
- DWORD arraysize;
- fp.Read(&arraysize, sizeof(DWORD));
- if (arraysize > 20)
- {
- fp.Close();
- return;
- }
- BYTE *pData = new BYTE[leng - sizeof(DWORD)];
- memset(pData, 0, leng - sizeof(DWORD));
- fp.Read(pData, leng - sizeof(DWORD));
- fp.Close();
- /*test
- for(int i=0; i<(leng - sizeof(DWORD)); i++)
- {
- if(pData[i] == '\n')
- MessageBox(_T("存在换行符"));
- }
- */
- CMemFile memfile;
- memfile.Attach(pData, leng - sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- infoArr.SetSize(arraysize, 1);
- for (int ii = 0; ii < infoArr.GetSize(); ii++)
- infoArr.ElementAt(ii).Serialize(ar);
- for(int i=0; i<infoArr.GetSize(); i++)
- {
- for(int j=0; j<infoArr.ElementAt(i).GetSize(); j++)
- {
- ::OutputDebugString(infoArr.ElementAt(i).ElementAt(j));
- ::OutputDebugString("\n");
- }
- }
- ar.Close();
- memfile.Detach();
- delete [] pData;
- }
- //编辑
- void ClyfzBranchInfoCfgDlg::OnBnClickedEditButton()
- {
- // TODO: 在此添加控件通知处理程序代码
- if(m_nCurrSel == -1)
- return;
- CString str = _T("");
- if( m_BranchInfoList.GetItemState(m_nCurrSel, LVIS_SELECTED) == LVIS_SELECTED)
- {
- int nidx = 1;
- ((CEdit*)GetDlgItem(IDC_Domain_EDIT))->GetWindowText(str);
- int nRow = m_BranchInfoList.InsertItem(m_nCurrSel, str);
- ((CEdit*)GetDlgItem(IDC_SHOPNAME_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- ((CEdit*)GetDlgItem(IDC_IPADDR_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- if(((CButton*)GetDlgItem(IDC_IsHQ_CHECK))->GetCheck() == 1)
- m_BranchInfoList.SetItemText(nRow, nidx++, _T("总店"));
- else
- m_BranchInfoList.SetItemText(nRow, nidx++, _T(""));
- ((CEdit*)GetDlgItem(IDC_Enterprise_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- ((CEdit*)GetDlgItem(IDC_ConectRight_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- ((CEdit*)GetDlgItem(IDC_Accessible_interfa_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- }
- m_nCurrSel = -1;
- }
- //保存
- void ClyfzBranchInfoCfgDlg::OnBnClickedSaveButton()
- {
- // TODO: 在此添加控件通知处理程序代码
- int nSize = m_BranchInfoList.GetItemCount();
- if(nSize == 0)
- {
- MessageBox(_T("没有添加数据,不用保存"));
- return;
- }
- CArray<CStringArray, CStringArray> infoArr;
- infoArr.SetSize(nSize, 1);
- infoArr.ElementAt(0).Add(_T("20150801095127452308.ly.com"));
- infoArr.ElementAt(0).Add(_T("儿童虚拟-1"));
- infoArr.ElementAt(0).Add(_T("192.168.220.128"));
- infoArr.ElementAt(0).Add(_T("总店"));
- infoArr.ElementAt(0).Add(_T("利亚方舟2"));
- infoArr.ElementAt(0).Add(_T("儿童虚拟-1"));
- infoArr.ElementAt(0).Add(_T("儿童本地-2"));
- infoArr.ElementAt(1).Add(_T("20151007104526521757.ly.com"));
- infoArr.ElementAt(1).Add(_T("儿童虚拟-2"));
- infoArr.ElementAt(1).Add(_T("192.168.1.115"));
- infoArr.ElementAt(1).Add(_T("总店"));
- infoArr.ElementAt(1).Add(_T("利亚方舟2"));
- infoArr.ElementAt(1).Add(_T("儿童虚拟-1"));
- infoArr.ElementAt(1).Add(_T("儿童本地-2"));
-
- // 创建内存文件;
- CMemFile MembranchInfo;
- CArchive ar(&MembranchInfo,CArchive::store);
- for ( int i = 0; i < nSize; i++)
- {
- // 将数组序列化到对象中;
- infoArr.ElementAt(i).Serialize(ar);
- }
- ar.Close();
- DWORD fLength = MembranchInfo.GetLength();
- PBYTE pData = MembranchInfo.Detach();
- CFile fb;
- if (fb.Open(m_strFilePath, CFile::modeCreate|CFile::modeWrite))
- {
- fb.Write(&nSize,sizeof(DWORD)); // 写入数组个数;
- fb.Write(pData,fLength); // 写入数组内容;
- DWORD dwFlag = 889900;
- fb.Write(&dwFlag,sizeof(DWORD)); // 写入结束标记;
- fb.Close();
- }
- MessageBox(_T("保存成功,需要重启服务端才能生效!"));
- }
- void ClyfzBranchInfoCfgDlg::OnNMClickBranchinfoList(NMHDR *pNMHDR, LRESULT *pResult)
- {
- LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
- // TODO: 在此添加控件通知处理程序代码
- m_nCurrSel = pNMItemActivate->iItem;
- if(m_nCurrSel != -1)
- {
- m_BranchInfoList.SetItemState(m_nCurrSel, LVIS_FOCUSED | LVIS_SELECTED,LVIS_FOCUSED | LVIS_SELECTED);
- ((CEdit*)GetDlgItem(IDC_Domain_EDIT))->SetWindowText(m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 0));
- ((CEdit*)GetDlgItem(IDC_SHOPNAME_EDIT))->SetWindowText(m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 1));
- ((CEdit*)GetDlgItem(IDC_IPADDR_EDIT))->SetWindowText(m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 2));
- CString strIsHQ = m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 3);
- if(strIsHQ == _T("总店"))
- ((CButton*)GetDlgItem(IDC_IsHQ_CHECK))->SetCheck(1);
- else
- ((CButton*)GetDlgItem(IDC_IsHQ_CHECK))->SetCheck(0);
- ((CEdit*)GetDlgItem(IDC_Enterprise_EDIT))->SetWindowText(m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 4));
- ((CEdit*)GetDlgItem(IDC_ConectRight_EDIT))->SetWindowText(m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 5));
- ((CEdit*)GetDlgItem(IDC_Accessible_interfa_EDIT))->SetWindowText(m_BranchInfoList.GetItemText(pNMItemActivate->iItem, 6));
- }
- *pResult = 0;
- }
- void ClyfzBranchInfoCfgDlg::OnLvnItemchangedBranchinfoList(NMHDR *pNMHDR, LRESULT *pResult)
- {
- LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
- // TODO: 在此添加控件通知处理程序代码
- *pResult = 0;
- }
- //添加
- void ClyfzBranchInfoCfgDlg::OnBnClickedAddButton()
- {
- // TODO: 在此添加控件通知处理程序代码
- int i = m_BranchInfoList.GetItemCount();
- int nidx = 1;
- CString str = _T("");
- ((CEdit*)GetDlgItem(IDC_Domain_EDIT))->GetWindowText(str);
- int nRow = m_BranchInfoList.InsertItem(i, str);
- ((CEdit*)GetDlgItem(IDC_SHOPNAME_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- ((CEdit*)GetDlgItem(IDC_IPADDR_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- if(((CButton*)GetDlgItem(IDC_IsHQ_CHECK))->GetCheck() == 1)
- m_BranchInfoList.SetItemText(nRow, nidx++, _T("总店"));
- else
- m_BranchInfoList.SetItemText(nRow, nidx++, _T(""));
- ((CEdit*)GetDlgItem(IDC_Enterprise_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- ((CEdit*)GetDlgItem(IDC_ConectRight_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- ((CEdit*)GetDlgItem(IDC_Accessible_interfa_EDIT))->GetWindowText(str);
- m_BranchInfoList.SetItemText(nRow, nidx++, str);
- }
- //删除
- void ClyfzBranchInfoCfgDlg::OnBnClickedDelButton()
- {
- // TODO: 在此添加控件通知处理程序代码
- if(m_nCurrSel != -1)
- {
- m_BranchInfoList.DeleteItem(m_nCurrSel);
- ((CEdit*)GetDlgItem(IDC_Domain_EDIT))->SetWindowText(_T(""));
- ((CEdit*)GetDlgItem(IDC_SHOPNAME_EDIT))->SetWindowText(_T(""));
- ((CEdit*)GetDlgItem(IDC_IPADDR_EDIT))->SetWindowText(_T(""));
- ((CButton*)GetDlgItem(IDC_IsHQ_CHECK))->SetCheck(0);
- ((CEdit*)GetDlgItem(IDC_Enterprise_EDIT))->SetWindowText(_T(""));
- ((CEdit*)GetDlgItem(IDC_ConectRight_EDIT))->SetWindowText(_T(""));
- ((CEdit*)GetDlgItem(IDC_Accessible_interfa_EDIT))->SetWindowText(_T(""));
- }
- }
|