-
April 7th, 2009, 03:46 AM
#1
Class , how to encapsulate this :
ok this my 1st time writing classes so i need help on
how to write a class for this :
Code:
void CADOMFC1View::OnMenuitem32771()
{
_RecordsetPtr pRecordSet;
CADOMFC1Doc * pDoc;
pDoc = GetDocument();
_bstr_t bstrQuery("SELECT * FROM App_Student");
_variant_t vRecsAffected(0L);
try
{
pRecordSet = pDoc->m_pConnection->Execute(bstrQuery,&vRecsAffected,adOptionUnspecified);
if (!pRecordSet->GetadoEOF())
{
CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl();
ctlList.DeleteAllItems();
while(ctlList.DeleteColumn(0));
ctlList.AddColumn(" ID ",0);
ctlList.AddColumn(" Name ",1);
ctlList.AddColumn(" Gender ",2);
ctlList.AddColumn(" Subject 1 ",3);
ctlList.AddColumn(" Subject 2 ",4);
ctlList.AddColumn(" Class ",5);
int i = 0;
_variant_t ID;
_variant_t vName;
_variant_t cGender;
_variant_t vSubject1;
_variant_t vSubject2;
_variant_t Class;
while (!pRecordSet->GetadoEOF())
{
ID = pRecordSet->GetCollect(L"ID");
ctlList.AddItem(i,0,(_bstr_t) ID);
vName = pRecordSet->GetCollect(L"vName");
ctlList.AddItem(i,1,(_bstr_t) vName);
cGender = pRecordSet->GetCollect(L"cGender");
ctlList.AddItem(i,2,(_bstr_t) cGender);
vSubject1 = pRecordSet->GetCollect(L"vSubject1");
ctlList.AddItem(i,3,(_bstr_t) vSubject1);
vSubject2 = pRecordSet->GetCollect(L"vSubject2");
ctlList.AddItem(i,4,(_bstr_t) vSubject2);
Class = pRecordSet->GetCollect(L"Class");
ctlList.AddItem(i,5,(_bstr_t) Class);
pRecordSet->MoveNext();
i++;
}
}
pRecordSet->Close();
}
catch( _com_error &e )
{
// Get info from _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE( "Exception thrown for classes generated by #import" );
TRACE( "\tCode = %08lx\n", e.Error());
TRACE( "\tCode meaning = %s\n", e.ErrorMessage());
TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);
TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
}
}
THANKS
Last edited by ovidiucucu; April 7th, 2009 at 04:35 AM.
Reason: added CODE tags
-
April 7th, 2009, 05:00 AM
#2
Re: Class , how to encapsulate this :
Originally Posted by shong
ok this my 1st time writing classes so i need help on how to write a class for this :
Code:
void CADOMFC1View::OnMenuitem32771()
{
//...
// ...
}
Sounds like you want to apply a "command pattern" (see "How to Scratch With the Foot" or "Design Patterns"... ).
My advice is: once you are using MFC, follow the MFC way!
Let (Class) Wizard to do its job (to add classes, command handler functions, etc) and forget other patterns.
That will prevent many further headaches.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|