📄 jjcc.pas
字号:
unit jjcc;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls, Mask, DBCtrls;
type
Tjjccfrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
DBComboBox1: TDBComboBox;
DBComboBox2: TDBComboBox;
DBEdit1: TDBEdit;
Table1: TTable;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DBComboBox1Click(Sender: TObject);
procedure DBEdit1DblClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
jjccfrm: Tjjccfrm;
implementation
{$R *.dfm}
procedure Tjjccfrm.FormCreate(Sender: TObject);
begin
shortdateFormat:='YYYY.MM.DD'; //确定日期格式
LongDateFormat:='YYYY.MM.DD';
DateSeparator:='.';
end;
procedure Tjjccfrm.FormShow(Sender: TObject);
var
datestr:string;
query:tquery;
sqlstr:string;
year,month,day:word ;
s1,s2,xuhao,danhao:string;
maxcount:integer;
begin
shortdateFormat:='YYYY.MM.DD'; //确定日期格式
LongDateFormat:='YYYY.MM.DD';
DateSeparator:='.';
datestr:=datetostr(date); //当前日期
table1.Close;
table1.Open; //打开车辆管理综合信息表
table1.Append ; //添加一空记录
table1.edit;
table1.FieldByName('日期').asstring:=datestr; //自动填用车日期
//查询当日派车情况
query:=tquery.Create (self);
query.DatabaseName :=table1.DatabaseName ;
query.sql.Clear ;
sqlstr:='select * from 车辆管理综合信息 where 日期>='+''''+datestr+''''+' order by 派车单号';
query.Close;
query.SQL.Clear ;
query.sql.text:=sqlstr;
query.Open;
//自动填写派车单号
DecodeDate(Date,year,month,day); //将日期分解为年、月、日
if month<10 then s1:='0'+inttostr(month) //将月补齐为两位数
else s1:=inttostr(month);
if day<10 then s2:='0'+inttostr(day) //将日补齐为两位数
else s2:=inttostr(day);
if query.RecordCount=0 then //没有当日派车记录
xuhao:='01' //当日第一张单
else //生成新的派车单号
begin
query.last; //指针指向当日最大的记录
xuhao:=copy(query.Fieldbyname('派车单号').AsString,9,2);//当日最大记录序号的后两位
maxcount:= strtoint(xuhao)+1 ; //派车单号+1
xuhao:=inttostr(maxcount); //变成字串
if maxcount<=9 then xuhao:='0'+xuhao; //补齐为两位数
end;
danhao:=inttostr(year)+s1+s2+xuhao; //生成派车单号(年月日序号字串)
table1.FieldByName('派车单号').asstring:=danhao;
//load 车号
DBComboBox1.Clear ; //首先清空它的文本
/ query:=tquery.Create (self);*
query.DatabaseName :=table1.DatabaseName ;
query.sql.Clear ;
//从车辆情况表中只取在位车辆的车牌号
sqlstr:='select * from 车辆情况 where 车号 not in (select 车号 from 车辆管理综合信息 where (发车时间 is not NULL) AND (回场时间 is NULL)) order by 车号';
query.SQL.Text :=sqlstr;
query.Open;
Query.First ;
while not Query.Eof do
begin //将车牌号逐一填入组合框
DBComboBox1.Items.Add(Query.FieldByName('车号').asstring);
Query.Next ;
end;
//load 司机
DBComboBox2.Clear ; //首先清空它的文本
query:=tquery.Create (self);
query.DatabaseName :=table1.DatabaseName ;
query.sql.Clear ;
sqlstr:='select 姓名 from 人员名册 where 职责='+''''+'司机'+'''';
query.SQL.Text :=sqlstr;
query.Open;
Query.First ;
while not Query.Eof do
begin //将司机姓名逐一填入组合框
DBComboBox2.Items.Add(Query.FieldByName('姓名').asstring);
Query.Next ;
end;
query.Free; //释放临时查询
end;
procedure Tjjccfrm.DBComboBox1Click(Sender: TObject);
var
query:tquery;
sqlstr:string;
begin
query:=tquery.Create (self); //创建查询
query.DatabaseName :=table1.DatabaseName; //指定数据库名
if DBComboBox1.Text <> '' then
begin //依据所选择的车号,自动填入司机和车种
query.SQL.Clear ;
sqlstr:='select * from 车辆情况 where 车号='+''''+DBComboBox1.Text+'''';
query.SQL.Text :=sqlstr;
query.Open;
table1.fieldbyname('车种').asstring :=query.fieldbyname('车种').asstring;
table1.fieldbyname('司机').asstring :=query.fieldbyname('司机').asstring;
end;
query.Free; //释放查询
end;
procedure Tjjccfrm.DBEdit1DblClick(Sender: TObject);
var
datestr:string;
begin
shortdateFormat:='YYYY.MM.DD'; //确定日期格式
LongDateFormat:='YYYY.MM.DD';
DateSeparator:='.';
if DBEdit1.Text='' then
begin //自动填入发车时间等项
datestr:=datetimetostr(now);
table1.Edit;
table1.FieldByName('发车时间').asstring:=datestr;
table1.FieldByName('用车时间').asstring:=timetostr(time);
table1.FieldByName('备注').asstring:='紧急出车';
end;
end;
procedure Tjjccfrm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if DBComboBox2.Focused then exit else //可填司机
key:=0;
end;
procedure Tjjccfrm.FormKeyPress(Sender: TObject; var Key: Char);
begin
if DBComboBox2.Focused then exit else //可填司机
key:=#0;
end;
procedure Tjjccfrm.Button1Click(Sender: TObject);
begin //保存并继续录入
if (DBEdit1.Text='')or(DBComboBox1.Text='')or(DBComboBox2.Text='') then
begin
showmessage('车号、司机、出车时间未填全,不能保存!');
exit;
end;
if Application.MessageBox('您确定要保存这条出车记录吗?','确定吗?',
MB_OKCANCEL + MB_DEFBUTTON1) = IDOK then
begin
with table1 do
begin
Database.StartTransaction;
try
ApplyUpdates; {try to write the updates to the database};
Database.Commit; {on success, commit the changes};
except
Database.Rollback; {on failure, undo the changes};
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
CommitUpdates; {on success, clear the cache}
end;
showmessage('保存完毕,可继续处理紧急出车或退出!');
jjccfrm.DoShow; //继续录入
end;
end;
procedure Tjjccfrm.Button2Click(Sender: TObject);
begin //保存并退出
if (DBEdit1.Text='')or(DBComboBox1.Text='')or(DBComboBox2.Text='') then
begin
showmessage('车号、司机、出车时间未填全,不能保存!');
exit;
end;
if Application.MessageBox('您确定要保存这条出车记录吗?','确定吗?',
MB_OKCANCEL + MB_DEFBUTTON1) = IDOK then
begin
with table1 do
begin
Database.StartTransaction;
try
ApplyUpdates; {try to write the updates to the database};
Database.Commit; {on success, commit the changes};
except
Database.Rollback; {on failure, undo the changes};
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
CommitUpdates; {on success, clear the cache}
end;
showmessage('保存完毕,退出!');
close;
end;
end;
procedure Tjjccfrm.Button3Click(Sender: TObject);
begin //取消并退出
table1.Cancel;
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -