Project

General

Profile

Feature #3478 » cctvC3Plug.cpp

yufeng wu, 09/11/2024 03:14 PM

 
1
// cctvC3Plug.cpp: implementation of the CPac3Plug class.
2
//
3
//////////////////////////////////////////////////////////////////////
4

    
5
#include "stdafx.h"
6
#include "cctvC3Plug.h"
7

    
8
#include "se_rbac.h"
9
#include "se_dcedef.h"
10
#include "se_rbacdef.h"
11
#include "se_ddbc.h"
12
#include "se_btl.h"
13
#include "se_rdb.h"
14
#include <string.h>
15

    
16
//#include "se_btl.h"
17

    
18
#ifdef _DEBUG
19
#undef THIS_FILE
20
static char THIS_FILE[]=__FILE__;
21
#define new DEBUG_NEW
22
#endif
23

    
24

    
25
//////////////////////////////////////////////////////////////////////
26

    
27
ScreenItemNames ScreenItemNameArray[] = {
28
    {"F5012_SCR1GROUPCODE", "F5012_SCR1CAMERACODE"},
29
    {"F5012_SCR2GROUPCODE", "F5012_SCR2CAMERACODE"},
30
    {"F5012_SCR3GROUPCODE", "F5012_SCR3CAMERACODE"},
31
    {"F5012_SCR4GROUPCODE", "F5012_SCR4CAMERACODE"},
32
	{"F5012_SCR5GROUPCODE", "F5012_SCR5CAMERACODE"},
33
	{"F5012_SCR6GROUPCODE", "F5012_SCR6CAMERACODE"},
34
	{"F5012_SCR7GROUPCODE", "F5012_SCR7CAMERACODE"},
35
	{"F5012_SCR8GROUPCODE", "F5012_SCR8CAMERACODE"}
36
};
37
int ScreenItemNameCount = sizeof(ScreenItemNameArray) / sizeof(ScreenItemNames);    
38

    
39

    
40
//////////////////////////////////////////////////////////////////////
41

    
42
extern "C" __declspec(dllexport) void UpdateCamerasByGroup(int group_index, LPCameraDescArray pCamera, void *pPlugin)
43
{
44
    if (NULL == pCamera || group_index < 0)
45
        return;
46
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
47
	if (NULL == pPlug)
48
		return;
49
    CameraDescArray_Init(pCamera);
50

    
51
	pPlug->GetCurrentGroupCameras(pPlug->m_group[group_index].code);
52
	if (pPlug->m_curCameraNum > 0)
53
    {
54
		pCamera->cameraNum = pPlug->m_curCameraNum;
55
		pCamera->cameras = new CameraDesc[pPlug->m_curCameraNum];
56
		for (int i = 0; i<pPlug->m_curCameraNum; i++)
57
        {
58
			CameraDesc_Copy(pCamera->cameras[i], pPlug->m_curCamera[i].desc);
59
        }
60
    }
61
    
62
    return;
63
}
64

    
65
extern "C" __declspec(dllexport) int UpdateScreenInfo(LPScreenSet lpScreenSet, void *pPlugin)
66
{
67
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
68
	if (NULL == pPlug)
69
		return 0;
70

    
71
    if (NULL == lpScreenSet)
72
        return 0;
73

    
74
	pPlug->m_log->WriteFmtStrWithTime_L3("[UpdateScreenInfo] >>> screenNum: %d, screenIndex: %d groupIndex: %d",
75
                                                   lpScreenSet->screenNum, lpScreenSet->screenIndex, lpScreenSet->screen.groupIndex);
76
    if ( (lpScreenSet->screenNum != 1 && lpScreenSet->screenNum != MaxNum_Screen && lpScreenSet->screenNum != 4 && lpScreenSet->screenNum != 5 && lpScreenSet->screenNum != 6 && lpScreenSet->screenNum != 7 ) ||
77
        lpScreenSet->screen.groupIndex < 0 || lpScreenSet->screenIndex < 0 || lpScreenSet->screenIndex > 7)
78
	{
79
		int a = lpScreenSet->screenNum;
80
		int b = lpScreenSet->screen.groupIndex;
81
		int c = lpScreenSet->screenIndex ;
82
        return 0;
83
	}
84

    
85
	return pPlug->Update_Screen(lpScreenSet);
86
}
87

    
88
extern "C" __declspec(dllexport) int AddDisplayMode(LPDisplayModeInfo lpDisplayMode, void *pPlugin)
89
{
90
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
91
	if (NULL == pPlug)
92
		return 0;
93
    
94
	return pPlug->InsertDisplayMode(lpDisplayMode);
95
}
96

    
97
extern "C" __declspec(dllexport) int ModifyDisplayMode(LPDisplayModeInfo lpDisplayMode, void *pPlugin)
98
{
99
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
100
	if (NULL == pPlug)
101
		return 0;
102
    
103
	return pPlug->Update_DisplayMode(lpDisplayMode);
104
}
105

    
106
extern "C" __declspec(dllexport) int RemoveDisplayMode(int list_displaymode_index, void *pPlugin)
107
{
108
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
109
	if (NULL == pPlug)
110
		return 0;
111
    
112
	return pPlug->DeleteDisplayMode(list_displaymode_index);
113
}
114

    
115
extern "C" __declspec(dllexport) int UpdateCurDisplayInfo(LPDisplayCurInfo lpDisplayCurInfo, bool bDisplayMode, bool isCollectedDispMode, bool bNeedUpdateMonitorInfo,void *pPlugin)
116
{
117
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
118
	if (NULL == pPlug)
119
		return 0;
120
    
121
	return pPlug->Update_CurDisplayInfo(lpDisplayCurInfo, bDisplayMode, isCollectedDispMode, bNeedUpdateMonitorInfo);
122
}
123

    
124
extern "C" __declspec(dllexport) int AddFavorite(LPFavoriteInfo lpFavorite, void *pPlugin)
125
{
126
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
127
	if (NULL == pPlug)
128
		return 0;
129

    
130
	return pPlug->InsertFavorite(lpFavorite);
131
}
132

    
133
extern "C" __declspec(dllexport) int UpdateFavorite(LPFavoriteInfo lpFavorite, void *pPlugin)
134
{
135
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
136
	if (NULL == pPlug)
137
		return 0;
138
    
139
	return pPlug->Update_Favorite(lpFavorite);
140
}
141

    
142
extern "C" __declspec(dllexport) int RemoveFavorite(int list_favorite_index, void *pPlugin)
143
{
144
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
145
	if (NULL == pPlug)
146
		return 0;
147

    
148
	return pPlug->DeleteFavorite(list_favorite_index);
149
}
150

    
151
extern "C" __declspec(dllexport) int OperateOnCamera(LPScreenSet lpScreenSet, OperTypeCamera oper_type, int nMouseState, void * value, void *pPlugin)
152
{
153
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
154
	if (NULL == pPlug)
155
		return 0;
156

    
157
	return pPlug->OperateCamera(lpScreenSet, oper_type, nMouseState, value);
158
}
159

    
160
extern "C" __declspec(dllexport) int ScanRoundMode(LPScreenSet lpScreenSet, OperTypeCamera oper_type, void * value, void *pPlugin)
161
{
162
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
163
	if (NULL == pPlug)
164
		return 0;
165
    
166
	return pPlug->RoundModeScan(lpScreenSet, oper_type, value);
167
}
168

    
169
extern "C" __declspec(dllexport) BOOL UpdateScreenInfoByDevNumber(LPScreenInfo lpScreenInfo, void *pPlugin)
170
{
171
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
172
	if (NULL == pPlug)
173
		return FALSE;
174
    
175
	return pPlug->UpdateScreenInfoByDevID(lpScreenInfo);
176
}
177

    
178
extern "C" __declspec(dllexport) void UpdateUiState(void *pPlugin)
179
{
180
	CPlugCCTVC3 *pPlug = (CPlugCCTVC3 *)pPlugin;
181
	if (NULL == pPlug)
182
		return;
183
	pPlug->getOtherDispatherMonitorInfo();
184

    
185
	if (NULL != pPlug->m_hDll)
186
	{
187
	//	pPlug->m_log->WriteFmtStrWithTime_L3("TimerProc[]");
188
		UIDLL_AutoRefresh AutoRefresh = (UIDLL_AutoRefresh)GetProcAddress(pPlug->m_hDll, "AutoRefresh");
189
		if (NULL != AutoRefresh)
190
		{
191
			for (int k = 0; k< MaxNum_Dispatch - 1; k++)
192
			{
193
				pPlug->m_otherInitParam[k].groupArr = NULL;
194
				pPlug->m_otherInitParam[k].plugFuncs = &pPlug->m_plugFuncs;
195
				pPlug->m_otherInitParam[k].displayInfo = &pPlug->m_display;
196
				//
197
				pPlug->m_otherInitParam[k].curDisplay = &pPlug->m_displayInfoArry[k]; //??ǰ??¼?û????ӵ???Ļ??Ϣ?????????ӵ?ÿ??????ͷ?? deviceNumber????š???????17????ӯ????1?????????ӵ???Ļ????
198
				pPlug->m_otherInitParam[k].displayModeNum = NULL;
199
				pPlug->m_otherInitParam[k].displaymode = NULL;
200
				pPlug->m_otherInitParam[k].favoriteNum = NULL;
201
				pPlug->m_otherInitParam[k].favorite = NULL;
202
			}
203

    
204
			AutoRefresh(pPlug->m_otherInitParam, MaxNum_Dispatch - 1, pPlug->m_hWndFather);
205
		}
206

    
207
	}
208
}
209

    
210
//////////////////////////////////////////////////////////////////////
211
// Construction/Destruction
212

    
213
CPlugCCTVC3::CPlugCCTVC3(LPVOID lpParam)
214
: m_hDll(NULL), m_bScanActively(FALSE)
215
{
216
    m_log = new Logger("CCTVC3", "plugin_cctvC3.log");
217

    
218
    m_curCameraNum = 0;
219
    m_curCamera = NULL;
220

    
221
	m_isLevel2 = false;	
222

    
223
	for(int i=0;i<MaxNum_Dispatch-1; i++)
224
	{
225
		//DisplayCurInfo curInfo;
226
		//m_displayInfoArry[i] = curInfo;
227

    
228
		DisplayCurInfo_Init(&m_displayInfoArry[i]);
229

    
230
		//InitParam newInitParam;
231
		//m_otherInitParam[i] = newInitParam;
232
		m_otherInitParam[i].groupArr = NULL;
233
		m_otherInitParam[i].plugFuncs = NULL;
234
		m_otherInitParam[i].displayInfo = NULL;
235
		//
236
		m_otherInitParam[i].curDisplay = NULL;
237
		m_otherInitParam[i].displayModeNum = NULL;
238
		m_otherInitParam[i].displaymode = NULL;
239
		m_otherInitParam[i].favoriteNum = NULL;
240
		m_otherInitParam[i].favorite = NULL;
241
	}
242

    
243
    // ??ʼ??Ȩ??????
244
    uint32 nPLevel[AOJ_K_MAX_CTRLPRIO];	// 0-Switch;1-PTZ;2-PA
245
    char szRoleName[256];
246
    RBAC_Initialize();
247
    AOJ_Initialize();
248
    RBAC_GetUserRoleDescription(NULL, NULL, NULL, szRoleName);
249
    RBAC_GetRolePLevel(szRoleName, nPLevel);
250
    m_nPLevel = nPLevel[1];
251

    
252
    m_log->WriteFmtStrWithTime_L2("Current ptz level: %d", m_nPLevel);
253
	//m_LastSendSec=m_LastSendMsec=0;
254

    
255
	//??ȡ???????????? yansx 2019-04-29
256
    GetCCTVAreaInfo();
257

    
258
    readIni();
259
}
260

    
261
CPlugCCTVC3::~CPlugCCTVC3()
262
{
263
    if (NULL != m_curCamera)
264
    {
265
        delete [] m_curCamera;
266
        m_curCamera = NULL;
267
    }
268

    
269
    if (NULL != m_hDll) {
270
        UIDLL_CloseDialog CloseDialog = (UIDLL_CloseDialog)GetProcAddress(m_hDll, "CloseDialog");
271
        if (NULL != CloseDialog)
272
            CloseDialog(m_hWndFather);
273
        FreeLibrary(m_hDll);
274
    }
275
    
276
//	if(m_nAutoRefreshTime != 0)
277
//	{
278
	//	::KillTimer(m_hWndFather,ID_TIMER);
279
//	}
280

    
281
    delete m_log;
282
}
283

    
284
/*
285
void CALLBACK AutoRefreshTimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent, DWORD dwTime)
286
{
287
	g_pCurPlugClass->getOtherDispatherMonitorInfo();
288

    
289
	if (NULL != g_pCurPlugClass->m_hDll)
290
	{
291
		g_pCurPlugClass->m_log->WriteFmtStrWithTime_L3("TimerProc[]");
292
		UIDLL_AutoRefresh AutoRefresh = (UIDLL_AutoRefresh)GetProcAddress(g_pCurPlugClass->m_hDll, "AutoRefresh");
293
        if (NULL != AutoRefresh)
294
		{
295
			for (int k=0; k< MaxNum_Dispatch - 1; k++)
296
			{
297
				g_pCurPlugClass->m_otherInitParam[k].groupArr = NULL;
298
				g_pCurPlugClass->m_otherInitParam[k].plugFuncs = &g_pCurPlugClass->m_plugFuncs;
299
				g_pCurPlugClass->m_otherInitParam[k].displayInfo = &g_pCurPlugClass->m_display;
300
				//
301
				g_pCurPlugClass->m_otherInitParam[k].curDisplay = &g_pCurPlugClass->m_displayInfoArry[k]; //??ǰ??¼?û????ӵ???Ļ??Ϣ?????????ӵ?ÿ??????ͷ?? deviceNumber????š???????17????ӯ????1?????????ӵ???Ļ????
302
				g_pCurPlugClass->m_otherInitParam[k].displayModeNum = NULL;
303
				g_pCurPlugClass->m_otherInitParam[k].displaymode = NULL;
304
				g_pCurPlugClass->m_otherInitParam[k].favoriteNum = NULL;
305
				g_pCurPlugClass->m_otherInitParam[k].favorite = NULL;
306
			}
307

    
308
			AutoRefresh(g_pCurPlugClass->m_otherInitParam, MaxNum_Dispatch - 1);
309
		}
310

    
311
    }
312
    
313
}*/
314

    
315
BOOL CPlugCCTVC3::Create(CWnd * fatherWnd, RECT rect, UINT id, UINT length, LPVOID pExtData)
316
{
317
    //CWnd::Create(NULL, NULL, WS_CHILD, CRect(0, 0, 0, 0), fatherWnd, id);	
318

    
319
    m_hWndFather = fatherWnd->m_hWnd;
320

    
321
	m_nLast4ScreenFocusIndex = 0;
322
	m_nLast4ScreenFocusIndex2 = 0;
323
	m_bSwitch4to1Screen = true;
324

    
325
    getExeFuncAddr();
326

    
327
    iniDBInfo();
328

    
329
    GroupDescArray grpArr;
330
    memset(&grpArr, 0, sizeof(GroupDescArray));
331
    if (m_groupNum > 0)
332
    {
333
        grpArr.groupNum = m_groupNum;//????վ????
334
        grpArr.groups = new GroupDesc[m_groupNum];
335
        for (int i=0; i<m_groupNum; i++)
336
        {
337
            strncpy(grpArr.groups[i].data, m_group[i].desc.data, MaxLen_DESC-1);
338
        }
339
    }
340

    
341
    DisplayModeInfo * pCurDispModeInfo = NULL;
342
    int nCnt_displaymode = m_listCurDisplaymode.GetCount();
343
    if (nCnt_displaymode > 0)
344
    {
345
        pCurDispModeInfo = new DisplayModeInfo[nCnt_displaymode];
346
        memset(pCurDispModeInfo, 0, sizeof(DisplayModeInfo)*nCnt_displaymode);
347
        transferCurDisplayModes(pCurDispModeInfo, nCnt_displaymode);
348
    }
349

    
350
    FavoriteInfo * pCurFavs = NULL;
351
    int nCnt_fav = m_listCurFav.GetCount();
352
    if (nCnt_fav > 0)
353
    {
354
        pCurFavs = new FavoriteInfo[nCnt_fav];
355
        memset(pCurFavs, 0, sizeof(FavoriteInfo)*nCnt_fav);
356
        transferCurFavorites(pCurFavs, nCnt_fav);
357
    }
358

    
359
    if (!m_useSDK)
360
    {
361
        memset(m_dllName, 0, 32*sizeof(char));
362
        strcpy(m_dllName, "cctvC3ui");
363
#ifdef _DEBUG
364
        strcat(m_dllName, "d.dll");
365
#else
366
        strcat(m_dllName, ".dll");
367
#endif
368
    }
369
    m_hDll = LoadLibrary(m_dllName);
370
    if (NULL == m_hDll)
371
        return FALSE;
372

    
373
    if (NULL != m_hDll) 
374
	{
375
        UIDLL_ShowDialog ShowDialog = (UIDLL_ShowDialog)GetProcAddress(m_hDll, "ShowDialog");
376
        if (NULL != ShowDialog) 
377
		{
378
            UISet_CCTV uiParam;
379
            uiParam.hParent = m_hWndFather;
380
			uiParam.freshTime = m_nAutoRefreshTime;
381
            uiParam.pos_x = rect.left;
382
            uiParam.pos_y = rect.top;
383
            uiParam.width = rect.right-rect.left;
384
            uiParam.height = rect.bottom-rect.top;
385

    
386
            RECT rectPlugin;
387
            fatherWnd->GetClientRect(&rectPlugin);
388
            uiParam.pos_y = (rectPlugin.bottom - rectPlugin.top) - rect.bottom;
389

    
390
            //COLORREF color1 = RGB(7, 54, 80);
391
            /*  ȡ??????ɫ???ԣ???????debug?汾??ԭ?򣬴??顣????
392
            CWnd * wndSvm = fatherWnd->GetParent();
393
            if (m_bConsistBackground && NULL != wndSvm)
394
            {
395
                HWND hSvm = wndSvm->m_hWnd;
396
                POINT pt1;
397
                pt1.x = uiParam.pos_x - 100;
398
                pt1.y = uiParam.pos_y - 100;
399
                ::ScreenToClient(hSvm, &pt1);
400
                HDC dcSvm = ::GetWindowDC(hSvm);
401
                color1 = ::GetPixel(dcSvm, pt1.x, pt1.y);
402
            }
403
            */
404
            uiParam.colorR = GetRValue(m_background);
405
            uiParam.colorG = GetGValue(m_background);
406
            uiParam.colorB = GetBValue(m_background);
407

    
408
            InitParam init_param;
409
            init_param.groupArr = &grpArr;  //վ̨??
410
            init_param.plugFuncs = &m_plugFuncs;
411
            init_param.displayInfo = &m_display;
412
            //
413
            init_param.curDisplay = &m_curDisplayInfo; //??ǰ??¼?û????ӵ???Ļ??Ϣ?????????ӵ?ÿ??????ͷ?? deviceNumber????š???????17????ӯ????1?????????ӵ???Ļ????
414
            init_param.displayModeNum = nCnt_displaymode;
415
            init_param.displaymode = pCurDispModeInfo;
416
            init_param.favoriteNum = nCnt_fav;
417
            init_param.favorite = pCurFavs;
418
			
419
			for (int k=0; k< MaxNum_Dispatch - 1; k++)
420
			{
421
				m_otherInitParam[k].groupArr = &grpArr;
422
				m_otherInitParam[k].plugFuncs = &m_plugFuncs;
423
				m_otherInitParam[k].displayInfo = &m_display;
424
				//
425
				m_otherInitParam[k].curDisplay = &m_displayInfoArry[k]; //??ǰ??¼?û????ӵ???Ļ??Ϣ?????????ӵ?ÿ??????ͷ?? deviceNumber????š???????17????ӯ????1?????????ӵ???Ļ????
426
				m_otherInitParam[k].displayModeNum = nCnt_displaymode;
427
				m_otherInitParam[k].displaymode = pCurDispModeInfo;
428
				m_otherInitParam[k].favoriteNum = nCnt_fav;
429
				m_otherInitParam[k].favorite = pCurFavs;
430
			}
431
            //
432
            ShowDialog(&uiParam, &init_param, &m_cctvAreaSet, m_otherInitParam, MaxNum_Dispatch - 1,this);
433
        }
434

    
435
		
436
		//??һ?ν????????Ժ?????һ??Timer ÿ??һ??ʱ?䣬?Զ?ȥȡһ??????????Ա?ķ?????Ϣ??Ȼ??ˢ?? Yansx 2019-09-05
437
	/*	m_log->WriteFmtStrWithTime_L2("Auto refresh time: %d second", m_nAutoRefreshTime);
438
		if(m_nAutoRefreshTime != 0)
439
		{
440
			::SetTimer(m_hWndFather, ID_TIMER, m_nAutoRefreshTime*1000,(TIMERPROC)AutoRefreshTimerProc); 
441
		}*/
442
    }
443

    
444
    if (NULL != pCurFavs)
445
        delete [] pCurFavs;
446
    if (NULL != pCurDispModeInfo)
447
        delete [] pCurDispModeInfo;
448
    if (NULL != grpArr.groups)
449
        delete [] grpArr.groups;
450

    
451
    return TRUE;
452
}
453

    
454
BOOL CPlugCCTVC3::MovePlugRect(RECT rect)
455
{
456
	return TRUE;
457
}
458

    
459
void CPlugCCTVC3::Draw(CDC *pDC, RECT rect)
460
{
461
}
462

    
463
BOOL CPlugCCTVC3::ShowProperty(void *pData, int *len)
464
{
465
	return TRUE;
466
}
467

    
468
void * CPlugCCTVC3::GetExData()
469
{
470
	return NULL;
471
}
472

    
473
UINT CPlugCCTVC3::GetExDataLength()
474
{
475
	return 0;
476
}
477

    
478
/*
479
void CPlugCCTVC3::SetParam(int paramID, void *pData)
480
{
481
    if (0 != paramID)
482
        return;
483

    
484
    if (NULL != m_pDlg)
485
        m_pDlg->SetParam(pData);
486
}
487
*/
488

    
489
void CPlugCCTVC3::getExeFuncAddr()
490
{
491
    m_plugFuncs.updateCamerasByGroup = UpdateCamerasByGroup;
492
    m_plugFuncs.updateScreenInfo = UpdateScreenInfo;
493
    m_plugFuncs.addDisplayMode = AddDisplayMode;
494
    m_plugFuncs.removeDisplayMode = RemoveDisplayMode;
495
    m_plugFuncs.updateCurDisplay = UpdateCurDisplayInfo;
496
    m_plugFuncs.addFavorite = AddFavorite;
497
    m_plugFuncs.updateFavorite = UpdateFavorite;
498
    m_plugFuncs.removeFavorite = RemoveFavorite;
499
    m_plugFuncs.operateCamera = OperateOnCamera;
500
    m_plugFuncs.scanRoundMode = ScanRoundMode;
501
    m_plugFuncs.updateScreenInfoByDevID = UpdateScreenInfoByDevNumber;
502
	m_plugFuncs.modifyDisplayMode = ModifyDisplayMode;
503
	m_plugFuncs.updateUiState = UpdateUiState;
504
}
505

    
506
void CPlugCCTVC3::readIni()
507
{
508
	m_nPLevel2 = -1;	//??ʼ??m_nPLevel2Ϊ-1
509
    memset(&m_display, 0, sizeof(DisplayInfo));
510
    m_useSDK = FALSE;
511
    memset(m_dllName, 0, 32*sizeof(char));
512

    
513
	memset(m_decode, 0, sizeof(m_decode));
514

    
515
    char *home = getenv("SEROOT");
516
    if (NULL == home)
517
        return;
518
    char filename[256] = {0};
519
    sprintf(filename, "%s%s", home, "\\cfg\\C3cctvUi.ini");
520
    
521
    CReadConf readconf;
522

    
523
    int nDispatchNum = readconf.ReadLong("General", "dispatchCount", filename, "0");
524
    if (nDispatchNum <= 0)
525
        return;
526
    m_Line = (unsigned char)readconf.ReadLong("General", "metro", filename, "0");
527
    m_display.count = nDispatchNum;
528
    m_bConsistBackground = readconf.ReadBool("General", "bgConsistent", filename, "0");
529
    int color_r = readconf.ReadLong("General", "background_red", filename, "0");
530
    int color_g = readconf.ReadLong("General", "background_green", filename, "0");
531
    int color_b = readconf.ReadLong("General", "background_blue", filename, "0");
532
    m_background = RGB(color_r, color_g, color_b);
533

    
534
	m_nAutoRefreshTime = readconf.ReadLong("General", "autoRefreshSecond", filename, "0");//?Զ?ˢ??????????ϯλ?????? ????????Ĭ?ϲ????Զ?ˢ??
535
	m_nAutoRefreshTime = ((m_nAutoRefreshTime<5) && (m_nAutoRefreshTime>0) || m_nAutoRefreshTime<0 )?5:m_nAutoRefreshTime;//С??5?룬ˢ??Ƶ??̫?졣
536

    
537
	m_nDigAnaCCTVtype = (unsigned char)readconf.ReadLong("General", "DigAnaCCTVtype", filename, "0");
538

    
539
    int ifUseSDK = readconf.ReadLong("General", "useSDK", filename, "0");
540
    readconf.ReadString("General", "uiLibrary", m_dllName, filename, "");
541
    if (ifUseSDK == 1 && strlen(m_dllName) > 0)
542
        m_useSDK = TRUE;
543

    
544
    int * disp_index = new int[nDispatchNum];
545
    int * disp_plevel = new int[nDispatchNum];
546
    int i, j=0;
547
    char sectionName[16];
548
    for (i=0; i<nDispatchNum; i++)
549
    {
550
        memset(sectionName, 0, 16);
551
        sprintf(sectionName, "dispatch%d", i+1);
552

    
553
		int nPtzlevel2 = readconf.ReadLong(sectionName, "ptzlevel2", filename, "-1");
554
		if(nPtzlevel2 >= 0)	//?????ȡ??ptzLevel2??ֵ
555
		{
556
			m_nPLevel2 = nPtzlevel2;
557
		}
558
        int nPtzlevel = readconf.ReadLong(sectionName, "ptzlevel", filename, "-1");
559
        if (nPtzlevel < 0) {
560
            m_display.count--;
561
            continue;
562
        }
563
        disp_index[j] = i;
564
        disp_plevel[j] = nPtzlevel;
565
        j++;
566
    }
567

    
568
	// ??1????Զ?ǵ?ǰ????
569
	//     for (i=1; i<nDispatchNum-1; i++)
570
    for (i=1; i<nDispatchNum; i++)
571
    {
572
        if (disp_plevel[i] == (int)m_nPLevel) {
573
            int nTemp = disp_index[0];
574
            disp_index[0] = disp_index[i];
575
            disp_index[i] = nTemp;
576
            
577
            disp_plevel[i] = disp_plevel[0];
578
            disp_plevel[0] = m_nPLevel;
579
            break;
580
        }
581
    }
582

    
583
    // ????ptz levelֵ??С????????????
584
    nDispatchNum = m_display.count;
585
    for (i=1; i<nDispatchNum-1; i++)
586
    {
587
        for (j=i+1; j<nDispatchNum-1; j++)
588
        {
589
            if (disp_plevel[i] > disp_plevel[j]) {
590
                int nTemp = disp_index[i];
591
                disp_index[i] = disp_index[j];
592
                disp_index[j] = nTemp;
593
				
594

    
595
                nTemp = disp_plevel[i];
596
                disp_plevel[i] = disp_plevel[j];
597
                disp_plevel[j] = nTemp;
598
            }
599
        }
600
    }
601

    
602
	if(m_nPLevel2 < 0)	//???û?ж?ȡ??ptzLevel2??ֵ,??????ϯλ??ptzLevel??ֵ??m_nPLevel2
603
	{
604
		if(nDispatchNum > 1)
605
			m_nPLevel2 = disp_plevel[1];
606
		else
607
			m_nPLevel2 = m_nPLevel;
608
	}
609

    
610
	for (i=0; i<nDispatchNum; i++)
611
	{
612
		m_dispPlevel[i] = disp_plevel[i];
613
	}
614
   
615
	//char t_sect[16];
616
    // ??ȡ??????Ϣ
617
    for (i=0; i<nDispatchNum; i++)
618
    {
619
        m_display.dispatch[i].ptzLevel = disp_plevel[i];
620
        
621
        memset(sectionName, 0, 16);
622
        sprintf(sectionName, "dispatch%d", disp_index[i]+1);
623
        
624
        readconf.ReadString(sectionName, "desc", m_display.dispatch[i].desc, filename, "");
625
        
626
        readconf.ReadString(sectionName, "code", m_display.dispatch[i].code, filename, "");
627
		readconf.ReadString(sectionName, "code2", m_display.dispatch[i].code2, filename, "");
628
		/*
629
		for(int j=0;j<4;j++)//WYF 20190127
630
		{
631
			memset(t_sect, 0, 16);
632
			sprintf(t_sect, "SplitScreen%d", j+1);
633
			readconf.ReadString(sectionName, t_sect, m_display.dispatch[i].SplitCode[j], filename, m_display.dispatch[i].code);
634
		}//WYF 20190127
635
		*/
636
		////////ȡ???????????? Yansx 20190129
637
		char decodeName[MaxLen_DeviceNumber];
638
		int nSplitScreenNum = readconf.ReadLong(sectionName, "SplitScreenNum", filename, "4");//Ĭ??Ϊ4??
639
		if(i == 0)
640
		{
641
			m_splitScreenNum = nSplitScreenNum;
642
		}
643
		m_screenNumArry[i] = nSplitScreenNum;	//??ȡÿ??????ϯλ?ķ?????
644
		if(nSplitScreenNum != 0)
645
		{
646
			char splitName[16];
647
			for(int nDecode=0; nDecode<nSplitScreenNum; nDecode++)
648
			{
649
				memset(splitName, 0, 16);
650
				sprintf(splitName, "SplitScreen%d", nDecode+1);
651
				readconf.ReadString(sectionName, splitName, decodeName, filename, "");
652
				strcpy(m_decode[i][nDecode],decodeName);
653
			}
654
		}
655
        /////
656
    }
657

    
658
    delete [] disp_index;
659
    delete [] disp_plevel;
660
}
661

    
662

    
663
//////////////////////////////////////////////////////////////////////
664
//CCTV????????Ϣ?????ݿ??????ȡ,????ͨ??ini
665

    
666
void CPlugCCTVC3::GetCCTVAreaInfo() //??ȡCCTV??????Ϣ
667
{
668
	CSE_DBOption dboption;
669
	char cmdbuf[256];
670
	
671
	memset(&m_cctvAreaSet, 0, sizeof(CCTVAreaParamSet));
672
	
673
    strcpy(cmdbuf, "select F1002_BAYAREANO,F1002_BAYAREACODE,F1002_BAYAREADESC,F1002_ASSIGNMENT from SEMODEL.TB1002_BAYAREA \
674
		where F1002_BAYAREA = 5 and rownum < 7 order by F1002_ASSIGNMENT");//=5 ??ʾ??CCTV???? ???ֵ?ǹ̶??? Ŀǰ????ֻ֧?????6??????
675
	int ret=dboption.BeginSelectRcdSet(cmdbuf);
676
	
677
	if(ret!=SEDB_SUCCESS)
678
		return;
679
	
680
    int count= dboption.GetRcdCount();
681
	if(count<=0)
682
	{
683
		dboption.EndSelectRcdSet();
684
		return ;
685
	}
686
	m_cctvAreaSet.nTotalArea = count;
687
    for (int i=0; i<count; i++)
688
    {
689
		m_cctvAreaSet.cctvAreaList[i].nAreaNo = (int)dboption.GetIntVal(i,0);
690
        strncpy(m_cctvAreaSet.cctvAreaList[i].areaCode, (char *)dboption.GetColVal(i,1), MaxLen_CODE-1);
691
        strncpy(m_cctvAreaSet.cctvAreaList[i].desc, (char *)dboption.GetColVal(i,2), MaxLen_DESC-1);
692
        m_cctvAreaSet.cctvAreaList[i].nCodeIndex = (int)dboption.GetIntVal(i,3);
693
    }
694
	
695
    dboption.EndSelectRcdSet();
696
}
697
//////
698

    
699
void CPlugCCTVC3::iniDBInfo()
700
{
701
    m_groupNum = 0;
702
    memset(m_group, 0, sizeof(GroupInfo)*MaxNum_Group);
703
    
704
    SEDB_CMDINFO cmdinfo;
705
    char cmdbuf[1256] = {0};
706
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB1001_GROUP");
707
    strcpy(cmdbuf, "select ");
708
    char * fieldCodes[] = {"F1001_GROUPCODE", "F1001_GROUPDESC", "F1001_GROUPNO"};//WYF 20190425 add field "F1001_GROUPNO"
709
    int i;
710
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
711
        strcat(cmdbuf, fieldCodes[i]);
712
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
713
            strcat(cmdbuf, ",");
714
    }
715
    strcat(cmdbuf, " from ");
716
    strcat(cmdbuf, cmdinfo.table);
717
    strcat(cmdbuf, " where F1005_DEVTYPEID=200 or F1005_DEVTYPEID=201" );//??????order by F1001_GROUPNO");//WYF 20190415 only 200????-201??վ
718
    
719
    CSE_DBOption dboption;
720
    dboption.BeginSelectRcdSet(cmdbuf);
721
    m_groupNum = dboption.GetRcdCount();
722
    if (m_groupNum <= 0) {
723
        dboption.EndSelectRcdSet();
724
        return;
725
    }
726
    m_groupNum = m_groupNum > MaxNum_Group ? MaxNum_Group : m_groupNum;
727
    for (i=0; i<m_groupNum; i++)
728
    {
729
        strncpy(m_group[i].code, (char *)dboption.GetColVal(i,0), MaxLen_CODE-1);
730
        strncpy(m_group[i].desc.data, (char *)dboption.GetColVal(i,1), MaxLen_DESC-1);
731
        m_group[i].groupno=dboption.GetIntVal(i,2);//WYF 20190425
732
    }
733
    dboption.EndSelectRcdSet();
734

    
735
    getMonitorNumberForDispatch();//?õ???????Ա??Ӧ?ļ???????Ϣ
736

    
737
//     GetCurrentGroupCameras(m_group[0].code);
738

    
739
    getDispatherFavorites();//??ǰ????Ա???ղ???Ϣ
740
    
741
    getDispatherDisplayMode();//??ǰ????Ա????ʾģʽ??Ϣ
742

    
743
    getDispatherMonitorInfo();//??ǰ????Ա?ļ???????Ϣ
744

    
745
	getOtherDispatherMonitorInfo();//????????Ա?ļ???????Ϣ
746
}
747

    
748
void CPlugCCTVC3::getDispatherFavorites()
749
{
750
    char tmpV[64] = {0};
751
    sprintf(tmpV, "%d", m_nPLevel);
752

    
753
    SEDB_CMDINFO cmdinfo;
754
    char cmdbuf[1256] = {0};
755
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB5015_CCTVFAV");
756
    strcpy(cmdbuf, "select ");
757
    char * fieldCodes[] = {"F5015_NO", "F4009_POINTCODE", "F5015_DESC"};
758
    int i;
759
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
760
        strcat(cmdbuf, fieldCodes[i]);
761
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
762
            strcat(cmdbuf, ",");
763
    }
