unit uHeOObj_QMS;

interface
{$I 'GlobalDefs.inc'}

uses
  System.Generics.Collections,
  MVCFramework.Serializer.Commons,
  MVCFramework.Nullables,
  MVCFramework.Swagger.Commons,
  FireDAC.Stan.Option,
  FireDAC.Comp.Client,
  FireDAC.Stan.Param,
  uDataMod,
  helTabsBIDs,
  uHeoObj_Base,
  uSvc_Base
  ;


const
{$I globalConsts.inc}

type
  [MVCNameCase(ncLowerCase)]
//  [MVCTable('TabPlanKalendPol')]
  TQMSUdrzbaStrojuAZarizeni = class(TAktivita)
   private
//    FIDStroj: NullableInt32;
   public
    constructor Create; virtual;
    destructor Destroy; override;

{
    [MVCColumn('IDStroje')]
    [MVCSwagJsonSchemaField(stInteger, 'IDStroj', 'ID stroje', false, true)] // typ, sysName, nazev, required, nullable, minLength, maxLength
    property IDStroj: NullableInt32 read FIDStroj write FIDStroj;
}
  end;






// TabKLPHlav
// TabKontaktJednani
  [MVCNameCase(ncLowerCase)]
  [MVCTable('TabKontaktJednani')]
  TQMSKontrolniPostup = class(TAktivita)
   private
    FTypKP: integer;
   public
{
    [MVCColumn('Kategorie')]
    [MVCSwagJsonSchemaField(stString, 'Kategorie', 'Kategorie kontrolního postupu', true, false, 1, 3)] // typ, sysName, nazev, required, nullable, minLength, maxLength
    property Kategorie: string read FKategorie write FKategorie;
}
    [MVCColumn('TypKP')]
    [MVCSwagJsonSchemaField(stInteger, 'TypKP', 'Typ Kontrolního postupu', true, false)] // typ, sysName, nazev, required, nullable, minLength, maxLength
    property TypKP: integer read FTypKP write FTypKP;
  end;




// TabKontaktJednani.Kategorie = (SELECT Cislo FROM TabKategKontJed WHERE QMSAgenda=12)
  [MVCNameCase(ncLowerCase)]
  [MVCTable('TabKPLHlav')]
  TQMSKontrolniPlan = class(TAktivita)
   private
    FOblastQMS: NullableString;
    FStavZpracovaniKP: NullableString;
   public
    constructor Create; virtual;
    procedure OnAfterLoad; virtual; // Called just after load the object state from database
    procedure OnAfterUpdate; virtual; // Called after update the object state to database
  end;




  [MVCNameCase(ncLowerCase)]
  TQMSParamKontrolnihoPostupu = class(THeliosObjekty)
   private
    FIDKPLHlav: integer;
    FPoradi: integer;
    FTypHodnoty: NullableInt32;
    FTypHodnotyText: string;
    FPopis: string;
    FPrvniKontrola: boolean;
    FHodnotaPozadovana: Extended;
    FToleranceHorni: Extended;
    FToleranceDolni: Extended;
   public
    [MVCColumn('IDKPLHlav')]
    [MVCSwagJsonSchemaField(stInteger, 'IDKPLHlav', 'ID hlavičky kontrolního postupu', true, false)]  // typ, sysName, nazev, required, nullable, minLength, maxLength
    property IDKPLHlav: integer read FIDKPLHlav write FIDKPLHlav;

    [MVCColumn('Poradi')]
    [MVCSwagJsonSchemaField(stInteger, 'Poradi', 'Pořadové číslo parametru', true, false)]
    property Poradi: integer read FPoradi write FPoradi;

    [MVCColumn('TypHodnoty')]
    [MVCSwagJsonSchemaField(stInteger, 'TypHodnoty', 'Typ hodnoty', false, true)]
    property TypHodnoty: NullableInt32 read FTypHodnoty write FTypHodnoty;

    [MVCColumn('TypHodnotyText')]
    [MVCSwagJsonSchemaField(stString, 'TypHodnotyText', 'Typ hodnoty textově', true, false)]
    property TypHodnotyText: string read FTypHodnotyText write FTypHodnotyText;

    [MVCColumn('Popis')]
    [MVCTableField('Popis')]
    [MVCSwagJsonSchemaField(stString, 'Popis', 'Popis parametru', false, false)]
    property Popis: string read FPopis write FPopis;

    [MVCColumn('PrvniKontrola')]
    [MVCSwagJsonSchemaField(stBoolean, 'PrvniKontrola', 'Kontrola 1.kusu', true, false)]
    property PrvniKontrola: boolean read FPrvniKontrola write FPrvniKontrola;

    [MVCColumn('HodnotaPozadovana')]
    [MVCSwagJsonSchemaField(stNumber, 'HodnotaPozadovana', 'Požadovaná hodnota', false, false)]
    property HodnotaPozadovana: Extended read FHodnotaPozadovana write FHodnotaPozadovana;

    [MVCColumn('ToleranceHorni')]
    [MVCSwagJsonSchemaField(stNumber, 'ToleranceHorni', 'Tolerance horní', false, false)]
    property ToleranceHorni: Extended read FToleranceHorni write FToleranceHorni;

    [MVCColumn('ToleranceDolni')]
    [MVCSwagJsonSchemaField(stNumber, 'ToleranceDolni', 'Tolerance dolní', false, false)]
    property ToleranceDolni: Extended read FToleranceDolni write FToleranceDolni;

  end;



implementation

uses
  System.SysUtils,
  System.StrUtils,
  System.RegularExpressions;





{ TQMSUdrzbaStrojuAZarizeni }

 constructor TQMSUdrzbaStrojuAZarizeni.Create;
  begin
   inherited;
  end;


 destructor TQMSUdrzbaStrojuAZarizeni.Destroy;
  begin
   inherited;
  end;





{ TQMSKontrolniPlan }

 constructor TQMSKontrolniPlan.Create;
  begin
   inherited;
   FStavZpracovaniKP:= ''; // dle IDCis1
   FOblastQMS:= ''; // dle IDCis2
  end;



 procedure TQMSKontrolniPlan.OnAfterLoad;
  var lSQL: string;
      lQry: TFDQuery;
  begin
   inherited;
{
   lQry:= TFDQuery.Create(nil);
   lQry.Connection:= uDataMod.datMod.sqlConn;
   try
     lSQL:= 'SELECT Cislo FROM ' + tblQMSCis + ' WHERE ID=:ID';
     lQry.Open(lSQL, [FIDCis1.Value]);
     if (lQry.RecordCount>0) then
      if not(FIDCis1.IsNull) then
       FStavZpracovaniKP:= lQry.FieldByName('Cislo').AsString;

     lSQL:= 'SELECT Cislo FROM ' + tblQMSCis + ' WHERE ID=:ID';
     lQry.Open(lSQL, [FIDCis2.Value]);
     if (lQry.RecordCount>0) then
     if not(FIDCis2.IsNull) then
      FOblastQMS:= lQry.FieldByName('Cislo').AsString;
    finally
     lQry.Free;
   end;
}
  end;



 procedure TQMSKontrolniPlan.OnAfterUpdate;
  begin
  end;


end.
