void CAddBuilding::OnCbnSelendokAddbuidingSelectcombo()
{
	CString strText;
	int nIndext=m_AddBuiding_SetComBox.GetCurSel();
	m_AddBuiding_SetComBox.GetLBText(nIndext,strText);

	if(m_nCurCol==AB_PROTOCOL)
	{
		m_strProtocol=strText;
	}
	if(m_nCurCol==AB_COMPORT)
	{
		m_strComPort=strText;
	}
	if(m_nCurCol==AB_BAUDRAT)
	{
		m_strBaudrat=strText;
	}

	if (m_nCurRow==m_AddBuiding_FlexGrid.get_Rows()-1)
	{
		
		m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
	}
	else
	{
		Update_Recorder();

	}
	m_AddBuiding_SetComBox.ShowWindow(SW_HIDE);
	m_Changed=TRUE;
//	AfxMessageBox(m_strBuilding_Name2);

}
void CAddBuilding::OnEnKillfocusMainbuildedit()
{
	CString strText;
	m_mainBuildEdt.GetWindowText(strText);
	if(strText.IsEmpty())
	{
		m_mainBuildEdt.ShowWindow(SW_HIDE);
		return;
	}

	if (m_nCurRow==m_AddBuiding_FlexGrid.get_Rows()-1)
	{
		CString strTemp;
		for(UINT i=0;i<m_BuildNameLst.size();i++)
		{
			strTemp=m_BuildNameLst.at(i).strMainBuildName;
			if(strText.CompareNoCase(strTemp)==0&&m_strBuilding_Name2.CompareNoCase(m_BuildNameLst.at(i).strSubBuildName)==0)
			{
				    AfxMessageBox(_T("The building Name has exist, please change another one."));
					m_mainBuildEdt.ShowWindow(SW_HIDE);
				return;
			}
		}
		m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
	}
	else
	{
		if(m_nCurCol==AB_MAINNAME && m_strMainBuildingName2.CompareNoCase(strText)!=0)
		{
			CString strTemp;
			for(UINT i=0;i<m_BuildNameLst.size();i++)
			{
				strTemp=m_BuildNameLst.at(i).strMainBuildName;
				if(strText.CompareNoCase(strTemp)==0&&m_strBuilding_Name2.CompareNoCase(m_BuildNameLst.at(i).strSubBuildName)==0)
				{
					AfxMessageBox(_T("The building Name has exist, please change another one."));
						m_mainBuildEdt.ShowWindow(SW_HIDE);
					return;
				}
			}
			m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
			m_strMainBuildingName=strText;				
			Update_Recorder();
		}
	}
	m_mainBuildEdt.ShowWindow(SW_HIDE);

}
void CAddBuilding::OnEnKillfocusAddbuidingSetedit()
{
#if 1
		CString strText;
		m_AddBuiding_SetEditCtrl.GetWindowText(strText);
		m_strMainBuildingName = m_AddBuiding_FlexGrid.get_TextMatrix(m_nCurRow, AB_MAINNAME);
		if (m_nCurRow==m_AddBuiding_FlexGrid.get_Rows()-1)
		{
			if(m_nCurCol==AB_NAME)
			{
				CString strTemp;
				//for(UINT i=0;i++;i<m_BuildNameLst.size())  // commented by zgq;2010-12-06,不知道这种写法是什么意思?				
				for(UINT i=0;i<m_BuildNameLst.size();i++) 
				{
					strTemp=m_BuildNameLst.at(i).strSubBuildName;
					if(strText.CompareNoCase(strTemp)==0 && m_BuildNameLst.at(i).strMainBuildName.CompareNoCase(m_strMainBuildingName)==0) 
					{
						AfxMessageBox(_T("The Subnet Name has existed, please input a unused name."));
						return;
					}
				}

				m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);

				m_strBuildingName=strText;
				m_strBuilding_Name2=strText;
			}
			
			if(m_nCurCol==AB_IPADDRESS)
			{
				CString strIP;
				bool is_domain = false;
				strIP = strText;
				if(strIP.IsEmpty())
					return;
				CStringArray temparray;
				SplitCStringA(temparray,strIP,_T("."));
				if((temparray.GetSize()==4))	//有3个  . 4段
				{
					CString temp_0;
					CString temp_1;
					CString temp_2;
					CString temp_3;
					temp_0 = temparray.GetAt(0);
					temp_1 = temparray.GetAt(1);
					temp_2 = temparray.GetAt(2);
					temp_3 = temparray.GetAt(3);

					if((Is_Dig_Num(temp_0)) && (Is_Dig_Num(temp_1)) && (Is_Dig_Num(temp_2)) && (Is_Dig_Num(temp_3)))
					{
						if(::ValidAddress(strIP) == false)
						{
							MessageBox(_T("Warning!IP address error!"));
							return;
						}

					}
					else	//否则判断为 域名;
					{
						is_domain = true;
					}
				}
				else	//判断为 域名;
				{
					is_domain = true;
				}

				if(is_domain)
				{
					CString temp_host_ip;
					if(!GetIPbyHostName(strText,temp_host_ip))
					{
						AfxMessageBox(_T("Can not get a validate IP adreess from the domain name!"));
						return;
					}
					strText = temp_host_ip;
					//char temp_domain[200];
					//WideCharToMultiByte( CP_ACP, 0, strIP.GetBuffer(), -1, temp_domain, 255, NULL, NULL );
					//strIP.ReleaseBuffer();
					//hostent* host = gethostbyname(temp_domain);
					//if(host == NULL)
					//{
					//	if(IDYES == MessageBox(_T("The domain is unreachable .Continue?"),_T("Warning"),MB_YESNO))
					//	{

					//	}
					//	else
					//	{
					//		return;
					//	}
					//}
				}


#if 0
				if(!ValidAddress(strText))
				{
					if(strText.IsEmpty())
					{
						AfxMessageBox(_T("Please input a validate IP adreess or domain name!"));
						return;
					}
					/*
					CStringIP;
					if(!GetIPbyHostName(strText,CStringIP))
					{
						AfxMessageBox(_T("Can not get a validate IP adreess from the domain name!"));
						return;
					}
					m_strIpAddress=CStringIP;
					m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
					return;
					*/

					
				}
				//if(m_strIpAddress.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
#endif
				m_strIpAddress=strText;
				m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
			}


			if(m_nCurCol==AB_IPPORT)
			{
				//if(m_strIpPort.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
				m_strIpPort=strText;
				m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
			}			
		}
		else
		{		
			if(m_nCurCol==AB_NAME && m_strBuilding_Name2.CompareNoCase(strText)!=0)
			{
				CString strTemp;
				for(UINT i=0;i<m_BuildNameLst.size();i++)
				{
					strTemp=m_BuildNameLst.at(i).strSubBuildName;
					if(strText.CompareNoCase(strTemp)==0&&m_strMainBuildingName2.CompareNoCase(m_BuildNameLst.at(i).strMainBuildName)==0)
					{
						AfxMessageBox(_T("The building Name has exist, please change another one."));
						return;
					}
				}
				/*Good Code//using Format is OK, use strSql= Error..??
				CString strSql;
				//strSql.Format(_T("update Building set Building_Name = '%s', where Building_Name = '%s'"),strText,m_strBuildingName);//erro
				 strSql.Format(_T("update Building set Building_Name = '"+strText+"'  where Building_Name =  '"+m_strBuildingName+"'"));
				_pCon->Execute(strSql.GetString(),NULL,adCmdText);	
				m_strBuildingName=strText;
				*/
				m_strBuildingName=strText;
				
			}
			if(m_nCurCol==AB_IPADDRESS)
			{
		
				if(!::ValidAddress(strText))
				{
					
					//if(strText.CompareNoCase((CString)NO_APPLICATION)==0)
					//return;

					if(strText.IsEmpty())
					{
						//AfxMessageBox(_T("Please input a validate IP adreess or domain name!"));
						return;
					}
				
					/*
					CStringIP;
					if(!GetIPbyHostName(strText,CStringIP))
					{
						AfxMessageBox(_T("Can not get a validate IP adreess from the domain name!"));
						return;
					}
					m_strIpAddress=CStringIP;
					m_AddBuiding_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
					*/
					//return;
				}
				//if(m_strIpAddress.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
				m_strIpAddress=strText;
			}

			if(m_nCurCol==AB_IPPORT)
			{
				//if(m_strIpPort.CompareNoCase(strText)==0)
				//{
				//	return;
				//}
				m_strIpPort=strText;
			}
			Update_Recorder();
		}
	
		m_AddBuiding_SetEditCtrl.ShowWindow(SW_HIDE);

		OnBnClickedAddbuiding();
