Смекни!
smekni.com

Разработка информационно-справочной системы по учету вагонов на подъездном пути предприятия (стр. 25 из 27)

begin

Polya := pole2+'='+#39+ToIns+#39+','+pole3+'='+#39+ToIns2+#39+','+pole4+'='+#39+ToIns3+#39+','+pole5+'='+#39+ToIns4+#39+','+pole6+'='+#39+ToIns5+#39+','+pole7+'='+#39+ToIns6+#39;

QueryString := 'UPDATE '+TBL+' SET '+Polya+' where '+pole1+'='+ForEdit;

InsEdit5 := false;

end

else

QueryString := 'insert into '+ TBL +' ('+pole2+', '+pole3+', '+pole4+', '+pole5+', '+pole6+', '+pole7+') values ('+#39+ToIns+#39+', '+#39+ToIns2+#39+', '+#39+ToIns3+#39+', '+#39+ToIns4+#39+', '+#39+ToIns5+#39+', '+#39+ToIns6+#39+')';

end;

if (YN = false) then

begin

ShowMessage(QueryString);

with SelectQ do

begin

Close;

SQL.Clear;

SQL.Add(QueryString);

ExecSQL;

end;

end

else

ShowMessage('Либо такая запись есть, либо запись введена не корректно');

end;

Procedure DelZapros();

var

TmpString: string;

begin

TmpString := 'delete from '+ TBL +' where ' + pole1 +'=' + ForDel;

// ShowMessage(TmpString);

with DataModule2.Query1 do

begin

Close;

SQL.Clear;

SQL.Add(TmpString);

ExecSQL;

end;

end;

Procedure SelTab();

begin

if (Tbl = 'Rod_vagona') then

begin

Form6.Edit9.Text := SelectQ[pole2];

Form6.Edit9.Tag := SelectQ[pole1];

end;

if (Tbl = 'Raion_dvizheniya') then

begin

Form6.Edit10.Text := SelectQ[pole2];

Form6.Edit10.Tag := SelectQ[pole1];

end;

if (Tbl = 'Station')and(Form3.Caption = 'Станция отправитель') then

begin

Form7.Edit1.Text := SelectQ[pole2];

Form7.Edit1.Tag := SelectQ[pole1];

end;

if (Tbl = 'Station')and(Form3.Caption = 'Станция получатель') then

begin

Form7.Edit7.Text := SelectQ[pole2];

Form7.Edit7.Tag := SelectQ[pole1];

end;

if (Tbl = 'Front')and(Form3.Caption = 'Фронт отправитель') then

begin

Form7.Edit2.Text := SelectQ[pole2];

Form7.Edit2.Tag := SelectQ[pole1];

end;

if (Tbl = 'Front')and(Form3.Caption = 'Фронт получатель') then

begin

Form7.Edit8.Text := SelectQ[pole2];

Form7.Edit8.Tag := SelectQ[pole1];

end;

if (Tbl = 'Operation') then

begin

Form7.Edit9.Text := SelectQ[pole2];

Form7.Edit9.Tag := SelectQ[pole1];

end;

if (Tbl = 'Gruz') then

begin

Form7.Edit10.Text := SelectQ[pole2];

Form7.Edit10.Tag := SelectQ[pole1];

end;

if (Tbl = 'Ceha')and(Form3.Caption = 'Цех заказчик') then

begin

Form8.Edit2.Text := SelectQ[pole2];

Form8.Edit2.Tag := SelectQ[pole1];

end;

if (Tbl = 'Ceha')and(Form3.Caption = 'Цех исполнитель') then

begin

Form8.Edit3.Text := SelectQ[pole2];

Form8.Edit3.Tag := SelectQ[pole1];

end;

if (Tbl = 'Vid_uslug') then

begin

Form5.Edit1.Text := SelectQ[pole2];

Form5.Edit1.Tag := SelectQ[pole1];

end;

if (Tbl = 'Ves') then

begin

Form5.Edit2.Text := SelectQ[pole2];

Form5.Edit2.Tag := SelectQ[pole1];

end;

end;

Procedure ForReport();

var

Polya, Tabli, Tabli2, Svyaz, Svyaz2, QueryString : string;

begin

