unit U_FinishedClothKCHZList;

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

type
  TfrmFinishedClothKCHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    MovePanel2: TMovePanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    Label5: TLabel;
    Label12: TLabel;
    P_CodeName: TEdit;
    P_Code: TEdit;
    tbOK: TToolButton;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Sel: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxgrdPS: TcxGridDBColumn;
    cxgrdMJLen: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure tbOKClick(Sender: TObject);
    procedure ordernoChange(Sender: TObject);
    procedure P_CodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    { Public declarations }
    FMainid, FSubId, FConNo, FColor, FCodeName: string;
    canshu1: string;
  end;

implementation

uses
  U_DataLink, U_Fun, U_SysLogHelp;

{$R *.dfm}
procedure TfrmFinishedClothKCHZList.SetStatus();
var
  i: Integer;
begin

//
//  case cxTabControl1.TabIndex of
//    0:
//      begin
//        ClearOrHideControls(Panel1, '0', True, True);
//        ClearOrHideControls(Panel1, '1', True, False);
//
//        for i := 0 to tv1.ColumnCount - 1 do
//        begin
//          tv1.Columns[i].Visible := false;
//        end;
//        IsVisibleTV(Panel1, TV1, '0', True);
//        cxgrdPS.Visible := True;
//        cxgrdMJLen.Visible := True;
//        cxgrdCKPS.Visible := True;
//        cxgrdConNoPS.Visible := True;
//        cxgrdWFPS.Visible := True;
//        Tv1Column9.Visible := True;
//        Tv1Column4.Visible := True;
//        Tv1Column10.Visible := True;
//        Tv1Column11.Visible := True;
//        Tv1Column13.Visible := True;
//        Tv1Column12.Visible := True;
////        Tv1Column5.Visible := True;
////        Tv1Column6.Visible := True;
//      end;
//
//    1:
//      begin
//        for i := 0 to tv1.ColumnCount - 1 do
//        begin
//          tv1.Columns[i].Visible := True;
//        end;
//        cxgrdPS.Visible := false;
//        cxgrdCKPS.Visible := false;
//        cxgrdConNoPS.Visible := false;
//        cxgrdWFPS.Visible := false;
//        Tv1Column9.Visible := false;
//        Tv1Column11.Visible := false;
//        ClearOrHideControls(Panel1, '0', False, True);
//        ClearOrHideControls(Panel1, '1', False, True);
//        Panel6.Visible := True;
//      end;
//  end;
end;

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

procedure TfrmFinishedClothKCHZList.InitGrid();
var
  fwhere, Pwhere, fFSId: string;
  Fwfps: Double;
begin
  Pwhere := SGetFilters(Panel1, 1, 2);
  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' and ' + trim(Pwhere);
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      sql.Add('exec P_CPCK_Get_KCHZ1 ');
      sql.Add('@WSql=' + quotedstr(fwhere));
 
//      showmessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);

  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmFinishedClothKCHZList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv1, '成品仓库');
  Close;
end;

procedure TfrmFinishedClothKCHZList.FormShow(Sender: TObject);
var
  fsj: string;
begin
  CurrentPage := 1;
  RecordsNumber := 500;

  fsj := 'select distinct Code=Null,Name=CRType from FinishedCloth_CR where CRFlag=''入库'' order by CRType ';
//  SInitComBoxBySql(ADOQueryTemp, CRType, False, fsj);
  ReadCxGrid(self.Caption, Tv1, '成品仓库');
  SetStatus();
  InitGrid();
end;

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

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

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

procedure TfrmFinishedClothKCHZList.ToolButton1Click(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmFinishedClothKCHZList.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmFinishedClothKCHZList.BTNPClick(Sender: TObject);
begin
  if CurrentPage < CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmFinishedClothKCHZList.Tv1DblClick(Sender: TObject);
var
  Tabint: integer;
begin
//  Tabint := cxTabControl1.TabIndex;
//  case Tabint of
//    0:
//      begin
//        AssignmentControls(Panel1, CDS_Main, '0');
//        cxTabControl1.TabIndex := 1;
//      end;
//  end;
end;

procedure TfrmFinishedClothKCHZList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

procedure TfrmFinishedClothKCHZList.TCBNORChange(Sender: TObject);
begin
//  RecordsNumber := StrToInt(TCBNOR.Text);
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmFinishedClothKCHZList.tbOKClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  ModalResult := 1;
end;

procedure TfrmFinishedClothKCHZList.ordernoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, cds_Main);
  SInitCDSData20(ADOQueryMain, cds_Main);
end;

procedure TfrmFinishedClothKCHZList.P_CodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmFinishedClothKCHZList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
//  case cxTabControl1.TabIndex of
//    1:
//      begin
//        if (AViewInfo.GridRecord.Values[v1Column7.Index] = '次品') then
//        begin
//          ACanvas.Brush.Color := $008080FF
//        end;
//      end;
//  end;

end;

end.

