int Search(const SStringT & strKey,SStudentSearchAdapter *pSearchAdapter) { if(strKey.IsEmpty()) return 0; for(UINT i=0;i<m_stuCurrent.GetCount();i++) { SStringT str = SStringT().Format(_T("%s(%u)"),m_stuCurrent[i].strNick,m_stuCurrent[i].imid); if(str.Find(strKey)!=-1) { SStudentSearchAdapter::StudentInfo2 info; info.strText = str; info.bExpired = FALSE; info.nPos = i; pSearchAdapter->m_searchResult.Add(info); } } for(UINT i=0;i<m_stuExpired.GetCount();i++) { SStringT str = SStringT().Format(_T("%s(%u)"),m_stuExpired[i].strNick,m_stuExpired[i].imid); if(str.Find(strKey)!=-1) { SStudentSearchAdapter::StudentInfo2 info; info.strText = str; info.bExpired = TRUE; info.nPos = i; pSearchAdapter->m_searchResult.Add(info); } } return pSearchAdapter->m_searchResult.GetCount(); }
virtual int getItemViewType(int position) { if(position == 0 || position == 1+ (m_bCurrentExpand?m_stuCurrent.GetCount():0)) return VT_GROUP; else return VT_DATA; }
bool OnStudentCheckChanged(EventArgs *e) { EventSwndStateChanged *e2 = sobj_cast<EventSwndStateChanged>(e); if(!e2->CheckState(WndState_Check)) return false; SCheckBox *pCheck = sobj_cast<SCheckBox>(e->sender); SASSERT(pCheck); SItemPanel * pItem = sobj_cast<SItemPanel>(pCheck->GetRoot()); int position = (int)pItem->GetItemIndex(); int nBaseCurrent = 1; int nBaseExpired = 1 + (m_bCurrentExpand?m_stuCurrent.GetCount():0) + 1; if(position < nBaseExpired) { m_stuCurrent[position - nBaseCurrent].bChecked = pCheck->IsChecked(); }else { m_stuExpired[position - nBaseExpired].bChecked = pCheck->IsChecked(); } if(m_pSelChangedHandler) { int nSelCur = 0, nSelExp=0; for(UINT i=0;i<m_stuCurrent.GetCount();i++) { nSelCur += m_stuCurrent[i].bChecked; } for(UINT i=0;i<m_stuExpired.GetCount();i++) { nSelExp += m_stuExpired[i].bChecked; } BOOL bAllCurrentChecked = nSelCur == m_stuCurrent.GetCount(); BOOL bAllExpiredChecked = nSelExp == m_stuExpired.GetCount(); if(bAllCurrentChecked!=m_bAllCurrentChecked || bAllExpiredChecked != m_bAllExpiredChecked) { m_bAllCurrentChecked = bAllCurrentChecked; m_bAllExpiredChecked = bAllExpiredChecked; notifyDataSetChanged(); } m_pSelChangedHandler->OnStudentCheckChanged(nSelCur,nSelExp); } return true; }
virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate) { int nViewType = getItemViewType(position); if(pItem->GetChildrenCount() == 0) { pugi::xml_node xmlItem; switch(nViewType) { case VT_GROUP: xmlItem = xmlTemplate.child(L"item_group");break; case VT_DATA: xmlItem = xmlTemplate.child(L"item_data");break; } pItem->InitFromXml(xmlItem); } if(nViewType == VT_GROUP) { SToggle * pSwitch=pItem->FindChildByID2<SToggle>(R.id.tgl_tv_expand); pSwitch->SetToggle(position==0?m_bCurrentExpand:m_bExpiredExpand); pSwitch->GetEventSet()->subscribeEvent(EVT_CMD,Subscriber(&CStudentAdapter::OnBtnGroupExpand,this)); pItem->FindChildByID(R.id.txt_group)->SetWindowText(TR(GETSTRING(position==0?R.string.current_student:R.string.expired_student),L"")); pItem->GetEventSet()->subscribeEvent(EVT_ITEMPANEL_DBCLICK,Subscriber(&CStudentAdapter::OnGroupDblClick,this)); SCheckBox *pGroupCheck = pItem->FindChildByID2<SCheckBox>(R.id.chk_select_group); pGroupCheck->GetEventSet()->subscribeEvent(EVT_STATECHANGED,Subscriber(&CStudentAdapter::OnGroupSelectCheckChanged,this)); pGroupCheck->GetEventSet()->setMutedState(true); pGroupCheck->SetCheck(position==0?m_bAllCurrentChecked:m_bAllExpiredChecked); pGroupCheck->GetEventSet()->setMutedState(false); }else { int nBaseCurrent = 1; int nBaseExpired = 1 + (m_bCurrentExpand?m_stuCurrent.GetCount():0) + 1; if(position< nBaseExpired) {//current student StudentInfo & stuInfo = m_stuCurrent[position-nBaseCurrent]; SCheckBox *pCheckBox = pItem->FindChildByID2<SCheckBox>(R.id.txt_nick); pCheckBox->GetEventSet()->subscribeEvent(EVT_STATECHANGED,Subscriber(&CStudentAdapter::OnStudentCheckChanged,this)); pCheckBox->GetEventSet()->setMutedState(true); pCheckBox->SetCheck(stuInfo.bChecked); pCheckBox->GetEventSet()->setMutedState(false); pCheckBox->SetWindowText(SStringT().Format(_T("%s(%u)"),stuInfo.strNick,stuInfo.imid)); pItem->FindChildByID(R.id.txt_loyal_degree)->SetWindowText(SStringT().Format(_T("%d"),stuInfo.nLoyalDegree)); pItem->FindChildByID(R.id.txt_time_span)->SetWindowText(stuInfo.tm1.Format(_T("%Y/%m/%d") + SStringT(_T(" - ")) + stuInfo.tm2.Format(_T("%Y/%m/%d")))); }else {//expired student StudentInfo & stuInfo = m_stuExpired[position-nBaseExpired]; SCheckBox *pCheckBox = pItem->FindChildByID2<SCheckBox>(R.id.txt_nick); pCheckBox->GetEventSet()->subscribeEvent(EVT_STATECHANGED,Subscriber(&CStudentAdapter::OnStudentCheckChanged,this)); pCheckBox->GetEventSet()->setMutedState(true); pCheckBox->SetCheck(stuInfo.bChecked); pCheckBox->GetEventSet()->setMutedState(false); pCheckBox->SetWindowText(SStringT().Format(_T("%s(%u)"),stuInfo.strNick,stuInfo.imid)); pItem->FindChildByID(R.id.txt_loyal_degree)->SetWindowText(SStringT().Format(_T("%d"),stuInfo.nLoyalDegree)); pItem->FindChildByID(R.id.txt_time_span)->SetWindowText(stuInfo.tm1.Format(_T("%Y/%m/%d") + SStringT(_T(" - ")) + stuInfo.tm2.Format(_T("%Y/%m/%d")))); } } }
bool OnGroupSelectCheckChanged(EventArgs *e) { EventSwndStateChanged *e2 = sobj_cast<EventSwndStateChanged>(e); SASSERT(e2); if(!e2->CheckState(WndState_Check)) return false; SCheckBox *pCheckBox = sobj_cast<SCheckBox>(e->sender); SASSERT(pCheckBox); SItemPanel * pItem = sobj_cast<SItemPanel>(pCheckBox->GetRoot()); int position = (int)pItem->GetItemIndex(); int nSelCur = 0, nSelExp=0; if(position == 0) { for(UINT i=0;i<m_stuCurrent.GetCount();i++) { m_stuCurrent[i].bChecked = (e2->dwNewState & WndState_Check)!=0; nSelCur += m_stuCurrent[i].bChecked; } for(UINT i=0;i<m_stuExpired.GetCount();i++) { nSelExp += m_stuExpired[i].bChecked; } }else { for(UINT i=0;i<m_stuCurrent.GetCount();i++) { nSelCur += m_stuCurrent[i].bChecked; } for(UINT i=0;i<m_stuExpired.GetCount();i++) { m_stuExpired[i].bChecked = (e2->dwNewState & WndState_Check)!=0;; nSelExp += m_stuExpired[i].bChecked; } } m_bAllCurrentChecked = nSelCur == m_stuCurrent.GetCount(); m_bAllExpiredChecked = nSelExp == m_stuExpired.GetCount(); notifyDataSetChanged(); if(m_pSelChangedHandler) m_pSelChangedHandler->OnStudentCheckChanged(nSelCur,nSelExp); return true; }
int EnsureKeyVisible(BOOL bExpired,int iItem) { if(!bExpired) { if(!m_bCurrentExpand) { m_bCurrentExpand = TRUE; notifyDataSetChanged(); } return 1+iItem; }else { if(!m_bExpiredExpand) { m_bExpiredExpand = TRUE; notifyDataSetChanged(); } return 2 + iItem + (m_bCurrentExpand?m_stuCurrent.GetCount():0); } }
virtual int getCount() { return m_smsRecord.GetCount(); }
virtual int getCount() { return 2 + (m_bCurrentExpand?m_stuCurrent.GetCount():0) + (m_bExpiredExpand?m_stuExpired.GetCount():0); }
VARIANT ExecuteScript(IWebBrowser2 *pWebBrowser, const SStringW & fun,SArray<SStringW> & params) { VARIANT varErr; VariantInit( &varErr ); //get document dispatch interface IDispatch* pDisp = NULL; HRESULT hr = pWebBrowser->get_Document( &pDisp ); if ( FAILED( hr ) || pDisp == NULL ) { return varErr; } IHTMLDocument2* pDoc = NULL; pDisp->QueryInterface( IID_IHTMLDocument2,(void**)&pDoc ); pDisp->Release(); IDispatch* pScript = NULL; hr = pDoc->get_Script( &pScript ); pDoc->Release(); if ( FAILED( hr ) || pScript == NULL ) { return varErr; } sbstr bstrMember((int)fun.GetLength(),fun ); DISPID dispid = 0; BSTR bstr = (BSTR)bstrMember; hr = pScript->GetIDsOfNames( IID_NULL,&(bstr),1,LOCALE_SYSTEM_DEFAULT,&dispid ); if ( FAILED( hr ) ) { return varErr; } DISPPARAMS dispparams; ::ZeroMemory( &dispparams,sizeof( DISPPARAMS ) ); dispparams.cArgs = (UINT)params.GetCount(); dispparams.rgvarg = new VARIANT[dispparams.cArgs]; dispparams.cNamedArgs = 0; for ( size_t i = 0;i < params.GetCount();i++ ) { size_t indx = params.GetCount() - i - 1; sbstr bstrParam((int)params[indx].GetLength(),params[indx]); dispparams.rgvarg[i].bstrVal = bstrParam.Release(); dispparams.rgvarg[i].vt = VT_BSTR; } EXCEPINFO excepinfo; ::ZeroMemory( &excepinfo,sizeof( EXCEPINFO ) ); VARIANT varRet; UINT nArgErr = (UINT)-1; //initialize to invalid arg hr = pScript->Invoke( dispid,IID_NULL,0,DISPATCH_METHOD,&dispparams,&varRet,&excepinfo,&nArgErr ); delete []dispparams.rgvarg; pScript->Release(); if ( FAILED( hr ) ) { return varErr; } return varRet; }