#endif
}
void CManageAccountDlg::OnEnKillfocusValueedit()
{
	m_valueEdit.ShowWindow(SW_HIDE);
	if(m_nCurRow==0)
		return;
	CString strText;
	m_valueEdit.GetWindowText(strText);
	strText.Trim();
	if (m_nCurRow==m_FlexGrid.get_Rows()-1&&m_nCurRow>1)
	{

		if(m_nCurCol==1)
		{
			CString strTemp;
			for(UINT i=0;i<m_AccountLst.size();i++)		//modify by fance.
			//for(UINT i=0;i++;i<m_AccountLst.size())
			{
				strTemp=m_AccountLst.at(i).strName;
				if(strText.CompareNoCase(strTemp)==0)
				{
					AfxMessageBox(_T("The building Name has exist,please change another one!"));
					m_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,_T(""));
					return;
				}
			}
			m_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
		}
		if(m_nCurCol==2)
		{
			m_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);
		}
	}
	else
	{
		if(m_nCurCol==1)
		{
			if(m_nCurRow==1)
			{
				if(m_strUserName.CompareNoCase(strText)==0)
					return;
				else
				{
					AfxMessageBox(_T("You can not change admin account name!"));
					return;
				}
			}
			else
			{
				if(m_strUserName.CompareNoCase(strText)==0)
					return;
				CString strTemp;
				int n=m_AccountLst.size();
				for(UINT i=0;i<m_AccountLst.size();i++)
				{
					strTemp=m_AccountLst.at(i).strName;
					if(strText.CompareNoCase(strTemp)==0)
					{
						AfxMessageBox(_T("The building Name has exist,please change another one!"));
						return;
					}
				}
				m_strUserName=strText;
			//	m_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strText);

			}

			/*
			if(m_strUserName.CompareNoCase(strText)==0)
				return;
			CString strTemp;
			for(int i=0;i++;i<m_AccountLst.size())
			{
				strTemp=m_AccountLst.at(i).strName;
				if(strText.CompareNoCase(strTemp)==0)
				{
					AfxMessageBox(_T("The building Name has exist,please change another one!"));
					return;
				}
			}
				m_strUserName=strText;
				*/
				
		}
		if(m_nCurCol==2)
		{
			if(m_strPassword.CompareNoCase(strText)==0)
				return;
			m_strPassword=strText;
		}
		Update_Recorder();
	}

	// TODO: Add your control notification handler code here
}