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

type
  TfrmCKProductBCPKCHZListPB = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    C_CodeName: TEdit;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    ConNo: TEdit;
    v1Column6: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    Label1: TLabel;
    C_Code: TEdit;
    v1Column7: TcxGridDBColumn;
    CheckBox1: TCheckBox;
    cv1Column5: TcxGridDBColumn;
    lbl1: TLabel;
    jhchejian: TComboBox;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label4: TLabel;
    Label7: TLabel;
    KHNAME: TEdit;
    C_SPEC: TEdit;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    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 TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure CheckBox1Click(Sender: TObject);
    procedure jhchejianChange(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    CANSHU1: string;
  end;

var
  frmCKProductBCPKCHZListPB: TfrmCKProductBCPKCHZListPB;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_JYMXInfo, U_PBOuGLtListsel;

{$R *.dfm}

procedure TfrmCKProductBCPKCHZListPB.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPKCHZListPB := nil;
end;

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

procedure TfrmCKProductBCPKCHZListPB.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

//      sql.Add('select A.* ,SYQTY=(C.C_QTY-(SELECT SUM(MJMaoZ) FROM WFB_MJJY_PB  G WHERE G.MAINID=A.MAINID GROUP BY G.MAINID )),C.BatchNoHZ,piqty=ISNULL(piqty,0),C.C_CodeName,C.C_Code,C.C_Color,C.ZhenCun,C.MF,C.KZ,C.C_Spec,C.KaiFu');
//      SQL.Add(',SYPS=(C.PIQTY-(SELECT COUNT(MJID) FROM WFB_MJJY_PB  G WHERE G.MAINID=A.MAINID GROUP BY G.MAINID ))');
//      SQL.Add(',jyps=(SELECT COUNT(MJID) FROM WFB_MJJY_PB  G WHERE G.MAINID=A.MAINID GROUP BY G.MAINID )');
//      sql.Add(' ,CM.ConNo,CM.KHName');
//
//      sql.Add(' from(select  Sum(KCKgQty) KCKgQty,count(*) JQty,PB.MainId,PB.SubId ');
//      sql.Add(' from CK_PBCP_KC KC ');
//      sql.Add(' inner join  CK_PBCP_CR A on KC.CRID=A.CRID and A.CRFlag=''入库'' ');
//      sql.Add(' inner join WFB_MJJY_PB PB on KC.MJID=PB.MJID ');
//      sql.Add(' where  KC.KCKGQty>0 group by PB.MainId,PB.SubId ) A');
//      Sql.add(' inner join Cloth_Sub C on A.MainId=C.MainId');
//      sql.Add(' inner join Cloth_Main CM on CM.MainId=C.MainId ');
      SQL.Add('EXEC P_View_PBHZCK');
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

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

procedure TfrmCKProductBCPKCHZListPB.FormShow(Sender: TObject);
begin
 
  ReadCxGrid('仓库库存汇总列表PB', Tv1, '坯布仓库');
  //InitGrid();
end;

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

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

procedure TfrmCKProductBCPKCHZListPB.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 TfrmCKProductBCPKCHZListPB.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmJYMXInfo := TfrmJYMXInfo.Create(Application);
    with frmJYMXInfo do
    begin
      FFMainId := Trim(self.CDS_Main.fieldbyname('MainId').AsString);
//      FFClothType:=Trim(self.CDS_Main.fieldbyname('ClothType').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmJYMXInfo.Free;
  end;
end;

procedure TfrmCKProductBCPKCHZListPB.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmCKProductBCPKCHZListPB.jhchejianChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPKCHZListPB.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  F1, F2: Double;
begin
  F1 := StrToFloatDef((AViewInfo.GridRecord.Values[Tv1Column5.Index]), 0);
  F2 := StrToFloatDef((AViewInfo.GridRecord.Values[Tv1Column6.Index]), 0);
  if F2 >= F1 * 0.8 then
  begin
    ACanvas.Brush.Color := clRed;
  end;
end;

procedure TfrmCKProductBCPKCHZListPB.ToolButton1Click(Sender: TObject);
begin
  try
    frmPBKCsel := TfrmPBKCsel.Create(Application);
    with frmPBKCsel do
    begin
      canshu1 := self.canshu1;
      ConNo.Text := Self.CDS_Main.FIELDBYNAME('CONNO').AsString;
      if ShowModal = 1 then
      begin
        initgrid();
      end;
    end;
  finally
    frmPBKCsel.Free;
  end;
end;

end.

