Смекни!
smekni.com

Проектирование Базы Данных для коммерческого предприятия (стр. 13 из 14)

procedure SpeedButton2Click(Sender: TObject);

procedure N13Click(Sender: TObject);

procedure N4Click(Sender: TObject);

procedure N5Click(Sender: TObject);

procedure N9Click(Sender: TObject);

procedure SpeedButton4Click(Sender: TObject);

procedure N18Click(Sender: TObject);

procedure N19Click(Sender: TObject);

procedure N20Click(Sender: TObject);

procedure N21Click(Sender: TObject);

procedure N22Click(Sender: TObject);

procedure SpeedButton6Click(Sender: TObject);

procedure N24Click(Sender: TObject);

procedure SpeedButton7Click(Sender: TObject);

procedure N25Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

MainForm: TMainForm;

editmark: boolean;

stDay : array[1..7] of string[11] = ('воскресенье','понедельник','вторник',

'среда','четверг','пятница','суббота');

implementation

uses Unit1, Unit2, Unit3, Unit4, Unit5;

{$R *.DFM}

procedure TMainForm.ComboBox1Change(Sender: TObject);

begin

warehouse.Active := false;

if combobox1.ItemIndex = 0 then begin

warehouse.TableName:='Audi.db';

end;

if combobox1.ItemIndex = 1 then begin

warehouse.TableName:= 'Volkswagen.db';

end;

if combobox1.ItemIndex = 2 then begin

warehouse.TableName := 'Skoda.db';

end;

warehouse.ReadOnly:=false;

dbgrid1.ReadOnly:=true;

warehouse.Active := true;

end;

procedure TMainForm.N8Click(Sender: TObject);

begin

application.Terminate;

end;

procedure TMainForm.FormCreate(Sender: TObject);

var Present: TDateTime;

year, month, day : word;

begin

present:=now;

decodedate(present,year,month,day);

statusbar1.Panels[2].Text:=inttostr(day)+'.'+inttostr(month)+'.'+inttostr(year)+', '+stDay[DayOfWeek(Present)];

end;

procedure TMainForm.N3Click(Sender: TObject);

begin

warehouse.Active := false;

if opendialog1.Execute then begin

warehouse.TableName:=opendialog1.FileName;

warehouse.Active:=true;

end;

end;

procedure TMainForm.Timer1Timer(Sender: TObject);

var date: Tdatetime;

begin

statusbar1.Panels[1].Text:=timetostr(time);

end;

procedure TMainForm.N6Click(Sender: TObject);

begin

combobox1.ItemIndex := -1;

warehouse.Active :=false;

warehouse.TableName := '';

end;

procedure TMainForm.SpeedButton1MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Добавить';

end;

procedure TMainForm.SpeedButton2MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Редактировать';

end;

procedure TMainForm.SpeedButton4MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Быстрыйпоиск';

end;

procedure TMainForm.SpeedButton5MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Покупка';

End;

procedure TMainForm.SpeedButton7MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Опрограмме';

end;

procedure TMainForm.SpeedButton8MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Выходизприложения';

end;

procedure TMainForm.SpeedButton3MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Удалить';

end;

procedure TMainForm.SpeedButton6MouseMove(Sender: TObject;

Shift: TShiftState; X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='Выгрузить/Добавитьнасклад';

end;

procedure TMainForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X,

Y: Integer);

begin

Statusbar1.Panels[0].Text:='';

end;

procedure TMainForm.ToolBar1MouseMove(Sender: TObject; Shift: TShiftState;

X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='';

end;

procedure TMainForm.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState;

X, Y: Integer);

begin

Statusbar1.Panels[0].Text:='';

end;

procedure TMainForm.SpeedButton1Click(Sender: TObject);

begin

if editmark=false then begin

label1.Caption:='Редактирование';

dbgrid1.Color:=clteal;

dbgrid1.ReadOnly:=false; warehouse.insert; editmark:=true end

else begin

dbgrid1.ReadOnly:=true; editmark:=false;

label1.Caption:='';

dbgrid1.Color:=clwindow; end;

end;

procedure TMainForm.SpeedButton3Click(Sender: TObject);

var k:integer;

begin

k:=messagebox(0,'Удалитьзапись?','Удаление',33);

if k=1 then begin

memo1.Lines.Add(Timetostr(time)+' Записьбылаудаленаизтаблицы [ '+inttostr(warehouse.fieldbyname('Код').Value)+' '+warehouse.fieldbyname('Наименование').Value+' ]');

warehouse.Delete;

end;

end;

procedure TMainForm.SpeedButton5Click(Sender: TObject);

begin

Application.CreateForm(TForm1, Form1);

Form1.Show;

end;

procedure TMainForm.SpeedButton8Click(Sender: TObject);

begin

application.Terminate;

end;

procedure TMainForm.SpeedButton2Click(Sender: TObject);

begin

if editmark=false then begin

label1.Caption:='Редактирование';

dbgrid1.Color:=clteal;

