unit U_DyeSimpleTechnicsList;

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,Clipbrd;

  //U_frameJGQXList, U_frameRGQXList, U_frameCCQXList, U_frameYMList

type
  TfrmDyeSimpleTechnicsList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    DTMName: TEdit;
    ADOQueryMain: TADOQuery;
    Label3: TLabel;
    DTMNo: TEdit;
    GPM_2: TcxGridPopupMenu;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    cxTabControl1: TcxTabControl;
    Tchk: TToolButton;
    TNochk: TToolButton;
    DS_PsType: TDataSource;
    CDS_PSType: TClientDataSet;
    ADOQuery1: TADOQuery;
    GPM_1: TcxGridPopupMenu;
    ToolButton3: TToolButton;
    ToolButton1: TToolButton;
    ToolButton4: TToolButton;
    TbSave: TToolButton;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Ssel: TcxGridDBColumn;
    v2GYNO: TcxGridDBColumn;
    v2GYName: TcxGridDBColumn;
    v2GYGX: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ScrollBox1: TScrollBox;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    Tv1PSType: TcxGridDBColumn;
    CDS_GX: TClientDataSet;
    DS_GX: TDataSource;
    Tv2DTMID: TcxGridDBColumn;
    ToolBar2: TToolBar;
    ToolButton5: TToolButton;
    Tv2Editer: TcxGridDBColumn;
    Tv2Edittime: TcxGridDBColumn;
    ToolButton6: TToolButton;
    GPM_3: TcxGridPopupMenu;
    cxSplitter2: TcxSplitter;
    cxSplitter1: TcxSplitter;
    TbCopy: TToolButton;
    TbMoveUp: TToolButton;
    ToolButton7: TToolButton;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Char: TEdit;
    Product: TEdit;
    GYRequire: TEdit;
    Label6: TLabel;
    Tv3: TcxGridDBTableView;
    cxGrid3Level1: TcxGridLevel;
    cxGrid3: TcxGrid;
    Tv3PSNO: TcxGridDBColumn;
    Tv3PSType: TcxGridDBColumn;
    Tv3PSName: TcxGridDBColumn;
    Tv3PSID: TcxGridDBColumn;
    Tv3Page: TcxGridDBColumn;
    Panel4: TPanel;
    GYNote: TMemo;
    pm1: TPopupMenu;
    N1: TMenuItem;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure DTMNoChange(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TNochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxGridDBColumn1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure ButtonEdit(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1DblClick(Sender: TObject);
    procedure TbSaveClick(Sender: TObject);

    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DTMNameKeyPress(Sender: TObject; var Key: Char);
    procedure DTMNoKeyPress(Sender: TObject; var Key: Char);
    procedure TbCopyClick(Sender: TObject);
    procedure TbMoveUpClick(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure CharKeyPress(Sender: TObject; var Key: Char);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
    procedure SetStatus();

    procedure InitPSTypeGrid();
    procedure InitGlide();
    procedure InitGXDetails();
    procedure CloseAllFrames();
    function SaveData(): Boolean;

    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();
    procedure SaveSpliterPosition();
    procedure ReadSpliterPosition();
  public
    fPSIDList: string;
    fmanage: string;
    fState: string;
  end;

var
  frmDyeSimpleTechnicsList: TfrmDyeSimpleTechnicsList;
  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;

{$R *.dfm}

procedure TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.SetStatus();
var
  i: integer;
begin

  Tchk.Visible := false;
  TNochk.Visible := false;
  TBDel.Visible := false;

//  Panel_zm.Visible := False;
//  Panel_ccqx.Visible := False;
//  Panel_rgqx.Visible := False;
//  Panel_jgqx.Visible := False;
//  Panel_dx.Visible := False;
//  Panel_FS.Visible := False;
//  Panel_GJ.Visible := False;
//  Panel_FP.Visible := False;

//  for i := 0 to tv2.ColumnCount - 1 do
//  begin
//    if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
//      tv2.Columns[i].Options.Editing := false;
//  end;
  if cxTabControl1.TabIndex = 0 then
  begin
    Tchk.Visible := true;
    TBDel.Visible := true;
  end;
  if cxTabControl1.TabIndex = 1 then
  begin
    TNochk.Visible := true;
  end;
  if cxTabControl1.TabIndex = 2 then
  begin

  end;
end;

procedure TfrmDyeSimpleTechnicsList.InitGrid();
var
  Pwhere: string;
begin

  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(char.Text) <> '' then
  begin
    if Length(trim(char.Text)) > 1 then
    begin
      if Pwhere <> '' then
        Pwhere := Pwhere + ' and 1=2'
      else
        Pwhere := '1=2';
    end
    else
    begin
      if Pwhere <> '' then
        Pwhere := Pwhere + ' and DTMNo like ''' + trim(char.Text) + '%-%'' '
      else
        Pwhere := 'DTMNo like ''' + trim(char.Text) + '%-%'' ';
    end;
  end;

  if trim(Product.Text) <> '' then
  begin
    if Pwhere <> '' then
      Pwhere := Pwhere + ' and DTMNo like ''%' + trim(Product.Text) + '%-%'''
    else
      Pwhere := 'DTMNo like ''%' + trim(Product.Text) + '%-%''';
  end;

  if trim(GYRequire.Text) <> '' then
  begin
    if Pwhere <> '' then
    begin
      Pwhere := Pwhere + ' and SUBSTRING(DTMNo, 7, 1) = ''' + trim(GYRequire.Text) + '''';
    end
    else
    begin
      Pwhere := ' SUBSTRING(DTMNo, 7, 1) = ''' + trim(GYRequire.Text) + '''';
    end;
  end;

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select * FROM Dye_Technics_Main where 1=1 ');
      if Pwhere <> '' then
      begin
        sql.Add(' and ' + Pwhere);
      end;
      if cxTabControl1.TabIndex < 2 then
        sql.Add(' and isnull(status,''0'')=''' + inttostr(cxTabControl1.TabIndex) + ''' ');
//      ShowMessage(SQL.Text);
      Open;

    end;
    ADOQueryMain.Filtered := false;
//    ShowMessage(IntToStr(ADOQueryMain.RecordCount));
    SCreateCDS(ADOQueryMain, CDS_2);
    SInitCDSData(ADOQueryMain, CDS_2);
//    ShowMessage(ADOQueryMain.FieldByName('DTMID').AsString);
//    ShowMessage(CDS_2.FieldByName('DTMID').AsString);
  finally
    ADOQueryMain.EnableControls;

    //CDS_1.EmptyDataSet;
  end;
end;

procedure TfrmDyeSimpleTechnicsList.SaveSpliterPosition();
var
  IniFile: TIniFile;
  leftPos: Integer;
begin
  try
    IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'SpliterPosition.INI');
    IniFile.WriteInteger('DyeSimpleTechnicsList_Spliter', 'Position1', cxSplitter1.Control.Width);
    IniFile.WriteInteger('DyeSimpleTechnicsList_Spliter', 'Position2', cxSplitter2.Control.Width);
  finally
    IniFile.Free;
  end;
end;

procedure TfrmDyeSimpleTechnicsList.ReadSpliterPosition();
var
  IniFile: TIniFile;
  leftPos1: Integer;
  leftPos2: Integer;
begin
  try
    IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'SpliterPosition.INI');
    leftPos1 := IniFile.ReadInteger('DyeSimpleTechnicsList_Spliter', 'Position1', 616);
    leftPos2 := IniFile.ReadInteger('DyeSimpleTechnicsList_Spliter', 'Position2', 785);
    cxSplitter1.Control.Width := leftPos1;
    cxSplitter2.Control.Width := leftPos2;
  finally
    IniFile.Free;
  end;
end;

function TfrmDyeSimpleTechnicsList.SaveData(): Boolean;
var
  MaxProcessID, MaxBCPID, MaxPSID, MaxDTMID, mDTMID, DTMPSlist: string;
  maxsubid1, maxsubid2, maxsubid3, maxsubid4, maxsubid5, maxsubid6, mmaxgx, maxId, mPSID, mPSType: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_GX.First;
    while not CDS_GX.Eof do
    begin
      mPSID := CDS_GX.FieldByName('PSID').AsString;
      mPSType := CDS_GX.FieldByName('PSType').AsString;
      mDTMID := CDS_2.FieldByName('DTMID').AsString;

      ///////////////////////////保存主表Dye_process////////////////////////////
      with ADOQueryCmd do
      begin
        Filtered := False;
        Close;
        SQL.Clear;
        sql.Add(' select * from Dye_Process where PSID=''' + Trim(mPSID) + '''');
        Open;
      end;

      with ADOQueryCmd do
      begin
        if Trim(CDS_GX.fieldbyname('PSID').AsString) = '' then
        begin
          if GetLSNo(ADOQueryCmd, maxId, 'JP', 'Dye_Process', 4, 1) = False then
          begin
            Result := False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxId := Trim(mPSID);
        end;
        with CDS_GX do
        begin
          Edit;
          FieldByName('PSID').Value := maxId;
          Post;
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Dye_Process where PSID=''' + Trim(maxId) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(mPSID) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
          end;
          FieldByName('PSID').Value := Trim(maxId);
          FieldByName('DTMID').Value := Trim(CDS_2.FieldByName('DTMID').AsString);
          FieldByName('PSType').Value := Trim(mPSType);
          FieldByName('PSName').Value := Trim(CDS_GX.FieldByName('PSName').AsString);
          FieldByName('DTMName').Value := Trim(CDS_2.FieldByName('DTMName').AsString);
          Post;
        end;
      end;

///////////////////保存主表Dye_process////////////////////////////
      if mPSType = '长车清洗' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameCCQXList1' then
        begin
          frameCCQXList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameCCQXList2' then
        begin
          frameCCQXList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameCCQXList3' then
        begin
          frameCCQXList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameCCQXList4' then
        begin
          frameCCQXList4.SaveData(maxId);
        end;
      end
      else if mPSType = '卷染缸清洗' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameRGQXList1' then
        begin
          frameRGQXList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameRGQXList2' then
        begin
          frameRGQXList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameRGQXList3' then
        begin
          frameRGQXList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameRGQXList4' then
        begin
          frameRGQXList4.SaveData(maxId);
        end;
      end
      else if mPSType = '机缸清洗' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameJGQXList1' then
        begin
          frameJGQXList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameJGQXList2' then
        begin
          frameJGQXList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameJGQXList3' then
        begin
          frameJGQXList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameJGQXList4' then
        begin
          frameJGQXList4.SaveData(maxId);
        end;
      end
      else if mPSType = '干定型' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameGDXList1' then
        begin
          frameGDXList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameGDXList2' then
        begin
          frameGDXList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameGDXList3' then
        begin
          frameGDXList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameGDXList4' then
        begin
          frameGDXList4.SaveData(maxId);
        end;
      end
      else if mPSType = '下水定型' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameFSList1' then
        begin
          frameFSList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameFSList2' then
        begin
          frameFSList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameFSList3' then
        begin
          frameFSList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameFSList4' then
        begin
          frameFSList4.SaveData(maxId);
        end;
      end
      else if mPSType = '发泡' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameFPList1' then
        begin
          frameFPList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameFPList2' then
        begin
          frameFPList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameFPList3' then
        begin
          frameFPList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameFPList4' then
        begin
          frameFPList4.SaveData(maxId);
        end;
      end
      else if mPSType = '刮胶' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameGJList1' then
        begin
          frameGJList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameGJList2' then
        begin
          frameGJList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameGJList3' then
        begin
          frameGJList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameGJList4' then
        begin
          frameGJList4.SaveData(maxId);
        end;
      end
      else if mPSType = '轧毛' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'frameYMList1' then
        begin
          frameYMList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameYMList2' then
        begin
          frameYMList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameYMList3' then
        begin
          frameYMList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'frameYMList4' then
        begin
          frameYMList4.SaveData(maxId);
        end;
      end
      else if mPSType = '拍打' then
      begin
        if CDS_GX.FieldByName('page').AsString = 'framePDList1' then
        begin
          framePDList1.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'framePDList2' then
        begin
          framePDList2.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'framePDList3' then
        begin
          framePDList3.SaveData(maxId);
        end
        else if CDS_GX.FieldByName('page').AsString = 'framePDList4' then
        begin
          framePDList4.SaveData(maxId);
        end;
      end;

      CDS_GX.Next;
    end;

    if Trim(mDTMID) = '' then
    begin
      if GetLSNo(ADOQueryCmd, MaxDTMID, 'GY', 'Dye_Technics_Main', 3, 1) = False then
        raise Exception.Create('取最大号失败！');
    end
    else
    begin
      MaxDTMID := mDTMID;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Dye_Technics_Sub where DTMID=' + quotedstr(trim(MaxDTMID)));
      execsql;
    end;

    DTMPSlist := '';
    with CDS_GX do
    begin
      First;
      while not Eof do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('SELECT * FROM Dye_Technics_Sub WHERE 1=2');
          Open;
        end;
        with ADOQueryCmd do
        begin
          Append;
          FieldByName('PSNO').Value := Trim(CDS_GX.fieldbyname('PSNO').AsString);
          FieldByName('DTMID').Value := Trim(MaxDTMID);
          FieldByName('PSId').Value := Trim(CDS_GX.fieldbyname('PSId').AsString);
          Post;
        end;
        if DTMPSlist = '' then
        begin
          DTMPSlist := Trim(CDS_GX.fieldbyname('PSNO').AsString) + '.' + Trim(CDS_GX.fieldbyname('PSName').AsString);
        end
        else
        begin
          DTMPSlist := DTMPSlist + '→' + Trim(CDS_GX.fieldbyname('PSNO').AsString) + '.' + Trim(CDS_GX.fieldbyname('PSName').AsString);
        end;

        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('SELECT * FROM Dye_Process WHERE PSID = ' + QuotedStr(Trim(CDS_GX.fieldbyname('PSId').AsString)));
          Open;
        end;
        with ADOQueryCmd do
        begin
          Edit;
          FieldByName('DTMName').Value := Trim(CDS_2.FieldByName('DTMName').AsString);
          FieldByName('DTMID').Value := Trim(MaxDTMID);
          Post;
        end;
        Next;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Dye_Technics_Main where DTMID =' + quotedstr(Trim(MaxDTMID)));
      Open;
    end;
    with ADOQueryCmd do
    begin
      if ADOQueryCmd.IsEmpty then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('filltime').Value := SGetServerDateTime(ADOQueryTemp);
        FieldByName('DTMID').Value := Trim(MaxDTMID);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('DTMNo').Value := CDS_2.FieldByName('DTMNo').AsString;
      FieldByName('DTMName').Value := CDS_2.FieldByName('DTMName').AsString;
      FieldByName('DTMPSlist').Value := Trim(DTMPSlist);
      Post;
    end;



        //////////////产品信息表内容修改//////////////
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from BS_Cloth_Info where DTMID =' + quotedstr(Trim(MaxDTMID)));
      Open;
    end;
    ADOQueryCmd.First;
    while not ADOQueryCmd.Eof do
    begin
      ADOQueryCmd.Edit;
      ADOQueryCmd.FieldByName('DTMPSlist').Value := Trim(DTMPSlist);
      ADOQueryCmd.FieldByName('Editer').Value := Trim(DName);
      ADOQueryCmd.FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
      ADOQueryCmd.Post;
      ADOQueryCmd.Next;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from BS_Cloth_Dye_Technics where DTMID =' + quotedstr(Trim(MaxDTMID)));
      Open;
    end;
    ADOQueryCmd.First;
    while not ADOQueryCmd.Eof do
    begin
      ADOQueryCmd.Edit;
      ADOQueryCmd.FieldByName('DTMPSlist').Value := Trim(DTMPSlist);
      ADOQueryCmd.FieldByName('DTMNo').Value := CDS_2.FieldByName('DTMNo').AsString;
      ADOQueryCmd.FieldByName('DTMName').Value := CDS_2.FieldByName('DTMName').AsString;
      ADOQueryCmd.Post;
      ADOQueryCmd.Next;
    end;
    //////////////产品信息表内容修改//////////////


    ADOQueryCmd.Connection.CommitTrans;
//    FPSID := maxId;
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;

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

procedure TfrmDyeSimpleTechnicsList.N1Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_2.fieldbyname(TV2.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));

end;

procedure TfrmDyeSimpleTechnicsList.InitGlide();
begin
  try
    ADOQueryTemp.DisableControls;
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* FROM V_Dye_Technics_Details A');
      sql.Add(' Where A.DTMID=''' + trim(CDS_2.fieldbyname('DTMID').AsString) + '''');
      SQL.Add(' ORDER BY A.PSNO');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS(ADOQueryTemp, CDS_GX);
    SInitCDSData(ADOQueryTemp, CDS_GX);
  finally
    ADOQueryTemp.EnableControls;
  end;
end;

procedure TfrmDyeSimpleTechnicsList.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_Technics_Details A');
        sql.Add(' Where A.PSID=''' + trim(CDS_GX.fieldbyname('PSID').AsString) + '''');
//        SQL.Add(' and A.PSID = ''' + trim(CDS_2.fieldbyname('PSID').AsString) + '''');
        Open;
      end;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select A.* FROM BS_Cloth_GY_Sub A');
        sql.Add(' Where A.PSID=''' + trim(CDS_GX.fieldbyname('PSID').AsString) + '''');
        SQL.Add(' Order By A.serialno');
//        SQL.Add(' and A.PSID = ''' + trim(CDS_2.fieldbyname('PSID').AsString) + '''');

        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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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();

          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 TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmDyeSimpleTechnicsList := nil;
end;

procedure TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmDyeSimpleTechnicsList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmDyeSimpleTechnicsList.TBDelClick(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    Exit;
  if CDS_2.Locate('ssel', true, []) = false then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_2 do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if Fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('delete Dye_Technics_Main where DTMID=''' + Trim(CDS_2.fieldbyname('DTMID').AsString) + '''');
            sql.Add('delete Dye_Technics_Sub where  DTMID=''' + Trim(CDS_2.fieldbyname('DTMID').AsString) + '''');

            execsql;
          end;
//          CDS_1.First;
//          while not CDS_1.Eof do
//          begin
//            with ADOQueryCmd do
//            begin
//              close;
//              sql.Clear;
//              sql.Add('delete Dye_Process where PSID=''' + Trim(CDS_1.fieldbyname('PSID').AsString) + '''');
//              sql.Add('delete BS_Cloth_GY_Sub where  PSID=''' + Trim(CDS_1.fieldbyname('PSID').AsString) + '''');
//              sql.Add('delete BS_Cloth_GY_Main where  PSID=''' + Trim(CDS_1.fieldbyname('PSID').AsString) + '''');
//
//              execsql;
//            end;
//            CDS_1.Next;
//          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmDyeSimpleTechnicsList.TbMoveUpClick(Sender: TObject);
var
  test: string;
  ACurrentRow, APrevRow: Integer;
begin
  ACurrentRow := Tv3.DataController.FocusedRowIndex + 1;//当前行位置（从1开始）
  if ACurrentRow = 1 then  // 已经是第一条记录
    Exit;

  APrevRow := ACurrentRow - 1;

  CDS_GX.DisableControls;
  try
    // 交换当前记录和上一条记录的顺序值
    CDS_GX.RecNo := ACurrentRow;
    CDS_GX.Edit;
    CDS_GX.FieldByName('PSNo').AsInteger := APrevRow;
    test := CDS_GX.FieldByName('PSName').AsString;
    CDS_GX.Post;

    CDS_GX.RecNo := APrevRow;
    CDS_GX.Edit;
    CDS_GX.FieldByName('PSNo').AsInteger := ACurrentRow;
    test := CDS_GX.FieldByName('PSName').AsString;
    CDS_GX.Post;

    // 刷新数据
//    CDS_1.Refresh;
    CDS_GX.IndexFieldNames := 'PSNo';
    // 重新定位到移动后的记录
    Tv3.DataController.FocusedRowIndex := APrevRow - 1;
  finally
    CDS_GX.EnableControls;
  end;
end;

procedure TfrmDyeSimpleTechnicsList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, '简易工艺管理');
  ReadCxGrid(trim(self.Caption) + 'Tv2', Tv2, '简易工艺管理');
  ReadCxGrid(trim(self.Caption) + 'Tv3', Tv3, '简易工艺管理');
  ReadSpliterPosition();
  SetStatus();
  InitGrid();

  KeyPreview := True;

end;

procedure TfrmDyeSimpleTechnicsList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmDyeSimpleTechnicsList.TbSaveClick(Sender: TObject);
begin
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
  end;
end;

procedure TfrmDyeSimpleTechnicsList.ToolButton1Click(Sender: TObject);
begin
  CDS_2.Append;
  tv2.Columns[1].Options.Editing := true;
  tv2.Columns[2].Options.Editing := true;
end;

procedure TfrmDyeSimpleTechnicsList.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_2);
    SInitCDSData(ADOQueryMain, CDS_2);
  end;
end;

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

procedure TfrmDyeSimpleTechnicsList.ToolButton4Click(Sender: TObject);
begin
  InitPSTypeGrid();
  tv2.Columns[1].Options.Editing := true;
  tv2.Columns[2].Options.Editing := true;
end;

procedure TfrmDyeSimpleTechnicsList.ToolButton5Click(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 TfrmDyeSimpleTechnicsList.ToolButton6Click(Sender: TObject);
begin
  CloseAllFrames();
  InitGXDetails();
end;

procedure TfrmDyeSimpleTechnicsList.ToolButton7Click(Sender: TObject);
var
  test: string;
  ACurrentRow, APrevRow: Integer;
begin
  ACurrentRow := Tv3.DataController.FocusedRowIndex + 1;//当前行位置（从1开始）
  if ACurrentRow = CDS_GX.RecordCount then  // 已经是第一条记录
    Exit;

  APrevRow := ACurrentRow + 1;

  CDS_GX.DisableControls;
  try
    // 交换当前记录和上一条记录的顺序值

    CDS_GX.RecNo := APrevRow;
    CDS_GX.Edit;
    CDS_GX.FieldByName('PSNo').AsInteger := ACurrentRow;
    test := CDS_GX.FieldByName('PSName').AsString;
    CDS_GX.Post;

    CDS_GX.RecNo := ACurrentRow;
    CDS_GX.Edit;
    CDS_GX.FieldByName('PSNo').AsInteger := APrevRow;
    test := CDS_GX.FieldByName('PSName').AsString;
    CDS_GX.Post;



    // 刷新数据
//    CDS_1.Refresh;
    CDS_GX.IndexFieldNames := 'PSNo';

    Tv3.DataController.FocusedRowIndex := ACurrentRow - 1;
  finally
    CDS_GX.EnableControls;
  end;
end;

procedure TfrmDyeSimpleTechnicsList.TbCopyClick(Sender: TObject);
var
  maxNo, maxsubid: string;
  mMaxDTMID: string;
  mCopyDTMID: string;
begin

  try
    ADOQueryCmd.Connection.BeginTrans;
  //保存需复制的工艺
    mCopyDTMID := CDS_2.FieldByName('DTMID').AsString;
//  fState := '复制';
    if GetLSNo(ADOQueryCmd, mMaxDTMID, 'GY', 'Dye_Technics_Main', 3, 1) = False then
      raise Exception.Create('取最大号失败！');

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Dye_Technics_Main where 1 = 2');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('Editer').Value := Trim(DName);
      FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
      FieldByName('DTMID').Value := Trim(mMaxDTMID);
      Post;
    end;

    CDS_GX.First;
    while not CDS_GX.Eof do
    begin

      if GetLSNo(ADOQueryCmd, maxNo, 'JP', 'Dye_Process', 4, 1) = False then
      begin
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        SQL.Add('exec P_CopyDyeProcess ');
        SQL.Add(' @PSID = ' + QuotedStr(Trim(CDS_GX.fieldbyname('PSID').AsString)));
        SQL.Add(' ,@maxNo = ' + QuotedStr(Trim(maxNo)));
        SQL.Add(' ,@DName = ' + QuotedStr(Trim(DName)));
//        SQL.Add(' ,@DTMID = ' + QuotedStr(Trim(DTMID.Text)));
        Open;
      end;

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('SELECT * FROM Dye_Technics_Sub WHERE 1=2');
        Open;
      end;
      with ADOQueryCmd do
      begin
        Append;
        FieldByName('PSNO').Value := Trim(CDS_GX.fieldbyname('PSNO').AsString);
        FieldByName('DTMID').Value := Trim(mMaxDTMID);
        FieldByName('PSId').Value := Trim(maxNo);
        Post;
      end;

      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        SQL.Add(' select * from BS_Cloth_GY_Sub where PSID = ' + QuotedStr(Trim(maxNo)));
        Open;
      end;
      ADOQueryCmd.First;
      while not ADOQueryCmd.Eof do
      begin

        if ADOQueryCmd.FieldByName('gytype').Value = '长车清洗' then
        begin
          if GetLSNo(ADOQueryTemp, maxsubid, 'CCQX', 'Bs_Cloth_GY_Sub', 5, 1) = False then
          begin
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else if ADOQueryCmd.FieldByName('gytype').Value = '卷染缸清洗' then
        begin
          if GetLSNo(ADOQueryTemp, maxsubid, 'RGQX', 'Bs_Cloth_GY_Sub', 5, 1) = False then
          begin
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else if ADOQueryCmd.FieldByName('gytype').Value = '机缸清洗' then
        begin
          if GetLSNo(ADOQueryTemp, maxsubid, 'JGQX', 'Bs_Cloth_GY_Sub', 5, 1) = False then
          begin
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else if ADOQueryCmd.FieldByName('gytype').Value = '下水定型' then
        begin
          if GetLSNo(ADOQueryTemp, maxsubid, 'FS', 'Bs_Cloth_GY_Sub', 5, 1) = False then
          begin
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else if ADOQueryCmd.FieldByName('gytype').Value = '刮胶' then
        begin
          if GetLSNo(ADOQueryTemp, maxsubid, 'GJ', 'Bs_Cloth_GY_Sub', 5, 1) = False then
          begin
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          if GetLSNo(ADOQueryTemp, maxsubid, 'FP', 'Bs_Cloth_GY_Sub', 5, 1) = False then
          begin
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end;

        ADOQueryCmd.Edit;
        ADOQueryCmd.fieldByName('BCPID').Value := maxsubid;
        ADOQueryCmd.Post;
        ADOQueryCmd.Next;
      end;

      CDS_GX.next;
    end;

    CDS_2.Append;
    CDS_2.FieldByName('DTMID').AsString := mMaxDTMID;
    tv2.Columns[1].Options.Editing := true;
    tv2.Columns[2].Options.Editing := true;

    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* FROM V_Dye_Technics_Details A');
      sql.Add(' Where A.DTMID=''' + trim(mMaxDTMID) + '''');
      SQL.Add(' ORDER BY A.PSNO');
      Open;
    end;
    SCreateCDS(ADOQueryTemp, CDS_GX);
    SInitCDSData(ADOQueryTemp, CDS_GX);

    CloseAllFrames();
    InitGXDetails();

    ADOQueryCmd.Connection.CommitTrans;
//    FPSID := maxId;

  except

    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('复制失败!', '提示', 0);
  end;
end;

procedure TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin

  GYNote.Lines.Text := '工艺备注：' + CDS_2.FieldByName('GYNote').AsString;
//  if fState <> '复制' then
//  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
    InitPSTypeGrid();
  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;

end;

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

      end;
    end;

  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeSimpleTechnicsList.DTMNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ToolButton2.Click;
  end;

end;

procedure TfrmDyeSimpleTechnicsList.DTMNoChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmDyeSimpleTechnicsList.DTMNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ToolButton2.Click;
  end;

end;

procedure TfrmDyeSimpleTechnicsList.TchkClick(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    exit;

  if CDS_2.Locate('ssel', true, []) = false then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_2 do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if Fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update Dye_Technics_Main SET status=''1'' ');
            sql.Add('where DTMID =' + quotedstr(trim(CDS_2.fieldbyname('DTMID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;

    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmDyeSimpleTechnicsList.TNochkClick(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    exit;

  if CDS_2.Locate('ssel', true, []) = false then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_2 do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if Fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update Dye_Technics_Main SET status=''0'' ');
            sql.Add('where DTMID =' + quotedstr(trim(CDS_2.fieldbyname('DTMID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

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

end;

procedure TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.CharKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();

  end;

end;

procedure TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.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 TfrmDyeSimpleTechnicsList.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.

