void CT3000App::ImportData(){ CADO ado; ado.OnInitADOConn(); CString sql=_T("select * from ALL_NODE"); ado.m_pRecordset=ado.OpenRecordset(sql); ALL_NODE temp; while(!ado.m_pRecordset->EndOfFile){ temp.MainBuilding_Name=ado.m_pRecordset->GetCollect(_T("MainBuilding_Name")); temp.Building_Name=ado.m_pRecordset->GetCollect(_T("Building_Name")); temp.Serial_ID=ado.m_pRecordset->GetCollect(_T("Serial_ID")); temp.Floor_name=ado.m_pRecordset->GetCollect(_T("Floor_name")); temp.Room_name=ado.m_pRecordset->GetCollect(_T("Room_name")); temp.Product_name=ado.m_pRecordset->GetCollect(_T("Product_name")); temp.Product_class_ID=ado.m_pRecordset->GetCollect(_T("Product_class_ID")); temp.Product_ID=ado.m_pRecordset->GetCollect(_T("Product_ID")); temp.Screen_Name=ado.m_pRecordset->GetCollect(_T("Screen_Name")); temp.Bautrate=ado.m_pRecordset->GetCollect(_T("Bautrate")); temp.Background_imgID=ado.m_pRecordset->GetCollect(_T("Background_imgID")); temp.Hardware_Ver=ado.m_pRecordset->GetCollect(_T("Hardware_Ver")); temp.Software_Ver=ado.m_pRecordset->GetCollect(_T("Software_Ver")); temp.Com_Port=ado.m_pRecordset->GetCollect(_T("Com_Port")); temp.EPsize=ado.m_pRecordset->GetCollect(_T("EPsize")); temp.Protocol=ado.m_pRecordset->GetCollect(_T("Protocol")); ado.m_pRecordset->MoveNext(); m_AllNodes.push_back(temp); } ado.CloseRecordset(); ado.CloseConn(); }
void CAirQuality::pctodb() { TRACE(_T("Updatedatabase()start!\n")); KillTimer(AirQualityTimer); //存入数据库中 CADO saveADO; saveADO.OnInitADOConn(); CString sql = _T("select * from AirQuality"); saveADO.m_pRecordset = saveADO.OpenRecordset(sql); if (!saveADO.m_pRecordset->EndOfFile) { saveADO.m_pRecordset->MoveFirst(); for(int i = 0;i<400;i++) { try { saveADO.m_pRecordset->PutCollect("Address",(_bstr_t)vecairquality.at(i).iaddress); saveADO.m_pRecordset->PutCollect("Data",(_bstr_t)vecairquality.at(i).CStvalue); saveADO.m_pRecordset->Update(); saveADO.m_pRecordset->MoveNext(); } catch(...) { SetPaneString(2,_T("Write dababase false!")); return ; } } } else { for(int i = 0;i<400;i++) { try { saveADO.m_pRecordset->AddNew(); saveADO.m_pRecordset->PutCollect("Address",(_bstr_t)vecairquality.at(i).iaddress); saveADO.m_pRecordset->PutCollect("Data",(_bstr_t)vecairquality.at(i).CStvalue); saveADO.m_pRecordset->Update(); } catch(...) { SetPaneString(2,_T("Write dababase false!")); return; } } } saveADO.CloseRecordset(); saveADO.CloseConn(); SetTimer(AirQualityTimer,1000,NULL); }
void CDialogT3::Updatedatabase() { TRACE(_T("Updatedatabase()start!\n")); KillTimer(T3_MODEL); //存入数据库中 CADO saveADO; saveADO.OnInitADOConn(); CString sql = _T("select * from T3_4AO"); saveADO.m_pRecordset = saveADO.OpenRecordset(sql); if (!saveADO.m_pRecordset->EndOfFile) { saveADO.m_pRecordset->MoveFirst(); for(int i = 0; i<230; i++) { try { //saveADO.m_pRecordset->AddNew(); //saveADO.m_pRecordset->Move(pos,vtMissing); // cstnum.Format(_T("%d"),i+1); // saveADO.m_pRecordset->PutCollect("Address",(_bstr_t)cstnum); // saveADO.m_pRecordset->PutCollect("Name",(_bstr_t)_T("output")); saveADO.m_pRecordset->PutCollect("Address",(_bstr_t)(i+1)); saveADO.m_pRecordset->PutCollect("Name",(_bstr_t)vect3model.at(i).CStName); saveADO.m_pRecordset->PutCollect("Data",(_bstr_t)shmPRegister[i]); saveADO.m_pRecordset->PutCollect("Range",(_bstr_t)vect3model.at(i).CStrange); if (i>=124&&i<=147) { switch ((int)(_variant_t)shmPRegister[i]) { case 0: //0- off 1 - mannel 2 - auto saveADO.m_pRecordset->PutCollect("AutoManual",(_bstr_t)"OFF"); break; case 1: saveADO.m_pRecordset->PutCollect("AutoManual",(_bstr_t)"Manual"); break; case 2: saveADO.m_pRecordset->PutCollect("AutoManual",(_bstr_t)"Auto"); break; default: break; } } // saveADO.m_pRecordset->PutCollect("Auto/Manual",(_bstr_t)"auto"); // saveADO.m_pRecordset->PutCollect("Range",(_bstr_t)"10%-100%"); saveADO.m_pRecordset->Update(); saveADO.m_pRecordset->MoveNext(); } catch(...) { SetPaneString(2,_T("Write dababase false!")); return ; } } } else { for(int i = 0; i<230; i++) { try { //saveADO.m_pRecordset->AddNew(); //saveADO.m_pRecordset->Move(pos,vtMissing); // cstnum.Format(_T("%d"),i+1); // saveADO.m_pRecordset->PutCollect("Address",(_bstr_t)cstnum); // saveADO.m_pRecordset->PutCollect("Name",(_bstr_t)_T("output")); saveADO.m_pRecordset->AddNew(); saveADO.m_pRecordset->PutCollect("Address",(_bstr_t)(i+1)); saveADO.m_pRecordset->PutCollect("Name",(_bstr_t)vect3model.at(i).CStName); saveADO.m_pRecordset->PutCollect("Data",(_bstr_t)shmPRegister[i]); saveADO.m_pRecordset->PutCollect("Range",(_bstr_t)vect3model.at(i).CStrange); if (i>=124&&i<=147) { switch ((int)(_variant_t)shmPRegister[i]) { case 0: //0- off 1 - mannel 2 - auto saveADO.m_pRecordset->PutCollect("AutoManual",(_bstr_t)"OFF"); break; case 1: saveADO.m_pRecordset->PutCollect("AutoManual",(_bstr_t)"Manual"); break; case 2: saveADO.m_pRecordset->PutCollect("AutoManual",(_bstr_t)"Auto"); break; default: break; } } // saveADO.m_pRecordset->PutCollect("Auto/Manual",(_bstr_t)"auto"); // saveADO.m_pRecordset->PutCollect("Range",(_bstr_t)"10%-100%"); saveADO.m_pRecordset->Update(); } catch(...) { //MessageBox(_T("Write dababase false!")); SetPaneString(2,_T("Write dababase false!")); return ; } } } saveADO.CloseRecordset(); saveADO.CloseConn(); SetTimer(T3_MODEL,1000,NULL); }
void CT3000App::JudgeDB(){ CADO ado; int versionno=0; ado.OnInitADOConn(); if (ado.IsHaveTable(ado,_T("Version")))//有Version表 { CString sql=_T("Select * from Version"); ado.m_pRecordset=ado.OpenRecordset(sql); ado.m_pRecordset->MoveFirst(); while (!ado.m_pRecordset->EndOfFile) { versionno=ado.m_pRecordset->GetCollect(_T("VersionNO")); ado.m_pRecordset->MoveNext(); } ado.CloseRecordset(); } ado.CloseConn(); if (g_versionNO>versionno)//版本过低 { SetPaneString(0,_T("The version of DB is lower,Updating.....")); _ConnectionPtr srcConTmp; _RecordsetPtr srcRsTemp; srcConTmp.CreateInstance("ADODB.Connection"); srcRsTemp.CreateInstance("ADODB.Recordset"); srcConTmp->Open(g_strDatabasefilepath.GetString(),"","",adModeUnknown); srcRsTemp->Open(_T("select * from ALL_NODE"),_variant_t((IDispatch *)srcConTmp,true),adOpenStatic,adLockOptimistic,adCmdText); ALL_NODE temp; while(!srcRsTemp->EndOfFile){ temp.MainBuilding_Name=srcRsTemp->GetCollect(_T("MainBuilding_Name")); temp.Building_Name=srcRsTemp->GetCollect(_T("Building_Name")); temp.Serial_ID=srcRsTemp->GetCollect(_T("Serial_ID")); temp.Floor_name=srcRsTemp->GetCollect(_T("Floor_name")); temp.Room_name=srcRsTemp->GetCollect(_T("Room_name")); temp.Product_name=srcRsTemp->GetCollect(_T("Product_name")); temp.Product_class_ID=srcRsTemp->GetCollect(_T("Product_class_ID")); temp.Product_ID=srcRsTemp->GetCollect(_T("Product_ID")); temp.Screen_Name=srcRsTemp->GetCollect(_T("Screen_Name")); temp.Bautrate=srcRsTemp->GetCollect(_T("Bautrate")); temp.Background_imgID=srcRsTemp->GetCollect(_T("Background_imgID")); temp.Hardware_Ver=srcRsTemp->GetCollect(_T("Hardware_Ver")); temp.Software_Ver=srcRsTemp->GetCollect(_T("Software_Ver")); // temp.Com_Port=srcRsTemp->GetCollect(_T("Com_Port")); temp.EPsize=srcRsTemp->GetCollect(_T("EPsize")); // temp.Protocol=srcRsTemp->GetCollect(_T("Protocol")); srcRsTemp->MoveNext(); m_AllNodes.push_back(temp); } srcRsTemp->Close(); if (srcConTmp->State) {srcConTmp->Close(); } CString filePath=g_strExePth+_T("Database\\T3000.mdb"); DeleteFile(filePath); HANDLE hFind;// WIN32_FIND_DATA wfd;// hFind = FindFirstFile(filePath, &wfd);// if (hFind==INVALID_HANDLE_VALUE)//说明当前目录下无t3000.mdb { //CopyFile(g_strOrigDatabaseFilePath,g_strDatabasefilepath,FALSE);// //没有找到就创建一个默认的数据库 filePath=g_strExePth+_T("Database\\T3000.mdb"); HRSRC hrSrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_T3000_DATABASE), _T("DB")); HGLOBAL hGlobal = LoadResource(AfxGetResourceHandle(), hrSrc); LPVOID lpExe = LockResource(hGlobal); CFile file; if(file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) file.Write(lpExe, (UINT)SizeofResource(AfxGetResourceHandle(), hrSrc)); file.Close(); ::UnlockResource(hGlobal); ::FreeResource(hGlobal); }// CString strsql; srcConTmp->Open(g_strDatabasefilepath.GetString(),"","",adModeUnknown); try { for (int i=0;i<m_AllNodes.size();i++) { strsql.Format(_T("insert into ALL_NODE (MainBuilding_Name,Building_Name,Serial_ID,Floor_name,Room_name,Product_name,Product_class_ID,Product_ID,Screen_Name,Bautrate,Background_imgID,Hardware_Ver,Software_Ver,EPsize) values('" +m_AllNodes[i].MainBuilding_Name+"','" +m_AllNodes[i].Building_Name+"','" +m_AllNodes[i].Serial_ID+"','" +m_AllNodes[i].Floor_name+"','" +m_AllNodes[i].Room_name+"','" +m_AllNodes[i].Product_name+"','" +m_AllNodes[i].Product_class_ID+"','" +m_AllNodes[i].Product_ID+"','" +m_AllNodes[i].Screen_Name+"','" +m_AllNodes[i].Bautrate+"','" +m_AllNodes[i].Background_imgID+"','" +m_AllNodes[i].Hardware_Ver+"','" +m_AllNodes[i].Software_Ver+"','" +m_AllNodes[i].EPsize+"')")); srcConTmp->Execute(strsql.GetString(),NULL,adCmdText); } } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } if (srcConTmp->State) {srcConTmp->Close(); } srcConTmp=NULL; } }
void CModbusPollView::Initial_RegName(){ _variant_t temp_var; if ((!m_isgetmodel)&&(!m_ischangedAddress)&&(!m_ischangeModelName)) { return; } // m_ischangeModelName=FALSE m_VecregisterData.clear(); for (int i=0;i<127;i++) { m_Alias[i]=_T(""); } CString TableName,RegName,RegAddress; CADO ado; ado.OnInitADOConn(); if(ado.IsHaveTable(ado,_T("ProductsTypeRegisterTables"))) { CString sql,temp; sql.Format(_T("Select * from ProductsTypeRegisterTables where ProductType=%d"),m_modeldata[1]); m_cur_modelNo=m_modeldata[1]; ado.m_pRecordset=ado.OpenRecordset(sql); if (!ado.m_pRecordset->EndOfFile) { temp_var=ado.m_pRecordset->GetCollect(_T("TableName")); if (temp_var.vt!=VT_NULL) { TableName=temp_var; } else { TableName=_T(""); } m_cur_TableName=TableName; temp_var=ado.m_pRecordset->GetCollect(_T("Col_RegName")); if (temp_var.vt!=VT_NULL) { RegName=temp_var; } else { RegName=_T(""); } m_cur_Col_RegName=RegName; temp_var=ado.m_pRecordset->GetCollect(_T("Col_RegAddress")); if (temp_var.vt!=VT_NULL) { RegAddress=temp_var; } else { RegAddress=_T(""); } m_cur_col_RegAddress=RegAddress; temp_var=ado.m_pRecordset->GetCollect(_T("ProductName")); if (temp_var.vt!=VT_NULL) { m_modelname=temp_var; } else { m_modelname=_T(""); } m_cur_modelName=m_modelname; } } ado.CloseRecordset(); if (TableName.GetLength()!=0) { if (ado.IsHaveTable(ado,TableName)) { DBRegister tempstuct; CString sql; if (TableName.CompareNoCase(_T("CustomProductTable"))==0) { sql.Format(_T("Select [%s],[%s] from %s where ModelNo=%d "),RegName.GetBuffer(),RegAddress.GetBuffer(),TableName.GetBuffer(),m_cur_modelNo); ado.m_pRecordset=ado.OpenRecordset(sql); while (!ado.m_pRecordset->EndOfFile) { temp_var=ado.m_pRecordset->GetCollect(RegAddress.GetBuffer()); if (temp_var.vt!=VT_NULL) { tempstuct.RegAddress=temp_var; } temp_var=ado.m_pRecordset->GetCollect(RegName.GetBuffer()); if (temp_var.vt!=VT_NULL) { tempstuct.RegName=temp_var; } m_VecregisterData.push_back(tempstuct); ado.m_pRecordset->MoveNext(); } } else { sql.Format(_T("Select [%s],[%s] from %s "),RegName.GetBuffer(),RegAddress.GetBuffer(),TableName.GetBuffer()); ado.m_pRecordset=ado.OpenRecordset(sql); while (!ado.m_pRecordset->EndOfFile) { temp_var=ado.m_pRecordset->GetCollect(RegAddress.GetBuffer()); if (temp_var.vt!=VT_NULL) { tempstuct.RegAddress=temp_var; } temp_var=ado.m_pRecordset->GetCollect(RegName.GetBuffer()); if (temp_var.vt!=VT_NULL) { tempstuct.RegName=temp_var; } m_VecregisterData.push_back(tempstuct); ado.m_pRecordset->MoveNext(); } } } if (m_VecregisterData.size()>=1) { int reglen=127; if (m_VecregisterData.size()<127) { reglen=m_VecregisterData.size(); } for (int i=0;i<reglen;i++) { m_Alias[i]=Find_RegName(i); } } m_ischangedAddress=FALSE; m_isnewmodel=FALSE; } else { m_isnewmodel=TRUE; for (int i=0;i<127;i++) { m_Alias[i]=_T(""); } } ado.CloseConn(); /*m_ischangeModelName=FALSE;*/ }
void CRegisterViewerDlg::LoadDataFromDB() { CString ProductModelName =Get_ProductModel(); _variant_t temp_var; if (ProductModelName.Find(_T("TStat"))!=-1)//Tstat serial { CADO ado; ado.OnInitADOConn(); if (ado.IsHaveTable(ado,_T("T3000_Register_Address_By_ID"))) { CString sql,temp; DBRegister tempstruct; sql.Format(_T("Select * from T3000_Register_Address_By_ID order by Register_Address")); ado.m_pRecordset=ado.OpenRecordset(sql); while (!ado.m_pRecordset->EndOfFile)//有表但是没有对应序列号的值 { if (product_type==T3000_5ABCDFG_LED_ADDRESS) { tempstruct.Register_Address=ado.m_pRecordset->GetCollect(_T("Register_Address")); tempstruct.AddressName=ado.m_pRecordset->GetCollect(_T("TSTAT5_LED_AddressName")); tempstruct.DataType=ado.m_pRecordset->GetCollect(_T("TSTAT5_LED_DATATYPE")); tempstruct.length=ado.m_pRecordset->GetCollect(_T("TSTAT5_LED_LEN")); temp_var=ado.m_pRecordset->GetCollect(_T("TSTAT5_LED_DESCRIPTION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Description=temp_var; } temp_var=ado.m_pRecordset->GetCollect(_T("TSTAT5_LED_Operation")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Operation=temp_var; } /* tempstruct.Description=(CString)ado.m_pRecordset->GetCollect(_T("TSTAT5_LED_DESCRIPTION"));*/ } else if (product_type==T3000_5EH_LCD_ADDRESS) { _variant_t vartemp; tempstruct.Register_Address=ado.m_pRecordset->GetCollect(_T("Register_Address")); tempstruct.AddressName=ado.m_pRecordset->GetCollect(_T("TSTAT5_LCD_AddressName")); tempstruct.DataType=ado.m_pRecordset->GetCollect(_T("TSTAT5_LCD_DATATYPE")); tempstruct.length=ado.m_pRecordset->GetCollect(_T("TSTAT5_LCD_LEN")); //tempstruct.Description=(CString)ado.m_pRecordset->GetCollect(_T("TSTAT5_LCD_DESCRIPTION")); vartemp=ado.m_pRecordset->GetCollect(_T("TSTAT5_LCD_DESCRIPTION")); if (vartemp.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Description=vartemp; } temp_var=ado.m_pRecordset->GetCollect(_T("TSTAT5_LCD_Operation")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Operation=temp_var; } } else if (product_type==T3000_6_ADDRESS) { tempstruct.Register_Address=ado.m_pRecordset->GetCollect(_T("Register_Address")); tempstruct.AddressName=ado.m_pRecordset->GetCollect(_T("TSTAT6_AddressName")); tempstruct.DataType=ado.m_pRecordset->GetCollect(_T("TSTAT6_DATATYPE")); tempstruct.length=ado.m_pRecordset->GetCollect(_T("TSTAT6_LEN")); temp_var=ado.m_pRecordset->GetCollect(_T("TSTAT6_DESCRIPTION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Description=temp_var; } temp_var=ado.m_pRecordset->GetCollect(_T("TSTAT6_Operation")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Operation=temp_var; } } if (tempstruct.AddressName.CompareNoCase(_T("RESERVED"))==0) { ado.m_pRecordset->MoveNext(); continue; } m_VecregisterData.push_back(tempstruct); m_recordcount++; ado.m_pRecordset->MoveNext(); } } ado.CloseRecordset(); ado.CloseConn(); } else if (ProductModelName.Find(_T("T3"))!=-1)//T3 Serial { CADO ado; ado.OnInitADOConn(); if (ado.IsHaveTable(ado,_T("T3_RegisterList"))) { CString sql,temp; DBRegister tempstruct; sql.Format(_T("Select * from T3_RegisterList order by RegID")); ado.m_pRecordset=ado.OpenRecordset(sql); if (m_modelno==PM_T3PT10) { while(!ado.m_pRecordset->EndOfFile){ tempstruct.Register_Address=ado.m_pRecordset->GetCollect(_T("RegID")); temp_var=ado.m_pRecordset->GetCollect(_T("T3-RTD")); if (temp_var.vt==VT_NULL) { tempstruct.AddressName=_T(""); } else { tempstruct.AddressName=temp_var; } if ((tempstruct.AddressName.CompareNoCase(_T("RESERVED"))==0)||tempstruct.AddressName.IsEmpty()) { ado.m_pRecordset->MoveNext(); continue; } tempstruct.DataType=ado.m_pRecordset->GetCollect(_T("T3-8AI8AO_DATATYPE")); tempstruct.length=ado.m_pRecordset->GetCollect(_T("T3-8AI8AO_LEN")); temp_var=ado.m_pRecordset->GetCollect(_T("T3-8AI8AO_DESCRIPTION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Description=temp_var; } temp_var=ado.m_pRecordset->GetCollect(_T("T3-8AI8AO_OPERATION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Operation=temp_var; } m_VecregisterData.push_back(tempstruct); m_recordcount++; ado.m_pRecordset->MoveNext(); } } else if (m_modelno==PM_T3PT10) { while(!ado.m_pRecordset->EndOfFile){ tempstruct.Register_Address=ado.m_pRecordset->GetCollect(_T("RegID")); temp_var=ado.m_pRecordset->GetCollect(_T("T3-RTD")); if (temp_var.vt==VT_NULL) { tempstruct.AddressName=_T(""); } else { tempstruct.AddressName=temp_var; } if ((tempstruct.AddressName.CompareNoCase(_T("RESERVED"))==0)||tempstruct.AddressName.IsEmpty()) { ado.m_pRecordset->MoveNext(); continue; } tempstruct.DataType=ado.m_pRecordset->GetCollect(_T("T3-8AI16O_DATATYPE")); tempstruct.length=ado.m_pRecordset->GetCollect(_T("T3-8AI16O_LEN")); temp_var=ado.m_pRecordset->GetCollect(_T("T3-8AI16O_DESCRIPTION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Description=temp_var; } temp_var=ado.m_pRecordset->GetCollect(_T("T3-8AI16O_OPERATION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Operation=temp_var; } m_VecregisterData.push_back(tempstruct); m_recordcount++; ado.m_pRecordset->MoveNext(); } } else if (m_modelno==PM_T3IOA) { } else if (m_modelno==PM_T332AI) { } else if (m_modelno==PM_T3AI16O) { } else if (m_modelno==PM_T3PERFORMANCE) { } else if (m_modelno==PM_T34AO) { while(!ado.m_pRecordset->EndOfFile){ tempstruct.Register_Address=ado.m_pRecordset->GetCollect(_T("RegID")); temp_var=ado.m_pRecordset->GetCollect(_T("T3-4AO")); if (temp_var.vt==VT_NULL) { tempstruct.AddressName=_T(""); } else { tempstruct.AddressName=temp_var; } if ((tempstruct.AddressName.CompareNoCase(_T("RESERVED"))==0)||tempstruct.AddressName.IsEmpty()) { ado.m_pRecordset->MoveNext(); continue; } tempstruct.DataType=ado.m_pRecordset->GetCollect(_T("T3-4AO_DATATYPE")); tempstruct.length=ado.m_pRecordset->GetCollect(_T("T3-4AO_LEN")); temp_var=ado.m_pRecordset->GetCollect(_T("T3-4AO_DESCRIPTION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Description=temp_var; } temp_var=ado.m_pRecordset->GetCollect(_T("T3-4AO_OPERATION")); if (temp_var.vt==VT_NULL) { tempstruct.Description=_T(""); } else { tempstruct.Operation=temp_var; } m_VecregisterData.push_back(tempstruct); m_recordcount++; ado.m_pRecordset->MoveNext(); } } else if (m_modelno==PM_T36CT) { } } ado.CloseRecordset(); ado.CloseConn(); } else { } CString temp; m_Datapages=(m_recordcount/ROWS)+1; temp.Format(_T("Product Name")); GetDlgItem(IDC_PRODUCTNAME)->SetWindowText(temp); GetDlgItem(IDC_PRODUCTNAME_T)->SetWindowText(GetProductName(product_register_value[7])); temp.Format(_T("%d/%d"),m_curPage,m_Datapages); GetDlgItem(IDC_PAGES)->SetWindowText(temp); }
/* Date:2013/05/29 Purpose: parameters 1:根据层次 2:改变的名字,有新旧比较 */ BOOL CWorkspaceBar::UpdateDataToDB(){ /* _ConnectionPtr m_pCon; _RecordsetPtr m_pRs; ::CoInitialize(NULL);*/ CADO ado; ado.OnInitADOConn(); CBADO bado; bado.SetDBPath(g_strCurBuildingDatabasefilePath); bado.OnInitADOConn(); try { //////////////////////////////////////////////////////////////////////////////////////////// //获取数据库名称及路径 ///////////////////////////////////////////////////////////////////////////////////////////////// //连接数据库 /* m_pCon.CreateInstance("ADODB.Connection"); m_pRs.CreateInstance(_T("ADODB.Recordset")); m_pCon->Open(g_strDatabasefilepath.GetString(),"","",adModeUnknown);*/ CString strSql; BOOL is_exist=FALSE; CString str_temp; switch (m_level) { case 0: //Subnet { //strSql.Format(_T("select * from Building where Main_BuildingName = '%s'"),m_strMainBuildingName); strSql.Format(_T("select * from Building order by Main_BuildingName")); //m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText); ado.m_pRecordset=ado.OpenRecordset(strSql); while(VARIANT_FALSE== ado.m_pRecordset->EndOfFile) { str_temp.Empty(); str_temp= ado.m_pRecordset->GetCollect("Building_Name"); if (str_temp.Compare(m_name_new)==0) { is_exist=TRUE; break; } ado.m_pRecordset->MoveNext(); } // m_pRs->Close(); ado.CloseRecordset(); if (!is_exist) //更新的名字在数据库中查找不到的 { ////////////先更新Building表///////////////////// //CString strSql; strSql.Format(_T("delete * from Building_ALL where Building_Name = '%s' "),m_name_old); ado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); strSql.Format(_T("Insert into Building_ALL(Building_Name,Default_Build) values('%s','%d')"),m_name_new,1); ado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); 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); ado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); strSql.Format(_T("select * from ALL_NODE where Building_Name='%s' order by Building_Name"),m_name_old); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE== bado.m_pRecordset->EndOfFile) { strSql.Format(_T("update ALL_NODE set Building_Name='%s' where Building_Name='%s'"),m_name_new,m_name_old); bado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); bado.m_pRecordset->MoveNext(); } //m_pRs->Close(); bado.CloseRecordset(); } else { return FALSE; } break; } case 1: //Floor { // strSql=_T("select * from Building where Default_SubBuilding=-1"); // 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); // m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE== bado.m_pRecordset->EndOfFile) { str_temp.Empty(); str_temp= bado.m_pRecordset->GetCollect("Floor_name"); if (str_temp.Compare(m_name_new)==0) {is_exist=TRUE; break; } bado.m_pRecordset->MoveNext(); } bado.CloseRecordset(); 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); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE==bado.m_pRecordset->EndOfFile) { strSql.Format(_T("update ALL_NODE set Floor_name='%s' where Floor_name='%s'"),m_name_new,m_name_old); bado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); bado.m_pRecordset->MoveNext(); } //m_pRs->Close(); bado.CloseRecordset(); 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); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE==bado.m_pRecordset->EndOfFile) { str_temp.Empty(); str_temp=bado.m_pRecordset->GetCollect("Room_name"); if (str_temp.Compare(m_name_new)==0) { is_exist=TRUE; break; } bado.m_pRecordset->MoveNext(); } // bado.m_pRecordset->Close(); bado.CloseRecordset(); 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); //bado.m_pConnection->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE==bado.m_pRecordset->EndOfFile) { strSql.Format(_T("update ALL_NODE set Room_name='%s' where Room_name='%s'"),m_name_new,m_name_old); bado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); bado.m_pRecordset->MoveNext(); } //m_pRs->Close(); bado.CloseRecordset(); 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); // m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE== bado.m_pRecordset->EndOfFile) { str_temp.Empty(); str_temp= bado.m_pRecordset->GetCollect("Product_name"); if (str_temp.Compare(m_name_new)==0) { is_exist=TRUE; break; } bado.m_pRecordset->MoveNext(); } // m_pRs->Close(); bado.CloseRecordset(); 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); // m_pRs->Open((_variant_t)strSql,_variant_t((IDispatch *)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText); bado.m_pRecordset=bado.OpenRecordset(strSql); while(VARIANT_FALSE== bado.m_pRecordset->EndOfFile) { strSql.Format(_T("update ALL_NODE set Product_name='%s' where Product_name='%s'"),m_name_new,m_name_old); bado.m_pConnection->Execute(strSql.GetString(),NULL,adCmdText); bado.m_pRecordset->MoveNext(); } //m_pRs->Close(); bado.CloseRecordset(); return TRUE; } break; } } } catch(_com_error e) { /* AfxMessageBox(e.Description());*/ //MessageBox(m_name_new+_T(" has been here\n Please change another name!")); bado.CloseConn(); return FALSE; //m_pCon->Close(); } ado.CloseRecordset(); ado.CloseConn(); bado.CloseRecordset(); bado.CloseConn(); return TRUE; }