764
    strcat(cmdbuf, " from ");
765
    strcat(cmdbuf, cmdinfo.table);
766
    strcat(cmdbuf, " where F0101_PTZPLEVEL=");
767
    strcat(cmdbuf, tmpV);
768
    strcat(cmdbuf, " order by F5015_NO");
769
    
770
    CSE_DBOption dboption;
771
    dboption.BeginSelectRcdSet(cmdbuf);
772
    int nCount = dboption.GetRcdCount();
773
    if (nCount <= 0) {
774
        dboption.EndSelectRcdSet();
775
        m_log->WriteFmtStrWithTime_L3("[getDispatherFavorites] : failed to find records (ptzlevel = %d) in table TB5015_CCTVFAV", m_nPLevel);
776
        return;
777
    }
778
    FavoriteList tmpFavorList;
779
    for (i=0; i<nCount; i++)
780
    {
781
        FavoriteInfo item;
782
        FavoriteInfo_Init(&item);
783
        item.index = (int)dboption.GetIntVal(i,0);
784
        strncpy(item.desc, (char *)dboption.GetColVal(i,2), MaxLen_DESC-1);
785
        strncpy(item.screen.camera_desc.code, (char *)dboption.GetColVal(i,1), MaxLen_CODE-1);
786
        tmpFavorList.AddTail(item);
787
    }
