unit U_WarpBeamQianList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, dxScrollbarAnnotations, cxContainer,
  dxSkinsCore, dxSkinsDefaultPainters, cxProgressBar;

type
  TfrmWarpBeamQianList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    WBNO: TcxTextEdit;
    ToCoName: TcxTextEdit;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    TV1Column22: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TV1Column1: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure SXBatchNOChange(Sender: TObject);
    procedure FromCoNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FromCoNamePropertiesChange(Sender: TObject);
  private
    canshu1, FStkName, canshu3: string;
    procedure InitGrid();

    { Private declarations }
  public

    { Public declarations }
  end;

var
  frmWarpBeamQianList: TfrmWarpBeamQianList;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmWarpBeamQianList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmWarpBeamQianList := nil;
end;

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

procedure TfrmWarpBeamQianList.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(self.fParameters1);
  FStkName := Trim(self.fParameters2);
  canshu3 := Trim(self.fParameters3);
end;

procedure TfrmWarpBeamQianList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' EXEC P_TatWB_StkALL ');

      sql.Add(' select A.WBNo ORGWBNo,B.*,C.* from Tat_WB_Stk A inner join Tat_WB_IO B on A.STKTWIOID=B.TWIOID ');
      sql.Add(' left join Tat_WB_Card C on C.WBCID=B.WBCID ');
      sql.Add(' where  B.IOFlag =''出库'' and  B.IOType = ''加工出库'' and A.WBNo like ''%JZ%'' and isnull(CLFlag,0)=0 ');


//      sql.Add('  select A.* ');
//      sql.Add('  from Tat_WB_IO A  ');
//      sql.Add('  where A.STKName =''空轴''  and A.IOFlag =''出库'' and A.WBNo like ''%JZ%'' and isnull(CLFlag,0)=0 ');
//      sql.Add('  and not EXISTS (select * from Tat_WB_IO X where X.STKName =''经轴''  and X.IOFlag =''入库'' and A.WBNO =X.WBNO)   ');
//
//      sql.Add('  UNION ALL   ');
//
//      sql.Add('  select A.* ');
//      sql.Add('  from Tat_WB_IO A  ');
//      sql.Add('  where A.STKName =''经轴''  and A.IOFlag =''出库'' and A.WBNo like ''%JZ%'' and isnull(CLFlag,0)=0  ');
//      sql.Add('  and not EXISTS (select * from Tat_WB_IO X where X.STKName =''空轴''  and X.IOFlag =''入库'' and A.WBNO =X.WBNO)   ');
//      ShowMessage(Sql.text);
      Open;
    end;

    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmWarpBeamQianList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmWarpBeamQianList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmWarpBeamQianList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '染色坯布仓库');
  InitGrid();
end;

procedure TfrmWarpBeamQianList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmWarpBeamQianList.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmWarpBeamQianList.SXBatchNOChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmWarpBeamQianList.FromCoNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmWarpBeamQianList.FromCoNamePropertiesChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmWarpBeamQianList.ToolButton2Click(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption), Tv1, '染色坯布仓库');
end;

procedure TfrmWarpBeamQianList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ModalResult := 1;
end;

end.

