📄 paichein.~pas
字号:
unit paichein;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Grids, DBGrids, StdCtrls, DBCtrls, Mask, ExtCtrls, DB,
ADODB,paichein_unit, DBClient,driverdata_unit,vehicledata_unit;
type
Tpaicheinfrm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label17: TLabel;
Label18: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
DBGrid1: TDBGrid;
StatusBar1: TStatusBar;
paiche_cds1: TClientDataSet;
paiche_ds1: TDataSource;
DateTimePicker1: TDateTimePicker;
Edit1: TEdit;
ComboBox1: TComboBox;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
DateTimePicker2: TDateTimePicker;
ComboBox2: TComboBox;
Edit5: TEdit;
Memo1: TMemo;
ComboBox3: TComboBox;
procedure FormShow(Sender: TObject);
procedure ComboBox2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
paiche:Tpaichein;
driver:Tdriverdata;
vehicle:Tvehicledata;
datestr:string;
sql:string;
no:string;
{ Private declarations }
public
{ Public declarations }
end;
var
paicheinfrm: Tpaicheinfrm;
implementation
uses loginfrmUnit3;
{$R *.dfm}
procedure Tpaicheinfrm.FormShow(Sender: TObject);
var
reccount:integer;
year,month,day:word ;
str,s1,s2,n:string;
max:integer;
begin
datetimepicker1.DateTime:=date;
sql:='select * from WORK_INFO where DATETIME>='+''''+datestr+''''+' order by PAICHE_ID';
reccount:=paiche.Find(sql);
paiche_cds1.Data:=paiche.Sel(sql); //显示当日的派车记录情况
if reccount<>0 then
StatusBar1.Panels[0].Text := '派车记录有'+ inttostr(reccount) +'条。'
else
StatusBar1.Panels[0].Text :='今日尚无派车记录。';
//自动填写派车单号
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 reccount=0 then //没有当日派车记录
n:='01' //当日第一张单
else
begin //生成新的派车单号
str:=paiche.GetPaicheIDl(sql);//找到当日最大的记录
n:=copy(str,9,2);//当日最大记录序号的后两位
max:= strtoint(n)+1 ; //派车单号+1
n:=inttostr(max); //变成字串
if max<=9 then n:='0'+n; //补齐为两位数
end;
no:=inttostr(year)+s1+s2+n; //生成派车单号(年月日序号字串)
//load 车辆编号
ComboBox2.Items.clear; //首先清空它的项目
ComboBox2.Items:=driver.GetDriverIDList1() ;
//load 司机编号
ComboBox3.Items.Clear ; //首先清空它的项目
ComboBox3.Items:=vehicle.GetVehicleNOList1() ;
end;
procedure Tpaicheinfrm.ComboBox2Click(Sender: TObject);
var
i:integer;
begin
if ComboBox2.Text <> '' then
begin
sql:='select VEHICLE_NO from WORK_INFO where (TIME_FROM is not NULL) AND (TIME_TO is NULL) AND (VEHICLE_NO='+''''+ComboBox2.Text+''')';
i:=paiche.Find(sql);
if i<>0 then //提示该车不在位
begin
if Application.MessageBox('此车外出未归,仍派此车吗?','确认吗?',
MB_OKCANCEL + MB_DEFBUTTON1) <> IDOK then
begin
ComboBox2.Text:='';
edit5.Text:='';
exit;
end;
end;
sql:='select VEHICLE_NO from WORK_INFO where (DATETIME>='+''''+datetostr(date)+''') and (TIME_FROM is NULL) AND (VEHICLE_NO='+''''+ComboBox2.Text+''')';
i:=paiche.Find(sql);
if i<>0 then //提示该车已有安排
begin
if Application.MessageBox('此车已有安排,仍派此车吗?','确认吗?',
MB_OKCANCEL + MB_DEFBUTTON1) <> IDOK then
begin
ComboBox2.Text:='';
edit5.Text:='';
exit;
end;
end;
// 按车辆编号,自动填入车型
edit5.Text:=vehicle.GetVehicleType(combobox2.Text);
end;
end;
procedure Tpaicheinfrm.Button1Click(Sender: TObject);
begin //保存派车单
if (Edit1.Text='')or(Combobox1.Text='') then
begin
showmessage('用车单位、用车性质资料不全!');
exit;
end;
if Application.MessageBox('您确定要保存这条派车记录吗?','确定吗?',
MB_OKCANCEL + MB_DEFBUTTON1) = IDOK then
begin
sql:='insert into work_info (PAICHE_ID,DATETIME,USER_COMPANY,USER1,'
+'PURPOSE,PLACE_FROM,PLACE_TO,DAY_BOOKED,VEHICLE_NO,VEHICLE_TYPE,'
+'DRIVER_ID,OPERTATOR,REMARK)'
+'values('''+no+''','''+datestr+''','''+edit1.Text+''','''+edit2.Text+''','
+''''+combobox1.Text+''','''+edit3.Text+''','''+edit4.Text+''','
+''''+datetostr(datetimepicker2.DateTime)+''','''+combobox2.Text+''','''+edit5.Text+''','
+''''+combobox3.Text+''','''+loginfrm.user+''','''+memo1.Text+''')';
paiche.Execu(sql);
paicheinfrm.DoShow; //重新显示当前派车情况
end;
end;
procedure Tpaicheinfrm.Button3Click(Sender: TObject);
begin
//不保存,不退出,重新录入派车单
if Application.MessageBox('您确实要取消这条派车记录吗?','确认吗?',
MB_OKCANCEL + MB_DEFBUTTON1) = IDOK then
begin
paicheinfrm.DoShow; //重新显示当前派车情况
end;
end;
procedure Tpaicheinfrm.Button2Click(Sender: TObject);
begin
driver.Free;
vehicle.Free;
paiche.Free;
close;
end;
procedure Tpaicheinfrm.FormCreate(Sender: TObject);
begin
paiche:=Tpaichein.create;
driver:=Tdriverdata.create;
vehicle:=Tvehicledata.create;
ShortdateFormat:='YYYY-MM-DD'; //确定日期格式
LongDateFormat:='YYYY-MM-DD';
DateSeparator:='-';
datestr:=datetostr(date); //当前日期
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -