J
jonyhuang
Unregistered / Unconfirmed
GUEST, unregistred user!
dataset控件连接SocketConnection1进行远程数据库连接
该程序在多次查询后系统资源会明显降低,直到最后死机,我查来查去
都查不出问题出在哪,请各位高手帮我看看,谢谢
unit cdUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DsFancyButton, StdCtrls, ExtCtrls, Grids, Mask, ToolEdit, CurrEdit,
Db, ADODB, DBGridEh;
type
TcdForm = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
DsFancyButton3: TDsFancyButton;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
DsFancyButton4: TDsFancyButton;
Edit2: TEdit;
dEdit1: TMaskEdit;
Label1: TLabel;
Label2: TLabel;
Label10: TLabel;
Label14: TLabel;
Edit7: TEdit;
Label15: TLabel;
dEdit2: TMaskEdit;
Edit10: TEdit;
Memo1: TMemo;
Label16: TLabel;
Edit3: TEdit;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
DBGridEh1: TDBGridEh;
DataSource1: TDataSource;
DsFancyButton6: TDsFancyButton;
RadioGroup1: TRadioGroup;
ListBox1: TListBox;
Label29: TLabel;
Memo2: TMemo;
ComboBox2: TComboBox;
ComboBox1: TComboBox;
Label30: TLabel;
procedure DsFancyButton3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject;
var Key: Char);
procedure DsFancyButton4Click(Sender: TObject);
procedure DsFancyButton1Click(Sender: TObject);
procedure DsFancyButton2Click(Sender: TObject);
procedure Edit3Click(Sender: TObject);
procedure Edit3DblClick(Sender: TObject);
procedure Edit3MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Edit3KeyPress(Sender: TObject;
var Key: Char);
procedure Edit2KeyPress(Sender: TObject;
var Key: Char);
procedure DsFancyButton6Click(Sender: TObject);
procedure ListBox1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
procedure clear;
procedure tj;
public
{ Public declarations }
end;
var
cdForm: TcdForm;
sdl,zl,gs:string;
implementation
uses shipdataUnit, shipnameUnit,downUnit,tsUnit,sumUnit, SDLUnit,
gktsUnit, tdzsUnit;
VAR
sql:string;
dbl:boolean;
{$R *.DFM}
procedure tcdform.tj;
var i,i1,i2,cmc,jg:integer;
zl:real;
cma,cmb,zl1:string;
begin
//1
with DataModule1do
begin
//2
label28.caption:='';
zl:=0;
dataset2.close;
dataset2.CommandText:='select * from sjk1';
dataset2.open;
for i:=1 to dataset2.RecordCountdo
begin
//3
if dataset2.fieldbyname('毛重').asstring<>'' then
begin
//4
zl1:='';
for i1:=1 to length(dataset2.fieldbyname('毛重').asstring)do
begin
//5
try //6
strtoint(copy(dataset2.fieldbyname('毛重').asstring,i1,1));
except
begin
//7
if copy(dataset2.fieldbyname('毛重').asstring,i1,1)<>'.' then
break;
end;
//7
end;
//6
zl1:=zl1+copy(dataset2.fieldbyname('毛重').asstring,i1,1);
end;
//5
zl:=zl+strtofloat(zl1);
end;
//4
dataset2.MoveBy(1);
end;
//3
label22.caption:=floattostr(zl);
for jg:=0 to 1do
begin
//8
dataset2.close;
dataset2.CommandText:='select distinct 箱号 from sjk1 where 吉柜='+''''+inttostr(jg)+'''';
dataset2.open;
if dataset2.RecordCount<>0 then
begin
dataset3.close;
dataset3.CommandText:='delete from sjk2';
dataset3.Execute;
dataset2.first;
for i:=1 to dataset2.RecordCountdo
begin
//9
cma:=dataset2.FieldByName('箱号').asstring;
cmb:='';
if cma<>'' then
begin
//10
for i1:=1 to length(cma)do
begin
//11
if copy(cma,i1,1)='/' then
break ;
end;
//11
for i2:=i1+1 to length(cma)do
begin
//12
if copy(cma,i2,1)='/' then
break
else
cmb:=cmb+copy(cma,i2,1);
end;
//12
dataset3.close;
dataset3.CommandText:='iNSERT INTO sjk2 (尺码) values('+quotedstr(cmb)+')';
dataset3.Execute;
end;
//10
dataset2.MoveBy(1);
end;
//9
dataset3.close;
dataset3.CommandText:='select distinct 尺码 from sjk2';
dataset3.open;
memo1.Lines.clear;
for i:=1 to dataset3.RecordCountdo
begin
//13
cma:=dataset3.fieldbyname('尺码').asstring;
if cma<>'' then
begin
//14
dataset2.close;
dataset2.CommandText:='select 尺码 from sjk2 where 尺码='+quotedstr(cma);
dataset2.open;
cmc:=dataset2.recordcount;
memo1.Lines.add(inttostr(cmc)+'×'+cma);
end;
//14
dataset3.MoveBy(1);
end;
//13
for i:=0 to memo1.lines.count-1do
begin
//15
cma:=memo1.lines;
if cma<>'' then
begin
//15
IF I=0 then
begin
//16
cmb:=cma;
if jg=0 then
cmb:=cmb+'(重柜)';
// if jg=1 then
cmb:=cmb+'(吉柜)';
if jg=1 then
cmb:=cmb+'(空柜)';
end;
//16
IF I>0 then
begin
//17
if jg=0 then
cmb:=cmb+'&'+cma+'(重柜)';
if jg=1 then
// cmb:=cmb+'&'+cma+'(吉柜)';
cmb:=cmb+'&'+cma+'(空柜)';
end;
//17
end;
//15
end;
//13
label28.caption:=label28.caption+cmb;
end;
end;
//8
dataset2.close;
dataset3.close;
dataset1.close;
dataset1.CommandText:='select * from sjk1 ORDER BY id';
dataset1.open;
end;
//2
end;
//1
procedure tcdform.clear;
begin
RadioGroup1.ItemIndex:=-1;
label24.caption:='';
label17.caption:='';
label18.caption:='';
label19.caption:='';
label20.caption:='';
label21.caption:='';
label22.caption:='';
label23.caption:='';
label26.caption:='';
label28.caption:='';
LABEL30.CAPTION:='';
edit3.Enabled:=true;
edit3.text:='';
edit2.text:='';
edit7.text:='';
edit10.text:='';
combobox1.Style:=csDropDown;
combobox2.Style:=csDropDown;
combobox2.text:='';
combobox1.text:='';
dedit1.text:='0000-00-00';
dedit2.text:='0000-00-00';
Edit3.SetFocus;
end;
procedure TcdForm.DsFancyButton3Click(Sender: TObject);
begin
close;
end;
procedure TcdForm.FormShow(Sender: TObject);
var i:integer;
begin
shortdateformat:='yyyy-mm-dd';
listbox1.items.clear;
label29.caption:='码'+#13#13+'头';
with DataModule1do
begin
dataset1.close;
dataset1.CommandText:='select * from sgk';
dataset1.open;
combobox2.Items.clear;
combobox1.items.clear;
for i:=1 to dataset1.recordcountdo
begin
combobox2.items.add(dataset1.fieldbyname('港口').asstring);
combobox1.items.add(dataset1.fieldbyname('港口').asstring);
dataset1.MoveBy(1);
end;
end;
clear;
end;
procedure TcdForm.ComboBox1KeyPress(Sender: TObject;
var Key: Char);
begin
if key=#13 then
begin
selectnext(((sender) as twincontrol),true,true);
key:=#0;
end;
end;
procedure TcdForm.DsFancyButton4Click(Sender: TObject);
begin
listbox1.items.clear;
clear;
end;
procedure TcdForm.DsFancyButton1Click(Sender: TObject);
begin
//0
end;
procedure TcdForm.DsFancyButton2Click(Sender: TObject);
begin
//1
end;
procedure TcdForm.Edit3Click(Sender: TObject);
var
n: Integer;
begin
n := GetTickCount;
while GetTickCount - n < 500do
Application.ProcessMessages;
if Dbl then
begin
dbl := false;
exit;
end;
end;
procedure TcdForm.Edit3DblClick(Sender: TObject);
begin
dbl:=true;
end;
procedure TcdForm.Edit3MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if Dbl = true then
begin
sp:='2';
shipnameform := tshipnameform.Create(Self);
shipnameform.ShowModal;
shipnameform.free;
if edit3.text<>'' then
edit2.SetFocus
else
edit3.SetFocus;
end;
end;
procedure TcdForm.Edit3KeyPress(Sender: TObject;
var Key: Char);
begin
if key=#13 then
begin
with DataModule1do
begin
dataset2.Close;
dataset2.CommandText:='select * from shipzl where 编号='+''''+edit3.text+'''';
dataset2.open;
if dataset2.RecordCount=0 then
begin
application.messagebox(PChar('查无此编码'),PChar('提示框'),mb_ok+mb_iconexclamation);
edit3.SetFocus;
exit;
end;
if dataset2.fieldbyname('船名').asstring<>'' then
begin
label24.caption:=dataset2.fieldbyname('船名').asstring;
label26.caption:=dataset2.fieldbynaME('船名1').ASSTRING;
END
else
label24.caption:=dataset2.fieldbyname('船名1').asstring;
selectnext(((sender) as twincontrol),true,true);
key:=#0;
end;
end;
end;
procedure TcdForm.Edit2KeyPress(Sender: TObject;
var Key: Char);
begin
if key=#13 then
begin
selectnext(((sender) as twincontrol),true,true);
key:=#0;
end;
end;
procedure TcdForm.DsFancyButton6Click(Sender: TObject);
var i,i1:integer;
begin
if (edit2.text<>'') or ((label24.caption='') and (label26.caption='')) then
begin
with DataModule1do
begin
dataset1.Close;
dataset2.close;
dataset2.CommandText:='delete from sjk';
dataset2.execute;
sql:='insert into sjk select * from cd where 编号='+''''+edit3.text+'''';
sql:=sql+' and 航次='+''''+edit2.text+'''';
sql:=sql+' order by 序号';
dataset2.close;
dataset2.commandtext:=sql;
dataset2.Execute;
dataset2.close;
dataset2.CommandText:='select * from sjk';
dataset2.open;
if dataset2.RecordCount=0 then
begin
Edit3.SetFocus;
exit;
end;
if dataset2.RecordCount<>0 then
begin
listbox1.items.clear;
dataset2.close;
dataset2.CommandText:='select distinct 从 from sjk';
dataset2.open;
for i:=1 to dataset2.RecordCountdo
begin
dataset3.close;
dataset3.commandtext:='select distinct 到 from sjk where 从='+''''+dataset2.fieldbyname('从').asstring+'''';
dataset3.open;
for i1:=1 to dataset3.RecordCountdo
begin
listbox1.Items.Add(dataset2.fieldbyname('从').asstring+'/'+dataset3.fieldbyname('到').asstring);
dataset3.MoveBy(1);
end;
dataset2.MoveBy(1);
end;
end;
end;
end;
end;
procedure TcdForm.ListBox1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
var fr,da,te:string;
i,i1:integer;
begin
if listbox1.items.count<>0 then
begin
try
te:=listbox1.items[listbox1.itemindex];
except
exit;
end;
fr:='';
da:='';
for i:=1 to length(listbox1.items[listbox1.itemindex])do
begin
if copy(listbox1.items[listbox1.itemindex],i,1)<>'/' then
fr:=fr+copy(listbox1.items[listbox1.itemindex],i,1) else
break;
end;
for i1:=i+1 to length(listbox1.items[listbox1.itemindex])do
begin
da:=da+copy(listbox1.items[listbox1.itemindex],i1,1);
end;
with DataModule1do
begin
sql:='select * from sjk where 从='+''''+fr+'''';
sql:=sql+' and 到='+''''+da+'''';
sql:=sql+' ORDER BY 序号';
dataset2.close;
dataset2.CommandText:=sql;
dataset2.open;
//clear;
label24.caption:=dataset2.fieldbyname('船名').asstring;
edit2.text:=dataset2.fieldbyname('航次').asstring;
label17.caption:=dataset2.fieldbyname('船型').asstring;
combobox2.text:=dataset2.fieldbyname('从').asstring;
combobox1.text:=dataset2.fieldbyname('到').asstring;
label21.caption:=dataset2.fieldbyname('旗').asstring;
label18.caption:=dataset2.fieldbyname('净吨位').asstring;
label19.caption:=dataset2.fieldbyname('总吨位').asstring;
label20.caption:=dataset2.fieldbyname('载重吨').asstring;
label30.caption:=dataset2.fieldbyname('代码1').asstring;
edit7.text:=dataset2.fieldbyname('装货点').asstring;
if datetostr(dataset2.fieldbyname('时间1').asdatetime)='1899-12-30' then
dedit1.text:='0000-00-00' else
dedit1.text:=datetostr(dataset2.fieldbyname('时间1').asdatetime);
if datetostr(dataset2.fieldbyname('时间2').asdatetime)='1899-12-30' then
dedit2.text:='0000-00-00' else
dedit2.text:=datetostr(dataset2.fieldbyname('时间2').asdatetime);
label22.caption:=dataset2.fieldbyname('装货重量').asstring;
edit10.text:=dataset2.fieldbyname('其中').asstring;
label23.caption:=dataset2.fieldbyname('船舶代码').asstring;
dataset2.close;
dataset2.CommandText:='delete from sjk1';
dataset2.Execute;
sql:='insert into sjk1 select * from sjk where 从='+''''+fr+'''';
sql:=sql+' and 到='+''''+da+'''';
dataset2.close;
dataset2.CommandText:=sql;
dataset2.Execute;
tj;
end;
end;
end;
procedure TcdForm.ComboBox2Change(Sender: TObject);
begin
combobox2.Style:=csDropDownList;
end;
procedure TcdForm.ComboBox1Change(Sender: TObject);
begin
combobox1.Style:=csDropDownList;
end;
end.
[b[red][/red][black][/black]
该程序在多次查询后系统资源会明显降低,直到最后死机,我查来查去
都查不出问题出在哪,请各位高手帮我看看,谢谢
unit cdUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DsFancyButton, StdCtrls, ExtCtrls, Grids, Mask, ToolEdit, CurrEdit,
Db, ADODB, DBGridEh;
type
TcdForm = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
DsFancyButton3: TDsFancyButton;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
DsFancyButton4: TDsFancyButton;
Edit2: TEdit;
dEdit1: TMaskEdit;
Label1: TLabel;
Label2: TLabel;
Label10: TLabel;
Label14: TLabel;
Edit7: TEdit;
Label15: TLabel;
dEdit2: TMaskEdit;
Edit10: TEdit;
Memo1: TMemo;
Label16: TLabel;
Edit3: TEdit;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
DBGridEh1: TDBGridEh;
DataSource1: TDataSource;
DsFancyButton6: TDsFancyButton;
RadioGroup1: TRadioGroup;
ListBox1: TListBox;
Label29: TLabel;
Memo2: TMemo;
ComboBox2: TComboBox;
ComboBox1: TComboBox;
Label30: TLabel;
procedure DsFancyButton3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject;
var Key: Char);
procedure DsFancyButton4Click(Sender: TObject);
procedure DsFancyButton1Click(Sender: TObject);
procedure DsFancyButton2Click(Sender: TObject);
procedure Edit3Click(Sender: TObject);
procedure Edit3DblClick(Sender: TObject);
procedure Edit3MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Edit3KeyPress(Sender: TObject;
var Key: Char);
procedure Edit2KeyPress(Sender: TObject;
var Key: Char);
procedure DsFancyButton6Click(Sender: TObject);
procedure ListBox1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
procedure clear;
procedure tj;
public
{ Public declarations }
end;
var
cdForm: TcdForm;
sdl,zl,gs:string;
implementation
uses shipdataUnit, shipnameUnit,downUnit,tsUnit,sumUnit, SDLUnit,
gktsUnit, tdzsUnit;
VAR
sql:string;
dbl:boolean;
{$R *.DFM}
procedure tcdform.tj;
var i,i1,i2,cmc,jg:integer;
zl:real;
cma,cmb,zl1:string;
begin
//1
with DataModule1do
begin
//2
label28.caption:='';
zl:=0;
dataset2.close;
dataset2.CommandText:='select * from sjk1';
dataset2.open;
for i:=1 to dataset2.RecordCountdo
begin
//3
if dataset2.fieldbyname('毛重').asstring<>'' then
begin
//4
zl1:='';
for i1:=1 to length(dataset2.fieldbyname('毛重').asstring)do
begin
//5
try //6
strtoint(copy(dataset2.fieldbyname('毛重').asstring,i1,1));
except
begin
//7
if copy(dataset2.fieldbyname('毛重').asstring,i1,1)<>'.' then
break;
end;
//7
end;
//6
zl1:=zl1+copy(dataset2.fieldbyname('毛重').asstring,i1,1);
end;
//5
zl:=zl+strtofloat(zl1);
end;
//4
dataset2.MoveBy(1);
end;
//3
label22.caption:=floattostr(zl);
for jg:=0 to 1do
begin
//8
dataset2.close;
dataset2.CommandText:='select distinct 箱号 from sjk1 where 吉柜='+''''+inttostr(jg)+'''';
dataset2.open;
if dataset2.RecordCount<>0 then
begin
dataset3.close;
dataset3.CommandText:='delete from sjk2';
dataset3.Execute;
dataset2.first;
for i:=1 to dataset2.RecordCountdo
begin
//9
cma:=dataset2.FieldByName('箱号').asstring;
cmb:='';
if cma<>'' then
begin
//10
for i1:=1 to length(cma)do
begin
//11
if copy(cma,i1,1)='/' then
break ;
end;
//11
for i2:=i1+1 to length(cma)do
begin
//12
if copy(cma,i2,1)='/' then
break
else
cmb:=cmb+copy(cma,i2,1);
end;
//12
dataset3.close;
dataset3.CommandText:='iNSERT INTO sjk2 (尺码) values('+quotedstr(cmb)+')';
dataset3.Execute;
end;
//10
dataset2.MoveBy(1);
end;
//9
dataset3.close;
dataset3.CommandText:='select distinct 尺码 from sjk2';
dataset3.open;
memo1.Lines.clear;
for i:=1 to dataset3.RecordCountdo
begin
//13
cma:=dataset3.fieldbyname('尺码').asstring;
if cma<>'' then
begin
//14
dataset2.close;
dataset2.CommandText:='select 尺码 from sjk2 where 尺码='+quotedstr(cma);
dataset2.open;
cmc:=dataset2.recordcount;
memo1.Lines.add(inttostr(cmc)+'×'+cma);
end;
//14
dataset3.MoveBy(1);
end;
//13
for i:=0 to memo1.lines.count-1do
begin
//15
cma:=memo1.lines;
if cma<>'' then
begin
//15
IF I=0 then
begin
//16
cmb:=cma;
if jg=0 then
cmb:=cmb+'(重柜)';
// if jg=1 then
cmb:=cmb+'(吉柜)';
if jg=1 then
cmb:=cmb+'(空柜)';
end;
//16
IF I>0 then
begin
//17
if jg=0 then
cmb:=cmb+'&'+cma+'(重柜)';
if jg=1 then
// cmb:=cmb+'&'+cma+'(吉柜)';
cmb:=cmb+'&'+cma+'(空柜)';
end;
//17
end;
//15
end;
//13
label28.caption:=label28.caption+cmb;
end;
end;
//8
dataset2.close;
dataset3.close;
dataset1.close;
dataset1.CommandText:='select * from sjk1 ORDER BY id';
dataset1.open;
end;
//2
end;
//1
procedure tcdform.clear;
begin
RadioGroup1.ItemIndex:=-1;
label24.caption:='';
label17.caption:='';
label18.caption:='';
label19.caption:='';
label20.caption:='';
label21.caption:='';
label22.caption:='';
label23.caption:='';
label26.caption:='';
label28.caption:='';
LABEL30.CAPTION:='';
edit3.Enabled:=true;
edit3.text:='';
edit2.text:='';
edit7.text:='';
edit10.text:='';
combobox1.Style:=csDropDown;
combobox2.Style:=csDropDown;
combobox2.text:='';
combobox1.text:='';
dedit1.text:='0000-00-00';
dedit2.text:='0000-00-00';
Edit3.SetFocus;
end;
procedure TcdForm.DsFancyButton3Click(Sender: TObject);
begin
close;
end;
procedure TcdForm.FormShow(Sender: TObject);
var i:integer;
begin
shortdateformat:='yyyy-mm-dd';
listbox1.items.clear;
label29.caption:='码'+#13#13+'头';
with DataModule1do
begin
dataset1.close;
dataset1.CommandText:='select * from sgk';
dataset1.open;
combobox2.Items.clear;
combobox1.items.clear;
for i:=1 to dataset1.recordcountdo
begin
combobox2.items.add(dataset1.fieldbyname('港口').asstring);
combobox1.items.add(dataset1.fieldbyname('港口').asstring);
dataset1.MoveBy(1);
end;
end;
clear;
end;
procedure TcdForm.ComboBox1KeyPress(Sender: TObject;
var Key: Char);
begin
if key=#13 then
begin
selectnext(((sender) as twincontrol),true,true);
key:=#0;
end;
end;
procedure TcdForm.DsFancyButton4Click(Sender: TObject);
begin
listbox1.items.clear;
clear;
end;
procedure TcdForm.DsFancyButton1Click(Sender: TObject);
begin
//0
end;
procedure TcdForm.DsFancyButton2Click(Sender: TObject);
begin
//1
end;
procedure TcdForm.Edit3Click(Sender: TObject);
var
n: Integer;
begin
n := GetTickCount;
while GetTickCount - n < 500do
Application.ProcessMessages;
if Dbl then
begin
dbl := false;
exit;
end;
end;
procedure TcdForm.Edit3DblClick(Sender: TObject);
begin
dbl:=true;
end;
procedure TcdForm.Edit3MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if Dbl = true then
begin
sp:='2';
shipnameform := tshipnameform.Create(Self);
shipnameform.ShowModal;
shipnameform.free;
if edit3.text<>'' then
edit2.SetFocus
else
edit3.SetFocus;
end;
end;
procedure TcdForm.Edit3KeyPress(Sender: TObject;
var Key: Char);
begin
if key=#13 then
begin
with DataModule1do
begin
dataset2.Close;
dataset2.CommandText:='select * from shipzl where 编号='+''''+edit3.text+'''';
dataset2.open;
if dataset2.RecordCount=0 then
begin
application.messagebox(PChar('查无此编码'),PChar('提示框'),mb_ok+mb_iconexclamation);
edit3.SetFocus;
exit;
end;
if dataset2.fieldbyname('船名').asstring<>'' then
begin
label24.caption:=dataset2.fieldbyname('船名').asstring;
label26.caption:=dataset2.fieldbynaME('船名1').ASSTRING;
END
else
label24.caption:=dataset2.fieldbyname('船名1').asstring;
selectnext(((sender) as twincontrol),true,true);
key:=#0;
end;
end;
end;
procedure TcdForm.Edit2KeyPress(Sender: TObject;
var Key: Char);
begin
if key=#13 then
begin
selectnext(((sender) as twincontrol),true,true);
key:=#0;
end;
end;
procedure TcdForm.DsFancyButton6Click(Sender: TObject);
var i,i1:integer;
begin
if (edit2.text<>'') or ((label24.caption='') and (label26.caption='')) then
begin
with DataModule1do
begin
dataset1.Close;
dataset2.close;
dataset2.CommandText:='delete from sjk';
dataset2.execute;
sql:='insert into sjk select * from cd where 编号='+''''+edit3.text+'''';
sql:=sql+' and 航次='+''''+edit2.text+'''';
sql:=sql+' order by 序号';
dataset2.close;
dataset2.commandtext:=sql;
dataset2.Execute;
dataset2.close;
dataset2.CommandText:='select * from sjk';
dataset2.open;
if dataset2.RecordCount=0 then
begin
Edit3.SetFocus;
exit;
end;
if dataset2.RecordCount<>0 then
begin
listbox1.items.clear;
dataset2.close;
dataset2.CommandText:='select distinct 从 from sjk';
dataset2.open;
for i:=1 to dataset2.RecordCountdo
begin
dataset3.close;
dataset3.commandtext:='select distinct 到 from sjk where 从='+''''+dataset2.fieldbyname('从').asstring+'''';
dataset3.open;
for i1:=1 to dataset3.RecordCountdo
begin
listbox1.Items.Add(dataset2.fieldbyname('从').asstring+'/'+dataset3.fieldbyname('到').asstring);
dataset3.MoveBy(1);
end;
dataset2.MoveBy(1);
end;
end;
end;
end;
end;
procedure TcdForm.ListBox1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
var fr,da,te:string;
i,i1:integer;
begin
if listbox1.items.count<>0 then
begin
try
te:=listbox1.items[listbox1.itemindex];
except
exit;
end;
fr:='';
da:='';
for i:=1 to length(listbox1.items[listbox1.itemindex])do
begin
if copy(listbox1.items[listbox1.itemindex],i,1)<>'/' then
fr:=fr+copy(listbox1.items[listbox1.itemindex],i,1) else
break;
end;
for i1:=i+1 to length(listbox1.items[listbox1.itemindex])do
begin
da:=da+copy(listbox1.items[listbox1.itemindex],i1,1);
end;
with DataModule1do
begin
sql:='select * from sjk where 从='+''''+fr+'''';
sql:=sql+' and 到='+''''+da+'''';
sql:=sql+' ORDER BY 序号';
dataset2.close;
dataset2.CommandText:=sql;
dataset2.open;
//clear;
label24.caption:=dataset2.fieldbyname('船名').asstring;
edit2.text:=dataset2.fieldbyname('航次').asstring;
label17.caption:=dataset2.fieldbyname('船型').asstring;
combobox2.text:=dataset2.fieldbyname('从').asstring;
combobox1.text:=dataset2.fieldbyname('到').asstring;
label21.caption:=dataset2.fieldbyname('旗').asstring;
label18.caption:=dataset2.fieldbyname('净吨位').asstring;
label19.caption:=dataset2.fieldbyname('总吨位').asstring;
label20.caption:=dataset2.fieldbyname('载重吨').asstring;
label30.caption:=dataset2.fieldbyname('代码1').asstring;
edit7.text:=dataset2.fieldbyname('装货点').asstring;
if datetostr(dataset2.fieldbyname('时间1').asdatetime)='1899-12-30' then
dedit1.text:='0000-00-00' else
dedit1.text:=datetostr(dataset2.fieldbyname('时间1').asdatetime);
if datetostr(dataset2.fieldbyname('时间2').asdatetime)='1899-12-30' then
dedit2.text:='0000-00-00' else
dedit2.text:=datetostr(dataset2.fieldbyname('时间2').asdatetime);
label22.caption:=dataset2.fieldbyname('装货重量').asstring;
edit10.text:=dataset2.fieldbyname('其中').asstring;
label23.caption:=dataset2.fieldbyname('船舶代码').asstring;
dataset2.close;
dataset2.CommandText:='delete from sjk1';
dataset2.Execute;
sql:='insert into sjk1 select * from sjk where 从='+''''+fr+'''';
sql:=sql+' and 到='+''''+da+'''';
dataset2.close;
dataset2.CommandText:=sql;
dataset2.Execute;
tj;
end;
end;
end;
procedure TcdForm.ComboBox2Change(Sender: TObject);
begin
combobox2.Style:=csDropDownList;
end;
procedure TcdForm.ComboBox1Change(Sender: TObject);
begin
combobox1.Style:=csDropDownList;
end;
end.
[b[red][/red][black][/black]