unit U_ZDPriceDetails;

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, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, cxPC, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
  U_BaseHelp, Vcl.Menus, Vcl.Clipbrd, DateUtils, dxSkinWXI,
  dxScrollbarAnnotations, U_BaseList, System.ImageList, Vcl.ImgList;

type
  TfrmZDPriceDetails = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    ADOQueryPrint: TADOQuery;
    ToolButton1: TToolButton;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridDBColumn26: TcxGridDBColumn;
    cxGridDBColumn27: TcxGridDBColumn;
    cxGridDBColumn28: TcxGridDBColumn;
    cxGridDBColumn29: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    TV4Column1: TcxGridDBColumn;
    TV4Column2: TcxGridDBColumn;
    TV4Column3: TcxGridDBColumn;
    TV4Column4: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    Tv5: TcxGridDBTableView;
    Tv5Column1: TcxGridDBColumn;
    Tv5Column2: TcxGridDBColumn;
    Tv5Column3: TcxGridDBColumn;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    Tv5Column4: TcxGridDBColumn;
    Tv5Column5: TcxGridDBColumn;
    Tv5Column6: TcxGridDBColumn;
    Tv5Column7: TcxGridDBColumn;
    Tv5Column8: TcxGridDBColumn;
    Tv5Column9: TcxGridDBColumn;
    Tv5Column10: TcxGridDBColumn;
    Tv5Column11: TcxGridDBColumn;
    Tv5Column12: TcxGridDBColumn;
    Tv5Column13: TcxGridDBColumn;
    Tv5Column14: TcxGridDBColumn;
    Tv5Column15: TcxGridDBColumn;
    Tv5Column16: TcxGridDBColumn;
    Tv5Column17: TcxGridDBColumn;
    Tv5Column18: TcxGridDBColumn;
    Tv5Column19: TcxGridDBColumn;
    Tv5Column20: TcxGridDBColumn;
    Tv5Column21: TcxGridDBColumn;
    Tv5Column22: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    FBCIOID, FStkId: string;
    FType: Integer;
    { Public declarations }
  end;

var
  frmZDPriceDetails: TfrmZDPriceDetails;

implementation

uses
  U_DataLink, U_RtFun;


{$R *.dfm}

procedure TfrmZDPriceDetails.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      case FType of
        0:
          begin
            sql.Add('Select * from bs_cloth_io where BCIOID in (' + FBCIOID + ')' );
            Open;
            SCreateCDS(ADOQueryMain, CDS_1);
            SInitCDSData(ADOQueryMain, CDS_1);
            cxGrid4.ActiveLevel := cxGridLevel4;
          end;
        1:
          begin
            sql.Add('Select *, A.OrderNo as ToOrdNo, B.OrderNo as FromOrdNo, DlyDate = (select DlyDate from Trade_Cloth_DR_Main X where X.DRMID = B.DRMID) from Trade_Cloth_Stock_ZD A join Trade_Cloth_DR_Sub B on A.DRSID=B.DRSID where StkId in (' + FStkId + ')' );
            Open;
            SCreateCDS(ADOQueryMain, CDS_2);
            SInitCDSData(ADOQueryMain, CDS_2);
            cxGrid4.ActiveLevel := cxGridLevel5;
          end;
      end;

    end;


  finally
    ADOQueryMain.EnableControls;
  end;
end;


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

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

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

procedure TfrmZDPriceDetails.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(self.Caption), Tv4, '转单价格信息明细');
  InitGrid();
end;

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

procedure TfrmZDPriceDetails.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv4, '转单价格信息明细');
end;

end.

