unit U_Dye_AbnormalCardSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters, cxNavigator,
  dxDateRanges, dxBarBuiltInMenu, System.ImageList, U_BaseInput,
  dxScrollbarAnnotations, cxDropDownEdit, cxCheckBox, cxCheckComboBox,
  cxCheckGroup;

type
  TfrmDye_AbnormalCardSel = class(TfrmBaseHelp)
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSaveFormat: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    Label1: TLabel;
    DTMNo: TEdit;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    TV1C_Name: TcxGridDBColumn;
    TV1OrderNo: TcxGridDBColumn;
    TV1DTMPSlist: TcxGridDBColumn;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    Label2: TLabel;
    DTMName: TEdit;
    TV1F_Name: TcxGridDBColumn;
    TV1C_Width: TcxGridDBColumn;
    TV1C_GramWeight: TcxGridDBColumn;
    TV1PCPiece: TcxGridDBColumn;
    TV1PCQty: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBSaveFormatClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure DTMNoChange(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority, FBCIID, fcode, FC_Name: string;
    { Public declarations }
  end;

var
  frmDye_AbnormalCardSel: TfrmDye_AbnormalCardSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmDye_AbnormalCardSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmDye_AbnormalCardSel.DTMNoChange(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 TfrmDye_AbnormalCardSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  Action := cahide;
end;

procedure TfrmDye_AbnormalCardSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
//      sql.Add('select A.* from Bs_Cloth_Dye_Technics A where C_Code = ' + QuotedStr(Trim(fCode)));
      SQL.Add(' select A.KaZu,A.OrderNo,A.C_Name,A.C_Width,A.C_GramWeight,A.DTMPSlist ');
      SQL.Add(' ,sum(PCPiece) as PCPiece,sum(PCQty) as PCQty ');
      SQL.Add(' from Dye_Plan_Card A where A.status = ''-1'' ');
      sql.Add(' group by A.KaZu,A.OrderNo,A.C_Name,A.C_Width,A.C_GramWeight,A.DTMPSlist ');
      SQL.Add(' ,A.TotalPCIDNum ');
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

  InitGrid();

  ReadCxGrid(self.Caption + 'TV1', TV1, '异常卡组选择');
  KeyPreview := True;
end;

procedure TfrmDye_AbnormalCardSel.TBCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmDye_AbnormalCardSel.TBSaveFormatClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption + 'TV1', TV1, '异常卡组选择');

end;

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

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

procedure TfrmDye_AbnormalCardSel.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;

end.

