unit U_TatDCGCLCXList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, MovePanel, cxButtonEdit, cxCalendar, RM_System, RM_Common,
  RM_Class, RM_GridReport, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, cxCheckBox, Vcl.Menus, cxContainer, dxScrollbarAnnotations,
  cxProgressBar;

type
  TfrmTatDCGCLCXList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    C_Name: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    MovePanel2: TMovePanel;
    RMGridReport1: TRMGridReport;
    customerNoName: TEdit;
    Label13: TLabel;
    ywy: TEdit;
    Label17: TLabel;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    lbHx: TEdit;
    Label7: TLabel;
    TBdel: TToolButton;
    begtime: TDateTimePicker;
    endTime: TDateTimePicker;
    ToolButton1: TToolButton;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    GlideName1: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Tv1Column1: TcxGridDBColumn;
    Label4: TLabel;
    JBSCPerson: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    ToolButton4: TToolButton;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    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 TBFindClick(Sender: TObject);
    procedure PRTColorChange(Sender: TObject);
    procedure TBdelClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure C_NameKeyPress(Sender: TObject; var Key: Char);
    procedure JBSCPersonKeyPress(Sender: TObject; var Key: Char);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    { Private declarations }
  public
    fsyrName, canshu1: string;
    { Public declarations }
  end;

var
  frmTatDCGCLCXList: TfrmTatDCGCLCXList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_OutPutHelp, U_LabelPrint;

{$R *.dfm}

procedure TfrmTatDCGCLCXList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTatDCGCLCXList := nil;
end;

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

procedure TfrmTatDCGCLCXList.FormCreate(Sender: TObject);
begin
  inherited;

  EndDate.DateTime := SGetServerDateTime(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 7;
  fsyrName := trim(DdataBase);
  canshu1 := trim(DParameters1);
end;

procedure TfrmTatDCGCLCXList.InitGrid();
var
  FFiltration: string;
begin
  FFiltration := DateToStr(BegDate.DATE) + '*' + DateToStr(EndDate.DATE);
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Tat_Cloth_Inspect_Refresh ');
      sql.Add(' @Filtration=' + quotedstr(Trim(FFiltration)));
//      showmessage(sql.Text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  TBFind.Click;
end;

procedure TfrmTatDCGCLCXList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

procedure TfrmTatDCGCLCXList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmTatDCGCLCXList.TBRafreshClick(Sender: TObject);
begin
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible := False;
end;

procedure TfrmTatDCGCLCXList.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(self.Caption + tv1.Name, Tv1, '成品仓库');
end;

procedure TfrmTatDCGCLCXList.ToolButton4Click(Sender: TObject);
begin
//  CDS_Main.EnableControls;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'BSYarnInPrt2';
      FFiltration1 := DateToStr(BegDate.DATE) + '*' + DateToStr(EndDate.DATE) + '*' + JBSCPerson.text;
//      ShowMessage(FFiltration1);
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;

    end;
  finally
    frmLabelPrint.Free;

  end;
end;

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

procedure TfrmTatDCGCLCXList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmTatDCGCLCXList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(self.Caption + tv1.Name, Tv1, '成品仓库');
  canshu1 := self.fParameters1;

  initgrid();
end;

procedure TfrmTatDCGCLCXList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
//  SelExportData(tv1,ADOQueryMain,self.Caption);
  TcxGridToExcel(self.Caption, cxGrid2);
end;

procedure TfrmTatDCGCLCXList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmTatDCGCLCXList.TBPrintClick(Sender: TObject);
//var
//  MBYIOID: string;
begin
//  if CDS_Main.IsEmpty then
//    Exit;
//  if CDS_Main.Locate('SSel', True, []) = False then
//  begin
//    Application.MessageBox('没有选择数据!', '提示', 0);
//    Exit;
//  end;
//
//  MBYIOID := '';
//  CDS_Main.DisableControls;
//  with CDS_Main do
//  begin
//    First;
//    while CDS_Main.Locate('SSel', True, []) do
//    begin
//
//      MBYIOID := MBYIOID + ',' + (Trim(CDS_Main.fieldbyname('CIID').AsString));
//
//      Edit;
//      FieldByName('SSel').Value := False;
//      Post;
//    end;
//  end;
//  CDS_Main.EnableControls;
//
//  try
//    frmLabelPrint := TfrmLabelPrint.Create(Application);
//    with frmLabelPrint do
//    begin
//      FLMType := 'BSYarnInPrt1';
//      FFiltration1 := MBYIOID;
////      +'*'+DateToStr(BegDate.DATE)+'*'+DateToStr(EndDate.DATE
////      ShowMessage(FFiltration1);
//      if ShowModal = 1 then
//      begin
////        Self.InitGrid();
//      end;
//
//    end;
//  finally
//    frmLabelPrint.Free;
//
//  end;
end;

procedure TfrmTatDCGCLCXList.C_NameKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  // 只在按回车时触发刷新（Key = #13 是回车的 ASCII 码）
  if Key = #13 then
  begin
    InitGrid(); // 回车时执行刷新
    Key := #0; // 抑制系统默认的回车行为（比如避免输入框失去焦点等）
  end;
end;

procedure TfrmTatDCGCLCXList.JBSCPersonKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  // 只在按回车时触发刷新（Key = #13 是回车的 ASCII 码）
  if Key = #13 then
  begin
    InitGrid(); // 回车时执行刷新
    Key := #0; // 抑制系统默认的回车行为（比如避免输入框失去焦点等）
  end;
end;

procedure TfrmTatDCGCLCXList.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTatDCGCLCXList.TBdelClick(Sender: TObject);
begin
//  if CDS_Main.IsEmpty then
//    Exit;
//  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
//    Exit;
//  try
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('delete Tat_Plan_OutPut where GOID=''' + Trim(CDS_Main.fieldbyname('GOID').AsString) + '''');
//      ExecSQL;
//    end;
////////////////////       更新进度       //////////////////
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('insert into Nap_Need_Up(UType,UDataId) values(''机台刷卡'',' + quotedstr(Trim(CDS_Main.fieldbyname('GOID').AsString)) + ')  ');
//      execsql;
//    end;
////////////////////       更新进度       //////////////////
//    CDS_Main.Delete;
//  except
//    application.MessageBox('删除失败！', '提示信息', 0);
//  end;

end;

end.

