/// / function: Pop-moving modification record window // Date: 2003.12 // void cmaindlg :: onradiomod () {// Todo: add your control notification handler code (); // This dialog is disconnected CModifyDlg dlg database connection; dlg.m_database.Open (_T ( "addresslist")); int i = m_ctrlperson.GetSelectionMark (); CString strSQL; int id = atoi (m_ctrlperson.GetItemText (i, 0)); CPersonSet m_recordset; CDBVARIANT VARVALUE; if (i == - 1) {MessageBox ("Please select a record!", "Tips", MB_ok | MB_ICONIONFORMATION);} else {int temp = 0; strsql.format ("SELECT * FROM Person where id =% d ", id); m_recordset.open (AFX_DB_USE_DEFAULT_TYPE, STRSQL); m_recordset.getfieldValue (TEMP, VARVALUE); DLG.M_MODID = VARVALUE.M_LVAL;
M_RecordSet.GetfieldValue (1, VARVALUE); DLG.M_MODNAME = VARVALUE.M_PSTRING-> GetBuffer (1);
M_RecordSet.GetfieldValue (2, VARVALUE); DLG.M_MODSEX = VARVALUE.M_PSTRING-> GetBuffer (1);
m_recordset.GetFieldValue (3, varValue); dlg.m_modrelation = varValue.m_pstring-> GetBuffer (1); m_recordset.GetFieldValue (4, varValue); dlg.m_modtelephone = varValue.m_pstring-> GetBuffer (1);
M_recordset.getfieldValue (5, VARVALUE); DLG.M_ModHandphone = VARVALUE.M_PSTRINE-> GetBuffer (1);
M_Recordset.GetfieldValue (6, VARVALUE); DLG.M_MODDRESS = VARVALUE.M_PSTRING-> GetBuffer (1);
M_Recordset.GetfieldValue (7, VARVALUE); DLG.M_ModWorkPlace = varValue.m_pstring-> getBuffer (1);
M_RecordSet.GetfieldValue (8, VARVALUE); DLG.M_Modemail = VARVALUE.M_PSTRING-> GetBuffer (1);
m_recordset.getfieldValue (9, VARVALUE); DLG.M_MODOICQ = VARVALUE.M_PSTRING-> GetBuffer (1); //m_database.close() The following cannot disconnect DLG.Domodal (); refreshdata ( }}
Void cmaindlg :: RefreshData () {// First ensure the database opens if (! m_database.isopen ()) {m_database.Open (_t ("addresslist"));} // Turn the contents of the list control, empty the original content m_ctrlperson.DeleteAllItems (); // create a record set CPersonSet m_personset (& m_database); m_personset.Open (AFX_DB_USE_DEFAULT_TYPE, m_query); CDBVariant varValue; char buf [20]; // number of the current record to record int i = 0; / / If there is a record in the table, after opening the slam in the first bit, enabling the first record in the record set to the current record IF (m_personset.getRecordcount ()! = 0) m_PersonSet.MoveFirst (); while (! M_personset. ISEOF ()) {int Temp = 0; // Treatment M_PersonSet.GetfieldValue (Temp, Varvalue); Sprintf (BUF, "% D", Varvalue.m_lval); m_ctrlperson.insertItem (i, buf); // String display processing //m_PersonSet.GetfieldValue (0, varchue); //m_ctrlperson.setitemtext(i ,0, varchue.m_pstring->GetBuffer (1));
m_personset.getfieldValue (1, varvalue); M_CtrlPerson.SetItemText (i, 1, varvalue.m_pstring-> getBuffer (1)); /// The first parameter is a line, the second parameter represents the column, the third representation value m_personset.GetFieldValue (2, varValue); m_ctrlperson.SetItemText (i, 2, varValue.m_pstring-> GetBuffer (1)); m_personset.GetFieldValue (3, varValue); m_ctrlperson.SetItemText (i, 3, varValue.m_pstring- > GetBuffer (1));
M_PersonSet.GetfieldValue (4, VARVALUE); M_CTRLPERSON.SETITEMTEXT (i, 4, varvalue.m_pstring-> getBuffer (1));
M_PersonSet.GetfieldValue (5, VARVALUE); M_CTRLPERSON.SETITEMTEXT (I, 5, VARVALUE.M_PSTRING-> GetBuffer (1));
M_PersonSet.GetfieldValue (6, VARVALUE); M_CTRLPERSON.SETITEMTEXT (i, 6, varvalue.m_pstring-> getBuffer (1));
M_PersonSet.GetfieldValue (7, VARVALUE); M_CTRLPERSON.SETITEMTEXT (i, 7, varvalue.m_pstring-> getBuffer (1));
M_PersonSet.GetfieldValue (8, VARVALUE); M_CTRLPERSON.SETITEMTEXT (i, 8, varvalue.m_pstring-> getBuffer);
m_PersonSet.GetfieldValue (9, VARVALUE); M_CTRLPERSON.SETITEMTEXT (i, 9, varvalue.m_pstring-> getBuffer (1)); m_personset.movenext (); i ;} // Show a total record number in the title bar Int Counts = m_personset.getRecordCount (); cstring str; str.format ("Address Book V1.0 Trial Edition Current Document:% D", Counts; This-> SetWindowText (STR);}} Code in the modification dialog box ;
// modifydlg.cpp: importation file //
#include "stdafx.h" #include "address.h" #include "modifydlg.h" #include "personset.h" #include "marindlg.h"
#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF
/// cmodifydlg dialog
CMODIFYDLG :: CMODIFYDLG (CWND * pParent / * = null * /): cdialog (cdialog (cmodifydlg :: IDD, pParent) {// {{AFX_DATA_INIT (CMODIFYDLG) m_modname = _t ("); m_modsex = _t (" "); /// This indicates that the string is empty, can be written into m_modsex = ""; m_modtelephone = _t ("); m_mod.comPhone = _t ("); m_modaddress = _t ("); m_modworkplace = _t ("); m_modemail = _t ("); m_modoicq = _t ("); m_modid = 0; m_modrelation = _t ("); //}} AFX_DATA_INIT}
void CModifyDlg :: DoDataExchange (CDataExchange * pDX) {CDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CModifyDlg) DDX_Text (pDX, IDC_EDIT8, m_modid); DDX_Text (pDX, IDC_EDIT1, m_modname); DDX_CBString (pDX, IDC_COMBO1 , m_modsex); DDX_Text (pDX, IDC_EDIT9, m_modrelation); DDX_Text (pDX, IDC_EDIT2, m_modtelephone); DDX_Text (pDX, IDC_EDIT3, m_modhandphone); DDX_Text (pDX, IDC_EDIT4, m_modaddress); DDX_Text (pDX, IDC_EDIT5, m_modworkplace); DDX_Text (PDX, IDC_EDIT6, M_MODEMAIL); DDX_TEXT (PDX, IDC_EDit7, M_MODOICQ); //}} AFX_DATA_MAP}
BEGIN_MESSAGE_MAP (CModifyDlg, CDialog) // {{AFX_MSG_MAP (CModifyDlg) ON_BN_CLICKED (IDC_CLEAR_BUTTON, OnClearButton) //}} AFX_MSG_MAPEND_MESSAGE_MAP () /// CModifyDlg message handlersvoid CModifyDlg :: OnOK () {// TODO: Add extra validation here UpdateData ( True); CPERSONSET M_RECORDSET; // This is the entity CString strsql; cmaindlg dlg; if (! M_modname.isempty ()) {strsql.format ("Update Person Set Name = '% s', sex ='% s ', ReasonPhone ='% s', handphone = '% s', address ='% s', Workplace = '% s', Email ='% s', OICQ = '% s' where ID =% d ", m_modname, m_modsex, m_modrelation, m_modtelephone, m_modhandphone, m_modaddress, m_modworkplace, m_modemail, m_modoicq, m_modid); m_database.ExecuteSQL (strSQL); // cibu m_database.Close (); CDialog :: OnOK () } Else {MessageBox ("Name" item is not empty! "," Tips ", MB_OK | MB_ICONInformation);}}
Void cmodifydlg :: OnClearButton () {// Todo: add your control notification handler code hereiff ("Do you really want to empty?", "Tips", MB_YESNO | MB_ICONQUESTION == iDyes) {CEDIT * m_pmodid = CEdit *) GetDlgItem (IDC_EDIT8); // m_pmodid-> SetWindowText ( ""); //m_modname.Empty (); //m_modsex.Empty (); m_modrelation.Empty (); m_modtelephone.Empty (); m_modhandphone.Empty (); M_modaddress.empty (); m_modWorkplace.empty (); m_modoicq.empty (); Updatedata (false);}}
Void cmodifydlg :: oncancel () {// Todo: add extra cleanup here //m_database.close (); cdialog :: oncancel ();