📄 loginpanel.cpp
字号:
#include "LoginPanel.h"#include "ConfigFrame.h"const int ID_Button_OK= 500;const int ID_Button_Clear= 501;extern MYSQL * myData ;BEGIN_EVENT_TABLE(LoginPanel, wxPanel) EVT_PAINT(LoginPanel::OnPaint) EVT_BUTTON(ID_Button_OK, LoginPanel::OnButtonOK) EVT_BUTTON(ID_Button_Clear, LoginPanel::OnButtonClear)END_EVENT_TABLE()wxString ConvertFromChar(const char *raw){ wxString str; wxChar wStr[512]; #ifdef UNICODE memset(wStr,0,sizeof(wStr)); mbstowcs(wStr,raw,strlen(raw)); str.Printf(_("%s"),wStr); #else str.Printf(_("%s"),raw); #endif return str;}// 将本地编码字符串转换成UTF-8编码const wxCharBuffer ConvertToUTF8(wxString anyString){ return wxConvUTF8.cWC2MB( anyString.wc_str(*wxConvCurrent) ) ;}// 将UTF-8编码的字符串转换成本地编码字符串wxString ConvertFromUTF8(const char* rawUTF8){ return wxString(wxConvUTF8.cMB2WC(rawUTF8), *wxConvCurrent);}LoginPanel::LoginPanel(wxWindow *parent, const wxPoint& point, const wxSize& size, long style) : wxPanel(parent, -1,point,size,style, _("")){ strIP = _T(""); strUser = _T(""); wxFileInputStream ConfigInStream(_("/software/config/passwd")); if(ConfigInStream.Ok())//检查配置文件是否存在 { wxFileConfig config(ConfigInStream, wxConvUTF8); if(!config.Read(_("IPADD"),&strIP)) { strIP = _(""); } if(!config.Read(_("USERNAME"),&strUser)) { strUser = _(""); } } // 建立到配置文件的连接,同时指定转换为UTF8格式 pStaticBox = new wxStaticBox(this,-1,_("登录"),wxPoint(300,200),wxSize(400,320)); pTxt1 = new wxStaticText(this,-1,_("应用服务器IP地址:"),wxPoint(325,275),wxSize(140,25),wxALIGN_RIGHT); pEdit1 = new EditCtrl(this,-1,strIP,wxPoint(475,275),wxSize(150,25),wxTE_PROCESS_ENTER); pTxt2 = new wxStaticText(this,-1,_("用户名:"),wxPoint(325,325),wxSize(140,25),wxALIGN_RIGHT); pEdit2 = new EditCtrl(this,-1,strUser,wxPoint(475,325),wxSize(150,25),wxTE_PROCESS_ENTER); pTxt3 = new wxStaticText(this,-1,_("密码:"),wxPoint(325,375),wxSize(140,25),wxALIGN_RIGHT); pEdit3 = new EditCtrl(this,-1,_(""),wxPoint(475,375),wxSize(150,25),wxTE_PASSWORD); pButtonOK = new ButtonCtrl(this,ID_Button_OK,_("确定"),wxPoint(380,440),wxSize(70,27)); pButtonClear = new ButtonCtrl(this,ID_Button_Clear,_("清除"),wxPoint(560,440),wxSize(70,27)); }void LoginPanel::OnPaint(wxPaintEvent& event){}LoginPanel::~LoginPanel(){ mysql_close( myData ) ;}void LoginPanel::OnButtonOK(wxCommandEvent& event){ ConfigFrame* pMainFrame = (ConfigFrame*)(this->GetParent()->GetParent()->GetParent()); if(myData) { mysql_close( myData ) ; } if ( (myData = mysql_init((MYSQL*) 0)) && mysql_real_connect( myData, (pEdit1->GetValue()).mb_str(wxConvUTF8), (pEdit2->GetValue()).mb_str(wxConvUTF8), (pEdit3->GetValue()).mb_str(wxConvUTF8), szDB,MYSQL_PORT_SVR,NULL, 0)) { if ( mysql_select_db( myData, szDB ) < 0 ) { mysql_close( myData ) ; wxMessageBox(_T("登陆失败,数据库不存在!"),_T("错误"),wxOK|wxCENTRE,this,460,300); return; } }else{ wxMessageBox(_T("登陆失败,数据库连接错误!"),_T("错误"),wxOK|wxCENTRE,this,460,300); return; } //操作数据库的例子 /*char szSQL[1024]; int devCount; MYSQL_ROW row ; MYSQL_RES * res; memset(szSQL,0,sizeof(szSQL)); strcpy(szSQL,"select dev_id,dev_name,dev_station,by1,dev_IP,dev_user,dev_userpass,dev_port from device"); if ( ! mysql_query( myData, szSQL ) ) { res = mysql_store_result( myData ) ; devCount = (int) mysql_num_rows( res ) ; while ( row = mysql_fetch_row( res ) ) { wxMessageBox(ConvertFromChar(row[2]),ConvertFromChar("错误"),wxOK|wxCENTRE,NULL,460,300); wxString str,dev_name; str = ConvertFromChar(row[0]); dev_name = ConvertFromChar(row[1]); //wxTreeItemId id = AppendItem(rootId, dev_name, imagefolder, imagefolderSel, // new MyTreeItemData(str)); //SetItemImage(id, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); } }*/ if(strIP!=pEdit1->GetValue() || strUser!=pEdit2->GetValue()) { wxTextFile file(_("/software/config/passwd")); if(file.Open()) { file.Clear(); file.AddLine(_("IPADD=")+pEdit1->GetValue()); file.AddLine(_("USERNAME=")+pEdit2->GetValue()); file.Write(); file.Close(); system("mount /dev/hda1 /mnt"); system("cp /software/config/passwd /mnt/boot/"); system("umount /mnt"); } } //pMainFrame->button1->Show(1); //pMainFrame->button2->Show(1); //pMainFrame->button3->Show(1); //pMainFrame->button4->Show(1); pMainFrame->InitIPList(); pMainFrame->m_treeCtrl->InitTree(); pMainFrame->ShowListPage();}void LoginPanel::OnButtonClear(wxCommandEvent& event){ pEdit1->Clear(); pEdit2->Clear(); pEdit3->Clear();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -