unit U_DJBCKKCList_HTSH;

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;

type
  TfrmDJBCKKCList_HTSH = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2MPRTCode: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v2DDQty3: TcxGridDBColumn;
    v1DDQty5: TcxGridDBColumn;
    v1HCQty: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    PRTCodeName: TEdit;
    PRTCode: TEdit;
    prtspec: TEdit;
    v1PRTColorNo: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1PRTHX: TcxGridDBColumn;
    Label9: TLabel;
    ConNo: TEdit;
    Label10: TLabel;
    PRTColor: TEdit;
    Label11: TLabel;
    StyleNo: TEdit;
    Label13: TLabel;
    PRTHX: TEdit;
    ToolButton2: TToolButton;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1ConNo: TcxGridDBColumn;
    v1PRTCodeName: TcxGridDBColumn;
    v1PRTColorEng: TcxGridDBColumn;
    v1BL3: TcxGridDBColumn;
    v1StyleNo: TcxGridDBColumn;
    v1BL5: TcxGridDBColumn;
    Label5: TLabel;
    prtmf: TEdit;
    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 PRTCodeChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton2Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    canshu1:string;
    { Public declarations }
  end;

var
  frmDJBCKKCList_HTSH: TfrmDJBCKKCList_HTSH;

implementation
uses
  U_DataLink,U_RTFun,U_SXCKInPut;

{$R *.dfm}

procedure TfrmDJBCKKCList_HTSH.FormDestroy(Sender: TObject);
begin
  frmDJBCKKCList_HTSH:=nil;
end;

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

procedure TfrmDJBCKKCList_HTSH.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select AA.*,BL3=(CKQty-DDQty3),BL5=(CKQty-DDQty5) ');
      sql.add(' from (select A.*,B.StyleNo,B.PrtCode,B.PrtCodeName,B.PRTspec,B.SOrdDefStr4,B.PRTColorNo,B.PRTHX,B.PRTColor,B.PRTOrderQty,B.PRTMF,B.PRTKZ,B.OrderUnit, ');
      sql.add(' DDQty3=(B.PRTOrderQty*1.03),DDQty5=(B.PRTOrderQty*1.05),');
      sql.add(' CKQty=(select Sum(D.MJQty4) from CK_BanCP_CR C inner join WFB_MJJY D on D.MJID=C.MJID ');
      sql.add(' where D.ConID=B.SubId and C.CRFlag=''出库'') ');
      sql.Add(' from JYOrderCon_Main A ');
      sql.add(' inner join JYOrderCon_Sub B on B.Mainid=A.Mainid ');
      sql.add(' where A.OrdDate>='''+trim(formatdatetime('yyyy-MM-dd',begdate.DateTime))+''' ');
      sql.Add(' and A.OrdDate<'''+trim(formatdatetime('yyyy-MM-dd',EndDate.DateTime+1))+''' ');
      if trim(canshu1)<>'高权限' then
      sql.add(' and (A.FillerCode='''+Trim(DCode)+''' or A.KeFu='''+Trim(DName)+''' or A.ConPerson1='''+Trim(DName)+''') ');
      sql.add(') AA');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmDJBCKKCList_HTSH.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('坯布损耗',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDJBCKKCList_HTSH.FormShow(Sender: TObject);
begin
  ReadCxGrid('坯布损耗',Tv1,'待检布仓库');
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-30;
  canshu1:=trim(DParameters1);
  InitGrid();
end;

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

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

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

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

procedure TfrmDJBCKKCList_HTSH.PRTCodeChange(Sender: TObject);
begin
  TBFind.Click;
end;

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

procedure TfrmDJBCKKCList_HTSH.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('待检布库存',cxGrid2);
end;

end.