788
    dboption.EndSelectRcdSet();
789

    
790
    POSITION pos = tmpFavorList.GetHeadPosition();
791
    while (pos != NULL) {
792
        FavoriteInfo item = tmpFavorList.GetNext(pos);
793
        getScreenInfo( &(item.screen) );
794
        m_listCurFav.AddTail(item);
795
    }
796
}
797

    
798
void CPlugCCTVC3::getDispatherDisplayMode()
799
{
800
    char tmpV[64] = {0};
801
    sprintf(tmpV, "%d", m_nPLevel);
802

    
803
    DispmodeList tmpList;
804
    
805
    SEDB_CMDINFO cmdinfo;
806
    char cmdbuf[1256] = {0};
807
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB5014_CCTVDISPLAYMODE");
808
    strcpy(cmdbuf, "select ");
809
    char * fieldCodes[] = {"F5014_NO", "F5014_DESC", "F5012_NO"};
810
    int i;
811
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
812
        strcat(cmdbuf, fieldCodes[i]);
813
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
814
            strcat(cmdbuf, ",");
815
    }
816
    strcat(cmdbuf, " from ");
817
    strcat(cmdbuf, cmdinfo.table);
818
    strcat(cmdbuf, " where F0101_PTZPLEVEL=");
819
    strcat(cmdbuf, tmpV);
820
    strcat(cmdbuf, " order by F5014_NO");
821
    
822
    CSE_DBOption dboption;
823
    dboption.BeginSelectRcdSet(cmdbuf);
824
    int nCount = dboption.GetRcdCount();
825
    if (nCount <= 0) {
826
        dboption.EndSelectRcdSet();
827
        m_log->WriteFmtStrWithTime_L3("[getDispatherDisplayMode] : failed to find records (ptzlevel = %d) in table TB5014_CCTVDISPLAYMODE", m_nPLevel);
828
        return;
829
    }
830
    for (i=0; i<nCount; i++)
831
    {
832
        DisplayModeInfo item;
833
        DisplayModeInfo_Init(&item);
834
        item.index = (int)dboption.GetIntVal(i,0);
835
        strncpy(item.desc, (char *)dboption.GetColVal(i,1), MaxLen_DISPLAYMODENAME-1);//MaxLen_DESC
836
        item.monitor.index = (int)dboption.GetIntVal(i,2);
837
        tmpList.AddTail(item);
838
    }
839
    dboption.EndSelectRcdSet();
840

    
841

    
842
    POSITION pos = tmpList.GetHeadPosition();
843
    while (pos != NULL) {
844
        DisplayModeInfo item = tmpList.GetNext(pos);
845
        getMonitorInfoItem( &(item.monitor) );
846
        m_listCurDisplaymode.AddTail(item);
847
    }
848
}
849

    
850
//??ȡ???ȼ?????Ϣ
851
void CPlugCCTVC3::getDispatherMonitorInfo()
852
{
853
    DisplayCurInfo_Init(&m_curDisplayInfo);
854
	m_curDisplayInfo.splitScreenNum = m_splitScreenNum;//??仰?????????ߣ???????ڲ?ѯ???ݿ?֮?󣬵????ݿ?Ϊ?գ??ͻ?return???޷???ֵ????ɽ??????
855

    
856
    char tmpV[64] = {0};
857
    sprintf(tmpV, "%d", m_nPLevel);
858
    
859
    SEDB_CMDINFO cmdinfo;
860
    char cmdbuf[1256] = {0};
861
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB5016_CCTVCURINFO");
862
    strcpy(cmdbuf, "select ");
863
    char * fieldCodes[] = {"F5016_NO", "F5012_NO"};
864
    int i;
865
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
866
        strcat(cmdbuf, fieldCodes[i]);
867
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
868
            strcat(cmdbuf, ",");
869
    }
870
    strcat(cmdbuf, " from ");
871
    strcat(cmdbuf, cmdinfo.table);
872
    strcat(cmdbuf, " where F0101_PTZPLEVEL=");
873
    strcat(cmdbuf, tmpV);
874
    
875
    CSE_DBOption dboption;
876
    dboption.BeginSelectRcdSet(cmdbuf);//???ݿ??л?ȡ??ǰ??ɫ??????ͷ???? -lilei
877
    int nCount = dboption.GetRcdCount();
878
    if (nCount <= 0) {
879
        dboption.EndSelectRcdSet();
880
        m_log->WriteFmtStrWithTime_L3("[getDispatherMonitorInfo] : failed to find record (ptzlevel = %d) in table TB5016_CCTVCURINFO", m_nPLevel);
881
        return;
882
    }
883
    m_curDisplayInfo.index = (int)dboption.GetIntVal(0,0);
884
    m_curDisplayInfo.monitor.index = (int)dboption.GetIntVal(0,1);
885

    
886
    dboption.EndSelectRcdSet();
887

    
888
    getMonitorInfoItem( &(m_curDisplayInfo.monitor) );
889
}
890

    
891
void CPlugCCTVC3::getOtherDispatherMonitorInfo()
892
{
893
//	DisplayCurInfo_Init(&m_curDisplayInfo);
894
//	UINT levelArry[4] = {1, 2, 3, 5};
895
	int mlength = sizeof(m_dispPlevel)/sizeof(m_dispPlevel[0]);
896
	for(int j=1; j< mlength; j++)
897
	{
898
		DisplayCurInfo_Init(&m_displayInfoArry[j-1]);
899
		m_displayInfoArry[j-1].splitScreenNum = m_screenNumArry[j];
900
	
901
		char tmpV[64] = {0};
902
		sprintf(tmpV, "%d", UINT(m_dispPlevel[j]));
903
    
904
		SEDB_CMDINFO cmdinfo;
905
		char cmdbuf[1256] = {0};
906
		sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB5016_CCTVCURINFO");
907
		strcpy(cmdbuf, "select ");
908
		char * fieldCodes[] = {"F5016_NO", "F5012_NO"};
909
		int i;
910
		for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
911
			strcat(cmdbuf, fieldCodes[i]);
912
			if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
913
				strcat(cmdbuf, ",");
914
		}
915
		strcat(cmdbuf, " from ");
916
		strcat(cmdbuf, cmdinfo.table);
917
		strcat(cmdbuf, " where F0101_PTZPLEVEL=");
918
		strcat(cmdbuf, tmpV);
919
    
920
		CSE_DBOption dboption;
921
		dboption.BeginSelectRcdSet(cmdbuf);//???ݿ??л?ȡ??ǰ??ɫ??????ͷ???? 
922
		int nCount = dboption.GetRcdCount();
923
		if (nCount <= 0) {
924
			dboption.EndSelectRcdSet();
925
		//	m_log->WriteFmtStrWithTime_L3("[getDispatherMonitorInfo] : failed to find record (ptzlevel = %d) in table TB5016_CCTVCURINFO", m_dispPlevel[j]);
926
			continue;
927
		}
928
		m_displayInfoArry[j-1].index = (int)dboption.GetIntVal(0,0);
929
		m_displayInfoArry[j-1].monitor.index = (int)dboption.GetIntVal(0,1);
930
		dboption.EndSelectRcdSet();
931
	
932
		getMonitorInfoItem( &(m_displayInfoArry[j-1].monitor) );
933
	}
