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

📄 querydecstate.cpp

📁 实时监控
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	DDX_Text(pDX, IDC_QUOTIWTY2, m_quotiwty2);
	DDX_Text(pDX, IDC_QUOTIWTY3, m_quotiwty3);
	DDX_Text(pDX, IDC_QUOTIWTY4, m_quotiwty4);

	DDX_Text(pDX, IDC_NAME1, m_name1);
	DDX_Text(pDX, IDC_NAME2, m_name2);
	DDX_Text(pDX, IDC_NAME3, m_name3);
	DDX_Text(pDX, IDC_NAME4, m_name4);
	
	DDX_Text(pDX, IDC_SWITCH_NAME1, m_switch_name1);
	DDX_Text(pDX, IDC_SWITCH_NAME2, m_switch_name2);
	DDX_Text(pDX, IDC_SWITCH_NAME3, m_switch_name3);
	DDX_Text(pDX, IDC_SWITCH_NAME4, m_switch_name4);

	DDX_CBIndex(pDX, IDC_SWITCH1_TYPE, m_switch_type1);
	DDX_CBIndex(pDX, IDC_SWITCH2_TYPE, m_switch_type2);
	DDX_CBIndex(pDX, IDC_SWITCH3_TYPE, m_switch_type3);
	DDX_CBIndex(pDX, IDC_SWITCH4_TYPE, m_switch_type4);

	DDX_Control(pDX, IDC_TEM_STATION, m_combo);
	DDX_Control(pDX, IDC_DECODE_ADD, m_dec_addctl);
	DDX_Control(pDX, IDC_TREE, m_tree);
	
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUpdateDecFile, CPropertyPage)
	//{{AFX_MSG_MAP(CUpdateDecFile)
		// NOTE: the ClassWizard will add message map macros here
		ON_BN_CLICKED(ID_ADD, OnAdd)
		ON_BN_CLICKED(ID_DEL, OnDel)
		ON_BN_CLICKED(ID_UPDATE, Onupdate)
		ON_CBN_SETFOCUS(IDC_DECODE_ADD, OnSetfocuseaddress)
		ON_CBN_SETFOCUS(IDC_TEM_STATION, OnSetfocusCombo)
		ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnDblclkTree)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CUpdateDecFile::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	on_add_list();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CUpdateDecFile::OnDblclkTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HTREEITEM  htree = m_tree.GetSelectedItem();
	CString m_decoder = m_tree.GetItemText(htree);
	htree = m_tree.GetParentItem(htree);
	if(htree)
	{
		CString m_station = m_tree.GetItemText(htree);
		on_data_update(m_station, m_decoder);
	}
	*pResult = 0;
}

bool CUpdateDecFile::testadd(CString m_station_name)
{
	UpdateData(TRUE);
	if(atoi(m_dec_add)>63 || atoi(m_dec_add)<0)
		return false;
	for(int i=0; i<m_file_length; i++)
	{
		inspect_date_query *p = &m_station_data[i];
		if(!strcmp(p->dvrname, m_station_name) && !strcmp(p->name, m_login_client_name))
		{
			if(!strcmp(p->decodename, m_dec_name) || p->address == atoi(m_dec_add))
				return false;
		}
	}
	return true;
}

void CUpdateDecFile::on_open_file()
{
	Cfileoperation <inspect_date_query> *m_fileoperation;
    m_file_length = m_fileoperation->openfile(m_inspect_date_query_directory,"rb",m_station_data);
}

void CUpdateDecFile::on_taxis_all_data(int postion)
{
	inspect_date_query * p, *pk, * pb;
	pk = &m_station_data[postion];

	for(int i=0; i<m_file_length; i++)
	{
		if(i == postion) continue;
		if(i == postion-1)
			pb = &m_station_data[i+2];
		else
			pb = &m_station_data[i+1];
		p = &m_station_data[i];
		
		if(!strcmp(pk->dvrname , p->dvrname) && !strcmp(pk->name, p->name))
		{
			if(!strcmp(pk->dvrname , pb->dvrname) && !strcmp(pk->name, pb->name))
			{
				if( p->address < pk->address && pk->address < pb->address)
				{
					on_taxis_data(i+1, postion);
					break;
				}
				else if(p->address > pk->address)
				{
					on_taxis_data(i, postion);
					break;
				}
			}
			else
			{
				on_taxis_data(i+1, postion);
				break;
			}
		}
		else if(!strcmp(pk->dvrname , pb->dvrname) && !strcmp(pk->name, pb->name))
		{
			if(pk->address < pb->address)
			{
					on_taxis_data(i+1, postion);
					break;
			}
		}

	}	
}
void CUpdateDecFile::on_taxis_data(int index, int postion)
{
	inspect_date_query m_temp = m_station_data[postion];
	if(postion < index)
	{
		for(int i=postion; i<index-1; i++)
		{
			m_station_data[i] = m_station_data[i+1];
		}
		m_station_data[index-1] =  m_temp;
	}
    if(postion > index)
	{
		for(int i=postion; i>index; i--)
		{
			m_station_data[i] = m_station_data[i-1];
		}
		m_station_data[index] =  m_temp;
	}
    
}

