unit U_ShaKCYJList;

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, cxCheckBox, RM_Common,
  RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, Menus,
  cxCalendar, cxButtonEdit, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmShaKCYJList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column1: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    SPName: TEdit;
    ToolButton2: TToolButton;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    Label1: TLabel;
    v1Column1: TcxGridDBColumn;
    CZStr: TComboBox;
    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 MPRTCodeNameChange(Sender: TObject);
    procedure SXBatchNOChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CZStrChange(Sender: TObject);
    procedure v1Column1CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmShaKCYJList: TfrmShaKCYJList;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmShaKCYJList.FormDestroy(Sender: TObject);
begin
  frmShaKCYJList:=nil;
end;

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

procedure TfrmShaKCYJList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' exec P_SXKC_YuJing ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmShaKCYJList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmShaKCYJList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption,Tv1,'纱线仓库');
  Close;
end;

procedure TfrmShaKCYJList.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption,Tv1,'纱线仓库');
  //InitGrid();
end;

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

procedure TfrmShaKCYJList.SXBatchNOChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmShaKCYJList.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmShaKCYJList.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  TcxGridToExcel(Self.Caption,cxGrid2);
end;

procedure TfrmShaKCYJList.CZStrChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmShaKCYJList.v1Column1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id:Integer;
begin
  Id:=TV1.GetColumnByFieldName('CZStr').Index;//;-TV1.GroupedItemCount;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[Id]='' then Exit;
  if AViewInfo.GridRecord.Values[Id]='不足' then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
end;


end.