934
}
935

    
936
void CPlugCCTVC3::getMonitorInfoItem(LPMonitorInfo pItem)
937
{
938
    if (NULL == pItem)
939
        return;
940
    int nIndex_Monitor = pItem->index;
941
    MonitorInfo_Init(pItem);
942
    pItem->index = nIndex_Monitor;
943

    
944
    char tmpV[64] = {0};
945
    sprintf(tmpV, "%d", pItem->index);
946
    
947
    SEDB_CMDINFO cmdinfo;
948
    char cmdbuf[1256] = {0};
949
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB5012_CCTVMONITORINFO");
950
    strcpy(cmdbuf, "select ");
951
    int i;
952
    strcat(cmdbuf, "F5012_SCREENCOUNT");
953
    for (i=0; i<ScreenItemNameCount; i++)
954
    {
955
        strcat(cmdbuf, ",");
956
        strcat(cmdbuf, ScreenItemNameArray[i].groupCode);
957
        strcat(cmdbuf, ",");
958
        strcat(cmdbuf, ScreenItemNameArray[i].camerCode);
959
    }
960
    strcat(cmdbuf, " from ");
961
    strcat(cmdbuf, cmdinfo.table);
962
    strcat(cmdbuf, " where F5012_NO=");
963
    strcat(cmdbuf, tmpV);
964
    
965
    CSE_DBOption dboption;
966
    dboption.BeginSelectRcdSet(cmdbuf);
967
    int nCount = dboption.GetRcdCount();
968
    if (nCount <= 0) {
969
        dboption.EndSelectRcdSet();
970
        m_log->WriteFmtStrWithTime_L3("[getMonitorInfoItem] : failed to find record (No=%d) in table TB5012_CCTVMONITORINFO", pItem->index);
971
        return;
972
    }
973

    
974
    pItem->screenNum = (int)dboption.GetIntVal(0, 0);
975
    if (pItem->screenNum > MaxNum_Screen )
976
        pItem->screenNum = MaxNum_Screen;
977

    
978
//	int nScreenNum = pItem->screenNum;
979
	int nScreenNum = MaxNum_ScreenColumn;
980

    
981
	if(m_curDisplayInfo.splitScreenNum == 8 || pItem->screenNum > MaxNum_ScreenColumn)	//?????Ļ??????4??????Ϊ??8????ϯλ
982
	{
983
		nScreenNum = MaxNum_Screen;
984
	}
985
    for (i=0; i<nScreenNum; i++)
986
    {
987
        char group_code[MaxLen_CODE] = {0};
988
        strncpy(group_code, (char *)dboption.GetColVal(0, 1+i*2), MaxLen_CODE-1);
989
        for (int k=0; k<m_groupNum; k++)
990
        {
991
            if (0 == strcmp(group_code, m_group[k].code))
992
            {
993
                pItem->screen[i].groupIndex = k;
994
                break;
995
            }
996
        }
997
        if (pItem->screen[i].groupIndex == -1) {
998
            continue;
999
        }
1000

    
1001
        strncpy(pItem->screen[i].camera_desc.code, (char *)dboption.GetColVal(0, 2+i*2), MaxLen_CODE-1);
1002
    }
1003

    
1004
    dboption.EndSelectRcdSet();
1005

    
1006

    
1007
    for (i=0; i< nScreenNum; i++)
1008
    {
1009
        getCameraDescByCode(&(pItem->screen[i].camera_desc));
1010
        getCCTVDeviceNumber(&(pItem->screen[i].camera_desc));
1011
    }
1012
}
1013

    
1014
int CPlugCCTVC3::updateDispatherMonitorInfo(LPDisplayCurInfo lpDisplayCufInfo)
1015
{
1016
    if (m_curDisplayInfo.monitor.index <= 0)
1017
    {
1018
        if ( insertItem_MonitorInfo( &(lpDisplayCufInfo->monitor) ) <= 0 ) {
1019
            m_log->WriteFmtStrWithTime_L3("[updateDispatherMonitorInfo] >>> failed to insertItem_MonitorInfo");
1020
            return 0;
1021
        }
1022
    }
1023
    else {
1024
        if ( updateItem_MonitorInfo( &(lpDisplayCufInfo->monitor) ) <= 0 ) {
1025
            m_log->WriteFmtStrWithTime_L3("[updateDispatherMonitorInfo] >>> failed to updateItem_MonitorInfo");
1026
            return 0;
1027
        }
1028
    }
1029
    
1030
    if (m_curDisplayInfo.index <= 0)
1031
    {
1032
        if ( insertItem_CurDisplayInfo(m_nPLevel, lpDisplayCufInfo) <= 0 ) {
1033
            m_log->WriteFmtStrWithTime_L3("[updateDispatherMonitorInfo] >>> failed to insertItem_CurDisplayInfo");
1034
            return 0;
1035
        }
1036
    }
1037
    
1038
    return 1;
1039
}
1040

    
1041
void CPlugCCTVC3::getMonitorNumberForDispatch()
1042
{
1043
    if (m_display.count <= 0)
1044
        return;
1045
	int i = 0;
1046
    for (i=0; i<m_display.count; i++)
1047
    {
1048
        CameraDesc camera_Desc;
1049
        CameraDesc_Init(&camera_Desc);
1050
        strcpy(camera_Desc.code, m_display.dispatch[i].code);
1051
        getCCTVDeviceNumber(&camera_Desc, 1);
1052
        strcpy(m_display.dispatch[i].deviceNumber, camera_Desc.deviceNumber);
1053
    }
1054

    
1055
    for (i=0; i<m_display.count; i++)
1056
    {
1057
        m_log->WriteFmtStrWithTime_L2("Dispatch %d: ptz %d, %s, %s, %s", i,
1058
            m_display.dispatch[i].ptzLevel, m_display.dispatch[i].code, m_display.dispatch[i].desc, m_display.dispatch[i].deviceNumber);
1059
    }
1060

    
1061
}
1062

    
1063
int CPlugCCTVC3::getGroupCameras(CameraInfo ** camera_array, int * camera_count, const char * group_code)
1064
{
1065
    if (NULL == camera_array || NULL == camera_count)
1066
        return 0;
1067
    
1068
    // ??????????ȡ??????????????
1069
    SEDB_CMDINFO cmdinfo;
1070
    char cmdbuf[1256] = {0};
1071
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB4009_DIGPOINT");
1072
    strcpy(cmdbuf, "select ");
1073
    char * fieldCodes[] = {"F4009_POINTCODE"};
1074
    int i;
1075
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1076
        strcat(cmdbuf, fieldCodes[i]);
1077
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1078
            strcat(cmdbuf, ",");
1079
    }
1080
    strcat(cmdbuf, " from ");
1081
    strcat(cmdbuf, cmdinfo.table);
1082
    strcat(cmdbuf, " where F1010_APPSYSID=10 AND F1001_GROUPCODE=\'");
1083
    strcat(cmdbuf, group_code);
1084
    strcat(cmdbuf, "\' order by F4009_POINTNO1");
1085
    
1086
    CSE_DBOption dboption;
1087
    dboption.BeginSelectRcdSet(cmdbuf);
1088
    int nCount = dboption.GetRcdCount();
1089
    if (nCount <= 0) {
1090
        dboption.EndSelectRcdSet();
1091
        m_log->WriteFmtStrWithTime_L3("[getGroupCameras] : failed to find records (group-code=%s) in table TB4009_DIGPOINT", group_code);
1092
        return 0;
1093
    }
1094
    
1095
    *camera_count = nCount;
1096
    
1097
    *camera_array = new CameraInfo[nCount];
1098
    for (i=0; i<nCount; i++)
1099
    {
1100
        LPCameraInfo lpCamera = &((*camera_array)[i]);
1101
        CameraInfo_Init(lpCamera);
1102
        
1103
        strncpy(lpCamera->desc.code, (char *)dboption.GetColVal(i,0), MaxLen_CODE-1);
1104
    }
1105
    dboption.EndSelectRcdSet();    
1106

    
1107
    for (i=0; i<nCount; i++)
1108
    {
1109
        LPCameraInfo lpCamera = &((*camera_array)[i]);
1110
        getCameraInfoByCode(lpCamera);
1111
    }
1112

    
1113
    return 1;
1114
}
1115

    
1116

    
1117
void CPlugCCTVC3::getScreenInfo(LPScreenInfo lpScreen)
1118
{
1119
    if (NULL == lpScreen || strlen(lpScreen->camera_desc.code) <= 0)
1120
        return;
1121

    
1122
    SEDB_CMDINFO cmdinfo;
1123
    char cmdbuf[1256] = {0};
1124
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB4009_DIGPOINT");
1125
    strcpy(cmdbuf, "select ");
1126
    char * fieldCodes[] = {"F4009_POINTDESC", "F1001_GROUPCODE"};
1127
    int i;
1128
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1129
        strcat(cmdbuf, fieldCodes[i]);
1130
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1131
            strcat(cmdbuf, ",");
1132
    }
1133
    strcat(cmdbuf, " from ");
1134
    strcat(cmdbuf, cmdinfo.table);
1135
    strcat(cmdbuf, " where (F1010_APPSYSID=10 AND F4009_POINTCODE=");
1136
    char tmpBuf[128] = {0};
1137
    sprintf(tmpBuf, "'%s')", lpScreen->camera_desc.code);
1138
    strcat(cmdbuf, tmpBuf);
1139
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
1140
    
1141
    CSE_DBOption dboption;
1142
    dboption.BeginSelectRcdSet(cmdbuf);
1143
    int nCount = dboption.GetRcdCount();
1144
    if (nCount <= 0) {
1145
        dboption.EndSelectRcdSet();
1146
        m_log->WriteFmtStrWithTime_L3("[getScreenInfo] : failed to find record (code=%s) in table TB4009_DIGPOINT", lpScreen->camera_desc.code);
1147
        return;
1148
    }
1149

    
1150
//     strcpy(lpScreen->cameraDesc, (char *)dboption.GetColVal(0, 0));
1151
    memset(tmpBuf, 0, 128);
1152
    strcpy(tmpBuf, (char *)dboption.GetColVal(0,1));
1153

    
1154
    dboption.EndSelectRcdSet();
1155

    
1156
    for (i=0; i<m_groupNum; i++)
1157
    {
1158
        if (0 == strcmp(tmpBuf, m_group[i].code))
1159
        {
1160
            lpScreen->groupIndex = i;
1161
            break;
1162
        }
1163
    }
1164

    
1165
    if (lpScreen->groupIndex >= 0)
1166
    {
1167
        getCameraDescByCode(&(lpScreen->camera_desc));
1168
        getCCTVDeviceNumber(&(lpScreen->camera_desc));
1169
    }
1170
}
1171

    
1172
int CPlugCCTVC3::getCameraInfoByCode(LPCameraInfo lpCameraInfo)
1173
{
1174
    if (NULL == lpCameraInfo)
1175
        return 0;
1176
    if ( strlen(lpCameraInfo->desc.code) <= 0 )
1177
        return 0;
1178

    
1179
    SEDB_CMDINFO cmdinfo;
1180
    char cmdbuf[1256] = {0};
1181
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB4009_DIGPOINT");
1182
    strcpy(cmdbuf, "select ");
1183
    char * fieldCodes[] = {"F4009_AOJ", "F1010_APPSYSID", "F4004_MEASTYPEID", "F4009_POINTNO1", "F1002_BAYAREANO", "F4009_POINTDESC"};
1184
    int i;
1185
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1186
        strcat(cmdbuf, fieldCodes[i]);
1187
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1188
            strcat(cmdbuf, ",");
1189
    }
1190
    strcat(cmdbuf, " from ");
1191
    strcat(cmdbuf, cmdinfo.table);
1192
    char tmpStr[128] = {0};
1193
    sprintf(tmpStr, " where F4009_POINTCODE='%s'", lpCameraInfo->desc.code);
1194
    strcat(cmdbuf, tmpStr);
1195
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
1196
    
1197
    CSE_DBOption dboption;
1198
    dboption.BeginSelectRcdSet(cmdbuf);
1199
    int nCount = dboption.GetRcdCount();
1200
    if (nCount <= 0) {
1201
        dboption.EndSelectRcdSet();
1202
        m_log->WriteFmtStrWithTime_L3("[getCameraInfoByCode] : failed to find record in TB4009_DIGPOINT by code %s", lpCameraInfo->desc.code);
1203
        return 0;
1204
    }
1205
    
1206
    lpCameraInfo->aoj = (uint)dboption.GetIntVal(0,0);
1207
    lpCameraInfo->appSysID = (BYTE)dboption.GetIntVal(0,1);
1208
    lpCameraInfo->measTypeID = (uint)dboption.GetIntVal(0,2);
1209
    lpCameraInfo->pointNo1 = (int)dboption.GetIntVal(0,3);
1210
    lpCameraInfo->desc.bayAreaNo = (int)dboption.GetIntVal(0,4);
1211
    strncpy(lpCameraInfo->desc.data, (char *)dboption.GetColVal(0,5), MaxLen_DESC-1);
1212

    
1213
    dboption.EndSelectRcdSet();
1214

    
1215
    getCCTVDeviceNumber(&(lpCameraInfo->desc));
1216

    
1217
    return 1;
1218
}
1219

    
1220
int CPlugCCTVC3::getCameraDescByCode(LPCameraDesc lpCameraDesc, int * groupIndex)
1221
{
1222
    if (NULL == lpCameraDesc)
1223
        return 0;
1224
    if ( strlen(lpCameraDesc->code) <= 0 )
1225
        return 0;
1226
    
1227
    SEDB_CMDINFO cmdinfo;
1228
    char cmdbuf[1256] = {0};
1229
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB4009_DIGPOINT");
1230
    strcpy(cmdbuf, "select ");
1231
    char * fieldCodes[] = {"F1002_BAYAREANO", "F4009_POINTDESC", "F1001_GROUPCODE"};
1232
    int i;
1233
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1234
        strcat(cmdbuf, fieldCodes[i]);
1235
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1236
            strcat(cmdbuf, ",");
1237
    }
1238
    strcat(cmdbuf, " from ");
1239
    strcat(cmdbuf, cmdinfo.table);
1240
    char tmpStr[128] = {0};
1241
    sprintf(tmpStr, " where F4009_POINTCODE='%s'", lpCameraDesc->code);
1242
    strcat(cmdbuf, tmpStr);
1243
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
1244
    
1245
    CSE_DBOption dboption;
1246
    dboption.BeginSelectRcdSet(cmdbuf);
1247
    int nCount = dboption.GetRcdCount();
1248
    if (nCount <= 0) {
1249
        dboption.EndSelectRcdSet();
1250
        m_log->WriteFmtStrWithTime_L3("[getCameraInfoByCode] : failed to find record in TB4009_DIGPOINT by code %s", lpCameraDesc->code);
1251
        return 0;
1252
    }
1253
    
1254
    lpCameraDesc->bayAreaNo = (int)dboption.GetIntVal(0, 0);
1255
    strncpy(lpCameraDesc->data, (char *)dboption.GetColVal(0, 1), MaxLen_DESC-1);
1256

    
1257
    if (NULL != groupIndex) {
1258
        char group_code[MaxLen_CODE] = {0};
1259
        strncpy(group_code, (char *)dboption.GetColVal(0, 2), MaxLen_CODE-1);
1260
        for (i=0; i<m_groupNum; i++)
1261
        {
1262
            if (0 == strcmp(m_group[i].code, group_code))
1263
            {
1264
                *groupIndex = i;
1265
                break;
1266
            }
1267
        }
1268
    }
1269
    
1270
    dboption.EndSelectRcdSet();
1271
    
1272
//     getCCTVDeviceNumber(lpCameraDesc);
1273
    
1274
    return 1;
1275
}
1276

    
1277
void CPlugCCTVC3::getCCTVDeviceNumber(LPCameraDesc lpCameraDesc, int cctv_type)
1278
{
1279
    if (NULL == lpCameraDesc)
1280
        return;
1281
    if ( strlen(lpCameraDesc->code) <= 0 )
1282
        return;
1283
    
1284
    SEDB_CMDINFO cmdinfo;
1285
    char cmdbuf[1256] = {0};
1286
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB2023_CCTVDEV");
1287
    strcpy(cmdbuf, "select ");
1288
    char * fieldCodes[] = {"F2023_DEVNO"};
1289
    int i;
1290
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1291
        strcat(cmdbuf, fieldCodes[i]);
1292
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1293
            strcat(cmdbuf, ",");
1294
    }
1295
    strcat(cmdbuf, " from ");
1296
    strcat(cmdbuf, cmdinfo.table);
1297
    char tmpStr[128] = {0};
1298
    sprintf(tmpStr, " where F2023_TYPE=%d and F4009_POINTCODE='%s'", cctv_type, lpCameraDesc->code);
1299
    strcat(cmdbuf, tmpStr);
1300
    
1301
    CSE_DBOption dboption;
1302
    dboption.BeginSelectRcdSet(cmdbuf);
1303
    int nCount = dboption.GetRcdCount();
1304
    if (nCount <= 0) {
1305
        dboption.EndSelectRcdSet();
1306
        return;
1307
    }
1308

    
1309
    strncpy(lpCameraDesc->deviceNumber, (char *)dboption.GetColVal(0, 0), MaxLen_DeviceNumber-1);
1310
    
1311
    dboption.EndSelectRcdSet();
1312
}
1313

    
1314
void CPlugCCTVC3::GetCurrentGroupCameras(const char * group_code)
1315
{
1316
    m_curCameraNum = 0;
1317
    if (NULL != m_curCamera)
1318
    {
1319
        delete [] m_curCamera;
1320
        m_curCamera = NULL;
1321
    }
1322
    
1323
    int nRe = getGroupCameras(&m_curCamera, &m_curCameraNum, group_code);
1324
}
1325

    
1326
BOOL CPlugCCTVC3::getCameraDescByDeviceID(LPCameraDesc lpCameraDesc, int * groupIndex)
1327
{
1328
    if (NULL == lpCameraDesc)
1329
        return FALSE;
1330
    if (strlen(lpCameraDesc->deviceNumber) == 0)
1331
        return FALSE;
1332
    
1333
    SEDB_CMDINFO cmdinfo;
1334
    char cmdbuf[1256] = {0};
1335
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB2023_CCTVDEV");
1336
    strcpy(cmdbuf, "select ");
1337
    char * fieldCodes[] = {"F4009_POINTCODE"};
1338
    int i;
1339
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1340
        strcat(cmdbuf, fieldCodes[i]);
1341
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1342
            strcat(cmdbuf, ",");
1343
    }
