AddDevice.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // AddDevice.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Editor.h"
  5. #include "AddDevice.h"
  6. #include "IniReader.h"
  7. // CAddDevice 对话框
  8. IMPLEMENT_DYNAMIC(CAddDevice, CDialog)
  9. CAddDevice::CAddDevice(CWnd* pParent /*=NULL*/)
  10. : CDialog(CAddDevice::IDD, pParent)
  11. , m_strDeviceName(_T(""))
  12. , m_strDeviceID(_T(""))
  13. , m_strResponseTime(_T(""))
  14. , m_strLineType(_T(""))
  15. , m_strComType(_T(""))
  16. , m_strPindef(_T(""))
  17. , m_strFactory(_T(""))
  18. , m_strClassType(_T(""))
  19. , m_strDeviceName2(_T(""))
  20. , m_strModelNum(_T(""))
  21. , m_strSeries(_T(""))
  22. , m_strProtocol(_T(""))
  23. {
  24. }
  25. CAddDevice::~CAddDevice()
  26. {
  27. }
  28. void CAddDevice::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. DDX_Text(pDX, ET_DEVICENAME, m_strDeviceName);
  32. DDX_Text(pDX, ET_DEVICEID, m_strDeviceID);
  33. DDX_Control(pDX, CB_RATE, m_cobRate);
  34. DDX_Control(pDX, CB_DATABIT, m_cobDatabit);
  35. DDX_Control(pDX, CB_STOPBIT, m_cobStopbit);
  36. DDX_Control(pDX, CB_PARITY, m_cobParity);
  37. DDX_Text(pDX, ET_RESPONSETIME, m_strResponseTime);
  38. DDX_Text(pDX, ET_FREQUENCY, m_strFrequency);
  39. DDX_Text(pDX, ET_LINETYPE, m_strLineType);
  40. DDX_Text(pDX, ET_COMTYPE, m_strComType);
  41. DDX_Text(pDX, ET_PINDEF, m_strPindef);
  42. //DDX_Control(pDX, CB_STORERECV, m_cobStore);
  43. DDX_Text(pDX, ET_FACTORY, m_strFactory);
  44. DDX_Text(pDX, ET_CLASSTYPE, m_strClassType);
  45. DDX_Text(pDX, ET_NAME, m_strDeviceName2);
  46. DDX_Text(pDX, ET_MODELNUM, m_strModelNum);
  47. DDX_Text(pDX, ET_SERIES, m_strSeries);
  48. DDX_Text(pDX, ET_PROTOCOL, m_strProtocol);
  49. }
  50. BEGIN_MESSAGE_MAP(CAddDevice, CDialog)
  51. ON_BN_CLICKED(IDOK, &CAddDevice::OnBnClickedOk)
  52. ON_BN_CLICKED(Btn_Exist, &CAddDevice::OnBnClickedExist)
  53. END_MESSAGE_MAP()
  54. // CAddDevice 消息处理程序
  55. BOOL CAddDevice::OnInitDialog()
  56. {
  57. CDialog::OnInitDialog();
  58. // TODO: 在此添加额外的初始化
  59. //////////////////
  60. CString strPath;
  61. TCHAR szFull[_MAX_PATH];
  62. TCHAR szDrive[_MAX_DRIVE];
  63. TCHAR szDir[_MAX_DIR];
  64. ::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
  65. _tsplitpath(szFull, szDrive, szDir, NULL, NULL);
  66. _tcscpy(szFull, szDrive);
  67. _tcscat(szFull, szDir);
  68. strPath = CString(szFull);
  69. CString strIni;
  70. strIni.Format("%s\\config.ini",strPath);
  71. CIniReader IniReader(strIni);
  72. m_strDepotPath = IniReader.GetKeyValueText("name","DeviceLibrary");
  73. m_strRutDepotPath = IniReader.GetKeyValueText("name","RunUnitLibrary");
  74. UpdateData(FALSE);
  75. return TRUE; // return TRUE unless you set the focus to a control
  76. // 异常: OCX 属性页应返回 FALSE
  77. }
  78. // 初始化数据视图界面 [4/3/2013 Zero.t]
  79. void CAddDevice::InitDataView()
  80. {
  81. }
  82. void CAddDevice::OnBnClickedOk()
  83. {
  84. UpdateData();
  85. CObjectdepot tObjectdepot;
  86. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  87. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  88. STDepotPhysical tDevicePhysical;
  89. STDeviceDocument tDeviceDocument;
  90. tDevicePhysical.iRate = GetDlgItemInt(CB_RATE);
  91. tDevicePhysical.iDBit = GetDlgItemInt(CB_DATABIT);
  92. tDevicePhysical.iSBit = m_cobStopbit.GetCurSel();
  93. tDevicePhysical.iPaty = m_cobParity.GetCurSel();
  94. tDevicePhysical.iRsTm = GetDlgItemInt(ET_RESPONSETIME);
  95. tDevicePhysical.iIntl = GetDlgItemInt(ET_FREQUENCY);
  96. sprintf(tDevicePhysical.szLineType,"%s",m_strLineType);
  97. sprintf(tDevicePhysical.szComType,"%s",m_strComType);
  98. sprintf(tDevicePhysical.szPinDef,"%s",m_strLineType);
  99. sprintf(tDeviceDocument.szdeviceClass,"%s",m_strSeries);
  100. sprintf(tDeviceDocument.szdeviceName,"%s",m_strDeviceName2);
  101. sprintf(tDeviceDocument.szdeviceType,"%s",m_strClassType);
  102. sprintf(tDeviceDocument.szFactory,"%s",m_strFactory);
  103. sprintf(tDeviceDocument.szProtocol,"%s",m_strProtocol);
  104. sprintf(tDeviceDocument.szUnitType,"%s",m_strModelNum);
  105. tObjectdepot.InsertElementNode(m_strDeviceName,m_strDeviceID,tDevicePhysical,tDeviceDocument);
  106. OnOK();
  107. }
  108. void CAddDevice::OnBnClickedExist()
  109. {
  110. // TODO: 在此添加控件通知处理程序代码
  111. CDialog::OnCancel();
  112. }