unit U_TradeJYXD;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxCurrencyEdit, cxImage, cxDBEdit, Menus, RM_Common, RM_Class, RM_e_Xls,
  RM_Dataset, RM_System, RM_GridReport, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxPC, cxSplitter, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, ShellAPI, cxDropDownEdit, cxCheckBox, RM_e_Graphic, RM_e_Jpeg,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, Math,
  dxDateRanges, IdExplicitTLSClientServerBase, U_BaseList, Vcl.Clipbrd,
  dxScrollbarAnnotations, cxProgressBar, FrameDateSel, dxSkinsCore,
  dxSkinsDefaultPainters;

type
  TfrmTradeJYXD = class(TfrmBaseList)
    cxgrdpmn1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    DataSource2: TDataSource;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    IdFTP1: TIdFTP;
    PopupMenu2: TPopupMenu;
    N3: TMenuItem;
    N4: TMenuItem;
    cxgrdpmn2: TcxGridPopupMenu;
    CDS_WXTS: TClientDataSet;
    N2: TMenuItem;
    GPM_3: TcxGridPopupMenu;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    CDS_1: TClientDataSet;
    DataSource3: TDataSource;
    CDS_2: TClientDataSet;
    DataSource4: TDataSource;
    CDS_4: TClientDataSet;
    CDS_3: TClientDataSet;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    Tv3Column6: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    ADO_1: TADOQuery;
    ADO_2: TADOQuery;
    ADO_3: TADOQuery;
    ADO_4: TADOQuery;
    Label2: TLabel;
    Label3: TLabel;
    Timer1: TTimer;
    Panel1: TPanel;
    ToolBar1: TToolBar;
    Label1: TLabel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1Column7: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure N1Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitGrid1();
    procedure InitGrid2();
    procedure InitGrid3();
    procedure InitGrid4();
//    procedure InitForm();

    { Private declarations }
  public
    canshu1, canshu2, canshu4, FOrdType: string;

    { Public declarations }
  end;

var
  frmTradeJYXD: TfrmTradeJYXD;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_AttachmentUpload, U_RPFun,
  U_TradeMarketInPut;

{$R *.dfm}

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

procedure TfrmTradeJYXD.FormShow(Sender: TObject);
begin
  inherited;
  InitGrid1();
  InitGrid2();

  Timer1.Enabled := true;
//  InitForm();
end;

procedure TfrmTradeJYXD.InitGrid();
begin
  InitGrid1();
  InitGrid2();
  InitGrid3();
  InitGrid4();

end;

procedure TfrmTradeJYXD.InitGrid1();
begin
  with ADO_1 do
  begin
    Close;
    sql.clear;
    sql.add('select   * from Trade_Market_MAIN  A   WHERE ISNULL(PrintStatus,0)=0 AND ORDTYPE=''门店剪样''');

    Open;
  end;
  SCreateCDS(ADO_1, CDS_1);
  SInitCDSData(ADO_1, CDS_1);
end;

procedure TfrmTradeJYXD.InitGrid2();
begin
  with ADO_2 do
  begin
    Close;
    sql.clear;
    sql.add('select   TOP 100 * from Trade_Market_MAIN  A   WHERE ISNULL(PrintStatus,0)=1 AND ORDTYPE=''门店剪样''');
    SQL.Add('ORDER BY FILLTIME DESC');
    Open;
  end;
  SCreateCDS(ADO_2, CDS_2);
  SInitCDSData(ADO_2, CDS_2);
end;

procedure TfrmTradeJYXD.InitGrid3();
begin

end;

procedure TfrmTradeJYXD.InitGrid4();
begin

end;

procedure TfrmTradeJYXD.N1Click(Sender: TObject);
var
  i: integer;
  MPCID: string;
  MPrintJson: string;
begin
  Timer1.Enabled := false;

  if CDS_2.IsEmpty = FALSE then
  begin

    MPCID := trim(CDS_2.fieldbyname('tmmid').AsString);
//        PrintCar(trim(CDS_2.fieldbyname('PCID').AsString));
    MPrintJson := '{ "LBName": "剪样小票","IsPreview": false, "PrtArgs": [ {"SqlStr": "EXEC P_Market_prt @Filtration=' + QuotedStr(MPCID) + ' " }, {"SqlStr": "EXEC P_Market_prt @Filtration=' + QuotedStr(MPCID) + '" } ] }';
//        ShowMessage(MPrintJson);
    FunPrintFR3(Application, PChar(DConString), PChar(MPrintJson));

//    CDS_1.Delete;
    Sleep(100);
  end;
  InitGrid2();
  Timer1.Enabled := true;

end;

procedure TfrmTradeJYXD.Timer1Timer(Sender: TObject);
var
  i: integer;
  MPCID: string;
  MPrintJson: string;
begin
  Timer1.Enabled := false;
  InitGrid1();
  if CDS_1.IsEmpty = FALSE then
  begin

    with CDS_1 do
    begin
      DisableControls;
      First;
      while not Eof do
      begin
        MPCID := trim(CDS_1.fieldbyname('tmmid').AsString);
//        PrintCar(trim(CDS_2.fieldbyname('PCID').AsString));
        MPrintJson := '{ "LBName": "剪样小票","IsPreview": false, "PrtArgs": [ {"SqlStr": "EXEC P_Market_prt @Filtration=' + QuotedStr(MPCID) + ' " }, {"SqlStr": "EXEC P_Market_prt @Filtration=' + QuotedStr(MPCID) + '" } ] }';
//        ShowMessage(MPrintJson);
        FunPrintFR3(Application, PChar(DConString), PChar(MPrintJson));

        CDS_1.Delete;
        Sleep(100);
      end;
      EnableControls;
    end;
  end;
  InitGrid2();
  Timer1.Enabled := true;
end;

end.