void CUpdateDecFile::on_add_list()
{
	if(m_tree.GetCount())
		m_tree.DeleteAllItems();
	on_open_file();

	HTREEITEM  htreem;

	for(int i=0; i<m_file_length; i++)
	{
		inspect_date_query *pk = &m_station_data[i];
		if(!strcmp(pk->name, m_login_client_name))
		{
			if(i ==0)
			{
				htreem = m_tree.InsertItem(pk->dvrname);
				m_tree.InsertItem(pk->decodename, htreem);
				continue;
			}

			inspect_date_query *p = &m_station_data[i-1];
			if(!strcmp(p->dvrname, pk->dvrname) && !strcmp(p->name, pk->name))
				m_tree.InsertItem(pk->decodename, htreem);
			else
			{
				htreem = m_tree.InsertItem(pk->dvrname);
				m_tree.InsertItem(pk->decodename, htreem);
			}
		}
	}
}

void CUpdateDecFile::OnSetfocusCombo()
{
	FILE *m_file;
	Remote_Station_setting m_comstation;
    m_file = fopen(m_remote_station_directory,"rb");
	if(m_file == NULL)
	{
		AfxMessageBox(IDS_OPEN_FILE);
		return;
	}
	m_combo.ResetContent();
	int tt =0;
	for(int i=0; ;i++)
	{
		if(fread(&m_comstation, sizeof(Remote_Station_setting), 1, m_file)!=1)
		{
			fclose(m_file);
			return;
		}
		if(!strcmp(m_comstation.name, m_login_client_name))
		{
		  m_combo.InsertString(tt, m_comstation.dvrname);
		  tt++;
		}
	}
	fclose(m_file);
}

void CUpdateDecFile::OnSetfocuseaddress()
{
	UpdateData(TRUE);
	m_dec_addctl.ResetContent();
	if(m_comname.IsEmpty()) return;
	for(int i=0; i<64; i++)
	{
		CString m_str;
		m_str.Format("%d",i);
		m_dec_addctl.InsertString(i, m_str);
	}
	for(int k=0; k<m_file_length; k++)
	{
		inspect_date_query *p = &m_station_data[k];
	    if(!strcmp(p->dvrname, m_comname) && !strcmp(p->name, m_login_client_name))
		{
			char dc[20];
			int index = m_dec_addctl.FindString(-1,itoa(p->address,dc,10));
			m_dec_addctl.DeleteString(index);
		}
	}
}


void CUpdateDecFile::on_update_data(int postion)
{
	UpdateData(TRUE);
	inspect_date_query *p = &m_station_data[postion];

	strcpy(p->name, m_login_client_name);
	strcpy(p->dvrname, m_comname);
	strcpy(p->decodename, m_dec_name);
	p->address = atoi(m_dec_add);

	p->m_switch[0].m_switch_type = m_switch_type1;
	p->m_switch[1].m_switch_type = m_switch_type2;
	p->m_switch[2].m_switch_type = m_switch_type3;
	p->m_switch[3].m_switch_type = m_switch_type4;

	strcpy(p->m_switch[0].m_switch_name, m_switch_name1);
	strcpy(p->m_switch[1].m_switch_name, m_switch_name2);
	strcpy(p->m_switch[2].m_switch_name, m_switch_name3);
	strcpy(p->m_switch[3].m_switch_name, m_switch_name4);

	strcpy(p->m_value[0].m_name, m_name1);
	strcpy(p->m_value[1].m_name, m_name2);
	strcpy(p->m_value[2].m_name, m_name3);
	strcpy(p->m_value[3].m_name, m_name4);

	strcpy(p->m_value[0].m_unit, m_nuit_str1);
	strcpy(p->m_value[1].m_unit, m_nuit_str2);
	strcpy(p->m_value[2].m_unit, m_nuit_str3);
	strcpy(p->m_value[3].m_unit, m_nuit_str4);

	p->m_value[0].quotiwty = m_quotiwty1;
	p->m_value[1].quotiwty = m_quotiwty2;
	p->m_value[2].quotiwty = m_quotiwty3;
	p->m_value[3].quotiwty = m_quotiwty4;

	p->m_value[0].m_zero_value = m_zero_value1;
	p->m_value[1].m_zero_value = m_zero_value2;
	p->m_value[2].m_zero_value = m_zero_value3;
	p->m_value[3].m_zero_value = m_zero_value4;
}

void CUpdateDecFile::on_save_file()
{
	Cfileoperation <inspect_date_query> *m_fileoperation;
    m_fileoperation->savefilename(m_inspect_date_query_directory, "wb+", m_station_data, m_file_length);
	on_add_list();
}

