unit U_DyeSimpleTechnicsKaiKa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, Menus, U_BaseList, dxSkinsCore, dxSkinsDefaultPainters,
  dxDateRanges, dxScrollbarAnnotations, cxContainer, cxDropDownEdit, cxLabel,
  cxButtons, cxMemo, U_frameFPList, U_frameGJList, U_frameGDXList, U_frameFSList,
  U_frameCCQXList, U_frameJGQXList, U_frameRGQXList, U_frameYMList,U_framePDList, U_BaseInput,
  System.ImageList, Vcl.ImgList;

  //U_frameJGQXList, U_frameRGQXList, U_frameCCQXList, U_frameYMList

type
  TfrmDyeSimpleTechnicsKaiKa = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    GPM_2: TcxGridPopupMenu;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    DS_PsType: TDataSource;
    CDS_PSType: TClientDataSet;
    ADOQuery1: TADOQuery;
    GPM_1: TcxGridPopupMenu;
    ToolButton3: TToolButton;
    Panel2: TPanel;
    Splitter1: TSplitter;
    ScrollBox1: TScrollBox;
    Splitter2: TSplitter;
    Panel3: TPanel;
    cxGrid9: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridLevel8: TcxGridLevel;
    CDS_GX: TClientDataSet;
    DS_GX: TDataSource;
    Tv3PSNO: TcxGridDBColumn;
    Tv3PSType: TcxGridDBColumn;
    Tv3PSName: TcxGridDBColumn;
    Tv3PSID: TcxGridDBColumn;
    ToolBar2: TToolBar;
    TbShow: TToolButton;
    Tv3Page: TcxGridDBColumn;
    GPM_3: TcxGridPopupMenu;
    Tv3MCNO: TcxGridDBColumn;
    GYNote: TMemo;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);

    procedure FormShow(Sender: TObject);

    procedure cxTabControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);

    procedure Tv1DblClick(Sender: TObject);

    procedure TbDeleteClick(Sender: TObject);
    procedure TbShowClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }

    procedure SetStatus();

    procedure InitGlide();
    procedure InitGXDetails();
    procedure CloseAllFrames();

    function GetNextFrameTop: Integer;
//    function SaveData(): Boolean;
    procedure FillAllTextEditsWithValue(AParent: TWinControl; const AHint, AValue: string; AExclude: TcxTextEdit = nil);
    procedure ClearAllTextEditsByHint(AParent: TWinControl; const AHint: string; AExclude: TcxTextEdit = nil);
    function FindLastEditedTextEdit(AParent: TWinControl; const AHint: string): string;
    procedure SetXH();
  public
    fPSIDList: string;
    fmanage: string;
    fKaZu: string;
  end;

var
  frmDyeSimpleTechnicsKaiKa: TfrmDyeSimpleTechnicsKaiKa;
  frameFPList1, frameFPList2, frameFPList3, frameFPList4: tframeFPList;
  frameGJList1, frameGJList2, frameGJList3, frameGJList4: tframeGJList;
  frameFSList1, frameFSList2, frameFSList3, frameFSList4: tframeFSList;
  frameGDXList1, frameGDXList2, frameGDXList3, frameGDXList4: TframeGDXList;
  frameJGQXList1, frameJGQXList2, frameJGQXList3, frameJGQXList4: TframeJGQXList;
  frameRGQXList1, frameRGQXList2, frameRGQXList3, frameRGQXList4: TframeRGQXList;
  frameCCQXList1, frameCCQXList2, frameCCQXList3, frameCCQXList4: TframeCCQXList;
  frameYMList1, frameYMList2, frameYMList3, frameYMList4: TframeYMList;
  framePDList1, framePDList2, framePDList3, framePDList4: TframePDList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_DyeTechnicsinput, U_DyeProcessDefin,
  U_DyeSimpleTechnicsList;

{$R *.dfm}

procedure TfrmDyeSimpleTechnicsKaiKa.SetXH();
var
  i: Integer;
begin
  with CDS_GX do
  begin
    First;
    i := 1;
    while not Eof do
    begin
      with CDS_GX do
      begin
        Edit;
        FieldByName('XHNoTemp').Value := i;
        Post;
      end;
      i := i + 1;
      Next;
    end;
  end;

  with CDS_GX do
  begin
    CDS_GX.IndexFieldNames := '';
    First;
    i := 1;
    while not Eof do
    begin
      with CDS_GX do
      begin
        Edit;
        FieldByName('PSNO').Value := FieldByName('XHNoTemp').AsInteger;
        Post;
      end;
      i := i + 1;
      Next;
    end;
    CDS_GX.IndexFieldNames := 'PSNO';
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.SetStatus();
var
  i: integer;
begin

end;

