4 Star 8 Fork 10

mellen / dbooks

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bookMain.pas 64.28 KB
一键复制 编辑 原始数据 按行查看 历史
mellen 提交于 2016-01-12 08:56 . 初始化
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161
unit bookMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, SUIForm, SUIMgr, Menus, SUIMainMenu, ToolWin, ComCtrls,
ImgList, StdCtrls, SUIPageControl, SUITabControl, SUITreeView, OleCtrls,
SHDocVw, SUIComboBox, mshtml, activex,PublicUnit,
SUIGroupBox, SUIMemo, SUIEdit, Buttons,StrUtils, DB, ADODB, ActnList,
SUIProgressBar, Gauges,ShellAPI, SUIPopupMenu, SUIToolBar,{QDialogs,}
SUIImagePanel,ShlObj,Inifiles,SUIListBox, SUIButton, SHDocVw_EWB,
EmbeddedWB;
type
TDBookBrowser = Class (TObject)
private
FModeCount:integer;
FModeContent:TStrings;
FModeName:TStrings;
FHtmStr:String;
FWebbrowser:TWebBrowser;
public
constructor Create;
destructor Destroy;override;
procedure GoToURL(URL:String);
procedure Init;
procedure SetHtmStr(ClassDoc:TClassDoc);overload;
procedure SetHtmStr(TmpNode:TTreeNode;IsExport:Boolean);overload;
function GetHtmStr:String;
procedure LoadHtmlMode;
procedure DisplayHtmlPage;
procedure DisplayModalPage(ATitle,AInfo: String);
procedure ExportNodeToHtm(currentNode:TtreeNode);
procedure ExportSubjectToHtm(subject:String);
end;
TMainFrm = class(TForm)
suiForm1: TsuiForm;
Tbar_Main: TsuiToolBar;
TB_NewSubject: TToolButton;
TB_NewRootNode: TToolButton;
ImageList1: TImageList;
Pnl_TopMain: TPanel;
TB_NewNode: TToolButton;
TB_NewDoc: TToolButton;
Pnl_BottomMain: TPanel;
Pnl_LeftMain: TPanel;
Pnl_RightMain: TPanel;
Splitter1: TSplitter;
spcl_Main: TsuiPageControl;
stst_EditMode: TsuiTabSheet;
stst_ViewMode: TsuiTabSheet;
ToolButton6: TToolButton;
TB_EditNode: TToolButton;
TB_DelNode: TToolButton;
TB_AdvanceApply: TToolButton;
TB_ExportNode: TToolButton;
pnl_LTop: TPanel;
pnl_LBottom: TPanel;
StaticText1: TStaticText;
scbb_Subject: TsuiComboBox;
Panel1: TPanel;
WebBrowser1: TWebBrowser;
Pnl_REditTop: TPanel;
Pnl_REditBottom: TPanel;
suiGroupBox1: TsuiGroupBox;
mem_DocText: TMemo;
suiPageControl2: TsuiPageControl;
suiTabSheet3: TsuiTabSheet;
suiTabSheet4: TsuiTabSheet;
sTV_Main: TsuiTreeView;
sedt_title: TsuiEdit;
StaticText2: TStaticText;
sedt_Description: TsuiEdit;
StaticText3: TStaticText;
sedt_memo: TsuiEdit;
StaticText4: TStaticText;
sBtn_Submit: TSpeedButton;
scbb_HtmlMode: TsuiComboBox;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ImageList2: TImageList;
ActionList1: TActionList;
NewSubject: TAction;
NewRootNode: TAction;
NewNode: TAction;
NewDoc: TAction;
DelNode: TAction;
EditNode: TAction;
lbl_Status: TLabel;
TB_ExportSubject: TToolButton;
gge_MainStatus: TGauge;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
TB_About: TToolButton;
At_ExportSubject: TAction;
At_ExportNode: TAction;
At_ExitApplication: TAction;
At_help: TAction;
At_About: TAction;
At_HideWindows: TAction;
sPopMenu_Icon: TsuiPopupMenu;
mnl_show: TMenuItem;
Exit1: TMenuItem;
About1: TMenuItem;
suiImagePanel1: TsuiImagePanel;
suiImagePanel2: TsuiImagePanel;
suiGroupBox2: TsuiGroupBox;
slb_SearchRecList: TsuiListBox;
sedt_Search: TsuiEdit;
sb_search: TSpeedButton;
scb_like: TsuiCheckBox;
scbb_keyclass: TsuiComboBox;
StaticText6: TStaticText;
ToolButton3: TToolButton;
ImageList3: TImageList;
suiweb: TsuiTabSheet;
edurl: TsuiComboBox;
btnGo: TSpeedButton;
suiTabSheet1: TsuiTabSheet;
Panel2: TPanel;
SpeedButton2: TSpeedButton;
StaticText7: TStaticText;
edtSearch: TEdit;
spdBtnGoogleSearch: TSpeedButton;
tvSearch: TsuiTreeView;
ImageList4: TImageList;
Splitter2: TSplitter;
ToolButton4: TToolButton;
webbrowser2: TEmbeddedWB;
lblAddress: TLabel;
ToolButton5: TToolButton;
imgToolBar: TImageList;
imgPageControl: TImageList;
imgFavorite: TImageList;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
ImageList5: TImageList;
CoolBar1: TCoolBar;
procedure FormCreate(Sender: TObject);
procedure sTV_MainChange(Sender: TObject; Node: TTreeNode);
procedure NewSubjectExecute(Sender: TObject);
procedure NewRootNodeExecute(Sender: TObject);
procedure NewNodeExecute(Sender: TObject);
procedure NewDocExecute(Sender: TObject);
procedure scbb_SubjectChange(Sender: TObject);
procedure sBtn_SubmitClick(Sender: TObject);
procedure DelNodeExecute(Sender: TObject);
procedure EditNodeExecute(Sender: TObject);
procedure TB_AdvanceApplyClick(Sender: TObject);
procedure WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
procedure Pnl_RightMainMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure TB_NewSubjectMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure At_ExportSubjectExecute(Sender: TObject);
procedure At_ExportNodeExecute(Sender: TObject);
procedure At_ExitApplicationExecute(Sender: TObject);
procedure At_helpExecute(Sender: TObject);
procedure At_HideWindowsExecute(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure mnl_showClick(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure At_AboutExecute(Sender: TObject);
procedure sb_searchClick(Sender: TObject);
procedure slb_SearchRecListClick(Sender: TObject);
// procedure sbtn_hideLeftPnlClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure btnGoClick(Sender: TObject);
procedure edurlKeyPress(Sender: TObject; var Key: Char);
procedure spdBtnGoogleSearchClick(Sender: TObject);
procedure edtSearchKeyPress(Sender: TObject; var Key: Char);
procedure tvSearchChange(Sender: TObject; Node: TTreeNode);
procedure tvSearchDblClick(Sender: TObject);
procedure tvSearchClick(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure edtSearchEnter(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
private
DBookBrowser:TDBookBrowser;
MyIconData:NOTIFYICONDATA;//任务栏通知区图标信息
FSearchList:TList;
{ Private declarations }
public
procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; //注册热键
procedure WMSysMin(var Msg : TWMSYSCOMMAND); message WM_SYSCOMMAND; //扑捉最小化事件
procedure IconOnClick(var msg:TMessage); message WM_USER+1; //点击托盘图标时发生事件
procedure DBookInit;
function GetPassword(UserID:String):String;
procedure createNodeDir(currentNode:TtreeNode;basePath:string);
procedure LoadSubjectList;
procedure LoadSubjectNodeData(Subject:String;TreeView:TsuiTreeView);
function IsDocNode(TmpNode:TTreeNode):Boolean;
procedure DisplayTheNode(TmpNode:TTreeNode);
function GetRandomID(Table:String):integer;
function GetNodeId(TmpNode:TTreeNode):integer;
function getLastNode(CurNode:TTreeNode;Var NextNode:TtreeNode;Var isPnode:boolean):TtreeNode;
function getNodeCount(TmpNode:TTreeNode):integer; //获得当前节点所有子节点的数量(包括自己)
function getNodeNum(CurNode:TTreeNode):integer; //获得当前节点在全树中的排行
function getNodePath(currentNode,baseNode:TtreeNode;basePath:String):String;
procedure DelNodes(CurNode:TTreeNode);
procedure DelNodeRec(CurNode:TTreeNode);
procedure SaveIndexNode(CurNode:TTreeNode;AClass:TClassID );
procedure SaveDoc(CurNode:TTreeNode; ClassDoc: TClassDoc);
procedure UpdateIndexNode(CurNode:TTreeNode;AClass:TClassID);overload;
procedure UpdateIndexNode(TmpNode:TTreeNode);overload;
procedure UpdateDoc(ID:integer;ClassDoc:TClassDoc);
function RegHotKey(hwnd:THandle;AHotKey:String):Boolean;
function UTF8EncodeStr(W: WideString): String;
{ Public declarations }
end;
var
MainFrm: TMainFrm;
implementation
uses AddUnit,AdvanceUnit,TempUnit,SplashUnit,LoginUnit;
{$R *.dfm}
{TForm}
//=============================================================================//
procedure TMainFrm.DBookInit;
var
ClassDoc:TClassDoc;
DBPath,ConnectStr,TempStr,LastSubjectStr:String;
inifile:TInifile;
Index:integer;
begin
SplashFrm.sPB_Splash.Visible:=True;
SplashFrm.sPB_Splash.Max:=10;
SplashFrm.sPB_Splash.StepBy(1);
//初始化程序数据
ExePath:=ExtractFileDir(ParamStr(0));
UserID:='Demosoft';
if ExePath[Length(ExePath)]='\' then Delete(ExePath,Length(ExePath),1);
IniFileName:=ExePath+'\data\Config.ini';
HtmlModeFileName:=ExePath+'\data\HtmlCfg.dat';
if Not DirectoryExists(ExePath+'\data') then CreateDir(ExePath+'\data');
HotKeyId:=GlobalAddAtom('DBook.Demosoft'); //注册全局热键原子
FSearchList:=TList.Create; //初始化搜索字段(保存节点ID的LIST)
SplashFrm.sPB_Splash.StepIt; //1
//初始化ini文件
inifile:=TInifile.Create(IniFileName);
TempStr:=inifile.ReadString('常用设置','系统热键','');
if TempStr<>'' then RegHotKey(handle,TempStr);
ExportPath:=ExePath+'\OutPath'; //缺省的导出路径
if Not DirectoryExists(ExportPath) then CreateDir(ExportPath);
ExportPath:=inifile.ReadString('常用设置','导出网页路径',ExportPath);
if Not DirectoryExists(ExportPath) then ExportPath:=ExePath+'\OutPath'; //用缺省的路径
LastSubjectStr:=inifile.ReadString('常用设置','最近课题','');
inifile.Free;
//初始化TDBookBrowser类
DBookBrowser:=TDBookBrowser.Create;
DBookBrowser.Init;
SplashFrm.sPB_Splash.StepIt;
SplashFrm.sPB_Splash.StepIt; //3
//连接数据库
DBPath:=ExePath+'\data\Data.ddb';
ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
DBPath+';Jet OLEDB:Database Password=DEMOSOFT;Persist Security Info=False';
with ADOConnection1 do
begin
if Connected then Connected := False;
ConnectionString := ConnectStr;
end;
ADOQuery1.Connection:=ADOConnection1;
SplashFrm.sPB_Splash.StepIt; //4
//加载数据库数据
LoadSubjectList; //加载课题列表
Index:= scbb_Subject.Items.IndexOf(LastSubjectStr);
if Index<>-1 then scbb_Subject.ItemIndex:=Index;
SplashFrm.sPB_Splash.StepIt;
SplashFrm.sPB_Splash.StepIt;
LoadSubjectNodeData(scbb_Subject.Text,sTV_Main); //加载课题数据
PUserPassword:=GetPassword(UserID); //获得用户密码
if PUserPassword<>'' then
PIsNeedLogin:=True
else
PIsNeedLogin:=False;
SplashFrm.sPB_Splash.StepIt;
SplashFrm.sPB_Splash.StepIt;
SplashFrm.sPB_Splash.StepIt; //9
//制作托盘图标
MyIconData.cbSize :=sizeof(MyIconData);
MyIconData.Wnd :=handle;
MyIconData.uID :=1;
MyIconData.uFlags :=7;
MyIconData.uCallbackMessage :=WM_USER+1;
MyIconData.hIcon :=Application.Icon.Handle ;{用自己的icon}
TempStr:=Application.Title;
StrCopy(MyIconData.szTip,PChar(TempStr));
Shell_NotifyIcon(NIM_ADD,@MyIconData);
SplashFrm.sPB_Splash.StepIt; //10
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
DBookInit;
end;
procedure TMainFrm.FormShow(Sender: TObject);
begin
if PIsNeedLogin then
begin
With TLoginFrm.Create(Self) Do
begin
if ShowModal<>mrOk then
Application.Terminate
else
begin
PIsNeedLogin:=False;
Free;
end;
end;
end;
tvSearch.FullExpand;
edurl.Items.LoadFromFile(ExtractFilePath(Application.ExeName)+'\address.ini');
end;
procedure TMainFrm.FormClose(Sender: TObject; var Action: TCloseAction);
var
inifile:TIniFile;
begin
inifile:=TInifile.Create(IniFileName);
inifile.WriteString('常用设置','最近课题',scbb_Subject.Text);
inifile.Free;
end;
procedure TMainFrm.FormDestroy(Sender: TObject);
begin
FSearchList.Free;
Shell_NotifyIcon(NIM_DELETE,@MyIconData);
end;
//=============================================================================//
{Windows消息函数区}
//=============================================================================//
procedure TMainFrm.IconOnClick(var msg: TMessage);
var
p: TPoint;
begin
if (msg.lParam = WM_LBUTTONDBLCLK) then
begin
Show;
Application.Restore;
Application.BringToFront;
Exit;
end;
if (msg.lParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
if Self.Visible=True then
mnl_show.Caption:='隐藏(&H)'
else
mnl_show.Caption:='显示(&S)';
sPopMenu_Icon.Popup( p.x ,p.y );
exit;
end;
end;
procedure TMainFrm.WMHotKey(var Msg: TWMHotKey);
begin
if (Msg.HotKey =HotKeyID) and (Self.Visible=False) then
begin
Show;
Application.Restore;
Application.BringToFront;
end;
end;
procedure TMainFrm.WMSysMin(var Msg: TWMSYSCOMMAND);
begin
if (Msg.CmdType =61472) then
begin
//showMessage('最小化,对不对?');
Application.Minimize;
Hide;
Inherited;//调用先前的处理函数
end
else
Inherited;
end;
//=============================================================================//
{ TDBookBrowser }
//=============================================================================//
constructor TDBookBrowser.Create;
begin
FWebbrowser:= MainFrm.WebBrowser1;
FModeName:=TStringList.Create;
FModeContent:=TStringList.Create;
FModeCount:=0;
FHtmStr:='';
end;
destructor TDBookBrowser.Destroy;
begin
FModeName.Free;
FModeContent.Free;
inherited;
end;
procedure TDBookBrowser.DisplayHtmlPage;
var
VTmp: Variant;
HTMLDocument: IHTMLDocument2;
begin
VTmp := VarArrayCreate([0, 0], varVariant);
VTmp[0]:=FHtmStr;
HTMLDocument :=FWebBrowser.Document as IHTMLDocument2;
HTMLDocument.Write(PSafeArray(TVarData(VTmp).VArray));
HTMLDocument.Close;
end;
procedure TDBookBrowser.DisplayModalPage(ATitle,AInfo: String);
var
VTmp: Variant;
HTMLDocument: IHTMLDocument2;
TempStr,Buf:String;
TextF:Text;
begin
Assignfile(TextF,ExePath+'\data\ModalPage.dat');
Reset(TextF);
While Not Eof(TextF) Do
begin
Readln(TextF,Buf);
TempStr:=TempStr+Buf;
end;
CloseFile(TextF);
TempStr:=AnsiReplaceStr(TempStr,'[TITLE]',ATitle);
TempStr:=AnsiReplaceStr(TempStr,'[INFO]',AInfo);
VTmp := VarArrayCreate([0, 0], varVariant);
VTmp[0]:=TempStr;
HTMLDocument :=FWebBrowser.Document as IHTMLDocument2;
HTMLDocument.Write(PSafeArray(TVarData(VTmp).VArray));
HTMLDocument.Close;
end;
procedure TDBookBrowser.ExportNodeToHtm(currentNode: TtreeNode);
var
pi_id,pi_pid,pi_tmp:^integer;
s_Exepath,s_path,s_filename,s_dir,s_cpt,s_memo,s_content,s_des,s_subject,s_ltmf,s_ct:String;
str_html,str_temp:TStrings;
tmpNode,nextNode:TtreeNode;
isPnode:Boolean;
ClassDoc:TClassDoc;
begin
str_html:=TStringList.Create;
str_temp:=TStringList.Create;
s_Exepath:=ExtractFileDir(application.ExeName);
pi_id:=currentNode.Data;
isPnode:=false;
with MainFrm Do
begin
tempFrm:=TtempFrm.Create(MainFrm);
tempFrm.Caption:='导出当前节点';
tempFrm.Show;
tempFrm.Gauge1.MaxValue:=getNodeCount(currentNode);
//tempFrm.Gauge1.StepBy(1);
CreateNodeDir(currentNode,currentNode.Text);
tmpNode:=currentNode;
Repeat
tmpNode:=getLastNode(tmpNode,nextNode,isPnode);
pi_tmp:=tmpNode.Data;
if isDocNode(tmpNode) then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from DocData');
ADOQuery1.SQL.Add('Where id ='+InttoStr(getNodeId(tmpNode)));
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(tmpNode,True);
end;
//s_dir:=ExportPath+'\'+getNodePath(sTV_Main.Items[i],tmpNode,subject);
s_dir:=s_Exepath+'\OutPath\'+getNodePath(tmpNode,currentNode,currentNode.Text);
//CreateDirectory(PChar(s_dir),nil);
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.StepIt;
tempFrm.Gauge1.Progress :=tempFrm.Gauge1.Progress +1;
Application.ProcessMessages;
tmpNode:=nextNode;
Until pi_tmp^=pi_id^;
str_html.Free;
str_temp.Free;
tempFrm.Free;
end;
end;
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>&nbsp;&nbsp;&nbsp;&nbsp;'+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>&nbsp;&nbsp;&nbsp;&nbsp;'+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('发生未知错误: 该文档的数据被破坏...');
sedt_title.Text:=sTV_Main.Selected.Text;
sedt_Description.Text:='请在此处填上简单描述';
sedt_memo.Text:='请在此处填上备注';
mem_DocText.Text:='请在这里输入您要保存的文档';
//保存
ClassDoc.Title:= TmpNode.Text;
ClassDoc.Description :=sedt_Description.Text;
ClassDoc.MemoText:= sedt_memo.Text;
ClassDoc.DocText :='';
ClassDoc.CreateTime :=DateToStr(Date)+' '+TimeToStr(Time);
ClassDoc.LastModified :=ClassDoc.CreateTime;
ClassDoc.HtmlMode :='默认格式';
ClassDoc.Subject := scbb_Subject.Text;
ClassDoc.UserID :=UserID;
SaveDoc(TmpNode,ClassDoc);
DisplayTheNode(TmpNode); //重新加载
end;
end;
end
else
begin
//禁止编辑模式
mem_DocText.Lines.Clear;
sedt_title.Text:='';
sedt_Description.Text:='';
sedt_memo.Text:='';
scbb_HtmlMode.ItemIndex:=-1;
sBtn_Submit.Enabled:=False;
//加载数据
DBookBrowser.SetHtmStr(TmpNode,False);
DBookBrowser.DisplayHtmlPage;
end;
end;
procedure TMainFrm.createNodeDir(currentNode: TtreeNode; basePath: string);
var
s_tmp,s_dir:String;
str_temp:TStrings;
i,i_count:integer;
pi_id,pi_tmp:^integer;
isPnode:boolean;
tmpNode,nextNode:TtreeNode;
begin
str_temp:=TStringList.Create;
str_temp.Clear;
pi_id:=currentNode.Data;
isPnode:=false;
tmpNode:=currentNode;
Repeat
tmpNode:=getLastNode(tmpNode,nextNode,isPnode);
pi_tmp:=tmpNode.Data;
if Not isDocNode(tmpNode) then
begin
s_dir:= ExportPath+'\'+getNodePath(tmpNode,currentNode,basePath);
str_temp.Add(s_dir);
end;
tmpNode:=nextNode;
Until pi_tmp^=pi_id^;
str_temp.Add(ExportPath+'\'+basePath); //把basePath也增加了
i_count:=str_temp.Count;
for i:=i_count-1 Downto 0 Do
begin
CreateDir(str_temp.Strings[i]);
end;
end;
procedure TMainFrm.delNodeRec(CurNode: TTreeNode);
var
pi_id,pi_pid:^integer;
i_tmp:integer;
s_tmp:string;
begin
pi_id:=CurNode.Data;
s_tmp:=inttostr(pi_id^);
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete from IndexData where id ='+s_tmp);
ADOQuery1.ExecSQL;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete from DocData where id ='+s_tmp);
ADOQuery1.ExecSQL;
end;
procedure TMainFrm.delNodes(CurNode: TtreeNode);
var
tmpNode,nextNode:TtreeNode;
pi_tmp,pi_current:^integer;
s_tmp:String;
b_isPnode:boolean;
begin
//遍历所有子节点,并将之在数据库中删除
b_isPnode:=false;
tmpNode:=getLastNode(CurNode,nextNode,b_isPnode);
delNodeRec(tmpNode);
pi_tmp:=tmpNode.Data;
pi_current:=CurNode.Data;
While pi_tmp^<>pi_current^ Do
begin
tmpNode:=getLastNode(nextNode,nextNode,b_isPnode);
delNodeRec(tmpNode);
pi_tmp:=tmpNode.Data;
end;
//在树视图中删除该节点以及其所有子节点
CurNode.Delete;
end;
function TMainFrm.getLastNode(CurNode: TTreeNode; var NextNode: TtreeNode;
var isPnode: boolean): TtreeNode; //获得当前节点的最后一个子节点
var //该函数用来遍历树节点
tmpNode:TtreeNode;
begin
tmpNode:=CurNode;
While (tmpNode.getFirstChild<>nil) and Not isPnode Do
begin
tmpNode:=tmpNode.getFirstChild;
end;
result:=tmpNode;
if tmpNode.getNextSibling<>nil then
begin
nextNode:=tmpNode.getNextSibling;
isPnode:=False;
end
else if tmpNode.Parent <>nil then
begin
nextNode:=tmpNode.Parent;
isPnode:=True;
end
else
begin
nextNode:=nil;
isPnode:=false;
end;
end;
function TMainFrm.getNodeCount(TmpNode: TtreeNode): integer;
var
pNode,currentNode:TTreeNode;
i_id,i_tmp,i_count,i_num,i:integer;
begin
if Not Assigned(TmpNode) then
begin
Result:=sTV_Main.Items.Count;
Exit;
end;
if Not TmpNode.HasChildren then
begin
Result:=1;
Exit;
end;
i_num:=GetNodeNum(TmpNode);
pNode:=TmpNode;
While pNode.getNextSibling =nil Do
begin
pNode:=pNode.Parent;
if Not Assigned(pNode) then break;
end;
if Assigned(pNode) then
pNode:=pNode.getNextSibling
else //不存在当前节点的下个节点
begin
Result:=sTV_Main.Items.count-i_num;
Exit;
end;
//存在当前节点的下个节点处理
i_tmp:=getNodenum(pNode);
Result:=i_tmp-i_num;
end;
function TMainFrm.GetNodeId(TmpNode: TTreeNode): integer;
var
pi_id:^integer;
begin
if Assigned(TmpNode) then
pi_id:=TmpNode.Data
else
pi_id:=nil;
Result:=pi_id^;
end;
function TMainFrm.GetNodeNum(CurNode: TtreeNode): integer;
var
i,i_id,i_tmp,i_num:Integer;
begin
i_id:=getNodeId(CurNode);
for i:=0 to sTV_Main.Items.Count-1 Do
begin
i_tmp:=getNodeId(sTV_Main.Items[i]);
if i_tmp=i_id then
begin
i_num:=i;
break;
end;
end;
Result:=i_num;
end;
function TMainFrm.getNodePath(currentNode, baseNode: TtreeNode;
basePath: String): String;
var
s_tmp:String;
i:integer;
tmpNode:TtreeNode;
begin
if Assigned(currentNode) then
begin
tmpNode:=currentNode;
s_tmp:=currentNode.Text;
for i:=baseNode.Level+1 to currentNode.Level Do
begin
s_tmp:=tmpNode.Parent.Text +'\'+s_tmp;
tmpNode:=tmpNode.Parent;
end;
s_tmp:=basePath+'\'+s_tmp;
Result:=s_tmp;
end
else
Result:='NULL';
end;
function TMainFrm.GetRandomID(Table: String): integer;
var
i_id:integer;
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Insert into '+Table+'(Nodekind,UserID)');
ADOQuery1.SQL.Add('Values("TmpNode","'+UserID+'")');
ADOQuery1.ExecSQL;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select ID from '+Table);
ADOQuery1.SQL.Add('Where Nodekind="TmpNode"');
ADOQuery1.Open;
i_id:=ADOquery1.FieldByName('ID').AsInteger;
if i_id=0 then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('delete from IndexData');
ADOQuery1.SQL.Add('Where ID=0');
ADOQuery1.ExecSQL;
Result:=getRandomId('IndexData');
Exit;
end;
Result:=i_id;
end;
procedure TMainFrm.SaveDoc(CurNode: TTreeNode; ClassDoc: TClassDoc);
var
pi_id:^integer;
MemoStream: TMemoryStream;
begin
if Not Assigned(CurNode) then
begin
ShowMessage('Debug: 此节点不存在!No Such Node!');
Exit;
end;
pi_id:=CurNode.Data;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('insert into DocData(ID,DocText,Description,MemoText,CreateTime,LastModified,Caption,Subject,HtmlMode,UserID)');
ADOQuery1.SQL.Add('values(:id,:Doc,:dspt,:mm,:ct,:ltm,:cpt,:subject,:Mode,:userid)');
ADOQuery1.Parameters.ParamByName('id').Value:=pi_id^;
ADOQuery1.Parameters.ParamByName('Doc').Value:=ClassDoc.DocText;
ADOQuery1.Parameters.ParamByName('dspt').Value:=ClassDoc.Description;
ADOQuery1.Parameters.ParamByName('mm').Value:= ClassDoc.MemoText;
ADOQuery1.Parameters.ParamByName('ct').Value:=ClassDoc.CreateTime;
ADOQuery1.Parameters.ParamByName('ltm').Value:=ClassDoc.LastModified;
ADOQuery1.Parameters.ParamByName('cpt').Value:=ClassDoc.Title ;
ADOQuery1.Parameters.ParamByName('subject').Value:=ClassDoc.Subject;
ADOQuery1.Parameters.ParamByName('Mode').Value:=ClassDoc.HtmlMode;
ADOQuery1.Parameters.ParamByName('userid').Value:=ClassDoc.UserID;
ADOQuery1.ExecSQL;
end;
procedure TMainFrm.SaveIndexNode(CurNode: TTreeNode;AClass:TClassID);
begin
UpdateIndexNode(CurNode,AClass);
end;
procedure TMainFrm.UpdateDoc(ID: integer; ClassDoc: TClassDoc);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Update DocData SET DocText=:Doc,Description=:dpt,MemoText=:mt,LastModified=:ltm,Caption=:cpt,subject=:subject,HtmlMode=:Mode');
ADOQuery1.SQL.Add('Where id='+InttoStr(ID));
ADOQuery1.Parameters.ParamByName('Doc').Value:=ClassDoc.DocText;
ADOQuery1.Parameters.ParamByName('dpt').Value:=ClassDoc.Description;
ADOQuery1.Parameters.ParamByName('mt').Value:=ClassDoc.MemoText;
ADOQuery1.Parameters.ParamByName('ltm').Value:=ClassDoc.LastModified;
ADOQuery1.Parameters.ParamByName('cpt').Value:=ClassDoc.Title;
ADOQuery1.Parameters.ParamByName('subject').Value:=ClassDoc.Subject;
ADOQuery1.Parameters.ParamByName('Mode').Value:=ClassDoc.HtmlMode;
ADOQuery1.ExecSQL;
end;
procedure TMainFrm.UpdateIndexNode(CurNode: TTreeNode; AClass:TClassID);
var
pi_id,pi_pid:^integer;
i_level,i_index:integer;
s_cpt,s_kind,s_subject,s_sql:string;
TmpNode:TtreeNode;
begin
New(pi_id);
New(pi_pid);
Case AClass of
CIDSubject:
begin
s_cpt:='';
s_subject:=scbb_Subject.Text;
s_kind:='subject';
i_level:=-1;
i_index:=0;
pi_id^:=getRandomId('IndexData');
pi_pid^:=0;
end;
CIDRootNode:
begin
s_cpt:=CurNode.Text;
s_subject:=scbb_Subject.Text;
s_kind:='wangle';
i_level:=CurNode.Level;
i_index:=CurNode.Index;
pi_id:=CurNode.data;
pi_pid^:=0;
end;
CIDNode:
begin
s_cpt:=CurNode.Text;
s_subject:=scbb_Subject.Text;
s_kind:='wangle';
i_level:=CurNode.Level;
i_index:=CurNode.Index;
pi_id:=CurNode.data;
if Assigned(CurNode.Parent) then
pi_pid:=CurNode.Parent.Data
else
pi_pid^:=0;
end;
CIDDoc:
begin
s_cpt:=CurNode.Text;
s_subject:=scbb_Subject.Text;
s_kind:='document';
i_level:=CurNode.Level;
i_index:=CurNode.Index;
pi_id:=CurNode.data;
pi_pid:=CurNode.Parent.Data;
end;
end;
s_sql:='Update IndexData SET pid=:pid,NodeCaption=:nodecaption,nodelevel=:nodelevel,'
+'nodeindex=:nodeindex,nodekind=:nodekind,subject=:subject';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(s_sql);
ADOQuery1.SQL.Add('Where Id='+IntToStr(pi_id^));
ADOQuery1.Parameters.ParamByName('PID').Value:=pi_pid^;
ADOQuery1.Parameters.ParamByName('Nodelevel').Value:=i_level;
ADOQuery1.Parameters.ParamByName('nodeindex').Value:=i_index;
ADOQuery1.Parameters.ParamByName('nodekind').Value:=s_kind;
ADOQuery1.Parameters.ParamByName('nodecaption').Value:=s_cpt;
ADOQuery1.Parameters.ParamByName('subject').Value:=s_subject;
ADOQuery1.ExecSQL;
end;
procedure TMainFrm.UpdateIndexNode(TmpNode: TTreeNode);
var
pi_id,pi_pid:^integer;
i_level,i_index:integer;
s_cpt,s_kind,s_subject,s_sql:string;
begin
New(pi_id);
New(pi_pid);
s_cpt:=TmpNode.Text;
s_subject:=scbb_Subject.Text;
s_kind:='wangle';
i_level:=TmpNode.Level;
i_index:=TmpNode.Index;
pi_id:=TmpNode.data;
if i_level<>0 then
pi_pid:=TmpNode.Parent.Data
else
pi_pid^:=0;
pi_id:=TmpNode.Data;
s_sql:='Update IndexData SET pid=:pid,NodeCaption=:nodecaption,nodelevel=:nodelevel,'
+'nodeindex=:nodeindex,nodekind=:nodekind,subject=:subject';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(s_sql);
ADOQuery1.SQL.Add('Where ID='+IntToStr(pi_id^));
ADOQuery1.Parameters.ParamByName('PID').Value:=pi_pid^;
ADOQuery1.Parameters.ParamByName('Nodelevel').Value:=i_level;
ADOQuery1.Parameters.ParamByName('nodeindex').Value:=i_index;
ADOQuery1.Parameters.ParamByName('nodekind').Value:=s_kind;
ADOQuery1.Parameters.ParamByName('nodecaption').Value:=s_cpt;
ADOQuery1.Parameters.ParamByName('subject').Value:=s_subject;
ADOQuery1.ExecSQL;
end;
//=============================================================================//
procedure TMainFrm.NewSubjectExecute(Sender: TObject);
var
Index:integer;
TempStr:String;
begin
With TAddFrm.Create(Self) Do
begin
Caption:='新建课题';
lbl_Caption.Caption:='课题名';
lbl_Info.Caption :='注意不要输入重复的课题,字数不要超过50个ASCII字符';
srb_borther.Visible :=False;
srb_son.Visible :=False;
if ShowModal=mrOk then
begin
Index:=scbb_Subject.Items.Add(sedt_caption.Text);
scbb_Subject.ItemIndex:=Index;
SaveIndexNode(nil,CIDSubject);
sTV_Main.Items.Clear;
TempStr:='<b>提示</b><p>'
+'新建好的课题是空的课题,您必须添加目录和文档到课题。<br><br>'
+'在没有根目录的时候是不能直接添加文档的,所以您至少要为该课题新建一个根节点(根目录)。<br>'
+'您可以点击“新建根节点(根目录)”在该课题下新建一个根目录。<br>';
DBookBrowser.DisplayModalPage('新建课题'+sedt_caption.Text,Tempstr);
end;
Free;
end;
end;
procedure TMainFrm.NewRootNodeExecute(Sender: TObject);
var
pi_id:^integer;
TmpNode:TTreeNode;
TempStr:String;
begin
New(pi_id);
with TAddFrm.Create(self) do
begin
Caption:='新建根类别';
lbl_Caption.Caption:='根类别名';
lbl_Info.Caption :='注意字数不要超过255个ASCII字符';
srb_borther.Visible :=False;
srb_son.Visible :=False;
if ShowModal=mrOk then
begin
pi_id^:=getRandomId('IndexData');
TmpNode:=sTV_Main.Items.AddObject(nil,sedt_caption.text,pi_id);
TmpNode.ImageIndex:=1;
TmpNode.SelectedIndex:=TmpNode.ImageIndex; //保持选中时和没有选中时节点图标相同
SaveIndexNode(TmpNode,CIDRootNode);
TmpNode.Selected :=True;
TempStr:='<b>提示</b><p>'
+'现在您可以选择添加文档,如果您想分得更细的话可以新建子类别<br><br>'
+'如果您还想新建根类别的话只需再次新建根类别。<br>';
DBookBrowser.DisplayModalPage('新建根类别'+sedt_caption.Text,Tempstr);
end;
free;
end;
end;
procedure TMainFrm.NewNodeExecute(Sender: TObject);
var
pi_id:^integer;
TmpNode:TTreeNode;
TempStr:string;
begin
New(pi_id);
if sTV_Main.Selected =nil then Exit;
if IsDocNode(sTV_Main.Selected) then
begin
MessageBox(Handle,'文档下面不能再添加类别!','提示',MB_OK + MB_ICONERROR);
Exit;
end;
with TAddFrm.Create(self) do
begin
Caption:='新建子类别';
lbl_Caption.Caption:='子类别名';
lbl_Info.Caption :='注意字数不要超过255个ASCII字符';
if ShowModal=mrOk then
begin
pi_id^:=getRandomId('IndexData');
if srb_Borther.Checked then
begin
TmpNode:=sTV_Main.Items.AddObject(sTV_Main.Selected,sedt_caption.text,pi_id);
end
else
begin
TmpNode:=sTV_Main.Items.AddChildObject(sTV_Main.Selected,sedt_caption.text,pi_id);
end;
TmpNode.ImageIndex:=2;
TmpNode.SelectedIndex:=TmpNode.ImageIndex; //保持选中时和没有选中时节点图标相同
SaveIndexNode(TmpNode,CIDNode);
TmpNode.Selected :=True;
TempStr:='<b>提示</b><p>'
+'现在您可以选择添加文档,如果您想分得更细的话可以新建子类别<br><br>'
+'如果您还想新建同级类别可以在新建子类别时选择同级类别<br>';
DBookBrowser.DisplayModalPage('新建子类别'+sedt_caption.Text,Tempstr);
end;
free;
end;
end;
procedure TMainFrm.NewDocExecute(Sender: TObject);
var
pi_id:^integer;
TmpNode:TTreeNode;
ClassDoc:TClassDoc;
begin
New(pi_id);
if sTV_Main.Selected =nil then Exit;
with TAddFrm.Create(self) do
begin
Caption:='新建文档';
lbl_Caption.Caption:='文档名';
lbl_Info.Caption :='注意字数不要超过255个ASCII字符';
if ShowModal=mrOk then
begin
pi_id^:=getRandomId('IndexData');
if Not IsDocNode(sTV_Main.Selected) then //子集文档
TmpNode:=sTV_Main.Items.AddChildObject(sTV_Main.Selected,sedt_caption.text,pi_id)
else //同级文档
TmpNode:=sTV_Main.Items.AddObject(sTV_Main.Selected,sedt_caption.text,pi_id);
TmpNode.ImageIndex:=3;
TmpNode.SelectedIndex:=TmpNode.ImageIndex; //保持选中时和没有选中时节点图标相同
ClassDoc.Title:=sedt_caption.text;
ClassDoc.Description :='在此处输入简单摘要';
ClassDoc.MemoText :='在此处输入备注';
ClassDoc.CreateTime:=DateToStr(Date)+' '+TimeToStr(Time);
ClassDoc.LastModified :=ClassDoc.CreateTime;
ClassDoc.DocText :='';
ClassDoc.Subject :=scbb_Subject.Text;
ClassDoc.UserID:=UserID;
ClassDoc.HtmlMode:='默认格式';
SaveIndexNode(TmpNode,CIDDoc);
SaveDoc(TmpNode,ClassDoc);
TmpNode.Selected :=True;
spcl_Main.ActivePage:= stst_EditMode;
mem_DocText.Text :='请在这里输入您要保存的文档...';
mem_DocText.SelectAll;
end;
free;
end;
end;
procedure TMainFrm.DelNodeExecute(Sender: TObject);
var
TmpNode:TTreeNode;
s_name,s_tmp:String;
begin
TmpNode:=sTV_Main.Selected;
if Not Assigned(TmpNode) then Exit;
if isDocNode(tmpNode) then
begin
if MessageBox(handle,'真的要删除该文档记录吗?','提示',MB_OKCANCEL+MB_ICONWARNING)=IDOK then
begin
delNodes(tmpNode); //如果为文档类型就在数据库删除文件
sTV_Main.SetFocus;
end;
end
else
begin
s_name:=tmpNode.Text;
if tmpNode.HasChildren Then
s_tmp:='此操作将会使 "'+s_name+'" 类别下所有子类别和子文档全部被清除,真的要删除该类别吗?'
else
s_tmp:='将要删除类别"'+s_name+'",真的要删除吗?';
if MessageBox(handle,PChar(s_tmp),'提示',MB_OKCANCEL+MB_ICONWARNING)=IDOK then
delNodes(tmpNode);
end;
end;
procedure TMainFrm.EditNodeExecute(Sender: TObject);
var
TmpNode:TTreeNode;
ClassID:TClassId;
begin
TmpNode:= sTV_Main.Selected;
if Not Assigned(TmpNode) then Exit;
if IsDocNode(TmpNode) then
begin
spcl_Main.ActivePage :=stst_EditMode;
sBtn_Submit.Enabled:=True;
mem_DocText.SelectAll;
end
else
begin
With TAddFrm.Create(Self) Do
begin
AddsFrm.Caption:='编辑类别';
Caption:='编辑类别';
lbl_caption.Caption:='类别名';
lbl_info.Caption :='注意不要超过50个';
sEdt_caption.Text :=TmpNode.Text;
srb_Borther.Visible :=False;
srb_Son.Visible :=False;
if ShowModal =mrOk then
begin
TmpNode.Text:=sEdt_caption.Text;
UpdateIndexNode(TmpNode);
end;
Free;
end;
end;
end;
procedure TMainFrm.At_ExportSubjectExecute(Sender: TObject);
begin
if scbb_Subject.Text ='' then Exit;
DBookBrowser.ExportSubjectToHtm(scbb_Subject.Text);
end;
procedure TMainFrm.At_ExportNodeExecute(Sender: TObject);
var
PathStr,OutPathStr:String;
begin
if Not Assigned(sTV_Main.Selected) then Exit;
DBookBrowser.ExportNodeToHtm(sTV_Main.Selected);
end;
procedure TMainFrm.At_ExitApplicationExecute(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMainFrm.At_helpExecute(Sender: TObject);
var
TempStr:String;
begin
// TempStr:=ExePath+'\data\help\Index.htm';
// //MessageBox(Handle,'很容易的,自己用着吧!','提示',MB_OK+MB_ICONINFORMATION);
// shellexecute(0,'Open',PChar(TempStr), '','',1);
With TSplashFrm.Create(Self) Do
begin
sPB_Splash.Visible:=False;
lbl_Close.Visible:=True;
ShowModal;
Free;
end;
end;
procedure TMainFrm.At_HideWindowsExecute(Sender: TObject);
begin
Application.Minimize;
Hide;
end;
//=============================================================================//
procedure TMainFrm.sTV_MainChange(Sender: TObject; Node: TTreeNode);
begin
DisplayTheNode(Node);
spcl_Main.ActivePage :=stst_ViewMode;
end;
procedure TMainFrm.scbb_SubjectChange(Sender: TObject);
var
vv: Variant;
HTMLDocument: IHTMLDocument2;
s_htm:String;
i_num1,i_num2,i:integer;
begin
sTV_Main.Items.Clear;
//禁止编辑模式
mem_DocText.Lines.Clear;
sedt_title.Text:='';
sedt_Description.Text:='';
sedt_memo.Text:='';
scbb_HtmlMode.ItemIndex:=-1;
sBtn_Submit.Enabled:=False;
sBtn_Submit.Enabled:=False;
gge_MainStatus.Progress:=0;
gge_MainStatus.Visible:=True;
LoadSubjectNodeData(scbb_Subject.Text,sTV_Main);
Sleep(10);
gge_MainStatus.Visible:=False;
i_num1:=0;
i_num2:=0;
for i:=0 to sTV_Main.Items.Count-1 Do
begin
if isDocNode(sTV_Main.items[i]) then
i_num1:=i_num1+1
else
i_num2:=i_num2+1;
end;
s_htm:='<html>'
+'<head>'
+'<title>[课题:'+scbb_Subject.Text+']</title>'
+'<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>'
+'</head>'
+'<body bgcolor="#eeeeee">'
+'<b>课题:'+scbb_Subject.Text+'</b>'
+'<hr>'
+'<br>'
+'相关记录如下...<br>'
+'<br>'
+'该课题总共有节点'+InttoStr(sTV_Main.Items.Count)+'个<br>'
+'该课题总共有文档'+InttoStr(i_num1)+'个<br>'
+'该课题总共有类别'+InttoStr(i_num2)+'个<br>'
+'<br>'
+'<hr>'
+'</body>'
+'</html>';
vv := VarArrayCreate([0, 0], varVariant);
vv[0]:=s_htm;
HTMLDocument :=MainFrm.WebBrowser1.Document as IHTMLDocument2;
HTMLDocument.Write(PSafeArray(TVarData(vv).VArray));
HTMLDocument.Close;
end;
procedure TMainFrm.sBtn_SubmitClick(Sender: TObject);
var
ClassDoc:TClassDoc;
id:Integer;
begin
if Not Assigned(sTV_Main.Selected) then
begin
showMessage('没有选中的文档可更新');
Exit;
end;
ClassDoc.LastModified :=DateToStr(Date)+' '+TimeToStr(Time);
ClassDoc.Title:=sedt_title.Text;
ClassDoc.Description :=sedt_Description.Text;
ClassDoc.MemoText:=sedt_Memo.Text;
ClassDoc.DocText:=mem_DocText.Text;
ClassDoc.HtmlMode:=scbb_HtmlMode.Text;
ClassDoc.Subject:=scbb_Subject.Text;
ClassDoc.UserID:=UserID;
sTV_Main.Selected.Text:=sedt_title.Text;
id:=GetNodeId(sTV_Main.Selected);
UpdateDoc(id,ClassDoc);
UpdateIndexNode(sTV_Main.Selected,CIDDoc);
DisplayTheNode(sTV_Main.Selected);
spcl_Main.ActivePage :=stst_ViewMode;
end;
procedure TMainFrm.TB_AdvanceApplyClick(Sender: TObject);
begin
with TAdvanceFrm.Create(Self) Do
begin
ShowModal;
Free;
end;
DBookBrowser.LoadHtmlMode;
edurl.items.LoadFromFile(ExtractFilePath(Application.ExeName)+'\address.ini');
end;
procedure TMainFrm.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
var
s_nodeText,s_tmp:String;
i_count,i_size,i:integer;
tmpNode:TtreeNode;
begin
i_size:=Length(CS_LINKPL);
tmpNode:=sTV_Main.Selected;
if MidStr(URL,1,i_size)=CS_LINKPL then
begin
s_tmp:=MidStr(URL,i_size+1,(Length(URL)-i_size));
s_tmp:=AnsiReplaceStr(s_tmp,'%20',' ');
tmpNode:=tmpNode.getFirstChild;
while InttoStr(tmpNode.index)<>s_tmp Do
begin
tmpNode:=tmpNode.getNextSibling;
end;
tmpNode.Selected:=True;
end;
end;
procedure TMainFrm.Pnl_RightMainMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
lbl_Status.Caption:='';
end;
procedure TMainFrm.TB_NewSubjectMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var
TagIndex:Integer;
begin
TagIndex:=(Sender As TToolButton).Tag;
Case TagIndex of
1:lbl_Status.Caption:='新建一个课题';
2:lbl_Status.Caption:='新建一个根类别(根目录)';
3:lbl_Status.Caption:='新建一个子类别(子目录)';
4:lbl_Status.Caption:='新建一个文档';
5:lbl_Status.Caption:='编辑类别或者文档';
6:lbl_Status.Caption:='删除一个类别或者文档';
7:lbl_Status.Caption:='高级应用,系统设置等';
8:lbl_Status.Caption:='将当前选中的节点导出成网页';
9:lbl_Status.Caption:='将当前课题导出成网页';
10:lbl_Status.Caption:='帮助主题,有任何疑问请来信 etu5@163.com';
11:lbl_Status.Caption:='关于DBook';
12:lbl_Status.Caption:='隐藏主窗口 -它将最小化存在于您的托盘内';
end;
end;
//=============================================================================//
procedure TMainFrm.mnl_showClick(Sender: TObject);
begin
if mnl_show.Caption ='显示(&S)' then
begin
Show;
Application.Restore;
Application.BringToFront;
end
else
begin
Application.Minimize;
Hide;
end;
end;
procedure TMainFrm.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMainFrm.At_AboutExecute(Sender: TObject);
begin
//MessageBox(Handle,'哈哈 外星人你还不认识? 打你屁股 :)','提示',MB_OK+MB_ICONINFORMATION);
With TSplashFrm.Create(Self) Do
begin
sPB_Splash.Visible:=False;
lbl_Close.Visible:=True;
ShowModal;
Free;
end;
end;
procedure TMainFrm.sb_searchClick(Sender: TObject);
var
SubjectStr,KeyStr,KeyClass,TempStr:String;
IsLikeSearch:Boolean;
Index:Integer;
P_id:^Integer;
begin
slb_SearchRecList.Items.Clear;
FSearchList.Clear;
SubjectStr:=scbb_Subject.Text;
KeyStr:=sedt_Search.Text;
if scb_like.Checked then
IsLikeSearch:=True
else
IsLikeSearch:=False;
Index:=scbb_keyclass.Items.IndexOf(scbb_keyclass.Text);
case Index of
0:KeyClass:='Caption';
1:KeyClass:='Description';
2:KeyClass:='MemoText';
3:KeyClass:='DocText';
4:KeyClass:='CreateTime';
5:KeyClass:='LastModified';
end;
if IsLikeSearch then
TempStr:= 'Where Subject="'+SubjectStr+'" and '+KeyClass+' like "'+KeyStr+'%"'
else
TempStr:= 'Where Subject="'+SubjectStr+'" and '+KeyClass+' = "'+KeyStr+'"';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select Caption,ID From DocData');
ADOQuery1.SQL.Add(TempStr);
ADOQuery1.Open;
While Not ADOQuery1.Eof Do
begin
New(p_id);
TempStr:=ADOQuery1.fieldByName('Caption').AsString;
p_id^:= ADOQuery1.fieldByName('ID').AsInteger;
slb_SearchRecList.Items.Add(TempStr);
FSearchList.Add(p_id);
ADOQuery1.Next;
end;
end;
procedure TMainFrm.slb_SearchRecListClick(Sender: TObject);
var
Index,i:Integer;
p_id,P_tmpid:^Integer;
ClassDoc:TClassDoc;
begin
Index:=slb_SearchRecList.ItemIndex;
p_id:=FSearchList.Items[Index];
//遍历全部节点
for i:=0 to sTV_Main.Items.Count-1 Do
begin
P_tmpid:=sTV_Main.Items[i].Data;
if p_tmpid^=p_id^ then
begin
sTV_Main.Items[i].Selected:=True;
end;
end;
{ 垃圾
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * from DocData');
ADOQuery1.SQL.Add('Where ID='+IntToStr(p_id^));
ADOQuery1.Open;
if ADOQuery1.RecordCount >0 then
begin
ClassDoc.Title:=ADOQuery1.FieldByName('Caption').AsString;
ClassDoc.Description:=ADOQuery1.FieldByName('Description').AsString;
ClassDoc.MemoText:=ADOQuery1.FieldByName('MemoText').AsString;
ClassDoc.DocText:=ADOQuery1.FieldByName('DocText').AsString;
ClassDoc.HtmlMode:=ADOQuery1.FieldByName('HtmlMode').AsString;
ClassDoc.LastModified:=ADOQuery1.FieldByName('LastModified').AsString;
ClassDoc.CreateTime:=ADOQuery1.FieldByName('CreateTime').AsString;
ClassDoc.UserID:=ADOQuery1.FieldByName('UserID').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;
spcl_Main.ActivePage :=stst_ViewMode;
end;
}
end;
procedure TMainFrm.btnGoClick(Sender: TObject);
begin
spcl_Main.ActivePage:=suiweb;
webbrowser2.Navigate(edurl.Text);
end;
procedure TMainFrm.edurlKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then begin
//spdBtnGoogleSearch.Click;
//btnGo.Click;
webbrowser2.Navigate(edurl.text);
spcl_Main.ActivePage:=suiweb;
end;
end;
procedure TMainFrm.spdBtnGoogleSearchClick(Sender: TObject);
begin
spcl_Main.ActivePage:=suiweb;
webbrowser2.Navigate('http://www.google.cn/search?hl=zh-CN&q='+edtSearch.Text);
end;
procedure TMainFrm.edtSearchKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then begin
spdBtnGoogleSearch.Click;
end;
end;
procedure TMainFrm.tvSearchChange(Sender: TObject; Node: TTreeNode);
begin
tvSearch.FullExpand;
end;
procedure TMainFrm.tvSearchDblClick(Sender: TObject);
begin
if (tvSearch.Selected.parent = nil) then exit;
spcl_Main.ActivePage:=suiweb;
if (tvSearch.Selected.Parent.Text='') then begin
end else if (tvSearch.Selected.Parent.Text='网页') then begin
if (tvSearch.Selected.Text='百度') then begin
webBrowser2.Navigate('http://www.baidu.com/s?wd='+edtSearch.Text);
end else if (tvSearch.Selected.Text='Google') then begin
webBrowser2.Navigate('http://www.google.cn/search?hl=zh-CN&q='+edtSearch.Text);
end else if (tvSearch.Selected.Text='Bing') then begin
webBrowser2.Navigate('http://cn.bing.com/search?q='+edtSearch.Text+'&form=QBRE&filt=all');
end else if (tvSearch.Selected.Text='Yahoo') then begin
webBrowser2.Navigate('http://one.cn.yahoo.com/s?p='+edtSearch.Text+'');
end else if (tvSearch.Selected.Text='搜狗') then begin
webBrowser2.Navigate('http://www.sogou.com/sohu?query='+edtSearch.Text+'');
//http://www.gougou.com/search?search=
end;
end else if (tvSearch.Selected.Parent.Text='图片') then begin
if (tvSearch.Selected.Text='百度') then begin
webBrowser2.Navigate('http://image.baidu.com/i?tn=baiduimage&ct=201326592&lm=-1&cl=2&word='+edtSearch.Text);
end else if (tvSearch.Selected.Text='Google') then begin
webBrowser2.Navigate('http://images.google.cn/images?hl=zh-CN&q='+edtSearch.Text+'&ie=GBK&sa=N&tab=li');
end;
end else if (tvSearch.Selected.Parent.Text='视频') then begin
if (tvSearch.Selected.Text='百度') then begin
webBrowser2.Navigate('http://video.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=7&word='+edtSearch.Text);
end;
end else if (tvSearch.Selected.Parent.Text='mp3') then begin
if (tvSearch.Selected.Text='百度') then begin
webBrowser2.Navigate('http://mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&word='+edtSearch.Text);
end else if (tvSearch.Selected.Text='Google') then begin
webBrowser2.Navigate('http://www.google.cn/music/search?q='+UTF8EncodeStr(edtSearch.text)+'&aq=f ');
end;
end else if (tvSearch.Selected.Parent.Text='生活') then begin
if (tvSearch.Selected.Text='百度知道') then begin
webBrowser2.Navigate('http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word='+edtSearch.Text);
end;
end else if (tvSearch.Selected.Parent.Text='地图') then begin
if (tvSearch.Selected.Text='百度') then begin
webBrowser2.Navigate('http://map.baidu.com/#word='+edtSearch.Text);
end else if (tvSearch.Selected.Text='Google') then begin
webBrowser2.Navigate('http://ditu.google.cn/maps?hl=zh-CN&q='+edtSearch.Text+'&ie=GBK&sa=N&tab=vl');
end;
end else if (tvSearch.Selected.Parent.Text='软件') then begin
//http://www.gougou.com/search?search=地球&id=1
end else if (tvSearch.Selected.Parent.Text='游戏') then begin
if (tvSearch.Selected.Text='百度') then begin
webBrowser2.Navigate('http://video.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=7&word='+edtSearch.Text);
end;
end else if (tvSearch.Selected.Parent.Text='社区博客') then begin
if (tvSearch.Selected.Text='百度贴吧') then begin
webBrowser2.Navigate('http://tieba.baidu.com/f?kw='+edtSearch.Text);
end;
end;
// Showmessage(tvSearch.Selected.Text);
tvSearch.FullExpand;
spcl_Main.ActivePage:=suiweb;
//webbrowser2.Navigate(suiComboBox1.Text);
end;
procedure TMainFrm.tvSearchClick(Sender: TObject);
begin
//tvSearch.FullExpand;
end;
procedure TMainFrm.ToolButton4Click(Sender: TObject);
begin
close;
end;
procedure TMainFrm.SpeedButton1Click(Sender: TObject);
begin
webbrowser2.Navigate(edurl.text);
end;
function TMainFrm.UTF8EncodeStr(W: WideString):String;
var U: UTF8String;
i: Integer;
begin
Result := '';
U := UTF8Encode(W);
for i:=1 to Length(U) do
Result:=Result+'%'+IntToHex(Ord(U[i]),2);
end;
procedure TMainFrm.edtSearchEnter(Sender: TObject);
begin
if edtsearch.text='输入关键词...' then edtsearch.Text:='';
end;
procedure TMainFrm.N1Click(Sender: TObject);
begin
if Pnl_LeftMain.Visible=True then
begin
Pnl_LeftMain.Visible:=False;
n1.Caption:='显示左面板';
end
else
begin
Pnl_LeftMain.Visible:=True;
n1.Caption:='隐藏左面板';
end;
end;
procedure TMainFrm.N3Click(Sender: TObject);
begin
webbrowser2.GoBack;
end;
procedure TMainFrm.N4Click(Sender: TObject);
begin
webbrowser2.GoForward;
end;
Initialization
OleInitialize(nil);
Finalization
try
OleUninitialize;
except
end;
end.
Delphi
1
https://gitee.com/mellen/dbooks.git
git@gitee.com:mellen/dbooks.git
mellen
dbooks
dbooks
master

搜索帮助