1344
    strcat(cmdbuf, " from ");
1345
    strcat(cmdbuf, cmdinfo.table);
1346
    char tmpStr[128] = {0};
1347
    sprintf(tmpStr, " where F2023_DEVNO='%s'", lpCameraDesc->deviceNumber);
1348
    strcat(cmdbuf, tmpStr);
1349
    
1350
    CSE_DBOption dboption;
1351
    dboption.BeginSelectRcdSet(cmdbuf);
1352
    int nCount = dboption.GetRcdCount();
1353
    if (nCount <= 0) {
1354
        dboption.EndSelectRcdSet();
1355
        return FALSE;
1356
    }
1357

    
1358
    strncpy(lpCameraDesc->code, (char *)dboption.GetColVal(0, 0), MaxLen_CODE-1);
1359

    
1360
    dboption.EndSelectRcdSet();
1361

    
1362
    getCameraDescByCode(lpCameraDesc, groupIndex);
1363

    
1364
    return TRUE;
1365
}
1366

    
1367
BOOL CPlugCCTVC3::UpdateScreenInfoByDevID(LPScreenInfo lpScreenInfo)
1368
{
1369
    if (NULL == lpScreenInfo)
1370
        return FALSE;
1371
    if (strlen(lpScreenInfo->camera_desc.deviceNumber) == 0)
1372
        return FALSE;
1373

    
1374
    BOOL bRet = getCameraDescByDeviceID(&(lpScreenInfo->camera_desc), &(lpScreenInfo->groupIndex));
1375

    
1376
    return bRet;
1377
}
1378

    
1379
int CPlugCCTVC3::Update_Screen(LPScreenSet lpScreenSet)//?л?????ͷ
1380
{
1381
    DisplayCurInfo tmp_display;
1382
    DisplayCurInfo_Copy(tmp_display, m_curDisplayInfo);
1383
    tmp_display.monitor.screenNum = lpScreenSet->screenNum;
1384
    ScreenInfo_Copy(tmp_display.monitor.screen[lpScreenSet->screenIndex], lpScreenSet->screen);
1385

    
1386
    if (updateDispatherMonitorInfo(&tmp_display) <= 0) {
1387
        m_log->WriteFmtStrWithTime_L3("[Update_Screen] >>> failed to updateDispatherMonitorInfo");
1388
        return 0;
1389
    }
1390
    DisplayCurInfo_Copy(m_curDisplayInfo, tmp_display);
1391
	
1392
    if (!m_useSDK)//Э???
1393
        switchCamera(lpScreenSet);
1394

    
1395
    return 1;
1396
}
1397

    
1398
int CPlugCCTVC3::InsertDisplayMode(LPDisplayModeInfo lpDisplayMode)
1399
{
1400
    if (NULL == lpDisplayMode)
1401
        return 0;
1402

    
1403
    if ( insertItem_MonitorInfo( &(lpDisplayMode->monitor) ) <= 0 )
1404
            return 0;
1405
    
1406
    if ( insertItem_DisplayMode(m_nPLevel, lpDisplayMode) <= 0 )
1407
        return 0;
1408

    
1409
    m_listCurDisplaymode.AddTail(*lpDisplayMode);
1410

    
1411
    return 1;
1412
}
1413

    
1414

    
1415
//???? DisplayModeInfo?????ݿ?  lilei  2019-6-11
1416
int CPlugCCTVC3::updateItem_DisplayMode(UINT ptzLevel, LPDisplayModeInfo pDisplayMode)
1417
{
1418
	char cmdbuf[2048] = {0};
1419
    strcpy(cmdbuf, "UPDATE SEMODEL.TB5014_CCTVDISPLAYMODE SET F5014_DESC = ");
1420
    char * fieldCodes[] = {"F0101_PTZPLEVEL", "F5012_NO", "F5014_DESC"};
1421
      
1422
    char tmpStr[128] = {0};
1423
   // sprintf(tmpStr, "%d,%d,'%s'", ptzLevel, pDisplayMode->monitor.index, pDisplayMode->desc);
1424
	sprintf(tmpStr, "'%s'", pDisplayMode->desc);
1425
    strcat(cmdbuf, tmpStr);
1426
	strcat(cmdbuf, " WHERE F5012_NO = ");
1427
	char tmpStr1[128] = {0};
1428
	sprintf(tmpStr1, "%d", pDisplayMode->monitor.index);
1429
	strcat(cmdbuf, tmpStr1);
1430
    strcat(cmdbuf, ";");
1431
	//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
1432
    
1433
    CSE_DBOption dboption;
1434
	//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
1435
	//         return 0;
1436
    int nRet = dboption.ExecuteCmd(cmdbuf);//SERVER_MAIN ?ij?NULL 
1437
	
1438
    char cmdbuf2[512] = {0};
1439
    strcpy(cmdbuf2, "select max(F5014_NO) FROM SEMODEL.dbo.TB5014_CCTVDISPLAYMODE");
1440
    
1441
    dboption.BeginSelectRcdSet(cmdbuf2);
1442
    int nRcdCount = dboption.GetRcdCount();
1443
    if (nRcdCount <= 0) {
1444
        dboption.EndSelectRcdSet();
1445
        return 0;
1446
    }
1447
    
1448
    pDisplayMode->index = (int)dboption.GetIntVal(0,0);
1449
    dboption.EndSelectRcdSet();
1450
    
1451
     return 1;
1452
}
1453

    
1454
//???? DisplayMode?????ݿ?  lilei  2019-6-11
1455
int CPlugCCTVC3::Update_DisplayMode(LPDisplayModeInfo displayMode)
1456
{
1457
	if (NULL == displayMode)
1458
        return 0;
1459
    
1460
    if ( updateItem_DisplayMode(m_nPLevel, displayMode) <= 0 )
1461
        return 0;
1462
	
1463
    return 1;
1464
}
1465

    
1466
int CPlugCCTVC3::DeleteDisplayMode(int list_displaymode_index)
1467
{
1468
    POSITION pos = m_listCurDisplaymode.FindIndex(list_displaymode_index);
1469
    if (NULL == pos)
1470
        return 0;
1471
    DisplayModeInfo dispmode = m_listCurDisplaymode.GetAt(pos);
1472

    
1473
    if ( removeItem_DisplayMode(&dispmode) <= 0 )
1474
        return 0;
1475
    m_listCurDisplaymode.RemoveAt(pos);
1476
    
1477
    if ( removeItem_MonitorInfo( &(dispmode.monitor) ) <= 0 )
1478
        return 0;
1479
    
1480
    return 1;
1481
}
1482

    
1483
int CPlugCCTVC3::Update_CurDisplayInfo(LPDisplayCurInfo lpDisplayCurInfo, bool bDisplayMode, bool isCollectedDispMode, bool bNeedUpdateMonitorInfo)
1484
{
1485
    if (lpDisplayCurInfo->monitor.screenNum != 1 && lpDisplayCurInfo->monitor.screenNum != MaxNum_Screen && lpDisplayCurInfo->monitor.screenNum != 4 
1486
		&& lpDisplayCurInfo->monitor.screenNum != 5  && lpDisplayCurInfo->monitor.screenNum != 6 && lpDisplayCurInfo->monitor.screenNum != 7)
1487
	{
1488
        return 0;
1489
	}
1490

    
1491
    DisplayCurInfo tmp_display;
1492
    DisplayCurInfo_Init(&tmp_display);
1493
    tmp_display.monitor.screenNum = lpDisplayCurInfo->monitor.screenNum;
1494
	tmp_display.lastSelectIndex = lpDisplayCurInfo->lastSelectIndex;
1495
	tmp_display.lastSelectIndex2 = lpDisplayCurInfo->lastSelectIndex2;
1496
	tmp_display.curScreenIndex = lpDisplayCurInfo->curScreenIndex;
1497
	int i = 0;
1498
	for (i = 0; i<MaxNum_Screen; i++)
1499
    {
1500
        ScreenInfo_Copy(tmp_display.monitor.screen[i], lpDisplayCurInfo->monitor.screen[i]);
1501
    }
1502

    
1503
	//Fix bug: 4?????г?1?????Ժ?,ÿ?????½??붼?Զ??г?4??. yansx 2019-02-19
1504
	tmp_display.monitor.index = lpDisplayCurInfo->monitor.index;
1505
	if(bNeedUpdateMonitorInfo)//?????????ʱ??,????Ҫ???˲???
1506
	{
1507
		if (updateDispatherMonitorInfo(&tmp_display) <= 0)
1508
        {
1509
			return 0;	
1510
		}	
1511
	}
1512

    
1513
    DisplayCurInfo_Copy(m_curDisplayInfo, tmp_display);
1514
    lpDisplayCurInfo->index = m_curDisplayInfo.index;
1515
    lpDisplayCurInfo->monitor.index = m_curDisplayInfo.monitor.index;
1516

    
1517
	if((lpDisplayCurInfo->monitor.screenNum == 1 || lpDisplayCurInfo->monitor.screenNum == 5 || lpDisplayCurInfo->monitor.screenNum == 6 || lpDisplayCurInfo->monitor.screenNum == 7)
1518
		/*&& m_bSwitch4to1Screen*/)//????4??????ʱ??,??ѡ?е?????ͷ,????1?????Ժ?,Ҫʹ?????decode.????????Զ??ʹ?õ?һ??.
1519
	{                                                                  //???????? 2019-04-25
1520
		m_nLast4ScreenFocusIndex = lpDisplayCurInfo->lastSelectIndex;
1521
		m_nLast4ScreenFocusIndex2 = lpDisplayCurInfo->lastSelectIndex2;
1522
		m_bSwitch4to1Screen = false;
1523
	}
1524
	else if(lpDisplayCurInfo->monitor.screenNum == 4 || lpDisplayCurInfo->monitor.screenNum == 8)
1525
	{
1526
		m_bSwitch4to1Screen = true;
1527
	}
1528
	//m_curDisplayInfo.monitor.screenNum ?п?????1??4??5??6??7??8, 
1529
	// 1??4????4??ģʽ
1530
	// 5??6??7??8??ʾ??8??ģʽ
1531
	// 5 ????ǰ4????Ϊ1????????4????Ϊ4????
1532
	// 6 ????ǰ4????Ϊ4????????4????Ϊ1????
1533
	// 7 ????ǰ4????Ϊ1????????4????Ϊ1????
1534
	// 6 ????ǰ4????Ϊ4????????4????Ϊ4????
1535
	int screenNum = (m_curDisplayInfo.monitor.screenNum > 4) ? MaxNum_Screen : MaxNum_ScreenColumn/*m_curDisplayInfo.monitor.screenNum*/;
1536
	int start = 0;
1537
	int stop = 0;
1538
	if (isCollectedDispMode)
1539
		m_curDisplayInfo.lastSelectIndex = 0;
1540
	if(!isCollectedDispMode && m_curDisplayInfo.curScreenIndex >= 4)// isCollectedDispMode?ж??Ƿ??dz?ʼ?????ߴӳ????ղ??б?????????ͷ?л?
1541
	{
1542
		start = 4;
1543
	}
1544
	if(!isCollectedDispMode && m_curDisplayInfo.curScreenIndex < 4 && screenNum >4)
1545
	{
1546
		stop = 4;
1547
	}
1548
	m_log->WriteFmtStrWithTime_L2("(%d) BEFORE -->>>> switch camera >>> Cur_ScreenNum: %d, screenNum: %d, start: %d, stop: %d", m_curDisplayInfo.monitor.screenNum, 
1549
		m_curDisplayInfo.curScreenIndex, screenNum, start, stop);
1550
    
1551
	int tmpNum = m_curDisplayInfo.monitor.screenNum;
1552
	for (i=start; i<screenNum - stop; i++)
1553
    {
1554
        ScreenSet tmp_screenset;
1555
		if(bDisplayMode || isCollectedDispMode)	//isCollectedDispMode=true??ʾ???ղ??б????»??߳?ʼ?????£?bDisplayMode=true??ʾ4????
1556
		{
1557
			if (i < 4)
1558
			{
1559
				if (tmpNum == 1 || tmpNum == 5 || tmpNum == 7 )  // tmpNum == 1??5??7˵??ǰ4????????4??1 
1560
				{
1561
					if (i == m_curDisplayInfo.lastSelectIndex )
1562
					{
1563
						tmp_screenset.screenIndex = m_curDisplayInfo.lastSelectIndex; // ??ǰ4????????4??1 ʱ??ֻ?л???ǰ??ѡ?е?????ͷ
1564
					}
1565
					else
1566
					{
1567
						continue;
1568
					}
1569
				}
1570
				else if (tmpNum == 4 || tmpNum == 6 || tmpNum == 8) // tmpNum == 4??6??8˵??ǰ4????Ϊ4?????л?ǰ4????????????ͷ  
1571
				{
1572
					tmp_screenset.screenIndex = i;
1573
				}
1574
			}
1575
			else 
1576
			{
1577
				if ( tmpNum == 6 || tmpNum == 7 )  //tmpNum == 1??5??7˵????4????????4??1 
1578
				{
1579
					if (i == m_curDisplayInfo.lastSelectIndex2 )
1580
					{
1581
						tmp_screenset.screenIndex = m_curDisplayInfo.lastSelectIndex2; //ֻ?л???ǰѡ?е???
1582
					}
1583
					else
1584
					{
1585
						continue;
1586
					}
1587
				}
1588
				else if ( tmpNum == 5 || tmpNum == 8)//tmpNum == 5??8˵????4????Ϊ4?????л???4????????????ͷ
1589
				{
1590
					tmp_screenset.screenIndex = i;
1591
				}
1592
			}
1593
			
1594
		}
1595
		else
1596
		{
1597
			if(i == m_curDisplayInfo.lastSelectIndex)
1598
			{
1599
				tmp_screenset.screenIndex = m_curDisplayInfo.lastSelectIndex;//???һ??ѡ?еķ???index,ͨ?????ֵ?????õ???ȷ??decodeֵ, Yansx 2019-04-18
1600
			}
1601
			else if(m_curDisplayInfo.lastSelectIndex2 == i && i >= 4)//????4????????Index??4~7,????Ҫ>=4 
1602
			{
1603
				tmp_screenset.screenIndex = m_curDisplayInfo.lastSelectIndex2;
1604
			}
1605
			else
1606
			{
1607
				continue;
1608
			}
1609
		}
1610

    
1611
		if(i >= 4)
1612
		{
1613
			m_isLevel2 = true;
1614
		}
1615
        tmp_screenset.screenNum = m_curDisplayInfo.monitor.screenNum;
1616
        ScreenInfo_Copy(tmp_screenset.screen, m_curDisplayInfo.monitor.screen[i]);
1617
        switchCamera(&tmp_screenset);
1618
    }
1619
	m_isLevel2 = false;
1620

    
1621
    return 1;
1622
}
1623

    
1624
int CPlugCCTVC3::InsertFavorite(LPFavoriteInfo lpFavorite)
1625
{
1626
    if (NULL == lpFavorite)
1627
        return 0;
1628

    
1629
    char cmdbuf[1024] = {0};
1630
    strcpy(cmdbuf, "INSERT INTO SEMODEL.TB5015_CCTVFAV (");
1631
    char * fieldCodes[] = {"F4009_POINTCODE", "F5015_DESC", "F0101_PTZPLEVEL"};
1632
    int i;
1633
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
1634
        strcat(cmdbuf, fieldCodes[i]);
1635
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
1636
            strcat(cmdbuf, ",");
1637
    }
1638
    strcat(cmdbuf, ") VALUES (");    
1639
    char tmpStr[128] = {0};