procedure TfrmDyeSimpleTechnicsKaiKa.InitGlide();
begin
  try
    ADOQueryTemp.DisableControls;
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.PSID,A.GlideNo,A.MCNO,B.PSType,B.PSName,B.page,C.GYNote FROM Dye_Plan_Glide A ');
      sql.Add(' inner join Dye_Process B on A.PSID = B.PSID ');
      sql.Add(' left join Dye_Technics_Main C on B.DTMID = C.DTMID ');
      sql.Add(' Where A.PCID=''' + trim(fKaZu) + '''');
      SQL.Add(' ORDER BY A.GlideNo ');
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS(ADOQueryTemp, CDS_GX);
    SInitCDSData(ADOQueryTemp, CDS_GX);
  finally
    ADOQueryTemp.EnableControls;
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.InitGXDetails();
begin
  try
    ADOQueryTemp.DisableControls;
    CDS_GX.First;
    while not CDS_GX.eof do
    begin

      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select A.* FROM V_Dye_TechnicsKaiKa_Details A');
        sql.Add(' Where A.PSID=''' + trim(CDS_GX.fieldbyname('PSID').AsString) + '''');
        SQL.Add(' and A.PCID = ''' + trim(fKaZu) + '''');
        Open;
      end;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select A.* FROM BS_Cloth_GY_Sub_Kaika A');
        sql.Add(' Where A.PSID=''' + trim(CDS_GX.fieldbyname('PSID').AsString) + '''');
        sql.Add(' and A.PCID=''' + trim(fKaZu) + '''');
        SQL.Add(' Order By A.serialno');
//        ShowMessage(SQL.Text);
        Open;
      end;



//      ShowMessage(IntToStr(ADOQueryCmd.RecordCount));

      if CDS_GX.FieldByName('PSType').AsString = '长车清洗' then
      begin
        if self.FindComponent('frameCCQXList1') = nil then
        begin
          frameCCQXList1 := TframeCCQXList.Create(self);
          frameCCQXList1.Name := 'frameCCQXList1';
          frameCCQXList1.Parent := self.ScrollBox1;
          frameCCQXList1.Top := GetNextFrameTop;
          frameCCQXList1.Visible := True;
          frameCCQXList1.LabelCCQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameCCQXList1.InitGrid();

          frameCCQXList1.TbCCQXAdd.Visible := False;
          frameCCQXList1.TbCCQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameCCQXList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameCCQXList1.Panel_ccqx, 2);
          frameCCQXList1.ccqx_note.Lines.Text := ADOQueryTemp.FieldByName('ccqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameCCQXList1.CDS_CCQX);
          SInitCDSData(ADOQueryCmd, frameCCQXList1.CDS_CCQX);

        end
        else if self.FindComponent('frameCCQXList2') = nil then
        begin
          frameCCQXList2 := TframeCCQXList.Create(self);
          frameCCQXList2.Name := 'frameCCQXList2';
          frameCCQXList2.Parent := self.ScrollBox1;
          frameCCQXList2.Top := GetNextFrameTop;
          frameCCQXList2.Visible := True;
          frameCCQXList2.LabelCCQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameCCQXList2.InitGrid();

          frameCCQXList2.TbCCQXAdd.Visible := False;
          frameCCQXList2.TbCCQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameCCQXList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameCCQXList2.Panel_ccqx, 2);
          frameCCQXList2.ccqx_note.Lines.Text := ADOQueryTemp.FieldByName('ccqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameCCQXList2.CDS_CCQX);
          SInitCDSData(ADOQueryCmd, frameCCQXList2.CDS_CCQX);

        end
        else if self.FindComponent('frameCCQXList3') = nil then
        begin
          frameCCQXList3 := TframeCCQXList.Create(self);
          frameCCQXList3.Name := 'frameCCQXList3';
          frameCCQXList3.Parent := self.ScrollBox1;
          frameCCQXList3.Top := GetNextFrameTop;
          frameCCQXList3.Visible := True;
          frameCCQXList3.LabelCCQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameCCQXList3.InitGrid();

          frameCCQXList3.TbCCQXAdd.Visible := False;
          frameCCQXList3.TbCCQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameCCQXList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameCCQXList3.Panel_ccqx, 2);
          frameCCQXList3.ccqx_note.Lines.Text := ADOQueryTemp.FieldByName('ccqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameCCQXList3.CDS_CCQX);
          SInitCDSData(ADOQueryCmd, frameCCQXList3.CDS_CCQX);
        end
        else if self.FindComponent('frameCCQXList4') = nil then
        begin
          frameCCQXList4 := TframeCCQXList.Create(self);
          frameCCQXList4.Name := 'frameCCQXList4';
          frameCCQXList4.Parent := self.ScrollBox1;
          frameCCQXList4.Top := GetNextFrameTop;
          frameCCQXList4.Visible := True;
          frameCCQXList4.LabelCCQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameCCQXList4.InitGrid();

          frameCCQXList4.TbCCQXAdd.Visible := False;
          frameCCQXList4.TbCCQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameCCQXList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameCCQXList4.Panel_ccqx, 2);
          frameCCQXList4.ccqx_note.Lines.Text := ADOQueryTemp.FieldByName('ccqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameCCQXList4.CDS_CCQX);
          SInitCDSData(ADOQueryCmd, frameCCQXList4.CDS_CCQX);
        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '卷染缸清洗' then
      begin
        if self.FindComponent('frameRGQXList1') = nil then
        begin
          frameRGQXList1 := TframeRGQXList.Create(self);
          frameRGQXList1.Name := 'frameRGQXList1';
          frameRGQXList1.Parent := self.ScrollBox1;
          frameRGQXList1.Top := GetNextFrameTop;
          frameRGQXList1.Visible := True;
          frameRGQXList1.LabelRGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameRGQXList1.InitGrid();

          frameRGQXList1.TbRGQXAdd.Visible := False;
          frameRGQXList1.TbRGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameRGQXList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameRGQXList1.Panel_rgqx, 2);
          frameRGQXList1.rgqx_note.Lines.Text := ADOQueryTemp.FieldByName('rgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameRGQXList1.CDS_rgQX);
          SInitCDSData(ADOQueryCmd, frameRGQXList1.CDS_RGQX);
        end
        else if self.FindComponent('frameRGQXList2') = nil then
        begin
          frameRGQXList2 := TframeRGQXList.Create(self);
          frameRGQXList2.Name := 'frameRGQXList2';
          frameRGQXList2.Parent := self.ScrollBox1;
          frameRGQXList2.Top := GetNextFrameTop;
          frameRGQXList2.Visible := True;
          frameRGQXList2.LabelRGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameRGQXList2.InitGrid();

          frameRGQXList2.TbRGQXAdd.Visible := False;
          frameRGQXList2.TbRGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameRGQXList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameRGQXList2.Panel_rgqx, 2);
          frameRGQXList2.rgqx_note.Lines.Text := ADOQueryTemp.FieldByName('rgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameRGQXList2.CDS_rgQX);
          SInitCDSData(ADOQueryCmd, frameRGQXList2.CDS_RGQX);
        end
        else if self.FindComponent('frameRGQXList3') = nil then
        begin
          frameRGQXList3 := TframeRGQXList.Create(self);
          frameRGQXList3.Name := 'frameRGQXList3';
          frameRGQXList3.Parent := self.ScrollBox1;
          frameRGQXList3.Top := GetNextFrameTop;
          frameRGQXList3.Visible := True;
          frameRGQXList3.LabelRGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameRGQXList3.InitGrid();

          frameRGQXList3.TbRGQXAdd.Visible := False;
          frameRGQXList3.TbRGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameRGQXList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameRGQXList3.Panel_rgqx, 2);
          frameRGQXList3.rgqx_note.Lines.Text := ADOQueryTemp.FieldByName('rgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameRGQXList3.CDS_rgQX);
          SInitCDSData(ADOQueryCmd, frameRGQXList3.CDS_RGQX);
        end
        else if self.FindComponent('frameRGQXList4') = nil then
        begin
          frameRGQXList4 := TframeRGQXList.Create(self);
          frameRGQXList4.Name := 'frameRGQXList4';
          frameRGQXList4.Parent := self.ScrollBox1;
          frameRGQXList4.Top := GetNextFrameTop;
          frameRGQXList4.Visible := True;
          frameRGQXList4.LabelRGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameRGQXList4.InitGrid();

          frameRGQXList4.TbRGQXAdd.Visible := False;
          frameRGQXList4.TbRGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameRGQXList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameRGQXList4.Panel_rgqx, 2);
          frameRGQXList4.rgqx_note.Lines.Text := ADOQueryTemp.FieldByName('rgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameRGQXList4.CDS_rgQX);
          SInitCDSData(ADOQueryCmd, frameRGQXList4.CDS_RGQX);
        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '机缸清洗' then
      begin
        if self.FindComponent('frameJGQXList1') = nil then
        begin
          frameJGQXList1 := TframeJGQXList.Create(self);
          frameJGQXList1.Name := 'frameJGQXList1';
          frameJGQXList1.Parent := self.ScrollBox1;
          frameJGQXList1.Top := GetNextFrameTop;
          frameJGQXList1.Visible := True;
          frameJGQXList1.LabelJGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameJGQXList1.InitGrid();

          frameJGQXList1.TbJGQXAdd.Visible := False;
          frameJGQXList1.TbJGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameJGQXList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameJGQXList1.Panel_jgqx, 2);
          frameJGQXList1.jgqx_note.Lines.Text := ADOQueryTemp.FieldByName('jgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameJGQXList1.CDS_JGQX);
          SInitCDSData(ADOQueryCmd, frameJGQXList1.CDS_JGQX);
        end
        else if self.FindComponent('frameJGQXList2') = nil then
        begin
          frameJGQXList2 := TframeJGQXList.Create(self);
          frameJGQXList2.Name := 'frameJGQXList2';
          frameJGQXList2.Parent := self.ScrollBox1;
          frameJGQXList2.Top := GetNextFrameTop;
          frameJGQXList2.Visible := True;
          frameJGQXList2.LabelJGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameJGQXList2.InitGrid();

          frameJGQXList2.TbJGQXAdd.Visible := False;
          frameJGQXList2.TbJGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameJGQXList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameJGQXList2.Panel_jgqx, 2);
          frameJGQXList2.jgqx_note.Lines.Text := ADOQueryTemp.FieldByName('jgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameJGQXList2.CDS_JGQX);
          SInitCDSData(ADOQueryCmd, frameJGQXList2.CDS_JGQX);
        end
        else if self.FindComponent('frameJGQXList3') = nil then
        begin
          frameJGQXList3 := TframeJGQXList.Create(self);
          frameJGQXList3.Name := 'frameJGQXList3';
          frameJGQXList3.Parent := self.ScrollBox1;
          frameJGQXList3.Top := GetNextFrameTop;
          frameJGQXList3.Visible := True;
          frameJGQXList3.LabelJGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameJGQXList3.InitGrid();

          frameJGQXList3.TbJGQXAdd.Visible := False;
          frameJGQXList3.TbJGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameJGQXList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameJGQXList3.Panel_jgqx, 2);
          frameJGQXList3.jgqx_note.Lines.Text := ADOQueryTemp.FieldByName('jgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameJGQXList3.CDS_JGQX);
          SInitCDSData(ADOQueryCmd, frameJGQXList3.CDS_JGQX);
        end
        else if self.FindComponent('frameJGQXList4') = nil then
        begin
          frameJGQXList4 := TframeJGQXList.Create(self);
          frameJGQXList4.Name := 'frameJGQXList4';
          frameJGQXList4.Parent := self.ScrollBox1;
          frameJGQXList4.Top := GetNextFrameTop;
          frameJGQXList4.Visible := True;
          frameJGQXList4.LabelJGQX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameJGQXList4.InitGrid();

          frameJGQXList4.TbJGQXAdd.Visible := False;
          frameJGQXList4.TbJGQXDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameJGQXList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameJGQXList4.Panel_jgqx, 2);
          frameJGQXList4.jgqx_note.Lines.Text := ADOQueryTemp.FieldByName('jgqx_note').AsString;

          SCreateCDS(ADOQueryCmd, frameJGQXList4.CDS_JGQX);
          SInitCDSData(ADOQueryCmd, frameJGQXList4.CDS_JGQX);
        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '干定型' then
      begin
        if self.FindComponent('frameGDXList1') = nil then
        begin
          frameGDXList1 := TframeGDXList.Create(self);
          frameGDXList1.Name := 'frameGDXList1';
          frameGDXList1.Parent := self.ScrollBox1;
          frameGDXList1.Top := GetNextFrameTop;
          frameGDXList1.Visible := True;
          frameGDXList1.LabelGDX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGDXList1.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGDXList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGDXList1.Panel_dx, 2);
          frameGDXList1.dx_Precautions.Lines.Text := ADOQueryTemp.FieldByName('dx_Precautions').AsString;
        end
        else if self.FindComponent('frameGDXList2') = nil then
        begin
          frameGDXList2 := TframeGDXList.Create(self);
          frameGDXList2.Name := 'frameGDXList2';
          frameGDXList2.Parent := self.ScrollBox1;
          frameGDXList2.Top := GetNextFrameTop;
          frameGDXList2.Visible := True;
          frameGDXList2.LabelGDX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGDXList2.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGDXList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGDXList2.Panel_dx, 2);
          frameGDXList2.dx_Precautions.Lines.Text := ADOQueryTemp.FieldByName('dx_Precautions').AsString;
        end
        else if self.FindComponent('frameGDXList3') = nil then
        begin
          frameGDXList3 := TframeGDXList.Create(self);
          frameGDXList3.Name := 'frameGDXList3';
          frameGDXList3.Parent := self.ScrollBox1;
          frameGDXList3.Top := GetNextFrameTop;
          frameGDXList3.Visible := True;
          frameGDXList3.LabelGDX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGDXList3.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGDXList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGDXList3.Panel_dx, 2);
          frameGDXList3.dx_Precautions.Lines.Text := ADOQueryTemp.FieldByName('dx_Precautions').AsString;
        end
        else if self.FindComponent('frameGDXList4') = nil then
        begin
          frameGDXList4 := TframeGDXList.Create(self);
          frameGDXList4.Name := 'frameGDXList4';
          frameGDXList4.Parent := self.ScrollBox1;
          frameGDXList4.Top := GetNextFrameTop;
          frameGDXList4.Visible := True;
          frameGDXList4.LabelGDX.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGDXList4.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGDXList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGDXList4.Panel_dx, 2);
          frameGDXList4.dx_Precautions.Lines.Text := ADOQueryTemp.FieldByName('dx_Precautions').AsString;
        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '下水定型' then
      begin
        if self.FindComponent('frameFSList1') = nil then
        begin
          frameFSList1 := tframeFSList.Create(self);
          frameFSList1.Name := 'frameFSList1';
          frameFSList1.Parent := self.ScrollBox1;
          frameFSList1.Top := GetNextFrameTop;
          frameFSList1.Visible := True;
          frameFSList1.LabelFS.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFSList1.InitGrid();

          frameFSList1.TbFSAdd.Visible := False;
          frameFSList1.TbFSDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFSList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFSList1.Panel_fs, 2);
          frameFSList1.fs_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fs_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFSList1.CDS_fS);
          SInitCDSData(ADOQueryCmd, frameFSList1.CDS_fS);
        end
        else if self.FindComponent('frameFSList2') = nil then
        begin
          frameFSList2 := tframeFSList.Create(self);
          frameFSList2.Name := 'frameFSList2';
          frameFSList2.Parent := self.ScrollBox1;
          frameFSList2.Top := GetNextFrameTop;
          frameFSList2.Visible := True;
          frameFSList2.LabelFS.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFSList2.InitGrid();

          frameFSList2.TbFSAdd.Visible := False;
          frameFSList2.TbFSDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFSList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFSList2.Panel_fs, 2);
          frameFSList2.fs_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fs_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFSList2.CDS_fS);
          SInitCDSData(ADOQueryCmd, frameFSList2.CDS_fS);
        end
        else if self.FindComponent('frameFSList3') = nil then
        begin
          frameFSList3 := tframeFSList.Create(self);
          frameFSList3.Name := 'frameFSList3';
          frameFSList3.Parent := self.ScrollBox1;
          frameFSList3.Top := GetNextFrameTop;
          frameFSList3.Visible := True;
          frameFSList3.LabelFS.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFSList3.InitGrid();

          frameFSList3.TbFSAdd.Visible := False;
          frameFSList3.TbFSDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFSList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFSList3.Panel_fs, 2);
          frameFSList3.fs_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fs_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFSList3.CDS_fS);
          SInitCDSData(ADOQueryCmd, frameFSList3.CDS_fS);
        end
        else if self.FindComponent('frameFSList4') = nil then
        begin
          frameFSList4 := tframeFSList.Create(self);
          frameFSList4.Name := 'frameFSList4';
          frameFSList4.Parent := self.ScrollBox1;
          frameFSList4.Top := GetNextFrameTop;
          frameFSList4.Visible := True;
          frameFSList4.LabelFS.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFSList4.InitGrid();

          frameFSList4.TbFSAdd.Visible := False;
          frameFSList4.TbFSDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFSList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFSList4.Panel_fs, 2);
          frameFSList4.fs_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fs_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFSList4.CDS_fS);
          SInitCDSData(ADOQueryCmd, frameFSList4.CDS_fS);
        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '发泡' then
      begin

        if self.FindComponent('frameFPList1') = nil then
        begin
          frameFPList1 := TframeFPList.Create(self);
          frameFPList1.Name := 'frameFPList1';
          frameFPList1.Parent := self.ScrollBox1;
          frameFPList1.Top := GetNextFrameTop;
          frameFPList1.Visible := True;
          frameFPList1.LabelFP.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFPList1.InitGrid();

          frameFPList1.TbFPAdd.Visible := False;
          frameFPList1.TbFPDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFPList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFPList1.Panel_fp, 2);
          frameFPList1.fp_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fp_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFPList1.CDS_FP);
          SInitCDSData(ADOQueryCmd, frameFPList1.CDS_FP);
        end
        else if self.FindComponent('frameFPList2') = nil then
        begin
          frameFPList2 := TframeFPList.Create(self);
          frameFPList2.Name := 'frameFPList2';
          frameFPList2.Parent := self.ScrollBox1;
          frameFPList2.Top := GetNextFrameTop;
          frameFPList2.Visible := True;
          frameFPList2.LabelFP.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFPList2.InitGrid();

          frameFPList2.TbFPAdd.Visible := False;
          frameFPList2.TbFPDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFPList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFPList2.Panel_fp, 2);
          frameFPList2.fp_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fp_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFPList2.CDS_FP);
          SInitCDSData(ADOQueryCmd, frameFPList2.CDS_FP);
        end
        else if self.FindComponent('frameFPList3') = nil then
        begin
          frameFPList3 := TframeFPList.Create(self);
          frameFPList3.Name := 'frameFPList3';
          frameFPList3.Parent := self.ScrollBox1;
          frameFPList3.Top := GetNextFrameTop;
          frameFPList3.Visible := True;
          frameFPList3.LabelFP.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFPList3.InitGrid();

          frameFPList3.TbFPAdd.Visible := False;
          frameFPList3.TbFPDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFPList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFPList3.Panel_fp, 2);
          frameFPList3.fp_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fp_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFPList3.CDS_FP);
          SInitCDSData(ADOQueryCmd, frameFPList3.CDS_FP);
        end
        else if self.FindComponent('frameFPList4') = nil then
        begin
          frameFPList4 := TframeFPList.Create(self);
          frameFPList4.Name := 'frameFPList4';
          frameFPList4.Parent := self.ScrollBox1;
          frameFPList4.Top := GetNextFrameTop;
          frameFPList4.Visible := True;
          frameFPList4.LabelFP.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameFPList4.InitGrid();

          frameFPList4.TbFPAdd.Visible := False;
          frameFPList4.TbFPDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameFPList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameFPList4.Panel_fp, 2);
          frameFPList4.fp_Precautions.Lines.Text := ADOQueryTemp.FieldByName('fp_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameFPList4.CDS_FP);
          SInitCDSData(ADOQueryCmd, frameFPList4.CDS_FP);
        end;

      end
      else if CDS_GX.FieldByName('PSType').AsString = '刮胶' then
      begin
        if self.FindComponent('frameGJList1') = nil then
        begin
          frameGJList1 := TframeGJList.Create(self);
          frameGJList1.Name := 'frameGJList1';
          frameGJList1.Parent := self.ScrollBox1;
          frameGJList1.Top := GetNextFrameTop;
          frameGJList1.Visible := True;
          frameGJList1.LabelGJ.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGJList1.InitGrid();

          frameGJList1.TbGJAdd.Visible := False;
          frameGJList1.TbGJDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGJList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGJList1.Panel_gj, 2);
          frameGJList1.gj_Precautions.Lines.Text := ADOQueryTemp.FieldByName('gj_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameGJList1.CDS_GJ);
          SInitCDSData(ADOQueryCmd, frameGJList1.CDS_GJ);
        end
        else if self.FindComponent('frameGJList2') = nil then
        begin
          frameGJList2 := TframeGJList.Create(self);
          frameGJList2.Name := 'frameGJList2';
          frameGJList2.Parent := self.ScrollBox1;
          frameGJList2.Top := GetNextFrameTop;
          frameGJList2.Visible := True;
          frameGJList2.LabelGJ.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGJList2.InitGrid();

          frameGJList2.TbGJAdd.Visible := False;
          frameGJList2.TbGJDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGJList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGJList2.Panel_gj, 2);
          frameGJList2.gj_Precautions.Lines.Text := ADOQueryTemp.FieldByName('gj_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameGJList2.CDS_GJ);
          SInitCDSData(ADOQueryCmd, frameGJList2.CDS_GJ);
        end
        else if self.FindComponent('frameGJList3') = nil then
        begin
          frameGJList3 := TframeGJList.Create(self);
          frameGJList3.Name := 'frameGJList3';
          frameGJList3.Parent := self.ScrollBox1;
          frameGJList3.Top := GetNextFrameTop;
          frameGJList3.Visible := True;
          frameGJList3.LabelGJ.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGJList3.InitGrid();

          frameGJList3.TbGJAdd.Visible := False;
          frameGJList3.TbGJDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGJList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGJList3.Panel_gj, 2);
          frameGJList3.gj_Precautions.Lines.Text := ADOQueryTemp.FieldByName('gj_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameGJList3.CDS_GJ);
          SInitCDSData(ADOQueryCmd, frameGJList3.CDS_GJ);
        end
        else if self.FindComponent('frameGJList4') = nil then
        begin
          frameGJList4 := TframeGJList.Create(self);
          frameGJList4.Name := 'frameGJList4';
          frameGJList4.Parent := self.ScrollBox1;
          frameGJList4.Top := GetNextFrameTop;
          frameGJList4.Visible := True;
          frameGJList4.LabelGJ.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameGJList4.InitGrid();

          frameGJList4.TbGJAdd.Visible := False;
          frameGJList4.TbGJDel.Visible := False;

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameGJList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameGJList4.Panel_gj, 2);
          frameGJList4.gj_Precautions.Lines.Text := ADOQueryTemp.FieldByName('gj_Precautions').AsString;

          SCreateCDS(ADOQueryCmd, frameGJList4.CDS_GJ);
          SInitCDSData(ADOQueryCmd, frameGJList4.CDS_GJ);
        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '轧毛' then
      begin
        if self.FindComponent('frameYMList1') = nil then
        begin
          frameYMList1 := TframeYMList.Create(self);
          frameYMList1.Name := 'frameYMList1';
          frameYMList1.Parent := self.ScrollBox1;
          frameYMList1.Top := GetNextFrameTop;
          frameYMList1.Visible := True;
          frameYMList1.LabelYM.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameYMList1.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameYMList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameYMList1.Panel_zm, 2);
          frameYMList1.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end
        else if self.FindComponent('frameYMList2') = nil then
        begin
          frameYMList2 := TframeYMList.Create(self);
          frameYMList2.Name := 'frameYMList2';
          frameYMList2.Parent := self.ScrollBox1;
          frameYMList2.Top := GetNextFrameTop;
          frameYMList2.Visible := True;
          frameYMList2.LabelYM.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameYMList2.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameYMList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameYMList2.Panel_zm, 2);
          frameYMList2.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end
        else if self.FindComponent('frameYMList3') = nil then
        begin
          frameYMList3 := TframeYMList.Create(self);
          frameYMList3.Name := 'frameYMList3';
          frameYMList3.Parent := self.ScrollBox1;
          frameYMList3.Top := GetNextFrameTop;
          frameYMList3.Visible := True;
          frameYMList3.LabelYM.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameYMList3.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameYMList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameYMList3.Panel_zm, 2);
          frameYMList3.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end
        else if self.FindComponent('frameYMList4') = nil then
        begin
          frameYMList4 := TframeYMList.Create(self);
          frameYMList4.Name := 'frameYMList4';
          frameYMList4.Parent := self.ScrollBox1;
          frameYMList4.Top := GetNextFrameTop;
          frameYMList4.Visible := True;
          frameYMList4.LabelYM.Caption := CDS_GX.FieldByName('PSName').AsString;
          frameYMList4.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'frameYMList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, frameYMList4.Panel_zm, 2);
          frameYMList4.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end;
      end
      else if CDS_GX.FieldByName('PSType').AsString = '拍打' then
      begin
        if self.FindComponent('framePDList1') = nil then
        begin
          framePDList1 := TframePDList.Create(self);
          framePDList1.Name := 'framePDList1';
          framePDList1.Parent := self.ScrollBox1;
          framePDList1.Top := GetNextFrameTop;
          framePDList1.Visible := True;
          framePDList1.LabelPD.Caption := CDS_GX.FieldByName('PSName').AsString;
          framePDList1.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'framePDList1';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, framePDList1.Panel_pd, 2);
//          frameYMList1.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end
        else if self.FindComponent('framePDList2') = nil then
        begin
          framePDList2 := TframePDList.Create(self);
          framePDList2.Name := 'framePDList2';
          framePDList2.Parent := self.ScrollBox1;
          framePDList2.Top := GetNextFrameTop;
          framePDList2.Visible := True;
          framePDList2.LabelPD.Caption := CDS_GX.FieldByName('PSName').AsString;
          framePDList2.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'framePDList2';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, framePDList2.Panel_pd, 2);
//          frameYMList2.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end
        else if self.FindComponent('framePDList3') = nil then
        begin
          framePDList3 := TframePDList.Create(self);
          framePDList3.Name := 'framePDList3';
          framePDList3.Parent := self.ScrollBox1;
          framePDList3.Top := GetNextFrameTop;
          framePDList3.Visible := True;
          framePDList3.LabelPD.Caption := CDS_GX.FieldByName('PSName').AsString;
          framePDList3.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'framePDList3';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, framePDList3.Panel_pd, 2);
//          frameYMList3.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end
        else if self.FindComponent('framePDList4') = nil then
        begin
          framePDList4 := TframePDList.Create(self);
          framePDList4.Name := 'framePDList4';
          framePDList4.Parent := self.ScrollBox1;
          framePDList4.Top := GetNextFrameTop;
          framePDList4.Visible := True;
          framePDList4.LabelPD.Caption := CDS_GX.FieldByName('PSName').AsString;
          framePDList4.InitGrid();

          CDS_GX.Edit;
          CDS_GX.FieldByName('page').AsString := 'framePDList4';
          CDS_GX.Post;

          SCSHData(ADOQueryTemp, framePDList4.Panel_pd, 2);
//          frameYMList3.zm_Precautions.Lines.Text := ADOQueryTemp.FieldByName('zm_Precautions').AsString;

        end;
      end;
      CDS_GX.Next;
    end;

  finally
    ADOQueryTemp.EnableControls;
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.CloseAllFrames();
var
  i: Integer;
  Component: TComponent;
begin
  // 关闭所有 GDXList 框架
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameGDXList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;

  // 关闭所有 FSList 框架
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameFSList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;

  // 关闭所有 FPList 框架
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameFPList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;

  // 关闭所有 GJList 框架
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameGJList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;

  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameCCQXList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameRGQXList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameJGQXList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('frameYMList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;
  for i := 1 to 4 do
  begin
    Component := self.FindComponent('framePDList' + IntToStr(i));
    if Component <> nil then
    begin
      TFrame(Component).Free;
    end;
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.FormDestroy(Sender: TObject);
begin
  inherited;
  frmDyeSimpleTechnicsKaiKa := nil;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key = VK_ESCAPE then  // VK_ESCAPE 是 ESC 键的常量
  begin
    Key := 0;  // 清除按键，防止继续传递
    Close;     // 或者 ModalResult := mrCancel;
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.FormShow(Sender: TObject);
begin
  inherited;

  ReadCxGrid(trim(self.Caption) + 'Tv3', Tv3, '简易工艺管理');

  SetStatus();
  InitGlide();
  GYNote.lines.Text := '工艺备注：' + CDS_GX.FieldByName('GYNote').AsString;

  TbShow.Click;
  KeyPreview := True;

end;

procedure TfrmDyeSimpleTechnicsKaiKa.ToolButton3Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption) + 'Tv3', Tv3, '简易工艺管理');
end;

procedure TfrmDyeSimpleTechnicsKaiKa.TbDeleteClick(Sender: TObject);
begin
  if CDS_GX.IsEmpty then
  begin
    Exit;
  end;
  if (CDS_GX.FieldByName('PSID').asString = '') or (CDS_GX.FieldByName('PSID').asString = null) then
  begin
    CDS_GX.Delete;
//    InitGXDetails();
  end
  else
  begin
    Application.MessageBox('已保存工序不能删除！', '提示信息', MB_OK);
  end;
  SetXH();
end;

procedure TfrmDyeSimpleTechnicsKaiKa.TbShowClick(Sender: TObject);
begin
  CloseAllFrames();
  InitGXDetails();
end;

procedure TfrmDyeSimpleTechnicsKaiKa.Tv1DblClick(Sender: TObject);
begin

  with CDS_GX do
  begin
    Append;
    FieldByName('PSNO').Value := CDS_GX.RecordCount + 1;
    FieldByName('PSType').Value := CDS_PSType.fieldbyname('PSType').AsString;
    FieldByName('PSId').Value := '';
    post;
  end;
//  InitGXDetails();

end;

procedure TfrmDyeSimpleTechnicsKaiKa.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  CloseAllFrames();
  SetStatus();
  InitGlide();
//  InitGXDetails();
//  ShowMessage(CDS_2.FieldByName('DTMID').AsString);
  if (CDS_2.FieldByName('DTMID').AsString = '') or (CDS_2.FieldByName('DTMID').AsString = null) then
  begin

  end
  else
  begin
    ADOQueryCMD.DisableControls;
    with ADOQueryCMD do
    begin
//      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select *,PSXH=0 from Dye_Technics where 1 = 2 ');
      Open;
    end;
//    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryCMD, CDS_PSType);
    SInitCDSData(ADOQueryCMD, CDS_PSType);
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
//      FPSType := self.CDS_1.FieldByName('PSType').Value;
//      FPSID := Self.CDS_1.FieldByName('PSID').Value;
      BtnInt := 3;//查看
      TbSave.visible := false;
      TbUpFile.Visible := False;
      if ShowModal = 1 then
      begin

      end;
    end;

  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
end;

procedure TfrmDyeSimpleTechnicsKaiKa.FormCreate(Sender: TObject);
begin
  inherited;
  fmanage := Trim(DParameters1);

end;

procedure TfrmDyeSimpleTechnicsKaiKa.FillAllTextEditsWithValue(AParent: TWinControl; const AHint, AValue: string; AExclude: TcxTextEdit = nil);  // 可选：排除特定控件
var
  i: Integer;
  AControl: TControl;
  ATextEdit: TcxTextEdit;
begin
  for i := 0 to AParent.ControlCount - 1 do
  begin
    AControl := AParent.Controls[i];
    if (AControl is TcxTextEdit) and ((AControl as TcxTextEdit).Text = '') then
    begin
      ATextEdit := AControl as TcxTextEdit;
      if (ATextEdit.Hint = AHint) and (ATextEdit <> AExclude) then
        ATextEdit.Text := AValue;
    end;
  end;
end;

procedure TfrmDyeSimpleTechnicsKaiKa.ClearAllTextEditsByHint(AParent: TWinControl; const AHint: string; AExclude: TcxTextEdit = nil);
var
  i: Integer;
  AControl: TControl;
begin
  for i := 0 to AParent.ControlCount - 1 do
  begin
    AControl := AParent.Controls[i];
    // 检查是否是 TcxTextEdit，并且 Hint 匹配，且不是排除的控件
    if (AControl is TcxTextEdit) and (TcxTextEdit(AControl).Hint = AHint) and (TcxTextEdit(AControl) <> AExclude) then
    begin
      TcxTextEdit(AControl).Text := ''; // 直接清空
    end;
  end;
end;

function TfrmDyeSimpleTechnicsKaiKa.FindLastEditedTextEdit(AParent: TWinControl; const AHint: string): string;
var
  i, j: Integer;
  AControl: TControl;
  SortedControls: TList;
  TempControl: TControl;
begin
  Result := '';

  // 如果没有子控件，直接返回空
  if AParent.ControlCount = 0 then
    Exit;

  // 使用 TList 存储控件（兼容旧版 Delphi）
  SortedControls := TList.Create;
  try
    // 将所有子控件添加到列表
    for i := 0 to AParent.ControlCount - 1 do
      SortedControls.Add(AParent.Controls[i]);

    // 手动排序：按 Top（Y坐标）和 Left（X坐标）升序排列
    for i := 0 to SortedControls.Count - 1 do
    begin
      for j := i + 1 to SortedControls.Count - 1 do
      begin
        // 比较两个控件的 Top 和 Left
        if (TControl(SortedControls[i]).Top > TControl(SortedControls[j]).Top) or ((TControl(SortedControls[i]).Top = TControl(SortedControls[j]).Top) and (TControl(SortedControls[i]).Left > TControl(SortedControls[j]).Left)) then
        begin
          // 交换位置
          TempControl := TControl(SortedControls[i]);
          SortedControls[i] := SortedControls[j];
          SortedControls[j] := TempControl;
        end;
      end;
    end;
    // 遍历排序后的控件
    for i := 0 to SortedControls.Count - 1 do
    begin
      AControl := TControl(SortedControls[i]);
      if (AControl is TcxTextEdit) and (TcxTextEdit(AControl).Hint = AHint) and (TcxTextEdit(AControl).Text <> '') then
      begin
        Result := TcxTextEdit(AControl).Text; // 最后一个符合条件的会被保留
      end;
    end;
  finally
    SortedControls.Free;
  end;
end;

function TfrmDyeSimpleTechnicsKaiKa.GetNextFrameTop: Integer;
var
  i: Integer;
  Ctrl: TControl;
  MaxBottom: Integer;
begin
  MaxBottom := 0;

  // 如果没有任何控件，从 0 开始
  if ScrollBox1.ControlCount = 1 then
  begin
    Result := 0;
    Exit;
  end;

  for i := 0 to ScrollBox1.ControlCount - 1 do
  begin
    Ctrl := ScrollBox1.Controls[i];
    if (Ctrl is TFrame) and Ctrl.Visible then
    begin
      // 计算当前 frame 的底部位置
      var BottomPos := Ctrl.Top + Ctrl.Height;
      if BottomPos > MaxBottom then
        MaxBottom := BottomPos;
    end;
  end;

  // 添加一些间距
  Result := MaxBottom + 5;
end;

end.

