unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ValEdit, Data.DB, Data.Win.ADODB, Vcl.DBGrids,shellapi;

type
  TForm5 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    StringGrid1: TStringGrid;
    Button2: TButton;
    Label2: TLabel;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);

    {procedure ValueListEditor1StringsChange(Sender: TObject); }
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;
  mass:array[0..1,0..50] of string[100];

   procedure change(var s:string;substrdel,substrins:string);
   function dataseek(name:string):integer;
   function trimuntil(s:string):string;


implementation
Uses Mainmodule, unit2, Datamodule;
{$R *.dfm}



 procedure change(var s:string;substrdel,substrins:string);
 var k:integer;
 begin
 k:=pos(substrdel,s);
 if k<>0 then
 begin
 delete(s,k,length(substrdel));
 insert(substrins,s,k);
 end;

 end;

procedure TForm5.Button1Click(Sender: TObject);
var
n,i,r,k:integer;
begin
r:=form2.StringGrid1.Row;
n:=datamodule1.ADOTable1.FieldCount;
datamodule1.ADOTable1.Edit;
{if datamodule1.ADOTable1.FieldList.Fields[1].AsString<>form2.StringGrid1.Cells[0,r] then }
  k:=dataseek(form2.StringGrid1.Cells[0,r]);
  if k=0 then
   begin
  datamodule1.ADOTable1.append;
  {datamodule1.ADOTable1.Last;}
  for i := 1 to n-1 do
  begin

    datamodule1.ADOTable1.FieldList.Fields[i].AsString:=stringgrid1.Cells[1,i];
  end;
   end
  else
  begin
     for i := 1 to n-1 do
  begin
    datamodule1.ADOTable1.RecNo:=k;
    datamodule1.ADOTable1.FieldList.Fields[i].AsString:=stringgrid1.Cells[1,i];

  end;
  end;

datamodule1.ADOTable1.Post;
form2.StringGrid1.Cells[9,r]:=datamodule1.ADOTable1.FieldList.Fields[0].AsString;
close;
end;

procedure TForm5.Button2Click(Sender: TObject);
var s,s1:string;
r:integer;
begin
r:=form2.StringGrid1.Row;
s:=ExtractFilepath(Application.ExeName)+form2.StringGrid1.Cells[7,r];
s1:=trimuntil(s);
if fileExists(s) then  // загрузка чертежей
begin
label2.Caption:='да';
shellexecute(Application.MainForm.Handle,nil,Pchar(s),'',Pchar(s1),SW_SHOW);
end
else label2.Caption:='нет';
end;

procedure TForm5.FormShow(Sender: TObject);
var n:integer;
  i,r,k: Integer;
