unit U_WBNeedHTList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView, Clipbrd,
  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, cxGroupBox;

type
  TfrmWBNeedHTList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    GPM_1: TcxGridPopupMenu;
    PM_1: TPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    C_Name: TcxTextEdit;
    ConNo: TcxTextEdit;
    ToolButton2: TToolButton;
    Panel2: TPanel;
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    TV1ConNo: TcxGridDBColumn;
    TV1C_Code: TcxGridDBColumn;
    TV1C_Name: TcxGridDBColumn;
    TV1C_Composition: TcxGridDBColumn;
    TV1YarnZS: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    CDS_1: TClientDataSet;
    TV1Density: TcxGridDBColumn;
    TV1C_Width: TcxGridDBColumn;
    N1: TMenuItem;
    ToolButton1: TToolButton;
    TV1OrdQty: TcxGridDBColumn;
    TV1WB_Code: TcxGridDBColumn;
    TV1WB_Name: TcxGridDBColumn;
    TV1WB_YarnQty: TcxGridDBColumn;
    TV1WB_ReedNo: TcxGridDBColumn;
    TV1WB_Width: TcxGridDBColumn;
    TV1KCQTY: TcxGridDBColumn;
    TV1ArrangeQTY: TcxGridDBColumn;
    TV1ConUnit: 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);
    procedure N1Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    canshu1, FStkName, canshu3: string;
    procedure InitGrid();
    { Private declarations }
  public
    FWB_Code: string;
    { Public declarations }
  end;

var
  frmWBNeedHTList: TfrmWBNeedHTList;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmWBNeedHTList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmWBNeedHTList := nil;
end;

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

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

procedure TfrmWBNeedHTList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.ConNo, C_Name, C_Code ');
      sql.Add(' ,C_Width');
      sql.Add(',C_Composition, Density ');
      sql.Add(', YarnZS');
      sql.Add(',sum(A.OrdQty) as OrdQty,sum(A.ConQty) as ConQty,ConUnit,WB_Code');
      sql.Add(', WB_Name, WB_YarnQty');
      sql.Add(', WB_ReedNo, WB_Width');
      sql.Add(',sum(A.KCQTY) as KCQTY');
      sql.Add(',sum(A.ArrangeQTY) as ArrangeQTY');
      SQL.ADD('from V_WBNeedHTLook A ');
//      SQL.Add('WHERE WB_Code=' + QuotedStr(FWB_Code));
      SQL.Add('group BY ConNo,C_Name,C_Code,C_Width,C_Composition,Density');
      SQL.Add(',YarnZS,WB_Code,WB_Name,WB_YarnQty,WB_ReedNo,WB_Width,ConUnit');
//      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_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWBNeedHTList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();

end;

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

procedure TfrmWBNeedHTList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmWBNeedHTList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '经轴需求合同');
  InitGrid();
end;

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

procedure TfrmWBNeedHTList.N1Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

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

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

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

procedure TfrmWBNeedHTList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel(self.Caption, cxGrid1);
end;

procedure TfrmWBNeedHTList.ToolButton2Click(Sender: TObject);
begin

  WriteCxGrid(trim(Self.Caption), Tv1, '经轴需求合同');
end;

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

end.