dbgrid1.ReadOnly:=false; warehouse.Edit; editmark:=true end

else begin

dbgrid1.ReadOnly:=true; editmark:=false;

label1.Caption:='';

memo1.Lines.Add(Timetostr(time)+' Таблицабылаотредактирована');

dbgrid1.Color:=clwindow; end;

end;

procedure TMainForm.N13Click(Sender: TObject);

begin

speedbutton5.Click;

end;

procedure TMainForm.N4Click(Sender: TObject);

begin

speedbutton1.Click;

end;

procedure TMainForm.N5Click(Sender: TObject);

begin

speedbutton2.Click;

end;

procedure TMainForm.N9Click(Sender: TObject);

begin

speedbutton3.Click;

end;

procedure TMainForm.SpeedButton4Click(Sender: TObject);

begin

Application.CreateForm(TForm2, Form2);

Form2.show;

end;

procedure TMainForm.N18Click(Sender: TObject);

begin

warehouse.IndexFieldNames:='Код';

end;

procedure TMainForm.N19Click(Sender: TObject);

begin

warehouse.IndexFieldNames:='Наименование';

end;

procedure TMainForm.N20Click(Sender: TObject);

begin

warehouse.IndexFieldNames:='Датавыпуска';

end;

procedure TMainForm.N21Click(Sender: TObject);

begin

warehouse.IndexFieldNames:='Датапоступления';

end;

procedure TMainForm.N22Click(Sender: TObject);

begin

warehouse.IndexFieldNames:='Группа';

end;

procedure TMainForm.SpeedButton6Click(Sender: TObject);

begin

Application.CreateForm(TForm3, Form3);

form3.Show;

form3.dbgrid1.DataSource:=datasource1;

end;

procedure TMainForm.N24Click(Sender: TObject);

var i,R,P,SR,SP: integer;

begin

Application.CreateForm(TForm4, Form4);

SR:=0; SP:=0;

form4.Show;

R:=0;

P:=0;

warehouse.Active:=false;

warehouse.TableName:='Audi.db';

warehouse.active:=true;

warehouse.First;

for i:=1 to warehouse.RecordCount do begin

R:=R+mainform.warehouse.fieldbyname('Кол-во').Value;

P:=P+mainform.warehouse.fieldbyname('Кол-во').Value*mainform.warehouse.fieldbyname('Ценазакупки').Value;

warehouse.Next;

end;

form4.label2.Caption:=inttostr(R);

form4.Label4.Caption:=inttostr(P); SR:=R; Sp:=P;

{second table}

R:=0;

P:=0;

warehouse.Active:=false;

warehouse.TableName:='Volkswagen.db';

warehouse.Active:=true;

warehouse.First;

for i:=1 to warehouse.RecordCount do begin

R:=R+mainform.warehouse.fieldbyname('Кол-во').Value;

P:=P+mainform.warehouse.fieldbyname('Кол-во').Value*mainform.warehouse.fieldbyname('Ценазакупки').Value;

warehouse.Next;

end;

form4.label6.Caption:=inttostr(R);

form4.Label7.Caption:=inttostr(P); SR:=SR+R; SP:=SP+P;

{third table}

R:=0;

P:=0;

warehouse.Active:=false;

warehouse.TableName:='Skoda.db';

warehouse.Active:=true;

warehouse.First;

for i:=1 to warehouse.RecordCount do begin

R:=R+mainform.warehouse.fieldbyname('Кол-во').Value;

P:=P+mainform.warehouse.fieldbyname('Кол-во').Value*mainform.warehouse.fieldbyname('Ценазакупки').Value;

warehouse.Next;

end;

form4.label8.Caption:=inttostr(R);

form4.Label9.Caption:=inttostr(P); SR:=SR+R; SP:=SP+P;

form4.Label17.Caption:=inttostr(SR);

form4.Label19.caption:=inttostr(SP);

warehouse.Active:=false;

warehouse.TableName:=combobox1.text+'.db';

warehouse.Active:=true;

end;

procedure TMainForm.SpeedButton7Click(Sender: TObject);

begin

Application.CreateForm(TForm5, Form5);

Form5.Show;

end;

procedure TMainForm.N25Click(Sender: TObject);

begin

warehouse.edit; warehouse.Post;

memo1.Lines.Add(Timetostr(time)+' Все изменения сохранены');

end;

end.

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ComCtrls, Mask, DBCtrls, DB, DBTables, Spin, Buttons;

type

TForm1 = class(TForm)

GroupBox1: TGroupBox;

Label1: TLabel;

Label2: TLabel;

GroupBox2: TGroupBox;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Edit2: TEdit;

ComboBox1: TComboBox;

MaskEdit1: TMaskEdit;

DateTimePicker1: TDateTimePicker;

SpinEdit1: TSpinEdit;

SpinEdit2: TSpinEdit;

Edit1: TEdit;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

procedure Button2Click(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses Mainunit;

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);

begin

mainform.warehouse.Delete;

Form1.Close;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