begin
 stringgrid1.Cells[0,0]:='Характеристика';
 stringgrid1.Cells[1,0]:='Значение';
 n:=datamodule1.ADOTable1.FieldCount;
 r:=form2.StringGrid1.Row;
 stringgrid1.RowCount:=n+1;
 k:=dataseek(form2.StringGrid1.Cells[0,r]);
 if k=0 then    //если по названию агрегат в базе не найден
  begin

 for i := 1 to n-1 do
  begin
    datamodule1.ADOTable1.RecNo:=1;
    stringgrid1.Cells[0,i]:=datamodule1.ADOTable1.Fields[i].FieldName;
  end;
  //если оутдоры
  if (datamodule1.ADOTable1.TableName='out')or(datamodule1.ADOTable1.TableName='vtho') then
  begin

    stringgrid1.Cells[1,1]:=form2.StringGrid1.Cells[0,r];   //Название агрегата
      //Название компрессоров

     if pos('+',form2.StringGrid1.Cells[3,r])=0 then
  begin
       stringgrid1.Cells[1,5]:=form2.StringGrid1.Cells[1,r];   //модель компрессоров первого типа
       stringgrid1.Cells[1,7]:=form2.StringGrid1.Cells[5,r];
  end
     else
  begin

    stringgrid1.Cells[1,5]:=copy(form2.StringGrid1.Cells[1,r],1,
    pos('+',form2.StringGrid1.Cells[1,r])-1);

    stringgrid1.Cells[1,6]:=copy(form2.StringGrid1.Cells[1,r],pos('+',form2.StringGrid1.Cells[1,r])+
    1,length(form2.StringGrid1.Cells[1,r])-pos('+',form2.StringGrid1.Cells[1,r]));

    stringgrid1.Cells[1,7]:=copy(form2.StringGrid1.Cells[5,r],1,
    pos('+',form2.StringGrid1.Cells[5,r])-1);

    stringgrid1.Cells[1,8]:=copy(form2.StringGrid1.Cells[5,r],pos('+',form2.StringGrid1.Cells[5,r])+
    1,length(form2.StringGrid1.Cells[5,r])-pos('+',form2.StringGrid1.Cells[5,r]));
  end;
   //название конденсатора
    stringgrid1.Cells[1,9]:=form2.StringGrid1.Cells[2,r];
    stringgrid1.Cells[1,10]:=form2.StringGrid1.Cells[6,r]; //количество конденсаторов
    stringgrid1.Cells[1,11]:=inttostr(cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,r])]);//Количество вентиляторов
    stringgrid1.Cells[1,12]:=cs.pol[strtoint(form2.StringGrid1.Cells[4,r])];//Количество полюсов в вентиляторе


    stringgrid1.Cells[1,15]:=floattostr(cs.FunsCap[strtoint(form2.StringGrid1.Cells[4,r])])+'X'
    +inttostr(cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,r])]*strtoint(form2.StringGrid1.Cells[6,r])); //мощность вентиляторов
    stringgrid1.Cells[1,16]:=floattostr(cs.FunsCurrent[strtoint(form2.StringGrid1.Cells[4,r])])+'X'
    +inttostr(cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,r])]*strtoint(form2.StringGrid1.Cells[6,r])); //
    stringgrid1.Cells[1,19]:='50гц/380В/3фазы'; //ток


    end;

    //если агрегаты
      if datamodule1.ADOTable1.TableName='agr' then
  begin

    stringgrid1.Cells[1,1]:=form2.StringGrid1.Cells[0,r];   //Название агрегата
      //Название компрессоров

    stringgrid1.Cells[1,5]:=form2.StringGrid1.Cells[1,r];   //модель компрессоров первого типа
    stringgrid1.Cells[1,8]:='50гц/380В/3фазы'; //питающее напряжение
    end;
    // конец


    // если многокомпрессорные
      if datamodule1.ADOTable1.TableName='mka' then
  begin

    stringgrid1.Cells[1,1]:=form2.StringGrid1.Cells[0,r];   //Название агрегата
      //Название компрессоров

     if pos('+',form2.StringGrid1.Cells[3,r])=0 then
  begin
       stringgrid1.Cells[1,5]:=form2.StringGrid1.Cells[1,r];   //модель компрессоров первого типа
       stringgrid1.Cells[1,7]:=form2.StringGrid1.Cells[5,r];   //количаство
  end
     else
  begin

    stringgrid1.Cells[1,5]:=copy(form2.StringGrid1.Cells[1,r],1,   //модель компрессоров первого типа
    pos('+',form2.StringGrid1.Cells[1,r])-1);

    stringgrid1.Cells[1,6]:=copy(form2.StringGrid1.Cells[1,r],pos('+',form2.StringGrid1.Cells[1,r])+
    1,length(form2.StringGrid1.Cells[1,r])-pos('+',form2.StringGrid1.Cells[1,r]));

    stringgrid1.Cells[1,7]:=copy(form2.StringGrid1.Cells[5,r],1,  //модель компрессоров второго типа
    pos('+',form2.StringGrid1.Cells[5,r])-1);

    stringgrid1.Cells[1,8]:=copy(form2.StringGrid1.Cells[5,r],pos('+',form2.StringGrid1.Cells[5,r])+
    1,length(form2.StringGrid1.Cells[5,r])-pos('+',form2.StringGrid1.Cells[5,r]));
  end;

    stringgrid1.Cells[1,11]:='50гц/380В/3фазы'; //ток


    end;

    // конец




  end else   //если найден
  begin
     for i := 1 to n-1 do
  begin
    datamodule1.ADOTable1.RecNo:=k;
    stringgrid1.Cells[0,i]:=datamodule1.ADOTable1.Fields[i].FieldName;
    stringgrid1.Cells[1,i]:=datamodule1.ADOTable1.FieldList.Fields[i].AsString;
  end;
  end;
end;

procedure TForm5.StringGrid1DblClick(Sender: TObject);
var
r:integer;
begin
//если out
  r:=form2.StringGrid1.Row;
   if datamodule1.ADOTable1.TableName='out' then
  begin
 if  stringgrid1.row=17 then
begin
  stringgrid1.Cells[1,17]:=floattostr(cs.FunsCap[strtoint(form2.StringGrid1.Cells[4,r])]*
  cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,r])]*strtoint(form2.StringGrid1.Cells[6,r])+
  strtofloatdef(stringgrid1.Cells[1,13],0)); //общая мощность
end;
 if  stringgrid1.row=18 then
begin
  stringgrid1.Cells[1,18]:=floattostr(cs.Funscurrent[strtoint(form2.StringGrid1.Cells[4,r])]*
  cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,r])]*strtoint(form2.StringGrid1.Cells[6,r])+
    strtofloatdef(stringgrid1.Cells[1,14],0)); //общий ток
end;
  end;

end;

function dataseek(name:string):integer;
var
  I,m,k: Integer;
begin
  m:=datamodule1.ADOTable1.RecordCount;
  k:=0;
  for I := 1 to m do
  begin
   datamodule1.ADOTable1.RecNo:=i;
   if name=datamodule1.ADOTable1.FieldList.Fields[1].AsString then k:=i;
  end;
  dataseek:=k;
end;

function trimuntil(s:string):string;
var i:integer;
 s1:string;
begin
 s1:=s;
  repeat
   delete(s1,length(s1),1);

  until (copy(s1,length(s1),1)='/')or(copy(s1,length(s1),1)='\')or(length(s1)<=1);
  trimuntil:=s1;
end;
end.