1640
    sprintf(tmpStr, "'%s','%s',%d)", lpFavorite->screen.camera_desc.code, lpFavorite->desc, m_nPLevel);
1641
    strcat(cmdbuf, tmpStr);
1642
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
1643
    
1644
    CSE_DBOption dboption;
1645
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
1646
//         return 0;
1647
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
1648
	int nRet = dboption.ExecuteCmd(cmdbuf);
1649
    
1650
    char cmdbuf2[512] = {0};
1651
    strcpy(cmdbuf2, "select max(F5015_NO) FROM SEMODEL.TB5015_CCTVFAV");
1652
    
1653
    dboption.BeginSelectRcdSet(cmdbuf2);
1654
    int nRcdCount = dboption.GetRcdCount();
1655
    if (nRcdCount <= 0) {
1656
        dboption.EndSelectRcdSet();
1657
        return 0;
1658
    }
1659
    
1660
    lpFavorite->index = (int)dboption.GetIntVal(0,0);
1661
    dboption.EndSelectRcdSet();
1662

    
1663
    m_listCurFav.AddTail(*lpFavorite);
1664

    
1665
    return 1;
1666
}
1667

    
1668
int CPlugCCTVC3::Update_Favorite(LPFavoriteInfo lpFavorite)
1669
{
1670
    if (NULL == lpFavorite)
1671
        return 0;
1672
    if (strlen(lpFavorite->desc) <= 0)
1673
        return 0;
1674

    
1675
    POSITION pos = m_listCurFav.GetHeadPosition();
1676
    while (pos != NULL)
1677
	{
1678
        //FavoriteInfo item = m_listCurFav.GetNext(pos);
1679
		FavoriteInfo item = m_listCurFav.GetAt(pos);
1680
        if (item.index == lpFavorite->index)
1681
		{
1682
			char cmdbuf[1024] = {0};
1683
			strcpy(cmdbuf, "UPDATE SEMODEL.TB5015_CCTVFAV SET ");
1684
			char tmpStr[128] = {0};
1685
			sprintf(tmpStr, "F5015_DESC='%s'", lpFavorite->desc);
1686
			strcat(cmdbuf, tmpStr);
1687
			strcat(cmdbuf, " WHERE F5015_NO=");
1688
			memset(tmpStr, 0, 128);
1689
			sprintf(tmpStr, "%d", lpFavorite->index);
1690
			strcat(cmdbuf, tmpStr);
1691
			
1692
			CSE_DBOption dboption;
1693
			
1694
			//int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
1695
			int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
1696
 			if(nRet != SEDB_SUCCESS)
1697
			{
1698
				m_log->WriteFmtStrWithTime_L3("Update_Favorite return Error. %s", cmdbuf);
1699
				return 0;
1700
			}
1701

    
1702
			strcpy(item.desc, lpFavorite->desc);
1703
			m_listCurFav.SetAt(pos, item);
1704

    
1705
            break;
1706
		}
1707

    
1708
		m_listCurFav.GetNext(pos);
1709
    }
1710

    
1711
    return 1;
1712
}
1713

    
1714
int CPlugCCTVC3::DeleteFavorite(int list_favorite_index)
1715
{
1716
    POSITION pos = m_listCurFav.FindIndex(list_favorite_index);
1717
    if (NULL == pos)
1718
        return 0;
1719
    FavoriteInfo favorInfo = m_listCurFav.GetAt(pos);
1720

    
1721
    char cmdbuf[1024] = {0};
1722
    strcpy(cmdbuf, "DELETE FROM SEMODEL.dbo.TB5015_CCTVFAV WHERE F5015_NO=");
1723
    char tmpStr[32] = {0};
1724
    sprintf(tmpStr, "%d", favorInfo.index);
1725
    strcat(cmdbuf, tmpStr);
1726
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
1727
    
1728
    CSE_DBOption dboption;
1729
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
1730
//         return 0;
1731
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
1732
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
1733

    
1734
    m_listCurFav.RemoveAt(pos);
1735

    
1736
    return 1;
1737
}
1738

    
1739
int CPlugCCTVC3::OperateCamera(LPScreenSet lpScreenSet, OperTypeCamera oper_type, int nMouseState , void * value)
1740
{
1741
    if (NULL == value)
1742
        return 0;
1743

    
1744
    if (oper_type == OperType_None)
1745
        return 0;
1746
    
1747
    PtzCtlInfoEx ptzctlex;
1748
    memset(&ptzctlex, 0, sizeof(PtzCtlInfoEx));
1749
    PtzCtlInfo_Copy(ptzctlex.ptz, *((LPPtzCtlInfo)value));
1750
    if (oper_type == OperType_Ptzctl)
1751
    {
1752
        switch (ptzctlex.ptz.ctrlValue)
1753
        {
1754
            case CCTV_E_PTZ_UP:
1755
                _tcscpy(ptzctlex.desc, _T("??"));
1756
                break;
1757
            case CCTV_E_PTZ_DOWN:
1758
                _tcscpy(ptzctlex.desc, _T("??"));
1759
                break;
1760
            case CCTV_E_PTZ_LEFT:
1761
                _tcscpy(ptzctlex.desc, _T("??"));
1762
                break;
1763
            case CCTV_E_PTZ_RIGHT:
1764
                _tcscpy(ptzctlex.desc, _T("??"));
1765
                break;
1766
            case CCTV_E_PTZ_LUP:
1767
                _tcscpy(ptzctlex.desc, _T("????"));
1768
                break;
1769
            case CCTV_E_PTZ_LDOWN:
1770
                _tcscpy(ptzctlex.desc, _T("????"));
1771
                break;
1772
            case CCTV_E_PTZ_RUP:
1773
                _tcscpy(ptzctlex.desc, _T("????"));
1774
                break;
1775
            case CCTV_E_PTZ_RDOWN:
1776
                _tcscpy(ptzctlex.desc, _T("????"));
1777
                break;		
1778
            case CCTV_E_PTZ_ZOOMIN:
1779
                _tcscpy(ptzctlex.desc, _T("?Ŵ?"));
1780
                break;
1781
            case CCTV_E_PTZ_ZOOMOUT:
1782
                _tcscpy(ptzctlex.desc, _T("??С"));
1783
                break;
1784
            case CCTV_E_PTZ_FOCUSNEAR:
1785
                _tcscpy(ptzctlex.desc, _T("????-"));
1786
                break;
1787
            case CCTV_E_PTZ_FOCUSFAR:
1788
                _tcscpy(ptzctlex.desc, _T("????+"));
1789
                break;
1790
            case CCTV_E_PTZ_IRIS_OPEN:
1791
                _tcscpy(ptzctlex.desc, _T("??Ȧ+"));
1792
                break;	
1793
            case CCTV_E_PTZ_IRIS_CLOSE:
1794
                _tcscpy(ptzctlex.desc, _T("??Ȧ-"));
1795
                break;
1796
            case CCTV_E_PRESET_GOTO:
1797
                _tcscpy(ptzctlex.desc, _T("????Ԥ??λ"));
1798
                break;
1799
            default:
1800
                return 0;
1801
                break;
1802
        }
1803
    }
1804
    else
1805
        return 0;
1806

    
1807
    return cameraAct(lpScreenSet, oper_type, nMouseState, (void *)(&ptzctlex));
1808
}
1809

    
1810
int CPlugCCTVC3::RoundModeScan(LPScreenSet lpScreenSet, OperTypeCamera oper_type, void * value)
1811
{
1812
    if (NULL == value)
1813
        return 0;
1814
    
1815
    if (oper_type == OperType_None)
1816
        return 0;
1817
    
1818
    PtzCtlInfoEx ptzctlex;
1819
    memset(&ptzctlex, 0, sizeof(PtzCtlInfoEx));
1820
    PtzCtlInfo_Copy(ptzctlex.ptz, *((LPPtzCtlInfo)value));
1821
    if (oper_type == OperType_RoundTourMode)
1822
    {
1823
        switch (ptzctlex.ptz.ctrlValue)
1824
        {
1825
        case CCTV_E_SCAN:
1826
            m_bScanActively = TRUE;
1827
            _tcscpy(ptzctlex.desc, _T("??Ѳ????"));
1828
            break;
1829
        case CCTV_E_HALT:
1830
            m_bScanActively = FALSE;
1831
            _tcscpy(ptzctlex.desc, _T("??Ѳֹͣ"));
1832
            break;
1833
        default:
1834
            return 0;
1835
            break;
1836
        }
1837
    }
1838
    else
1839
        return 0;
1840

    
1841

    
1842
    CameraInfo camera_info;
1843
    CameraInfo_Init(&camera_info);
1844
    strcpy(camera_info.desc.code, lpScreenSet->screen.camera_desc.code);
1845
    if ( getCameraInfoByCode(&camera_info) <= 0 )
1846
        return -1;
1847

    
1848
    ALM_D_BASE_INFO alminfo = {0};
1849
    memset(&alminfo, 0, sizeof(ALM_D_BASE_INFO));
1850
    
1851
    strcpy(alminfo.DeviceKey, camera_info.desc.code);
1852
    strcpy(alminfo.ClassName, "Control");
1853
    alminfo.Operator = ALM_K_OPR_ALM;
1854
    
1855
    CSeTime kt;
1856
    TCriterionTime ct;
1857
    kt.GetNow(&ct, &alminfo.Msec);
1858
    alminfo.Second = ct;
1859
    alminfo.Priority = ALM_K_PRI_EVENT;
1860
    alminfo.DeviceType = 80;
1861
    alminfo.MessageId = 1;
1862
    strcpy(alminfo.Graph, "");
1863
    alminfo.AttrNum = 5;
1864
    
1865
    strcpy(alminfo.UserAttrList[0].UserAttrName, "User");
1866
    
1867
    strcpy(alminfo.UserAttrList[1].UserAttrName, "Console");
1868
    get_host_name(alminfo.UserAttrList[1].UserAttrVal);
1869
    AOJ_GetConsoleDesc(alminfo.UserAttrList[1].UserAttrVal, alminfo.UserAttrList[1].UserAttrValDesc);
1870
    
1871
    strcpy(alminfo.UserAttrList[2].UserAttrName, "CtrlType");
1872
    sprintf(alminfo.UserAttrList[2].UserAttrVal, "%d", ptzctlex.ptz.ctrlValue);
1873
    strcpy(alminfo.UserAttrList[2].UserAttrValDesc, ptzctlex.desc);
1874
    
1875
    strcpy(alminfo.UserAttrList[3].UserAttrName, "CtrlState");
1876
    strcpy(alminfo.UserAttrList[3].UserAttrVal, "0");
1877
    strcpy(alminfo.UserAttrList[3].UserAttrValDesc, "?ɹ?");
1878
    
1879
    strcpy(alminfo.UserAttrList[4].UserAttrName, "Point");
1880
    strcpy(alminfo.UserAttrList[4].UserAttrVal, camera_info.desc.code);	
1881
    
1882
    AOJ_D_ASSIGNMENT AojMask;
1883
    AOJ_GetAssignment(NULL,AojMask, DEF_RIGHT_DEVICE_C);
1884
    
1885
    char   UserName[SE_K_USER_CODE] = {0};
1886
    RBAC_GetUserRoleDescription(UserName, alminfo.UserAttrList[0].UserAttrValDesc, NULL, NULL);
1887
    strcpy(alminfo.UserAttrList[0].UserAttrVal, UserName);	
1888
    
1889
    alminfo.Aoj = camera_info.aoj;
1890
    alminfo.AppSysId = camera_info.appSysID;
1891
    strcpy(alminfo.UserAttrList[4].UserAttrValDesc, camera_info.desc.data);
1892
    strcpy(alminfo.GroupName, m_group[lpScreenSet->screen.groupIndex].code);
1893
    
1894
    m_csi.CCTV_Login(m_nPLevel);
1895
    
1896
//    m_Sta = lpScreenSet->screen.groupIndex + 1;
1897
	m_Sta = m_group[lpScreenSet->screen.groupIndex].groupno;//WYF 20190425
1898
   // m_Div = (lpScreenSet->screenNum == MaxNum_Screen || lpScreenSet->screenNum == MaxNum_ScreenColumn) ? 1 : 0;
1899
	m_Div = getDiv(lpScreenSet);
1900
    m_Win = lpScreenSet->screenIndex + 1;
1901
    m_Wall = 2; // ??ȷ????????ǽ???
1902
    m_Task = 3; // ??ȷ??????????
1903

    
1904
	//Yansx 20190130
1905
	CameraDesc camera_Desc;
1906
    CameraDesc_Init(&camera_Desc);
1907
    strcpy(camera_Desc.code, m_decode[0][m_Win-1]);
1908
	getCCTVDeviceNumber(&camera_Desc,1);
1909

    
1910
	BYTE deviceNum = atoi(camera_Desc.deviceNumber);//???ֵС??255
1911

    
1912
	// ??ȡmonitor??code???????Ļ??????4????ʹ?õ?2??monitor??code  lilei 20190710
1913
	char* code = m_display.dispatch[0].code;
1914
	if (m_Win > 4)
1915
	{
1916
		code = m_display.dispatch[0].code2;
1917
	}
1918
	
1919
    m_csi.CCTV_SelectCam(camera_info.desc.code, m_Line, m_Sta, m_Div, (m_Win-1)%4+1, m_Wall, m_Task, (char)deviceNum);
1920
    
1921
//     LPDispatchInfoEx pDispatchEx = (LPDispatchInfoEx)m_display.dispatch[0].exInfo;
1922
//     m_csi.CCTV_SelectMon(pDispatchEx->code);
1923
   // m_csi.CCTV_SelectMon(m_display.dispatch[0].code);
1924
	m_csi.CCTV_SelectMon(code);
1925

    
1926
    m_csi.CCTV_Scan(ptzctlex.ptz.paraValue);
1927
    if (ptzctlex.ptz.ctrlValue == 2)
1928
    {
1929
        m_csi.CCTV_Scan(0);
1930
    }
1931
//    m_csi.AlmSignal(UserName,alminfo);//ע?ʹ˴???,??????ʷ??ѹ??. feature #130 Yansx 20190610
1932

    
1933
    return 1;
1934
}
1935

    
1936

    
1937

    
1938

    
1939
//////////////////////////////////////////////////////////////////////
1940

    
1941
void CPlugCCTVC3::transferCurFavorites(LPFavoriteInfo lpFavoriteInfo, int arrayCount)
1942
{
1943
    if (NULL == lpFavoriteInfo)
1944
        return;
1945

    
1946
    int i = 0;
1947
    POSITION pos = m_listCurFav.GetHeadPosition();
1948
    while (pos != NULL)
1949
    {
1950
        if (i >= arrayCount)
1951
            break;
1952
        FavoriteInfo * pFavorite = lpFavoriteInfo + i++;
1953

    
1954
        FavoriteInfo item = m_listCurFav.GetNext(pos);
1955
        FavoriteInfo_Copy(*pFavorite, item);
1956
    }
1957
}
1958

    
1959
void CPlugCCTVC3::transferCurDisplayModes(LPDisplayModeInfo lpDisplaymode, int arrayCount)
1960
{
1961
    if (NULL == lpDisplaymode)
1962
        return;
1963

    
1964
    int i = 0;
1965
    POSITION pos = m_listCurDisplaymode.GetHeadPosition();
1966
    while (pos != NULL) {
1967
        if (i >= arrayCount)
1968
            break;
1969
        LPDisplayModeInfo pDispMode = lpDisplaymode + i++;
1970

    
1971
        DisplayModeInfo item = m_listCurDisplaymode.GetNext(pos);
1972
        DisplayModeInfo_Copy(*pDispMode, item);
1973
    }
1974
}
1975

    
1976

    
1977

    
1978
//////////////////////////////////////////////////////////////////////
1979

    
1980
int CPlugCCTVC3::insertItem_MonitorInfo(LPMonitorInfo pMonitor)
1981
{
1982
    char cmdbuf[2048] = {0};
1983
    strcpy(cmdbuf, "INSERT INTO SEMODEL.dbo.TB5012_CCTVMONITORINFO (");
1984
    int i;
1985
    strcat(cmdbuf, "F5012_SCREENCOUNT");
1986
    for (i=0; i<ScreenItemNameCount; i++)
1987
    {
1988
        strcat(cmdbuf, ",");
1989
        strcat(cmdbuf, ScreenItemNameArray[i].groupCode);
1990
        strcat(cmdbuf, ",");
1991
        strcat(cmdbuf, ScreenItemNameArray[i].camerCode);
1992
    }
1993
    strcat(cmdbuf, ") VALUES (");    
1994
    char tmpStr[128] = {0};
1995
    sprintf(tmpStr, "%d",  pMonitor->screenNum);
1996
    strcat(cmdbuf, tmpStr);
1997
    for (i=0; i<MaxNum_Screen; i++)
1998
    {
1999
        memset(tmpStr, 0, 128);
2000
        if (0 < strlen(pMonitor->screen[i].camera_desc.code))
2001
            sprintf(tmpStr, ",'%s','%s'", m_group[pMonitor->screen[i].groupIndex].code, pMonitor->screen[i].camera_desc.code);
2002
        else
2003
            sprintf(tmpStr, ",null,null");
2004
        strcat(cmdbuf, tmpStr);
2005
    }
2006
    strcat(cmdbuf, ");");
2007
    m_log->WriteFmtStrWithTime_L3("[insertItem_MonitorInfo] >>> SQL: %s", cmdbuf);
2008
    
2009
    CSE_DBOption dboption;
2010
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_ALL) != SEDB_SUCCESS) {
2011
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2012
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2013
    if (nRet != SEDB_SUCCESS) {
2014
        m_log->WriteFmtStrWithTime_L1("[insertItem_MonitorInfo] >>> failed to dboption.ExecuteCmd, err = %d", nRet);
2015
//         return 0;
2016
    }
2017

    
2018
    // get index
2019
    char cmdbuf2[512] = {0};
2020
    strcpy(cmdbuf2, "select max(F5012_NO) FROM SEMODEL.dbo.TB5012_CCTVMONITORINFO");
2021

    
2022
    dboption.BeginSelectRcdSet(cmdbuf2);
2023
    int nRcdCount = dboption.GetRcdCount();
2024
    if (nRcdCount <= 0) {
2025
        dboption.EndSelectRcdSet();
2026
        m_log->WriteFmtStrWithTime_L1("[insertItem_MonitorInfo] >>> no recorder is found");
2027
        return 0;
2028
    }
2029
    
2030
    pMonitor->index = (int)dboption.GetIntVal(0,0);
2031
    dboption.EndSelectRcdSet();
2032

    
2033
    return 1;
2034
}
2035

    
2036
int CPlugCCTVC3::insertItem_CurDisplayInfo(UINT ptzLevel, LPDisplayCurInfo pCurDisplayInfo)
2037
{
2038
	char cmdbuf[2048] = {0};
2039
	int nRet = 0;
2040
	CSE_DBOption dboption;
2041
	if(checkCurDisplyItem(ptzLevel))
2042
	{
2043
		strcpy(cmdbuf, "UPDATE SEMODEL.TB5016_CCTVCURINFO SET F5012_NO = ");
2044
		char tmpStr[128] = {0};
2045
		sprintf(tmpStr, "%d",pCurDisplayInfo->monitor.index);
2046
		strcat(cmdbuf, tmpStr);
2047
		sprintf(tmpStr, " WHERE F0101_PTZPLEVEL = %d;",ptzLevel);
2048
		strcat(cmdbuf, tmpStr);
2049
		m_log->WriteFmtStrWithTime_L3("SQL: %s", cmdbuf);
2050
		//nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);	
2051
		nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2052
	}	
2053
	else
2054
	{
2055
    
2056
		strcpy(cmdbuf, "INSERT INTO SEMODEL.TB5016_CCTVCURINFO (");
2057
		char * fieldCodes[] = {"F0101_PTZPLEVEL", "F5012_NO"};
2058
		int i;
2059
		for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
2060
			strcat(cmdbuf, fieldCodes[i]);
2061
			if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
2062
				strcat(cmdbuf, ",");
2063
		}
2064
		strcat(cmdbuf, ") VALUES (");    
2065
		char tmpStr[128] = {0};
2066
		sprintf(tmpStr, "%d,%d", ptzLevel, pCurDisplayInfo->monitor.index);
2067
		strcat(cmdbuf, tmpStr);
2068
		strcat(cmdbuf, ");");    
2069
		m_log->WriteFmtStrWithTime_L3("SQL: %s", cmdbuf);
2070

    
2071

    
2072
	//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
2073
	//         return 0;
2074
		 //nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2075
		nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2076
	}
2077
    
2078
    // get index
2079
    char cmdbuf2[512] = {0};
2080
    strcpy(cmdbuf2, "select max(F5016_NO) FROM SEMODEL.TB5016_CCTVCURINFO");
2081
    
2082
    dboption.BeginSelectRcdSet(cmdbuf2);
2083
    int nRcdCount = dboption.GetRcdCount();
2084
    if (nRcdCount <= 0) {
2085
        dboption.EndSelectRcdSet();
2086
        m_log->WriteFmtStrWithTime_L1("[updateItem_MonitorInfo] >>> no recorder is found");
2087
        return 0;
2088
    }
2089
    
2090
    pCurDisplayInfo->index = (int)dboption.GetIntVal(0,0);
2091
    dboption.EndSelectRcdSet();
2092
    
2093
    return 1;
2094
}
2095

    
2096
bool CPlugCCTVC3::checkCurDisplyItem(UINT nLevel)
2097
{
2098
	return FALSE; //??ʱ?ȷ???false??Ϊ?˲??ı???ǰ???߼?
2099

    
2100
	char cmdbuf[1024] = {0};
2101
    strcpy(cmdbuf, "SELECT * FROM SEMODEL.dbo.TB5016_CCTVCURINFO WHERE F0101_PTZPLEVEL = ");
2102
    
2103
	char tmpStr[128] = {0};
2104
	sprintf(tmpStr, "%d",nLevel);
2105
	strcat(cmdbuf, tmpStr);
2106
	strcat(cmdbuf, " ORDER BY F5016_NO DESC;");
2107

    
2108
    CSE_DBOption dboption;
2109
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2110
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2111
	if (nRet == SEDB_SUCCESS)
2112
	{
2113
		int nRcdCount = dboption.GetRcdCount();
2114
		if (nRcdCount > 0)
2115
		{
2116
			dboption.EndSelectRcdSet();
2117
			return TRUE;
2118
		}
2119
	}
2120

    
2121
	dboption.EndSelectRcdSet();
2122
	return FALSE;
2123
}
2124

    
2125
int CPlugCCTVC3::insertItem_DisplayMode(UINT ptzLevel, LPDisplayModeInfo pDisplayMode)
2126
{
2127
    char cmdbuf[2048] = {0};
2128
    strcpy(cmdbuf, "INSERT INTO SEMODEL.dbo.TB5014_CCTVDISPLAYMODE (");
2129
    char * fieldCodes[] = {"F0101_PTZPLEVEL", "F5012_NO", "F5014_DESC"};
2130
    int i;
2131
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
2132
        strcat(cmdbuf, fieldCodes[i]);
2133
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
2134
            strcat(cmdbuf, ",");
2135
    }
2136
    strcat(cmdbuf, ") VALUES (");    
2137
    char tmpStr[256] = {0};
2138
	memset(tmpStr,0,256);
2139
    sprintf(tmpStr, "%d,%d,'%s'", ptzLevel, pDisplayMode->monitor.index, pDisplayMode->desc);
2140
    strcat(cmdbuf, tmpStr);
2141
    strcat(cmdbuf, ");");
2142
	m_log->WriteFmtStrWithTime_L3("insertItem_DisplayMode SQL: %s", cmdbuf);
2143
    
2144
    CSE_DBOption dboption;
2145
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
2146
//         return 0;
2147
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2148
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2149

    
2150
    char cmdbuf2[512] = {0};
2151
    strcpy(cmdbuf2, "select max(F5014_NO) FROM SEMODEL.TB5014_CCTVDISPLAYMODE");
2152
    
2153
    dboption.BeginSelectRcdSet(cmdbuf2);
2154
    int nRcdCount = dboption.GetRcdCount();
2155
    if (nRcdCount <= 0) {
2156
        dboption.EndSelectRcdSet();
2157
        return 0;
2158
    }
2159
    
2160
    pDisplayMode->index = (int)dboption.GetIntVal(0,0);
2161
    dboption.EndSelectRcdSet();
2162
    
2163
    return 1;
