?? configframe.cpp
字號:
#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include "wx/tokenzr.h"#include "PicPanel.h"#include "ConfigFrame.h"#include "wx/artprov.h"#include "wx/listctrl.h"#include "wx/checkbox.h"#include "wx/brush.h"#include "wx/dc.h"#include "wx/dcclient.h"#include "wx/colour.h"#include "mainstore.xpm"#include "unsel.xpm"#include "sel.xpm"#include "check.xpm"#define MAX_WIN 32const int ID_LOGIN =143;const int ID_RESTART =144;const int ID_SHUTDOWN =145;const int ID_NET =146;const int ID_IPLISTCHANGE = 147;const int ID_CHECKBOX1 =148;const int ID_CHECKBOX2 =149;const int ID_LISTFILE =150;const int ID_SELALL =151;const int ID_OUTPUT =152;MYSQL * myData =NULL;int curSel; typedef struct { unsigned int code; //命令編號,該字段指明報文的類型 char m_strText[128]; //邏輯機號}TRequest;TRequest pRequest[MAX_WIN];typedef struct { int isCheck; int server_type; char server_ip[20]; char url[128]; char device[9]; int port; char by1[256]; int by2;}TWinInfo;TWinInfo winInfo[MAX_WIN];BEGIN_EVENT_TABLE(ConfigFrame, wxFrame) EVT_PAINT(ConfigFrame::OnPaint) EVT_BUTTON (ID_LOGIN, ConfigFrame::OnMyButtons) EVT_BUTTON (ID_RESTART, ConfigFrame::OnMyButtons) EVT_BUTTON (ID_SHUTDOWN, ConfigFrame::OnMyButtons) EVT_BUTTON (ID_NET, ConfigFrame::OnMyButtons) EVT_BUTTON (ID_SELALL, ConfigFrame::OnMyButtons) EVT_BUTTON (ID_OUTPUT, ConfigFrame::OnMyButtons) EVT_COMBOBOX(ID_IPLISTCHANGE, ConfigFrame::OnSelectIPList) EVT_CHECKBOX(ID_CHECKBOX1, ConfigFrame::OnCheckBox) EVT_CHECKBOX(ID_CHECKBOX2, ConfigFrame::OnCheckBox) EVT_LIST_ITEM_SELECTED(ID_LISTFILE, ConfigFrame::OnListFile) EVT_LIST_ITEM_DESELECTED(ID_LISTFILE, ConfigFrame::OnListFileUnsel) EVT_LIST_ITEM_ACTIVATED(ID_LISTFILE , ConfigFrame::OnActived) EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, ConfigFrame::OnSelChanged) EVT_MENU(TreeTest_ToReady,ConfigFrame::OnMenuSelect) EVT_MENU(TreeTest_ToDev,ConfigFrame::OnMenuSelect)END_EVENT_TABLE()wxString ConvertFromStrs(const char *raw){ wxString str; wxCSConv conv(_("gb2312")); return wxString(raw,conv);}int Minnumber(int x,int y){ return x>y?y:x; }int Maxnumber(int x,int y){ return x>y?x:y; }ConfigFrame::ConfigFrame(wxFrame *frame, const wxPoint& point, const wxSize& size, long style) : wxFrame(frame, -1, _(""),point,size,style), m_treeCtrl(NULL){ curSel = -1; wxCSConv conv(_("gb2312")); memset(&pRequest,0,sizeof(pRequest)); memset(&winInfo,0,sizeof(winInfo)); for(int i=0;i<MAX_WIN;i++) winInfo[i].server_type = 2; wxPanel* bg_panel = new wxPanel(this,-1,point,size); wxBitmap headbitmap(mainstore_xpm); headPanel = new PicPanel(bg_panel,wxPoint(0,0), wxSize(1024,768),headbitmap); m_treeCtrl = new MyTreeCtrl(headPanel, TreeTest_Ctrl, wxPoint(635,75), wxSize(341,610), wxTR_DEFAULT_STYLE); m_treeCtrl->SetWindowStyle(m_treeCtrl->GetWindowStyle() ^ wxTR_NO_LINES); m_treeCtrl->SetBackgroundColour(wxColor(192,191,251)); // 列表控件 listCtrlReport = new wxListCtrl( headPanel , ID_LISTFILE, wxPoint(44,141), wxSize(566, 490), wxLC_REPORT|wxLC_SINGLE_SEL); // 圖象列表 wxImageList *imageList = new wxImageList(16, 16, true, 1); wxBitmap listicon0(unsel_xpm); wxBitmap listicon1(sel_xpm); wxBitmap listicon2(check_xpm); imageList->Add(listicon0); imageList->Add(listicon1); imageList->Add(listicon2); //listCtrlReport->SetImageList(imageList, wxIMAGE_LIST_NORMAL); listCtrlReport->SetImageList(imageList, wxIMAGE_LIST_SMALL); //listCtrlReport->SetBackgroundColour(wxColor(241,243,250)); wxListItem itemCol; itemCol.SetAlign(wxLIST_FORMAT_CENTRE); itemCol.SetText(wxString("狀態",conv)); //itemCol.SetImage(-1); listCtrlReport->InsertColumn(0, itemCol); listCtrlReport->SetColumnWidth(0, 37 ); itemCol.SetText(wxString("監視位置",conv)); listCtrlReport->InsertColumn(1, itemCol); listCtrlReport->SetColumnWidth(1, 80 ); itemCol.SetText(wxString("關聯設備",conv)); listCtrlReport->InsertColumn(2, itemCol); listCtrlReport->SetColumnWidth(2, 120/* wxLIST_AUTOSIZE */ ); itemCol.SetText(wxString("關聯地址",conv)); listCtrlReport->InsertColumn(3, itemCol); listCtrlReport->SetColumnWidth(3, 315/* wxLIST_AUTOSIZE */ ); m_radioHAlign = new wxCheckBox(headPanel, ID_CHECKBOX1, _T(""), wxPoint(108,68), wxDefaultSize); m_radioVAlign = new wxCheckBox(headPanel, ID_CHECKBOX2, _T(""), wxPoint(299,68), wxDefaultSize); m_radioHAlign->SetValue(1); m_radioVAlign->SetValue(0); m_radioHAlign->SetBackgroundColour(wxColor(241,243,250)); m_radioVAlign->SetBackgroundColour(wxColor(241,243,250)); button1 = new wxButton(headPanel,ID_LOGIN,wxString("登錄界面",conv),wxPoint(36,716),wxSize(150,30)); button2 = new wxButton(headPanel,ID_NET,wxString("網絡配置",conv),wxPoint(296,716),wxSize(150,30)); button3 = new wxButton(headPanel,ID_RESTART,wxString("重啟系統",conv),wxPoint(571,716),wxSize(150,30)); button4 = new wxButton(headPanel,ID_SHUTDOWN,wxString("關閉系統",conv),wxPoint(831,716),wxSize(150,30)); buttonSel = new wxButton(headPanel,ID_SELALL,wxString("全選",conv),wxPoint(54,655),wxSize(70,25)); buttonOut = new wxButton(headPanel,ID_OUTPUT,wxString("輸出",conv),wxPoint(529,655),wxSize(70,25)); m_panel = new wxPanel(bg_panel,-1,wxPoint(35,60),wxSize(944,636)); m_panel->SetBackgroundColour(wxColor(241,243,250)); loginPage = new LoginPanel(m_panel,wxDefaultPosition, wxDefaultSize,0); loginPage->SetBackgroundColour(wxColor(241,243,250)); networkPage = new NetworkPanel(m_panel,wxDefaultPosition, wxDefaultSize,0); networkPage->SetBackgroundColour(wxColor(241,243,250)); m_sizerFrame = new wxBoxSizer(wxVERTICAL); m_sizerFrame->Add(loginPage, 0, wxEXPAND); m_sizerFrame->Add(networkPage, 1, wxEXPAND); ShowLoginPage(); m_panel->SetSizer(m_sizerFrame); }void ConfigFrame::OnMenuSelect(wxCommandEvent& event){ switch(event.GetId()) { case TreeTest_ToDev: m_treeCtrl->InitTree(); break; case TreeTest_ToReady: m_treeCtrl->InitTrees(); break; default: break; }}void ConfigFrame::OnActived(wxListEvent &event){ //2007-07-27 修改全選的BUG long selItem = event.GetIndex(); if(winInfo[selItem].port > 0) { if(winInfo[selItem].isCheck ==0) winInfo[selItem].isCheck = 2; else winInfo[selItem].isCheck = 0; } listCtrlReport->SetItemImage(selItem,winInfo[selItem].isCheck);}void ConfigFrame::OnSelChanged(wxTreeEvent& event){ //選擇樹型目錄 if(curSel == -1) return; int i = 0; long val; long curSels = curSel; wxCSConv conv(_("gb2312")); wxString url,chan,devid,devname; wxTreeItemId id = event.GetItem(); MyTreeItemData *iData = (MyTreeItemData *)m_treeCtrl->GetItemData(id); wxString desc = iData->GetDesc(); if(desc.Contains(_T("AllSelected,"))) { wxString str= odc2->GetValue(); if(str.Contains(wxString("服務器IP地址",conv))) { wxMessageBox(wxString("請選擇服務器IP地址!",conv),wxString("警告",conv),wxOK|wxCENTRE,this,460,300); return; } wxTreeItemIdValue cookie; wxTreeItemId sid; sid = m_treeCtrl->GetFirstChild(id,cookie); while(sid.IsOk()) { iData = (MyTreeItemData *)m_treeCtrl->GetItemData(sid); desc = iData->GetDesc(); if(desc.Contains(_T("rtsp://"))) { wxStringTokenizer tkz(desc, wxT(",")); i=0; while ( tkz.HasMoreTokens() ) { wxString token = tkz.GetNextToken(); if(i==0) url = token; if(i==1) chan = token; if(i==2) devid = token; if(i==3) devname = token; i++; } chan.ToLong(&val); wxString strDev,strTemp; strTemp.Printf(wxString("[第 %ld 路]",conv),val+1); strDev = devname + strTemp; listCtrlReport->SetItem(curSels,2,strDev); listCtrlReport->SetItem(curSels,3,url); listCtrlReport->SetItemImage(curSels,0); memset(&pRequest[curSels],0,sizeof(TRequest)); memset(&winInfo[curSels],0,sizeof(TWinInfo)); if(m_radioHAlign->GetValue() == 1) winInfo[curSels].server_type = 2; else winInfo[curSels].server_type = 3; sprintf(winInfo[curSels].by1,"%s",(const char *)strDev.mb_str(conv)); sprintf(winInfo[curSels].server_ip,"%s",(const char *)(odc2->GetValue()).mb_str(wxConvUTF8)); sprintf(winInfo[curSels].url,"%s",(const char *)url.mb_str(wxConvUTF8)); sprintf(winInfo[curSels].device,"%s",(const char *)devid.mb_str(wxConvUTF8)); winInfo[curSels].port = curSels + 1; winInfo[curSels].by2 = val; pRequest[curSels].code = curSels +1; sprintf(pRequest[curSels].m_strText,"%s",(const char *)url.mb_str(wxConvUTF8)); curSels = curSels + 1; } sid = m_treeCtrl->GetNextChild(id,cookie); } return; } if(desc.Contains(_T("rtsp://"))) { wxString str= odc2->GetValue(); if(str.Contains(wxString("服務器IP地址",conv))) { wxMessageBox(wxString("請選擇服務器IP地址!",conv),wxString("警告",conv),wxOK|wxCENTRE,this,460,300); return; } wxStringTokenizer tkz(desc, wxT(",")); i = 0; while ( tkz.HasMoreTokens() ) { wxString token = tkz.GetNextToken(); if(i==0) url = token; if(i==1) chan = token; if(i==2) devid = token; if(i==3) devname = token; i++; } chan.ToLong(&val); wxString strDev,strTemp; strTemp.Printf(wxString("[第 %ld 路]",conv),val+1); strDev = devname + strTemp; listCtrlReport->SetItem(curSel,2,strDev); listCtrlReport->SetItem(curSel,3,url); listCtrlReport->SetItemImage(curSel,0); memset(&pRequest[curSel],0,sizeof(TRequest)); memset(&winInfo[curSel],0,sizeof(TWinInfo)); if(m_radioHAlign->GetValue() == 1) winInfo[curSel].server_type = 2; else winInfo[curSel].server_type = 3; sprintf(winInfo[curSel].by1,"%s",(const char *)strDev.mb_str(conv)); sprintf(winInfo[curSel].server_ip,"%s",(const char *)(odc2->GetValue()).mb_str(wxConvUTF8)); sprintf(winInfo[curSel].url,"%s",(const char *)url.mb_str(wxConvUTF8)); sprintf(winInfo[curSel].device,"%s",(const char *)devid.mb_str(wxConvUTF8)); winInfo[curSel].port = curSel + 1; winInfo[curSel].by2 = val; pRequest[curSel].code = curSel +1; sprintf(pRequest[curSel].m_strText,"%s",(const char *)url.mb_str(wxConvUTF8)); }}void ConfigFrame::InitIPList(){ curSel = -1; memset(&pRequest,0,sizeof(pRequest)); memset(&winInfo,0,sizeof(winInfo)); listCtrlReport->DeleteAllItems(); m_arrItems.Clear(); if(odc2) delete odc2; wxCSConv conv(_("gb2312")); m_arrItems.Add( wxString("服務器IP地址列表...",conv) ); MYSQL_ROW row ; MYSQL_RES * res; int devCount; char szSQL[256]; memset(szSQL,0,sizeof(szSQL)); if(m_radioHAlign->GetValue() == 1) strcpy(szSQL,"select server_ip from serveriplist where server_code=2"); else strcpy(szSQL,"select server_ip from serveriplist where server_code=3"); if ( ! mysql_query( myData, szSQL ) ) { res = mysql_store_result( myData ) ; devCount = (int) mysql_num_rows( res ) ; while ( (row = mysql_fetch_row( res )) ) { m_arrItems.Add(wxString(row[0],wxConvUTF8)); } if(res) mysql_free_result(res); } odc2 = new wxOwnerDrawnComboBox(headPanel,ID_IPLISTCHANGE,wxEmptyString, wxPoint(200,97), wxDefaultSize, m_arrItems, wxNO_BORDER | wxCB_READONLY //(long)0 // ); odc2->SetSelection(0); odc2->SetBackgroundColour(wxColor(241,243,250));}void ConfigFrame::OnListFile(wxListEvent &event){ long selItem = event.GetIndex(); //listCtrlReport->SetItemImage(selItem,1); curSel = selItem;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -