unit U_CKProductBCPKCHZList;

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, MovePanel, cxButtonEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmCKProductBCPKCHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    PRTCodeName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    orderNo: TEdit;
    Label6: TLabel;
    SOrddefstr1: TEdit;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label8: TLabel;
    PRTKZ: TEdit;
    Label9: TLabel;
    PRTMF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    v1Column3: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    YWY: TEdit;
    OrdPerson1: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    PRTColor: TComboBox;
    Panel4: TPanel;
    Label13: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure PRTCodeNameChange(Sender: TObject);
    procedure v1Column5PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure PRTColorChange(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image2Click(Sender: TObject);
  private
       FLeft,FTop:Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCKProductBCPKCHZList: TfrmCKProductBCPKCHZList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}

procedure TfrmCKProductBCPKCHZList.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPKCHZList:=nil;
end;

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

procedure TfrmCKProductBCPKCHZList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCKProductBCPKCHZList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select YWY=B.OrdPerson2,B.OrdPerson1,C.SOrdDefStr10,C.SubId,A.* ,B.OrdDefStr1,B.OrderNo,C.PRTCodeName,C.PRTColor,C.PRTMF,C.PRTKZ ');
      sql.Add(',C.SOrddefstr1,C.PRTHX');
      sql.Add(' from(select sum(KCQty) KCQty,Sum(KCKgQty) KCKgQty,count(*) JQty,AA.MainId,AA.SubId,AA.CPType,KC.KCQtyUnit ');
      sql.Add(' from CK_BanCP_KC KC inner join CK_BanCP_CR AA on KC.CRID=AA.CRID and AA.CRType=''检验入库''');
      sql.Add(' where (KC.KCQty>0 or KC.KCKgQty>0) group by AA.MainId,AA.SubId,AA.CPType,KC.KCQtyUnit ) A');
      Sql.add(' inner join JYOrder_Main B on A.MainId=B.MainId');
      Sql.add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
     { if Trim(DParameters1)<>'高权限' then
      begin
        sql.Add(' where B.Filler='''+Trim(DName)+'''');
      end else
      begin
      end;   }
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCKProductBCPKCHZList.TBRafreshClick(Sender: TObject);
begin
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

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

procedure TfrmCKProductBCPKCHZList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('仓库库存汇总列表',Tv1,'成品仓库');
  Close;
end;

procedure TfrmCKProductBCPKCHZList.FormShow(Sender: TObject);
begin

  ReadCxGrid('仓库库存汇总列表',Tv1,'成品仓库');
  if Trim(DParameters2)='管理' then
  begin
    v1Column5.Options.Focusing:=True;
  end else
  begin
    v1Column5.Options.Focusing:=False;
  end;
  //InitGrid();
end;

procedure TfrmCKProductBCPKCHZList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('库存汇总列表',cxGrid2);
end;

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

procedure TfrmCKProductBCPKCHZList.v1Column5PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SOrdDefStr10';
      flagname:='库存存放地点';
      if ShowModal=1 then
      begin
        with CDS_Main do
        begin
          Edit;
          FieldByName('SOrdDefStr10').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update JYOrder_Sub Set SOrdDefStr10='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          sql.Add(' where SubId='''+Trim(Self.CDS_Main.fieldbyname('SubId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCKProductBCPKCHZList.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPKCHZList.Tv1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_Main.IsEmpty=False then
  begin
    InitOrderColor(Trim(CDS_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
    //InitBCGangNo(Trim(CDS_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmCKProductBCPKCHZList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  Panel4.Left:=FLeft;
  Panel4.Top:=FTop+110;
  Panel4.Visible:=True;
  Panel4.Refresh;
  Panel10.Caption:=Trim(TV1.Controller.FocusedColumn.Caption);
  RichEdit1.Text:=CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmCKProductBCPKCHZList.Tv1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft:=X;
  FTop:=Y;
end;

procedure TfrmCKProductBCPKCHZList.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

end.
