unit U_SQKCHZSelList;

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, cxCheckBox, cxPC, Math, cxCalendar,
  Menus;

type
  TfrmSQKCHZSelList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    MovePanel2: TMovePanel;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    Label3: TLabel;
    Label5: TLabel;
    Label13: TLabel;
    MPRTCodeName: TEdit;
    ConNo: TEdit;
    PRTColor: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxgrdSSel: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxgrdMJGW: TcxGridDBColumn;
    cxgrdMJNW: TcxGridDBColumn;
    cxgrdMJLen: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    cxgrdPS: TcxGridDBColumn;
    Label6: TLabel;
    gangNo: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    VC_YWY: TcxGridDBColumn;
    Panel2: TPanel;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    cxTabControl1: TcxTabControl;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    VC_lidan: TcxGridDBColumn;
    v1XS: TcxGridDBColumn;
    v1JYF: 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 ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
  private
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    { Public declarations }
    FKCStatus, FKCLevel, FYWY: string;
  end;

var
  frmSQKCHZSelList: TfrmSQKCHZSelList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp,U_RTFun;

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

  case cxTabControl1.TabIndex of
    4:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := false;
        end;
        ClearOrHideControls(Panel1, '0', True, True);
        ClearOrHideControls(Panel1, '1', True, False);
        ClearOrHideControls(Panel1, '2', True, False);
        ClearOrHideControls(Panel1, '3', True, False);
        ClearOrHideControls(Panel1, '4', True, False);
        IsVisibleTV(Panel1, TV1, '0', True);
      end;
    0:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := false;
        end;
        ClearOrHideControls(Panel1, '0', False, True);
        ClearOrHideControls(Panel1, '1', False, True);
        ClearOrHideControls(Panel1, '2', True, False);
        ClearOrHideControls(Panel1, '3', True, False);
        ClearOrHideControls(Panel1, '4', True, False);
        IsVisibleTV(Panel1, TV1, '0', True);
        IsVisibleTV(Panel1, TV1, '1', True);
        VC_lidan.Visible := True;
        VC_YWY.Visible := True;
      end;
    1:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := false;
        end;
        ClearOrHideControls(Panel1, '0', False, True);
        ClearOrHideControls(Panel1, '1', False, True);
        ClearOrHideControls(Panel1, '2', False, True);
        ClearOrHideControls(Panel1, '3', True, False);
        ClearOrHideControls(Panel1, '4', True, False);
        IsVisibleTV(Panel1, TV1, '0', True);
        IsVisibleTV(Panel1, TV1, '1', True);
        IsVisibleTV(Panel1, TV1, '2', True);
        VC_lidan.Visible := True;
        VC_YWY.Visible := True;
      end;
    2:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := True;
        end;
        ClearOrHideControls(Panel1, '0', False, True);
        ClearOrHideControls(Panel1, '1', False, True);
        ClearOrHideControls(Panel1, '2', False, True);
        ClearOrHideControls(Panel1, '3', False, True);
        ClearOrHideControls(Panel1, '4', True, False);
        IsVisibleTV(Panel1, TV1, '0', True);
        IsVisibleTV(Panel1, TV1, '1', True);
        IsVisibleTV(Panel1, TV1, '2', True);
        IsVisibleTV(Panel1, TV1, '3', True);
        VC_lidan.Visible := True;
        VC_YWY.Visible := True;
      end;
    3:
      begin
        for i := 0 to tv1.ColumnCount - 1 do
        begin
          tv1.Columns[i].Visible := True;
        end;
        ClearOrHideControls(Panel1, '0', False, True);
        ClearOrHideControls(Panel1, '1', False, True);
        ClearOrHideControls(Panel1, '2', False, True);
        ClearOrHideControls(Panel1, '3', False, True);
        ClearOrHideControls(Panel1, '4', False, True);
        VC_lidan.Visible := True;
        VC_YWY.Visible := True;
      end;
  end;
  cxgrdPS.Visible := true;
  cxgrdMJGW.Visible := true;
  cxgrdMJNW.Visible := true;
  cxgrdMJLen.Visible := true;
  cxgrdSSel.Visible := true;
  v1XS.Visible:=True;
  v1JYF.Visible:=True;
end;

procedure TfrmSQKCHZSelList.FormDestroy(Sender: TObject);
begin
  frmSQKCHZSelList := nil;
end;

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

procedure TfrmSQKCHZSelList.InitGrid();
var
  Pwhere: string;
begin
  Pwhere := '';
  if SGetFilters(Panel1, 1, 2) <> '' then
    Pwhere := Pwhere + ' and ' + SGetFilters(Panel1, 1, 2);
  if FYWY <> '' then
    Pwhere := Pwhere + ' and YWY=' + quotedstr(Trim(FYWY));
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      case cxTabControl1.TabIndex of
        4:   /////////////////////////品名//////////////////////////////
          begin
            sql.Add('exec P_DB_KCSel ');
            sql.Add('@KCStatus=' + quotedstr(FKCStatus));
            sql.Add(',@KCLevel=' + quotedstr('品名'));
            sql.Add(',@criteria= ' + quotedstr(Pwhere));
          end;
        0:   //////////////////////////订单/////////////////////////////
          begin
            sql.Add('exec P_DB_KCSel ');
            sql.Add('@KCStatus=' + quotedstr(FKCStatus));
            sql.Add(',@KCLevel=' + quotedstr('订单'));
            sql.Add(',@criteria= ' + quotedstr(Pwhere));
          end;
        1:   /////////////////////////颜色//////////////////////////////
          begin
            sql.Add('exec P_DB_KCSel ');
            sql.Add('@KCStatus=' + quotedstr(FKCStatus));
            sql.Add(',@KCLevel=' + quotedstr('颜色'));
            sql.Add(',@criteria= ' + quotedstr(Pwhere));
          end;
        2:   /////////////////////////缸号//////////////////////////////
          begin
            sql.Add('exec P_DB_KCSel ');
            sql.Add('@KCStatus=' + quotedstr(FKCStatus));
            sql.Add(',@KCLevel=' + quotedstr('缸号'));
            sql.Add(',@criteria= ' + quotedstr(Pwhere));
          end;
        3:   /////////////////////////明细//////////////////////////////
          begin
            sql.Add('exec P_DB_KCSel ');
            sql.Add('@KCStatus=' + quotedstr(FKCStatus));
            sql.Add(',@KCLevel=' + quotedstr('明细'));
            sql.Add(',@criteria= ' + quotedstr(Pwhere));
          end;
      end;
//      showmessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
//    if cxTabControl1.TabIndex = 4 then
//      LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSQKCHZSelList.TBRafreshClick(Sender: TObject);
begin
  //BegDate.SetFocus;
  {if Trim(MPRTCodeName.Text)='' then
  begin
    Application.MessageBox('品名不能为空，可模糊查询，不用输入精确品名。','提示',0);
    Exit;
  end; }
  MovePanel2.Visible := True;
  MovePanel2.Refresh;

  InitGrid();
  MovePanel2.Visible := False;
end;

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

procedure TfrmSQKCHZSelList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('发货申请专用', Tv1, '坯布仓库');
  Close;
end;

procedure TfrmSQKCHZSelList.FormShow(Sender: TObject);
begin
  ReadCxGrid('发货申请专用', Tv1, '坯布仓库');
  CurrentPage := 1;
  RecordsNumber := 500;
  SetStatus();
//  InitGrid();
end;

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

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

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

procedure TfrmSQKCHZSelList.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

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

procedure TfrmSQKCHZSelList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, false);
end;

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

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

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

end.

