unit U_TatClothInspHZList2;

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, MovePanel, Math, Clipbrd,
  U_BaseInput, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxTextEdit,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, cxPC, System.StrUtils, dxScrollbarAnnotations, cxCurrencyEdit,
  System.ImageList, Vcl.ImgList;

type
  TfrmTatClothInspHZList2 = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    GPM_1: TcxGridPopupMenu;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_1: TClientDataSet;
    begtime: TDateTimePicker;
    endTime: TDateTimePicker;
    IsJYTime: TCheckBox;
    ToolButton4: TToolButton;
    Label5: TLabel;
    C_Name: TEdit;
    PM_1: TPopupMenu;
    PM11: TMenuItem;
    N1: TMenuItem;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column22: TcxGridDBColumn;
    Tv1C_Name: TcxGridDBColumn;
    Tv1DXMF: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1PCID: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Tv1dxmeter: TcxGridDBColumn;
    Tv1Carno: TcxGridDBColumn;
    Tv1qgSL: TcxGridDBColumn;
    Tv1qgMeter: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1fbJS: TcxGridDBColumn;
    Tv1fbqty: TcxGridDBColumn;
    Tv1CIMachNo: TcxGridDBColumn;
    Tv1BCIOID: TcxGridDBColumn;
    Label1: TLabel;
    C_width: TEdit;
    Label3: TLabel;
    pcid: TEdit;
    Label4: TLabel;
    C_GramWeight: TEdit;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1YDpf: TcxGridDBColumn;
    Tv1edpf: TcxGridDBColumn;
    Tv1xjPF: TcxGridDBColumn;
    Tv1cspf: TcxGridDBColumn;
    Tv1fqPF: TcxGridDBColumn;
    Tv1FBPF: TcxGridDBColumn;
    Tv1issp: TcxGridDBColumn;
    N2: TMenuItem;
    N3: TMenuItem;
    Tv1SHMeter: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure orderNoKeyPress(Sender: TObject; var Key: Char);
    procedure BTNPClick(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure JYTypeChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure CDS_1BeforeOpen(DataSet: TDataSet);
    procedure Tv1DataControllerFilterBeforeChange(Sender: TcxDBDataFilterCriteria; ADataSet: TDataSet; const AFilterText: string);

    procedure Tv1TcxGridDBDataControllerTcxDataSummaryFooterSummaryItems6GetText(Sender: TcxDataSummaryItem; const AValue: Variant; AIsFooter: Boolean; var AText: string);
    procedure ToolButton4Click(Sender: TObject);
    procedure PM11Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure IsJYTimeClick(Sender: TObject);
    procedure C_NameKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1PCIDCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1C_NameCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1DXMFCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1dxmeterCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1CarnoCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1CIMachNoCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1BCIOIDCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1qgSLCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1qgMeterCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure Tv1isspCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);

  private
    CurrentPage, RecordsNumber: Integer;
    lstCust: TStringList;
    procedure InitGrid();
    procedure SetStatus();
    procedure CopyColumnSummaryToClipboard(AColumn: TcxGridColumn);
    { Private declarations }
  public
    fC_Name, fissp, fCarno, fpcid: string;
    fEndDateTime,fBegDateTime : TDateTime;

    { Public declarations }
  end;

var
  frmTatClothInspHZList2: TfrmTatClothInspHZList2;

implementation

uses
  U_DataLink, U_RTFun, U_LabelPrint, U_TatInspSHHZ;

{$R *.dfm}

procedure TfrmTatClothInspHZList2.SetStatus();
begin

end;

procedure TfrmTatClothInspHZList2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  FreeAndNil(lstCust);
  Action := caFree;
end;

