unit U_PBKCListSel;

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, Menus, cxCheckBox, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel,
  dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue;

type
  TfrmPBKCListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    C_CodeName: TEdit;
    C_Code: TEdit;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    ConNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    v1Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column2: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    v1Column14: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    v1Column10: TcxGridDBColumn;
    Label1: TLabel;
    carno: TEdit;
    cv1Column13: TcxGridDBColumn;
    lbl1: TLabel;
    apbatchno: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Label2: TLabel;
    khname: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Label15: TLabel;
    jhCheJian: TComboBox;
    Label7: TLabel;
    KuWei: 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 C_CodeNameChange(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure jhCheJianChange(Sender: TObject);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FMainid, FSubId, FConNo, FColor, FCodeName, FCKOrdNo, FCarNoHZ: string;
  end;

var
  frmPBKCListSel: TfrmPBKCListSel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmPBKCListSel.FormDestroy(Sender: TObject);
begin
  frmPBKCListSel := nil;
end;

procedure TfrmPBKCListSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

procedure TfrmPBKCListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('select AA.KCKgQty,B.ConNo,b.khname,C.C_CodeName,C.C_Code,C.C_Color,C.C_Spec,D.APXH,AA.CRID ');
      SQL.Add(' ,B.Filler,D.ClothType,AA.MJID,C.MFQty,C.KZQty,D.MJStr3,D.CDQK,D.carno,D.APBATCHNO,RKPerson=A.Filler ');
      SQL.Add(' ,A.KUWEI ,jhchejian,WFGYSNameJC=(select WFGYSNameJC from cloth_WJG WJG where RTrim(WJG.JGID)=isnull(A.JGID,''''))');
      SQL.Add(' from CK_PBCP_KC AA  ');
      SQL.Add(' inner join  CK_PBCP_CR A on AA.CRID=A.CRID and A.CRFlag=''入库''    ');
      SQL.Add(' inner join Cloth_Main B on A.MainId=B.MainId  ');
      SQL.Add(' inner join Cloth_Sub C on A.MainId=C.MainId ');
      SQL.Add(' inner join WFB_MJJY_PB D on AA.MJId=D.MJId  ');
      SQL.Add(' where  kckgqty>0 ');
//      SQL.Add(' and exists( select E.* from FHSQ_MAIN E where ');
//      SQL.Add(' isnull(E.PrtCode,'''')=isnull(C.C_Code,'''') ');
      if TRIM(FCarNoHZ) <> '' then
      begin
        SQL.Add(' and ' + Quotedstr(FCarNoHZ) + ' like ''%''+D.carno +''%''');
      end;
      if TRIM(jhCheJian.Text) <> '' then
      begin
        SQL.Add(' and  jhchejian=' + QuotedStr(Trim(jhCheJian.Text)));
      end;

      if Trim(C_CodeName.Text) <> '' then
      begin
        SQL.Add(' and C.C_CodeName like ' + QuotedStr('%' + Trim(C_CodeName.Text) + '%'));
      end; 
//      SQL.Add(' and E.FSID=' + quotedstr(FCKOrdNo) + ')');
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmPBKCListSel.TBRafreshClick(Sender: TObject);
begin
 // BegDate.SetFocus;
  ToolBar1.SetFocus;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible := False;
end;

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

procedure TfrmPBKCListSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('仓库库存列表PB', Tv1, '坯布仓库');
  Close;
end;

procedure TfrmPBKCListSel.FormShow(Sender: TObject);
begin

  ReadCxGrid('仓库库存列表PB', Tv1, '坯布仓库');

  InitGrid();
  TBFind.Click();
end;

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

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

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

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

procedure TfrmPBKCListSel.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked = True then
  begin
    ConNo.Tag := 1;
  end
  else
  begin
    ConNo.Tag := 2;
  end;
  TBFind.Click;
end;

procedure TfrmPBKCListSel.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmPBKCListSel.jhCheJianChange(Sender: TObject);
begin
  TBRafresh.Click();
end;

end.

