main.cpp
资源名称:cd_man.zip [点击查看]
上传用户:deyixm
上传日期:2007-01-06
资源大小:43k
文件大小:24k
源码类别:
行业应用
开发平台:
Visual C++
- //---------------------------------------------------------------------------
- // 学韬电子光盘册 版本: 1.0.2
- // 作者:颜承 时间:2000.1.17
- // 主要构件: TListView ,TTreeView ,TClientDataSet ,TList等
- // API函数: GetVolumeInformation,ShellExecute GetDriveType GetLogicDriveStrings
- // 自定义类: TSerchDisk 递归方法搜索整个磁盘目录文件结构
- // 此为主窗口实现文件
- // 版本更新:v1.1.0 修改界面,支持右键,支持双击打开文件.
- // v1.2.0 增加选项功能,增加输出html文件功能.
- // v1.2.1 调整输出html方式,允许设置是否建立链接.
- //---------------------------------------------------------------------------
- // 版权所有(C)2000 颜 承
- // 这一程序是自由软件,
- // 你可以遵照自由软件基金会出版的GNU通用公共许可证条款来修改和重新发布这一程序。
- // 发布这一程序的目的是希望它有用,但没有任何担保。甚至没有适合特定目的的隐含的担保。
- // 更详细的情况请参阅GNU通用公共许可证。
- // 你应该已经和程序一起收到一份GNU通用公共许可证的副本。
- // 我的联系方式:桂林集琦药业股份有限公司技术部(541004)
- // E-Mail: ycshowtop@sohu.com
- //-------------------------------------------------------------------------------
- #include <vcl.h>
- #include <stdio.h>
- #include <winuser.h>
- #include <shellapi.h>
- #include <vclregistry.hpp>
- #pragma hdrstop
- #include "main.h"
- #include "about.h"
- #include "CDAdd.h"
- #include "SFAdd.h"
- #include "CDFind.h"
- #include "ModiSF.h"
- #include "config.h"
- #include "Progressbar.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- extern AnsiString TheCDSeriNo; //光盘序列号
- AnsiString TheSoft; //查找的软件名
- typedef struct AList { //查找软件结果列表
- AnsiString cdName;
- AnsiString swName;
- }TAList;
- typedef TAList* PAList;
- int curNum; //已找到的软件个数
- extern AnsiString cdbname;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- TheSoft="";
- curNum=0;
- pList=new TList();
- }
- //---------------------------------------------------------------------------
- //显示关于窗口
- void __fastcall TForm1::itemAboutExecute(TObject *Sender)
- {
- AboutBox = new TAboutBox(this);
- AboutBox->ShowModal();
- delete AboutBox;
- }
- //---------------------------------------------------------------------------
- //关闭程序
- void __fastcall TForm1::itemExtExecute(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- //添加光盘记录
- void __fastcall TForm1::itemAddCDExecute(TObject *Sender)
- {
- Form3->Show();
- }
- //---------------------------------------------------------------------------
- //添加软件记录
- void __fastcall TForm1::itemAddSoftExecute(TObject *Sender)
- {
- Form4->Show();
- }
- //---------------------------------------------------------------------------
- //创建窗口
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- //打开程序的提示功能,使之指向ShowHint函数
- Application->OnHint=&ShowHint;
- //在本程序目录中是否存在ini文件,如无则建立.
- AnsiString tmp;
- tmp=ExtractFileDir(Application->ExeName); //取应用程序所在目录
- tmp=tmp+AnsiString("\cdpack.ini");
- if(!FileExists(tmp)) {
- TMemIniFile * Reg=new TMemIniFile(tmp);
- Reg->WriteInteger("Common","FilterCount",3);
- Reg->WriteBool("Common","FileBind",false);
- Reg->WriteBool("Common","HtmlLink",false);
- Reg->WriteString("Filter","item0","exe");
- Reg->WriteString("Filter","item1","zip");
- Reg->WriteString("Filter","item2","rar");
- Reg->UpdateFile();
- delete Reg;
- }
- }
- //---------------------------------------------------------------------------
- //在状态栏上显示提示
- void __fastcall TForm1::ShowHint(TObject * Sender)
- {
- StatusBar1->Panels->Items[0]->Text=Application->Hint;
- }
- //--------------------------------------------------------------------------
- //检索光盘
- void __fastcall TForm1::itemFindCDExecute(TObject *Sender)
- {
- Form5->Show();
- }
- //---------------------------------------------------------------------------
- //查找软件
- void __fastcall TForm1::itemFindSoftExecute(TObject *Sender)
- {
- TheSoft=InputBox("查找软件","请输入要查找的软件名称:","");
- if(TheSoft==""){ //如果没给出软件名,则返回
- itemFindNext->Enabled=false;
- return;
- }
- //关闭软件数据库的过滤器
- ClientDataSet2->Filtered=false;
- PAList pItem;
- TheSoft=TheSoft.LowerCase(); //处理软件名为小写
- ClientDataSet2->First();
- pList->Clear();
- curNum=0;
- while(!ClientDataSet2->Eof) {
- //查找,如果找到把CDSeriNo,SWName 加入pList中
- if(ClientDataSet2->FieldByName("SWName")->AsString.LowerCase().AnsiPos(TheSoft)!=0) {
- pItem = new TAList;
- pItem->swName=ClientDataSet2->FieldValues["SWName"];
- pItem->cdName=ClientDataSet2->FieldValues["CDSeriNo"];
- pList->Add(pItem);
- }
- ClientDataSet2->Next(); //下一条
- }
- int m=pList->Count;
- if(m==0) { //如果没有找到任何一个软件
- Application->MessageBox("没有相匹配的软件!","提示",MB_OK);
- itemFindNext->Enabled=false;
- return;
- }
- int i;
- PAList temp;
- ClientDataSet1->First();
- while(!ClientDataSet1->Eof) {
- //把pList中的CDSeriNo值换成 CDName
- for(i=0;i<m;i++) {
- temp=(PAList)pList->Items[i];
- if(temp->cdName == ClientDataSet1->FieldByName("CDSeriNo")->AsString ) {
- temp->cdName = ClientDataSet1->FieldByName("CDName")->AsString;
- break;
- }
- }
- ClientDataSet1->Next();
- }
- //在TreeView 中找到相应的光盘名,将其选择,允许查找下一个
- TTreeNode * myNode=TreeView1->Items->Item[1];
- while(myNode!=NULL) {
- temp=(PAList)pList->Items[0];
- if(myNode->Text==temp->cdName ) break;
- myNode=myNode->GetNext();
- }
- if(myNode!=NULL) TreeView1->Selected=myNode;
- if(m>1) itemFindNext->Enabled=true;
- //在ListView中找到相应的软件名,将其选择,
- ListView1->SetFocus();
- ListView1->Selected=NULL;
- for(i=0;i<ListView1->Items->Count;i++) {
- temp=(PAList)pList->Items[0];
- if(ListView1->Items->Item[i]->Caption==temp->swName){
- ListView1->Selected=ListView1->Items->Item[i];
- break;
- }
- }
- //以下几句保证选择项一定在窗口中显示.
- i=ListView1->Items->IndexOf(ListView1->Selected);
- int j=i-ListView1->Items->IndexOf(ListView1->TopItem);
- i=ListView1->ClientHeight/ListView1->VisibleRowCount;
- if(j>ListView1->VisibleRowCount) ListView1->Scroll(0,i*j);
- }
- //---------------------------------------------------------------------------
- //新建数据库
- void __fastcall TForm1::itemNewExecute(TObject *Sender)
- {
- OpenDialog1->Title="新建";
- AnsiString temp;
- if(OpenDialog1->Execute()) {
- if(ClientDataSet1->Active==true) {
- ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
- ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
- }
- //处理文件名, 确保先关闭ClientDataSet
- temp=OpenDialog1->FileName;
- if(temp.AnsiPos(".cdb")==0) temp=temp+AnsiString(".cdb");
- ClientDataSet1->Active=false;
- ClientDataSet1->FileName=temp;
- int k=temp.Length()-4;
- temp=temp.SubString(1,k)+AnsiString(".dat");
- ClientDataSet2->Active=false;
- ClientDataSet2->FileName=temp;
- ClientDataSet1->FieldDefs->Clear(); //建立数据库结构
- ClientDataSet1->FieldDefs->Add("CDName",ftString,64,true);
- ClientDataSet1->FieldDefs->Add("CDNumber",ftString,8,true);
- ClientDataSet1->FieldDefs->Add("CDSeriNo",ftString,32,true);
- ClientDataSet1->CreateDataSet(); //建立新表
- ClientDataSet2->FieldDefs->Clear(); //建立数据库结构
- ClientDataSet2->FieldDefs->Add("CDSeriNo",ftString,32,true);
- ClientDataSet2->FieldDefs->Add("SWName",ftString,64,true);
- ClientDataSet2->FieldDefs->Add("SWDirFile",ftString,128,true);
- ClientDataSet2->FieldDefs->Add("SWDescription",ftString,256,true);
- ClientDataSet2->CreateDataSet(); //建立新表
- ClientDataSet1->Active=true; //打开数据库
- ClientDataSet2->Active=true;
- //清空TreeView ,ListView
- TreeView1->Items->Item[0]->DeleteChildren();
- ListView1->Items->BeginUpdate();
- ListView1->Items->Clear();
- ListView1->Items->EndUpdate();
- StatusBar1->Panels->Items[2]->Text="";
- //打开一些相关按钮
- itemAddCD->Enabled=true;
- itemSave->Enabled=true;
- itemOutput->Enabled=true;
- itemDelCD->Enabled=false;
- itemAddSoft->Enabled=false;
- itemDelSoft->Enabled=false;
- itemFindCD->Enabled=false;
- itemFindSoft->Enabled=false;
- Form1->Caption=AnsiString("学韬电子光盘册 - ")+ OpenDialog1->FileName;
- }
- }
- //---------------------------------------------------------------------------
- //打开数据库
- void __fastcall TForm1::itemOpenExecute(TObject *Sender)
- {
- OpenDialog1->Title="打开";
- if(OpenDialog1->Execute())
- OpenCDBFile(OpenDialog1->FileName);
- }
- //---------------------------------------------------------------------------
- //重画窗口时改变状态条中光盘编号项的位置
- void __fastcall TForm1::FormPaint(TObject *Sender)
- {
- StatusBar1->Panels->Items[0]->Width=Form1->Width-192;
- StatusBar1->Panels->Items[1]->Width=64;
- StatusBar1->Panels->Items[2]->Width=128;
- }
- //---------------------------------------------------------------------------
- //TreeView改变
- void __fastcall TForm1::TreeView1Change(TObject *Sender, TTreeNode *Node)
- {
- ListView1->Items->BeginUpdate(); // 清空ListView
- ListView1->Items->Clear();
- ListView1->Items->EndUpdate();
- //如果不是选择根结点,才进行以下操作
- if(TreeView1->Selected!=TreeView1->Items->Item[0]) {
- itemAddSoft->Enabled=true; //打开两个按钮
- itemDelCD->Enabled=true;
- //定位在所选光盘的记录上,显示光盘编号
- TLocateOptions op;
- op.Clear();
- op<<loCaseInsensitive;
- ClientDataSet1->Locate("CDName",Node->Text,op);
- TheCDSeriNo=ClientDataSet1->FieldValues["CDSeriNo"];
- StatusBar1->Panels->Items[2]->Text=ClientDataSet1->FieldValues["CDNumber"];
- //根据所选光盘序列号,在软件库设置过滤器
- if(ClientDataSet2->Filtered==true) ClientDataSet2->Filtered=false;
- ClientDataSet2->Filter="CDSeriNo="+TheCDSeriNo;
- ClientDataSet2->Filtered=true;
- ClientDataSet2->First();
- TListItem * ListItem;
- //把相应此光盘的软件加入ListView中
- while(!ClientDataSet2->Eof) {
- ListItem = ListView1->Items->Add();
- ListItem->Caption=ClientDataSet2->FieldByName("SWName")->AsString;
- ListItem->SubItems->Add(ClientDataSet2->FieldByName("SWDirFile")->AsString);
- ListItem->SubItems->Add(ClientDataSet2->FieldByName("SWDescription")->AsString);
- ClientDataSet2->Next();
- }
- }
- else { //如果选择是根结点项,关闭相关按钮,不显示编号
- itemAddSoft->Enabled=false;
- itemDelCD->Enabled=false;
- StatusBar1->Panels->Items[2]->Text="";
- }
- }
- //---------------------------------------------------------------------------
- //删除光盘
- void __fastcall TForm1::itemDelCDExecute(TObject *Sender)
- {
- ClientDataSet1->First();
- TLocateOptions op;
- op.Clear();
- op<<loCaseInsensitive;
- //定位在所选择的光盘上
- ClientDataSet1->Locate("CDName",TreeView1->Selected->Text,op);
- TheCDSeriNo=ClientDataSet1->FieldValues["CDSeriNo"];
- //确认是否删除
- AnsiString temp= ClientDataSet1->FieldValues["CDName"];
- temp=AnsiString("是否删除光盘 ")+temp+AnsiString(" 及它所包括的所有软件记录?");
- int res = MessageDlg(temp,mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0);
- if(res==mrYes) { //删除此光盘记录及软件库中与其相关的软件
- if(ClientDataSet2->Filtered==true) ClientDataSet2->Filtered=false;
- ClientDataSet2->Filter="CDSeriNo="+TheCDSeriNo;
- ClientDataSet2->Filtered=true; //设置过滤器
- ClientDataSet2->First();
- while(!ClientDataSet2->Eof) ClientDataSet2->Delete(); //全是与光盘有关的记录
- ClientDataSet1->Delete();
- TreeView1->Selected->Delete(); //在TreeView中删除相应项
- TreeView1->Selected=TreeView1->Items->Item[0];
- }
- if(ClientDataSet1->RecordCount==0) {
- itemFindCD->Enabled=false;
- itemFindSoft->Enabled=false;
- }
- }
- //---------------------------------------------------------------------------
- //删除软件
- void __fastcall TForm1::itemDelSoftExecute(TObject *Sender)
- {
- ClientDataSet2->First();
- TLocateOptions op;
- op.Clear();
- op<<loCaseInsensitive;
- int i;
- ListView1->Items->BeginUpdate();
- //只要选择的项目数不为空,一个个删除数据库中的相应软件和ListView中相应项目
- while(ListView1->Selected!=NULL) {
- ClientDataSet2->Locate("SWName",ListView1->Selected->Caption,op);
- ClientDataSet2->Delete();
- i=ListView1->Items->IndexOf(ListView1->Selected);
- ListView1->Items->Delete(i);
- }
- ListView1->Items->EndUpdate();
- ListView1->Selected=ListView1->ItemFocused;
- if(ClientDataSet2->RecordCount==0) itemFindSoft->Enabled=false;
- }
- //---------------------------------------------------------------------------
- //ListView改变选择项目时,同时改变两个按钮状态
- void __fastcall TForm1::ListView1Change(TObject *Sender, TListItem *Item,
- TItemChange Change)
- {
- if(ListView1->Selected!=NULL){
- itemDelSoft->Enabled=true;
- pmModiSF->Enabled=true;
- }
- else{
- itemDelSoft->Enabled=false;
- pmModiSF->Enabled=false;
- }
- }
- //---------------------------------------------------------------------------
- //以下两个函数对Del按键产生反应.
- void __fastcall TForm1::TreeView1KeyDown(TObject *Sender, WORD &Key,
- TShiftState Shift)
- {
- if( Key==VK_DELETE && itemDelCD->Enabled==true && !(TreeView1->IsEditing()) )
- itemDelCDExecute(Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ListView1KeyDown(TObject *Sender, WORD &Key,
- TShiftState Shift)
- {
- if( Key==VK_DELETE && itemDelSoft->Enabled==true )
- itemDelSoftExecute(Sender);
- if( Key==VK_RETURN && ListView1->Selected!=NULL)
- ListView1DblClick(Sender);
- }
- //---------------------------------------------------------------------------
- //光盘改名,如果为空则取消改变
- void __fastcall TForm1::TreeView1Edited(TObject *Sender, TTreeNode *Node,
- AnsiString &S)
- {
- if(S=="") S=Node->Text;
- else {
- ClientDataSet1->Edit();
- ClientDataSet1->FieldByName("CDName")->AsString=S;
- ClientDataSet1->Post();
- ClientDataSet1->MergeChangeLog();
- }
- }
- //---------------------------------------------------------------------------
- //不允许改变根结点项的名字
- void __fastcall TForm1::TreeView1Editing(TObject *Sender, TTreeNode *Node,
- bool &AllowEdit)
- {
- if(Node->Level==0) AllowEdit=false;
- }
- //---------------------------------------------------------------------------
- //查找下一个软件
- void __fastcall TForm1::itemFindNextExecute(TObject *Sender)
- {
- curNum++; //已找到的软件数加一,如果找完则关闭下一个按钮
- if(curNum >= pList->Count) {
- itemFindNext->Enabled=false;
- curNum=0;
- return;
- }
- //在TreeView中找到要查找软件对应光盘,选择
- PAList temp;
- TTreeNode * myNode=TreeView1->Items->Item[1];
- while(myNode!=NULL) {
- temp=(PAList)pList->Items[curNum];
- if(myNode->Text==temp->cdName ) break;
- myNode=myNode->GetNext();
- }
- if(myNode!=NULL) TreeView1->Selected=myNode;
- int i;
- ListView1->SetFocus();
- ListView1->Selected=NULL; //取消前一个选择
- for(i=0;i<ListView1->Items->Count;i++) { //找到下一个相应软件,选择
- temp=(PAList)pList->Items[curNum];
- if(ListView1->Items->Item[i]->Caption==temp->swName){
- ListView1->Selected=ListView1->Items->Item[i];
- break;
- }
- }
- //以下确保选择项被显示
- i=ListView1->Items->IndexOf(ListView1->Selected);
- int j=i-ListView1->Items->IndexOf(ListView1->TopItem);
- i=ListView1->ClientHeight/ListView1->VisibleRowCount;
- if(j>ListView1->VisibleRowCount) ListView1->Scroll(0,i*j);
- }
- //---------------------------------------------------------------------------
- //修改软件名称属性
- void __fastcall TForm1::pmModiSFClick(TObject *Sender)
- {
- Form2->Show();
- }
- //---------------------------------------------------------------------------
- //执行软件
- void __fastcall TForm1::ListView1DblClick(TObject *Sender)
- {
- if(ListView1->Selected!=NULL) {
- int k= ListView1->Selected->SubItems->Strings[1].AnsiPos("!");
- if(k!=0) {
- AnsiString temp=ListView1->Selected->SubItems->Strings[1];
- temp=temp.SubString(k,temp.Length()-k+1);
- int res=MessageDlg(temp+" 是否继续执行?",mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0);
- if(res==mrNo) return;
- }
- ShellExecute(Form1->Handle,"open",ListView1->Selected->SubItems->Strings[0].c_str(),NULL,NULL,SW_SHOWNORMAL);
- }
- }
- //---------------------------------------------------------------------------
- //修改光盘编号
- void __fastcall TForm1::StatusBar1DblClick(TObject *Sender)
- {
- if(StatusBar1->Panels->Items[2]->Text=="") return;
- AnsiString temp1 = ClientDataSet1->FieldByName("CDNumber")->AsString;
- AnsiString temp2 =InputBox("修改光盘编号","请输入新的光盘编号:",temp1);
- if(temp2!=temp1) {
- ClientDataSet1->Edit();
- ClientDataSet1->FieldByName("CDNumber")->AsString=temp2;
- ClientDataSet1->Post();
- ClientDataSet1->MergeChangeLog();
- }
- StatusBar1->Panels->Items[2]->Text=ClientDataSet1->FieldValues["CDNumber"];
- }
- //---------------------------------------------------------------------------
- //关闭程序,保存文件消除对象
- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
- {
- pList->Clear();
- delete pList;
- if(ClientDataSet1->Active==true) {
- ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
- ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
- ClientDataSet1->Active=false;
- ClientDataSet2->Active=false;
- }
- }
- //---------------------------------------------------------------------------
- //打开数据库文件
- void __fastcall TForm1::OpenCDBFile(AnsiString filename)
- {
- AnsiString temp=filename;
- //处理文件名,确保关闭了ClientDataSet
- if(ClientDataSet1->Active==true) {
- ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
- ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
- }
- if(temp.AnsiPos(".cdb")==0) temp=temp+AnsiString(".cdb");
- ClientDataSet1->Active=false;
- ClientDataSet1->FileName=temp;
- int k=temp.Length()-4;
- temp=temp.SubString(1,k)+AnsiString(".dat");
- ClientDataSet2->Active=false;
- ClientDataSet2->FileName=temp;
- ClientDataSet1->Active=true; //打开
- ClientDataSet2->Active=true;
- //清空ListView TreeView
- TreeView1->Items->Item[0]->DeleteChildren();
- ListView1->Items->BeginUpdate();
- ListView1->Items->Clear();
- ListView1->Items->EndUpdate();
- StatusBar1->Panels->Items[2]->Text="";
- //将数据库中记录加入TreeView中
- k=ClientDataSet1->RecordCount;
- int i;
- ClientDataSet1->First();
- TTreeNode * tmpNode = TreeView1->Items->Item[0];
- for(i=0;i<k;i++) {
- TreeView1->Items->AddChild(tmpNode,ClientDataSet1->FieldByName("CDName")->AsString);
- TreeView1->Items->Item[i+1]->ImageIndex=1;
- TreeView1->Items->Item[i+1]->SelectedIndex=0;
- ClientDataSet1->Next();
- }
- //打开一些相关按钮
- itemAddCD->Enabled=true;
- itemSave->Enabled=true;
- itemOutput->Enabled=true;
- itemDelCD->Enabled=false;
- itemAddSoft->Enabled=false;
- itemDelSoft->Enabled=false;
- if(ClientDataSet1->RecordCount!=0) itemFindCD->Enabled=true;
- else itemFindCD->Enabled=false;
- if(ClientDataSet2->RecordCount!=0)itemFindSoft->Enabled=true;
- else itemFindSoft->Enabled=false;
- Form1->Caption=AnsiString("学韬电子光盘册 - ")+filename;
- }
- //--------------------------------------------------------------------------
- //以命令行参数打开数据库
- void __fastcall TForm1::FormShow(TObject *Sender)
- {
- if(cdbname!="")
- OpenCDBFile(cdbname);
- }
- //---------------------------------------------------------------------------
- //保存文件
- void __fastcall TForm1::itemSaveExecute(TObject *Sender)
- {
- if(ClientDataSet1->Active==true) {
- ClientDataSet1->SaveToFile(ClientDataSet1->FileName);
- ClientDataSet2->SaveToFile(ClientDataSet2->FileName);
- }
- }
- //---------------------------------------------------------------------------
- //设置参数
- void __fastcall TForm1::itemConfigExecute(TObject *Sender)
- {
- Form6->Show();
- }
- //---------------------------------------------------------------------------
- //输出HTML
- void __fastcall TForm1::itemOutputExecute(TObject *Sender)
- {
- AnsiString tmp;
- tmp=ExtractFileDir(Application->ExeName); //取应用程序所在目录
- tmp=tmp+AnsiString("\cdpack.ini");
- TMemIniFile * Reg=new TMemIniFile(tmp);
- bool bLink=Reg->ReadBool("Common","HtmlLink",false); //是否要在HTML文件中设置链接
- Form7->Show();
- OutputHTML(Sender,bLink);
- Form7->Close();
- delete Reg;
- }
- //---------------------------------------------------------------------------
- //写HTML文件
- void __fastcall TForm1::OutputHTML(TObject * Sender, bool isLink)
- {
- int i,k;
- AnsiString tmp,temp,tempNo;
- tmp=ExtractFileName(ClientDataSet1->FileName);
- k=tmp.Length()-4;
- tmp=tmp.SubString(1,k);
- FILE * fp;
- temp=tmp+AnsiString(".htm");
- fp=fopen(temp.c_str(),"w");
- if(fp==NULL){
- Application->MessageBox("不能创建文件!","错误",MB_OK);
- return;
- }
- fprintf(fp,"<html>");
- fprintf(fp,"<head>");
- fprintf(fp,"<meta http-equiv="Content-Type" content="text/html; charset=gb2312">");
- temp= AnsiString("<title>")+tmp+AnsiString("</title>");
- fprintf(fp,"%s",temp.c_str());
- fprintf(fp,"</head>");
- fprintf(fp,"<body>");
- fprintf(fp,"<p align="center"><strong><font face="幼圆" size="3" color="#FF8000">索引</font> </strong></p>");
- fprintf(fp,"<table border="1" width="80%">");
- fprintf(fp,"<tr><th width="20%">编号</th><th width="80%">光盘名称</th></tr>");
- ClientDataSet1->First();
- k=ClientDataSet1->RecordCount;
- Form7->ProgressBar1->Max=2*k;
- Form7->ProgressBar1->Position=1;
- for(i=0;i<k;i++) {
- fprintf(fp,"<tr>");
- temp=AnsiString("<td width="20%">") +
- ClientDataSet1->FieldByName("CDNumber")->AsString +
- AnsiString("</td>");
- fprintf(fp,"%s",temp.c_str());
- temp=AnsiString("<td width="80%"><a href="./Content/") +
- ClientDataSet1->FieldByName("CDName")->AsString +
- AnsiString(".htm">") + ClientDataSet1->FieldByName("CDName")->AsString +
- AnsiString("</a></td>");
- fprintf(fp,"%s",temp.c_str());
- fprintf(fp,"</tr>");
- Form7->ProgressBar1->StepIt();
- ClientDataSet1->Next();
- }
- fprintf(fp,"</table>");
- fprintf(fp,"</body>");
- fprintf(fp,"</html>");
- fclose(fp);
- fp=NULL;
- CreateDir("Content");
- Form7->ProgressBar1->Position=k;
- ClientDataSet1->First();
- for(i=0;i<k;i++) {
- tmp=ClientDataSet1->FieldByName("CDName")->AsString;
- temp=GetCurrentDir()+AnsiString("\Content\")+tmp+AnsiString(".htm");
- fp=fopen(temp.c_str(),"w");
- if(fp==NULL) {
- Application->MessageBox("不能创建文件!","错误",MB_OK);
- return;
- }
- fprintf(fp,"<html>");
- fprintf(fp,"<head>");
- fprintf(fp,"<meta http-equiv="Content-Type" content="text/html; charset=gb2312">");
- temp= AnsiString("<title>")+tmp+AnsiString("</title>");
- fprintf(fp,"%s",temp.c_str());
- fprintf(fp,"</head>");
- fprintf(fp,"<body>");
- temp=AnsiString("<p align="center"><strong><font face="幼圆" size="3" color="#FF8000">") +
- tmp + AnsiString("</font> </strong></p>");
- fprintf(fp,"%s",temp.c_str());
- fprintf(fp,"<p></p>");
- //根据所选光盘序列号,在软件库设置过滤器
- tempNo=ClientDataSet1->FieldByName("CDSeriNo")->AsString;
- if(ClientDataSet2->Filtered==true) ClientDataSet2->Filtered=false;
- ClientDataSet2->Filter="CDSeriNo="+tempNo;
- ClientDataSet2->Filtered=true;
- ClientDataSet2->First();
- while(!ClientDataSet2->Eof) {
- if(isLink==true)
- temp=AnsiString("<p><strong>软件名称:</strong><a href="") +
- ClientDataSet2->FieldByName("SWDirFile")->AsString +
- AnsiString("">")+ ClientDataSet2->FieldByName("SWName")->AsString +
- AnsiString("</a><br>");
- else temp=AnsiString("<p><strong>软件名称:</strong>") +
- ClientDataSet2->FieldByName("SWName")->AsString +
- AnsiString("<br>");
- fprintf(fp,"%s",temp.c_str());
- temp=AnsiString("<strong>软件说明:</strong>") +
- ClientDataSet2->FieldByName("SWDescription")->AsString +
- AnsiString("</p>");
- fprintf(fp,"%s",temp.c_str());
- fprintf(fp,"<hr>");
- ClientDataSet2->Next();
- }
- fprintf(fp,"</body>");
- fprintf(fp,"</html>");
- Form7->ProgressBar1->StepIt();
- fclose(fp);
- fp=NULL;
- ClientDataSet1->Next();
- }
- }