Polya := 'n_dor_ved,invent_nomer,OSV.mydate, OSV.mytime,STN.station as STN,FN.front as FN,CNA.n_ceha as NA,CNA.bal_schet as BSO,STK.station as STK,FK.front as FK,CS.n_ceha as CS,CS.bal_schet as CBS,G.gruz,VU.vid_uslug,VE.ves,weight,cena';

Tabli := 'Vagon V, Rod_vagona RV, Raion_dvizheniya RD, Operations_s_vagonom OSV, Uslugi_sv USV, Stoimost ST, Vid_uslug VU, Ves VE, Ceha CNA, Ceha CS, Station STN, Station STK';

Tabli2 := 'Front FN, Front FK, Operation OP, Gruz G';

Svyaz := 'V.key_rod_vagona=RV.id and V.key_raion_dvizh=RD.id and V.id=OSV.key_vagon and OSV.id=USV.key_vagon and ST.id=USV.key_uslugi and VU.id=ST.key_vid_uslug and VE.id=ST.key_ves and USV.key_na=CNA.id and USV.key_s=CS.id';

Svyaz2 := 'STN.id=OSV.key_station_otpr and STK.id=key_Station_naznach and FN.id=OSV.key_front_otpr and FK.id=OSV.key_front_naznach and OSV.key_operation=OP.id and OSV.key_gruz=G.id';

if ForSort then

begin

QueryString := 'select '+Polya+' from '+Tabli+ ', '+ Tabli2 +' where '+Svyaz + ' and ' + Svyaz2 + ' order by '+ ForOrder;

end;

if ForFiltr then

begin

QueryString := 'select '+Polya+' from '+Tabli+ ', '+ Tabli2 +' where '+Svyaz + ' and ' + Svyaz2 + ' and '+ TmpFiltr;

end;

if ((ForSort=false)and(ForFiltr=False)) then

begin

QueryString := 'select '+Polya+' from '+Tabli+ ', '+ Tabli2 +' where '+Svyaz + ' and ' + Svyaz2 + ' order by invent_nomer desc';

end;

with DataModule2.QueryRep do

begin

Close;

SQL.Clear;

SQL.Add(QueryString);

if ForFiltr then

begin

Parameters.ParamByName('Par1').Value := Form10.Edit1.Text;

Parameters.ParamByName('Par2').Value := Form10.Edit2.Text;

end;

Open;

end;

Form9.DBGrid1.Columns[0].Title.Caption :='№ дор. вед.';

Form9.DBGrid1.Columns[1].Title.Caption :='Инвент. №';

Form9.DBGrid1.Columns[2].Title.Caption :='Дата';

Form9.DBGrid1.Columns[3].Title.Caption :='Время';

Form9.DBGrid1.Columns[4].Title.Caption :='Станция отпр.';

Form9.DBGrid1.Columns[5].Title.Caption :='Фронт отпр.';

Form9.DBGrid1.Columns[6].Title.Caption :='№ цеха отпр.';

Form9.DBGrid1.Columns[7].Title.Caption :='БС цеха отпр.';

Form9.DBGrid1.Columns[8].Title.Caption :='Станция заказ.';

Form9.DBGrid1.Columns[9].Title.Caption :='Фронт заказ.';

Form9.DBGrid1.Columns[10].Title.Caption :='№ цеха заказ.';

Form9.DBGrid1.Columns[11].Title.Caption :='БС цеха заказ.';

Form9.DBGrid1.Columns[12].Title.Caption :='Груз';

Form9.DBGrid1.Columns[13].Title.Caption :='Операция';

Form9.DBGrid1.Columns[14].Title.Caption :='Ед. изм.';

Form9.DBGrid1.Columns[15].Title.Caption :='Вес';

Form9.DBGrid1.Columns[16].Title.Caption :='Цена';

end;

end.


unit Unit5;

interface

uses

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

Dialogs, StdCtrls, Grids, DBGrids;

type

TForm5 = class(TForm)

GroupBox1: TGroupBox;

Edit1: TEdit;

Button1: TButton;

Edit2: TEdit;

Edit3: TEdit;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

procedure Button1Click(Sender: TObject);

procedure FormShow(Sender: TObject);

procedure Edit1Enter(Sender: TObject);

procedure Edit2Enter(Sender: TObject);

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

procedure Edit3Exit(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form5: TForm5;

implementation

Uses Unit2, Unit4, Unit3;

{$R *.dfm}

procedure TForm5.Button1Click(Sender: TObject);

begin

ToIns := IntToStr(Edit1.Tag);

ToIns2 := IntToStr(Edit2.Tag);

ToIns3 := Edit3.Text;

If ((Edit1.Text<>'')and(Edit2.Text<>'')and(Edit3.Text<>'')) then

begin

if EditMode4 then

begin

ForEdit := DataModule2.QSelUs['ST.id'];

InsEdit2 := true;

InsertZapros();

ShowZapros();

end

else

begin

InsertZapros();

ShowZapros();

ForEdit := '-1';

end;

Form5.Close;

end

else

ShowMessage('Все поля обязательны к заполнению!');

end;

procedure TForm5.FormShow(Sender: TObject);

begin

TBL:='Stoimost';

if EditMode4 then

begin

Edit1.Text := DataModule2.QSelUs['vid_uslug'];

Edit1.Tag := StrToInt(DataModule2.QSelUs['key_vid_uslug']);

Edit2.Text := DataModule2.QSelUs['ves'];

Edit2.Tag := StrToInt(DataModule2.QSelUs['key_ves']);

Edit3.Text := DataModule2.QSelUs['stoimost'];

Form5.Edit3.SetFocus;

end

else

begin

Edit1.Text := '';

Edit2.Text := '';

Edit2.Tag := 0;

Edit3.Text := '';

Edit3.Tag := 0;

Button1.SetFocus;

end

end;

procedure TForm5.Edit1Enter(Sender: TObject);

begin

Form3.Caption := 'Вид услуг';

Form3.Label1.Caption:= Form3.Caption;

Tbl := 'Vid_uslug';

pole1 := 'id';

pole2 := 'vid_uslug';

pole3 := '';

pole4 := '';

pole5 := '';

pole6 := '';

pole7 := '';

pole8 := '';

pole9 := '';

pole10 := '';

pole11 := '';

pole12 := '';

pole13 := '';

ShowZapros;

Form3.ShowModal;

Tbl := 'Stoimost';

Form5.Edit2.SetFocus;

end;

procedure TForm5.Edit2Enter(Sender: TObject);

begin

Form3.Caption := 'Единица измерения';

Form3.Label1.Caption:= Form3.Caption;

Tbl := 'Ves';

pole1 := 'id';

pole2 := 'ves';

pole3 := '';

pole4 := '';

pole5 := '';

pole6 := '';

pole7 := '';

pole8 := '';

pole9 := '';

pole10 := '';

pole11 := '';

pole12 := '';

pole13 := '';

ShowZapros;

Form3.ShowModal;

Tbl := 'Stoimost';

Form5.Edit3.SetFocus;

end;

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

begin

if EditMode4 then

begin

EditMode4:=false;

end;

TBL:='Uslugi_sv';

end;

procedure TForm5.Edit3Exit(Sender: TObject);

var ResVar : real;

E : integer;

begin

try

strtofloat(Edit3.Text);

except

ShowMessage('Здесь должно быть число!!... ну или поменяйте точку на запятую;)');

Edit3.SetFocus;

end;

end;

end.

unit Unit6;

interface

uses

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

Dialogs, StdCtrls, Grids, DBGrids, ActnList, Menus, ComCtrls;

type

TForm6 = class(TForm)

GroupBox1: TGroupBox;

ComboBox1: TComboBox;

Edit2: TEdit;

Edit3: TEdit;

Edit5: TEdit;

Button1: TButton;

GroupBox2: TGroupBox;

DBGrid1: TDBGrid;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label8: TLabel;

Label10: TLabel;

Edit8: TEdit;

Label12: TLabel;

Edit9: TEdit;

Edit10: TEdit;

PopupMenu1: TPopupMenu;

ActionList1: TActionList;

add: TAction;

edit: TAction;

del: TAction;

N1: TMenuItem;

N2: TMenuItem;

N3: TMenuItem;

DateTimePicker1: TDateTimePicker;

DateTimePicker2: TDateTimePicker;

procedure Button1Click(Sender: TObject);

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

procedure FormShow(Sender: TObject);

procedure Edit9Enter(Sender: TObject);

procedure Edit10Enter(Sender: TObject);

procedure addExecute(Sender: TObject);

procedure editExecute(Sender: TObject);

procedure delExecute(Sender: TObject);

procedure Edit2Exit(Sender: TObject);

procedure Edit3Exit(Sender: TObject);

procedure Edit5Exit(Sender: TObject);

procedure Edit8Exit(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form6: TForm6;

implementation

Uses Unit2, Unit4, Unit3, Unit7, DateUtils;

{$R *.dfm}

procedure TForm6.Button1Click(Sender: TObject);

var qtmp: string;

begin

ToIns := ComboBox1.Items[ComboBox1.ItemIndex];

ToIns2 := IntToStr(YearOf(DateTimePicker1.Date));

ToIns3 := Edit2.Text;

ToIns4 := Edit3.Text;

ToIns5 := IntToStr(YearOf(DateTimePicker2.Date));

ToIns6 := Edit5.Text;

ToIns7 := IntToStr(Edit9.Tag);

ToIns8 := Edit8.Text;

ToIns9 := IntToStr(Edit10.Tag);

If ((ComboBox1.Text<>'')and(Edit2.Text<>'')and(Edit3.Text<>'')

and(Edit5.Text<>'')and(Edit8.Text<>'')and(Edit9.Text<>'')and(Edit10.Text<>'')) then

begin

if EditMode then

begin

ForEdit := DataModule2.QShow['V.id'];

InsEdit3 := true;

InsertZapros();

ShowZapros();

end

else

begin

EditIns := true;

InsertZapros();

QueryString:='SELECT top 1 id from '+ TBL+' order by id desc';

with DataModule2.Qtmp do

begin

Close;

SQL.Clear;

SQL.Add(QueryString);

Open;

end;

qtmp := DataModule2.Qtmp['id'];

Form6.Close;

ShowZapros();

DataModule2.QShow.Locate('v.id',qtmp,[]);

ForEdit := '-1';

end;

Form6.Close;

end

else

ShowMessage('Все поля обязательны к заполнению!');

end;

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

begin

if EditMode then

begin

EditMode:=false;

end;

end;

procedure TForm6.FormShow(Sender: TObject);

var i, k: integer;

begin

EditIns := False;

if EditMode then

begin

DBGrid1.Visible := true;

DateTimePicker1.Date := StrToDate('01.01.'+ DataModule2.QShow['myyear']);

Edit2.Text := DataModule2.QShow['nomer_vagona'];

Edit3.Text := DataModule2.QShow['invent_nomer'];

DateTimePicker2.Date := StrToDate('01.01.'+ DataModule2.QShow['year_izgot']);

Edit5.Text := DataModule2.QShow['gruzopodemnost'];

Edit8.Text := DataModule2.QShow['iznos'];

Edit9.Text := DataModule2.QShow['rod_vagona'];

Edit9.Tag := DataModule2.QShow['rv.id'];

Edit10.Text := DataModule2.QShow['raion_dvizh'];

Edit10.Tag := DataModule2.QShow['rd.id'];

For i:=0 to ComboBox1.Items.Count do

begin

ComboBox1.ItemIndex := i;

if ComboBox1.Items[ComboBox1.ItemIndex] = DataModule2.QShow['mymonth'] then

k := ComboBox1.ItemIndex;

end;

ComboBox1.ItemIndex := k;

Tbl:='Operations_s_vagonom';

ShowZapros();

end

else

begin

DateTimePicker1.Date := Date;

DateTimePicker2.Date := StrToDate('01.01.1950');

Edit2.Text := '';

Edit3.Text := '';

Edit5.Text := '';

Edit8.Text := '';

Edit9.Text := '';

Edit9.Tag := 0;

Edit10.Text := '';

Edit10.Tag := 0;

DBGrid1.Visible := false;

end;

TBL:='Vagon';

end;

procedure TForm6.Edit9Enter(Sender: TObject);

begin

Form3.Caption := 'Род вагона';

Form3.Label1.Caption:= Form3.Caption;

Tbl := 'Rod_vagona';

pole1 := 'id';

pole2 := 'Rod_vagona';

pole3 := '';

pole4 := '';

pole5 := '';

pole6 := '';

pole7 := '';

pole8 := '';

pole9 := '';

pole10 := '';

pole11 := '';

pole12 := '';

pole13 := '';

ShowZapros;

Form3.ShowModal;

Tbl := 'Vagon';

Edit10.SetFocus;

end;

procedure TForm6.Edit10Enter(Sender: TObject);

begin

Form3.Caption := 'Район движения';

Form3.Label1.Caption:= Form3.Caption;

Tbl := 'Raion_dvizheniya';