unit U_DyeClothInspList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, Math, Clipbrd, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, dxSkinsCore,
  dxSkinsDefaultPainters, dxDateRanges, U_BaseList, dxDateTimeWheelPicker,
  dxScrollbarAnnotations;

type
  TfrmDyeClothInspList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    btnEdit: TToolButton;
    TBZF: TToolButton;
    btnJBQ: TToolButton;
    RM1: TRMGridReport;
    RMDB_1: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    btnJYBG: TToolButton;
    ToolButton1: TToolButton;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column42: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1MKXS: TcxGridDBColumn;
    v1Column34: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    v1Column46: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Panel1: TPanel;
    Label3: TLabel;
    Label7: TLabel;
    Label10: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label23: TLabel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    CIID: TEdit;
    Grade: TComboBox;
    C_Name: TEdit;
    C_Color: TEdit;
    IsJYTime: TCheckBox;
    C_Code: TEdit;
    PCId: TEdit;
    Tv1SSel: TcxGridDBColumn;
    N2: TMenuItem;
    N3: TMenuItem;
    Tv1Inspector1: TcxGridDBColumn;
    Tv1Inspector2: TcxGridDBColumn;
    Tv1C_description: TcxGridDBColumn;
    Tv1checktime: TcxGridDBColumn;
    ToolButton2: TToolButton;
    Tv1barCode: TcxGridDBColumn;
    N4: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure btnEditClick(Sender: TObject);
    procedure TBZFClick(Sender: TObject);
    procedure btnJBQClick(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure conNOKeyPress(Sender: TObject; var Key: Char);
    procedure CIIOFlagChange(Sender: TObject);
    procedure GradeChange(Sender: TObject);
    procedure KHConNOKeyPress(Sender: TObject; var Key: Char);
    procedure RKOrdIDKeyPress(Sender: TObject; var Key: Char);
    procedure btnJYBGClick(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure cxPageControl1Change(Sender: TObject);
    procedure chkZFClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure N4Click(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure SetStatus();
    procedure PrintCKMDG(MRKOrdID: string);
    { Private declarations }
  public
    FFInt: Integer;
    canshu1, FWorkshop: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_DyeInspEdit, U_ZDYHelp, U_LabelPrint;

{$R *.dfm}

procedure TfrmDyeClothInspList.SetStatus();
begin
//  btnEdit.Enabled := False;
//  TBZF.Enabled := False;
//  btnHY.Enabled := False;
//  btnJBQ.Enabled := False;
//  btnJYBG.Enabled := False;
//
//  btnEdit.Enabled := True;
//  TBZF.Enabled := True;
//  btnJBQ.Enabled := True;
//  btnJYBG.Enabled := True;

end;

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

procedure TfrmDyeClothInspList.FormCreate(Sender: TObject);
begin
  inherited;
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
  FWorkshop := trim(Self.fParameters3);
end;

procedure TfrmDyeClothInspList.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then  // VK_ESCAPE 是 ESC 键的常量
  begin
    Key := 0;  // 清除按键，防止继续传递
    Close;     // 或者 ModalResult := mrCancel;
  end;
end;

procedure TfrmDyeClothInspList.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmDyeClothInspList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmDyeClothInspList.PrintCKMDG(MRKOrdID: string);
begin

end;

procedure TfrmDyeClothInspList.InitGrid();
var
  WSql: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  WSql := SGetFilters(Panel1, 1, 2);
  if trim(WSql) <> '' then
  begin
    WSql := ' and ' + trim(WSql);
  end;

  if trim(FWorkshop) <> '' then
    WSql := WSql + ' and A.Workshop=''' + trim(FWorkshop) + '''';

  if IsJYTime.Checked then
  begin
    WSql := WSql + ' and A.checktime>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    WSql := WSql + ' and A.checktime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end
  else
  begin
    if trim(WSql) <> '' then
      WSql := ' and 1=1' + trim(WSql)
    else
      WSql := WSql + ' and 1=2 ';
  end;
  if trim(WSql) = 'and 1=2' then
    Application.MessageBox('勾选检验日期或填入搜索条件', '提示', 0);

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
//      sql.Add('exec P_Dye_Insp_Get_Page ');
//      sql.Add('@pageIndex=' + inttostr(CurrentPage));
//      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
//      sql.Add(',@criteria= ' + quotedstr(WSql));


       sql.Add(' select top ' + inttostr(RecordsNumber) + ' AA.* from (');
      sql.Add(' select rownumber=CAST(row_number() over(order by A.Filltime ) AS INT)');
      sql.Add(',TotalCount=CAST(COUNT(1) OVER() AS INT)');
      sql.Add(',* from V_Dye_Insp_Get_Page A where 1=1 ');
      sql.Add(WSql);
      SQL.Add(' ) AA');
      sql.Add(' where rownumber> ' + inttostr(((CurrentPage - 1) * RecordsNumber)));
      sql.Add(' order by rownumber');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, Order_Main);
    SInitCDSData(ADOQueryMain, Order_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));

    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
    TV1.DataController.Filter.Clear;
  end;
end;

procedure TfrmDyeClothInspList.TBRafreshClick(Sender: TObject);
begin
  OrderNo.SetFocus;
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmDyeClothInspList.FormShow(Sender: TObject);
var
  fsj: string;
begin
  inherited;
  canshu1 := self.fParameters1;
  CurrentPage := 1;
  RecordsNumber := 500;
  ReadCxGrid(Trim(self.Caption) + 'Tv1', Tv1, '贸易检验管理');
  EndDate.DateTime := SGetServerDate(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  fsj := 'select distinct(Filler) name from Dye_Cloth_Inspect   ';
//  SInitComBoxBySql(ADOQueryCmd, Filler, False, fsj);
//  Filler.ItemIndex := Filler.Items.IndexOf(trim(DName));


  InitGrid();
  SetStatus();
  InitGrid();
  KeyPreview := True;  // 确保表单可以预览按键
end;

procedure TfrmDyeClothInspList.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmDyeClothInspList.btnEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Dye_Cloth_IO where IOFlag=''入库'' and StkId=''' + Trim(Order_Main.fieldbyname('CIID').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Order_Main.EnableControls;
    Application.MessageBox('已产生入库数据不能编辑!', '提示', 0);
    Exit;
  end;
  try
    frmDyeInspEdit := TfrmDyeInspEdit.Create(Application);
    with frmDyeInspEdit do
    begin
      CIID.Text := Trim(Self.Order_Main.fieldbyname('CIID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmDyeInspEdit.Free;
  end;
end;

procedure TfrmDyeClothInspList.TBZFClick(Sender: TObject);
var
  MCIIDS, MPCIDS: string;
begin
  if Order_Main.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要作废数据吗？作废后数据不能恢复。', '提示', 32 + 4) <> IDYES then
    Exit;
  MCIIDS := '';
  MPCIDS := '';
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean = True then
      begin
        MCIIDS := MCIIDS + Trim(Order_Main.fieldbyname('CIID').AsString) + ',';
        MPCIDS := MPCIDS + Trim(Order_Main.fieldbyname('PCID').AsString) + ',';
        Order_Main.Delete;
      end
      else
        Next;
    end;
  end;
  Order_Main.EnableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into Dye_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails)       ');
      sql.Add('values(''印染机台检验''    ');
      sql.Add(',' + quotedstr(MPCIDS));
      sql.Add(',''删除''   ');
      sql.Add(',' + quotedstr(DName));
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(MCIIDS));
      sql.Add(')  ');
      execsql;
    end;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Dye_Insp_Del ');
      Sql.Add('@CIIDS=' + quotedstr(Trim(MCIIDS)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CurrentPage := 1;
    InitGrid();
    application.MessageBox('删除成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmDyeClothInspList.btnJBQClick(Sender: TObject);
var
  MCIID: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  MCIID := '';
  Order_Main.DisableControls;
  with Order_Main do
  begin
    MCIID := Trim(Order_Main.fieldbyname('CIID').AsString);
    First;
    while Order_Main.Locate('SSel', True, []) do
    begin

//      MPCID := MPCID + ',' + Trim(CDS_1.fieldbyname('PCID').AsString);

      Edit;
      FieldByName('SSel').Value := False;
      Post;
    end;
  end;
  Order_Main.EnableControls;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'DyeClothInspListPrint1';
      FFiltration1 := MCIID;
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update Dye_Cloth_Inspect Set PrtCount=PrtCount+1,PrtDate=getdate(),Prter=''' + Trim(DName) + '''');
          sql.Add(' where CIID=''' + Trim(Order_Main.fieldbyname('CIID').AsString) + '''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;
end;


//var
//  fPrintFile, FLBName: string;
//begin
//  if Order_Main.IsEmpty then
//    Exit;
//  if Order_Main.Locate('SSel', True, []) = False then
//  begin
//    Application.MessageBox('没有选择数据!', '提示', 0);
//    Exit;
//  end;
//  Order_Main.DisableControls;
//  with Order_Main do
//  begin
//    First;
//    while not Eof do
//    begin
//      if Order_Main.FieldByName('SSel').AsBoolean = True then
//      begin
//        with ADOQueryCmd do
//        begin
//          Close;
//          sql.Clear;
//          sql.Add('Update Dye_Cloth_Inspect Set PrtCount=PrtCount+1,PrtDate=getdate(),Prter=''' + Trim(DName) + '''');
//          sql.Add(' where CIID=''' + Trim(Order_Main.fieldbyname('CIID').AsString) + '''');
//          ExecSQL;
//        end;
//
//        with ADOQueryPrint do
//        begin
//          Close;
//          SQL.Clear;
//          sql.Add(' EXEC P_Dye_Insp_Prt_Lab ');
//          SQL.Add(' @CIID=''' + Trim(Order_Main.fieldbyname('CIID').AsString) + '''');
//          Open;
//        end;
//        if ADOQueryPrint.IsEmpty then
//        begin
//          application.MessageBox('标签内容未找到！', '提示信息', MB_ICONERROR);
//          exit;
//        end;
//
//        FLBName := Trim(ADOQueryPrint.fieldbyname('LBName').AsString);
//        ExportFtErpFile(FLBName + '.rmf', ADOQueryTemp);
//
//        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + FLBName + '.rmf';
//
//        if FileExists(fPrintFile) then
//        begin
//          RM1.LoadFromFile(fPrintFile);
//          Rm1.DefaultCopies := 2;
//          RM1.PrintReport;
//        end
//        else
//        begin
//          Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
//        end;
//      end;
//      Next;
//    end;
//  end;
//  Order_Main.EnableControls;
//end;

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

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

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

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

procedure TfrmDyeClothInspList.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption) + 'Tv1', Tv1, '贸易检验管理');
end;

procedure TfrmDyeClothInspList.ToolButton2Click(Sender: TObject);
begin
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('exec P_OrderCR');

//      ShowMessage(sql.Text);
      execsql;
    end;

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec P_Auto_InspectToStock @Filler = ' + quotedStr(Trim(DName)));
      ExecSQL;
    end;
    Application.MessageBox('操作执行成功！', '提示', MB_OK + MB_ICONINFORMATION);
  except
    on E: Exception do
    begin
      Application.MessageBox(PChar('操作执行失败：' + E.Message), '错误', MB_OK + MB_ICONERROR);
    end;
  end;
end;

procedure TfrmDyeClothInspList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmDyeClothInspList.chkZFClick(Sender: TObject);
begin
  inherited;
  CurrentPage := 1;
  SetStatus();
  InitGrid();
end;

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

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

procedure TfrmDyeClothInspList.CIIOFlagChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmDyeClothInspList.GradeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

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

procedure TfrmDyeClothInspList.N1Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));

end;

procedure TfrmDyeClothInspList.N2Click(Sender: TObject);
begin
  inherited;
  SelOKNoFiler(Tv1, True);
end;

procedure TfrmDyeClothInspList.N3Click(Sender: TObject);
begin
  inherited;
  SelOKNoFiler(Tv1, False);
end;

procedure TfrmDyeClothInspList.N4Click(Sender: TObject);
var
  InputValues: array[0..1] of string;
  StartRow, EndRow, i: Integer;
  topIndex: Integer;
begin
  topIndex := tv1.Controller.TopRowIndex;

  // 初始化为空字符串
  InputValues[0] := '';
  InputValues[1] := '';

  if InputQuery('选择行范围', ['起始行:', '结束行:'], InputValues) then
  begin
    // 检查是否为空
    if InputValues[0] = '' then
    begin
      ShowMessage('请输入起始行');
      exit;
    end;

    if InputValues[1] = '' then
    begin
      ShowMessage('请输入结束行');
      exit;
    end;

    // 转换输入值
    StartRow := StrToIntDef(InputValues[0], 0);
    EndRow := StrToIntDef(InputValues[1], 0);

    // 验证范围
    if StartRow <= 0 then
    begin
      ShowMessage('起始行必须大于0');
      exit;
    end;

    if EndRow < StartRow then
    begin
      ShowMessage('结束行不能小于起始行');
      exit;
    end;

//    if EndRow > Order_Main.RecordCount then
//    begin
//      ShowMessage(Format('结束行不能超过总行数(%d)', [Order_Main.RecordCount]));
//      Exit;
//    end;

    // 循环设置指定范围内的行
    Order_Main.DisableControls;
    try
      Order_Main.First;
      for i := 1 to Order_Main.RecordCount do
      begin
        if (i >= StartRow) and (i <= EndRow) then
        begin
          Order_Main.Edit;
          Order_Main.FieldByName('ssel').Value := True;
          Order_Main.post;
        end;

        Order_Main.Next;
      end;
    finally
      Order_Main.EnableControls;
    end;

  end;

  tv1.Controller.TopRowIndex := topIndex;
end;

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

procedure TfrmDyeClothInspList.btnJYBGClick(Sender: TObject);
var
  WSql: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  WSql := '';
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      if Order_Main.fieldbyname('SSel').AsBoolean then
      begin
        if WSql <> '' then
        begin
          WSql := WSql + ',' + QuotedStr(Trim(Order_Main.fieldbyname('CIID').AsString));
        end
        else
        begin
          WSql := QuotedStr(Trim(Order_Main.fieldbyname('CIID').AsString));
        end;
      end;
      Next;
    end;
  end;
  Order_Main.Locate('SSel', True, []);
  Order_Main.EnableControls;
  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'DyeInsp';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;

end;

procedure TfrmDyeClothInspList.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBlack, clBlack, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -3, -2); //Platform specific. May not work on Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

end.

