unit U_YGListMoresel;

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;

type
  TfrmYGListMoresel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2PSName: TcxGridDBColumn;
    v2PSSH: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TSsel: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DataSource1: TDataSource;
    Order_FZ: TClientDataSet;
    ADOQuery1: TADOQuery;
    V1PSXH: TcxGridDBColumn;
    Panel2: TPanel;
    v2Column1: TcxGridDBColumn;
    V1Column1: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    note1: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ZdyNameChange(Sender: TObject);
    procedure TSselClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fDEFstr5, FCRTime, FBanCi: string;
  end;

var
  frmYGListMoresel: TfrmYGListMoresel;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZDYHelpYuanGong;

{$R *.dfm}

procedure TfrmYGListMoresel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('select A.*,ZJM=dbo.getPinYin(A.ZdyName) from KH_ZDY A where A.Type=''YGXinxi''');

      sql.Add('and not exists(select * from GZListMain X where A.ZDYName=X.YGName and A.Note=X.YGCode ');
      sql.Add(' and X.CRTime=' + quotedstr(FCRTime) + ' and X.BanCi=' + quotedstr(FBanCi) + ')');
      sql.Add(' order by note');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
    SCreateCDS20(ADOQueryMain, Order_FZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGListMoresel.FormDestroy(Sender: TObject);
begin
  frmYGListMoresel := nil;
end;

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

procedure TfrmYGListMoresel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('工序查询', Tv2, '客户自定义');
  Close;
end;

procedure TfrmYGListMoresel.FormShow(Sender: TObject);
begin
  ReadCxGrid('工序查询', Tv2, '客户自定义');
  InitGrid();
end;

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

procedure TfrmYGListMoresel.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

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

procedure TfrmYGListMoresel.TSselClick(Sender: TObject);
begin
  if Order_FZ.IsEmpty then
    exit;
  ModalResult := 1;
end;

procedure TfrmYGListMoresel.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  with Order_FZ do
  begin
    Append;
    FieldByName('Note').Value := CDS_HZ.fieldbyname('Note').AsString;
    FieldByName('ZDYName').Value := CDS_HZ.fieldbyname('ZDYName').AsString;
    FieldByName('note1').Value := CDS_HZ.fieldbyname('note1').AsString;
    post;
  end;
  CDS_HZ.Delete;
end;

procedure TfrmYGListMoresel.TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  with CDS_HZ do
  begin
    Append;
    FieldByName('Note').Value := Order_FZ.fieldbyname('Note').AsString;
    FieldByName('ZDYName').Value := Order_FZ.fieldbyname('ZDYName').AsString;
    FieldByName('note1').Value := Order_FZ.fieldbyname('note1').AsString;
    post;
  end;
  Order_FZ.Delete;
end;

end.

