Shopediterdlg. CPP {cfiledialog openfiledlg (true); openfiledlg. m_ofn.lpstrfilter = "Excel (*. XLS) \ 0 *. XLS \ 0 "; openfiledlg. m_ofn.lpstrdefext = "xls"; if (openfiledlg. domodal () = idok) {checkmodify (); If (! M_shop.importfromdb (openfiledlg. m_ofn.lpstrfile) {MessageBox ("failed to import file from Excel", "error"); return;} m_blstartmodify = false; m_nmodifiedtime = 0; setitemgroupnoitem (); displayshop (& m_shop ); cmenu * menu = getmenu (); If (menu) menu-> enablemenuitem (id_save, 4); MessageBox ("data imported from Excel is successful! "," OK ") ;}} void cshopediterdlg: checkmodify () {If (m_nmodifiedtime> 0) {If (MessageBox (" the data has been modified. Do you want to save it? "," Prompt ", mb_okcancel) = idok) {onsave () ;}} void cshopediterdlg: onsave () {char szpath [256] sprintf (szpath, "% s \ shopworking \ shopbase. dat ", m_szcurrdir); char szpathback [2, 256]; systemtime STM; getsystemtime (& sTM); sprintf (szpathack, "% s \ shopworking \ shopbase % d-% d _ % d. dat ", m_szcurrdir, STM. wmonth, STM. wday, STM. whour, STM. wminute); cfile: Rename (szpath, szpathback); m_shop.save (szpath); m_nmodifiedtime = 0;} shop. cppb OOl shops: importfromdb (const char * szfilename) {cstring sfile = szfilename; cstring sdriver = getexceldriver (); cdatabase dB; // create a string cstring sdsn; sdsn. format ("ODBC; driver ={% s}; readonly = falsen =''; DBQ = % s ", sdriver, sfile); If (dB, open (null, false, false, sdsn) {bool B = loadshopfromexcel (& dB); bool B = loaditemfromexcel (& dB); dB. close (); return B;} return false;} bool shops: loadshopfromexcel (cdat Abase * PDB) {crecordset recset (PDB); cstring ssql = "select * From shoplist"; if (! Recset. Open (crecordset: forwardonly, ssql, crecordest: readonly) return false; int ncnt = recset. getrecordcount (); m_pshoplist.resetcontent (); While (! Recset. iseof () {cstring szval; shopbase * pinfo = new shopbase; m_shoplist-> Add (pinfo); recset. getfiledvalue ("name", szval); pinfo-> setname (pinfo, szval );................ recset. movenext ();} return true;} bool shops: loaditemfromexcel (cdatabase * PDB) {crecordset recset (PDB); cstring ssql = "select * From itemlist"; if (! Recset. Open (crecordset: forwardonly, ssql, crecordest: readonly) return false; int ncnt = recset. getrecordcount (); While (! Recset. iseof () {cstring szval; shopitemdata * pitem = new shopitemdata; cstring btab; recset. getfieldvalue ("name", btab); shopbase * pbase = findtab (btab. getbuffer (); If (pbase = NULL) return true; If (pbase! = NULL) {pbase-> m_pitemlist-> Add (pitem);} recset. getfieldvalue ("Itemid", szval); pitem-> witemid = atoi (szval );.......... recset. movenext ();} void shopbase: setname (shopbase * pshop, const char * szstr) {If (pshop-> m_szname! = NULL) {free (pshop-> m_szname); pshop-> m_szname = NULL;} If (strlen (szstr)> 0) pshop-> m_szname = strdup (szstr ); elsepshop-> m_szname = strdup ("Untitled");}-itembase * shop: finditem (DWORD dwid) {_ itembase * base = NULL; For (INT I = 0; I <m_itembase-> count; I ++) {_ itembase * itembase = (_ itembase *) m_itembase-> items [I]; If (null = itembase) continue; if (itembase-> dwid = dwid) {base = itembase; break;} return base;} shopbase * shop: findtab (char * m_szname) {shopbase * base = NULL; For (INT I = 0; I <m_shoplist-> count; I ++) {shopbase * shopbase = (shopbase *) m_shoplist-> items [I]; If (null = shopbase) continue; If (strcmp (shopbase-> m_szname, m_szname) = 0) {base = shopbase; break;} return base ;}