慢慢看吧,这是我的一个小程序,整理资料,可以拖放文件我网叶,并保存与数据库中
要源码吗????
unit fabao;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl, StdCtrls, ComCtrls, ToolWin, ExtCtrls, Menus, Buttons, Tabnotbk,
Grids, DBGrids, Db, DBTables, DBCtrls, Mask,DropURLTarget,
ImgList,shellapi, DropSource, DropTarget, ExtDlgs;
type
TmainForm = class(TForm)
StatusBar1: TStatusBar;
Panel1: TPanel;
Panel2: TPanel;
MainMenu1: TMainMenu;
N1: TMenuItem;
N31: TMenuItem;
N27: TMenuItem;
N28: TMenuItem;
N29: TMenuItem;
N30: TMenuItem;
N2: TMenuItem;
N25: TMenuItem;
N26: TMenuItem;
N3: TMenuItem;
N22: TMenuItem;
N23: TMenuItem;
N24: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N18: TMenuItem;
treeview2: TMenuItem;
N21: TMenuItem;
N6: TMenuItem;
N20: TMenuItem;
N19: TMenuItem;
Popup1: TPopupMenu;
ncopy: TMenuItem;
npaste: TMenuItem;
ndel: TMenuItem;
ImageList1: TImageList;
Timer1: TTimer;
FontDialog1: TFontDialog;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Splitter1: TSplitter;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TreeView1: TTreeView;
DataSource1: TDataSource;
SpeedButton2: TSpeedButton;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
ComboBox1: TComboBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
DBGrid2: TDBGrid;
DBMemo1: TDBMemo;
DBGrid1: TDBGrid;
N32: TMenuItem;
nnew: TMenuItem;
Nrename: TMenuItem;
ToolBar1: TToolBar;
new: TToolButton;
del: TToolButton;
refresh: TToolButton;
font: TToolButton;
exit: TToolButton;
help: TToolButton;
find: TToolButton;
open: TToolButton;
BitBtn1: TBitBtn;
ImageList2: TImageList;
TabSheet4: TTabSheet;
GroupBox1: TGroupBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
ToolButton1: TToolButton;
GroupBox2: TGroupBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
showtime: TCheckBox;
downmenu: TPopupMenu;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
dragdrop: TMenuItem;
Label1: TLabel;
Edit2: TEdit;
changeshujuku: TBitBtn;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
CoolBar1: TCoolBar;
N15: TMenuItem;
N16: TMenuItem;
first: TMenuItem;
putong: TMenuItem;
DropURLTarget1: TDropURLTarget;
ToolButton4: TToolButton;
dropmenu: TPopupMenu;
drophtml: TMenuItem;
dropwenjian: TMenuItem;
DropFileTarget1: TDropFileTarget;
OpenPictureDialog1: TOpenPictureDialog;
OpenDialog2: TOpenDialog;
Query1: TQuery;
createjiedian: TMenuItem;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure refreshClick(Sender: TObject);
procedure TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TreeView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure nnewClick(Sender: TObject);
procedure NrenameClick(Sender: TObject);
procedure exitClick(Sender: TObject);
procedure findClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure findtextClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure TreeView1Editing(Sender: TObject; Node: TTreeNode;
var AllowEdit: Boolean);
procedure TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
procedure ToolButton1Click(Sender: TObject);
procedure showtimeClick(Sender: TObject);
procedure drogClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure DropURLTarget1Drop(Sender: TObject; ShiftState: TShiftState;
Point: TPoint; var Effect: Integer);
procedure changeshujukuClick(Sender: TObject);
procedure getkind(str:string);
procedure htmltotxt(str:string);
procedure dbmemofontClick(Sender: TObject);
procedure treeviewfontClick(Sender: TObject);
procedure saveshow;
procedure N15Click(Sender: TObject);
procedure firstClick(Sender: TObject);
procedure putongClick(Sender: TObject);
procedure drophtmlClick(Sender: TObject);
procedure dropwenjianClick(Sender: TObject);
procedure DropFileTarget1Drop(Sender: TObject; ShiftState: TShiftState;
Point: TPoint; var Effect: Integer);
procedure delClick(Sender: TObject);
procedure N21Click(Sender: TObject);
procedure helpClick(Sender: TObject);
procedure createjiedianClick(Sender: TObject);
private
{ Private declarations }
public
node,oldnode,tempnode:Ttreenode;
fujiedian:integer;
s:string;//存放拖放html转换所取得的txt
g:Tstrings;//存放拖放txt文件所取得的txt;
n:boolean;//是否新建的记录
d:boolean;//是否拖动;
shujukuname:string;//数据库名字;
ini:Tstrings; //配置文件;
wwidth:integer;//窗口宽度;
end;
var
mainForm: TmainForm;
implementation
uses savemodi;
{$R *.DFM}
procedure TmainForm.Timer1Timer(Sender: TObject);
begin
statusbar1.panels[4].text:=timetostr(time);
//statusbar1.Refresh;
end;
procedure TmainForm.FormCreate(Sender: TObject);
begin
fujiedian:=0;
g:=Tstringlist.create;// 初始化
ini:=Tstringlist.create;
query1.databasename:=ExtractFilePath(Application.ExeName);
ini.loadfromfile(query1.databasename+'struct.cfg'); //读配置文件
shujukuname:=ini[0];//第一行为默认数据库
dbmemo1.font.color:=clblue;///文本颜色
dbmemo1.font.size:=10;
refreshclick(self);
//状态栏
statusbar1.canvas.font.style:=[fsbold];
end;
procedure TmainForm.FormDestroy(Sender: TObject);
begin
DropURLTarget1.UnRegister;//取消注册
dropfiletarget1.unregister;//
end;
procedure TmainForm.refreshClick(Sender: TObject);
var
a:integer;//a为总当前接点数
begin
pagecontrol1.activepage:=tabsheet1;//刷新时页为第一页
combobox1.text:='全部查找';
a:=-1; //因index从0开始的;
try
query1.close;
query1.sql.clear;
query1.SQL.add('select name,kind,txt from'+''''+shujukuname+'''');
query1.sql.add('order by kind');
query1.Open;
query1.DisableControls;
treeview1.items.clear;
query1.First;
ComboBox1.items.add('全部查找');
while not query1.eof do
begin
if a=-1 then
begin
treeview1.items.add(nil,query1.fieldbyname('kind').asstring);
a:=a+1;
ComboBox1.items.add(query1.fieldbyname('kind').asstring);//相应在查找的combobox1中增加条项
treeview1.items.addchild(treeview1.Items[a],query1.fieldbyname('name').asstring);
a:=a+1;
end
else
begin
if query1.fieldbyname('kind').asstring=treeview1.items[a].parent.text then
begin//是否与前一节点相同,如果相同则增加子节点.否则则增加父节点
treeview1.items.addchild(treeview1.Items[a].parent,query1.fieldbyname('name').asstring);
a:=a+1;
end
else
begin
treeview1.items.add(nil,query1.fieldbyname('kind').asstring);
a:=a+1;
ComboBox1.items.add(query1.fieldbyname('kind').asstring);
treeview1.items.addchild(treeview1.Items[a],query1.fieldbyname('name').asstring);
a:=a+1;
end;
end;
query1.next;
end;
query1.enablecontrols;
except
showmessage('打开数据库失败,请检查是否与与系统数据库相同');
end;
end;
procedure TmainForm.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if query1.modified then saveshow;
try
node:=treeview1.getnodeat(x,y);
if node.level=1 then
begin
if oldnode=nil then
getkind(node.parent.text);//如果是第一次调用getkind
if oldnode.parent<>node.parent then
getkind(node.parent.text);
query1.Locate('name',node.text,[]);
oldnode:=node;
combobox1.text:= node.Parent.text;//改变combobox1的显示
end;
if node.level=0 then
begin
getkind(node.text);
combobox1.text:=node.text;//改变ocmbobox1的显示
end;
statusbar1.panels[0].text:='当前项目:'+query1.fieldbyname('kind').asstring;
statusbar1.panels[2].text:='记录名称:'+query1.fieldbyname('name').asstring;
except
showmessage('打开记录失败');
end;
end;
procedure TmainForm.TreeView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
node:=treeview1.getnodeat(x,y);
if (button=mbRight) and (node<>nil) then//mouseup and button=mbright;
if node.level=0 then
begin
ndel.enabled:=false;
ncopy.enabled:=false;
nrename.enabled:=false;
end
else
begin
ndel.enabled:=true;
ncopy.enabled:=true;
nrename.enabled:=true;
nnew.enabled:=false;
end;
end;
procedure TmainForm.nnewClick(Sender: TObject);
begin
if query1.modified then saveshow;
if node<>nil then
begin
n:=true;//新建了记录
node.expand(true);
dbmemo1.lines.clear;
query1.edit;
query1.append;
query1.fieldbyname('name').asstring:='新记录';
if node.level=0 then //在父接点点击’新建‘
begin
query1.fieldbyname('kind').asstring:=node.text;
treeview1.items.addchild(node,'新记录');
node:=node.GetLastChild;//得到最后增加的孩子
end
else
begin //在子接点点击’新建‘
query1.fieldbyname('kind').asstring:=node.parent.text;
treeview1.items.Add(node,'新记录'); //增加接点
node:=node.parent.GetLastChild; //得到最后增加的孩子
end;
end;
end;
procedure TmainForm.NrenameClick(Sender: TObject);
begin
node.EditText;///子接点改名
end;
procedure TmainForm.exitClick(Sender: TObject);
begin
close;
end;
procedure TmainForm.findClick(Sender: TObject);
begin
pagecontrol1.activepage:=tabsheet3;
end;
procedure TmainForm.getkind(str:string);//得到一类的表
begin
oldnode:=node;
query1.close;
query1.sql.clear;
query1.SQL.add('select name,kind,txt from'+''''+shujukuname+'''');
query1.sql.add('where kind='''+str+'''');
//query1.sql.add('order by name');
query1.Open;
query1.edit;
//showmessage('getkind');
end;
procedure TmainForm.FormResize(Sender: TObject);
begin
{statusbar1.panels[2].width:=
statusbar1.width-statusbar1.panels[0].width
-statusbar1.panels[3].width
-statusbar1.panels[1].width;}
end;
procedure TmainForm.findtextClick(Sender: TObject);
var
aa,aa1:string;
begin
aa:='%'+edit1.text+'%';
aa1:=edit1.text+'%';
dbgrid2.datasource:=datasource1;
dbgrid1.datasource:=nil;
if (checkbox1.checked) or (checkbox2.checked) then
begin
query1.close;
query1.sql.clear;
query1.SQL.add('select name,kind,txt from'+''''+shujukuname+'''');
if (checkbox1.checked) and (checkbox2.checked=false) then //匹配记录名
begin
query1.sql.add('where (name like'+''''+aa+''''+'or name like'+''''+aa1+''''+')');
end;
if (checkbox2.checked) and (checkbox1.checked=false) then //匹配txt的内容
begin
query1.sql.add('where (txt like'+''''+aa+''''+'or txt like'+''''+aa1+''''+')');
end;
if (checkbox1.checked) and (checkbox2.checked) then //两项都要匹配
begin
query1.sql.add('where (name like'+''''+aa+''''+'or name like'+''''+aa1+''''+')');
query1.sql.add('and (txt like'+''''+aa+''''+'or txt like'+''''+aa1+''''+')');
end;
if combobox1.text<>'全部查找' then
query1.sql.add('and (kind='+''''+combobox1.text+''''+')');
query1.Open;
end;
end;
procedure TmainForm.PageControl1Change(Sender: TObject);
begin
{if (pagecontrol1.ActivePage=Tabsheet1)and
(pagecontrol1.ActivePage=Tabsheet2) then
begin
dbgrid2.datasource:=nil;
dbgrid1.datasource:=datasource1;
end
else
dbgrid1.datasource:=nil; }
end;
procedure TmainForm.TreeView1Editing(Sender: TObject; Node: TTreeNode;
var AllowEdit: Boolean);
begin
allowedit:=true;
end;
procedure TmainForm.TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
begin
query1.edit;
//query1.locate('name',node.text,[]);
query1.fieldbyname('name').asstring:=s;
query1.post;
node.text:=s;
statusbar1.panels[2].text:='记录名称:'+query1.fieldbyname('name').asstring;;
end;
procedure TmainForm.ToolButton1Click(Sender: TObject);
begin
pagecontrol1.activepage:=tabsheet4;// 打开设计页
end;
procedure TmainForm.showtimeClick(Sender: TObject);
begin
if showtime.checked then
begin
timer1.enabled:=false;
statusbar1.panels[3].text:='';
statusbar1.panels[2].width:=statusbar1.panels[2].width
+statusbar1.panels[3].width;
end
else
begin
timer1.enabled:=true;
statusbar1.panels[2].width:=statusbar1.panels[2].width
-statusbar1.panels[3].width;
end;
end;
procedure TmainForm.drogClick(Sender: TObject);
begin
if dragdrop.checked=false then
begin
wwidth:=mainform.width;
coolbar1.Hide;
mainform.width:=215;
dragdrop.checked:=true;
end
else
begin
coolbar1.show;
dragdrop.checked:=false;
mainform.width:=wwidth;
end;
end;
procedure TmainForm.DropURLTarget1Drop(Sender: TObject;
ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
begin
node:=treeview1.getnodeat(point.x,point.y);//得到拖放接点
if node<>nil then
begin
if query1.modified then saveshow;//if query modified then save
if node.level=1 then
begin
treeview1.items.add(node,DropURLTarget1.title);
getkind(node.parent.text);
end
else
begin
treeview1.items.addchild(node,DropURLTarget1.Title);
getkind(node.text);
end;
node:=node.GetLastChild;//得到最后增加的孩子
node.parent.expand(true);//扩展父接点
///追加记录
query1.edit;
query1.Append;
query1.fieldbyname('name').asstring:=node.Text;
query1.fieldbyname('kind').asstring:=node.parent.text;
htmltotxt(dropurltarget1.url);//file to txt in dbmemo1;
query1.fieldbyname('txt').asstring:=s;
end;
end;
procedure TmainForm.changeshujukuClick(Sender: TObject);
var
struct:Tstrings;
begin
struct:=Tstringlist.create;
if opendialog2.execute then
begin
edit2.text:=OpenDialog2.FileName;
struct.text:=edit2.text;
shujukuname:=edit2.text;
if FileExists('struct.cfg') then
begin
deletefile('struct.cfg');
showmessage('delete ok');
end;
struct.savetofile('struct.cfg');
struct.loadfromfile('struct.cfg');
showmessage(struct[0]);
refreshClick(self);
end;
end;
procedure TmainForm.htmltotxt(str:string);
var
sels,sele:longint;
begin
s:=str;
//if pos('http',s) then save
if pos('file',s)<>0 then delete(s,1,8);//去掉url中的'file:///';
try
g.loadfromfile(s);
s:=g.text;
screen.Cursor := crHourGlass;
while pos('<br>',s)<>0 do delete(s,pos('<br>',s),4);
while pos('-->',s)<>0 do delete(s,pos('-->',s),3);
while pos('>>',s)<>0 do delete(s,pos('>>',s),2);
while (pos('<' ,s)<>0) and (pos('>',s)<>0) do
begin
sels:=pos('<',s);
sele:=pos('>',s);
//if sele=0 then break;
if sels>sele then break
else
delete(s,sels,sele-sels+1);
end;
dbmemo1.perform(wm_vscroll,sb_top,0);
screen.Cursor := crDefault;
except
showmessage('html文件打开文件失败');
end;
end;
procedure TmainForm.dbmemofontClick(Sender: TObject);
begin
if fontdialog1.execute then
dbmemo1.font:=fontdialog1.Font;
end;
procedure TmainForm.treeviewfontClick(Sender: TObject);
begin
if fontdialog1.execute then
treeview1.font:=fontdialog1.Font;
end;
procedure TmainForm.saveshow;
begin
save:=Tsave.create(self);
save.showmodal;
end;
procedure TmainForm.N15Click(Sender: TObject);
begin
if openpicturedialog1.execute then ///改变背景;
begin
toolbar1.Transparent:=false;
coolbar1.bands[0].bitmap.loadfromfile(openpicturedialog1.FileName);
end;
toolbar1.Transparent:=true;
end;
procedure TmainForm.firstClick(Sender: TObject);
begin
mainform.formstyle:=fsStayOnTop;//窗口ontop
putong.checked:=false;
first.checked:=true;
end;
procedure TmainForm.putongClick(Sender: TObject);
begin
mainform.formstyle:=fsnormal;//普通窗口
putong.checked:=true;
first.checked:=false;
end;
procedure TmainForm.drophtmlClick(Sender: TObject);
begin
dropfiletarget1.unregister;
dropurltarget1.register(treeview1);//注册drop url控件(treeview1)
drophtml.checked:=true;
dropwenjian.checked:=false;
statusbar1.panels[3].text:='拖动: '+'网页';
end;
procedure TmainForm.dropwenjianClick(Sender: TObject);
begin
dropurltarget1.unregister;
dropfiletarget1.register(treeview1);//注册drop 文件控件(treeview1)
drophtml.checked:=false;
dropwenjian.checked:=true;
statusbar1.panels[3].text:='拖动: '+'文件';
end;
procedure TmainForm.DropFileTarget1Drop(Sender: TObject;
ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
var
a:integer;
fname:string;
begin
node:=treeview1.getnodeat(point.x,point.y);//得到拖放接点
if node<>nil then
begin
try
for a:=0 to dropfiletarget1.files.count-1 do
begin
if query1.modified then saveshow;//如果记录修改则保存
d:=true;
g.loadfromfile(dropfiletarget1.files[a]);
fname:=ExtractFilename(DropfileTarget1.Files[a]);
delete(fname,pos('.',fname),sizeof(fname));//删除扩展名
if node.level=1 then
begin
treeview1.items.add(node,fname); //增加子接点
getkind(node.parent.text); //在列表中显示数据
node:=node.parent.GetLastChild;//得到最后增加的孩子
end
else
begin
treeview1.items.addchild(node,fname);
getkind(node.text);
node:=node.GetLastChild;//得到最后增加的孩子
end;
node.parent.expand(true);//扩展父接点
///追加记录
query1.edit;
query1.Append;
query1.fieldbyname('name').asstring:=node.Text;
query1.fieldbyname('kind').asstring:=node.parent.text;
query1.fieldbyname('txt').asstring:=g.text;
end;
except
showmessage('不能打开这个文件');
end;
end;
end;
procedure TmainForm.delClick(Sender: TObject);
begin
try
query1.delete;
if node.Parent.count>1 then
node.delete
else
begin
node.parent.delete;
combobox1.items.delete(combobox1.Items.IndexOf(node.parent.text));
end;
except
showmessage('删除记录失败');
end;
end;
procedure TmainForm.N21Click(Sender: TObject);
begin
query1.edit;
end;
procedure TmainForm.helpClick(Sender: TObject);
begin
if FileExists('struct.ini')then
deletefile('struct.ini');
end;
procedure TmainForm.createjiedianClick(Sender: TObject);
var
createjiedian:string;
begin
createjiedian:= InputBox('项目名', '项目名', '');
if createjiedian<>'' then
begin
node:=nil;
treeview1.items.add(nil,createjiedian);
end;
end;
end.