unit U_JWLcktjlist;

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, Clipbrd,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmJWLcktjlist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column15: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    ToolButton2: TToolButton;
    v1Column17: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    Panel1: TPanel;
    CheckBox1: TCheckBox;
    Tv1Column1: TcxGridDBColumn;
    Label1: TLabel;
    SPHX: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Label6: TLabel;
    orderno: TEdit;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Label2: TLabel;
    SPName: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SXBatchNOChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FDYFlag: string;
    { Public declarations }
  end;

var
  frmJWLcktjlist: TfrmJWLcktjlist;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmJWLcktjlist.FormDestroy(Sender: TObject);
begin
  frmJWLcktjlist := nil;
end;

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

procedure TfrmJWLcktjlist.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_JWLCKTJLIST');
      sql.add(' @BEGDATE=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' ,@ENDDATE=''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');

//      sql.Add(' select A.* ,CKQty=isnull(Qty,0)-isnull(MXKCQty,0),CKPiQty=isnull(PiQty,0)-isnull(MXKCPiQty,0)');
//      sql.Add(' ,CKZHS=(SELECT SUM(ZHS) FROM CK_SXPB_CR B WHERE B.FZSPID=A.SPID AND CRFLAG=''出库'' )');
//      sql.Add(' ,JSMoney=price*Qty ');
//      sql.Add(' from CK_SXPB_CR A where isnull(CKName,'''')=''机物料'' ');
//      SQL.Add(' and A.CRFlag=''入库'' and ZFFlag=0 ');
//      if CheckBox1.Checked = false then
//      begin
//        SQL.Add('  and MXKCQty>0  ');
//      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmJWLcktjlist.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('机物料库存列表', Tv1, '机物料仓库7');
  Close;
end;

procedure TfrmJWLcktjlist.FormShow(Sender: TObject);
begin
  ReadCxGrid('机物料库存列表', Tv1, '机物料仓库7');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 30;
  if FDYFlag = '99' then
  begin
    InitGrid();
    TBFind.Click;
  end;
end;

procedure TfrmJWLcktjlist.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

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

procedure TfrmJWLcktjlist.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmJWLcktjlist.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

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

procedure TfrmJWLcktjlist.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJWLcktjlist.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  TcxGridToExcel(Self.Caption, cxGrid2);
end;

procedure TfrmJWLcktjlist.Tv1DblClick(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

end.

