⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsetting.cpp

📁 实时监控
💻 CPP
字号:
// LSetting.cpp : implementation file
//

#include "stdafx.h"
#include "../Resource.h"
#include "../utils/custom_msgs.h"
#include "../dvrmanager.h"
#include "fileoperation.h"
#include "LSetting.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLSetting dialog


CLSetting::CLSetting(CWnd* pParent /*=NULL*/)
	: CDialog(CLSetting::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLSetting)
	m_dvrname = _T("");
	m_ip = _T("");
	m_loginpass = _T("");
	m_port = 8101;
	m_loginuser = _T("");
	//}}AFX_DATA_INIT
	m_brush.CreateSolidBrush(RGB(117, 200, 146));
}


void CLSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLSetting)
	DDX_Control(pDX, ID_GROUP1, m_grp1);
	DDX_Control(pDX, IDC_lable6, m_lable6);
	DDX_Control(pDX, IDC_lable5, m_lable5);
	DDX_Control(pDX, IDC_lable4, m_lable4);
	DDX_Control(pDX, IDC_lable3, m_lable3);
	DDX_Control(pDX, IDC_lable2, m_lable2);
	DDX_Control(pDX, IDC_lable1, m_lable1);
	DDX_Control(pDX, IDOK, m_ok);
	DDX_Control(pDX, IDCANCEL, m_cancel);
	DDX_Control(pDX, IDC_dvrname, m_dvrcontrol);
	DDX_Text(pDX, IDC_dvrname, m_dvrname);
	DDX_Text(pDX, IDC_IPADDRESS, m_ip);
//	DDX_Control(pDX, IDC_IPADDRESS, m_ipcontrol);
	DDX_Text(pDX, IDC_loginpass, m_loginpass);
	DDX_Text(pDX, IDC_port, m_port);
	DDX_Text(pDX, IDC_loginuser, m_loginuser);
	//}}AFX_DATA_MAP
	if(m_control) m_dvrcontrol.EnableWindow(false);
}


BEGIN_MESSAGE_MAP(CLSetting, CDialog)
	//{{AFX_MSG_MAP(CLSetting)
		ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLSetting message handlers
extern CString m_login_client_name;

extern char m_remote_station_directory[150];
extern char m_channel_window_directory[150];
extern char m_inspect_date_query_directory[150];
extern char	m_alarm_server_link_directory[150];

void CLSetting::OnOK() 
{
   UpdateData(true);
   CString m_logfile;
   m_logfile.Format(IDS_STATION_SET);
   Openfile();
   openmachine();
   if(m_control) 
   {
	   updatefile();
	   savefile();
	   savemachine();
	   postmsg();
	   write_log_file(m_logfile);
	   CDialog::OnOK();
   }
   else if(addfile())
   {
     savefile();
	 postmsg();
     write_log_file(m_logfile);
     CDialog::OnOK();
   }
   else update(); 
}
void CLSetting::postmsg()
{
   UpdateData(true);
   Remote_Station_setting m_station_p;

   strcpy(m_station_p.dvrname,m_dvrname);
   //m_ipcontrol.GetWindowText(m_ip); 
   strcpy(m_station_p.ip, m_ip);
   m_station_p.port=m_port;
   strcpy(m_station_p.logindvrname,m_loginuser);
   strcpy(m_station_p.logindvrpass,m_loginpass);
   if(m_control) 
      CRightLogin::the_one()->SendMessage(NTM_CMD_LOGIN_UPDATE, (WPARAM)&m_station_p);
   else
      CRightLogin::the_one()->SendMessage(NTM_CMD_LOGIN_AGAIN, (WPARAM)&m_station_p);
}
void CLSetting::update()
{
    m_dvrname = _T("");
	m_ip = _T("");
	m_loginpass = _T("");
	m_port = 8101;
	m_loginuser = _T("");
	UpdateData(false);

}


void CLSetting::updatefile()
{
	UpdateData(true);
	//m_ipcontrol.GetWindowText(m_ip); 
	if(m_loginuser.GetLength()>19)
	{
		AfxMessageBox(ID_INPUT_IS_OVER);
		return;
	}
	
	//if(!testadd(m_ip, m_port)) 
	//	return;

	for(int i=0;i<m_file_length;i++)
	{
      if(!strcmp(m_station[i].name,m_login_client_name)&&!strcmp(m_station[i].dvrname,m_dvrname))
      {
         strcpy(m_station[i].ip,m_ip);
		 m_station[i].port=m_port;
		 strcpy(m_station[i].logindvrname,m_loginuser);
		 strcpy(m_station[i].logindvrpass,m_loginpass);
	  }
	}

    for(int m=0;m<m_file_length1;m++)
	{
      if(!strcmp(m_machine[m].name,m_login_client_name)&&!strcmp(m_machine[m].dvrname,m_dvrname))
      {
		 //m_ipcontrol.GetWindowText(m_ip); 
         strcpy(m_machine[m].ip,m_ip);
		 m_machine[m].port=m_port;
		 strcpy(m_machine[m].logindvrname,m_loginuser);
		 strcpy(m_machine[m].logindvrpass,m_loginpass);
	  }
	}
}

bool CLSetting::testadd(CString m_str, USHORT port )
{
  for(int i=0;i<m_file_length;i++)
  {
      if(!strcmp(m_station[i].name,m_login_client_name))
      if(!strcmp(m_station[i].ip, m_str) && m_station[i].port == port ) 
	  {
		AfxMessageBox(IDS_SAME_VALUE);
		return false;
	  }	
  }
  return true;
}

