void CUserAcessSetDlg::InserSingleSetConfig()
{

	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;

	try
	{

		if(q.eof())
		{
			strSql.Format(_T("insert into UserLevelSingleSet values('%s','%s','%s',%i,%i)"),m_strMainBuilding,m_strSubNetName,m_strUserName,0,0);		
			SqliteDBBuilding.execDML((UTF8MBSTR)strSql); 
		}

		SqliteDBBuilding.closedb();
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}



}
예제 #2
0
void CTroubleShootDlg::SaveNewIPAddress(CString newip,CString oldip){
	CppSQLite3DB SqliteDBBuilding;
	CppSQLite3Table table;
	CppSQLite3Query q;
	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);


	 
	try 
	{
		CString strSql;
		////////////////////////////////////////////////////////////////////////////////////////////
		//获取数据库名称及路径
		/////////////////////////////////////////////////////////////////////////////////////////////////
		//连接数据库
	    
		strSql.Format(_T("select * from ALL_NODE where Bautrate='%s' "),oldip);
		//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 Bautrate='%s' where Bautrate='%s'"),newip,oldip);
			SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
			q.nextRow();
		}
		 
		CMainFrame* pFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
		::PostMessage(pFrame->m_hWnd, WM_MYMSG_REFRESHBUILDING,0,0);
	}
	catch(_com_error e)
	{
		/* AfxMessageBox(e.Description());*/
		//MessageBox(m_name_new+_T("  has been here\n Please change another name!"));


		//m_pCon->Close();
		SqliteDBBuilding.closedb();
	}
	//m_pCon->Close(); 
	 SqliteDBBuilding.closedb();
}
void T3000_Default_MainView::OnCbnKillfocusBaudratecombo()
{
	if (product_register_value[MODBUS_BAUDRATE] == m_brandrate_combox.GetCurSel())	//Add this to judge weather this value need to change.
		return;

	/* Post_Thread_Message(MY_WRITE_ONE,g_tstat_id,MODBUS_BAUDRATE,m_baudRateCombox.GetCurSel(),
	product_register_value[MODBUS_BAUDRATE],this->m_hWnd,IDC_BAUDRATECOMBO,_T("BAUDRATE"));*/

	int ret = write_one(g_tstat_id, MODBUS_BAUDRATE, m_brandrate_combox.GetCurSel());

	int index_brandrate = m_brandrate_combox.GetCurSel();
	int brandrate = 19200;

	if (index_brandrate == 0)
	{
		brandrate = 9600;
	}
	else if (index_brandrate == 1)
	{
		brandrate = 19200;
	}
	else if (index_brandrate == 2)
	{
		brandrate = 38400;
	}
	else if (index_brandrate == 3)
	{
		brandrate = 57600;
	}
	else if (index_brandrate == 4)
	{
		brandrate = 115200;
	}
	if (GetCommunicationType() == 1)
	{
		return;
	}
	CString SqlText;

	SqlText.Format(_T("update ALL_NODE set Bautrate = '%d' where Serial_ID='%d'"), brandrate, get_serialnumber());
	Change_BaudRate(brandrate);


	CppSQLite3DB SqliteDBBuilding;
	CppSQLite3Table table;
	CppSQLite3Query q;
	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);

	SqliteDBBuilding.execDML((UTF8MBSTR)SqlText);
	SqliteDBBuilding.closedb();
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->ScanTstatInDB();
}
void CUserAcessSetDlg::OnCbnSelchangeSinglesetcombo()
{
	
	if(m_nCurRow2==0)
		return;
	if(m_nCurCol2==0)
		return;
	CString strValue;
	strValue=m_FlexGrid2.get_TextMatrix(m_nCurRow2,m_nCurCol2);
	CString strSelect;
	int nIdext=m_singleLevelSetCombox.GetCurSel();
	if(nIdext>=0)
	{
		m_singleLevelSetCombox.GetLBText(nIdext,strSelect);
		if(strSelect.CompareNoCase(strValue)==0)
		{
			return;
		}
		else
		{
			int nNewValue=nIdext;
			m_FlexGrid2.put_TextMatrix(m_nCurRow2,m_nCurCol2,strSelect);

			CString strField;
			if(m_nCurCol2==2)
				strField="networkcontroller";
			if(m_nCurCol2==3)
				strField="database_limition";
	
			try
			{

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

			CString strSql;

			strSql.Format(_T("update UserLevelSingleSet set "+strField+" = %i where username ='******' and MainBuilding_Name='%s' and Building_Name='%s'"),nNewValue,m_strUserName,m_strMainBuilding,m_strSubNetName);
			 
              SqliteDBBuilding.execDML((UTF8MBSTR)strSql);
			SqliteDBBuilding.closedb();
			}
			catch(_com_error *e)
			{
				AfxMessageBox(e->ErrorMessage());
			}

		}
	}
	
}
   	/*
	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::OnCbnSelchangeLevelsetcombo()
{
	
	if(m_nCurRow==0)
		return;
	if(m_nCurCol==0)
		return;
	CString strValue;
	strValue=m_FlexGrid.get_TextMatrix(m_nCurRow,m_nCurCol);
	CString strSelect;
	int nIdext=m_userLeveSetBox.GetCurSel();
	if(nIdext>=0)
	{
		m_userLeveSetBox.GetLBText(nIdext,strSelect);
		if(strSelect.CompareNoCase(strValue)==0)
		{
			return;
		}
		else
		{
			int nNewValue=nIdext;
			m_FlexGrid.put_TextMatrix(m_nCurRow,m_nCurCol,strSelect);

			CString strField;
			if(m_nCurCol==6)
				strField="mainscreen_level";
			if(m_nCurCol==7)
				strField="parameter_level";
			if(m_nCurCol==8)
				strField="outputtable_level";
			if(m_nCurCol==9)
				strField="graphic_level";

			//if(m_nCurCol==10)
				//	strField="building_level";
			if(m_nCurCol==10)
				strField="burnhex_level";
			if(m_nCurCol==11)
				strField="loadconfig_level";
			if(m_nCurCol==12)
				strField="allscreen_level";

			CString strSerial=m_FlexGrid.get_TextMatrix(m_nCurRow,2);
			strSerial.TrimLeft();
			strSerial.TrimRight();
			int nSerial=_wtol(strSerial);
			try
			{

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

			CString strSql;

			strSql.Format(_T("update user_level set "+strField+" = %i where serial_number = %i and username ='******' and MainBuilding_Name='%s' and Building_Name='%s'"),nNewValue,nSerial,m_strUserName,m_strMainBuilding,m_strSubNetName);
			 SqliteDBBuilding.execDML((UTF8MBSTR)strSql);

		     SqliteDBBuilding.closedb();
			}
			catch(_com_error *e)
			{
				AfxMessageBox(e->ErrorMessage());
			}	 

		}
	}

	if(m_nCurCol==12)
	{
		if(nIdext==0)//enable
		{
			for(int k=0;k<=12;k++)
				{
					if (m_nCurRow%2==0)
					{
						m_FlexGrid.put_Row(m_nCurRow);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(COLOR_CELL);
					}
					else
					{
						m_FlexGrid.put_Row(m_nCurRow);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(RGB(255,255,240));

					}
				}
		}
		else//unenable
		{
			for(int k=0;k<12;k++)
			{
			
				m_FlexGrid.put_Row(m_nCurRow);m_FlexGrid.put_Col(k);m_FlexGrid.put_CellBackColor(RGB(215,215,215));
			}
		}
	}
	//ReloadUserLevelDB();
}
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 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 T3000_Default_MainView::OnCbnSelchangeComboMstpModbus()
{
	int sel = m_mstpmodbus_combox.GetCurSel();
	int protocol = 0;

	if (product_register_value[7] == PM_TSTAT8
		|| (product_register_value[7] == PM_TSTAT8_WIFI) || (product_register_value[7] == PM_TSTAT8_OCC) || (product_register_value[7] == PM_TSTAT7_ARM) || (product_register_value[7] == PM_TSTAT8_220V)
		)
	{
 
		if (sel == 0)
		{
			protocol = 1;
		} 
		else
		{
			protocol = 0;
		}
	}
	else
	{
		if (sel == 1)
		{
			protocol = 3;
		}
	}
	
	 
    if (write_one(g_tstat_id, 21, protocol) > 0)
    {
        int temp_protocol = 0;
        if ((g_protocol == PROTOCOL_MSTP_TO_MODBUS) || (g_protocol == MODBUS_RS485))
        {
            if (protocol == 1) //设备选中MSTP 协议
            {
                temp_protocol = PROTOCOL_MSTP_TO_MODBUS;
            }
            else
            {
                temp_protocol = MODBUS_RS485;
            }
        }
        else //这里还要额外判断 挂在T3下面的MSTP 设备的处理方法;
        {
            return;
        }
        CString SqlText;
        SqlText.Format(_T("update ALL_NODE set Protocol = '%d' where Serial_ID='%d'"), temp_protocol, get_serialnumber());

        CppSQLite3DB SqliteDBBuilding;
        CppSQLite3Table table;
        CppSQLite3Query q;
        SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);

        SqliteDBBuilding.execDML((UTF8MBSTR)SqlText);
        SqliteDBBuilding.closedb();
        CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
        pFrame->ScanTstatInDB();
    }
	
 

}
void T3000_Default_MainView::OnBnClickedApplybutton()
{
    int m_nListenPort=0;
    BeginWaitCursor();
    //m_nListenPort	
    CString strText;
    m_ListenPort.GetWindowText(strText);
    if(!strText.IsEmpty())
        m_nListenPort=_wtoi(strText);
    if(m_nListenPort>=12767)
    {
        AfxMessageBox(_T("The listen port number is too big, please change it."));
        return;
    }
    if(m_nListenPort<=0)
    {
        AfxMessageBox(_T("The listen port number must be greater than 0!"));
        return;
    }
    write_one(g_tstat_id,75,m_nListenPort);
    product_register_value[75]=m_nListenPort;
    BYTE address1,address2,address3,address4;
    m_ipaddress.GetAddress(address1,address2,address3,address4);

    int sel = m_ip_model.GetCurSel ();
     write_one(g_tstat_id,61,sel);

    int CO2_NET_MODBUS_IP_ADDRESS_GHOST_START = 62 ;
    int n=write_one(g_tstat_id,CO2_NET_MODBUS_IP_ADDRESS_GHOST_START,address1);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_IP_ADDRESS_GHOST_START+1,address2);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_IP_ADDRESS_GHOST_START+2,address3);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_IP_ADDRESS_GHOST_START+3,address4);
    int CO2_NET_MODBUS_SUBNET_MASK_ADDRESS_GHOST_START = 66;
    m_Subnet_Mask.GetAddress(address1,address2,address3,address4);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_SUBNET_MASK_ADDRESS_GHOST_START+0,address1);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_SUBNET_MASK_ADDRESS_GHOST_START+1,address2);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_SUBNET_MASK_ADDRESS_GHOST_START+2,address3);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_SUBNET_MASK_ADDRESS_GHOST_START+3,address4);
    m_GatewayAddress.GetAddress(address1,address2,address3,address4);
    int CO2_NET_MODBUS_GATEWAY_ADDRESS_GHOST_START =   70;
    n=write_one(g_tstat_id,CO2_NET_MODBUS_GATEWAY_ADDRESS_GHOST_START,address1);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_GATEWAY_ADDRESS_GHOST_START+1,address2);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_GATEWAY_ADDRESS_GHOST_START+2,address3);
    n=write_one(g_tstat_id,CO2_NET_MODBUS_GATEWAY_ADDRESS_GHOST_START+3,address4);
    int CO2_NET_MODBUS_ENABLE_GHOST = 76;
    n=write_one(g_tstat_id,CO2_NET_MODBUS_ENABLE_GHOST,1);

    Sleep(5*1000);



    CMainFrame* pPraent=(CMainFrame*)GetParent();

    CString strBuilding,strSubBuilding;
    strBuilding=pPraent->m_strCurMainBuildingName;
    strSubBuilding=pPraent->m_strCurSubBuldingName;
    CString strIP,strPort;
    strPort.Format(_T("%d"),product_register_value[75]);
    // BYTE address1,address2,address3,address4;
    m_ipaddress.GetAddress(address1,address2,address3,address4);
    strIP.Format(_T("%d.%d.%d.%d"),address1,address2,address3,address4);
    if(g_CommunicationType==1)//TCP
    {
       /* int nPort;
        nPort=_wtoi(strPort);*/
        //m_strIP=build_info.strIp; 
        g_CommunicationType=1;
        SetCommunicationType(g_CommunicationType);
        BOOL bOk=FALSE;
        bOk=Open_Socket2(strIP,m_nListenPort);
        CString strInfo;

        strInfo.Format((_T("Open IP:%s successful")),strIP);//prompt info;
        SetPaneString(1,strInfo);
        if(bOk)
        {
            try
			{
			CppSQLite3DB SqliteDBBuilding;
			CppSQLite3Table table;
			CppSQLite3Query q;
			SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);


                CString strSql;
                //strSql.Format(_T("update Building set Ip_Address='%s' where Ip_Address='%s'"),strIP,pPraent->m_strIP);
                //t_pCon->Execute(strSql.GetString(),NULL,adCmdText);

                // ¸Änode
                CString strSID;

                strSID.Format(_T("%d"), get_serialnumber());
                strSql.Format(_T("update ALL_NODE set Bautrate='%s',Com_Port='%s' where Serial_ID='%s'"),strIP,strPort,strSID); //bautrate ·ÅIP
                SqliteDBBuilding.execDML((UTF8MBSTR)strSql);

                SqliteDBBuilding.closedb();

            }
            catch(_com_error *e)
            {
                AfxMessageBox(e->ErrorMessage());
            }

            pPraent->m_strIP=strIP;
            pPraent->ScanTstatInDB();

        }
        else
        {

        }



    }
    EndWaitCursor();
}