procedure TfrmTatClothInspHZList2.FormCreate(Sender: TObject);
begin
  inherited;
  lstCust := TStringList.Create;
  EndDate.DateTime := SGetServerDateTime(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 20;
end;

procedure TfrmTatClothInspHZList2.InitGrid();
var
  WSql, WSql1: string;
begin

  WSql := SGetFilters(Panel1, 1, 2);
  if Trim(WSql) <> '' then
    WSql := ' and ' + WSql;
  if IsJYTime.Checked then
  begin
    WSql1 := ' and A.FillTime>=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    WSql1 := WSql1 + ' and A.FillTime<' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end;

  try
    ADOQueryMain.DisableControls;

//    with ADOQueryMain do
//    begin
//      Filtered := False;
//      Close;
//      sql.Clear;
//      sql.Add('select * from ( ');
//      sql.Add('select A.C_NAME, A.C_width,A.C_GramWeight,A.pcid,A.Carno,A.dxmeter,issp=isnull(A.issp,'''')  ');
//      sql.Add(' ,maX(B.C_Width) AS DXMF,A.CIMachNo,A.BCIOID ');
////      sql.Add(' ,CAST(isNull(A.dxmeter,''1'') AS DECIMAL(18,2)) ');
//
////      SQL.Add(' ,qgMeter=sum(meter+SHMeter)/ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) ');
//
//      sql.Add(' ,meterall=(select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )');
//      sql.Add(' ,C_Widthall= ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) ');
//
//      SQL.Add(' ,qgMeter=(select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )/ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) ');
//
////      SQL.Add(' ,qgSL = ROUND((select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )*100 ');
////      sql.Add(' / ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1)/CAST(ISNULL(NULLIF(A.dxmeter, ''''), 1) AS DECIMAL(18,2)) , 2) ');
//
//      SQL.Add(' ,qgSL = ROUND((CAST(ISNULL(NULLIF(A.dxmeter, ''''), 1) AS DECIMAL(18,2)) - (select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid  and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )');
//      SQL.Add(' /ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) )*100 ');
//      sql.Add(' /CAST(ISNULL(NULLIF(A.dxmeter, ''''), 1) AS DECIMAL(18,2)) , 3) ');
//
//      SQL.Add(',SHpf=SUM(CASE WHEN ISNUMERIC(A.SHMETER) = 1 AND ISNUMERIC(A.C_WIDTH) = 1  ');
//      SQL.Add('     THEN CAST(A.SHMETER AS DECIMAL(18,2))/100 * CAST(A.C_WIDTH AS DECIMAL(18,2)) ');
//      SQL.Add('     ELSE 0 END)');
//
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END )AS YDJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''优等品'' THEN A.meter ELSE 0 END )AS Ydqty');
//      SQL.Add(',YDpf=SUM(CASE WHEN A.GRADE=''优等品'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');
//
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END )AS edJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''二等品'' THEN A.meter ELSE 0 END )AS edqty');
//      SQL.Add(',edpf=SUM(CASE WHEN A.GRADE=''二等品'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');
//
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END )AS xjJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''小卷'' THEN A.meter ELSE 0 END )AS xjqty');
//      SQL.Add(',xjpf=SUM(CASE WHEN A.GRADE=''小卷'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');
//
//      SQL.Add(',SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END )AS fbJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''废布'' THEN A.meter ELSE 0 END )AS fbqty');
//      SQL.Add(',fbpf=SUM(CASE WHEN A.GRADE=''废布'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');
//
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END )AS fqJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''分切'' THEN A.meter ELSE 0 END )AS fqqty');
//      SQL.Add(',fqpf=SUM(CASE WHEN A.GRADE=''分切'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');
//
////      SQL.Add(',SUM(CASE WHEN A.GRADE=''循环布'' THEN 1 ELSE 0 END )AS xhJS');
////      SQL.Add(',SUM(CASE WHEN A.GRADE=''循环布'' THEN A.meter ELSE 0 END )AS xhqty');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END )AS csJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''测试'' THEN A.meter ELSE 0 END )AS csqty');
//      SQL.Add(',cspf=SUM(CASE WHEN A.GRADE=''测试'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');
//
//
//     // 添加优等率字段 - 优等卷数/(优等卷数+小卷卷数+二等卷数+测试卷数+分切卷数+废布卷数(排除米数为0的))
//      SQL.Add(',YDRate=CAST(');
//      SQL.Add('    CASE ');
//      SQL.Add('        WHEN (SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');  // YDJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');     // xjJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');   // edJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');     // csJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');     // fqJS
//      SQL.Add('              SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) = 0 '); // fbJS（排除米数为0）
//      SQL.Add('        THEN 0 ');
//      SQL.Add('        ELSE ');
//      SQL.Add('            CAST(SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END)*100 AS DECIMAL(18,4)) / '); // 分子：YDJS
//      SQL.Add('            CAST((SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');                  // YDJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');                     // xjJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');                   // edJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');                     // csJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');                     // fqJS
//      SQL.Add('                  SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) AS DECIMAL(18,4)) '); // fbJS
//      SQL.Add('    END ');
//      SQL.Add('AS DECIMAL(18,4)) ');
//
//      // 添加优等率字段 - 优等卷数/(优等卷数+小卷卷数+二等卷数+测试卷数+分切卷数+废布卷数(排除米数为0的))
//      SQL.Add(',FBRate=CAST(');
//      SQL.Add('    CASE ');
//      SQL.Add('        WHEN (SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');  // YDJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');     // xjJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');   // edJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');     // csJS
//      SQL.Add('              SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');     // fqJS
//      SQL.Add('              SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) = 0 '); // fbJS（排除米数为0）
//      SQL.Add('        THEN 0 ');
//      SQL.Add('        ELSE ');
//      SQL.Add('            CAST(SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)*100 AS DECIMAL(18,4)) / '); // 分子：YDJS
//      SQL.Add('            CAST((SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');                  // YDJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');                     // xjJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');                   // edJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');                     // csJS
//      SQL.Add('                  SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');                     // fqJS
//      SQL.Add('                  SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) AS DECIMAL(18,4)) '); // fbJS
//      SQL.Add('    END ');
//      SQL.Add('AS DECIMAL(18,4)) ');
//
//      SQL.Add('from   Tat_Cloth_Inspect A    ');
//      SQL.Add(' left join BS_Cloth_IO B on A.BCIOID = B.BCIOID ');
//      SQL.Add(' where (A.BEFOREC_WIDTH='''' OR A.BEFOREC_WIDTH is null) ');
//      SQL.Add(' and (NOT EXISTS (select * from BS_Cloth_IO_mx X WHERE X.BCIOID = A.BCIOID and X.C_MXSHWidth  is not NULL)) ');
//      SQL.Add(' and A.GRADE<>''循环布'' ');
//      SQL.Add(' and A.Carno<>'''' and A.Carno is not NULL ');
//
//      SQL.Add(WSql1);
//
//      sql.Add(' group by A.C_NAME, A.C_width,A.C_GramWeight,A.pcid,A.Carno,A.dxmeter');
//      sql.Add(' ,A.CIMachNo,A.BCIOID,isnull(A.issp,'''')');
//
//      sql.add(' ) T where 1=1 ');
//      SQL.Add(WSql);
//      sql.Add(' Order By T.Carno,T.pcid,ISNULL(CAST(NULLIF(dxmeter, '''') AS DECIMAL), 0),BCIOID ');
////      showmessage(sql.text);
//      Open;
//    end;


    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select * from ( ');
      sql.Add('select A.C_NAME, A.C_width,A.C_GramWeight,A.pcid,A.Carno,A.dxmeter,issp=isnull(A.issp,'''')  ');
      sql.Add(' ,maX(B.C_Width) AS DXMF,A.CIMachNo,A.BCIOID ');
//      sql.Add(' ,CAST(isNull(A.dxmeter,''1'') AS DECIMAL(18,2)) ');

//      SQL.Add(' ,qgMeter=sum(meter+SHMeter)/ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) ');

      sql.Add(' ,meterall=(select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )');
      sql.Add(' ,C_Widthall= ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) ');
      //去掉损耗米数  20260206 cai
      SQL.Add(' ,qgMeter=(select sum(meter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )/ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) ');
      SQL.Add(' ,SHMeter=(select sum(SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo ) ');
//      SQL.Add(' ,qgSL = ROUND((select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid and X.BCIOID = A.BCIOID and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )*100 ');
//      sql.Add(' / ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1)/CAST(ISNULL(NULLIF(A.dxmeter, ''''), 1) AS DECIMAL(18,2)) , 2) ');

      SQL.Add(' ,qgSL = ROUND((CAST(ISNULL(NULLIF(A.dxmeter, ''''), 1) AS DECIMAL(18,2)) - (select sum(meter+SHMeter) FROM Tat_Cloth_Inspect X WHERE X.pcid = A.pcid  and X.GRADE<>''循环布''  and X.CIMachNo=A.CIMachNo )');
      SQL.Add(' /ISNULL(NULLIF(MAX(ISNULL(B.C_WidthNum, 1)), 0), 1) )*100 ');
      sql.Add(' /CAST(ISNULL(NULLIF(A.dxmeter, ''''), 1) AS DECIMAL(18,2)) , 3) ');

      SQL.Add(',SHpf=SUM(CASE WHEN ISNUMERIC(A.SHMETER) = 1 AND ISNUMERIC(A.C_WIDTH) = 1  ');
      SQL.Add('     THEN CAST(A.SHMETER AS DECIMAL(18,2))/100 * CAST(A.C_WIDTH AS DECIMAL(18,2)) ');
      SQL.Add('     ELSE 0 END)');

      SQL.Add(',SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END )AS YDJS');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''优等品'' THEN A.meter ELSE 0 END )AS Ydqty');
      SQL.Add(',YDpf=SUM(CASE WHEN A.GRADE=''优等品'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');

      SQL.Add(',SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END )AS edJS');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''二等品'' THEN A.meter ELSE 0 END )AS edqty');
      SQL.Add(',edpf=SUM(CASE WHEN A.GRADE=''二等品'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');

      SQL.Add(',SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END )AS xjJS');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''小卷'' THEN A.meter ELSE 0 END )AS xjqty');
      SQL.Add(',xjpf=SUM(CASE WHEN A.GRADE=''小卷'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');

      SQL.Add(',SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END )AS fbJS');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''废布'' THEN A.meter ELSE 0 END )AS fbqty');
      SQL.Add(',fbpf=SUM(CASE WHEN A.GRADE=''废布'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');

      SQL.Add(',SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END )AS fqJS');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''分切'' THEN A.meter ELSE 0 END )AS fqqty');
      SQL.Add(',fqpf=SUM(CASE WHEN A.GRADE=''分切'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');

//      SQL.Add(',SUM(CASE WHEN A.GRADE=''循环布'' THEN 1 ELSE 0 END )AS xhJS');
//      SQL.Add(',SUM(CASE WHEN A.GRADE=''循环布'' THEN A.meter ELSE 0 END )AS xhqty');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END )AS csJS');
      SQL.Add(',SUM(CASE WHEN A.GRADE=''测试'' THEN A.meter ELSE 0 END )AS csqty');
      SQL.Add(',cspf=SUM(CASE WHEN A.GRADE=''测试'' THEN A.meter ELSE 0 END )*A.C_Width/100 ');


     // 添加优等率字段 - 优等卷数/(优等卷数+小卷卷数+二等卷数+测试卷数+分切卷数+废布卷数(排除米数为0的))
      SQL.Add(',YDRate=CAST(');
      SQL.Add('    CASE ');
      SQL.Add('        WHEN (SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');  // YDJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');     // xjJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');   // edJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');     // csJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');     // fqJS
      SQL.Add('              SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) = 0 '); // fbJS（排除米数为0）
      SQL.Add('        THEN 0 ');
      SQL.Add('        ELSE ');
      SQL.Add('            CAST(SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END)*100 AS DECIMAL(18,4)) / '); // 分子：YDJS
      SQL.Add('            CAST((SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');                  // YDJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');                     // xjJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');                   // edJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');                     // csJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');                     // fqJS
      SQL.Add('                  SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) AS DECIMAL(18,4)) '); // fbJS
      SQL.Add('    END ');
      SQL.Add('AS DECIMAL(18,4)) ');

      // 添加优等率字段 - 优等卷数/(优等卷数+小卷卷数+二等卷数+测试卷数+分切卷数+废布卷数(排除米数为0的))
      SQL.Add(',FBRate=CAST(');
      SQL.Add('    CASE ');
      SQL.Add('        WHEN (SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');  // YDJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');     // xjJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');   // edJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');     // csJS
      SQL.Add('              SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');     // fqJS
      SQL.Add('              SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) = 0 '); // fbJS（排除米数为0）
      SQL.Add('        THEN 0 ');
      SQL.Add('        ELSE ');
      SQL.Add('            CAST(SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)*100 AS DECIMAL(18,4)) / '); // 分子：YDJS
      SQL.Add('            CAST((SUM(CASE WHEN A.GRADE=''优等品'' THEN 1 ELSE 0 END) + ');                  // YDJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''小卷'' THEN 1 ELSE 0 END) + ');                     // xjJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''二等品'' THEN 1 ELSE 0 END) + ');                   // edJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''测试'' THEN 1 ELSE 0 END) + ');                     // csJS
      SQL.Add('                  SUM(CASE WHEN A.GRADE=''分切'' THEN 1 ELSE 0 END) + ');                     // fqJS
      SQL.Add('                  SUM(CASE WHEN (A.GRADE=''废布'' and A.meter>0) THEN 1 ELSE 0 END)) AS DECIMAL(18,4)) '); // fbJS
      SQL.Add('    END ');
      SQL.Add('AS DECIMAL(18,4)) ');

      SQL.Add('from   Tat_Cloth_Inspect A    ');
      SQL.Add(' left join BS_Cloth_IO B on A.BCIOID = B.BCIOID ');
      SQL.Add(' where (A.BEFOREC_WIDTH='''' OR A.BEFOREC_WIDTH is null) ');
      SQL.Add(' and (NOT EXISTS (select * from BS_Cloth_IO_mx X WHERE X.BCIOID = A.BCIOID and X.C_MXSHWidth  is not NULL)) ');
      SQL.Add(' and A.GRADE<>''循环布'' ');
      SQL.Add(' and A.C_Name= ' + QuotedStr(Trim(fC_Name)));
      SQL.Add(' and A.Carno= ' + QuotedStr(Trim(fCarno)));
      SQL.Add(' and A.pcid= ' + QuotedStr(Trim(fpcid)));
      SQL.Add(' and isnull(A.issp,'''') = ' + QuotedStr(Trim(fissp)));

      SQL.Add(WSql1);

      sql.Add(' group by A.C_NAME, A.C_width,A.C_GramWeight,A.pcid,A.Carno,A.dxmeter');
      sql.Add(' ,A.CIMachNo,A.BCIOID,isnull(A.issp,'''')');

      sql.add(' ) T where 1=1 ');
      SQL.Add(WSql);
      sql.Add(' Order By T.Carno,T.pcid,ISNULL(CAST(NULLIF(dxmeter, '''') AS DECIMAL), 0),BCIOID ');
//      showmessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);

  finally
    ADOQueryMain.EnableControls;
    TV1.DataController.Filter.Clear;
  end;

end;

procedure TfrmTatClothInspHZList2.IsJYTimeClick(Sender: TObject);
begin
  inherited;
  InitGrid();
end;

procedure TfrmTatClothInspHZList2.TBRafreshClick(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmTatClothInspHZList2.CDS_1BeforeOpen(DataSet: TDataSet);
begin

  lstCust.Clear;
end;

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

procedure TfrmTatClothInspHZList2.cxPageControl1Change(Sender: TObject);
begin
  CurrentPage := 1;
  SetStatus();
  InitGrid();
end;

procedure TfrmTatClothInspHZList2.C_NameKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmTatClothInspHZList2.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmTatClothInspHZList2.FormShow(Sender: TObject);
begin
  inherited;

  ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, '检验信息汇总2');
  CurrentPage := 1;
  RecordsNumber := 500;

  SetStatus();

  BegDate.DateTime := fBegDateTime;
  EndDate.DateTime := fEndDateTime;
  InitGrid();

end;

procedure TfrmTatClothInspHZList2.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  with CDS_1 do
  begin
    Filtered := false;
    Filter := ' ssel = 1';
    Filtered := true;
  end;
  TcxGridToExcel(Self.Caption, cxGrid1);
  InitGrid();
end;

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

procedure TfrmTatClothInspHZList2.PM11Click(Sender: TObject);
begin
  SelOKNo(CDS_1, false);
end;

procedure TfrmTatClothInspHZList2.Tv1PCIDCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1PCID.Index] = ARow2.Values[Tv1PCID.Index]) and (ARow1.Values[Tv1PCID.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1qgMeterCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin

  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;
//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1qgMeter.Index] = ARow2.Values[Tv1qgMeter.Index]) and (ARow1.Values[Tv1qgMeter.Index] <> NULL) and (ARow2.Values[Tv1qgMeter.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1qgSLCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin

  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;

//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;
  if (ARow1.Values[Tv1qgSL.Index] = ARow2.Values[Tv1qgSL.Index]) and (ARow1.Values[Tv1qgSL.Index] <> NULL) and (ARow2.Values[Tv1qgSL.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1DXMFCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;
//  if (ARow1.Values[Tv1C_Name.Index] <> ARow2.Values[Tv1C_Name.Index]) or (ARow1.Values[Tv1C_Name.Index] = NULL) or (ARow2.Values[Tv1C_Name.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;
//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1DXMF.Index] = ARow2.Values[Tv1DXMF.Index]) and (ARow1.Values[Tv1DXMF.Index] <> NULL) and (ARow2.Values[Tv1DXMF.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1isspCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;

  if (ARow1.Values[Tv1issp.Index] = ARow2.Values[Tv1issp.Index]) and (ARow1.Values[Tv1issp.Index] <> NULL) and (ARow2.Values[Tv1issp.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1BCIOIDCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin

  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;

//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1BCIOID.Index] = ARow2.Values[Tv1BCIOID.Index]) and (ARow1.Values[Tv1BCIOID.Index] <> NULL) and (ARow2.Values[Tv1BCIOID.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;
end;

procedure TfrmTatClothInspHZList2.Tv1CarnoCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;
//  if (ARow1.Values[Tv1C_Name.Index] <> ARow2.Values[Tv1C_Name.Index]) or (ARow1.Values[Tv1C_Name.Index] = NULL) or (ARow2.Values[Tv1C_Name.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;
//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1Carno.Index] = ARow2.Values[Tv1Carno.Index]) and (ARow1.Values[Tv1Carno.Index] <> NULL) and (ARow2.Values[Tv1Carno.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1CIMachNoCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin

  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;
//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1CIMachNo.Index] = ARow2.Values[Tv1CIMachNo.Index]) and (ARow1.Values[Tv1CIMachNo.Index] <> NULL) and (ARow2.Values[Tv1CIMachNo.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1C_NameCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin

  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;

//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1C_Name.Index] = ARow2.Values[Tv1C_Name.Index]) and (ARow1.Values[Tv1C_Name.Index] <> NULL) and (ARow2.Values[Tv1C_Name.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1DataControllerFilterBeforeChange(Sender: TcxDBDataFilterCriteria; ADataSet: TDataSet; const AFilterText: string);
begin
  lstCust.Clear;
end;

procedure TfrmTatClothInspHZList2.Tv1dxmeterCompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
  if (ARow1.Values[Tv1PCID.Index] <> ARow2.Values[Tv1PCID.Index]) or (ARow1.Values[Tv1PCID.Index] = NULL) or (ARow2.Values[Tv1PCID.Index] = NULL) then
  begin
    AAreEqual := False;
    exit;
  end;
//  if (ARow1.Values[Tv1C_Name.Index] <> ARow2.Values[Tv1C_Name.Index]) or (ARow1.Values[Tv1C_Name.Index] = NULL) or (ARow2.Values[Tv1C_Name.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;
//  if (ARow1.Values[Tv1issp.Index] <> ARow2.Values[Tv1issp.Index]) or (ARow1.Values[Tv1issp.Index] = NULL) or (ARow2.Values[Tv1issp.Index] = NULL) then
//  begin
//    AAreEqual := False;
//    exit;
//  end;

  if (ARow1.Values[Tv1dxmeter.Index] = ARow2.Values[Tv1dxmeter.Index]) and (ARow1.Values[Tv1dxmeter.Index] <> NULL) and (ARow2.Values[Tv1dxmeter.Index] <> NULL) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmTatClothInspHZList2.Tv1TcxGridDBDataControllerTcxDataSummaryFooterSummaryItems6GetText(Sender: TcxDataSummaryItem; const AValue: Variant; AIsFooter: Boolean; var AText: string);
begin
  if lstCust <> nil then
    AText := IntToStr(lstCust.Count);
end;

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

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

procedure TfrmTatClothInspHZList2.TCBNORChange(Sender: TObject);
begin

  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmTatClothInspHZList2.JYTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmTatClothInspHZList2.N1Click(Sender: TObject);
begin

  SelOKNo(CDS_1, true);
end;

procedure TfrmTatClothInspHZList2.N2Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));

end;

procedure TfrmTatClothInspHZList2.N3Click(Sender: TObject);
begin
  CopyColumnSummaryToClipboard(TV1.Controller.FocusedColumn);
end;

procedure TfrmTatClothInspHZList2.CopyColumnSummaryToClipboard(AColumn: TcxGridColumn);
var
  AView: TcxGridDBTableView;
  SummaryIndex: Integer;
  SummaryText: string;
begin
  AView := Tv1;

  // 查找指定列的汇总项
  SummaryIndex := AView.DataController.Summary.FooterSummaryItems.IndexOfItemLink(AColumn);
  if SummaryIndex <> -1 then
  begin
    SummaryText := AView.DataController.Summary.FooterSummaryTexts[SummaryIndex];
    Clipboard.AsText := SummaryText;
  end
  else
    ShowMessage('未找到该列的汇总数据');
end;

procedure TfrmTatClothInspHZList2.ToolButton2Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  WSql := '';
  CDS_1.DisableControls;
  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      if CDS_1.fieldbyname('SSel').AsBoolean then
      begin
        if WSql <> '' then
        begin
          WSql := WSql + ',' + QuotedStr(Trim(CDS_1.fieldbyname('CIID').AsString));
        end
        else
        begin
          WSql := QuotedStr(Trim(CDS_1.fieldbyname('CIID').AsString));
        end;
      end;
      Next;
    end;
  end;
  CDS_1.Locate('SSel', True, []);
  CDS_1.EnableControls;
  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'TradeClothStk';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmLabelPrint.Free;
  end;
end;

procedure TfrmTatClothInspHZList2.ToolButton4Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, '检验信息汇总2');
end;

end.

