table.Next;
end;
gen_id:=n+1;
end;
procedure TFadd.LMDSpeedButton4Click(Sender: TObject);
begin
OpenPictureDialog1.Execute;
Продолжение приложения А
pic1:=OpenPictureDialog1.FileName;
if pic1<>'' then Image4.Picture.LoadFromFile(pic1)
else begin
MessageBox(Handle,'Фотография кузова не выбрана!','',MB_OK);
exit;
end;
end;
procedure TFadd.LMDSpeedButton5Click(Sender: TObject);
begin
OpenPictureDialog1.Execute;
pic2:=OpenPictureDialog1.FileName;
if pic2<>'' then Image5.Picture.LoadFromFile(pic2)
else begin
MessageBox(Handle,'Фотография салона не выбрана!','',MB_OK);
exit;
end;
end;
procedure TFadd.LMDSpeedButton2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
edit6.Text:='';
edit7.Text:='';
edit8.Text:='';
edit9.Text:='';
edit10.Text:='';
edit11.Text:='';
edit12.Text:='';
edit13.Text:='';
edit14.Text:='';
CheckBox1.Checked:=false;
CheckBox2.Checked:=false;
CheckBox3.Checked:=false;
CheckBox4.Checked:=false;
CheckBox5.Checked:=false;
CheckBox6.Checked:=false;
CheckBox7.Checked:=false;
CheckBox8.Checked:=false;
Memo1.Clear;
Memo2.Clear;
end;
procedure TFadd.FormCreate(Sender: TObject);
begin
// dm1.vlad.Close;
// dm1.vlad.Open;
Memo1.Clear;
Memo2.Clear;
end;
procedure TFadd.LMDSpeedButton3Click(Sender: TObject);
begin
close;
end;
Продолжение приложения А
procedure TFadd.FormClose(Sender: TObject; var Action: TCloseAction);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
edit6.Text:='';
edit7.Text:='';
edit8.Text:='';
edit9.Text:='';
edit10.Text:='';
edit11.Text:='';
edit12.Text:='';
edit13.Text:='';
edit14.Text:='';
CheckBox1.Checked:=false;
CheckBox2.Checked:=false;
CheckBox3.Checked:=false;
CheckBox4.Checked:=false;
CheckBox5.Checked:=false;
CheckBox6.Checked:=false;
CheckBox7.Checked:=false;
CheckBox8.Checked:=false;
Memo1.Clear;
Memo2.Clear;
end;
procedure TFadd.LMDSpeedButton1Click(Sender: TObject);
var k1,k2,k3:integer;
st1,q1,st2,q2,v,a,a_i:string;
i,u:integer;
begin
if (edit1.Text='') or (edit2.Text='') or (edit3.Text='') or (edit4.Text='')
or (DBLookupComboBox2.KeyValue=Null) or (edit9.Text='') or (edit10.Text='') or (edit11.Text='')
or (edit12.Text='') or (edit13.Text='') or (edit14.Text='') or (pic1='')
or (pic2='') then begin
MessageBox(Handle,'Возможно некоторые поля не заполнены!','Внимание',MB_OK);
exit;
end
else begin
dm1.komplect.Append;
dm1.avto_in.Append;
v:='KOD_vlad';
k1:=gen_id(dm1.vlad,v);
dm1.vlad.Append;
dm1.vlad.FieldByName('KOD_vlad').Value:=k1;
dm1.vlad.FieldByName('FAM').Value:=edit1.text;
dm1.vlad.FieldByName('NAME').value:=edit2.Text;
dm1.vlad.FieldByName('OTH').value:=edit3.text;
dm1.vlad.FieldByName('adres').value:=edit4.text;
dm1.vlad.fieldByName('mail').value:=edit5.Text;
dm1.vlad.FieldByName('tel').value:=edit6.text;
dm1.vlad.FieldByName('sot').value:=edit7.text;
Продолжение приложения А
a:='KOD_avto';
k2:=gen_id(dm1.avto,a);
dm1.avto.Append;
dm1.avto.FieldByName('KOD_avto').Value:=k2;
dm1.avto.FieldByName('KOD_vlad').Value:=k1;
dm1.avto.FieldByName('marka').Value:=DBLookupComboBox2.KeyValue;
dm1.avto.FieldByName('model').value:=edit9.Text ;
dm1.avto.FieldByName('cvet').value:=edit11.text;
dm1.avto.FieldByName('gos_nom').value:=edit10.text ;
dm1.avto.fieldByName('tip_kuz').value:=ComboBox1.Text;
dm1.avto.FieldByName('v').value:=edit12.text;
dm1.avto.FieldByName('cena').value:=edit13.text;
st1:='';
q1:='';
for i:=length(pic1) downto 1 do
if pic1[i]<>'.' then insert(pic1[i],q1,0) else break;
st1:=ExtractFilePath(Application.Exename);
ForceDirectories(st1+'FOTO');
if dm1.avto.FieldByName('foto_1').AsString<>'' then
DeleteFile(st1+'FOTO\'+dm1.avto.FieldByName('foto_1').AsString);
if copyfileto(pchar(pic1),pchar(st1+'FOTO\'+inttostr(k2)+'kuz' + '.'+q1)) then
else begin
MessageBox(Handle,'Невозможно скопировать файл!','Внимание',MB_OK);
exit;
end;
dm1.avto.FieldByName('foto_1').AsString:=inttostr(k2)+'kuz' + '.'+q1;
st2:='';
q2:='';
for u:=length(pic2) downto 1 do
if pic2[u]<>'.' then insert(pic2[u],q2,0) else break;
st2:=ExtractFilePath(Application.Exename);
ForceDirectories(st2+'FOTO');
if dm1.avto.FieldByName('foto_2').AsString<>'' then
DeleteFile(st2+'FOTO\'+dm1.avto.FieldByName('foto_2').AsString);
if copyfileto(pchar(pic2),pchar(st2+'FOTO\'+inttostr(k2)+'sal' + '.'+q2)) then
else begin
MessageBox(Handle,'Невозможно скопировать файл!','Внимание',MB_OK);
exit;
end;
dm1.avto.FieldByName('foto_2').AsString:=inttostr(k2)+'sal' + '.'+q2;
dm1.komplect.FieldByName('KOD_avto').Value:=k2;
if CheckBox1.Checked=true then dm1.komplect.FieldByName('zapaska').Value:='true'
else dm1.komplect.FieldByName('zapaska').Value:='false';
if CheckBox2.Checked=true then dm1.komplect.FieldByName('instrument').Value:='true'
else dm1.komplect.FieldByName('instrument').Value:='false';
Продолжение приложения А
if CheckBox3.Checked=true then dm1.komplect.FieldByName('music').Value:='true'
else dm1.komplect.FieldByName('music').Value:='false';
if CheckBox4.Checked=true then dm1.komplect.FieldByName('medic').Value:='true'
else dm1.komplect.FieldByName('medic').Value:='false';
if CheckBox5.Checked=true then dm1.komplect.FieldByName('elect_pak').Value:='true'
else dm1.komplect.FieldByName('elect_pak').Value:='false';
if CheckBox6.Checked=true then dm1.komplect.FieldByName('abs').Value:='true'
else dm1.komplect.FieldByName('abs').Value:='false';
if CheckBox7.Checked=true then dm1.komplect.FieldByName('gur').Value:='true'
else dm1.komplect.FieldByName('gur').Value:='false';
if CheckBox8.Checked=true then dm1.komplect.FieldByName('kondic').Value:='true'
else dm1.komplect.FieldByName('kondic').Value:='false';
dm1.komplect.FieldByName('koleso').Value:=ComboBox2.Text;
dm1.komplect.FieldByName('korobka').Value:=ComboBox3.Text;
dm1.komplect.FieldByName('privod').Value:=ComboBox4.Text;
dm1.komplect.FieldByName('info').Value:=Memo1.Text;
dm1.komplect.FieldByName('defekt').Value:=Memo2.Text;
a_i:='KOD_avto';
k3:=gen_id(dm1.avto,a_i);
dm1.avto_in.FieldByName('KOD_in').Value:=k3;
dm1.avto_in.FieldByName('akt_nom').Value:=Edit14.Text;
dm1.avto_in.FieldByName('KOD_avto').Value:=k2;
dm1.avto_in.FieldByName('KOD_vlad').Value:=k1;
dm1.avto_in.FieldByName('KOD_sot').Value:=DBLookupComboBox1.KeyValue;
dm1.avto_in.FieldByName('data').Value:=DateEdit1.Date;
// dm1.vlad.Post;
// dm1.avto.Post;
dm1.komplect.Post;
dm1.avto_in.Post;
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
edit6.Text:='';
edit7.Text:='';
edit8.Text:='';
edit9.Text:='';
edit10.Text:='';
edit11.Text:='';
edit12.Text:='';
edit13.Text:='';
Продолжение приложения А
edit14.Text:='';
CheckBox1.Checked:=false;
CheckBox2.Checked:=false;
CheckBox3.Checked:=false;
CheckBox4.Checked:=false;
CheckBox5.Checked:=false;
CheckBox6.Checked:=false;
CheckBox7.Checked:=false;
CheckBox8.Checked:=false;
Memo1.Clear;
Memo2.Clear;
end;
end;
procedure TFadd.OpenPictureDialog1CanClose(Sender: TObject;
var CanClose: Boolean);
begin
MessageBox(Handle,'Вы не выбрали машину!','Внимание',MB_OK);
end;
procedure TFadd.Edit6KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'0'..'9',#8: key:=key
else key:=#0;
end;
end;
procedure TFadd.Edit7KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'0'..'9',#8: key:=key
else key:=#0;
end;
end;
procedure TFadd.Edit13KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'0'..'9',#8: key:=key
else key:=#0;
end;
end;
procedure TFadd.Edit14KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'0'..'9',#8: key:=key
else key:=#0;
end;
end;
procedure TFadd.DBLookupComboBox2Click(Sender: TObject);
begin
// Edit8.Text:=DBLookupComboBox2.KeyValue;
end;
Продолжение приложения А
end.
unit del;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, ExtCtrls, StdCtrls, LMDControl, LMDBaseControl,
LMDBaseGraphicButton,ActiveX,ComObj, ComCtrls, LMDCustomSpeedButton, LMDSpeedButton,DB;
type
TFdel = class(TForm)
Panel1: TPanel;
DBGrid1: TDBGrid;
Panel5: TPanel;
Panel2: TPanel;
Image1: TImage;
LMDSpeedButton1: TLMDSpeedButton;
Edit1: TEdit;
RadioGroup1: TRadioGroup;
Panel3: TPanel;
LMDSpeedButton2: TLMDSpeedButton;
Image2: TImage;
RadioGroup2: TRadioGroup;
Panel4: TPanel;
Image3: TImage;
LMDSpeedButton3: TLMDSpeedButton;
LMDSpeedButton4: TLMDSpeedButton;
procedure LMDSpeedButton1Click(Sender: TObject);
procedure LMDSpeedButton2Click(Sender: TObject);
procedure LMDSpeedButton4Click(Sender: TObject);
procedure LMDSpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Fdel: TFdel;
App, Ke, Abc : Variant;
ExelOtch : String;
Result : HResult;
AppProgID : string;
ServerIsRunning :boolean;
Unknown :IUnknown;
i:integer;
implementation
uses dm;
{$R *.dfm}
Продолжение приложения А
procedure TFdel.LMDSpeedButton1Click(Sender: TObject);
begin
if edit1.Text<>'' then begin
if RadioGroup1.ItemIndex=0 then
if dm1.avto_out.Locate('marka_out',edit1.Text,[loCaseInsensitive]) then
else MessageBox(Handle,'Нет автомобиля такой марки...','',MB_OK);
if RadioGroup1.ItemIndex=1 then
if dm1.avto_out.Locate('model_out',edit1.Text,[loCaseInsensitive]) then
else MessageBox(Handle,'Нет автомобиля такой модели...','',MB_OK);
end
else MessageBox(Handle,'Введите значение для поиска!','',MB_OK);
end;
procedure TFdel.LMDSpeedButton2Click(Sender: TObject);
begin
if RadioGroup2.ItemIndex=0 then
dm1.avto_out.IndexName:='marka_out';
if RadioGroup2.ItemIndex=1 then
dm1.avto_out.IndexName:='V_out';
if RadioGroup2.ItemIndex=2 then
dm1.avto_out.IndexName:='tipkuz_out';
end;
procedure TFdel.LMDSpeedButton4Click(Sender: TObject);
begin
close;
end;
procedure TFdel.LMDSpeedButton3Click(Sender: TObject);
begin
AppProgID := 'Excel.Application';
ServerIsRunning := False;
Result:=GetActiveObject(ProgIDToClassID(AppProgID),nil,Unknown);
try
if (Result = MK_E_UNAVAILABLE) then
App := CreateOleObject(AppProgID)
else
begin
App := GetActiveOleObject(AppProgID);
ServerIsRunning := True;
end;
ExelOtch:=ExtractFilePath(Application.EXEName)+'Проданные автомобили на '+DateToStr(Date)+'.xls';
App.WorkBooks.Add;
Ke:=App.WorkBooks[1];
Abc:=Ke.WorkSheets[1];
Abc.Name:='Проданные авто('+DateToStr(Date)+').xls';
except on EinOutError do begin
messageBox(handle,'Не удаётся создать файл!','Ошибка',MB_ICONERROR);
exit;
end;
end;
App.DisplayAlerts:=False;
Abc.Cells[1,3]:='Проданные авто('+DateToStr(Date)+').xls';
Продолжение приложения А
Abc.Cells[1,3].Font.Bold:=True;
Abc.Cells[1,3].Font.Size:=11;
dm1.avto_out.first;
i:=3;
while not dm1.avto_out.eof do begin
i:=i+1;
app.cells[i,1]:=vartostr(dm1.avto_out['Marka_out']);
Abc.Cells[i,1].ColumnWidth:=15;
app.cells[i,2]:=vartostr(dm1.avto_out['Model_out']);
Abc.Cells[i,2].ColumnWidth:=15;
app.cells[i,3]:=vartostr(dm1.avto_out['v_out']);
Abc.Cells[i,3].ColumnWidth:=5;
app.cells[i,4]:=vartostr(dm1.avto_out['cvet_out']);
Abc.Cells[i,4].ColumnWidth:=15;
app.cells[i,5]:=vartostr(dm1.avto_out['tipkuz_out']);
Abc.Cells[i,5].ColumnWidth:=15;
app.cells[i,6]:=vartostr(dm1.avto_out['cena_out']);
Abc.Cells[i,6].ColumnWidth:=10;
app.cells[i,7]:=vartostr(dm1.avto_out['date']);
Abc.Cells[i,7].ColumnWidth:=8;
dm1.avto_out.next;
end;
App.ActiveWorkBook.SaveAs(ExelOtch);
App.Quit;
App:=Unassigned;
AppProgID := 'Excel.Application';
App := CreateOleObject(AppProgID);
App.Visible := True;
ExelOtch:=ExtractFilePath(Application.EXEName)+'Проданные автомобили на '+DateToStr(Date)+'.xls';
App.WorkBooks.Open(ExelOtch);
end;
end.
unit dm;
interface
uses
SysUtils, Classes, DB, DBTables;
type
Tdm1 = class(TDataModule)
dsvlad: TDataSource;
dsavto: TDataSource;
dssot: TDataSource;
dskomplect: TDataSource;
dsavto_in: TDataSource;
dsavto_out: TDataSource;
Продолжение приложения А
sot: TTable;
komplect: TTable;
avto_in: TTable;
avto_out: TTable;
sotKOD_SOT: TSmallintField;
sotFAM: TStringField;
sotNAME: TStringField;
sotOTH: TStringField;
avto_inKOD_IN: TFloatField;
avto_inAKT_NOM: TFloatField;
avto_inKOD_AVTO: TFloatField;
avto_inKOD_VLAD: TFloatField;
avto_inKOD_SOT: TFloatField;
avto_inDATA: TDateField;
komplectKOD_AVTO: TFloatField;
komplectKOLESO: TStringField;
komplectZAPASKA: TBooleanField;
komplectINSTRUMENT: TBooleanField;
komplectMUSIC: TBooleanField;
komplectMEDIC: TBooleanField;