2164
}
2165

    
2166
#if 1
2167
int CPlugCCTVC3::updateItem_MonitorInfo(LPMonitorInfo pMonitor)
2168
{
2169
    char cmdbuf[2048] = {0};
2170
    strcpy(cmdbuf, "UPDATE SEMODEL.dbo.TB5012_CCTVMONITORINFO SET ");
2171
    char tmpStr[128] = {0};
2172
    sprintf(tmpStr, "F5012_SCREENCOUNT=%d", pMonitor->screenNum);
2173
    strcat(cmdbuf, tmpStr);
2174
    int i;
2175
    for (i=0; i<ScreenItemNameCount; i++)
2176
    {
2177
        memset(tmpStr, 0, 128);
2178
        if (0 < strlen(pMonitor->screen[i].camera_desc.code))
2179
            sprintf(tmpStr, ", %s='%s', %s='%s'",
2180
                ScreenItemNameArray[i].groupCode, m_group[pMonitor->screen[i].groupIndex].code,
2181
                ScreenItemNameArray[i].camerCode, pMonitor->screen[i].camera_desc.code);
2182
        else
2183
            sprintf(tmpStr, ", %s=null, %s=null",
2184
            ScreenItemNameArray[i].groupCode,
2185
            ScreenItemNameArray[i].camerCode);
2186
        strcat(cmdbuf, tmpStr);
2187
    }
2188
    strcat(cmdbuf, " WHERE F5012_NO=");
2189
    memset(tmpStr, 0, 128);
2190
    sprintf(tmpStr, "%d", pMonitor->index);
2191
    strcat(cmdbuf, tmpStr);
2192
    m_log->WriteFmtStrWithTime_L3("SQL: %s", cmdbuf);
2193
    
2194
    CSE_DBOption dboption;
2195
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS) {
2196
//         m_log->WriteFmtStrWithTime_L1("[updateItem_MonitorInfo] >>> no recorder is found");
2197
//         return 0;
2198
//     }
2199
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2200
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2201
    if (nRet == 0)
2202
        m_log->WriteFmtStrWithTime_L1("[updateItem_MonitorInfo] >>> no recorder is found");
2203
    
2204
    return 1;
2205
}
2206
#else
2207
int CPlugCCTVC3::updateItem_MonitorInfo(LPMonitorInfo pMonitor)
2208
{
2209
    char cmdbuf[2048] = {0};
2210
    strcpy(cmdbuf, "UPDATE SEMODEL.TB5012_CCTVMONITORINFO SET (");
2211
    int i;
2212
    strcat(cmdbuf, "F5012_SCREENCOUNT");
2213
    for (i=0; i<ScreenItemNameCount; i++)
2214
    {
2215
        strcat(cmdbuf, ",");
2216
        strcat(cmdbuf, ScreenItemNameArray[i].groupCode);
2217
        strcat(cmdbuf, ",");
2218
        strcat(cmdbuf, ScreenItemNameArray[i].camerCode);
2219
    }
2220
    strcat(cmdbuf, ") = (select ");    
2221
    char tmpStr[128] = {0};
2222
    sprintf(tmpStr, "%d", pMonitor->screenNum);
2223
    strcat(cmdbuf, tmpStr);
2224
    for (i=0; i<MaxNum_Screen; i++)
2225
    {
2226
        memset(tmpStr, 0, 128);
2227
        if (0 < strlen(pMonitor->screen[i].cameraCode))
2228
            sprintf(tmpStr, ",'%s','%s'", m_group[pMonitor->screen[i].groupIndex].code, pMonitor->screen[i].cameraCode);
2229
        else
2230
            sprintf(tmpStr, ",null,null");
2231
        strcat(cmdbuf, tmpStr);
2232
    }
2233
    strcat(cmdbuf, " from dual) WHERE F5012_NO=");    
2234
    memset(tmpStr, 0, 128);
2235
    sprintf(tmpStr, "%d", pMonitor->index);
2236
    strcat(cmdbuf, tmpStr);
2237
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
2238

    
2239
    CSE_DBOption dboption;
2240
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
2241
//         return 0;
2242
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2243
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2244

    
2245
    return 1;
2246
}
2247
#endif
2248

    
2249

    
2250
int CPlugCCTVC3::removeItem_MonitorInfo(LPMonitorInfo pMonitor)
2251
{
2252
    char cmdbuf[1024] = {0};
2253
    strcpy(cmdbuf, "DELETE FROM SEMODEL.TB5012_CCTVMONITORINFO WHERE F5012_NO=");
2254
    char tmpStr[32] = {0};
2255
    sprintf(tmpStr, "%d", pMonitor->index);
2256
    strcat(cmdbuf, tmpStr);
2257
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
2258
    
2259
    CSE_DBOption dboption;
2260
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
2261
//         return 0;
2262
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2263
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2264

    
2265
    return 1;
2266
}
2267

    
2268
int CPlugCCTVC3::removeItem_DisplayMode(LPDisplayModeInfo pDisplayMode)
2269
{
2270
    char cmdbuf[1024] = {0};
2271
    strcpy(cmdbuf, "DELETE FROM SEMODEL.TB5014_CCTVDISPLAYMODE WHERE F5014_NO=");
2272
    char tmpStr[32] = {0};
2273
    sprintf(tmpStr, "%d", pDisplayMode->index);
2274
    strcat(cmdbuf, tmpStr);
2275
//     m_log->WriteFmtStrWithTime_L3("%s", cmdbuf);
2276
    
2277
    CSE_DBOption dboption;
2278
//     if (dboption.ExecuteCmd(cmdbuf, SERVER_MAIN) != SEDB_SUCCESS)
2279
//         return 0;
2280
    //int nRet = dboption.ExecuteCmd(cmdbuf, SERVER_MAIN);
2281
	int nRet = dboption.ExecuteCmd(cmdbuf);//BUG #251 CCTV???????????л?????ͷ????????ͬ??д?????????ͬ????????
2282

    
2283
    return 1;
2284
}
2285

    
2286
unsigned char CPlugCCTVC3::getDiv(LPScreenSet lpScreenSet)
2287
{
2288
	if(lpScreenSet->screenIndex < 4)  
2289
	{
2290
		if (lpScreenSet->screenNum == 5 || lpScreenSet->screenNum == 1 || lpScreenSet->screenNum == 7) // lpScreenSet->screenNum == 5\7\1˵??ǰ4????????4??1????
2291
		{
2292
			return 0;
2293
		}
2294
		else
2295
		{
2296
			return 1;
2297
		}
2298
	}
2299
	else
2300
	{
2301
		if (lpScreenSet->screenNum == 4 || lpScreenSet->screenNum == 5 || lpScreenSet->screenNum == 8) // lpScreenSet->screenNum == 4??5??8??˵????4????Ϊ4????
2302
		{
2303
			return 1;
2304
		}
2305
		else
2306
		{
2307
			return 0;
2308
		}
2309
	}
2310
}
2311

    
2312
////////////////////////////////////////////////////////////////////////////////////
2313

    
2314
int CPlugCCTVC3::switchCamera(LPScreenSet lpScreenSet)
2315
{
2316
    CameraInfo camera_info;
2317
    CameraInfo_Init(&camera_info);
2318
    strcpy(camera_info.desc.code, lpScreenSet->screen.camera_desc.code);
2319
    if ( getCameraInfoByCode(&camera_info) <= 0 )
2320
        return -1;
2321
    
2322
    ALM_D_BASE_INFO alminfo = {0};
2323
    memset(&alminfo, 0, sizeof(ALM_D_BASE_INFO));
2324
    
2325
    strcpy(alminfo.DeviceKey, camera_info.desc.code);
2326
    strcpy(alminfo.ClassName, "Control");
2327
    alminfo.Operator = ALM_K_OPR_ALM;
2328
    
2329
    CSeTime kt;
2330
    TCriterionTime ct;
2331
    kt.GetNow(&ct, &alminfo.Msec);
2332
    alminfo.Second = ct;
2333
    alminfo.Priority = ALM_K_PRI_EVENT;
2334
    alminfo.DeviceType = 80;
2335
    alminfo.MessageId = 1;
2336
    strcpy(alminfo.Graph, "");
2337
    alminfo.AttrNum = 5;
2338
    
2339
    strcpy(alminfo.UserAttrList[0].UserAttrName, "User");
2340
    
2341
    strcpy(alminfo.UserAttrList[1].UserAttrName, "Console");
2342
    get_host_name(alminfo.UserAttrList[1].UserAttrVal);
2343
    AOJ_GetConsoleDesc(alminfo.UserAttrList[1].UserAttrVal, alminfo.UserAttrList[1].UserAttrValDesc);
2344
    
2345
    strcpy(alminfo.UserAttrList[2].UserAttrName, "CtrlType");
2346
    sprintf(alminfo.UserAttrList[2].UserAttrVal, "%d", CCTV_E_VIEW);
2347
    strcpy(alminfo.UserAttrList[2].UserAttrValDesc, "ͼ????ʾ");
2348
    
2349
    strcpy(alminfo.UserAttrList[3].UserAttrName, "CtrlState");
2350
    strcpy(alminfo.UserAttrList[3].UserAttrVal, "0");
2351
    strcpy(alminfo.UserAttrList[3].UserAttrValDesc, "?ɹ?");
2352
    
2353
    strcpy(alminfo.UserAttrList[4].UserAttrName, "Point");
2354
    strcpy(alminfo.UserAttrList[4].UserAttrVal, camera_info.desc.code);	
2355
    
2356
    AOJ_D_ASSIGNMENT AojMask;
2357
    AOJ_GetAssignment(NULL, AojMask, DEF_RIGHT_DEVICE_C);
2358
    
2359
    char   UserName[SE_K_USER_CODE] = {0};
2360
    RBAC_GetUserRoleDescription(UserName, alminfo.UserAttrList[0].UserAttrValDesc, NULL, NULL);
2361
    strcpy(alminfo.UserAttrList[0].UserAttrVal, UserName);	
2362
    
2363
    alminfo.Aoj = camera_info.aoj;
2364
    alminfo.AppSysId = camera_info.appSysID;
2365
    strcpy(alminfo.UserAttrList[4].UserAttrValDesc, camera_info.desc.data);
2366
    strcpy(alminfo.GroupName, m_group[lpScreenSet->screen.groupIndex].code);
2367
/*    
2368
    if(!m_isLevel2)
2369
	{
2370
		m_csi.CCTV_Login(m_nPLevel);
2371
	}
2372
	else
2373
	{
2374
		m_csi.CCTV_Login(m_nPLevel2);
2375
	}
2376
*/    
2377
//    m_Sta = lpScreenSet->screen.groupIndex + 1;//վ
2378
	m_Sta = m_group[lpScreenSet->screen.groupIndex].groupno;//WYF 20190425
2379
  //  m_Div = (lpScreenSet->screenNum == MaxNum_Screen || lpScreenSet->screenNum == MaxNum_ScreenColumn) ? 1 : 0;//??ǰ??????
2380
	m_Div = getDiv(lpScreenSet);
2381
    m_Win = lpScreenSet->screenIndex + 1;//1????:????0   4????:????0 ~ ????3
2382
    m_Wall = 2; // ??ȷ????????ǽ???
2383
    m_Task = 3; // ??ȷ??????????
2384
    if(lpScreenSet->screenIndex<4) // ǰ4??????ptzLevel
2385
	{
2386
		m_csi.CCTV_Login(m_nPLevel);m_isLevel2=false;
2387
	}
2388
	else // ??4??????ptzLevel2
2389
	{
2390
		m_csi.CCTV_Login(m_nPLevel2);m_isLevel2=true;
2391
	}
2392

    
2393
	if(m_nDigAnaCCTVtype == 2 && m_Div == 0)//17???߲???Ҫ?˹??? 17???ߵ?ʱ???????ļ?????DigAnaCCTVtypeֵҪ??Ϊ1
2394
	{
2395
		if(lpScreenSet->screenIndex < 4)
2396
		{
2397
			m_Win = (m_nLast4ScreenFocusIndex==0)?1:m_nLast4ScreenFocusIndex+1;
2398
		}
2399
		else
2400
		{
2401
			m_Win = m_nLast4ScreenFocusIndex2 +1;
2402
		}
2403
	}
2404

    
2405
	CameraDesc camera_Desc;
2406
	CameraDesc_Init(&camera_Desc);
2407
    strcpy(camera_Desc.code, m_decode[0][m_Win-1]);
2408
	getCCTVDeviceNumber(&camera_Desc,1);
2409

    
2410
	BYTE deviceNum = atoi(camera_Desc.deviceNumber);//???ֵС??255
2411

    
2412
	// ??ȡmonitor??code???????Ļ??????4????ʹ?õ?2??monitor??code  lilei 20190710
2413
	char* code = m_display.dispatch[0].code;
2414
	if (m_Win > 4)
2415
	{
2416
		code = m_display.dispatch[0].code2;
2417
	}
2418

    
2419
    m_log->WriteFmtStrWithTime_L2("(%d) switch camera >>> camera: %s, line: %d, station: %d, div: %d, win: %d, monitor: %s, decode: %d,??ɫ%d",
2420
        __LINE__, camera_info.desc.code, m_Line, m_Sta, m_Div, m_Win, code, deviceNum,m_isLevel2*m_nPLevel2);
2421

    
2422
    m_csi.CCTV_SelectCam(camera_info.desc.code, m_Line, m_Sta, m_Div, (m_Win-1)%4+1, m_Wall, m_Task, (char)deviceNum);
2423

    
2424
   // m_csi.CCTV_SelectMon(m_display.dispatch[0].code);
2425
	m_csi.CCTV_SelectMon(code);
2426

    
2427
    m_csi.CCTV_Switch();
2428
    //m_csi.AlmSignal(UserName, alminfo);//ע?ʹ˴???,??????ʷ??ѹ??. feature #130 Yansx 20190610
2429
    
2430
    return 1;
2431
}
2432

    
2433
int CPlugCCTVC3::cameraAct(LPScreenSet lpScreenSet, OperTypeCamera oper_type, int nMouseState ,void * value)
2434
{
2435
    if (NULL == lpScreenSet || NULL == value)
2436
        return 0;
2437

    
2438
	unsigned short nowMsec=0;
2439
	//sint32 nowSec=GetNowSecond(&nowMsec);//WYF 20190127
2440
	//if(2>nowSec-m_LastSendSec)return 0; //Remove by Yansx 2019-03-04 ??Ϊ????click?¼???ֳ?Down??Up?¼?,???Է???UI??ȥ??2?????.
2441
    LPPtzCtlInfoEx lpPtzctlex = (LPPtzCtlInfoEx)value;
2442

    
2443
    CameraInfo camera_info;
2444
    CameraInfo_Init(&camera_info);
2445
    strcpy(camera_info.desc.code, lpScreenSet->screen.camera_desc.code);
2446
    if ( getCameraInfoByCode(&camera_info) <= 0 )
2447
        return -1;
2448

    
2449
    ALM_D_BASE_INFO alminfo = {0};
2450
    memset(&alminfo, 0, sizeof(ALM_D_BASE_INFO));
2451
    
2452
    strcpy(alminfo.DeviceKey, camera_info.desc.code);
2453
    strcpy(alminfo.ClassName, "Control");
2454
    alminfo.Operator = ALM_K_OPR_ALM;
2455
    
2456
    CSeTime kt;
2457
    TCriterionTime ct;
2458
    kt.GetNow(&ct, &alminfo.Msec);
2459
    alminfo.Second = ct;
2460
    alminfo.Priority = ALM_K_PRI_EVENT;
2461
    alminfo.DeviceType = 80;
2462
    alminfo.MessageId = 1;
2463
    strcpy(alminfo.Graph, "");
2464
    alminfo.AttrNum = 5;
2465

    
2466
    strcpy(alminfo.UserAttrList[0].UserAttrName, "User");
2467
    
2468
    strcpy(alminfo.UserAttrList[1].UserAttrName, "Console");
2469
    get_host_name(alminfo.UserAttrList[1].UserAttrVal);
2470
    AOJ_GetConsoleDesc(alminfo.UserAttrList[1].UserAttrVal, alminfo.UserAttrList[1].UserAttrValDesc);
2471
    
2472
    strcpy(alminfo.UserAttrList[2].UserAttrName, "CtrlType");
2473
    sprintf(alminfo.UserAttrList[2].UserAttrVal, "%d", lpPtzctlex->ptz.ctrlValue);
2474
    strcpy(alminfo.UserAttrList[2].UserAttrValDesc, lpPtzctlex->desc);
2475
    
2476
    strcpy(alminfo.UserAttrList[3].UserAttrName, "CtrlState");
2477
    strcpy(alminfo.UserAttrList[3].UserAttrVal, "0");
2478
    strcpy(alminfo.UserAttrList[3].UserAttrValDesc, "?ɹ?");
2479
    
2480
    strcpy(alminfo.UserAttrList[4].UserAttrName, "Point");
2481
    strcpy(alminfo.UserAttrList[4].UserAttrVal, camera_info.desc.code);	
2482
    
2483
    AOJ_D_ASSIGNMENT AojMask;
2484
    AOJ_GetAssignment(NULL,AojMask, DEF_RIGHT_DEVICE_C);
2485
    
2486
    char   UserName[SE_K_USER_CODE] = {0};
2487
    RBAC_GetUserRoleDescription(UserName, alminfo.UserAttrList[0].UserAttrValDesc, NULL, NULL);
2488
    strcpy(alminfo.UserAttrList[0].UserAttrVal, UserName);	
2489
    
2490
    alminfo.Aoj = camera_info.aoj;
2491
    alminfo.AppSysId = camera_info.appSysID;
2492
    strcpy(alminfo.UserAttrList[4].UserAttrValDesc, camera_info.desc.data);
2493
    strcpy(alminfo.GroupName, m_group[lpScreenSet->screen.groupIndex].code);
2494

    
2495
    m_csi.CCTV_Login(m_nPLevel);
2496
    
2497
//    m_Sta = lpScreenSet->screen.groupIndex + 1;
2498
	m_Sta = m_group[lpScreenSet->screen.groupIndex].groupno;//WYF 20190425
2499
    //m_Div = (lpScreenSet->screenNum == MaxNum_Screen || lpScreenSet->screenNum == MaxNum_ScreenColumn) ? 1 : 0;
2500
	m_Div = getDiv(lpScreenSet);
2501
    m_Win = lpScreenSet->screenIndex + 1;
2502
    m_Wall = 2; // ??ȷ????????ǽ???
2503
    //m_Task = 3; // ??ȷ??????????
2504
	m_Task = nMouseState;//???ֵ??????ʱ??????ʾ????״̬,1??ʾDown,0??ʾUp Yansx 2019-02-27
2505

    
2506
	if(lpScreenSet->screenIndex<4)
2507
	{
2508
		m_csi.CCTV_Login(m_nPLevel);m_isLevel2=false;
2509
	}
2510
	else
2511
	{
2512
		m_csi.CCTV_Login(m_nPLevel2);m_isLevel2=true;
2513
	}
2514

    
2515

    
2516
	if(m_nDigAnaCCTVtype == 2 && m_Div == 0)//17???߲???Ҫ?˹??? 17???ߵ?ʱ???????ļ?????DigAnaCCTVtypeֵҪ??Ϊ1
2517
	{
2518
		if(lpScreenSet->screenIndex < 4)
2519
		{
2520
			m_Win = (m_nLast4ScreenFocusIndex==0)?1:m_nLast4ScreenFocusIndex+1;
2521
		}
2522
		else
2523
		{
2524
			m_Win = m_nLast4ScreenFocusIndex2 +1;
2525
		}
2526
	}
2527

    
2528
	//Yansx 20190130
2529
	CameraDesc camera_Desc;
2530
	CameraDesc_Init(&camera_Desc);
2531
    strcpy(camera_Desc.code, m_decode[0][m_Win-1]);
2532
	getCCTVDeviceNumber(&camera_Desc,1);
2533

    
2534
	BYTE deviceNum = atoi(camera_Desc.deviceNumber);//???ֵС??255
2535
	
2536
	// ??ȡmonitor??code???????Ļ??????4????ʹ?õ?2??monitor??code  lilei 20190710
2537
	char* code = m_display.dispatch[0].code;
2538
	if (m_Win > 4)
2539
	{
2540
		code = m_display.dispatch[0].code2;
2541
	}
2542

    
2543
//     m_log->WriteFmtStrWithTime_L2("(%d) control camera >>> camera: %s, line: %d, station: %d, div: %d, win: %d,MouseState: %d, monitor: %s",
2544
//         __LINE__, camera_info.desc.code, m_Line, m_Sta, m_Div, m_Win,m_Task, code);
2545
	m_log->WriteFmtStrWithTime_L2("(%d) control camera >>> camera: %s, line: %d, station: %d, div: %d, win: %d,MouseState: %d, monitor: %s, decode: %d,??ɫ%d" ,
2546
		__LINE__, camera_info.desc.code, m_Line, m_Sta, m_Div, (m_Win-1)%4+1, m_Task, code, deviceNum,m_isLevel2*m_nPLevel2);
2547
    m_csi.CCTV_SelectCam(camera_info.desc.code, m_Line, m_Sta, m_Div, (m_Win-1)%4+1, m_Wall, m_Task, (char)deviceNum);
2548
    
2549
    m_csi.CCTV_SelectMon(code);
2550

    
2551
    if (lpPtzctlex->ptz.ctrlValue == CCTV_E_PRESET_GOTO)
2552
    {
2553
        m_log->WriteFmtStrWithTime_L2("(%d) go to preset place %d", __LINE__, lpPtzctlex->ptz.paraValue);
2554
        m_csi.CCTV_View(lpPtzctlex->ptz.paraValue);
2555
    }
2556
    else {
2557
        m_log->WriteFmtStrWithTime_L2("(%d) PTZ: type = %d, steplen = %d", __LINE__, lpPtzctlex->ptz.ctrlValue, lpPtzctlex->ptz.paraValue);
2558
        m_csi.CCTV_PTZ(lpPtzctlex->ptz.ctrlValue, lpPtzctlex->ptz.paraValue); // ptz????
2559
    }
2560
    //m_csi.AlmSignal(UserName, alminfo);//ע?ʹ˴???,??????ʷ??ѹ??. feature #130 Yansx 20190610
2561
	//m_LastSendSec=GetNowSecond(&m_LastSendMsec);//WYF 20190127
2562

    
2563
    return 1;
2564
}
2565

    
2566

    
(2-2/5)