unit U_DyeProcessList;

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, Menus, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, dxScrollbarAnnotations;

type
  TfrmDyeProcessList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TbAdd_zm: TToolButton;
    TbEdit: TToolButton;
    Label5: TLabel;
    WorkHour: TEdit;
    Label1: TLabel;
    PSName: TEdit;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    TbAdd_ccqx: TToolButton;
    TbAdd_rgqx: TToolButton;
    TbAdd_jgqx: TToolButton;
    TbAdd_dx: TToolButton;
    TbAdd_fs: TToolButton;
    Label2: TLabel;
    MachineName: TEdit;
    TV2MachineName: TcxGridDBColumn;
    TV2WorkHour: TcxGridDBColumn;
    TbLook: TToolButton;
    TbAdd_FB: TToolButton;
    TbAdd_gj: TToolButton;
    TbAdd_fp: TToolButton;
    TV2Filler: TcxGridDBColumn;
    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 ZdyNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TbEditClick(Sender: TObject);
    procedure TbAdd_zmClick(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure TbAdd_ccqxClick(Sender: TObject);
    procedure TbAdd_rgqxClick(Sender: TObject);
    procedure TbAdd_jgqxClick(Sender: TObject);
    procedure TbAdd_dxClick(Sender: TObject);
    procedure TbAdd_fsClick(Sender: TObject);
    procedure TbLookClick(Sender: TObject);
    procedure TbAdd_FBClick(Sender: TObject);
    procedure TbAdd_fpClick(Sender: TObject);
    procedure TbAdd_gjClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDEFstr5: string;
    FPSType: string;
    FPSID: string;
    BtnInt: Integer;
    //0增加，1修改，2复制，3查看
  end;

var
  frmDyeProcessList: TfrmDyeProcessList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_DyeProcessInput, U_DyeProcessDefin;

{$R *.dfm}

procedure TfrmDyeProcessList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select * from Dye_Process ');
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
//  ToolButton2.Click;
end;

procedure TfrmDyeProcessList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmDyeProcessList := nil;
end;

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

procedure TfrmDyeProcessList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption), Tv2, '染色计划');
  Close;
end;

procedure TfrmDyeProcessList.TBDelClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(CDS_1.fieldbyname('PSID').AsString) <> '' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete Dye_Process where PSID=''' + Trim(CDS_1.fieldbyname('PSID').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete BS_Cloth_GY_Main where PSID=''' + Trim(CDS_1.fieldbyname('PSID').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete BS_Cloth_GY_Sub where PSID=''' + Trim(CDS_1.fieldbyname('PSID').AsString) + '''');
      ExecSQL;
    end;
  end;
  CDS_1.Delete;
end;

procedure TfrmDyeProcessList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv2, '染色计划');
  InitGrid();
end;

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

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

procedure TfrmDyeProcessList.TbAdd_fpClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '发泡';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;

  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_FBClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '翻布';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.ZdyNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmDyeProcessList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
//  SelExportData(Tv2,ADOQueryMain,'供应商资料列表');
end;

procedure TfrmDyeProcessList.TbEditClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 1;
      FPSID := Trim(Self.CDS_1.fieldbyname('PSID').AsString);
      FPSType := Trim(Self.CDS_1.fieldbyname('PSType').AsString);
      fDEFstr5 := self.fDEFstr5;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbLookClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 3;
      FPSID := Trim(Self.CDS_1.fieldbyname('PSID').AsString);
      FPSType := Trim(Self.CDS_1.fieldbyname('PSType').AsString);
      fDEFstr5 := self.fDEFstr5;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_ccqxClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '长车清洗';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_jgqxClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '机缸清洗';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_rgqxClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '卷染缸清洗';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_dxClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '干定型';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_zmClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '轧毛';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;

  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_fsClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '下水定型';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.TbAdd_gjClick(Sender: TObject);
begin
  try
    frmDyeProcessDefin := TfrmDyeProcessDefin.Create(Application);
    with frmDyeProcessDefin do
    begin
      BtnInt := 0;
      FPSType := '刮胶';
      FPSID := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;

  finally
    frmDyeProcessDefin.Free;
  end;
end;

procedure TfrmDyeProcessList.Tv2DblClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  ModalResult := 1;
end;

end.

