The management software of students ' achievement based on DAO

Source: Internet
Author: User
Tags assert

I have written a few documents on the database before, and this one is the successor of the article. The front is developed with ODBC, now switch to Dao,dao has a disadvantage, not sync to support the latest version of Access, but also to the early version, do not know what Microsoft is doing. Say less, first look at the use of software:

    • 1. The dialog box has two menu items for creating classes and adding or subtracting accounts, with two subkeys below. The "Add Class" can only be used when you select a class in the combo control in the dialog box and then press the Start button, because the structure of the table is first available to create a new table. And the other three children are just the opposite, only if the program has just opened the class is not available by pressing the "Start button" or by selecting the "Close Class" item in the group control to press the Start button, because these three items are only safe to work when all class recordsets are closed.
    • 2, increase the record and before a little different, open the Add Record dialog box, you can see different, because the subject is with the "Add and subtract account" changes, so increase the record of the subject to dynamic change.
    • 3, modify the record only if you select a record in the list control, press the Modify Record button.
    • 4, the other is the same as the previous version.

Let's look at the development process:

Because the subject can change, so I didn't use a specific CDaoRecordset class, so most of the

The functionality is implemented using SQL statements.

1, first look at the OnInitDialog ():

BOOL Clistdlg::oninitdialog ()
{
CDialog::OnInitDialog ();
 
SetWindowText ("Student performance management");
Idm_aboutbox must is in the System command range.
ASSERT ((Idm_aboutbox & 0xfff0) = = Idm_aboutbox);
ASSERT (Idm_aboutbox < 0xf000);
cmenu* Psysmenu = GetSystemMenu (FALSE);
if (Psysmenu!= NULL)
{
CString Straboutmenu;
Straboutmenu.loadstring (Ids_aboutbox);
if (!straboutmenu.isempty ())
{
Psysmenu->appendmenu (Mf_separator);
Psysmenu->appendmenu (mf_string, Idm_aboutbox, Straboutmenu);
}
}
 
SetIcon (M_hicon, TRUE); Set Big icon
SetIcon (M_hicon, FALSE); Set Small Icon
GetDlgItem (Idc_strat)->enablewindow (FALSE);
This->enable (FALSE);
M_pdb=new CDaoDatabase;
CString spath;
GetModuleFileName (Null,spath.getbuffersetlength (max_path+1), MAX_PATH);
Spath.releasebuffer ();
int NPOs;
Npos=spath.reversefind (' \ \ ');
Spath=spath.left (NPOs);
Npos=spath.reversefind (' \ \ ');
Spath=spath.left (NPOs);
CString lpszfile = spath + "\\db6.mdb";
try{
M_pdb->open (lpszfile);
}
catch (cdaoexception* e)
{
AfxMessageBox (e->m_perrorinfo->m_strdescription,mb_iconexclamation);
Delete m_pdb;
E->delete ();
return FALSE;
}
  
CDaoTableDefInfo Tabinfo;
int ntabledefcount = M_pdb->gettabledefcount ();
for (int i = 0; i < Ntabledefcount; i++)
{
M_pdb->gettabledefinfo (I,tabinfo);
if (Tabinfo.m_lattributes & Dbsystemobject)
Continue
M_com.addstring (Tabinfo.m_strname);
}
M_precordset=new CDaoRecordset (M_PDB);
M_btf=true;
M_bcr=false;
return TRUE; Return TRUE unless your set the focus to a control
}

Its main task is to open the database and the name of the table

2, the following is the most important onstatr ():

void Clistdlg::onstrat ()
{
if (M_precordset->isopen ())
M_precordset->close ();
 
M_list1.deleteallitems ();
if (nfield!=0)
{
for (long i=0;i<nfield;i++)
{
M_list1.deletecolumn (0);
}
}
  
M_com.getlbtext (M_com.getcursel (), m_getstring);
if (m_getstring== "Close class")
{
M_btf=true;
M_bcr=false;
return;
}
M_btf=false;
M_bcr=true;
CString strsql= "SELECT * from" + m_getstring;
try{
M_precordset->open (dbOpenDynaset, strSQL);
M_precordset->m_strfilter.empty ();
}
catch (CDaoException *e)
{
AfxMessageBox (e->m_perrorinfo->m_strdescription,mb_iconexclamation);
Delete M_precordset;
M_pdb->close ();
Delete m_pdb;
E->delete ();
return;
}
  
if (M_precordset!= NULL)
{
M_pimagelist = new CImageList ();
M_pimagelist->create (IDB_BITMAP4, 1, RGB (255,0,0));
M_list1.setimagelist (M_pimagelist, Lvsil_small); /* Set Extended stlyes*/
    
DWORD dwExStyle = Lvs_ex_fullrowselect | Lvs_ex_gridlines | /*lvs_ex_subitemimages |*/
M_list1.setextendedstyle (lvs_ex_fullrowselect| Lvs_ex_gridlines);
Lvs_ex_headerdragdrop | Lvs_ex_trackselect;
Lv_column Lvcolumn;
Lvcolumn.mask = Lvcf_fmt | Lvcf_width | Lvcf_text | Lvcf_subitem;
LVCOLUMN.FMT = Lvcfmt_left; Lvcolumn.cx = 67;
Nfield=m_precordset->getfieldcount ();
for (int i = 0; i < Nfield i++)//Set up columns
{
CDaoFieldInfo M_fieldinfo;
M_precordset->getfieldinfo (i, m_fieldinfo);//get field name
int len = M_fieldinfo.m_strName.GetLength ();
CString temp = m_fieldinfo.m_strname;
tchar* szbuffer = new Tchar[len + 1];
strcpy (Szbuffer, temp. GetBuffer (len));
Temp. ReleaseBuffer ();
Lvcolumn.psztext = Szbuffer;
M_list1.insertcolumn (i, &lvcolumn);//insert column
Delete szbuffer;
}
/*set number of items in listview*/
M_precordset->movefirst ();
M_precordset->movelast ();
Long Count =m_precordset->getrecordcount ()//get number of records
This->ongetdispinfolist (count, Nfield);
  
}
GetDlgItem (Idc_strat)->enablewindow (FALSE);
This->enable (TRUE);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.