unit U_TatClothCKHZList;

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,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxTextEdit, dxSkinsCore,
  dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu, U_BaseList, cxPC,
  System.StrUtils, dxScrollbarAnnotations;

type
  TfrmTatClothCKHZList = class(TfrmBaseList)
    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;
    Label1: TLabel;
    DRMID: TEdit;
    Label3: TLabel;
    CoName: TEdit;
    Label6: TLabel;
    C_Width: TEdit;
    Label7: TLabel;
    C_GramWeight: TEdit;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column22: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1C_GramWeight: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Tv1NetWeight: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    CDS_2: TClientDataSet;
    DS_2: TDataSource;
    GPM_2: TcxGridPopupMenu;
    Tv1issp: TcxGridDBColumn;
    Tv2issp: TcxGridDBColumn;
    N2: TMenuItem;
    N3: TMenuItem;
    PM_2: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    TabSheet3: TTabSheet;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    PM_3: TPopupMenu;
    MenuItem5: TMenuItem;
    MenuItem6: TMenuItem;
    MenuItem7: TMenuItem;
    MenuItem8: TMenuItem;
    DS_3: TDataSource;
    CDS_3: TClientDataSet;
    Tv3COName: TcxGridDBColumn;
    TabSheet4: TTabSheet;
    cxGrid4: TcxGrid;
    Tv4: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    Tv1IOTime: TcxGridDBColumn;
    Tv1DRMID: TcxGridDBColumn;
    Tv1CoName: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    Tv1C_Width: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    Tv1PF: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    CDS_4: TClientDataSet;
    DS_4: TDataSource;
    PM_4: TPopupMenu;
    MenuItem9: TMenuItem;
    MenuItem10: TMenuItem;
    MenuItem11: TMenuItem;
    MenuItem12: TMenuItem;
    GPM_3: TcxGridPopupMenu;
    GPM_4: TcxGridPopupMenu;
    Tv4PFPrice: TcxGridDBColumn;
    Tv4amount: TcxGridDBColumn;
    Tv4Saleser: TcxGridDBColumn;
    Tv4dept: TcxGridDBColumn;
    Tv4CompanyName: TcxGridDBColumn;
    Tv4note: TcxGridDBColumn;
    Tv4isIncludeTax: TcxGridDBColumn;
    Tv4Grade: TcxGridDBColumn;
    Tv4FHDH: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv4Column1: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv3Column1: 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 cxTabControl1Change(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure MenuItem4Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure MenuItem5Click(Sender: TObject);
    procedure MenuItem6Click(Sender: TObject);
    procedure MenuItem7Click(Sender: TObject);
    procedure MenuItem8Click(Sender: TObject);
    procedure Tv3DblClick(Sender: TObject);
    procedure MenuItem9Click(Sender: TObject);
    procedure MenuItem10Click(Sender: TObject);
    procedure MenuItem11Click(Sender: TObject);
    procedure MenuItem12Click(Sender: TObject);
  private
    CurrentPage, RecordsNumber: Integer;
    lstCust: TStringList;
    procedure InitGrid();
    procedure SetStatus();
    procedure InitGrid2();
    procedure CopyColumnSummaryToClipboard(AColumn: TcxGridColumn);
    procedure CopyColumnSummaryToClipboard2(AColumn: TcxGridColumn);
    procedure InitGrid3();
    procedure CopyColumnSummaryToClipboard3(AColumn: TcxGridColumn);
    procedure InitGrid4();
    procedure CopyColumnSummaryToClipboard4(AColumn: TcxGridColumn);
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_LabelPrint, U_TatClothCKHZList2, U_TatClothCKHZList3;

{$R *.dfm}

procedure TfrmTatClothCKHZList.SetStatus();
begin

end;

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

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

procedure TfrmTatClothCKHZList.InitGrid();
var
  WSql: string;
begin

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

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      sql.Add('SELECT A.C_CODE,A.C_Name,A.C_GramWeight,DRMID = '''',ISZS ');
//      sql.Add(',B.ToCoID ');
//      sql.Add(',COName = '''' ');
      sql.Add(' ,js = count(*),Meter=sum(A.meter),NetWeight = sum(A.NetWeight)   ');
//      sql.Add(',pf = CAST(A.C_Width AS DECIMAL(18,2))/100*sum(A.meter) ');
      SQL.Add(',issp=isnull(A.issp,'''') ');
      sql.Add(' FROM V_Tat_Cloth_IO A   ');
      sql.Add(' left JOIN Tat_Cloth_DR_Main B on A.IONo = B.DRMID ');
      sql.Add(' left join BS_Company D on D.CoID = B.ToCoID ');
      sql.Add(' where A.IONo LIKE ''RSG%'' and A.IOFlag = ''出库'' ');
      sql.Add(WSql);
      if canshu1 = '业务' then
      begin
        sql.Add(' and EXISTS ( select * from BS_Company X where X.COID = B.ToCoID and X.Saleser = ' + quotedStr(Trim(DName)) + ')');
      end;
      SQL.Add(' group by A.C_CODE ,A.C_GramWeight,A.C_Name,isnull(A.issp,''''),ISZS');
//      ,B.ToCoID
      SQL.Add(' order by A.C_CODE ,A.C_GramWeight,ISZS');

//            showmessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);

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

end;

procedure TfrmTatClothCKHZList.InitGrid2();
var
  WSql: string;
begin

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

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('SELECT A.C_CODE,A.C_Name,A.C_GramWeight,ISZS ');
//      sql.Add(',ioType=max(A.ioType) ');
      sql.Add(',COName = '''' ');
      sql.Add(' ,js = count(*),Meter=sum(A.meter),NetWeight = sum(A.NetWeight) ');
      sql.Add(' ,ISNULL(A.issp, '''') as issp ');
      sql.Add(' FROM V_Tat_Cloth_IO A   ');
      sql.Add(' left JOIN Tat_Cloth_DR_Main B on A.IONo = B.DRMID ');
      sql.Add(' left join BS_Company D on D.CoID = B.ToCoID ');
      sql.Add(' where  A.IONo not LIKE ''RSG%'' and A.IOFlag = ''出库''  ');
      sql.Add(WSql);
      if canshu1 = '业务' then
      begin
        sql.Add(' and EXISTS ( select * from BS_Company X where X.COID = B.ToCoID and X.Saleser = ' + quotedStr(Trim(DName)) + ')');
      end;

      SQL.Add(' group by A.C_CODE ,A.C_GramWeight,A.C_Name,ISNULL(A.issp, ''''),ISZS');
      SQL.Add(' order By A.C_CODE ,A.C_GramWeight');
//      SQL.Add(' order by B.DRMID');
//      showmessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_2);
    SInitCDSData(ADOQueryMain, CDS_2);

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

end;

procedure TfrmTatClothCKHZList.InitGrid3();
var
  WSql: string;
begin

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

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      sql.Add('SELECT ');
      sql.Add(' B.ToCoID,DRMID = '''' ');
      sql.Add(',COName = (select COName from BS_Company X where X.CoID = B.ToCoID)');
      sql.Add(' ,js = count(*),Meter=sum(A.meter),NetWeight = sum(A.NetWeight),ISZS   ');
//      sql.Add(',pf = CAST(A.C_Width AS DECIMAL(18,2))/100*sum(A.meter) ');
//      SQL.Add(',issp=isnull(A.issp,'''') ');
      sql.Add(' FROM V_Tat_Cloth_IO A   ');
      sql.Add(' left JOIN Tat_Cloth_DR_Main B on A.IONo = B.DRMID ');
      sql.Add(' left join BS_Company D on D.CoID = B.ToCoID ');
      sql.Add(' where A.IONo LIKE ''RSG%'' and A.IOFlag = ''出库'' ');
      sql.Add(WSql);
      if canshu1 = '业务' then
      begin
        sql.Add(' and EXISTS ( select * from BS_Company X where X.COID = B.ToCoID and X.Saleser = ' + quotedStr(Trim(DName)) + ')');
      end;
      SQL.Add(' group by B.ToCoID,ISZS');

//            showmessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_3);
    SInitCDSData(ADOQueryMain, CDS_3);

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

end;

procedure TfrmTatClothCKHZList.InitGrid4();
var
  WSql: string;
begin

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

  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      sql.Add('SELECT ISZS,A.C_CODE,A.C_Name,A.C_width,A.C_GramWeight,A.IONO as DRMID,A.Grade,A.FHDH ');
      sql.Add(',CAST(ioTime AS DATE) as ioTime, C.PFPrice, (CAST(A.C_Width AS DECIMAL(18,2))/100 * SUM(A.meter) * C.PFPrice) as amount');
//      sql.Add(', (SELECT COName FROM BS_Company X WHERE X.CoID = B.ToCoID) as COName');
      sql.Add(', D.COName,D.Saleser,D.dept,B.CompanyName,C.note,C.isIncludeTax ');
      sql.Add(' ,COUNT(*) as js, SUM(A.meter) as Meter,SUM(A.NetWeight) as NetWeight ');
      sql.Add(', CAST(A.C_Width AS DECIMAL(18,2))/100 * SUM(A.meter) as pf');
      SQL.Add(',ISNULL(A.issp, '''') as issp ');
      sql.Add(' FROM V_Tat_Cloth_IO A   ');
      sql.Add(' left JOIN Tat_Cloth_DR_Main B on A.IONo = B.DRMID ');
      Sql.Add(' left JOIN Tat_Cloth_DR_Sub C on B.DRMID = C.DRMID and C.C_CODE=A.C_CODE and C.C_width=A.C_width and C.C_GramWeight=A.C_GramWeight ');
      sql.Add(' left join BS_Company D on D.CoID = B.ToCoID ');
      sql.Add(' where A.IONo LIKE ''RSG%'' and A.IOFlag = ''出库'' ');
//      sql.Add(' and  (select COName from BS_Company X where X.CoAbbrName = max(B.ToCoName))= ' + QuotedStr(Trim(fconame)));
//      sql.Add(' and A.C_Name = ' + QuotedStr(Trim(fC_Name)));
//      sql.Add(' and B.ToCoID = ' + QuotedStr(Trim(fToCoID)));
//      sql.Add(' and isnull(A.issp,'''') = ' + QuotedStr(Trim(fissp)));
      sql.Add(WSql);
      if canshu1 = '业务' then
      begin
        sql.Add(' and EXISTS ( select * from BS_Company X where X.COID = B.ToCoID and X.Saleser = ' + quotedStr(Trim(DName)) + ')');
      end;

      if C_Name.text <> '' then
      begin
        SQL.Add(' and A.C_Name like ' + QuotedStr('%' + Trim(C_Name.text) + '%'));
      end;
      if C_Width.text <> '' then
      begin
        SQL.Add(' and A.C_Width like ' + QuotedStr('%' + Trim(C_Width.text) + '%'));
      end;
      if CoName.text <> '' then
      begin
        SQL.Add(' and D.CoName like ' + QuotedStr('%' + Trim(CoName.text) + '%'));
      end;
      if DRMID.text <> '' then
      begin
        SQL.Add(' and B.DRMID like ' + QuotedStr('%' + Trim(DRMID.text) + '%'));
      end;
      if C_GramWeight.text <> '' then
      begin
        SQL.Add(' and A.C_GramWeight like ' + QuotedStr('%' + Trim(C_GramWeight.text) + '%'));
      end;

      SQL.Add(' group by ISZS,A.C_CODE,A.C_width,A.C_GramWeight,A.IONO,A.C_Name,isnull(A.issp,''''),B.ToCoID, D.COName,CAST(ioTime AS DATE),C.PFPrice,D.Saleser,D.dept,B.CompanyName,C.note,C.isIncludeTax,A.Grade,A.FHDH');
//      sql.Add(' HAVING(select COName from BS_Company X where X.CoAbbrName = max(B.ToCoName))= ' + QuotedStr(Trim(fconame)));
      SQL.Add(' order by A.IONO,A.C_CODE,CAST(A.C_width AS INT),A.C_GramWeight,CAST(ioTime AS DATE),A.Grade,A.FHDH');

//      showmessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_4);
    SInitCDSData(ADOQueryMain, CDS_4);

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

end;

procedure TfrmTatClothCKHZList.IsJYTimeClick(Sender: TObject);
begin
  inherited;
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.TBRafreshClick(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.CDS_1BeforeOpen(DataSet: TDataSet);
begin

  lstCust.Clear;
end;

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

procedure TfrmTatClothCKHZList.cxPageControl1Change(Sender: TObject);
begin
  CurrentPage := 1;
  SetStatus();
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.cxTabControl1Change(Sender: TObject);
begin
  inherited;
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

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

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

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

  ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, '成品出库汇总');
  ReadCxGrid(trim(self.Caption) + 'Tv2', Tv2, '成品出库汇总');
  ReadCxGrid(trim(self.Caption) + 'Tv3', Tv3, '成品出库汇总');
  ReadCxGrid(trim(self.Caption) + 'Tv4', Tv4, '成品出库汇总');
  CurrentPage := 1;
  RecordsNumber := 500;
  canshu1 := Trim(Self.fParameters1);
  EndDate.DateTime := SGetServerDate(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  SetStatus();
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.TBExportClick(Sender: TObject);
begin
  if PageControl1.ActivePage.Caption = '有出库单出库' then
  begin
    if CDS_1.IsEmpty then
      Exit;
    with CDS_1 do
    begin
      Filtered := false;
      Filter := ' ssel = 1';
      Filtered := true;
    end;
    TcxGridToExcel(Self.Caption, cxGrid1);
    InitGrid();
  end
  else if PageControl1.ActivePage.Caption = '有出库单出库明细' then
  begin
    if CDS_4.IsEmpty then
      Exit;
    with CDS_4 do
    begin
      Filtered := false;
      Filter := ' ssel = 1';
      Filtered := true;
    end;
    TcxGridToExcel(Self.Caption, cxGrid4);
    InitGrid4();
  end
  else if PageControl1.ActivePage.Caption = '无出库单出库' then
  begin
    if CDS_2.IsEmpty then
      Exit;
    with CDS_2 do
    begin
      Filtered := false;
      Filter := ' ssel = 1';
      Filtered := true;
    end;
    TcxGridToExcel(Self.Caption, cxGrid2);
    InitGrid2();
  end
  else if PageControl1.ActivePage.Caption = '有出库单汇总(客户)' then
  begin
    if CDS_3.IsEmpty then
      Exit;
    with CDS_3 do
    begin
      Filtered := false;
      Filter := ' ssel = 1';
      Filtered := true;
    end;
    TcxGridToExcel(Self.Caption, cxGrid3);
    InitGrid3();
  end;
end;

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

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

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

procedure TfrmTatClothCKHZList.Tv1DblClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmTatClothCKHZList2 := TfrmTatClothCKHZList2.Create(Application);
    with frmTatClothCKHZList2 do
    begin

      fEndDateTime := self.EndDate.DateTime;
      fBegDateTime := Self.BegDate.DateTime;

//      fDRMID := Self.CDS_1.FieldByName('DRMID').AsString;
      fToCoID := '';
      fC_Name := Self.CDS_1.FieldByName('C_Name').AsString;
      fissp := Self.CDS_1.FieldByName('issp').AsString;
//      fioType := Self.CDS_1.FieldByName('ioType').AsString;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmTatClothCKHZList2.Free;
  end;
end;

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

procedure TfrmTatClothCKHZList.Tv2DblClick(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    Exit;
  try
    frmTatClothCKHZList3 := TfrmTatClothCKHZList3.Create(Application);
    with frmTatClothCKHZList3 do
    begin

      fEndDateTime := self.EndDate.DateTime;
      fBegDateTime := Self.BegDate.DateTime;

      fC_Name := Self.CDS_2.FieldByName('C_Name').AsString;
      fissp := Self.CDS_2.FieldByName('issp').AsString;
//      fioType := Self.CDS_1.FieldByName('ioType').AsString;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmTatClothCKHZList3.Free;
  end;
end;

procedure TfrmTatClothCKHZList.Tv3DblClick(Sender: TObject);
begin
  if CDS_3.IsEmpty then
    Exit;
  try
    frmTatClothCKHZList2 := TfrmTatClothCKHZList2.Create(Application);
    with frmTatClothCKHZList2 do
    begin

      fEndDateTime := self.EndDate.DateTime;
      fBegDateTime := Self.BegDate.DateTime;

//      fDRMID := Self.CDS_1.FieldByName('DRMID').AsString;
      fToCoID := Self.CDS_3.FieldByName('ToCoID').AsString;
//      fC_Name := Self.CDS_1.FieldByName('C_Name').AsString;
//      fissp := Self.CDS_1.FieldByName('issp').AsString;
//      fioType := Self.CDS_1.FieldByName('ioType').AsString;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmTatClothCKHZList2.Free;
  end;
end;

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

procedure TfrmTatClothCKHZList.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.TCBNORChange(Sender: TObject);
begin

  CurrentPage := 1;
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.JYTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
  InitGrid2();
  InitGrid3();
  InitGrid4();
end;

procedure TfrmTatClothCKHZList.MenuItem10Click(Sender: TObject);
begin
  SelOKNo(CDS_4, false);
end;

procedure TfrmTatClothCKHZList.MenuItem11Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_4.fieldbyname(TV4.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmTatClothCKHZList.MenuItem12Click(Sender: TObject);
begin
  CopyColumnSummaryToClipboard4(TV4.Controller.FocusedColumn);
end;

procedure TfrmTatClothCKHZList.MenuItem1Click(Sender: TObject);
begin

  SelOKNo(CDS_2, true);
end;

procedure TfrmTatClothCKHZList.MenuItem2Click(Sender: TObject);
begin
  SelOKNo(CDS_2, false);

end;

procedure TfrmTatClothCKHZList.MenuItem3Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_2.fieldbyname(TV2.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmTatClothCKHZList.MenuItem4Click(Sender: TObject);
begin

  CopyColumnSummaryToClipboard2(TV2.Controller.FocusedColumn);
end;

procedure TfrmTatClothCKHZList.MenuItem5Click(Sender: TObject);
begin
  SelOKNo(CDS_3, true);

end;

procedure TfrmTatClothCKHZList.MenuItem6Click(Sender: TObject);
begin
  SelOKNo(CDS_3, false);

end;

procedure TfrmTatClothCKHZList.MenuItem7Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_3.fieldbyname(TV3.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmTatClothCKHZList.MenuItem8Click(Sender: TObject);
begin
  CopyColumnSummaryToClipboard3(TV3.Controller.FocusedColumn);
end;

procedure TfrmTatClothCKHZList.MenuItem9Click(Sender: TObject);
begin
  SelOKNo(CDS_4, true);
end;

procedure TfrmTatClothCKHZList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_1, true);
end;

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

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

end;

procedure TfrmTatClothCKHZList.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 TfrmTatClothCKHZList.CopyColumnSummaryToClipboard2(AColumn: TcxGridColumn);
var
  AView: TcxGridDBTableView;
  SummaryIndex: Integer;
  SummaryText: string;
begin
  AView := Tv2;

  // 查找指定列的汇总项
  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 TfrmTatClothCKHZList.CopyColumnSummaryToClipboard3(AColumn: TcxGridColumn);
var
  AView: TcxGridDBTableView;
  SummaryIndex: Integer;
  SummaryText: string;
begin
  AView := Tv3;

  // 查找指定列的汇总项
  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 TfrmTatClothCKHZList.CopyColumnSummaryToClipboard4(AColumn: TcxGridColumn);
var
  AView: TcxGridDBTableView;
  SummaryIndex: Integer;
  SummaryText: string;
begin
  AView := Tv4;

  // 查找指定列的汇总项
  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 TfrmTatClothCKHZList.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 TfrmTatClothCKHZList.ToolButton4Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, '成品出库汇总');
  WriteCxGrid(trim(self.Caption) + 'Tv2', Tv2, '成品出库汇总');
  WriteCxGrid(trim(self.Caption) + 'Tv3', Tv3, '成品出库汇总');
  WriteCxGrid(trim(self.Caption) + 'Tv4', Tv4, '成品出库汇总');
end;

end.

