/*
	Date:2013/05/29
	Purpose:
	parameters 1:根据层次
	2:改变的名字,有新旧比较
   	*/
BOOL CWorkspaceBar::UpdateDataToDB(){
 
	CppSQLite3DB SqliteDBT3000;
	CppSQLite3DB SqliteDBBuilding;
	CppSQLite3Table table;
	CppSQLite3Query q;
	SqliteDBT3000.open((UTF8MBSTR)g_strDatabasefilepath);

	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);

	 try 
	 {
 
		 CString strSql;   BOOL is_exist=FALSE;	  CString str_temp;
         switch (m_level)
         {
         case 0:  //Subnet
		 {
				 strSql.Format(_T("select * from Building order by Main_BuildingName"));
				q = SqliteDBT3000.execQuery((UTF8MBSTR)strSql);
				 while(!q.eof())
				 {	   	 
					 str_temp.Empty();
					 str_temp= q.getValuebyName(L"Building_Name");
				     if (str_temp.Compare(m_name_new)==0)
				     {	  
				      is_exist=TRUE;
				     break;
				     }			
					 q.nextRow();
				 }
				 
				 if (!is_exist)	 //更新的名字在数据库中查找不到的
				 {
				 ////////////先更新Building表/////////////////////
					 //CString strSql;
					 strSql.Format(_T("delete   from Building_ALL where Building_Name = '%s' "),m_name_old);
					 SqliteDBT3000.execDML((UTF8MBSTR)strSql);

					 strSql.Format(_T("Insert into Building_ALL(Building_Name,Default_Build) values('%s','%d')"),m_name_new,1);
					 SqliteDBT3000.execDML((UTF8MBSTR)strSql);

					 strSql.Format(_T("update Building set Building_Name='%s',Main_BuildingName= where Building_Name='%s'"),m_name_new,m_name_new,m_name_old);
					 //MessageBox(strSql);
					 SqliteDBT3000.execDML((UTF8MBSTR)strSql);


					 strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' order by Building_Name"),m_name_old);

					 
					 q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
					 while(!q.eof())
					 {
						 strSql.Format(_T("update ALL_NODE set Building_Name='%s' where Building_Name='%s'"),m_name_new,m_name_old);
						 SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
						 q.nextRow();
					 }

					  

				 }
				 else
				 {

					 return FALSE;
				 }

				 break;	
				 
          
			 }
		 case 1:		//Floor
		 {	 
             // m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText);
			 HTREEITEM parentnode=m_TreeCtrl.GetParentItem(m_hSelItem);

			  CString subnetname=m_TreeCtrl.GetItemText(parentnode);//m_pRs->GetCollect("Building_Name");
	 
			 //  m_pRs->Close();
			   strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' and Floor_name='%s' order by Building_Name"),subnetname,m_name_new);
				  q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
				 while(!q.eof())
				 {	   	
					 str_temp.Empty();
					 str_temp=q.getValuebyName(L"Floor_name");
					 if (str_temp.Compare(m_name_new)==0)
					 {is_exist=TRUE;
					 break;
					 }			
					 q.nextRow();
				 }
			 

				if (is_exist)
				{
						return FALSE;
				} 
				else
				{  
				     strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' and Floor_name='%s' order by Building_Name"),subnetname,m_name_old);
				     //m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText);
				     q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
				     while(!q.eof())
				     {
				     	strSql.Format(_T("update ALL_NODE set Floor_name='%s' where Floor_name='%s'"),m_name_new,m_name_old);
				     	SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
				     	q.nextRow();
				     }
				 
				     return TRUE;
				}
			
		 
		 break;
         }
		 case 2:		//Room
		 {
			//Subnet
			HTREEITEM root=m_TreeCtrl.GetRootItem();
			CString subnetname=m_TreeCtrl.GetItemText(root);
		   //Floor
			HTREEITEM parentnode=m_TreeCtrl.GetParentItem(m_hSelItem);
			CString Floorname=m_TreeCtrl.GetItemText(parentnode);
			  strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' and Floor_name='%s' and Room_name='%s' order by Building_Name"),subnetname,Floorname,m_name_new);
			 // m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText);
			 q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
			  while(q.eof())
			  {	   	 str_temp.Empty();
			  str_temp=q.getValuebyName(L"Room_name");
			  if (str_temp.Compare(m_name_new)==0)
			  {	   is_exist=TRUE;
			  break;
			  }			
			  q.nextRow();
			  }
			  

			  if (is_exist)
			  {
			  return FALSE;
			  } 
			  else
			  {
			        strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' and Floor_name='%s' and Room_name='%s' order by Building_Name"),subnetname,Floorname,m_name_old);
			        q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
			        while(!q.eof())
			        {
			       	  strSql.Format(_T("update ALL_NODE set Room_name='%s' where Room_name='%s'"),m_name_new,m_name_old);
			       	   SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
			       	   q.nextRow();
			        }
			        
			        return TRUE; 
			  }
			  																				  
			    
		  break;
		 }
		 case 3:		//Device Name Leaf
		 {
			 //Subnet
			 HTREEITEM root=m_TreeCtrl.GetRootItem();
			 CString subnetname=m_TreeCtrl.GetItemText(root);
			 //Room
			 HTREEITEM parentnode=m_TreeCtrl.GetParentItem(m_hSelItem);
			 CString Roomname=m_TreeCtrl.GetItemText(parentnode);
			 //Floor
			 HTREEITEM floornode=m_TreeCtrl.GetParentItem(parentnode);
			 CString Floorname=m_TreeCtrl.GetItemText(floornode);
			 strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' and Floor_name='%s' and Room_name='%s' and Product_name='%s' order by Building_Name"),subnetname,Floorname,Roomname,m_name_new);
			 q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
			 while(!q.eof())
			 {	   	 
			     str_temp.Empty();
			     str_temp=q.getValuebyName(L"Product_name");
			     if (str_temp.Compare(m_name_new)==0)
			     {	   is_exist=TRUE;
			     break;
			     }			
			      q.nextRow();
			     }
			 
			 
			 if (is_exist)
			 {
			 return FALSE;
			 }
			 else
			 {
				  strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' and Floor_name='%s' and Room_name='%s' and Product_name='%s' order by Building_Name"),subnetname,Floorname,Roomname,m_name_old);
			 
			 q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
			 while(!q.eof())
			 {
				 strSql.Format(_T("update ALL_NODE set Product_name='%s' where Product_name='%s'"),m_name_new,m_name_old);
				 SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
				 q.nextRow();
			 }
			  
			 return TRUE;
			 }
			 
		 break;
		 }
		 }
	 }
	 catch(_com_error e)
	 {
	 
		 SqliteDBBuilding.closedb();
		 return FALSE;
		 //m_pCon->Close();

	 }
	  SqliteDBBuilding.closedb();
	  SqliteDBT3000.closedb();
 
	return TRUE;
 }
void CUserAcessSetDlg::ReloadSingleLevelSetDB()
{
	m_FlexGrid2.Clear();
	m_FlexGrid2.put_Cols(4);	
	m_FlexGrid2.put_TextMatrix(0,1,_T("Grid 1"));
	m_FlexGrid2.put_TextMatrix(0,1,_T("User"));
	m_FlexGrid2.put_TextMatrix(0,2,_T("Network Controller"));
	m_FlexGrid2.put_TextMatrix(0,3,_T("Database"));

	m_FlexGrid2.put_ColWidth(0,1000);
	m_FlexGrid2.put_ColWidth(1,1000);
	m_FlexGrid2.put_ColWidth(2,1500);
	m_FlexGrid2.put_ColWidth(3,1000);
	for(int i=0;i<4;i++)
	{
		m_FlexGrid2.put_ColAlignment(i,4);
	}

	CppSQLite3Table table;
	CppSQLite3Query q;

	CppSQLite3DB SqliteDBBuilding;
	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);

	CString strSql;
	strSql.Format(_T("select * from UserLevelSingleSet where MainBuilding_Name='%s' and Building_Name='%s' and username='******'"),m_strMainBuilding,m_strSubNetName,m_strUserName);
	q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);

	_variant_t temp_variant;
	BOOL b_useLogin=false;
	int temp_row=0;
	CString strTemp;
	int nTemp;
	while(!q.eof())
	{

		++temp_row;
		
		 
			strTemp=q.getValuebyName(L"username");
		m_FlexGrid2.put_TextMatrix(temp_row,1,strTemp);

		 
			nTemp=q.getIntField("networkcontroller");
		switch (nTemp)
		{
			case 0:strTemp=_T("Read & write");break;
			case 1:strTemp=_T("Read only");break;
			default:strTemp=_T("Read & write");
		}
		m_FlexGrid2.put_TextMatrix(temp_row,2,strTemp);

		nTemp=q.getIntField("database_limition");//
	 
		switch (nTemp)
		{
			case 0:strTemp=_T("Read & write");break;
			case 1:strTemp=_T("Read only");break;
			default:strTemp=_T("Read & write");
		}
		m_FlexGrid2.put_TextMatrix(temp_row,3,strTemp);

		q.nextRow();
	}
	SqliteDBBuilding.closedb();
}
void CUserAcessSetDlg::InserProductToUserSetDB()
{
	CppSQLite3Table table;
	CppSQLite3Query q;

	CppSQLite3DB SqliteDBBuilding;
	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);

	CString strSql;
	strSql.Format(_T("select * from user_level where MainBuilding_Name='%s' and Building_Name='%s'and username='******'"),m_strMainBuilding,m_strSubNetName,m_strUserName);	
	 q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
	 USERLEVEL UserLevelV;
	_variant_t temp_variant;
	CString strTemp;
	int nTemp;
	m_UserLevelLst.clear();
	while(!q.eof())
	{
		
		strTemp=q.getValuebyName(L"username");//
		 
		UserLevelV.strUserName=strTemp;
		
		nTemp=q.getIntField("serial_number");//
		
		UserLevelV.nSerialNumber=nTemp;

		m_UserLevelLst.push_back(UserLevelV);
		q.nextRow();
	}

	 



	VERYPRODCT veryProduct;
	//strSql=_T("select * from ALL_NODE where ");///MainBuilding_Name
	strSql.Format(_T("select * from ALL_NODE where MainBuilding_Name='%s' and Building_Name='%s'"),m_strMainBuilding,m_strSubNetName);

//	m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText);	
	q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
	m_VeryProdctLst.clear();
	while(!q.eof())
	{
		//veryProduct.strMainBuildingName=m_pRs->GetCollect("MainBuilding_Name");//
		strTemp=q.getValuebyName(L"MainBuilding_Name");//
	 
		veryProduct.strMainBuildingName=strTemp;
		
		//veryProduct.strBuildingName=m_pRs->GetCollect("Building_Name");//
		strTemp=q.getValuebyName(L"Building_Name");//
		 
		veryProduct.strBuildingName=strTemp;

	//	veryProduct.nSerialNumber=m_pRs->GetCollect("Serial_ID");
		strTemp=q.getValuebyName(L"Serial_ID");//
	 
		veryProduct.nSerialNumber=_wtol(strTemp);

		//veryProduct.ProductID=m_pRs->GetCollect("Product_ID");
		strTemp=q.getValuebyName(L"Product_ID");//
		 
		veryProduct.ProductID=_wtoi(strTemp);

		//veryProduct.product_class_id=m_pRs->GetCollect("Product_class_ID");
		strTemp=q.getValuebyName(L"Product_class_ID");//
		 
		veryProduct.product_class_id=_wtoi(strTemp);

		//veryProduct.strFloorName=m_pRs->GetCollect("Floor_name");
		strTemp=q.getValuebyName(L"Floor_name");//
		 
		veryProduct.strFloorName=strTemp;

	//	veryProduct.strRoomName=m_pRs->GetCollect("Room_name");
		strTemp=q.getValuebyName(L"Room_name");//
		 
		veryProduct.strRoomName=strTemp;
		m_VeryProdctLst.push_back(veryProduct);
		q.nextRow();
	}
	int nVerySerialNum;
	int nUserlevelSerial;
	CString strUserName;
	for(UINT i=0;i<m_VeryProdctLst.size();i++)
	{
		nVerySerialNum=m_VeryProdctLst.at(i).nSerialNumber;
		BOOL bFind=FALSE;
		for(UINT j=0;j<m_UserLevelLst.size();j++)
		{
			nUserlevelSerial=m_UserLevelLst.at(j).nSerialNumber;
			if(nVerySerialNum==nUserlevelSerial)
			{
	
				bFind=TRUE;
				break;
			}
			//else
			//{
			//	bFind=FALSE;
		
			//}
		}
			
		if(!bFind)//insert to userlevel table.
		{

			try
			{


			strSql.Format(_T("insert into user_level values('%s','%s',%i,'%i','%s','%s','%s','%i','%i','%i','%i','%i','%i','%i','%i',%i)"),
			m_VeryProdctLst.at(i).strMainBuildingName,
			m_VeryProdctLst.at(i).strBuildingName,
			m_VeryProdctLst.at(i).nSerialNumber,
			m_VeryProdctLst.at(i).ProductID,
			m_strUserName,
			m_VeryProdctLst.at(i).strFloorName,
			m_VeryProdctLst.at(i).strRoomName,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			0,
			0
			);				
			SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
			}
			catch(_com_error *e)
			{
				AfxMessageBox(e->ErrorMessage());
			}
		}
		
	
		
	}
	
	SqliteDBBuilding.closedb();

}
void CUserAcessSetDlg::ReloadUserLevelDB()
{
	m_FlexGrid.Clear();
	m_FlexGrid.put_Cols(13);	
	m_FlexGrid.put_TextMatrix(0,1,_T("Grid 2"));
	m_FlexGrid.put_TextMatrix(0,1,_T("User"));
	m_FlexGrid.put_TextMatrix(0,2,_T("Serial"));
	m_FlexGrid.put_TextMatrix(0,3,_T("ID"));
	m_FlexGrid.put_TextMatrix(0,4,_T("Floor"));
	m_FlexGrid.put_TextMatrix(0,5,_T("Room"));
	m_FlexGrid.put_TextMatrix(0,6,_T("Main Screen"));
	m_FlexGrid.put_TextMatrix(0,7,_T("Parameter"));
	m_FlexGrid.put_TextMatrix(0,8,_T("Output "));
//	m_FlexGrid.put_TextMatrix(0,9,_T("Network Ctr"));
	m_FlexGrid.put_TextMatrix(0,9,_T("Graphic"));	
//	m_FlexGrid.put_TextMatrix(0,10,_T("Building Set"));
	m_FlexGrid.put_TextMatrix(0,10,_T("Burn Hex"));
	m_FlexGrid.put_TextMatrix(0,11,_T("Load Config"));
	m_FlexGrid.put_TextMatrix(0,12,_T("All Screen"));
		
	m_FlexGrid.put_ColWidth(0,700);
	m_FlexGrid.put_ColWidth(1,700);
	m_FlexGrid.put_ColWidth(2,700);
	m_FlexGrid.put_ColWidth(3,1000);
	m_FlexGrid.put_ColWidth(4,1000);

	m_FlexGrid.put_ColWidth(5,1000);
	m_FlexGrid.put_ColWidth(6,1100);
	m_FlexGrid.put_ColWidth(7,1100);
	m_FlexGrid.put_ColWidth(8,1100);
	m_FlexGrid.put_ColWidth(9,1100);
	m_FlexGrid.put_ColWidth(10,1100);
	m_FlexGrid.put_ColWidth(11,1100);
	m_FlexGrid.put_ColWidth(12,1100);



	for(int i=0;i<13;i++)
	{
		m_FlexGrid.put_ColAlignment(i,4);
	}


	CppSQLite3Table table;
	CppSQLite3Query q;

	CppSQLite3DB SqliteDBBuilding;
	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);
	 
	CString strSql;

	//m_pRsTemp->Open((_variant_t)("select * from user_level where username = '******'"),_variant_t((IDispatch *)m_pConTmp,true),adOpenStatic,adLockOptimistic,adCmdText);	
	//	strSql.Format(_T("select * from user_level where MainBuilding_Name='%s' and Building_Name='%s'"),m_strMainBuilding,m_strSubNetName);
	strSql.Format(_T("select * from user_level where MainBuilding_Name='%s' and Building_Name='%s' and username='******'"),m_strMainBuilding,m_strSubNetName,m_strUserName);
	q = SqliteDBBuilding.execQuery((UTF8MBSTR)strSql);
	table = SqliteDBBuilding.getTable((UTF8MBSTR)strSql);
	 USERLEVEL UserLevelV;
	int temp_row=0;
	int nTemp;
	CString strTemp;
	_variant_t temp_variant;

	m_FlexGrid.put_Rows(table.numRows()+1);

	for(int i=1;i<table.numRows()+1;i++)
	{	
		for(int k=0;k<=12;k++)
		{
			if (i%2==0)
			{
				m_FlexGrid.put_Row(i);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(COLOR_CELL);
			}
		}
	}

	while(!q.eof())
	{
		++temp_row;
		 
			strTemp=q.getValuebyName(L"MainBuilding_Name");
		UserLevelV.strMainBuildingName=strTemp;

		 
			strTemp=q.getValuebyName(L"Building_Name");
		UserLevelV.strSubBuildingName=strTemp;

		 
			strTemp=q.getValuebyName(L"username");
		UserLevelV.strUserName=strTemp;

		 
			nTemp=q.getIntField("serial_number");
		UserLevelV.nSerialNumber=nTemp;

		 
			nTemp=q.getIntField("product_id");
		UserLevelV.ProductID=nTemp;

	 
			strTemp=q.getValuebyName(L"floorname");
		UserLevelV.strFloorName=strTemp;

	 
			strTemp=q.getValuebyName(L"roomname");
		UserLevelV.strRoomName=strTemp;

		 
		nTemp=q.getIntField("mainscreen_level");
		UserLevelV.MainLevel=nTemp;

		 
			nTemp=q.getIntField("parameter_level");
		UserLevelV.ParamerLevel=nTemp;

		 
			nTemp=q.getIntField("outputtable_level");
		UserLevelV.Outputtable_level=nTemp;

	 
			nTemp=q.getIntField("graphic_level");
		UserLevelV.Graphic_level=nTemp;

	 
			nTemp=q.getIntField("burnhex_level");
		UserLevelV.Burnhex_level=nTemp;

		 
		nTemp=q.getIntField("loadconfig_level");
		UserLevelV.Loadconfig_level=nTemp;

		 

		 
			nTemp=q.getIntField("allscreen_level");
		UserLevelV.Allscreen_level=nTemp;

		
		if(UserLevelV.Allscreen_level==1)
		{
			

			for(int k=0;k<12;k++)
			{
			
				m_FlexGrid.put_Row(temp_row);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(RGB(215,215,215));
			}
		}
		else
		{
				for(int k=0;k<=12;k++)
				{
					if (temp_row%2==0)
					{
						m_FlexGrid.put_Row(temp_row);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(COLOR_CELL);
					}
					else
					{
						m_FlexGrid.put_Row(temp_row);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(RGB(255,255,240));

					}
				}
		}
		

		q.nextRow();


		m_FlexGrid.put_TextMatrix(temp_row,1,UserLevelV.strUserName);
		CString strTemp;;
		strTemp.Format(_T("%d"),UserLevelV.nSerialNumber);
	
		m_FlexGrid.put_TextMatrix(temp_row,2,strTemp);
		strTemp.Format(_T("%d"),UserLevelV.ProductID);
		m_FlexGrid.put_TextMatrix(temp_row,3,strTemp);
		m_FlexGrid.put_TextMatrix(temp_row,4,UserLevelV.strFloorName);
		m_FlexGrid.put_TextMatrix(temp_row,5,UserLevelV.strRoomName);
		switch (UserLevelV.MainLevel)
		{
			case 0:strTemp=_T("Read & write");break;
			case 1:strTemp=_T("Read only");break;
			default:strTemp=_T("Read & write");
		}
		m_FlexGrid.put_TextMatrix(temp_row,6,strTemp);
		switch (UserLevelV.ParamerLevel)
		{
			case 0:strTemp=_T("Read & write");break;
			case 1:strTemp=_T("Read only");break;
			default:strTemp=_T("Read & write");
		}
		m_FlexGrid.put_TextMatrix(temp_row,7,strTemp);
		
		switch (UserLevelV.Outputtable_level)
		{
			case 0:strTemp=_T("Read & write");break;
			case 1:strTemp=_T("Read only");break;
			default:strTemp=_T("Read & write");
		}
		m_FlexGrid.put_TextMatrix(temp_row,8,strTemp);
		switch (UserLevelV.Graphic_level)
		{
			case 0:strTemp=_T("Read & write");break;
			case 1:strTemp=_T("Read only");break;
			default:strTemp=_T("Read & write");
		}
		m_FlexGrid.put_TextMatrix(temp_row,9,strTemp);

		 



		switch (UserLevelV.Burnhex_level)
		{
			case 0:strTemp=_T("Enable");break;
			case 1:strTemp=_T("Unenable");break;
			default:strTemp=_T("Enable");
		}
		m_FlexGrid.put_TextMatrix(temp_row,10,strTemp);
		switch (UserLevelV.Loadconfig_level)
		{
			case 0:strTemp=_T("Enable");break;
			case 1:strTemp=_T("Unenable");break;
			default:strTemp=_T("Enable");
		}
		m_FlexGrid.put_TextMatrix(temp_row,11,strTemp);
		
		switch (UserLevelV.Allscreen_level)
		{
			case 0:strTemp=_T("Enable");break;
			case 1:strTemp=_T("Unenable");break;
			default:strTemp=_T("Enable");
		}
		m_FlexGrid.put_TextMatrix(temp_row,12,strTemp);
	}


	SqliteDBBuilding.closedb();
}
void T38AI8AO::InitialRegister(){
    T3Register temp;
	g_VectorT3Register.clear();
	CppSQLite3DB SqliteDBT3000;
	CppSQLite3Table table;
	CppSQLite3Query q;
	SqliteDBT3000.open((UTF8MBSTR)g_strDatabasefilepath);
#if 1
	CString SQL = _T("select * from T3_RegisterList");
	q = SqliteDBT3000.execQuery((UTF8MBSTR)SQL);
	_variant_t vartemp;
	while(!q.eof())
	{
		temp.regID=q.getIntField("RegID");
		temp.regName =q.getValuebyName(L"T3_8AI8AO");
		q.nextRow();
		g_VectorT3Register.push_back(temp);
	}
	SqliteDBT3000.closedb();
	SN_LOW=Get_RegID(_T("SN_LOW"))	;
	SN_HI=Get_RegID(_T("SN_HI"))	;
	EPROM_VER_NUMBER=Get_RegID(_T("EPROM_VER_NUMBER"))	;
	FIRMWARE_VER_NUMBER=Get_RegID(_T("FIRMWARE_VER_NUMBER"))	;
	MODBUS_ID=Get_RegID(_T("MODBUS_ID"))	;
	PRODUCT_MODEL	=Get_RegID(_T("PRODUCT_MODEL"));
	HARDWARE_VER_NUMBER=Get_RegID(_T("HARDWARE_VER_NUMBER"))	;
	PIC_VER_NUMBER=Get_RegID(_T("PIC_VER_NUMBER"))	;
	CALIBRATION_OUTPUTS	=Get_RegID(_T("CALIBRATION_OUTPUTS"));
	BAUDRATE=Get_RegID(_T("BAUDRATE"))	;
	RESPONSE_DELAY	=Get_RegID(_T("RESPONSE_DELAY"));

	OUTPUT1	=Get_RegID(_T("OUTPUT1	"));
	OUTPUT2	=Get_RegID(_T("OUTPUT2	"));
	OUTPUT3	=Get_RegID(_T("OUTPUT3	"));
	OUTPUT4	=Get_RegID(_T("OUTPUT4	"));
	OUTPUT5	=Get_RegID(_T("OUTPUT5	"));
	OUTPUT6	=Get_RegID(_T("OUTPUT6	"));
	OUTPUT7	=Get_RegID(_T("OUTPUT7	"));
	OUTPUT8	=Get_RegID(_T("OUTPUT8	"));
	INPUT1	=Get_RegID(_T("INPUT1	"));
	INPUT2	=Get_RegID(_T("INPUT2	"));
	INPUT3	=Get_RegID(_T("INPUT3	"));
	INPUT4	=Get_RegID(_T("INPUT4	"));
	INPUT5	=Get_RegID(_T("INPUT5	"));
	INPUT6	=Get_RegID(_T("INPUT6	"));
	INPUT7	=Get_RegID(_T("INPUT7	"));
	INPUT8	=Get_RegID(_T("INPUT8	"));
	SWITCH1_STATUS=Get_RegID(_T("SWITCH1_STATUS"))	;
	SWITCH2_STATUS=Get_RegID(_T("SWITCH2_STATUS"))	;
	RANGE_INPUT1	=Get_RegID(_T("RANGE_INPUT1	"));
	RANGE_INPUT2	=Get_RegID(_T("RANGE_INPUT2	"));
	RANGE_INPUT3	=Get_RegID(_T("RANGE_INPUT3	"));
	RANGE_INPUT4	=Get_RegID(_T("RANGE_INPUT4	"));
	RANGE_INPUT5	=Get_RegID(_T("RANGE_INPUT5	"));
	RANGE_INPUT6	=Get_RegID(_T("RANGE_INPUT6	"));
	RANGE_INPUT7	=Get_RegID(_T("RANGE_INPUT7	"));
	RANGE_INPUT8	=Get_RegID(_T("RANGE_INPUT8	"));
	FILTER_INPUT1	=Get_RegID(_T("FILTER_INPUT1	"));
	FILTER_INPUT2	=Get_RegID(_T("FILTER_INPUT2	"));
	FILTER_INPUT3	=Get_RegID(_T("FILTER_INPUT3	"));
	FILTER_INPUT4	=Get_RegID(_T("FILTER_INPUT4	"));
	FILTER_INPUT5	=Get_RegID(_T("FILTER_INPUT5	"));
	FILTER_INPUT6	=Get_RegID(_T("FILTER_INPUT6	"));
	FILTER_INPUT7	=Get_RegID(_T("FILTER_INPUT7	"));
	FILTER_INPUT8	=Get_RegID(_T("FILTER_INPUT8	"));
#endif 
}