unit U_WarpBeamStkList;

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
  TfrmWarpBeamStkList = 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;
    WBCID: TcxTextEdit;
    FromCoName: TcxTextEdit;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    TV1Column22: TcxGridDBColumn;
    TV1Column23: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TV1Column1: TcxGridDBColumn;
    Label1: TLabel;
    WBNO: TcxTextEdit;
    Label2: TLabel;
    WB_YarnQty2: TcxTextEdit;
    Label5: TLabel;
    JSName: TcxTextEdit;
    TV1Column2: 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
  frmWarpBeamStkList: TfrmWarpBeamStkList;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmWarpBeamStkList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmWarpBeamStkList := nil;
end;

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

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

procedure TfrmWarpBeamStkList.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.*,WB_YarnQty2= cast (WB_YarnQty AS Varchar)  ');
      sql.Add(' ,JSName=cast((SELECT  Y_Name +'';'' from  Tat_WB_Formula X inner join Tat_WB_Spec Y on X.WBSID=Y.WBSID where C.WB_Code=Y.WB_Code FOR XML PATH(''''))as VARCHAR(6000)  )');
      sql.Add(' from Tat_WB_Stk A inner join Tat_WB_IO B on A.STKTWIOID=B.TWIOID ');
      sql.Add(' inner join Tat_WB_Card C on C.WBCID=B.WBCID ');
      sql.Add(' where   B.IOFlag =''入库''  and isnull(B.stkName,'''')=''' + Trim(FstkName) + '''');
//      ShowMessage(sql.text);
      Open;
    end;

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

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

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

procedure TfrmWarpBeamStkList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

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

procedure TfrmWarpBeamStkList.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 TfrmWarpBeamStkList.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

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

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

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

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

end.