mainform.warehouse.InsertRecord([edit2.text,edit1.text,maskedit1.text,spinedit2.text,spinedit1.text,'',combobox1.text,datetimepicker1.date]);

mainform.Memo1.Lines.Add('Произведенапокупка'+timetostr(time));

form1.Close;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

mainform.warehouse.InsertRecord([edit2.text,edit1.text,maskedit1.text,spinedit2.text,spinedit1.text,'',combobox1.text,datetimepicker1.date]);

mainform.Memo1.Lines.Add(timetostr(time)+' Произведенапокупка '+edit1.Text+' [ '+spinedit2.Text+' поцене '+spinedit1.text+'р. ]');

edit1.Clear;

edit2.Clear;

combobox1.Clear;

maskedit1.Clear;

spinedit1.Clear;

spinedit2.Clear;

form1.Close;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);

begin

edit1.Clear;

edit2.Clear;

combobox1.Clear;

maskedit1.Clear;

spinedit1.Clear;

spinedit2.Clear;

Form1.Close;

end;

end.

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Mask, DBCtrls, ComCtrls;

type

TForm2 = class(TForm)

Edit1: TEdit;

ComboBox1: TComboBox;

GroupBox1: TGroupBox;

ComboBox2: TComboBox;

Button1: TButton;

MaskEdit1: TMaskEdit;

procedure DBEdit1Change(Sender: TObject);

procedure Edit1Change(Sender: TObject);

procedure ComboBox1Change(Sender: TObject);

procedure ComboBox2Change(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure FormClose(Sender: TObject; var Action: TCloseAction);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

p,pd: integer;

implementation

uses MainUnit;

{$R *.dfm}

procedure TForm2.DBEdit1Change(Sender: TObject);

begin

mainform.warehouse.FindField('Код');

end;

procedure TForm2.Edit1Change(Sender: TObject);

var lan,i,mark: integer;

strmark: string;

begin

lan:=mainform.warehouse.RecordCount;

mainform.warehouse.First;

if edit1.text='' then begin mark:=0; end

else begin

if p=0 then begin mark:=strtoint(edit1.text);

for i:=0 to lan do begin

if mainform.warehouse.Fields[p].AsInteger=mark then

else mainform.warehouse.Next;

end; end;

if ((p=1) or (p=6)) then begin strmark:=edit1.Text;

for i:=0 to lan do begin

mainform.warehouse.setkey;

mainform.warehouse.IndexFieldNames:=mainform.warehouse.Fields[p].FieldName;

mainform.warehouse.FindNearest([edit1.text]);

end; end;

end;

end;

procedure TForm2.ComboBox1Change(Sender: TObject);

begin

case combobox1.ItemIndex of

0: p:=0;

1: p:=1;

2: p:=6; end;

end;

procedure TForm2.ComboBox2Change(Sender: TObject);

begin

case combobox2.ItemIndex of

0: pd:=2;

1: pd:=7; end;

end;

procedure TForm2.Button1Click(Sender: TObject);

begin

if pd=0 then pd:=2;

if maskedit1.Text='' then else

begin mainform.warehouse.SetKey;

mainform.warehouse.IndexFieldNames:=mainform.warehouse.Fields[pd].FieldName;

mainform.warehouse.FindNearest([maskedit1.text]);

end;

end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);

begin

edit1.Text:=''; maskedit1.Text:='';

end;

end.

unit Unit3;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables, Buttons, Mask, DBCtrls,

ExtCtrls;

type

TForm3 = class(TForm)

DataSource1: TDataSource;

DBGrid1: TDBGrid;

Edit2: TEdit;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

DBEdit1: TDBEdit;

GroupBox1: TGroupBox;

ComboBox1: TComboBox;

Edit1: TEdit;

Button1: TButton;

GroupBox2: TGroupBox;

Label2: TLabel;

RadioGroup1: TRadioGroup;

RadioButton1: TRadioButton;

RadioButton2: TRadioButton;

Label1: TLabel;

Memo1: TMemo;

procedure Button2Click(Sender: TObject);

procedure Edit1Change(Sender: TObject);

procedure ComboBox1Change(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);

procedure Edit2Change(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure ComboBox2Change(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure FormClose(Sender: TObject; var Action: TCloseAction);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form3: TForm3;

p,pd: integer;

implementation

uses mainunit;

{$R *.dfm}

procedure TForm3.Button2Click(Sender: TObject);

begin

form3.Close;

end;

procedure TForm3.Edit1Change(Sender: TObject);

var lan,i,mark: integer;

strmark: string;

begin

lan:=mainform.warehouse.RecordCount;

mainform.warehouse.First;

if edit1.text='' then begin mark:=0; end

else begin

if p=0 then begin mark:=strtoint(edit1.text);

for i:=0 to lan do begin

if mainform.warehouse.Fields[p].AsInteger=mark then

else mainform.warehouse.Next;

end; end;

if ((p=1) or (p=6)) then begin strmark:=edit1.Text;