123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- // MainDlg.cpp : implementation of the CLoginDlg class
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "LoginDlg.h"
- #include "StabtypeControl.h"
- #include "CApp.h"
- #include "CNetWork.h"
-
- CLoginDlg::CLoginDlg() : SHostWnd(_T("LAYOUT:XML_LOGIN"))
- {
- m_bLayoutInited = FALSE;
- m_is_reg = FALSE;
-
- }
- CLoginDlg::~CLoginDlg()
- {
-
- }
- int CLoginDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- SetMsgHandled(FALSE);
- return 0;
- }
- BOOL CLoginDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
- {
- m_bLayoutInited = TRUE;
- Init();
- return 0;
- }
- void CLoginDlg::Init()
- {
- //if (m_network_tools == nullptr)
- //{
- // m_network_tools = new CManageNetWork();
- // //m_network_tools.Attach(new CManageNetWork());
- // m_network_tools->init();
- //}
- CManageNetWork::getSingletonPtr()->init();
-
-
- ServerListUrl list;
- list.id = 0;
- list.name = L"首选";
- list.url = "https://api.ruanjian.buzz";
- ServerListUrl list1;
- list1.id = 1;
- list1.name = L"备用1";
- list1.url = "https://api.ruanjian1.buzz";
- ServerListUrl list2;
- list2.id = 2;
- list2.name = L"备用2";
- list2.url = "https://ruanjian2.xyz";
- vctInfo.push_back(list);
- vctInfo.push_back(list1);
- vctInfo.push_back(list2);
- vctInfoUrl.push_back(list);
- vctInfoUrl.push_back(list2);
- vctInfoUrl.push_back(list2);
- CManageNetWork::getSingletonPtr()->SetUrlList(vctInfo);
- //StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"nodeclass");
- //if (tabtype)
- //{
- // for (auto i = 0; i < vctInfo.size(); i++)
- // {
- // tabtype->ItemCreateChildren(vctInfo[i].id, vctInfo[i].name, i == 0 ? true : false);
- // }
- // if (vctInfo.size() > 0)
- // {
- // CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[0].url.c_str());
- //
- // //Curl::getSingletonPtr()->SetUrl(vctInfo[0].url);
- // }
- // tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
- // Subscriber(&CLoginDlg::OnTabtypeControl, this));
- //}
- SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
- SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
- if (m_edit_username) {
- m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
- m_edit_username->Invalidate();
- }
- if (m_edit_password)
- {
- m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
- m_edit_password->Invalidate();
- }
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(L"正在获取系统配置..");
- onlogin->EnableWindow(FALSE);
- onlogin->Invalidate();
- }
- CManageNetWork::getSingletonPtr()->GetSysConfig();
-
- /*CManageNetWork::getSingletonPtr()->DonloadConfg();*/
- }
- bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
- {
- SOUI::EventTabtypeControl* pTestControlEvent =
- SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
- CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
-
- /*if (m_curl)
- {
- m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
- }*/
- //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
- return true;
- }
- //TODO:消息映射
- void CLoginDlg::OnClose()
- {
- CSimpleWnd::DestroyWindow();
- }
- void CLoginDlg::OnMaximize()
- {
- SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
- }
- void CLoginDlg::OnRestore()
- {
- SendMessage(WM_SYSCOMMAND, SC_RESTORE);
- }
- void CLoginDlg::OnMinimize()
- {
- SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
- }
- void CLoginDlg::OnLogin()
- {
-
- SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
- SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
- if (m_edit_username && m_edit_password)
- {
- auto username = m_edit_username->GetWindowTextW();
- auto password = m_edit_password->GetWindowTextW();
- /*if (m_base_curl) {
- char data[256] = { 0 };
- HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
- SLOG_DEBUG(data);
- }*/
- if (m_is_reg == FALSE)
- {
- CManageNetWork::getSingletonPtr()->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
- }
- else {
- CManageNetWork::getSingletonPtr()->Reg(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
- }
- }
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- auto text = m_is_reg == FALSE ? L"正在登录..." : L"正在注册...";
- onlogin->SetWindowTextW(text);
- onlogin->EnableWindow(FALSE);
- onlogin->Invalidate();
- }
- /**/
- }
- void CLoginDlg::ToMain()
- {
- CApp::getSingletonPtr()->SetOut(1);
- CSimpleWnd::DestroyWindow();
- }
- void CLoginDlg::OnUpdateLInkUI()
- {
- /*SLink* reglink = FindChildByName2<SLink>(L"reglink");
- if (reglink)
- {
- reglink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reg.c_str(),CP_UTF8));
- reglink->UpdateWindow();
- }*/
-
- SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
- if (resetlink)
- {
- resetlink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reset.c_str(), CP_UTF8));
- resetlink->UpdateWindow();
- }
- }
- void CLoginDlg::OnLoginFinish(EventArgs* e)
- {
- EventLogin* e2 = sobj_cast<EventLogin>(e);
- if (!e2)
- {
- return;
- }
- if (e2->status == 0)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- } else if (e2->status == -1)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
- }
- else if (e2->status == -2) //用户到期
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
- }
- else if (e2->status == -3) //用户流量用完
- {
-
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetOnlineLink(), NULL, NULL, SW_SHOWNORMAL);
- }
- else if (e2->status == 200)
- {
- /*if (m_network_tools)
- {
- m_network_tools->DonloadConfg();
- }*/
- ToMain();
- }
-
- }
- void CLoginDlg::OnDonloadFinish(EventArgs* e)
- {
- EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
- if (e2)
- {
- if (e2->status != 200)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- }
- else {
- ToMain();
- }
- }
- }
- void CLoginDlg::OnSysConfig(EventArgs* e)
- {
- EventSysconfig* e2 = sobj_cast<EventSysconfig>(e);
- if (e2)
- {
- if (e2->status == 200)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(L"获取配置成功,点击登录");
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- OnUpdateLInkUI();
-
- }
- else {
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- }
- }
- }
- void CLoginDlg::OnReg()
- {
- if (m_is_reg == FALSE)
- {
- SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
- if (resetlink)
- {
- resetlink->SetAttribute(L"show", L"0");
- resetlink->Invalidate();
- }
- SLink* reglink = FindChildByName2<SLink>(L"reglink");
- if (reglink)
- {
- reglink->SetWindowTextW(L"切换登录界面");
- ///reglink->SetAttribute(L"show", L"0");
- reglink->Invalidate();
- }
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(L"点击注册");
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
- SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
- if (m_edit_username && m_edit_password)
- {
- /*auto username = m_edit_username->GetWindowTextW();
- auto password = m_edit_password->GetWindowTextW();*/
- m_edit_username->SetWindowTextW(L"");
- m_edit_password->SetWindowTextW(L"");
- }
- m_is_reg = TRUE;
- }
- else
- {
- SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
- if (resetlink)
- {
- resetlink->SetAttribute(L"show", L"1");
- resetlink->Invalidate();
- }
- SLink* reglink = FindChildByName2<SLink>(L"reglink");
- if (reglink)
- {
- reglink->SetWindowTextW(L"注册新用户");
- ///reglink->SetAttribute(L"show", L"0");
- reglink->Invalidate();
- }
- SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
- SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
- if (m_edit_username) {
- m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
- m_edit_username->Invalidate();
- }
- if (m_edit_password)
- {
- m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
- m_edit_password->Invalidate();
- }
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(L"点击登录");
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- m_is_reg = FALSE;
- }
-
- }
|