main.cpp
上传用户:deyixm
上传日期:2007-01-06
资源大小:43k
文件大小:24k
源码类别:

行业应用

开发平台:

Visual C++

  1. //---------------------------------------------------------------------------
  2. // 学韬电子光盘册   版本: 1.0.2
  3. // 作者:颜承     时间:2000.1.17
  4. // 主要构件: TListView ,TTreeView ,TClientDataSet ,TList等
  5. // API函数: GetVolumeInformation,ShellExecute  GetDriveType GetLogicDriveStrings
  6. // 自定义类: TSerchDisk 递归方法搜索整个磁盘目录文件结构
  7. // 此为主窗口实现文件
  8. // 版本更新:v1.1.0  修改界面,支持右键,支持双击打开文件.
  9. //           v1.2.0  增加选项功能,增加输出html文件功能.
  10. //           v1.2.1  调整输出html方式,允许设置是否建立链接.
  11. //---------------------------------------------------------------------------
  12. // 版权所有(C)2000 颜 承
  13. // 这一程序是自由软件,
  14. // 你可以遵照自由软件基金会出版的GNU通用公共许可证条款来修改和重新发布这一程序。
  15. // 发布这一程序的目的是希望它有用,但没有任何担保。甚至没有适合特定目的的隐含的担保。
  16. // 更详细的情况请参阅GNU通用公共许可证。
  17. // 你应该已经和程序一起收到一份GNU通用公共许可证的副本。
  18. // 我的联系方式:桂林集琦药业股份有限公司技术部(541004)
  19. // E-Mail: ycshowtop@sohu.com
  20. //-------------------------------------------------------------------------------
  21. #include <vcl.h>
  22. #include <stdio.h>
  23. #include <winuser.h>
  24. #include <shellapi.h>
  25. #include <vclregistry.hpp>
  26. #pragma hdrstop
  27. #include "main.h"
  28. #include "about.h"
  29. #include "CDAdd.h"
  30. #include "SFAdd.h"
  31. #include "CDFind.h"
  32. #include "ModiSF.h"
  33. #include "config.h"
  34. #include "Progressbar.h"
  35. //---------------------------------------------------------------------------
  36. #pragma package(smart_init)
  37. #pragma resource "*.dfm"
  38. TForm1 *Form1;
  39. extern AnsiString TheCDSeriNo; //光盘序列号
  40. AnsiString TheSoft;      //查找的软件名
  41. typedef struct AList {    //查找软件结果列表
  42.     AnsiString cdName;
  43.     AnsiString swName;
  44.  }TAList;
  45. typedef TAList* PAList;
  46. int curNum;   //已找到的软件个数
  47. extern AnsiString cdbname;
  48. //---------------------------------------------------------------------------
  49. __fastcall TForm1::TForm1(TComponent* Owner)
  50.         : TForm(Owner)
  51. {
  52. TheSoft="";
  53. curNum=0;
  54. pList=new TList();
  55. }
  56. //---------------------------------------------------------------------------
  57. //显示关于窗口
  58. void __fastcall TForm1::itemAboutExecute(TObject *Sender)
  59. {
  60.  AboutBox = new TAboutBox(this);
  61.  AboutBox->ShowModal();
  62.  delete AboutBox;
  63. }
  64. //---------------------------------------------------------------------------
  65. //关闭程序
  66. void __fastcall TForm1::itemExtExecute(TObject *Sender)
  67. {
  68.  Close();
  69. }
  70. //---------------------------------------------------------------------------
  71. //添加光盘记录
  72. void __fastcall TForm1::itemAddCDExecute(TObject *Sender)
  73. {
  74.  Form3->Show();
  75. }
  76. //---------------------------------------------------------------------------
  77. //添加软件记录
  78. void __fastcall TForm1::itemAddSoftExecute(TObject *Sender)
  79. {
  80.  Form4->Show();
  81. }
  82. //---------------------------------------------------------------------------
  83. //创建窗口
  84. void __fastcall TForm1::FormCreate(TObject *Sender)
  85. {
  86. //打开程序的提示功能,使之指向ShowHint函数
  87.  Application->OnHint=&ShowHint;
  88.  //在本程序目录中是否存在ini文件,如无则建立.
  89.  AnsiString tmp;
  90.  tmp=ExtractFileDir(Application->ExeName); //取应用程序所在目录
  91.  tmp=tmp+AnsiString("\cdpack.ini");
  92.  if(!FileExists(tmp)) {
  93.     TMemIniFile * Reg=new TMemIniFile(tmp);
  94.     Reg->WriteInteger("Common","FilterCount",3);
  95.     Reg->WriteBool("Common","FileBind",false);
  96.     Reg->WriteBool("Common","HtmlLink",false);
  97.     Reg->WriteString("Filter","item0","exe");
  98.     Reg->WriteString("Filter","item1","zip");
  99.     Reg->WriteString("Filter","item2","rar");
  100.     Reg->UpdateFile();
  101.     delete Reg;
  102.  }
  103. }
  104. //---------------------------------------------------------------------------
  105. //在状态栏上显示提示
  106. void __fastcall TForm1::ShowHint(TObject * Sender)
  107. {
  108.  StatusBar1->Panels->Items[0]->Text=Application->Hint;
  109. }
  110. //--------------------------------------------------------------------------
  111. //检索光盘
  112. void __fastcall TForm1::itemFindCDExecute(TObject *Sender)
  113. {
  114.  Form5->Show();
  115. }
  116. //---------------------------------------------------------------------------
  117. //查找软件
  118. void __fastcall TForm1::itemFindSoftExecute(TObject *Sender)
  119. {
  120.  TheSoft=InputBox("查找软件","请输入要查找的软件名称:","");
  121.  if(TheSoft==""){ //如果没给出软件名,则返回
  122.   itemFindNext->Enabled=false;
  123.   return;
  124.  }
  125.  //关闭软件数据库的过滤器
  126.  ClientDataSet2->Filtered=false;
  127.  PAList pItem;
  128.  TheSoft=TheSoft.LowerCase(); //处理软件名为小写
  129.  ClientDataSet2->First();
  130.  pList->Clear();
  131.  curNum=0;
  132.  while(!ClientDataSet2->Eof) {
  133.        //查找,如果找到把CDSeriNo,SWName 加入pList中
  134.        if(ClientDataSet2->FieldByName("SWName")->AsString.LowerCase().AnsiPos(TheSoft)!=0) {
  135.           pItem = new TAList;
  136.           pItem->swName=ClientDataSet2->FieldValues["SWName"];
  137.           pItem->cdName=ClientDataSet2->FieldValues["CDSeriNo"];
  138.           pList->Add(pItem);
  139.        }
  140.        ClientDataSet2->Next();   //下一条
  141.   }
  142.  int m=pList->Count;
  143.  if(m==0) {          //如果没有找到任何一个软件
  144.    Application->MessageBox("没有相匹配的软件!","提示",MB_OK);
  145.    itemFindNext->Enabled=false;
  146.    return;
  147.  }
  148.  int i;
  149.  PAList temp;
  150.  ClientDataSet1->First();
  151.  while(!ClientDataSet1->Eof) {
  152.     //把pList中的CDSeriNo值换成 CDName
  153.     for(i=0;i<m;i++) {
  154.        temp=(PAList)pList->Items[i];
  155.        if(temp->cdName == ClientDataSet1->FieldByName("CDSeriNo")->AsString ) {
  156.           temp->cdName = ClientDataSet1->FieldByName("CDName")->AsString;
  157.           break;
  158.        }
  159.     }
  160.     ClientDataSet1->Next();
  161.  }
  162.  //在TreeView 中找到相应的光盘名,将其选择,允许查找下一个
  163.  TTreeNode * myNode=TreeView1->Items->Item[1];
  164.  while(myNode!=NULL) {
  165.    temp=(PAList)pList->Items[0];
  166.    if(myNode->Text==temp->cdName ) break;
  167.    myNode=myNode->GetNext();
  168.  }
  169.  if(myNode!=NULL) TreeView1->Selected=myNode;
  170.  if(m>1) itemFindNext->Enabled=true;
  171.  //在ListView中找到相应的软件名,将其选择,
  172.  ListView1->SetFocus();
  173.  ListView1->Selected=NULL;
  174.  for(i=0;i<ListView1->Items->Count;i++) {
  175.    temp=(PAList)pList->Items[0];
  176.    if(ListView1->Items->Item[i]->Caption==temp->swName){
  177.       ListView1->Selected=ListView1->Items->Item[i];
  178.       break;
  179.    }
  180.  }
  181.  //以下几句保证选择项一定在窗口中显示.
  182.  i=ListView1->Items->IndexOf(ListView1->Selected);
  183.  int j=i-ListView1->Items->IndexOf(ListView1->TopItem);
  184.  i=ListView1->ClientHeight/ListView1->VisibleRowCount;
  185.  if(j>ListView1->VisibleRowCount) ListView1->Scroll(0,i*j);
  186. }
  187. //---------------------------------------------------------------------------
  188. //新建数据库
  189. void __fastcall TForm1::itemNewExecute(TObject *Sender)
  190. {
  191.  OpenDialog1->Title="新建";
  192.  AnsiString temp;
  193.  if(OpenDialog1->Execute()) {
  194.      if(ClientDataSet1->Active==true) {
  195.          ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
  196.          ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
  197.      }
  198.      //处理文件名, 确保先关闭ClientDataSet
  199.      temp=OpenDialog1->FileName;
  200.      if(temp.AnsiPos(".cdb")==0) temp=temp+AnsiString(".cdb");
  201.      ClientDataSet1->Active=false;
  202.      ClientDataSet1->FileName=temp;
  203.      int k=temp.Length()-4;
  204.      temp=temp.SubString(1,k)+AnsiString(".dat");
  205.      ClientDataSet2->Active=false;
  206.      ClientDataSet2->FileName=temp;
  207.      ClientDataSet1->FieldDefs->Clear();      //建立数据库结构
  208.      ClientDataSet1->FieldDefs->Add("CDName",ftString,64,true);
  209.      ClientDataSet1->FieldDefs->Add("CDNumber",ftString,8,true);
  210.      ClientDataSet1->FieldDefs->Add("CDSeriNo",ftString,32,true);
  211.      ClientDataSet1->CreateDataSet();   //建立新表
  212.      ClientDataSet2->FieldDefs->Clear();      //建立数据库结构
  213.      ClientDataSet2->FieldDefs->Add("CDSeriNo",ftString,32,true);
  214.      ClientDataSet2->FieldDefs->Add("SWName",ftString,64,true);
  215.      ClientDataSet2->FieldDefs->Add("SWDirFile",ftString,128,true);
  216.      ClientDataSet2->FieldDefs->Add("SWDescription",ftString,256,true);
  217.      ClientDataSet2->CreateDataSet();   //建立新表
  218.      ClientDataSet1->Active=true;      //打开数据库
  219.      ClientDataSet2->Active=true;
  220.      //清空TreeView ,ListView
  221.      TreeView1->Items->Item[0]->DeleteChildren();
  222.      ListView1->Items->BeginUpdate();
  223.      ListView1->Items->Clear();
  224.      ListView1->Items->EndUpdate();
  225.      StatusBar1->Panels->Items[2]->Text="";
  226.      //打开一些相关按钮
  227.      itemAddCD->Enabled=true;
  228.      itemSave->Enabled=true;
  229.      itemOutput->Enabled=true;
  230.      itemDelCD->Enabled=false;
  231.      itemAddSoft->Enabled=false;
  232.      itemDelSoft->Enabled=false;
  233.      itemFindCD->Enabled=false;
  234.      itemFindSoft->Enabled=false;
  235.      Form1->Caption=AnsiString("学韬电子光盘册 - ")+ OpenDialog1->FileName;
  236.  }
  237. }
  238. //---------------------------------------------------------------------------
  239. //打开数据库
  240. void __fastcall TForm1::itemOpenExecute(TObject *Sender)
  241. {
  242.  OpenDialog1->Title="打开";
  243.  if(OpenDialog1->Execute())
  244.      OpenCDBFile(OpenDialog1->FileName);
  245. }
  246. //---------------------------------------------------------------------------
  247. //重画窗口时改变状态条中光盘编号项的位置
  248. void __fastcall TForm1::FormPaint(TObject *Sender)
  249. {
  250.  StatusBar1->Panels->Items[0]->Width=Form1->Width-192;
  251.  StatusBar1->Panels->Items[1]->Width=64;
  252.  StatusBar1->Panels->Items[2]->Width=128;
  253. }
  254. //---------------------------------------------------------------------------
  255. //TreeView改变
  256. void __fastcall TForm1::TreeView1Change(TObject *Sender, TTreeNode *Node)
  257. {
  258.  ListView1->Items->BeginUpdate(); // 清空ListView
  259.  ListView1->Items->Clear();
  260.  ListView1->Items->EndUpdate();
  261.  //如果不是选择根结点,才进行以下操作
  262.  if(TreeView1->Selected!=TreeView1->Items->Item[0]) {
  263.     itemAddSoft->Enabled=true;      //打开两个按钮
  264.     itemDelCD->Enabled=true;
  265.     //定位在所选光盘的记录上,显示光盘编号
  266.     TLocateOptions op;
  267.     op.Clear();
  268.     op<<loCaseInsensitive;
  269.     ClientDataSet1->Locate("CDName",Node->Text,op);
  270.     TheCDSeriNo=ClientDataSet1->FieldValues["CDSeriNo"];
  271.     StatusBar1->Panels->Items[2]->Text=ClientDataSet1->FieldValues["CDNumber"];
  272.     //根据所选光盘序列号,在软件库设置过滤器
  273.     if(ClientDataSet2->Filtered==true) ClientDataSet2->Filtered=false;
  274.     ClientDataSet2->Filter="CDSeriNo="+TheCDSeriNo;
  275.     ClientDataSet2->Filtered=true;
  276.     ClientDataSet2->First();
  277.     TListItem * ListItem;
  278.     //把相应此光盘的软件加入ListView中
  279.     while(!ClientDataSet2->Eof) {
  280.       ListItem = ListView1->Items->Add();
  281.       ListItem->Caption=ClientDataSet2->FieldByName("SWName")->AsString;
  282.       ListItem->SubItems->Add(ClientDataSet2->FieldByName("SWDirFile")->AsString);
  283.       ListItem->SubItems->Add(ClientDataSet2->FieldByName("SWDescription")->AsString);
  284.       ClientDataSet2->Next();
  285.     }
  286.  }
  287.  else { //如果选择是根结点项,关闭相关按钮,不显示编号
  288.     itemAddSoft->Enabled=false;
  289.     itemDelCD->Enabled=false;
  290.     StatusBar1->Panels->Items[2]->Text="";
  291.  }
  292. }
  293. //---------------------------------------------------------------------------
  294. //删除光盘
  295. void __fastcall TForm1::itemDelCDExecute(TObject *Sender)
  296. {
  297.  ClientDataSet1->First();
  298.  TLocateOptions op;
  299.  op.Clear();
  300.  op<<loCaseInsensitive;
  301.  //定位在所选择的光盘上
  302.  ClientDataSet1->Locate("CDName",TreeView1->Selected->Text,op);
  303.  TheCDSeriNo=ClientDataSet1->FieldValues["CDSeriNo"];
  304.  //确认是否删除
  305.  AnsiString temp= ClientDataSet1->FieldValues["CDName"];
  306.  temp=AnsiString("是否删除光盘 ")+temp+AnsiString(" 及它所包括的所有软件记录?");
  307.  int res = MessageDlg(temp,mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0);
  308.  if(res==mrYes) { //删除此光盘记录及软件库中与其相关的软件
  309.    if(ClientDataSet2->Filtered==true) ClientDataSet2->Filtered=false;
  310.    ClientDataSet2->Filter="CDSeriNo="+TheCDSeriNo;
  311.    ClientDataSet2->Filtered=true;                 //设置过滤器
  312.    ClientDataSet2->First();
  313.    while(!ClientDataSet2->Eof) ClientDataSet2->Delete(); //全是与光盘有关的记录
  314.    ClientDataSet1->Delete();
  315.    TreeView1->Selected->Delete();    //在TreeView中删除相应项
  316.    TreeView1->Selected=TreeView1->Items->Item[0];
  317.  }
  318.  if(ClientDataSet1->RecordCount==0) {
  319.     itemFindCD->Enabled=false;
  320.     itemFindSoft->Enabled=false;
  321.  }
  322. }
  323. //---------------------------------------------------------------------------
  324. //删除软件
  325. void __fastcall TForm1::itemDelSoftExecute(TObject *Sender)
  326. {
  327.     ClientDataSet2->First();
  328.     TLocateOptions op;
  329.     op.Clear();
  330.     op<<loCaseInsensitive;
  331.     int i;
  332.     ListView1->Items->BeginUpdate();
  333.     //只要选择的项目数不为空,一个个删除数据库中的相应软件和ListView中相应项目
  334.     while(ListView1->Selected!=NULL) {
  335.        ClientDataSet2->Locate("SWName",ListView1->Selected->Caption,op);
  336.        ClientDataSet2->Delete();
  337.        i=ListView1->Items->IndexOf(ListView1->Selected);
  338.        ListView1->Items->Delete(i);
  339.     }
  340.     ListView1->Items->EndUpdate();
  341.     ListView1->Selected=ListView1->ItemFocused;
  342.     if(ClientDataSet2->RecordCount==0) itemFindSoft->Enabled=false;
  343. }
  344. //---------------------------------------------------------------------------
  345. //ListView改变选择项目时,同时改变两个按钮状态
  346. void __fastcall TForm1::ListView1Change(TObject *Sender, TListItem *Item,
  347.       TItemChange Change)
  348. {
  349.  if(ListView1->Selected!=NULL){
  350.    itemDelSoft->Enabled=true;
  351.    pmModiSF->Enabled=true;
  352.  }
  353.  else{
  354.    itemDelSoft->Enabled=false;
  355.    pmModiSF->Enabled=false;
  356.  }
  357. }
  358. //---------------------------------------------------------------------------
  359. //以下两个函数对Del按键产生反应.
  360. void __fastcall TForm1::TreeView1KeyDown(TObject *Sender, WORD &Key,
  361.       TShiftState Shift)
  362. {
  363.     if( Key==VK_DELETE && itemDelCD->Enabled==true && !(TreeView1->IsEditing()) )
  364.     itemDelCDExecute(Sender);
  365. }
  366. //---------------------------------------------------------------------------
  367. void __fastcall TForm1::ListView1KeyDown(TObject *Sender, WORD &Key,
  368.       TShiftState Shift)
  369. {
  370.     if( Key==VK_DELETE && itemDelSoft->Enabled==true  )
  371.        itemDelSoftExecute(Sender);
  372.     if( Key==VK_RETURN && ListView1->Selected!=NULL)
  373.        ListView1DblClick(Sender);
  374. }
  375. //---------------------------------------------------------------------------
  376. //光盘改名,如果为空则取消改变
  377. void __fastcall TForm1::TreeView1Edited(TObject *Sender, TTreeNode *Node,
  378.       AnsiString &S)
  379. {
  380.  if(S=="") S=Node->Text;
  381.  else {
  382.    ClientDataSet1->Edit();
  383.    ClientDataSet1->FieldByName("CDName")->AsString=S;
  384.    ClientDataSet1->Post();
  385.    ClientDataSet1->MergeChangeLog();
  386.  }
  387. }
  388. //---------------------------------------------------------------------------
  389. //不允许改变根结点项的名字
  390. void __fastcall TForm1::TreeView1Editing(TObject *Sender, TTreeNode *Node,
  391.       bool &AllowEdit)
  392. {
  393.  if(Node->Level==0) AllowEdit=false;
  394. }
  395. //---------------------------------------------------------------------------
  396. //查找下一个软件
  397. void __fastcall TForm1::itemFindNextExecute(TObject *Sender)
  398. {
  399.  curNum++; //已找到的软件数加一,如果找完则关闭下一个按钮
  400.  if(curNum >= pList->Count) {
  401.    itemFindNext->Enabled=false;
  402.    curNum=0;
  403.    return;
  404.  }
  405.  //在TreeView中找到要查找软件对应光盘,选择
  406.  PAList temp;
  407.  TTreeNode * myNode=TreeView1->Items->Item[1];
  408.  while(myNode!=NULL) {
  409.    temp=(PAList)pList->Items[curNum];
  410.    if(myNode->Text==temp->cdName ) break;
  411.    myNode=myNode->GetNext();
  412.  }
  413.  if(myNode!=NULL) TreeView1->Selected=myNode;
  414.  int i;
  415.  ListView1->SetFocus();
  416.  ListView1->Selected=NULL; //取消前一个选择
  417.  for(i=0;i<ListView1->Items->Count;i++) {  //找到下一个相应软件,选择
  418.    temp=(PAList)pList->Items[curNum];
  419.    if(ListView1->Items->Item[i]->Caption==temp->swName){
  420.       ListView1->Selected=ListView1->Items->Item[i];
  421.       break;
  422.    }
  423.  }
  424.  //以下确保选择项被显示
  425.  i=ListView1->Items->IndexOf(ListView1->Selected);
  426.  int j=i-ListView1->Items->IndexOf(ListView1->TopItem);
  427.  i=ListView1->ClientHeight/ListView1->VisibleRowCount;
  428.  if(j>ListView1->VisibleRowCount) ListView1->Scroll(0,i*j);
  429. }
  430. //---------------------------------------------------------------------------
  431. //修改软件名称属性
  432. void __fastcall TForm1::pmModiSFClick(TObject *Sender)
  433. {
  434.  Form2->Show();
  435. }
  436. //---------------------------------------------------------------------------
  437. //执行软件
  438. void __fastcall TForm1::ListView1DblClick(TObject *Sender)
  439. {
  440.  if(ListView1->Selected!=NULL) {
  441.    int k= ListView1->Selected->SubItems->Strings[1].AnsiPos("!");
  442.    if(k!=0) {
  443.      AnsiString temp=ListView1->Selected->SubItems->Strings[1];
  444.      temp=temp.SubString(k,temp.Length()-k+1);
  445.      int res=MessageDlg(temp+"  是否继续执行?",mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0);
  446.      if(res==mrNo) return;
  447.    }
  448.    ShellExecute(Form1->Handle,"open",ListView1->Selected->SubItems->Strings[0].c_str(),NULL,NULL,SW_SHOWNORMAL);
  449.  }
  450. }
  451. //---------------------------------------------------------------------------
  452. //修改光盘编号
  453. void __fastcall TForm1::StatusBar1DblClick(TObject *Sender)
  454. {
  455.  if(StatusBar1->Panels->Items[2]->Text=="") return;
  456.  AnsiString temp1 = ClientDataSet1->FieldByName("CDNumber")->AsString;
  457.  AnsiString temp2 =InputBox("修改光盘编号","请输入新的光盘编号:",temp1);
  458.  if(temp2!=temp1) {
  459.    ClientDataSet1->Edit();
  460.    ClientDataSet1->FieldByName("CDNumber")->AsString=temp2;
  461.    ClientDataSet1->Post();
  462.    ClientDataSet1->MergeChangeLog();
  463.  }
  464.  StatusBar1->Panels->Items[2]->Text=ClientDataSet1->FieldValues["CDNumber"];
  465. }
  466. //---------------------------------------------------------------------------
  467. //关闭程序,保存文件消除对象
  468. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  469. {
  470.  pList->Clear();
  471.  delete pList;
  472.  if(ClientDataSet1->Active==true) {
  473.     ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
  474.     ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
  475.     ClientDataSet1->Active=false;
  476.     ClientDataSet2->Active=false;
  477.  }
  478. }
  479. //---------------------------------------------------------------------------
  480. //打开数据库文件
  481. void __fastcall TForm1::OpenCDBFile(AnsiString filename)
  482. {
  483.      AnsiString temp=filename;
  484.        //处理文件名,确保关闭了ClientDataSet
  485.      if(ClientDataSet1->Active==true) {
  486.          ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
  487.          ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
  488.      }
  489.      if(temp.AnsiPos(".cdb")==0) temp=temp+AnsiString(".cdb");
  490.      ClientDataSet1->Active=false;
  491.      ClientDataSet1->FileName=temp;
  492.      int k=temp.Length()-4;
  493.      temp=temp.SubString(1,k)+AnsiString(".dat");
  494.      ClientDataSet2->Active=false;
  495.      ClientDataSet2->FileName=temp;
  496.      ClientDataSet1->Active=true;   //打开
  497.      ClientDataSet2->Active=true;
  498.      //清空ListView TreeView
  499.      TreeView1->Items->Item[0]->DeleteChildren();
  500.      ListView1->Items->BeginUpdate();
  501.      ListView1->Items->Clear();
  502.      ListView1->Items->EndUpdate();
  503.      StatusBar1->Panels->Items[2]->Text="";
  504.      //将数据库中记录加入TreeView中
  505.      k=ClientDataSet1->RecordCount;
  506.      int i;
  507.      ClientDataSet1->First();
  508.      TTreeNode * tmpNode = TreeView1->Items->Item[0];
  509.      for(i=0;i<k;i++) {
  510.         TreeView1->Items->AddChild(tmpNode,ClientDataSet1->FieldByName("CDName")->AsString);
  511.         TreeView1->Items->Item[i+1]->ImageIndex=1;
  512.         TreeView1->Items->Item[i+1]->SelectedIndex=0;
  513.         ClientDataSet1->Next();
  514.      }
  515.      //打开一些相关按钮
  516.      itemAddCD->Enabled=true;
  517.      itemSave->Enabled=true;
  518.      itemOutput->Enabled=true;
  519.      itemDelCD->Enabled=false;
  520.      itemAddSoft->Enabled=false;
  521.      itemDelSoft->Enabled=false;
  522.      if(ClientDataSet1->RecordCount!=0) itemFindCD->Enabled=true;
  523.      else itemFindCD->Enabled=false;
  524.      if(ClientDataSet2->RecordCount!=0)itemFindSoft->Enabled=true;
  525.      else itemFindSoft->Enabled=false;
  526.      Form1->Caption=AnsiString("学韬电子光盘册 - ")+filename;
  527. }
  528. //--------------------------------------------------------------------------
  529. //以命令行参数打开数据库
  530. void __fastcall TForm1::FormShow(TObject *Sender)
  531. {
  532.  if(cdbname!="")
  533.     OpenCDBFile(cdbname);
  534. }
  535. //---------------------------------------------------------------------------
  536. //保存文件
  537. void __fastcall TForm1::itemSaveExecute(TObject *Sender)
  538. {
  539.  if(ClientDataSet1->Active==true) {
  540.     ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
  541.     ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
  542.  }
  543. }
  544. //---------------------------------------------------------------------------
  545. //设置参数
  546. void __fastcall TForm1::itemConfigExecute(TObject *Sender)
  547. {
  548.  Form6->Show();
  549. }
  550. //---------------------------------------------------------------------------
  551. //输出HTML
  552. void __fastcall TForm1::itemOutputExecute(TObject *Sender)
  553. {
  554.  AnsiString tmp;
  555.  tmp=ExtractFileDir(Application->ExeName); //取应用程序所在目录
  556.  tmp=tmp+AnsiString("\cdpack.ini");
  557.  TMemIniFile * Reg=new TMemIniFile(tmp);
  558.  bool bLink=Reg->ReadBool("Common","HtmlLink",false); //是否要在HTML文件中设置链接
  559.  Form7->Show();
  560.  OutputHTML(Sender,bLink);
  561.  Form7->Close();
  562.  delete Reg;
  563. }
  564. //---------------------------------------------------------------------------
  565. //写HTML文件
  566. void __fastcall TForm1::OutputHTML(TObject * Sender, bool isLink)
  567. {
  568.  int i,k;
  569.  AnsiString tmp,temp,tempNo;
  570.  tmp=ExtractFileName(ClientDataSet1->FileName);
  571.  k=tmp.Length()-4;
  572.  tmp=tmp.SubString(1,k);
  573.  FILE * fp;
  574.  temp=tmp+AnsiString(".htm");
  575.  fp=fopen(temp.c_str(),"w");
  576.  if(fp==NULL){
  577.    Application->MessageBox("不能创建文件!","错误",MB_OK);
  578.    return;
  579.  }
  580.  fprintf(fp,"<html>");
  581.  fprintf(fp,"<head>");
  582.  fprintf(fp,"<meta http-equiv="Content-Type" content="text/html; charset=gb2312">");
  583.  temp= AnsiString("<title>")+tmp+AnsiString("</title>");
  584.  fprintf(fp,"%s",temp.c_str());
  585.  fprintf(fp,"</head>");
  586.  fprintf(fp,"<body>");
  587.  fprintf(fp,"<p align="center"><strong><font face="幼圆" size="3" color="#FF8000">索引</font> </strong></p>");
  588.  fprintf(fp,"<table border="1" width="80%">");
  589.  fprintf(fp,"<tr><th width="20%">编号</th><th width="80%">光盘名称</th></tr>");
  590.  ClientDataSet1->First();
  591.  k=ClientDataSet1->RecordCount;
  592.  Form7->ProgressBar1->Max=2*k;
  593.  Form7->ProgressBar1->Position=1;
  594.  for(i=0;i<k;i++) {
  595.     fprintf(fp,"<tr>");
  596.     temp=AnsiString("<td width="20%">") +
  597.          ClientDataSet1->FieldByName("CDNumber")->AsString +
  598.          AnsiString("</td>");
  599.     fprintf(fp,"%s",temp.c_str());
  600.     temp=AnsiString("<td width="80%"><a href="./Content/") +
  601.          ClientDataSet1->FieldByName("CDName")->AsString +
  602.          AnsiString(".htm">") + ClientDataSet1->FieldByName("CDName")->AsString +
  603.          AnsiString("</a></td>");
  604.     fprintf(fp,"%s",temp.c_str());
  605.     fprintf(fp,"</tr>");
  606.     Form7->ProgressBar1->StepIt();
  607.     ClientDataSet1->Next();
  608.  }
  609.  fprintf(fp,"</table>");
  610.  fprintf(fp,"</body>");
  611.  fprintf(fp,"</html>");
  612.  fclose(fp);
  613.  fp=NULL;
  614.  CreateDir("Content");
  615.  Form7->ProgressBar1->Position=k;
  616.  ClientDataSet1->First();
  617.  for(i=0;i<k;i++) {
  618.    tmp=ClientDataSet1->FieldByName("CDName")->AsString;
  619.    temp=GetCurrentDir()+AnsiString("\Content\")+tmp+AnsiString(".htm");
  620.    fp=fopen(temp.c_str(),"w");
  621.    if(fp==NULL) {
  622.      Application->MessageBox("不能创建文件!","错误",MB_OK);
  623.      return;
  624.    }
  625.    fprintf(fp,"<html>");
  626.    fprintf(fp,"<head>");
  627.    fprintf(fp,"<meta http-equiv="Content-Type" content="text/html; charset=gb2312">");
  628.    temp= AnsiString("<title>")+tmp+AnsiString("</title>");
  629.    fprintf(fp,"%s",temp.c_str());
  630.    fprintf(fp,"</head>");
  631.    fprintf(fp,"<body>");
  632.    temp=AnsiString("<p align="center"><strong><font face="幼圆" size="3" color="#FF8000">") +
  633.        tmp + AnsiString("</font> </strong></p>");
  634.    fprintf(fp,"%s",temp.c_str());
  635.    fprintf(fp,"<p></p>");
  636.    //根据所选光盘序列号,在软件库设置过滤器
  637.    tempNo=ClientDataSet1->FieldByName("CDSeriNo")->AsString;
  638.    if(ClientDataSet2->Filtered==true) ClientDataSet2->Filtered=false;
  639.    ClientDataSet2->Filter="CDSeriNo="+tempNo;
  640.    ClientDataSet2->Filtered=true;
  641.    ClientDataSet2->First();
  642.    while(!ClientDataSet2->Eof) {
  643.      if(isLink==true)
  644.           temp=AnsiString("<p><strong>软件名称:</strong><a href="") +
  645.                ClientDataSet2->FieldByName("SWDirFile")->AsString +
  646.                AnsiString("">")+ ClientDataSet2->FieldByName("SWName")->AsString +
  647.                AnsiString("</a><br>");
  648.      else temp=AnsiString("<p><strong>软件名称:</strong>") +
  649.                ClientDataSet2->FieldByName("SWName")->AsString +
  650.                AnsiString("<br>");
  651.      fprintf(fp,"%s",temp.c_str());
  652.      temp=AnsiString("<strong>软件说明:</strong>") +
  653.           ClientDataSet2->FieldByName("SWDescription")->AsString +
  654.           AnsiString("</p>");
  655.      fprintf(fp,"%s",temp.c_str());
  656.      fprintf(fp,"<hr>");
  657.      ClientDataSet2->Next();
  658.     }
  659.     fprintf(fp,"</body>");
  660.     fprintf(fp,"</html>");
  661.     Form7->ProgressBar1->StepIt();
  662.     fclose(fp);
  663.     fp=NULL;
  664.     ClientDataSet1->Next();
  665.  }
  666. }