ULONG CLSetting::create_randomdata()
{
	int num;
	srand((unsigned)time( NULL ));

	while(1)
	{
		num = rand();
		if(num < 10000)
			return num;
	}
}

bool CLSetting::addfile()
{
   	UpdateData(true);
	//m_ipcontrol.GetWindowText(m_ip);
	if(!checkdvrname(m_dvrname))
	{
		AfxMessageBox(IDS_SAME_VALUE);
		return false;
	}
    if(!testadd(m_ip, m_port)) return false;
    if(!strcmp(m_dvrname,"")) return false;
    if(m_file_length >= 120)
	{
		AfxMessageBox(ID_ADD_STATION_OVER);
		return false;
	}
	if(m_dvrname.GetLength()>19 || m_loginuser.GetLength()>19)
	{
		AfxMessageBox(ID_INPUT_IS_OVER);
		return false;
	}
	m_station[m_file_length].stid = create_randomdata();
	strcpy(m_station[m_file_length].name,m_login_client_name);
	strcpy(m_station[m_file_length].dvrname,m_dvrname);
	strcpy(m_station[m_file_length].ip,m_ip);
    m_station[m_file_length].port=m_port;
	strcpy(m_station[m_file_length].logindvrname,m_loginuser);
	strcpy(m_station[m_file_length].logindvrpass,m_loginpass);
	m_file_length++;
	return true;
}

void CLSetting::Openfile()
{
	Cfileoperation <Remote_Station_setting> *m_fileoperation;
    m_file_length=m_fileoperation->openfile(m_remote_station_directory,"ab+",m_station);
}

void CLSetting::openmachine()
{
	Cfileoperation <Machine_Channel_Setting> *m_fileoperation;
    m_file_length1=m_fileoperation->openfile(m_channel_window_directory,"ab+",m_machine,300);
}

void CLSetting::opendecodestate()
{
	Cfileoperation <inspect_date_query> *m_fileoperation;
    m_file_length2 = m_fileoperation->openfile(m_inspect_date_query_directory,"ab+",m_station_data);
}

void CLSetting::openalarmserver()
{
	Cfileoperation <Alarm_Server_Linking> *m_fileoperation;
    m_file_length3 = m_fileoperation->openfile(m_alarm_server_link_directory,"ab+", m_alarmserver,300);
}

void CLSetting::savefile()
{
    Cfileoperation <Remote_Station_setting> *m_fileoperation;
    m_fileoperation->savefilename(m_remote_station_directory,"wb+",m_station,m_file_length);
}

void CLSetting::savemachine()
{
	Cfileoperation <Machine_Channel_Setting> *m_fileoperation;
    m_fileoperation->savefilename(m_channel_window_directory,"wb+",m_machine,m_file_length1);
}
void CLSetting::savedecodestate()
{
    Cfileoperation <inspect_date_query> *m_fileoperation;
    m_fileoperation->savefilename(m_inspect_date_query_directory, "wb+", m_station_data, m_file_length2);
}
void CLSetting::savealarmserver()
{
    Cfileoperation <Alarm_Server_Linking> *m_fileoperation;
    m_fileoperation->savefilename(m_alarm_server_link_directory, "wb+", m_alarmserver, m_file_length3);
}

void CLSetting::delfile()
{
	Openfile();
	openmachine();
	opendecodestate();
	openalarmserver();
	for(int m=0;m<m_file_length;m++)
	{
       if(!strcmp(m_station[m].name,m_login_client_name)&&!strcmp(m_station[m].dvrname,m_dvrname))
	   {  
	    strcpy(m_station[m].name ,"");
	   }   
	}

	for(int i=0;i<m_file_length1;i++)
	{
       if(!strcmp(m_machine[i].name,m_login_client_name)&&!strcmp(m_machine[i].dvrname,m_dvrname))
	   {  
	    strcpy(m_machine[i].name ,"");
	   }   
	}

	for(int k=0;k<m_file_length2;k++)
	{
       if(!strcmp(m_station_data[k].name,m_login_client_name)&&!strcmp(m_station_data[k].dvrname,m_dvrname))
	   {  
	    strcpy(m_station_data[k].name ,"");
	   }   
	}

	for(k=0;k<m_file_length3;k++)
	{
       if(!strcmp(m_alarmserver[k].name,m_login_client_name)&&!strcmp(m_alarmserver[k].dvrname,m_dvrname))
	   {  
	    strcpy(m_alarmserver[k].name ,"");
	   }   
	}

	savefile();
	savemachine();
	savedecodestate();
	savealarmserver();
}
bool CLSetting::checkdvrname(CString m_str)
{
  for(int m=0;m<m_file_length;m++)
  {
     if(!strcmp(m_station[m].name,m_login_client_name)&&!strcmp(m_station[m].dvrname,m_str))
	    return false;   
  }
  return true;
}

HBRUSH CLSetting::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	if (nCtlColor==CTLCOLOR_DLG) 
	return (HBRUSH)m_brush .GetSafeHandle( ) ;
	return hbr;
}

BOOL CLSetting::OnInitDialog() 
{	
	CDialog::OnInitDialog();
	init_label(m_lable1);
	init_label(m_lable2);
	init_label(m_lable3);
	init_label(m_lable4);
	init_label(m_lable5);
	init_title(m_lable6);
	//m_ipcontrol.SetWindowText(m_ip);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -