Dlg_ZuTaiAdd.cpp 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  1. // Dlg_ZuTaiAdd.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Dlg_ZuTaiAdd.h"
  5. #include ".\dlg_zutaiadd.h"
  6. #include "MainFrm.h"
  7. #include "resource.h"
  8. #include "Shlwapi.h"
  9. #include "Network.h"
  10. #include "DrawObj.h"
  11. #include "SysLib.h"
  12. #include "IniFile.h"
  13. // CDlg_ZuTaiAdd 对话框
  14. typedef struct
  15. {
  16. CString sDevUid;//设备UID
  17. CString sVarName;//变量名称
  18. CString sVarDesc;//变量描述
  19. int nVarTypeID;//变量类型ID
  20. int nDataLen;//变量数据长度
  21. int nRegNum;//请求寄存器个数
  22. int nFuncCode;//功能码id
  23. int nRegStartAddr;//寄存器起始地址
  24. CString sRs232Cmd;// 串口232请求命令
  25. CString sRs232Type;// 串口232请求类型
  26. int nRs232Index;//索引
  27. int nIdentifyTime;//辨识时间
  28. int nRedetectTime;//重新检测等待时间
  29. BOOL bIsNormalAlarm;//恢复正常是否触发远程报警
  30. CString sSnmpOid;//snmp对象oid
  31. CString sFields;//SNMP域
  32. int nMaxValues;//最大值
  33. int nMinValues;//最小值
  34. int nMaxConvtRate;//最大转换比率
  35. int nMinConvtRate;//最小转换比率
  36. int nLowerLimit;//下限
  37. int nUpperLimit;//上限
  38. int nNormalState;//正常状态
  39. int nRearm;//校正值
  40. int nOffset;//偏移值
  41. CString sUnit;//单位
  42. int nCollectFreq;//采集频率
  43. float fCoef;//转换系数
  44. int nWaringLevel;//告警级别
  45. int nPurview;//读写权限
  46. BOOL bIsSave;//是否保存数值
  47. BOOL bRealtimeFlag;//是否实时采集数据
  48. BOOL bRecCurve;//是否记录实时曲线
  49. BOOL bIsDDE;//是否允许DDE访问
  50. int nRegChildID;//寄存器子ID ????????????????????????????
  51. int nVarItemID;//位信息ID
  52. int nDevID;//设备类型ID ??????????????????????
  53. CString sOnDesc;//开的描述
  54. CString sOffDesc;//关的描述
  55. CString sSetValue;//设定值
  56. int nStartBit;//变量起始BIT位
  57. int nEndBit;//变量终止BIT位
  58. CString sReserved1;//预留1_Str
  59. CString sReserved2;//预留2_Str
  60. CString sReserved3;//预留3_Str
  61. CString sReserved4;//预留4_Str
  62. CString sReserved5;//预留5_Str
  63. CString sReserved6;//预留6_Str
  64. CString sReserved7;//预留7_Str
  65. CString sReserved8;//预留8_Str
  66. CString sReserved9;//预留9_Str
  67. CString sReserved10;//预留10_Str
  68. int nReserved1;//预留1_Int
  69. int nReserved2;//预留2_Int
  70. int nReserved3;//预留3_Int
  71. int nReserved4;//预留4_Int
  72. int nReserved5;//预留5_Int
  73. int nReserved6;//预留6_Int
  74. int nReserved7;//预留7_Int
  75. int nReserved8;//预留8_Int
  76. int nReserved9;//预留9_Int
  77. int nReserved10;//预留10_Int
  78. BOOL bReserved1;//预留1_Bool
  79. BOOL bReserved2;//预留2_Bool
  80. BOOL bReserved3;//预留3_Bool
  81. BOOL bReserved4;//预留4_Bool
  82. BOOL bReserved5;//预留5_Bool
  83. BOOL bReserved6;//预留6_Bool
  84. BOOL bReserved7;//预留7_Bool
  85. BOOL bReserved8;//预留8_Bool
  86. BOOL bReserved9;//预留9_Bool
  87. BOOL bReserved10;//预留10_Bool
  88. int nVarStatusNum;//变量状态个数
  89. int nVarStatusID;//变量状态ID
  90. CString sVarStatusDesc;//变量状态描述
  91. //下面是临时的
  92. CString sVarNameTemp;//变量名称
  93. CString sVarDescTemp;//变量描述
  94. }VARLIST;//变量列表
  95. VARLIST g_VarList[1000];
  96. typedef struct
  97. {
  98. CString sMainType;//主类
  99. CString sSlaveType;//次类
  100. CString sDevBrand;//设备品牌
  101. CString sDevVersion;//设备型号
  102. //Parameters
  103. CString sDevUid;//设备UID
  104. CString sVarFileName;//变量文件名称
  105. CString sPicFileName;//界面文件名称
  106. int nCommunicationType;//通信类型
  107. int nCommunicationTreaty;//通信协议
  108. CString sDllName;//驱动名称
  109. CString sIniName;//配置文件
  110. int nBaudRate;//波特率
  111. int nDataBit;//数据位
  112. int nStopBit;//停止位
  113. int nCheckBit;//校验位
  114. int nNetPort;//通讯端口
  115. }DEV_VAR_PIC;//设备列表
  116. DEV_VAR_PIC g_DVP[1000];
  117. void g_FunInitVarList()
  118. {
  119. for( int i=0;i<1000;i++ )
  120. {
  121. if( g_VarList[i].sVarName=="" )
  122. break;
  123. g_VarList[i].sVarName = "";
  124. }
  125. }
  126. IMPLEMENT_DYNAMIC(CDlg_ZuTaiAdd, CDialog)
  127. CDlg_ZuTaiAdd::CDlg_ZuTaiAdd(CWnd* pParent /*=NULL*/)
  128. : CDialog(CDlg_ZuTaiAdd::IDD, pParent)
  129. , m_nDevAddr(1)
  130. , m_nCommPort(1)
  131. , m_nEdit_DevNumber(1)
  132. , m_nNetIP(0)
  133. , m_nNetPort(0)
  134. {
  135. m_nChooseItem = -1;
  136. m_bIsJubgeHaveBit = false;
  137. m_bHaveBit = false;
  138. m_bChangeVarToPic = false;
  139. m_bIsExistExcel = false;
  140. m_bReadResourceFinish = false;
  141. m_bIsUserZuTai = false;
  142. m_sFilePath = "C:\\WINDOWS\\system32\\drivers\\lastday.sys";
  143. }
  144. CDlg_ZuTaiAdd::~CDlg_ZuTaiAdd()
  145. {
  146. if( m_bIsUserZuTai )
  147. {
  148. CIniFile IniFile;
  149. IniFile.SetPath( m_sFilePath );
  150. int n=0;
  151. IniFile.GetVarInt(_T("ZT"),_T("USERTIME"),n );
  152. IniFile.SetVarInt(_T("ZT"),_T("USERTIME"),n+1 );
  153. }
  154. }
  155. void CDlg_ZuTaiAdd::DoDataExchange(CDataExchange* pDX)
  156. {
  157. CDialog::DoDataExchange(pDX);
  158. DDX_Text(pDX, IDC_EDT_DEV_ADDR, m_nDevAddr);
  159. DDX_Text(pDX, IDC_EDT_COMM_PORT, m_nCommPort);
  160. DDX_Text(pDX, IDC_EDT_DEVNUMBER, m_nEdit_DevNumber);
  161. DDX_IPAddress(pDX, IDC_IPADDR_DEV, m_nNetIP);
  162. DDX_Text(pDX, IDC_EDT_NET_PORT, m_nNetPort);
  163. DDX_Control(pDX, IDC_TREE_DEVICE_FOLDER, m_ctrlDevFolder);
  164. }
  165. BEGIN_MESSAGE_MAP(CDlg_ZuTaiAdd, CDialog)
  166. ON_WM_CTLCOLOR()
  167. ON_WM_ERASEBKGND()
  168. ON_BN_CLICKED(IDC_BTN_TEST, OnBnClickedBtnTest)
  169. ON_BN_CLICKED(IDC_BTN_CREAT, OnBnClickedBtnCreate)
  170. ON_BN_CLICKED(IDC_BTN_QUIT, OnBnClickedBtnQuit)
  171. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_DEVICE_FOLDER, OnTvnSelchangedTreeDeviceFolder)
  172. ON_WM_CLOSE()
  173. END_MESSAGE_MAP()
  174. // CDlg_ZuTaiAdd 消息处理程序
  175. BOOL CDlg_ZuTaiAdd::OnInitDialog()
  176. {
  177. CDialog::OnInitDialog();
  178. // TODO: 在此添加额外的初始化
  179. if( !m_imagelistTree )
  180. {
  181. m_imagelistTree.Create(IDB_ADD_DEVICE, 16, 16, RGB(255,255,255));
  182. }
  183. m_ctrlDevFolder.SetImageList(&m_imagelistTree, TVSIL_NORMAL);
  184. GetDlgItem( IDC_IPADDR_DEV )->EnableWindow( false );
  185. GetDlgItem( IDC_EDT_NET_PORT )->EnableWindow( false );
  186. m_nNetIP = htonl(inet_addr("192.168.1.111"));
  187. m_nNetPort = 6000;
  188. //int nDevDriveID=0,nDevFactoryID=0,nDevTypeID=0;
  189. //GetDevIDFromUID( "5.32.131.1",nDevDriveID,nDevFactoryID,nDevTypeID );
  190. //CString sDevDriveName,sDevFactoryName,sDevTypeName;
  191. //CDBInterface::GetInstancePtr()->GetDriverName( nDevDriveID,sDevDriveName );
  192. //CDBInterface::GetInstancePtr()->GetFactoryName( nDevDriveID,nDevFactoryID,sDevFactoryName );
  193. //CDBInterface::GetInstancePtr()->GetDevicesName( nDevDriveID,nDevFactoryID,nDevTypeID,sDevTypeName );
  194. if( !m_ExcelMain.IsExistExcel() )
  195. {
  196. m_bIsExistExcel = false;
  197. return false;
  198. }
  199. else
  200. m_bIsExistExcel = true;
  201. return TRUE; // return TRUE unless you set the focus to a control
  202. // 异常: OCX 属性页应返回 FALSE
  203. }
  204. void CDlg_ZuTaiAdd::MyExpandTree(HTREEITEM hTreeItem)
  205. {
  206. if(!m_ctrlDevFolder.ItemHasChildren(hTreeItem))
  207. {
  208. return;
  209. }
  210. HTREEITEM hNextItem = m_ctrlDevFolder.GetChildItem(hTreeItem);
  211. while (hNextItem != NULL)
  212. {
  213. MyExpandTree(hNextItem);
  214. hNextItem = m_ctrlDevFolder.GetNextItem(hNextItem, TVGN_NEXT);
  215. }
  216. m_ctrlDevFolder.Expand(hTreeItem,TVE_EXPAND);
  217. }
  218. HBRUSH CDlg_ZuTaiAdd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  219. {
  220. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  221. // TODO: 在此更改 DC 的任何属性
  222. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  223. return hbr;
  224. }
  225. BOOL CDlg_ZuTaiAdd::OnEraseBkgnd(CDC* pDC)
  226. {
  227. // TODO: 在此添加消息处理程序代码和/或调用默认值
  228. return CDialog::OnEraseBkgnd(pDC);
  229. }
  230. void CDlg_ZuTaiAdd::OnBnClickedBtnTest()
  231. {
  232. // TODO: 在此添加控件通知处理程序代码
  233. }
  234. void CDlg_ZuTaiAdd::OnBnClickedBtnCreate()
  235. {
  236. UpdateData();
  237. if( m_nEdit_DevNumber<=0 )
  238. {
  239. MessageBox( "设备个数不能少于1!","提示" );
  240. return;
  241. }
  242. if( m_nChooseItem==-1 && m_sMainType=="" || m_sSlaveType=="" || m_sDevBrand=="" || m_sDevVersion=="" )
  243. {
  244. MessageBox( "先选择设备!","提示" );
  245. return;
  246. }
  247. CString sShow;
  248. sShow.Format( "%s %s %s %s",m_sMainType,m_sSlaveType,m_sDevBrand,m_sDevVersion );
  249. if( MessageBox( sShow,"提示",MB_YESNO )!=IDYES )
  250. return;
  251. m_bIsJubgeHaveBit = false;
  252. m_bHaveBit = false;
  253. m_bChangeVarToPic = false;
  254. CString strName,strUID;
  255. CString sDevName,sDevUid;
  256. int nDevIndex=0;
  257. strUID = g_DVP[m_nChooseItem].sDevUid.Left( g_DVP[m_nChooseItem].sDevUid.GetLength()-2 );
  258. strName.Format( "%s(%s)",m_sSlaveType,m_sDevBrand );
  259. bool bOpenVarFile=false;//是否已经从变量文件读取到变量信息
  260. int nDevAddr = m_nDevAddr;
  261. for( int iDevIndex=0;iDevIndex<m_nEdit_DevNumber;iDevIndex++ )
  262. {
  263. //uid
  264. CHAR szDevNum[MAX_ID + 1] = {0};
  265. CDBInterface::GetInstancePtr()->FindDevInfoByUID((char *)(LPCTSTR)strUID, szDevNum);
  266. sDevUid.Format("%s.%d", strUID, atoi(szDevNum) + 1);
  267. //name
  268. CDBInterface::GetInstancePtr()->FindDevNameByName( (char *)(LPCTSTR)strName,sDevName,nDevIndex );
  269. int nRet = AddDeviceToDB( sDevName,sDevUid,m_nCommPort,nDevAddr,m_nNetIP,m_nNetPort );
  270. if( nRet==1 )
  271. {
  272. //一。从变量文件读取变量信息 只操作一次
  273. if( !bOpenVarFile )
  274. {
  275. bOpenVarFile = true;
  276. OpenVarExcel( g_DVP[m_nChooseItem].sVarFileName );
  277. }
  278. //二。设备UID,变量名,变量描述, 位信息ID( 变量起始BIT位, 变量终止BIT )
  279. ChangeVarInfo( sDevUid,nDevIndex );
  280. //三。把变量写入数据库
  281. AddVarToDB();
  282. //四。生成画面文件
  283. ChangePicRelevanceVar( g_DVP[m_nChooseItem].sPicFileName,sDevName+".view" );//g_DVP[m_nChooseItem].sPicFileName,nDevIndex );
  284. if( !m_bChangeVarToPic )
  285. {
  286. MessageBox( "画面文件不对!","提示" );
  287. return;
  288. }
  289. nDevAddr++;
  290. }
  291. else if( nRet==100 )//IP与端口重复
  292. {
  293. MessageBox( "设备IP重复!","提示" );
  294. return;
  295. }
  296. else
  297. {
  298. iDevIndex--;
  299. nDevAddr++;
  300. }
  301. }
  302. MessageBox( "生成完成!","提示" );
  303. m_bIsUserZuTai = true;
  304. }
  305. void CDlg_ZuTaiAdd::ChangeVarInfo( CString sDevUid,int nDevIndex )
  306. {
  307. //是否已经判断过有没有BIT位信息
  308. if( !m_bIsJubgeHaveBit )
  309. {
  310. m_bIsJubgeHaveBit = true;
  311. if( !m_bHaveBit )
  312. {
  313. //判断有没有BIT位信息
  314. for( int i=0;i<1000;i++ )
  315. {
  316. if( g_VarList[i].sVarName=="" )
  317. break;
  318. if( g_VarList[i].nStartBit>0 || g_VarList[i].nEndBit>0 )
  319. {
  320. m_bHaveBit = true;
  321. break;
  322. }
  323. }
  324. }
  325. }
  326. //位信息ID( 变量起始BIT位, 变量终止BIT )
  327. if( m_bHaveBit )
  328. {
  329. int nBitID=0;
  330. for( int i=0;i<1000;i++ )
  331. {
  332. if( g_VarList[i].sVarName=="" )
  333. break;
  334. if( -1!=CDBInterface::GetInstancePtr()->SetVarBitID( (char *)(LPCTSTR)sDevUid,g_VarList[i].nStartBit,g_VarList[i].nEndBit,nBitID ) )
  335. {
  336. g_VarList[i].nVarItemID = nBitID;
  337. }
  338. }
  339. }
  340. for( int i=0;i<1000;i++ )
  341. {
  342. if( g_VarList[i].sVarName=="" )
  343. break;
  344. g_VarList[i].sDevUid = sDevUid;//设备UID
  345. g_VarList[i].sVarNameTemp.Format( "%s_%d",g_VarList[i].sVarName,nDevIndex );//变量名
  346. if( -1!=g_VarList[i].sVarDesc.Find( "*" ) )//变量描述
  347. {
  348. CString s;
  349. s.Format( "%d",nDevIndex );
  350. g_VarList[i].sVarDescTemp = g_VarList[i].sVarDesc;
  351. g_VarList[i].sVarDescTemp.Replace( "*",s );
  352. }
  353. else
  354. {
  355. g_VarList[i].sVarDescTemp.Format( "%s_%d",g_VarList[i].sVarDesc,nDevIndex );
  356. }
  357. }
  358. }
  359. void CDlg_ZuTaiAdd::OnBnClickedBtnQuit()
  360. {
  361. OnOK();
  362. }
  363. bool CDlg_ZuTaiAdd::OpenDevExcel()
  364. {
  365. if( !m_bIsExistExcel )
  366. return false;
  367. char Path[_MAX_PATH] = {0};
  368. strcat(Path, g_strDirectory);
  369. strcat(Path,"\\");
  370. strcat(Path, _LIBRARY);
  371. strcat(Path, "设备列表.xls");
  372. if( !PathFileExists( Path ) )
  373. return false;
  374. CString sMainType;//主类
  375. CString sSlaveType;//次类
  376. CString sDevBrand;//设备品牌
  377. CString sDevVersion;//设备型号
  378. CString sDevUid;//设备UID
  379. CString sVarFileName;//变量文件名称
  380. CString sPicFileName;//界面文件名称
  381. CString sCommunicationType;//通信类型
  382. CString sCommunicationTreaty;//通信协议
  383. CString sDllName;//驱动名称
  384. CString sIniName;//配置文件
  385. CString sBaudRate;//波特率
  386. CString sDataBit;//数据位
  387. CString sStopBit;//停止位
  388. CString sCheckBit;//校验位
  389. CString sNetPort;//通讯端口
  390. int nIndex=0;
  391. int i,j,k=0;
  392. CString strText;
  393. if(m_ExcelMain.IsFileExist(Path,FALSE))
  394. {
  395. if( !m_ExcelMain.Open(Path) )
  396. return false;
  397. if( !m_ExcelMain.OpenSheet("View") )
  398. return false;
  399. m_ExcelMain.AutoRange();
  400. //size_t maxRows = ExcelMain.GetColS();
  401. //size_t maxCols = ExcelMain.GetRowS();
  402. int INDEX=0;
  403. bool bBreak=false;
  404. for(i=2;i<99999;i++)
  405. {
  406. if( m_ExcelMain.IsRowEmpty( i ) )
  407. break;
  408. for(j=1;j<30;j++)
  409. {
  410. strText=m_ExcelMain.GetItemText(i,j);
  411. if( j==1 )
  412. {
  413. if( strText!="" )
  414. {
  415. sMainType = strText;
  416. sSlaveType = "";
  417. sDevBrand = "";
  418. }
  419. }
  420. else if( j==2 )
  421. {
  422. if( strText!="" )
  423. {
  424. sSlaveType = strText;
  425. sDevBrand = "";
  426. }
  427. }
  428. else if( j==3 )
  429. {
  430. if( strText!="" )
  431. {
  432. sDevBrand = strText;
  433. }
  434. }
  435. else if( j==4 )
  436. {
  437. sDevVersion = strText;
  438. }
  439. else if( j==5 )
  440. {
  441. sDevUid = strText;
  442. }
  443. else if( j==6 )
  444. {
  445. sVarFileName = strText;
  446. }
  447. else if( j==7 )
  448. {
  449. sPicFileName = strText;
  450. }
  451. else if( j==8 )
  452. {
  453. sCommunicationType = strText;
  454. }
  455. else if( j==9 )
  456. {
  457. sCommunicationTreaty = strText;
  458. }
  459. else if( j==10 )
  460. {
  461. sDllName = strText;
  462. }
  463. else if( j==11 )
  464. {
  465. sIniName = strText;
  466. }
  467. else if( j==12 )
  468. {
  469. sBaudRate = strText;
  470. }
  471. else if( j==13 )
  472. {
  473. sDataBit = strText;
  474. }
  475. else if( j==14 )
  476. {
  477. sStopBit = strText;
  478. }
  479. else if( j==15 )
  480. {
  481. sCheckBit = strText;
  482. }
  483. else if( j==17 )//16是IP
  484. {
  485. sNetPort = strText;
  486. }
  487. }
  488. g_DVP[nIndex].sMainType = sMainType;
  489. g_DVP[nIndex].sSlaveType = sSlaveType;
  490. g_DVP[nIndex].sDevBrand = sDevBrand;
  491. g_DVP[nIndex].sDevVersion = sDevVersion;
  492. g_DVP[nIndex].sDevUid = sDevUid;
  493. g_DVP[nIndex].sVarFileName = sVarFileName;
  494. g_DVP[nIndex].sPicFileName = sPicFileName;
  495. g_DVP[nIndex].nCommunicationType = sCommunicationType=="串口"?0:1;
  496. g_DVP[nIndex].nCommunicationTreaty = GetCommunicationTreaty( sCommunicationTreaty );
  497. g_DVP[nIndex].sDllName = sDllName;
  498. g_DVP[nIndex].sIniName = sIniName;
  499. g_DVP[nIndex].nBaudRate = GetBaudRateIndex( sBaudRate );
  500. g_DVP[nIndex].nDataBit = GetCommDataBitIndex( sDataBit );
  501. if( sStopBit=="1" )
  502. g_DVP[nIndex].nStopBit = 0;
  503. else if( sStopBit=="1.5" )
  504. g_DVP[nIndex].nStopBit = 1;
  505. else if( sStopBit=="2" )
  506. g_DVP[nIndex].nStopBit = 2;
  507. g_DVP[nIndex].nCheckBit = atoi( sCheckBit );
  508. g_DVP[nIndex].nNetPort = atoi( sNetPort );
  509. nIndex++;
  510. if( nIndex==1000 )
  511. break;
  512. }
  513. }
  514. else
  515. {
  516. return false;
  517. }
  518. return true;
  519. }
  520. bool CDlg_ZuTaiAdd::OpenVarExcel( CString sPath )
  521. {
  522. char Path[_MAX_PATH] = {0};
  523. strcat(Path, g_strDirectory);
  524. strcat(Path,"\\");
  525. strcat(Path, _LIBRARY);
  526. strcat(Path, "变量\\");
  527. strcat(Path, sPath);
  528. if( !PathFileExists( Path ) )
  529. return false;
  530. g_FunInitVarList();//初始化变量列表
  531. int nIndex=0;
  532. int i,j,k=0;
  533. CString strText;
  534. if(m_ExcelMain.IsFileExist(Path,FALSE))
  535. {
  536. m_ExcelMain.Open(Path);//ExcelMain.GetAppPath()+"\\Test.xls");
  537. m_ExcelMain.OpenSheet("View");
  538. m_ExcelMain.AutoRange();
  539. int INDEX=0;
  540. bool bBreak=false;
  541. for(i=2;i<99999;i++)
  542. {
  543. if( m_ExcelMain.IsRowEmpty( i ) )
  544. break;
  545. for(j=2;j<80;j++)
  546. {
  547. strText=m_ExcelMain.GetItemText(i,j);
  548. if( j==2 )
  549. g_VarList[nIndex].sDevUid = strText;
  550. else if( j==3 )
  551. g_VarList[nIndex].sVarName = strText;
  552. else if( j==4 )
  553. g_VarList[nIndex].sVarDesc = strText;
  554. else if( j==5 )
  555. g_VarList[nIndex].nVarTypeID = atoi( strText );
  556. else if( j==6 )
  557. g_VarList[nIndex].nDataLen = atoi( strText );
  558. else if( j==7 )
  559. g_VarList[nIndex].nRegNum = atoi( strText );
  560. else if( j==8 )
  561. g_VarList[nIndex].nFuncCode = atoi( strText );
  562. else if( j==9 )
  563. g_VarList[nIndex].nRegStartAddr = atoi( strText );
  564. else if( j==10 )
  565. g_VarList[nIndex].sRs232Cmd = strText;
  566. else if( j==11 )
  567. g_VarList[nIndex].sRs232Type = strText;
  568. else if( j==12 )
  569. g_VarList[nIndex].nRs232Index = atoi( strText );
  570. else if( j==13 )
  571. g_VarList[nIndex].nIdentifyTime = atoi( strText );
  572. else if( j==14 )
  573. g_VarList[nIndex].nRedetectTime = atoi( strText );
  574. else if( j==15 )
  575. g_VarList[nIndex].bIsNormalAlarm = atoi( strText );
  576. else if( j==16 )
  577. g_VarList[nIndex].sSnmpOid = strText;
  578. else if( j==17 )
  579. g_VarList[nIndex].sFields = strText;
  580. else if( j==18 )
  581. g_VarList[nIndex].nMaxValues = atoi( strText );
  582. else if( j==19 )
  583. g_VarList[nIndex].nMinValues = atoi( strText );
  584. else if( j==20 )
  585. g_VarList[nIndex].nMaxConvtRate = atoi( strText );
  586. else if( j==21 )
  587. g_VarList[nIndex].nMinValues = atoi( strText );
  588. else if( j==22 )
  589. g_VarList[nIndex].nLowerLimit = atoi( strText );
  590. else if( j==23 )
  591. g_VarList[nIndex].nUpperLimit = atoi( strText );
  592. else if( j==24 )
  593. g_VarList[nIndex].nNormalState = atoi( strText );
  594. else if( j==25 )
  595. g_VarList[nIndex].nRearm = atoi( strText );
  596. else if( j==26 )
  597. g_VarList[nIndex].nOffset = atoi( strText );
  598. else if( j==27 )
  599. g_VarList[nIndex].sUnit = strText;
  600. else if( j==28 )
  601. g_VarList[nIndex].nCollectFreq = atoi( strText );
  602. else if( j==29 )
  603. g_VarList[nIndex].fCoef = atof( strText );
  604. else if( j==30 )
  605. g_VarList[nIndex].nWaringLevel = atoi( strText );
  606. else if( j==31 )
  607. g_VarList[nIndex].nPurview = atoi( strText );
  608. else if( j==32 )
  609. g_VarList[nIndex].bIsSave = atoi( strText );
  610. else if( j==33 )
  611. g_VarList[nIndex].bRealtimeFlag = atoi( strText );
  612. else if( j==34 )
  613. g_VarList[nIndex].bRecCurve = atoi( strText );
  614. else if( j==35 )
  615. g_VarList[nIndex].bIsDDE = atoi( strText );
  616. else if( j==36 )
  617. g_VarList[nIndex].nRegChildID = atoi( strText );
  618. else if( j==37 )
  619. g_VarList[nIndex].nVarItemID = atoi( strText );
  620. else if( j==38 )
  621. g_VarList[nIndex].nDevID = atoi( strText );
  622. else if( j==39 )
  623. g_VarList[nIndex].sOnDesc = strText;
  624. else if( j==40 )
  625. g_VarList[nIndex].sOffDesc = strText;
  626. else if( j==41 )
  627. g_VarList[nIndex].sSetValue = strText;
  628. else if( j==42 )
  629. g_VarList[nIndex].nStartBit = atoi( strText );
  630. else if( j==43 )
  631. g_VarList[nIndex].nEndBit = atoi( strText );
  632. else if( j==44 )
  633. g_VarList[nIndex].sReserved1 = strText;
  634. else if( j==45 )
  635. g_VarList[nIndex].sReserved2 = strText;
  636. else if( j==46 )
  637. g_VarList[nIndex].sReserved3 = strText;
  638. else if( j==47 )
  639. g_VarList[nIndex].sReserved4 = strText;
  640. else if( j==48 )
  641. g_VarList[nIndex].sReserved5 = strText;
  642. else if( j==49 )
  643. g_VarList[nIndex].sReserved6 = strText;
  644. else if( j==50 )
  645. g_VarList[nIndex].sReserved7 = strText;
  646. else if( j==51 )
  647. g_VarList[nIndex].sReserved8 = strText;
  648. else if( j==52 )
  649. g_VarList[nIndex].sReserved9 = strText;
  650. else if( j==53 )
  651. g_VarList[nIndex].sReserved10 = strText;
  652. else if( j==54 )
  653. g_VarList[nIndex].nReserved1 = atoi( strText );
  654. else if( j==55 )
  655. g_VarList[nIndex].nReserved2 = atoi( strText );
  656. else if( j==56 )
  657. g_VarList[nIndex].nReserved3 = atoi( strText );
  658. else if( j==57 )
  659. g_VarList[nIndex].nReserved4 = atoi( strText );
  660. else if( j==58 )
  661. g_VarList[nIndex].nReserved5 = atoi( strText );
  662. else if( j==59 )
  663. g_VarList[nIndex].nReserved6 = atoi( strText );
  664. else if( j==60 )
  665. g_VarList[nIndex].nReserved7 = atoi( strText );
  666. else if( j==61 )
  667. g_VarList[nIndex].nReserved8 = atoi( strText );
  668. else if( j==62 )
  669. g_VarList[nIndex].nReserved9 = atoi( strText );
  670. else if( j==63 )
  671. g_VarList[nIndex].nReserved10 = atoi( strText );
  672. else if( j==64 )
  673. g_VarList[nIndex].bReserved1 = atoi( strText );
  674. else if( j==65 )
  675. g_VarList[nIndex].bReserved2 = atoi( strText );
  676. else if( j==66 )
  677. g_VarList[nIndex].bReserved3 = atoi( strText );
  678. else if( j==67 )
  679. g_VarList[nIndex].bReserved4 = atoi( strText );
  680. else if( j==68 )
  681. g_VarList[nIndex].bReserved5 = atoi( strText );
  682. else if( j==69 )
  683. g_VarList[nIndex].bReserved6 = atoi( strText );
  684. else if( j==70 )
  685. g_VarList[nIndex].bReserved7 = atoi( strText );
  686. else if( j==71 )
  687. g_VarList[nIndex].bReserved8 = atoi( strText );
  688. else if( j==72 )
  689. g_VarList[nIndex].bReserved9 = atoi( strText );
  690. else if( j==73 )
  691. g_VarList[nIndex].bReserved10 = atoi( strText );
  692. else if( j==74 )
  693. g_VarList[nIndex].nVarStatusNum = atoi( strText );
  694. else if( j==75 )
  695. g_VarList[nIndex].nVarStatusID = atoi( strText );
  696. else if( j==76 )
  697. g_VarList[nIndex].sVarStatusDesc = strText;
  698. }
  699. nIndex++;
  700. if( nIndex==1000 )
  701. break;
  702. }
  703. }
  704. else
  705. {
  706. return false;
  707. }
  708. return true;
  709. }
  710. int CDlg_ZuTaiAdd::GetCommunicationTreaty( CString sData )
  711. {
  712. int nRet=-1;
  713. if( sData=="Modbus Rtu" )
  714. nRet = 0;
  715. if( sData=="Modbus Ascii" )
  716. nRet = 1;
  717. if( sData=="Modbus Tcp" )
  718. nRet = 2;
  719. if( sData=="Snmp" )
  720. nRet = 3;
  721. if( sData=="RS232" )
  722. nRet = 4;
  723. return nRet;
  724. }
  725. int CDlg_ZuTaiAdd::GetBaudRateIndex( CString sBaudRate )
  726. {
  727. int nRet=-1;
  728. if( sBaudRate=="1200" )
  729. nRet = 0;
  730. if( sBaudRate=="2400" )
  731. nRet = 1;
  732. if( sBaudRate=="4800" )
  733. nRet = 2;
  734. if( sBaudRate=="9600" )
  735. nRet = 3;
  736. if( sBaudRate=="14400" )
  737. nRet = 4;
  738. if( sBaudRate=="19200" )
  739. nRet = 5;
  740. if( sBaudRate=="38400" )
  741. nRet = 6;
  742. if( sBaudRate=="57600" )
  743. nRet = 7;
  744. if( sBaudRate=="115200" )
  745. nRet = 8;
  746. if( sBaudRate=="128000" )
  747. nRet = 9;
  748. if( sBaudRate=="256000" )
  749. nRet = 10;
  750. return nRet;
  751. }
  752. // 获取实际数据位
  753. int CDlg_ZuTaiAdd::GetCommDataBitIndex( CString sDataBit )
  754. {
  755. int nRet=-1;
  756. if( sDataBit=="7" )
  757. nRet = 0;
  758. if( sDataBit=="8" )
  759. nRet = 1;
  760. return nRet;
  761. }
  762. void CDlg_ZuTaiAdd::ListDeviceTypes( HTREEITEM hItemParent )
  763. {
  764. HTREEITEM hItemDrive=NULL, hItemFactory=NULL, hItemType=NULL;
  765. CString sMainType,sMainTypeOld="1";//主类
  766. CString sSlaveType,sSlaveTypeOld="1";//次类
  767. CString sDevBrand,sDevBrandOld="1";//设备品牌
  768. CString sDevVersion;//设备型号
  769. for( int i=0;i<1000;i++ )
  770. {
  771. if( g_DVP[i].sMainType=="" )
  772. break;
  773. sMainType = g_DVP[i].sMainType;
  774. if( sMainType!="" && sMainType!=sMainTypeOld )
  775. {
  776. sMainTypeOld = sMainType;
  777. hItemDrive = m_ctrlDevFolder.InsertItem( sMainType, 0, 1, hItemParent );
  778. sSlaveTypeOld = "";
  779. sDevBrandOld = "";
  780. hItemFactory = NULL;
  781. hItemType = NULL;
  782. }
  783. sSlaveType = g_DVP[i].sSlaveType;
  784. if( sSlaveType!="" && sSlaveType!=sSlaveTypeOld && hItemDrive )
  785. {
  786. sSlaveTypeOld = sSlaveType;
  787. hItemFactory = m_ctrlDevFolder.InsertItem( sSlaveType, 0, 1, hItemDrive );
  788. sDevBrandOld = "";
  789. hItemType = NULL;
  790. }
  791. sDevBrand = g_DVP[i].sDevBrand;
  792. if( sDevBrand!="" && sDevBrand!=sDevBrandOld && hItemFactory )
  793. {
  794. sDevBrandOld = sDevBrand;
  795. hItemType = m_ctrlDevFolder.InsertItem( sDevBrand, 0, 1, hItemFactory );
  796. }
  797. sDevVersion = g_DVP[i].sDevVersion;
  798. if( sDevVersion!="" && hItemType )
  799. m_ctrlDevFolder.InsertItem( sDevVersion, 2, 2, hItemType );
  800. }
  801. }
  802. int CDlg_ZuTaiAdd::SelChangedTreeDeviceFolder(HTREEITEM hItemSelect)
  803. {
  804. int nRet = -1;
  805. CString strSelect = m_ctrlDevFolder.GetItemText( hItemSelect );
  806. CString strDevDriveName = "", strDevFactoryName = "", strDevTypeName = "";
  807. HTREEITEM hItemParent = m_ctrlDevFolder.GetParentItem( hItemSelect );
  808. HTREEITEM hItemChild = m_ctrlDevFolder.GetChildItem( hItemSelect );
  809. if( hItemParent && hItemChild == NULL )
  810. {
  811. m_sDevVersion = m_ctrlDevFolder.GetItemText( hItemSelect );
  812. m_sDevBrand = m_ctrlDevFolder.GetItemText( hItemParent );
  813. hItemParent = m_ctrlDevFolder.GetParentItem( hItemParent );
  814. if( hItemParent != NULL )
  815. {
  816. m_sSlaveType = m_ctrlDevFolder.GetItemText( hItemParent );
  817. hItemParent = m_ctrlDevFolder.GetParentItem( hItemParent );
  818. if( hItemParent != NULL )
  819. {
  820. m_sMainType = m_ctrlDevFolder.GetItemText( hItemParent );
  821. }
  822. }
  823. for( int i=0;i<1000;i++ )
  824. {
  825. if( m_sMainType==g_DVP[i].sMainType && m_sSlaveType==g_DVP[i].sSlaveType && m_sDevBrand==g_DVP[i].sDevBrand && m_sDevVersion==g_DVP[i].sDevVersion )
  826. {
  827. nRet = i;
  828. break;
  829. }
  830. }
  831. if( g_DVP[nRet].nCommunicationType==0 )
  832. {
  833. GetDlgItem( IDC_EDT_DEVNUMBER )->EnableWindow( true );
  834. GetDlgItem( IDC_EDT_DEV_ADDR )->EnableWindow( true );
  835. GetDlgItem( IDC_EDT_COMM_PORT )->EnableWindow( true );
  836. GetDlgItem( IDC_IPADDR_DEV )->EnableWindow( false );
  837. GetDlgItem( IDC_EDT_NET_PORT )->EnableWindow( false );
  838. }
  839. else
  840. {
  841. m_nEdit_DevNumber = 1;
  842. UpdateData(false);
  843. GetDlgItem( IDC_EDT_DEVNUMBER )->EnableWindow( false );
  844. GetDlgItem( IDC_EDT_DEV_ADDR )->EnableWindow( false );
  845. GetDlgItem( IDC_EDT_COMM_PORT )->EnableWindow( false );
  846. GetDlgItem( IDC_IPADDR_DEV )->EnableWindow( true );
  847. GetDlgItem( IDC_EDT_NET_PORT )->EnableWindow( true );
  848. }
  849. }
  850. return nRet;
  851. }
  852. void CDlg_ZuTaiAdd::OnTvnSelchangedTreeDeviceFolder(NMHDR *pNMHDR, LRESULT *pResult)
  853. {
  854. LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
  855. // TODO: 在此添加控件通知处理程序代码
  856. HTREEITEM hItemSelect = pNMTreeView->itemNew.hItem;
  857. m_nChooseItem = SelChangedTreeDeviceFolder( hItemSelect );
  858. *pResult = 0;
  859. }
  860. void CDlg_ZuTaiAdd::GetDevIDFromUID( CString sDevUid,int &nDevDriveID, int &nDevFactoryID, int &nDevTypeID )
  861. {
  862. int n1=-1,n2=-1,n3=-1,n4=-1;
  863. n1 = sDevUid.Find( "." );
  864. n2 = sDevUid.Find( ".",n1+1 );
  865. n3 = sDevUid.Find( ".",n2+1 );
  866. nDevDriveID = atoi( sDevUid.Mid( 0,n1 ) );
  867. nDevFactoryID = atoi( sDevUid.Mid( n1+1,n2-n1-1 ) );
  868. nDevTypeID = atoi( sDevUid.Mid( n2+1,n3-n2-1 ) );
  869. }
  870. int CDlg_ZuTaiAdd::AddDeviceToDB( CString sDevName,CString sDevUid,int nCommPort,int nDevAddr,DWORD nNetIP,int nNetPort )
  871. {
  872. int nDevDriveID=0,nDevFactoryID=0,nDevTypeID=0;
  873. GetDevIDFromUID( sDevUid,nDevDriveID,nDevFactoryID,nDevTypeID );
  874. CString sDevDriveName,sDevFactoryName,sDevTypeName;
  875. CDBInterface::GetInstancePtr()->GetDriverName( nDevDriveID,sDevDriveName );
  876. CDBInterface::GetInstancePtr()->GetFactoryName( nDevDriveID,nDevFactoryID,sDevFactoryName );
  877. CDBInterface::GetInstancePtr()->GetDevicesName( nDevDriveID,nDevFactoryID,nDevTypeID,sDevTypeName );
  878. // 加入该设备的参数
  879. CChannel* pChannel = NULL;
  880. //
  881. CDevice* pDev = new CDevice();
  882. pDev->Create();
  883. CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  884. int nIP;
  885. nIP = htonl(nNetIP);
  886. // 通信协议(例:Modbus rtu, Modbus Ascii, Modbus tcp)
  887. pDev->m_nProtocolType = g_DVP[m_nChooseItem].nCommunicationTreaty;
  888. // 动态库名称
  889. pDev->m_strProtocolName = g_DVP[m_nChooseItem].sDllName;
  890. // 配置文件名称
  891. pDev->m_strIniName = g_DVP[m_nChooseItem].sIniName;
  892. // 是否为采集模块
  893. pDev->m_nIsCollectDev = 0;
  894. // 是否启用设备
  895. pDev->m_bUsed = 1;
  896. // 设备UID
  897. pDev->m_strUID = sDevUid;
  898. // 设备名称
  899. pDev->m_strName = sDevName;
  900. // 设备类型
  901. pDev->m_strType = sDevTypeName;//GetDevTypeID(sDevUid); ****
  902. // 设备地址
  903. pDev->m_Address = (BYTE)nDevAddr;
  904. // 驱动名称(例:UPS、空调)
  905. pDev->m_strDevDriveName = sDevDriveName;//m_wndDevice.m_strDevDriveName; ****
  906. // 设备厂家名称
  907. pDev->m_strDevFactoryName = sDevFactoryName;//m_wndDevice.m_strDevFactoryName; ****
  908. // 通讯超时
  909. pDev->m_nTimeout = 10000;
  910. // 网络设备IP
  911. pDev->m_strDevIP = inet_ntoa(*(struct in_addr *)&nIP);
  912. // 网络设备通信端口
  913. pDev->m_nNetPort = nNetPort;
  914. // 预留1 设备所属区域
  915. pDev->m_strReserved1 = "";
  916. // 预留2
  917. pDev->m_strReserved2 = "";
  918. // 预留3
  919. pDev->m_strReserved3 = "";
  920. // 预留4
  921. pDev->m_strReserved4 = "";
  922. // 预留5
  923. pDev->m_strReserved5 = "";
  924. // 预留6
  925. pDev->m_strReserved6 = "";
  926. // 预留7
  927. pDev->m_strReserved7 = "";
  928. // 预留8
  929. pDev->m_strReserved8 = "";
  930. // 预留9
  931. pDev->m_strReserved9 = "";
  932. // 预留10
  933. pDev->m_strReserved10 = "";
  934. // 预留1
  935. pDev->m_nReserved1 = 0;
  936. // 预留2
  937. pDev->m_nReserved2 = 0;
  938. // 预留3
  939. pDev->m_nReserved3 = 0;
  940. // 预留4
  941. pDev->m_nReserved4 = 0;
  942. // 预留5
  943. pDev->m_nReserved5 = 0;
  944. // 预留6
  945. pDev->m_nReserved6 = 0;
  946. // 预留7
  947. pDev->m_nReserved7 = 0;
  948. // 预留8
  949. pDev->m_nReserved8 = 0;
  950. // 预留9
  951. pDev->m_nReserved9 = 0;
  952. // 预留10
  953. pDev->m_nReserved10 = 0;
  954. // 预留1
  955. pDev->m_bReserved1 = 0;
  956. // 预留2
  957. pDev->m_bReserved2 = 0;
  958. // 预留3
  959. pDev->m_bReserved3 = 0;
  960. // 预留4
  961. pDev->m_bReserved4 = 0;
  962. // 预留5
  963. pDev->m_bReserved5 = 0;
  964. // 预留6
  965. pDev->m_bReserved6 = 0;
  966. // 预留7
  967. pDev->m_bReserved7 = 0;
  968. // 预留8
  969. pDev->m_bReserved8 = 0;
  970. // 预留9
  971. pDev->m_bReserved9 = 0;
  972. // 预留10
  973. pDev->m_bReserved10 = 0;
  974. CString strCommPort;
  975. int nIndex, nFreeIndex;
  976. int nChannelSize;
  977. int nDeviceSize;
  978. CHAR szMaxID[MAX_ID + 1] = {0};
  979. CHAR szDevTypeID[MAX_ID + 1] = {0};
  980. // 获取t_dev_property设备属性表字段ID的最大值
  981. int nRet = CDBInterface::GetInstancePtr()->GetMaxID("t_dev_property", "id", szMaxID);
  982. if( -1 == nRet )
  983. {
  984. pDev->Destroy();
  985. delete pDev;
  986. return -1;
  987. }
  988. int nID;
  989. if( atoi(szMaxID) > 0 )
  990. {
  991. nID = atoi(szMaxID) + 1;
  992. }
  993. else if( atoi(szMaxID) == 0 )
  994. {
  995. nID = 1;
  996. }
  997. //// 获取设备类型ID
  998. //CDBInterface::GetInstancePtr()->GetDevTypeID((char *)(LPCTSTR)m_wndDevice.m_strDevTypeName, szDevTypeID);
  999. //if( !m_wndComport.m_strDevName.Compare("") )
  1000. //{
  1001. // MessageBox(g_strDevNumCannotBlank,g_strTip,MB_ICONWARNING);
  1002. // pDev->Destroy();
  1003. // delete pDev;
  1004. // return 0;
  1005. //}
  1006. //检查合法值
  1007. CHAR szDevName[MAX_DESC + 1] = {0};
  1008. CHAR szDevUID[MAX_DESC + 1] = {0};
  1009. nRet = CDBInterface::GetInstancePtr()->GetDevName((char *)(LPCTSTR)sDevUid, szDevName);
  1010. if( nRet > 0 )
  1011. {
  1012. //MessageBox(g_strDevUidExist,g_strTip,MB_ICONWARNING);
  1013. pDev->Destroy();
  1014. delete pDev;
  1015. return 0;
  1016. }
  1017. nRet = CDBInterface::GetInstancePtr()->GetDevUID( (char *)(LPCTSTR)sDevName, (char *)(LPCTSTR)sDevUid );
  1018. if( nRet > 0 )
  1019. {
  1020. //MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING);
  1021. pDev->Destroy();
  1022. delete pDev;
  1023. return 0;
  1024. }
  1025. // 串口设备
  1026. if( g_DVP[m_nChooseItem].nCommunicationType == 0 )
  1027. {
  1028. strCommPort.Format("COM%d", nCommPort);
  1029. nIndex = pMainFrm->GetIndexSerialTreeItem(strCommPort);//得到COM的序列号
  1030. if( nIndex == -1 )
  1031. {
  1032. nFreeIndex = pMainFrm->GetFreeSerialTreeItem();
  1033. CChannel* pComport = new CChannel();
  1034. //CSerial* pComport = new CSerial();
  1035. // 串行端口
  1036. pComport->m_strPort = strCommPort.Trim();
  1037. // 串行端口地址
  1038. pComport->m_nAddr = nDevAddr;
  1039. // 波特率
  1040. pComport->m_nBaudRate = g_DVP[m_nChooseItem].nBaudRate; // 1200;2400;4800;9600;14400;19200;38400;57600;115200;128000;256000
  1041. // 数据位
  1042. pComport->m_nByteSize = g_DVP[m_nChooseItem].nDataBit; // 0-1=7,8
  1043. // 检验位
  1044. pComport->m_nParity = g_DVP[m_nChooseItem].nCheckBit; // 0-4=no,odd,even,mark
  1045. // 停止位
  1046. pComport->m_nStopBits = g_DVP[m_nChooseItem].nStopBit; // 0-2=1,1.5,2
  1047. pDevicesManager->m_channels.Add(pComport);
  1048. nChannelSize = pDevicesManager->m_channels.GetSize();
  1049. pChannel = pDevicesManager->m_channels[nChannelSize - 1];
  1050. pChannel->m_strName = strCommPort.Trim();
  1051. pChannel->m_nCommunicateType = g_DVP[m_nChooseItem].nCommunicationType;
  1052. nDeviceSize = pChannel->m_Devices.GetSize();
  1053. pMainFrm->m_hSerialGroup[nFreeIndex] = pMainFrm->m_wndTree.InsertItem(strCommPort, 4, 4, pMainFrm->m_hSerial);
  1054. pMainFrm->m_hSerialDev[nFreeIndex][nDeviceSize] = pMainFrm->m_wndTree.InsertItem( sDevName, 4, 4, pMainFrm->m_hSerialGroup[nFreeIndex] );
  1055. }
  1056. else
  1057. {
  1058. nChannelSize = pDevicesManager->m_channels.GetSize();
  1059. for( int i = 0; i < nChannelSize; i++ )
  1060. {
  1061. CChannel* pCommPort =pDevicesManager->m_channels[i];
  1062. if( ( !pCommPort->m_strPort.Compare(strCommPort) ) && pCommPort->m_Devices.GetSize() > 0 )
  1063. {
  1064. nDeviceSize = pCommPort->m_Devices.GetSize();
  1065. for( int j = 0; j < nDeviceSize; j++ )
  1066. {
  1067. if( (int)pCommPort->m_Devices[j]->m_Address == nDevAddr )
  1068. {
  1069. //MessageBox(g_strSerialPortInUse,g_strTip,MB_ICONWARNING);
  1070. pDev->Destroy();
  1071. delete pDev;
  1072. return 0;
  1073. }
  1074. }
  1075. }
  1076. }
  1077. for( int i = 0; i < nChannelSize; i++ )
  1078. {
  1079. CChannel* pCommPort = pDevicesManager->m_channels[i];
  1080. if( !pCommPort->m_strPort.Compare(strCommPort) )
  1081. {
  1082. nDeviceSize = pCommPort->m_Devices.GetSize();
  1083. pChannel = pDevicesManager->m_channels[i];
  1084. break;
  1085. }
  1086. }
  1087. pMainFrm->m_hSerialDev[nIndex][nDeviceSize] = pMainFrm->m_wndTree.InsertItem( sDevName, 4, 4, pMainFrm->m_hSerialGroup[nIndex]);
  1088. }
  1089. if( pChannel != NULL )
  1090. {
  1091. pDev->m_pChannel = pChannel;
  1092. pChannel->m_Devices.Add(pDev);
  1093. }
  1094. }
  1095. else// 网络设备
  1096. {
  1097. int nChannelIndex;
  1098. // 得到m_channels数组中网络设备的索引,有且只有一个
  1099. nIndex = pMainFrm->GetIndexNetworkTreeItem( sDevName );
  1100. if( nIndex == -1 )
  1101. {
  1102. nChannelIndex = pMainFrm->GetNetworkChannelIndex();
  1103. if( nChannelIndex == -1 )
  1104. {
  1105. CNetwork *pNetwork = new CNetwork();
  1106. pNetwork->m_strName = g_strNetDev;
  1107. pDevicesManager->m_channels.Add(pNetwork);
  1108. nChannelIndex = pDevicesManager->m_channels.GetSize() - 1;
  1109. }
  1110. else
  1111. {
  1112. pChannel = pDevicesManager->m_channels[nChannelIndex];
  1113. for( int j = 0; j < pChannel->m_Devices.GetSize(); j ++ )
  1114. {
  1115. if( !(pChannel->m_Devices[j]->m_strDevIP.Compare(inet_ntoa(*(struct in_addr *)&nIP))) &&
  1116. (pChannel->m_Devices[j]->m_nNetPort == nNetPort ) )
  1117. {
  1118. //MessageBox(g_strIPConflict, g_strTip, MB_ICONWARNING);
  1119. pDev->Destroy();
  1120. delete pDev;
  1121. return 100;
  1122. }
  1123. }
  1124. }
  1125. pChannel = pDevicesManager->m_channels[nChannelIndex];
  1126. pChannel->m_nCommunicateType = g_DVP[m_nChooseItem].nCommunicationType;
  1127. nDeviceSize = pChannel->m_Devices.GetSize();
  1128. nFreeIndex = pMainFrm->GetFreeNetworkTreeItem();
  1129. pMainFrm->m_hNetworkDev[nFreeIndex] = pMainFrm->m_wndTree.InsertItem( sDevName, 2, 2, pMainFrm->m_hEtherNet);
  1130. pDev->m_pChannel = pChannel;
  1131. pChannel->m_Devices.Add(pDev);
  1132. }
  1133. else
  1134. {
  1135. //MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING);
  1136. pDev->Destroy();
  1137. delete pDev;
  1138. return 0;
  1139. }
  1140. }
  1141. // 插入设备信息
  1142. CDBInterface::GetInstancePtr()->InsertDevInfo(
  1143. nID,
  1144. (char *)(LPCTSTR)sDevUid,
  1145. nCommPort,
  1146. nDevAddr,
  1147. (char *)(LPCTSTR)sDevName,
  1148. nDevTypeID,
  1149. g_DVP[m_nChooseItem].nBaudRate,
  1150. g_DVP[m_nChooseItem].nDataBit,
  1151. g_DVP[m_nChooseItem].nStopBit,
  1152. g_DVP[m_nChooseItem].nCheckBit,
  1153. 0,
  1154. inet_ntoa( *(struct in_addr *)&nIP ),
  1155. nNetPort,
  1156. g_DVP[m_nChooseItem].nCommunicationType,
  1157. 0,
  1158. g_DVP[m_nChooseItem].nCommunicationTreaty,
  1159. 10000,//通信超时
  1160. 1,
  1161. (char *)(LPCTSTR)g_DVP[m_nChooseItem].sDllName,
  1162. (char *)(LPCTSTR)g_DVP[m_nChooseItem].sIniName,
  1163. "",//设备所属区域 //(char *)(LPCTSTR)m_wndDevice.m_strReserved1,
  1164. "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved2,
  1165. "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved3,
  1166. "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved4,
  1167. "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved5,
  1168. "",//(char *)(LPCTSTR)m_wndComport.m_strReserved6,
  1169. "",//(char *)(LPCTSTR)m_wndComport.m_strReserved7,
  1170. "",//(char *)(LPCTSTR)m_wndComport.m_strReserved8,
  1171. "",//(char *)(LPCTSTR)m_wndComport.m_strReserved9,
  1172. "",//(char *)(LPCTSTR)m_wndComport.m_strReserved10,
  1173. 0,//m_wndDevice.m_nReserved1,
  1174. 0,//m_wndDevice.m_nReserved2,
  1175. 0,//m_wndDevice.m_nReserved3,
  1176. 0,//m_wndDevice.m_nReserved4,
  1177. 0,//m_wndDevice.m_nReserved5,
  1178. 0,//m_wndComport.m_nReserved6,
  1179. 0,//m_wndComport.m_nReserved7,
  1180. 0,//m_wndComport.m_nReserved8,
  1181. 0,//m_wndComport.m_nReserved9,
  1182. 0,//m_wndComport.m_nReserved10,
  1183. 0,//(int)m_wndDevice.m_bReserved1,
  1184. 0,//(int)m_wndDevice.m_bReserved2,
  1185. 0,//(int)m_wndDevice.m_bReserved3,
  1186. 0,//(int)m_wndDevice.m_bReserved4,
  1187. 0,//(int)m_wndDevice.m_bReserved5,
  1188. 0,//(int)m_wndComport.m_bReserved6,
  1189. 0,//(int)m_wndComport.m_bReserved7,
  1190. 0,//(int)m_wndComport.m_bReserved8,
  1191. 0,//(int)m_wndComport.m_bReserved9,
  1192. 0//(int)m_wndComport.m_bReserved10
  1193. );
  1194. return 1;
  1195. }
  1196. int CDlg_ZuTaiAdd::AddVarToDB( )
  1197. {
  1198. int INDEX=0;
  1199. CHAR szMaxID[MAX_ID + 1] = {0};
  1200. for( int i=0;i<1000;i++ )
  1201. {
  1202. INDEX = i;
  1203. if( g_VarList[INDEX].sVarName=="" )
  1204. break;
  1205. CDBInterface::GetInstancePtr()->GetMaxID("t_dev_variant", "id", szMaxID);
  1206. int nID;
  1207. if( atoi(szMaxID) > 0 )
  1208. {
  1209. nID = atoi(szMaxID) + 1;
  1210. }
  1211. else if( atoi(szMaxID) == 0 )
  1212. {
  1213. nID = 1;
  1214. }
  1215. // 插入变量信息
  1216. CDBInterface::GetInstancePtr()->InsertVarInfo(
  1217. nID,
  1218. g_VarList[INDEX].nDevID, //(char *)(LPCTSTR)
  1219. (char *)(LPCTSTR)g_VarList[INDEX].sVarNameTemp,
  1220. (char *)(LPCTSTR)g_VarList[INDEX].sVarDescTemp,
  1221. g_VarList[INDEX].nVarTypeID,
  1222. g_VarList[INDEX].nMinValues,
  1223. g_VarList[INDEX].nMaxValues,
  1224. g_VarList[INDEX].nMaxConvtRate,
  1225. g_VarList[INDEX].nMinConvtRate,
  1226. g_VarList[INDEX].nCollectFreq,
  1227. g_VarList[INDEX].bIsDDE,
  1228. g_VarList[INDEX].nRegStartAddr,
  1229. g_VarList[INDEX].nWaringLevel,
  1230. (char *)(LPCTSTR)g_VarList[INDEX].sSetValue,
  1231. (char *)(LPCTSTR)g_VarList[INDEX].sUnit,
  1232. (char *)(LPCTSTR)g_VarList[INDEX].sDevUid,
  1233. "",//(char *)(LPCTSTR)g_VarList[INDEX].sRelatepage,
  1234. g_VarList[INDEX].bRecCurve,
  1235. g_VarList[INDEX].nRegNum,
  1236. (char *)(LPCTSTR)g_VarList[INDEX].sOnDesc,
  1237. (char *)(LPCTSTR)g_VarList[INDEX].sOffDesc,
  1238. g_VarList[INDEX].nUpperLimit,
  1239. g_VarList[INDEX].nLowerLimit,
  1240. 0,//g_VarList[INDEX].nChildid,
  1241. g_VarList[INDEX].nVarItemID,
  1242. g_VarList[INDEX].nNormalState,
  1243. (char *)(LPCTSTR)g_VarList[INDEX].sFields,
  1244. (char *)(LPCTSTR)g_VarList[INDEX].sSnmpOid,
  1245. g_VarList[INDEX].nRearm,
  1246. g_VarList[INDEX].nOffset,
  1247. g_VarList[INDEX].nFuncCode,
  1248. g_VarList[INDEX].nDataLen,
  1249. g_VarList[INDEX].fCoef,
  1250. g_VarList[INDEX].bRealtimeFlag,
  1251. g_VarList[INDEX].bIsSave,
  1252. (char *)(LPCTSTR)g_VarList[INDEX].sRs232Cmd,
  1253. (char *)(LPCTSTR)g_VarList[INDEX].sRs232Type,
  1254. g_VarList[INDEX].nRs232Index,
  1255. g_VarList[INDEX].nIdentifyTime,
  1256. g_VarList[INDEX].nRedetectTime,
  1257. g_VarList[INDEX].bIsNormalAlarm,
  1258. g_VarList[INDEX].nPurview,
  1259. (char *)(LPCTSTR)g_VarList[INDEX].sReserved1,
  1260. (char *)(LPCTSTR)g_VarList[INDEX].sReserved2,
  1261. (char *)(LPCTSTR)g_VarList[INDEX].sReserved3,
  1262. (char *)(LPCTSTR)g_VarList[INDEX].sReserved4,
  1263. (char *)(LPCTSTR)g_VarList[INDEX].sReserved5,
  1264. (char *)(LPCTSTR)g_VarList[INDEX].sReserved6,
  1265. (char *)(LPCTSTR)g_VarList[INDEX].sReserved7,
  1266. (char *)(LPCTSTR)g_VarList[INDEX].sReserved8,
  1267. (char *)(LPCTSTR)g_VarList[INDEX].sReserved9,
  1268. (char *)(LPCTSTR)g_VarList[INDEX].sReserved10,
  1269. g_VarList[INDEX].nReserved1,
  1270. g_VarList[INDEX].nReserved2,
  1271. g_VarList[INDEX].nReserved3,
  1272. g_VarList[INDEX].nReserved4,
  1273. g_VarList[INDEX].nReserved5,
  1274. g_VarList[INDEX].nReserved6,
  1275. g_VarList[INDEX].nReserved7,
  1276. g_VarList[INDEX].nReserved8,
  1277. g_VarList[INDEX].nReserved9,
  1278. g_VarList[INDEX].nReserved10,
  1279. g_VarList[INDEX].bReserved1,
  1280. g_VarList[INDEX].bReserved2,
  1281. g_VarList[INDEX].bReserved3,
  1282. g_VarList[INDEX].bReserved4,
  1283. g_VarList[INDEX].bReserved5,
  1284. g_VarList[INDEX].bReserved6,
  1285. g_VarList[INDEX].bReserved7,
  1286. g_VarList[INDEX].bReserved8,
  1287. g_VarList[INDEX].bReserved9,
  1288. g_VarList[INDEX].bReserved10
  1289. );
  1290. // 插入变量状态表
  1291. int n = g_VarList[INDEX].sVarStatusDesc.Find( "," );
  1292. if( n!=-1 )
  1293. {
  1294. g_VarList[INDEX].sVarStatusDesc.Delete( n );
  1295. }
  1296. if( g_VarList[INDEX].nVarStatusID!=0 )
  1297. CDBInterface::GetInstancePtr()->SetVarStatusID( (char *)(LPCTSTR)g_VarList[INDEX].sDevUid,nID,g_VarList[INDEX].nVarStatusID,(char *)(LPCTSTR)g_VarList[INDEX].sVarStatusDesc );
  1298. else if(g_VarList[INDEX].sVarStatusDesc!="0" )
  1299. CDBInterface::GetInstancePtr()->SetVarStatusID( (char *)(LPCTSTR)g_VarList[INDEX].sDevUid,nID,g_VarList[INDEX].nVarStatusID,(char *)(LPCTSTR)g_VarList[INDEX].sVarStatusDesc );
  1300. CAnalog *pAnalog = new CAnalog();
  1301. int nTemp = -1;
  1302. // 变量ID
  1303. pAnalog->m_nVarID = nID;
  1304. // 是否需要用户设置
  1305. if( g_VarList[INDEX].bReserved3 == 1 )
  1306. {
  1307. pAnalog->m_bReserved3 = TRUE;
  1308. }
  1309. else if( g_VarList[INDEX].bReserved3 == 0 )
  1310. {
  1311. pAnalog->m_bReserved3 = FALSE;
  1312. }
  1313. // 变量UID
  1314. pAnalog->m_strVarUID = g_VarList[INDEX].sDevUid;
  1315. // 变量名称
  1316. pAnalog->m_strName = g_VarList[INDEX].sVarNameTemp;
  1317. // 变量描述
  1318. pAnalog->m_strDesc = g_VarList[INDEX].sVarDescTemp;
  1319. // 变量类型ID
  1320. pAnalog->m_nVarTypeID = g_VarList[INDEX].nVarTypeID;
  1321. // 变量数据长度
  1322. pAnalog->m_nDataLen = g_VarList[INDEX].nDataLen;
  1323. // 开的描述
  1324. pAnalog->m_strOnDesc = g_VarList[INDEX].sOnDesc;
  1325. // 关的描述
  1326. pAnalog->m_strOffDesc = g_VarList[INDEX].sOffDesc;
  1327. // 最大值
  1328. pAnalog->m_nMaxValues = g_VarList[INDEX].nMaxValues;
  1329. // 最小值
  1330. pAnalog->m_nMinValues = g_VarList[INDEX].nMinValues;
  1331. // 最大转换比率
  1332. pAnalog->m_nMaxConvtRate = g_VarList[INDEX].nMaxConvtRate;
  1333. // 最小转换比率
  1334. pAnalog->m_nMinConvtRate = g_VarList[INDEX].nMinConvtRate;
  1335. // 下限
  1336. pAnalog->m_nLowerLimit = g_VarList[INDEX].nLowerLimit;
  1337. // 上限
  1338. pAnalog->m_nUpperLimit = g_VarList[INDEX].nUpperLimit;
  1339. // 正常状态
  1340. pAnalog->m_nNormalState = g_VarList[INDEX].nNormalState;
  1341. // 设定值
  1342. pAnalog->m_strSetValue = g_VarList[INDEX].sSetValue;
  1343. // 校正值
  1344. pAnalog->m_nRearm = g_VarList[INDEX].nRearm;
  1345. // 偏移量
  1346. pAnalog->m_nOffset = g_VarList[INDEX].nOffset;
  1347. // 单位
  1348. pAnalog->m_strUnit = g_VarList[INDEX].sUnit;
  1349. // 采集频率
  1350. pAnalog->m_nCollectFreq = g_VarList[INDEX].nCollectFreq;
  1351. // 转换系数
  1352. pAnalog->m_fCoef = g_VarList[INDEX].fCoef;
  1353. // 告警级别
  1354. pAnalog->m_nWaringLevel = g_VarList[INDEX].nWaringLevel;
  1355. // 读写权限
  1356. pAnalog->m_nPurview = g_VarList[INDEX].nPurview;
  1357. // 是否保存数值
  1358. pAnalog->m_bIsSave = g_VarList[INDEX].bIsSave;
  1359. // 是否实时采集数据
  1360. pAnalog->m_bRealtimeFlag = g_VarList[INDEX].bRealtimeFlag;
  1361. // 是否记录实时曲线
  1362. pAnalog->m_bRecCurve = g_VarList[INDEX].bRecCurve;
  1363. // 是否允许DDE访问
  1364. pAnalog->m_bIsDDE = g_VarList[INDEX].bIsDDE;
  1365. // 请求寄存器个数
  1366. pAnalog->m_nRegNum = g_VarList[INDEX].nRegNum;
  1367. // 功能码id
  1368. pAnalog->m_nFuncCode = g_VarList[INDEX].nFuncCode;
  1369. // 寄存器子id
  1370. pAnalog->m_nVarChildID = 0;//g_VarList[INDEX].nvar
  1371. // 位信息id
  1372. pAnalog->m_nVarItemID = g_VarList[INDEX].nVarItemID;
  1373. // SNMP对象oid
  1374. pAnalog->m_strSnmpOid = g_VarList[INDEX].sSnmpOid;
  1375. // SNMP域
  1376. pAnalog->m_strFields = g_VarList[INDEX].sFields;
  1377. // 设备类型ID
  1378. pAnalog->m_nDevID = g_VarList[INDEX].nDevID;
  1379. // 起始地址
  1380. pAnalog->m_nRegStartAddr = g_VarList[INDEX].nRegStartAddr;
  1381. // Rs232请求命令
  1382. pAnalog->m_strRs232Cmd = g_VarList[INDEX].sRs232Cmd;
  1383. // Rs232请求类型
  1384. pAnalog->m_strRs232Type = g_VarList[INDEX].sRs232Type;
  1385. // Rs232数据索引
  1386. pAnalog->m_nRs232Index = g_VarList[INDEX].nRs232Index;
  1387. // 辨別時間
  1388. pAnalog->m_nIdentifyTime = g_VarList[INDEX].nIdentifyTime;
  1389. // 重新檢測時間
  1390. pAnalog->m_nRedetectTime = g_VarList[INDEX].nRedetectTime;
  1391. //// 起始BIT位
  1392. //if( m_nStartBit >= 0 && m_nStartBit <= 64 )
  1393. //{
  1394. // pAnalog->m_nStartBit = m_nStartBit;
  1395. //}
  1396. //// 终止BIT位
  1397. //if( m_nEndBit >= 0 && m_nEndBit <= 64 )
  1398. //{
  1399. // pAnalog->m_nEndBit = m_nEndBit;
  1400. //}
  1401. pAnalog->m_strReserved1 = g_VarList[INDEX].sReserved1;
  1402. pAnalog->m_strReserved2 = "";
  1403. pAnalog->m_strReserved3 = "";
  1404. pAnalog->m_strReserved4 = "";
  1405. pAnalog->m_strReserved5 = "";
  1406. pAnalog->m_strReserved6 = "";
  1407. pAnalog->m_strReserved7 = "";
  1408. pAnalog->m_strReserved8 = "";
  1409. pAnalog->m_strReserved9 = "";
  1410. pAnalog->m_strReserved10 = "";
  1411. pAnalog->m_nReserved1 = g_VarList[INDEX].nReserved1;
  1412. pAnalog->m_nReserved2 = g_VarList[INDEX].nReserved2;
  1413. pAnalog->m_nReserved3 = g_VarList[INDEX].nReserved3;
  1414. pAnalog->m_nReserved4 = 0;
  1415. pAnalog->m_nReserved5 = 0;
  1416. pAnalog->m_nReserved6 = 0;
  1417. pAnalog->m_nReserved7 = 0;
  1418. pAnalog->m_nReserved8 = 0;
  1419. pAnalog->m_nReserved9 = 0;
  1420. pAnalog->m_nReserved10 = 0;
  1421. if( g_VarList[INDEX].bReserved1 == 1 )
  1422. {
  1423. pAnalog->m_bReserved1 = TRUE;
  1424. }
  1425. else if( g_VarList[INDEX].bReserved1 == 0 )
  1426. {
  1427. pAnalog->m_bReserved1 = FALSE;
  1428. }
  1429. if( g_VarList[INDEX].bReserved2 == 1 )
  1430. {
  1431. pAnalog->m_bReserved2 = TRUE;
  1432. }
  1433. else if( g_VarList[INDEX].bReserved2 == 0 )
  1434. {
  1435. pAnalog->m_bReserved2 = FALSE;
  1436. }
  1437. //pAnalog->m_bReserved1 = FALSE;
  1438. //pAnalog->m_bReserved2 = FALSE;
  1439. //pAnalog->m_bReserved3 = FALSE;
  1440. pAnalog->m_bReserved4 = FALSE;
  1441. pAnalog->m_bReserved5 = FALSE;
  1442. pAnalog->m_bReserved6 = FALSE;
  1443. pAnalog->m_bReserved7 = FALSE;
  1444. pAnalog->m_bReserved8 = FALSE;
  1445. pAnalog->m_bReserved9 = FALSE;
  1446. pAnalog->m_bReserved10 = FALSE;
  1447. pAnalog->m_pDevice = NULL;
  1448. pAnalog->m_fData = 0.0;
  1449. pVariantsManager->m_analog.Add(pAnalog);
  1450. }
  1451. return 1;
  1452. }
  1453. void CDlg_ZuTaiAdd::ChangeVarToPic( CString &sVarName )
  1454. {
  1455. CString sVarName1 = sVarName;
  1456. CString sVarName2 = sVarName;
  1457. sVarName1.MakeLower();
  1458. CString sTemp;
  1459. CString s1,s2,s3;
  1460. for( int i=0;i<1000;i++ )
  1461. {
  1462. if( g_VarList[i].sVarName=="" )
  1463. break;
  1464. sTemp = g_VarList[i].sVarName;
  1465. sTemp.MakeLower();
  1466. int nPos=sVarName1.Find( sTemp );
  1467. if( sVarName1.GetLength()>sTemp.GetLength() )
  1468. {
  1469. s3 = sVarName2.Right( sVarName2.GetLength()-sTemp.GetLength()-nPos );
  1470. if( s3[0]=='_' )
  1471. continue;
  1472. }
  1473. if( nPos!=-1 )
  1474. {
  1475. s1 = sVarName2.Left( nPos );
  1476. s3 = sVarName2.Right( sVarName2.GetLength()-sTemp.GetLength()-nPos );
  1477. sVarName = s1+sTemp+s3;
  1478. sVarName.Replace( sTemp,g_VarList[i].sVarNameTemp );
  1479. m_bChangeVarToPic = true;
  1480. break;
  1481. }
  1482. }
  1483. if( !m_bChangeVarToPic )
  1484. {
  1485. CString str;
  1486. str.Format( "%s",sVarName );
  1487. AfxMessageBox( str );
  1488. }
  1489. int a = 0;
  1490. }
  1491. bool CDlg_ZuTaiAdd::ChangePicRelevanceVar(CString sPicPath,CString sPicName )
  1492. {
  1493. char PathScr[_MAX_PATH] = {0};
  1494. strcat(PathScr, g_strDirectory);
  1495. strcat(PathScr,"\\");
  1496. strcat(PathScr, _LIBRARY);
  1497. strcat(PathScr,"画面\\");
  1498. strcat(PathScr, sPicPath );
  1499. CString sTemp,sBack=".view";
  1500. //sTemp = sPicName.Left( sPicName.GetLength()-sBack.GetLength() );
  1501. //sPicName.Format( "%s[%d]%s",sTemp,nDevIndex,sBack );
  1502. char PathDes[_MAX_PATH] = {0};
  1503. strcat(PathDes, g_strDirectory);
  1504. strcat(PathDes,"\\");
  1505. strcat(PathDes, _PICTUREDIR);
  1506. strcat(PathDes, sPicName );
  1507. if( !PathFileExists( PathScr ) )
  1508. return false;
  1509. if( PathFileExists( PathDes ) )
  1510. DeleteFile( PathDes );
  1511. else
  1512. {
  1513. CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  1514. pMainFrm->m_wndTree.InsertItem( sPicName.Left(sPicName.GetLength()-sBack.GetLength()), 1, 1, pMainFrm->m_wndTree.GetRootItem() );
  1515. }
  1516. CopyFile( PathScr,PathDes,false );
  1517. //////////////////////////////////////////////////////////////
  1518. CDrawObjList _ObjList;
  1519. BYTE m_Type;
  1520. CSize m_sizePic;
  1521. CSize m_sizeGrid;
  1522. BOOL m_bGrid;
  1523. COLORREF m_clrBack;
  1524. CFile file;
  1525. if(file.Open(PathDes,CFile::modeRead))
  1526. {
  1527. CArchive ar(&file,CArchive::load);
  1528. ar >> m_Type;
  1529. ar >> m_sizePic;
  1530. ar >> m_sizeGrid;
  1531. ar >> m_bGrid;
  1532. ar >> m_clrBack;
  1533. _ObjList.Serialize(ar);
  1534. if( !_ObjList.IsEmpty() )
  1535. {
  1536. for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
  1537. {
  1538. POSITION pos1 = pos ;
  1539. CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
  1540. if( ct->m_bVariant && ct->m_strCaption!="" )
  1541. ChangeVarToPic( ct->m_strCaption );
  1542. if( ct->m_strDynShow!="" )
  1543. ChangeVarToPic( ct->m_strDynShow );
  1544. if( ct->m_strDynForeCon!="" )
  1545. ChangeVarToPic( ct->m_strDynForeCon );
  1546. if( ct->m_strDynBackCon!="" )
  1547. ChangeVarToPic( ct->m_strDynBackCon );
  1548. if( ct->m_strDynLineCon!="" )
  1549. ChangeVarToPic( ct->m_strDynLineCon );
  1550. if( ct->m_strHoriPos!="" )
  1551. ChangeVarToPic( ct->m_strHoriPos );
  1552. if( ct->m_strHoriSize!="" )
  1553. ChangeVarToPic( ct->m_strHoriSize );
  1554. if( ct->m_strVertiPos!="" )
  1555. ChangeVarToPic( ct->m_strVertiPos );
  1556. if( ct->m_strVertiSize!="" )
  1557. ChangeVarToPic( ct->m_strVertiSize );
  1558. if( ct->m_strCurrentCaption!="" )
  1559. ChangeVarToPic( ct->m_strCurrentCaption );
  1560. if( ct->m_downAction.m_strVariant!="" )
  1561. ChangeVarToPic( ct->m_downAction.m_strVariant );
  1562. if( ct->IsKindOf( RUNTIME_CLASS(CDrawBitmap) ) )
  1563. {
  1564. if( ((CDrawBitmap *)ct)->m_strDynCondition!="" )
  1565. ChangeVarToPic( ((CDrawBitmap *)ct)->m_strDynCondition );
  1566. }
  1567. if( ct->IsKindOf( RUNTIME_CLASS(CDrawGif) ) )
  1568. {
  1569. if( ((CDrawGif *)ct)->m_strDynCondition!="" )
  1570. ChangeVarToPic( ((CDrawGif *)ct)->m_strDynCondition );
  1571. }
  1572. }
  1573. }
  1574. ///////////////////////////////////////
  1575. ar.Close();
  1576. file.Close();
  1577. }
  1578. if( PathFileExists( PathDes ) )
  1579. DeleteFile( PathDes );
  1580. CFile fileWrite;
  1581. if(fileWrite.Open(PathDes,CFile::modeCreate|CFile::modeWrite))
  1582. {
  1583. CArchive ar(&fileWrite,CArchive::store);
  1584. ar << m_Type;
  1585. ar << m_sizePic;
  1586. ar << m_sizeGrid;
  1587. ar << m_bGrid;
  1588. ar << m_clrBack;
  1589. _ObjList.Serialize(ar);
  1590. ar.Flush();
  1591. ar.Close();
  1592. fileWrite.Flush();
  1593. fileWrite.Close();
  1594. }
  1595. if(!_ObjList.IsEmpty())
  1596. {
  1597. for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
  1598. {
  1599. POSITION pos1 = pos ;
  1600. CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
  1601. _ObjList.RemoveAt(pos1);
  1602. delete ct;
  1603. }
  1604. _ObjList.RemoveAll();
  1605. ASSERT(_ObjList.IsEmpty());
  1606. }
  1607. return true;
  1608. }
  1609. void CDlg_ZuTaiAdd::OnClose()
  1610. {
  1611. // TODO: 在此添加消息处理程序代码和/或调用默认值
  1612. m_ExcelMain.Exit();
  1613. CDialog::OnClose();
  1614. }
  1615. void CDlg_ZuTaiAdd::ReadResource()
  1616. {
  1617. if( m_bReadResourceFinish )
  1618. return;
  1619. m_bReadResourceFinish = true;
  1620. OpenDevExcel();
  1621. ListDeviceTypes();
  1622. MyExpandTree( m_ctrlDevFolder.GetRootItem() );
  1623. UpdateData( false );
  1624. }