VC and database operation - Essence of inserting data into the Ctrllist control

xiaoxiao2021-03-06  69

Use of Ctrllist in VC and database link

Qinghua Chong Tian Ma Jingfa QQ: 283989349 E-mail: MJF150080@tom.com

When there is a problem, we can pass this forum http://www.hustc.mpc.cn,

Or through QQ to learn and discuss

// Dialog_traincourse.cpp: importation file //

#include "stdafx.h" #include "train.h" #include "dialog_traincourse.h" #include "courseinfo.h" #include "Dialog_Appise.h" #include "coursetet.h"

#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF

/// cdialog_traincourse dialog

CDIALOG_TRAINCOURSE :: CDIALOG_TRAINCOURSE (CWnd * pParent / * = NULL * /): CDialog (CDIALOG_TRAINCOURSE :: IDD, pParent) {// {{AFX_DATA_INIT (CDIALOG_TRAINCOURSE) // NOTE: the ClassWizard will add member initialization here //}} AFX_DATA_INIT }

void CDIALOG_TRAINCOURSE :: DoDataExchange (CDataExchange * pDX) {CDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CDIALOG_TRAINCOURSE) DDX_Control (pDX, IDC_LIST1, m_content); //}} AFX_DATA_MAP}

BEGIN_MESSAGE_MAP (CDIALOG_TRAINCOURSE, CDialog) // {{AFX_MSG_MAP (CDIALOG_TRAINCOURSE) ON_BN_CLICKED (IDC_BUTTONADD, OnButtonadd) ON_BN_CLICKED (IDC_BUTTONDEL, OnButtondel) //}} AFX_MSG_MAPEND_MESSAGE_MAP ()

/// cdialog_traincourse Message Handlers

void CDIALOG_TRAINCOURSE :: OnButtonadd () {// TODO: Add your control notification handler code here m_database.Close (); CCourseInfo m_courseinfo; m_courseinfo.m_database.Open (_T ( "train")); m_courseinfo.DoModal (); RefreshData ( }

void CDIALOG_TRAINCOURSE :: OnOK () {// TODO: Add extra validation here CDIALOG_APPISE m_apprisemanager; int i = m_content.GetSelectionMark (); CString strSQL; if (i == - 1) {MessageBox ( "please choose a course first!" } Else {m_apprisemanager.course_id = ATOI (m_content.getitemtext (i, 0)); m_database.close (); m_apprisemanager.m_database.open (_T ("train")); m_apprisemanager.domodal ();}}

BOOL CDIALOG_TRAINCOURSE :: OnInitDialog () {CDialog :: OnInitDialog (); // TODO: Add extra initialization here m_content.InsertColumn (0, "course number"); m_content.InsertColumn (1, "Course categories"); m_content.InsertColumn (2, "Course Chinese Name"); M_Content.insertColumn (3, "Course English Name"); M_Content.insertColumn (4, "Course Description"); M_Content.insertColumn (5, "Course"); m_content.insertColumn (6, "Textbook"); M_Content.insertColumn (7, "Equivalent Course"); M_Content.insertColumn (8, "Prerelection Course"); M_Content.insertColumn (9, "First Training / Reissue Sign"); M_Content.insertColumn (10, "Salary Department"); Rect Rect; M_Content.getWindowRect; Int Wid = Rect.right - Rect.Left; M_Content.SetColumnWidth (0, WID / 11); M_Content.SetColumnWidth (1, WID / 11); m_content.setColumnWidth (2, wid / 11); m_content.setColumnwidth (3, wid / 11); m_content.setColumnWidth (4, wid / 11); m_content.setColumnWidth (5, wid / 11); m_content .SETCOLUMNWIDTH (6, WID / 11); M_Content.SetColumnwidth (7, WID / 11); M_Content.SetColumnWidth (8, WID / 11); M_Content.SetColumnWidth (9, WID / 11); M_Content.SetColumnWidth (10, WID / 11); M_Content.sextendedStyle (LVS_EX_FULLR Ooselect; refreshdata (); return true; // Return True unless} EXCEPTION: OCX Property Pages Should Return False}

void CDIALOG_TRAINCOURSE :: RefreshData () {if {m_database.Open (_T ( "train")) (m_database.IsOpen ()!);} m_content.DeleteAllItems (); CCourseSet m_recordset (& m_database); CString strSQL; strSQL.Format ( "select * from COURSE"); m_recordset.Open (AFX_DB_USE_DEFAULT_TYPE, strSQL); CDBVariant varValue; if (m_recordset.GetRecordCount ()! = 0) m_recordset.MoveFirst (); char buf [20]; int i = 0; while ( M_RecordSet.iseof ()) {int Temp = 0; m_recordset.getfieldValue (Temp, Varvalue); Sprintf (buf, "% d", varvalue.m_ival); m_content.insertitem (i, buf); m_recordset.getfieldValue (1 , VARVALUE); M_Content.SetItemText (i, 1, varvalue.m_pstring-> getBuffer (1)); m_recordset.getfieldValue (2, varvalue); m_content.setitemtext (i, 2, varvalue.m_pstring-> getBuffer (1)) ; m_recordset.GetFieldValue (3, varValue); m_content.SetItemText (i, 3, varValue.m_pstring-> GetBuffer (1)); m_recordset.GetFieldValue (4, varValue); m_content.SetItemText (i, 4, varValue.m_pstring- > GetBuffer (1)); m_recordset.getfieldValue (5, varvalue); sprintf (buf, "% d", Varvalue .m_ival); m_content.setitemtext (i, 5, buf); m_recordset.getfieldValue (6, varValue); m_content.setitemtext (i, 6, varvalue.m_pstring-> getBuffer (1)); m_recordset.getfieldValue (7, VARVALUE ); Sprintf (buf, "% d", varvalue.m_ival); m_content.setitemtext (i, 7, buf); m_recordset.getfieldValue (8, varValue); Sprintf (buf, "% d", varValue.m_ival); M_Content.SetItemText (i, 8, buf); m_recordset.getfieldValue (9, varValue); sprintf (buf, "% d", varvalue.m_chval); m_content.SetItemtext (i, 9, buf); m_recordset.getfieldValue (10 , VARVALUE); Sprintf (buf, "% d", varvalue.m_ival); m_content.setitemtext (i, 10, buf); m_recordset.movenext (); i ;}}

void CDIALOG_TRAINCOURSE :: OnButtondel () {// TODO: Add your control notification handler code here int i = m_content.GetSelectionMark (); CString strSQL; if (i == - 1) {MessageBox ( "please choose a record first!" } Else {int keyid = atoi (m_content.getitemtext (i, 0)); strsql.format ("delete from course where course_id =% d", keyid); m_database.executesql (strsql); strsql.format (" delete from COURSE_EVALUATION where COURSE_ID =% d ", keyid); m_database.ExecuteSQL (strSQL); m_database.Close (); RefreshData ();}} void CDIALOG_TRAINCOURSE :: OnCancel () {// TODO: Add extra cleanup here m_database. CLOSE (); cdialog :: oncancel ();

转载请注明原文地址:https://www.9cbs.com/read-119713.html

New Post(0)