HTREEITEM  CUpdateDecFile::get_tree_postion(CString station, CString decname)
{
	HTREEITEM htree ;
	CString m_sta, m_dec;
	for(int i=0; i<m_tree.GetCount(); i++)
	{
		if(!i) 
			htree = m_tree.GetFirstVisibleItem();
		else
			htree = m_tree.GetNextSiblingItem(htree);
		m_sta = m_tree.GetItemText(htree);

		if(m_sta == station && m_tree.ItemHasChildren(htree))
		{
			htree = m_tree.GetChildItem(htree);
			while(htree)
			{
				m_dec = m_tree.GetItemText(htree);
				if(m_dec == decname)
					return htree;
                htree = m_tree.GetNextSiblingItem(htree);
			}
            htree = m_tree.GetParentItem(htree);
			break;
		}
	}
	return NULL;
		
}
void CUpdateDecFile::OnAdd()
{
	UpdateData(TRUE);
	if(m_comname.IsEmpty() || m_dec_add.IsEmpty() || m_dec_name.IsEmpty())
		return;
	if(!testadd(m_comname)) return;
	on_update_data(m_file_length);
	on_taxis_all_data(m_file_length);
	m_file_length++;
	on_save_file();

	HTREEITEM htree = get_tree_postion(m_comname, m_dec_name);
	if(htree)
		m_tree.SelectItem(htree);
}
void CUpdateDecFile::OnDel()
{
	UpdateData(TRUE);
	if(m_comname.IsEmpty() || m_dec_add.IsEmpty() || m_dec_name.IsEmpty())
		return;

	for(int i=0; i<m_file_length; i++)
	{
		inspect_date_query *p = &m_station_data[i];
	    if(!strcmp(p->dvrname, m_comname) && !strcmp(p->name, m_login_client_name))
			if(!strcmp(p->decodename, m_dec_name))
			{
				strcpy(p->name, "");
				break;
			}
	}
    on_save_file();
	On_initidata();
	UpdateData(FALSE);
}

void CUpdateDecFile::Onupdate()
{
	UpdateData(TRUE);
	if(m_comname.IsEmpty() || m_dec_add.IsEmpty() || m_dec_name.IsEmpty())
		return;
	if(atoi(m_dec_add)>63 || atoi(m_dec_add)<0)
		return ;

	for(int i=0; i<m_file_length; i++)
	{
		inspect_date_query *p = &m_station_data[i];
		if(!strcmp(p->dvrname, m_comname) && !strcmp(p->name, m_login_client_name))
			if(!strcmp(p->decodename, m_dec_name))
			{
				on_update_data(i);
				on_taxis_all_data(i);
				on_save_file();
				AfxMessageBox(IDS_DEC_INF_UPDATE_OK);
				break;
			}
	}
	HTREEITEM htree = get_tree_postion(m_comname, m_dec_name);
	if(htree)	m_tree.SelectItem(htree);	
}

void CUpdateDecFile::on_data_update(CString m_station, CString m_decodename)
{
	int postion = -1;

	for(int i=0; i<m_file_length; i++)
	{
		inspect_date_query *p = &m_station_data[i];
		if(!strcmp(p->dvrname, m_station) && !strcmp(p->name, m_login_client_name))
		if(!strcmp(p->decodename, m_decodename))
		{
			postion = i;
			break;
		}
	}

	if(postion == -1)
		return;
	inspect_date_query *p = &m_station_data[postion];
	m_comname = p->dvrname;

	CString m_str;
	char dc[20];
	m_str.Format(IDS_STATION_DECODE_SET, p->dvrname,p->decodename);
	m_statoin_param = m_str;
	m_dec_add = itoa(p->address, dc, 10);
	m_dec_name = p->decodename;

	m_switch_type1 = p->m_switch[0].m_switch_type;
	m_switch_type2 = p->m_switch[1].m_switch_type;
	m_switch_type3 = p->m_switch[2].m_switch_type;
	m_switch_type4 = p->m_switch[3].m_switch_type;

	m_switch_name1 = p->m_switch[0].m_switch_name;
	m_switch_name2 = p->m_switch[1].m_switch_name;
	m_switch_name3 = p->m_switch[2].m_switch_name;
	m_switch_name4 = p->m_switch[3].m_switch_name;

	m_name1 = p->m_value[0].m_name;
	m_name2 = p->m_value[1].m_name;
	m_name3 = p->m_value[2].m_name;
	m_name4 = p->m_value[3].m_name;

	m_nuit_str1 = p->m_value[0].m_unit;
	m_nuit_str2 = p->m_value[1].m_unit;
	m_nuit_str3 = p->m_value[2].m_unit;
	m_nuit_str4 = p->m_value[3].m_unit;

	m_quotiwty1 = p->m_value[0].quotiwty;
	m_quotiwty2 = p->m_value[1].quotiwty;
	m_quotiwty3 = p->m_value[2].quotiwty;
	m_quotiwty4 = p->m_value[3].quotiwty;

	m_zero_value1 = p->m_value[0].m_zero_value;
	m_zero_value2 = p->m_value[1].m_zero_value;
	m_zero_value3 = p->m_value[2].m_zero_value;
	m_zero_value4 = p->m_value[3].m_zero_value;

	UpdateData(FALSE);
}

⌨️ 快捷键说明

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