📄 main.pas
字号:
procedure TDBookBrowser.ExportSubjectToHtm(subject: String);
var
i_count,i:integer;
str_html:TStrings;
s_path,s_dir,s_Exepath,s_filename,s_cpt,s_memo,s_des,s_content,s_ltmf,s_ct,s_subject:String;
tmpNode:TtreeNode;
ClassDoc:TClassDoc;
begin
if (subject='') or (MainFrm.sTV_Main.Items.Count=0) then
begin
showMessage('没有存在的课题或者文档需要导出! ');
Exit;
end;
str_html:=TStringList.Create;
//s_Exepath:=ExtractFileDir(application.ExeName);
with MainFrm Do
begin
tempFrm:=TtempFrm.Create(nil);
tempFrm.Caption:='导出当前课题';
tempFrm.Show;
tempFrm.Gauge1.MaxValue:=getNodeCount(nil);
//tempFrm.Gauge1.MaxValue:=sTV_Main.Items.Count;
i_count:=sTV_Main.Items.Count;
for i:=0 to i_count-1 Do
begin
if isDocNode(sTV_Main.Items[i]) then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from DocData');
ADOQuery1.SQL.Add('Where id ='+InttoStr(getNodeId(sTV_Main.Items[i])));
ADOQuery1.Open;
ClassDoc.Title :=ADOQuery1.fieldbyName('Caption').AsString;
ClassDoc.MemoText :=ADOQuery1.fieldbyName('MemoText').AsString;
ClassDoc.Description :=ADOQuery1.fieldbyName('Description').AsString;
ClassDoc.LastModified:=ADOQuery1.fieldbyName('LastModified').AsString;
ClassDoc.CreateTime:=ADOQuery1.fieldbyName('CreateTime').AsString;
ClassDoc.DocText :=ADOQuery1.fieldbyName('DocText').AsString;
ClassDoc.Subject:=ADOQuery1.fieldbyName('Subject').AsString;
ClassDoc.HtmlMode:=ADOQuery1.fieldbyName('HtmlMode').AsString;
ClassDoc.UserID:=UserID;
setHtmStr(ClassDoc);
end
else
begin
setHtmStr(sTV_Main.Items[i],True);
end;
if sTV_Main.Items[i].Level=0 then
begin
tmpNode:=sTV_Main.Items[i]; //总让TmpNode为根节点
CreateNodeDir(tmpNode,subject); //并且为其创造文件夹
end;
s_dir:=ExportPath+'\'+getNodePath(sTV_Main.Items[i],tmpNode,subject);
s_filename:= s_dir+'.htm';
str_html.Clear;
str_html.Add(FHtmStr);
str_html.SaveToFile(s_filename);
tempFrm.lbl_Status.Caption:='正在导出文件'+s_filename;
tempFrm.Gauge1.Progress :=tempFrm.Gauge1.Progress +1;
Application.ProcessMessages;
end;
tempFrm.Free;
end;
str_html.Free;
end;
function TDBookBrowser.GetHtmStr: String;
begin
Result:=FHtmStr;
end;
procedure TDBookBrowser.GoToURL(URL: String);
begin
FWebBrowser.Navigate(URL);
end;
procedure TDBookBrowser.Init;
begin
GoToURL(ExtractFileDir(application.ExeName)+'\data\Index.htm');
LoadHtmlMode;
end;
procedure TDBookBrowser.LoadHtmlMode;
var
BinF:file of TRecKind;
Rec:TRecKind;
FilePath:String;
i:integer;
begin
FilePath:=HtmlModeFileName;
AssignFile(BinF,FilePath);
if Not FileExists(FilePath) then
begin
ReWrite(BinF);
CloseFile(BinF);
MainFrm.scbb_HtmlMode.Items.Clear;
MainFrm.scbb_HtmlMode.Items.Add('默认格式');
MainFrm.scbb_HtmlMode.ItemIndex:=0;
Exit;
end
else
Reset(BinF);
MainFrm.scbb_HtmlMode.Items.Clear;
MainFrm.scbb_HtmlMode.Items.Add('默认格式');
FModeName.Clear;
FModeContent.Clear;
FModeCount:=FileSize(BinF);
for i:=0 to FileSize(BinF)-1 Do
begin
Read(BinF,Rec);
MainFrm.scbb_HtmlMode.Items.Add(Rec.Name);
FModeName.Add(Rec.Name);
FModeContent.Add(Rec.Content);
end;
CloseFile(BinF);
MainFrm.scbb_HtmlMode.ItemIndex:=0;
end;
procedure TDBookBrowser.SetHtmStr(ClassDoc: TClassDoc);
var
TempStr:String;
i,i_indexitem:integer;
TmpStrList:TStringList;
begin
TmpStrList:=TStringList.Create;
TmpStrList.Text:=ClassDoc.DocText;
for i:=0 to TmpStrList.Count-1 Do
begin
TmpStrList.Strings[i]:=TmpStrList.Strings[i]+'<br>';
end;
ClassDoc.DocText:=TmpStrList.Text;
TmpStrList.Free;
i_indexitem:=-1;
for i:=0 to FModeCount-1 Do
if ClassDoc.HtmlMode = FModeName[i] then
begin
i_indexitem:=i;
Break;
end;
if i_indexitem<>-1 then
begin
TempStr:= FModeContent[i_indexitem];
TempStr:=AnsiReplaceStr(TempStr,CS_TITLE,ClassDoc.Title);
TempStr:=AnsiReplaceStr(TempStr,CS_CREATETIME,ClassDoc.CreateTime);
TempStr:=AnsiReplaceStr(TempStr,CS_LASTTIMEMODIFIED,ClassDoc.LastModified);
TempStr:=AnsiReplaceStr(TempStr,CS_DESCRIPTION,ClassDoc.Description);
TempStr:=AnsiReplaceStr(TempStr,CS_MEMO,ClassDoc.MemoText);
TempStr:=AnsiReplaceStr(TempStr,CS_CONTENT,ClassDoc.DocText);
TempStr:=AnsiReplaceStr(TempStr,CS_AUTHOR,ClassDoc.UserID);
end
else
begin
TempStr:='<html>'+#13+#10
+'<head>'+#13+#10
+'<title>'+ClassDoc.Title+'</title>'+#13+#10
+'<style type="text/css">'+#13+#10
+'body{font-size: 10.5pt;font-family: "Arial";};'+#13+#10
+'#blue{font-family: "宋体"; font-size: 12px;color:navy;};'+#13+#10
+'#div1{padding: 10px;border: 1px solid #0099cc;height: 50px;width: 100%;font-family: "宋体"; font-size: 12px;background-color: #99ccff;color:#333333;};'+#13+#10
+'#div2{padding: 10px;border-top: 0px solid #ffffff;border-bottom: 0px solid #ffffff;border-left: 1px solid #0099cc;border-right: 1px solid #0099cc;width: 100%;font-family: "宋体"; font-size: 12px;background-color: #e8f4ff;color:#000000;line-height:1.5;};'+#13+#10
+'#div3{padding: 10px;border-top: 0px solid #ffffff;border-bottom: 1px solid #0099cc;border-left: 1px solid #0099cc;border-right: 1px solid #0099cc;width: 100%;font-family: "宋体"; font-size: 12px;background-color: #000000;color:#eeeeee;};'+#13+#10
+'#headline{font-size: 24px;color: #333333;font-family: "Arial Black";}'+#13+#10
+'</style>'+#13+#10
+'</head>'+#13+#10
+'<body bgcolor="#ffffff"><pre>'+#13+#10
+'<p id="headline">'+ClassDoc.Title+'</p>'+#13+#10
+'<div id="div1">'+'<b>简单描述</b>'+'<br> '+ClassDoc.Description+'</div>'+#13+#10
+'<div id="div2">'+ClassDoc.DocText+'<br><br>'+#13+#10
+'<HR width="100%" align="center"><div id="blue">最后一次编辑时间: '+ClassDoc.LastModified+'</div></div>' +#13+#10
+'<div id="div1">'+'<b>备注</b>'+'<br> '+ClassDoc.MemoText+'</div>'+#13+#10
+'</pre></body>'+#13+#10
+'</html>';
end;
FHtmStr:=TempStr;
end;
procedure TDBookBrowser.SetHtmStr(TmpNode: TTreeNode; IsExport: Boolean);
var
NodeKindStrList,HtmStrList:TStringList;
PID:^Integer;
TempStr,HtmStyleStr,UrlStr,TitleStr:String;
i,j,NodeCount:integer;
CurNode:TTreeNode;
begin
NodeKindStrList:=TStringList.Create;
HtmStrList:=TStringList.Create;
CurNode:=TmpNode.getFirstChild;
TempStr:=TmpNode.Text;
NodeCount:=TmpNode.Count;
With MainFrm Do
begin
PID:=TmpNode.Data;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select NodeKind from IndexData');
ADOQuery1.SQL.Add('Where PID = '+InttoStr(PID^)+' and NodeLevel = '+InttoStr(TmpNode.level+1));
ADOQuery1.Open;
While Not ADOQuery1.Eof Do
begin
NodeKindStrList.Add(ADOQuery1.FieldByName('NodeKind').AsString);
ADOQuery1.Next;
end;
end;
HtmStyleStr:='<style type="text/css">'
+'A:visited{TEXT-DECORATION: none;Color:#333333;}'
+'A:active{TEXT-DECORATION: none;Color:#333333;}'
+'A:hover{TEXT-DECORATION: underline;Color:red;}'
+'A:link{text-decoration: none;Color:#000000;}'
+'body{font-family: "Arial";font-size: 10.5pt;};'
+'</style>';
HtmStrList.Add('<Html>');
HtmStrList.Add('<head>');
HtmStrList.Add('<title>'+TempStr+'</title>');
HtmStrList.Add(HtmStyleStr);
HtmStrList.Add('</head>');
HtmStrList.Add('<body bgcolor="#FFFFFF">');
if NodeCount >0 then
begin
HtmStrList.Add('<b>'+TmpNode.Text+'</b> (该目录下共有'+IntToStr(NodeCount)+'项记录)');
HtmStrList.Add('<HR>');
for i:=0 to NodeCount-1 Do
begin
UrlStr:=IntToStr(CurNode.Index);
if Not IsExport then //如果不是导出文件
if NodeKindStrList.Strings[i]='document' then
TempStr:='<p><Img src="'+ExePath+'\Data\Images\doc.gif"> <a href="'+CS_LINKPL+UrlStr
+'" Title="'+TitleStr+'">'+CurNode.Text+'</a></p>'
else
TempStr:='<p><Img src="'+ExePath+'\Data\Images\ifolder.gif"> <a href="'+CS_LINKPL+UrlStr+'">'
+CurNode.Text+'</a></p>'
else
begin
UrlStr:=CurNode.Parent.Text+'/'+CurNode.Text+'.htm';
if NodeKindStrList.Strings[i]='document' then
TempStr:='<p><Img src="'+ExePath+'\Data\Images\doc.gif"> <a href="'+UrlStr
+'" Title="'+TitleStr+'">'+CurNode.Text+'</a></p>'
else
TempStr:='<p><Img src="'+ExePath+'\Data\Images\ifolder.gif"> <a href="'+UrlStr+'">'
+CurNode.Text+'</a></p>';
end;
HtmStrList.Add(TempStr);
CurNode:=CurNode.getNextSibling;
end;
end
else
begin
HtmStrList.Add('<b>'+TmpNode.Text+'</b> ');
HtmStrList.Add('<HR>');
HtmStrList.Add('无子类别');
end;
HtmStrList.Add('<HR>');
HtmStrList.Add('</body>');
HtmStrList.Add('</html>');
FHtmStr:=HtmStrList.Text;
HtmStrList.Free;
NodeKindStrList.Free;
end;
//=============================================================================//
{自定义函数区}
//=============================================================================//
function TMainFrm.RegHotKey(hwnd:THandle;AHotKey:String):Boolean;
var
fsm,vk:integer;
HotkeyStr:String;
i_Pos,i:integer;
begin
fsm:=0;
vk:=0;
HotkeyStr:=AHotKey;
if HotKeyStr='' then //取消热键
begin
RegisterHotKey(handle,HotKeyID,0,0);
Result:=True;
Exit;
end;
if Pos('Ctrl',HotKeyStr)<>0 then
fsm:=fsm+MOD_CONTROL;
if Pos('Shift',HotKeyStr)<>0 then
fsm:=fsm+MOD_SHIFT;
if Pos('ALT',HotKeyStr)<>0 then
fsm:=fsm+MOD_ALT;
i_Pos:=Pos('+',HotkeyStr);
if i_Pos=0 then
begin
if (HotkeyStr[1]='F') and (Length(HotkeyStr)>1) then
vk:=VK_F1-1+StrToInt(HotKeyStr[2])
else
if Length(HotKeyStr)=1 then
vk:=Ord(HotKeyStr[1]);
end
else
begin
if HotKeyStr[Length(HotKeyStr)] in ['A'..'Z'] then
Vk:=Ord(HotKeyStr[Length(HotKeyStr)]);
end;
if vk =0 then
begin
Result:=false;
Exit;
end;
RegisterHotKey(hwnd,HotKeyId,fsm,vk);
Result:=True;
end;
function TMainFrm.GetPassword(UserID: String): String;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select Passwords from UsersData');
ADOQuery1.SQL.Add('Where UserID="'+UserID+'"');
ADOQuery1.Open;
if ADOQuery1.RecordCount >0 then
Result:=ADOQuery1.fieldByName('Passwords').AsString
else
Result:='';
end;
function TMainFrm.IsDocNode(TmpNode: TTreeNode): Boolean;
begin
if Tmpnode.ImageIndex =3 then
Result:=True
else
Result:=False;
end;
procedure TMainFrm.LoadSubjectList;
var
TempStr:string;
begin
scbb_Subject.Items.Clear;
with ADOQuery1 Do
begin
Close;
SQL.Clear;
SQL.Add('select Distinct Subject from Indexdata');
SQL.Add('Where NodeLevel=-1 and UserID="'+UserID+'"');
Open;
while Not Eof Do
begin
TempStr:=ADOQuery1.fieldbyName('Subject').AsString;
scbb_subject.Items.Add(TempStr);
ADOQuery1.Next;
end;
end;
scbb_Subject.ItemIndex:=0;
end;
procedure TMainFrm.LoadSubjectNodeData(Subject:String;TreeView:TsuiTreeView);
var
pi_id,pi_pid,pi_tmp:^integer;
i_tmp,i_count,i:integer;
s_cpt,s_kind,s_tmp:String;
tmpNode:TtreeNode;
begin
TreeView.Items.Clear;
sBtn_Submit.Enabled:=False;
with ADOQuery1 Do
begin
//进度条
Close;
SQL.Clear;
SQL.Add('select * from Indexdata');
SQL.Add('where UserID="'+UserID+'" and Subject="'+Subject+'" and Nodelevel>-1');
Open;
gge_MainStatus.MaxValue:=ADOQuery1.RecordCount;
//Load 根结点
Close;
SQL.Clear;
SQL.Add('select * from Indexdata');
SQL.Add('where Subject= "'+Subject+'" and Nodelevel=0 and UserID="'+UserID+'"');
SQL.Add('order by Nodeindex');
Open;
While Not Eof Do
begin
New(pi_id);
pi_id^:=fieldByName('ID').AsInteger;
s_cpt:=fieldByName('NodeCaption').AsString;
TmpNode:=TreeView.Items.AddObject(nil,s_cpt,pi_id);
TmpNode.ImageIndex:=1;
TmpNode.SelectedIndex:=1;
gge_MainStatus.Progress:=gge_MainStatus.Progress+1;
Next;
end;
//Load 子节点
New(pi_tmp);
Close;
SQL.Clear;
SQL.Add('select * from Indexdata');
SQL.Add('where Subject= "'+subject+'" and Nodelevel>0 and UserID="'+UserID+'"');
SQL.Add('order by NodeLevel,NodeIndex');
Open;
While Not ADOQuery1.Eof Do
begin
New(pi_id);
New(pi_pid);
i_count:=TreeView.Items.Count;
pi_pid^:=ADOQuery1.fieldByName('PID').AsInteger;
pi_id^:=ADOQuery1.fieldByName('ID').AsInteger;
s_cpt:= ADOQuery1.fieldByName('NodeCaption').AsString;
s_kind:=ADOQuery1.fieldByName('NodeKind').AsString;
for i:=0 to i_count-1 Do
begin
pi_tmp:=TreeView.Items[i].Data;
if pi_pid^=pi_tmp^ then
begin
tmpNode:=TreeView.Items.AddChildObject(TreeView.Items[i],s_cpt,pi_id);
gge_MainStatus.Progress:=gge_MainStatus.Progress+1;
if s_kind='wangle' then
begin
tmpNode.ImageIndex:=2;
tmpNode.SelectedIndex:=2;
end
else if s_kind='document' then
begin
tmpNode.ImageIndex:=3;
tmpNode.SelectedIndex:=3;
end;
break;
end;
end;
ADOQuery1.Next;
end;
end;
end;
procedure TMainFrm.DisplayTheNode(TmpNode: TTreeNode);
var
PID:^Integer;
Blob:TStream;
TempDoc:TStrings;
ClassDoc:TClassDoc;
begin
PID:=TmpNode.Data;
if IsDocNode(TmpNode) then
begin
With ADOQuery1 Do
begin
Close;
SQL.Clear;
SQL.Add('Select * From DocData');
SQL.Add('Where ID='+InttoStr(PID^)+' and Subject="'+scbb_Subject.Text+'"');
Open;
if RecordCount>0 then
begin
Blob:=TMemoryStream.Create;
TempDoc:=TStringList.Create;
TBlobField(FieldByName('DocText')).SaveToStream(Blob);
Blob.Seek(0, soFromBeginning);
TempDoc:=TStringList.Create;
TempDoc.LoadFromStream(Blob);
ClassDoc.Title:=FieldByName('Caption').AsString;
ClassDoc.Description:=FieldByName('Description').AsString;
ClassDoc.MemoText:=FieldByName('MemoText').AsString;
ClassDoc.LastModified:=FieldByName('LastModified').AsString;
ClassDoc.CreateTime:=FieldByName('CreateTime').AsString;
ClassDoc.HtmlMode:=FieldByName('HtmlMode').AsString;
ClassDoc.DocText:= FieldByName('DocText').AsString;
scbb_HtmlMode.ItemIndex:=scbb_HtmlMode.Items.IndexOf(ClassDoc.HtmlMode);
sedt_title.Text:=ClassDoc.Title;
sedt_Description.Text:=ClassDoc.Description;
sedt_memo.Text:=ClassDoc.MemoText;
mem_DocText.Text:=ClassDoc.DocText;
sBtn_Submit.Enabled:=True;
DBookBrowser.SetHtmStr(ClassDoc);
DBookBrowser.DisplayHtmlPage;
end
else //如果为0,表示发生意外错误
begin
showMessage('发生未知错误: 该文档的数据被破坏...');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -