unit U_TradeMarketList_JD;

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
  TfrmTradeMarketList_JD = class(TfrmBaseList)
    GPM4: 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;
    GPM3: TcxGridPopupMenu;
    Panel1: TPanel;
    ToolBar1: TToolBar;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column16: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    Tv4: TcxGridDBTableView;
    cxGridLevel3: TcxGridLevel;
    CDS_1: TClientDataSet;
    DataSource3: TDataSource;
    CDS_2: TClientDataSet;
    DataSource4: TDataSource;
    CDS_4: TClientDataSet;
    CDS_3: TClientDataSet;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    Tv2Column7: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    Tv3Column6: TcxGridDBColumn;
    Tv4Column1: TcxGridDBColumn;
    Tv4Column2: TcxGridDBColumn;
    Tv4Column3: TcxGridDBColumn;
    Tv4Column4: TcxGridDBColumn;
    Tv4Column5: TcxGridDBColumn;
    Tv4Column6: TcxGridDBColumn;
    Tv4Column7: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    ADO_1: TADOQuery;
    ADO_2: TADOQuery;
    ADO_3: TADOQuery;
    ADO_4: TADOQuery;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    ToolBar3: TToolBar;
    Label4: TLabel;
    ToolBar4: TToolBar;
    Label5: TLabel;
    Timer1: TTimer;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    GPM1: TcxGridPopupMenu;
    GPM2: TcxGridPopupMenu;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(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
  frmTradeMarketList_JD: TfrmTradeMarketList_JD;

implementation

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

{$R *.dfm}

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

procedure TfrmTradeMarketList_JD.FormCreate(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Self.Caption, Tv1, 'DWSY');
  ReadCxGrid(Self.Caption, Tv2, 'DWSY');
  ReadCxGrid(Self.Caption, Tv3, 'DWSY');
  ReadCxGrid(Self.Caption, Tv4, 'DWSY');
end;

procedure TfrmTradeMarketList_JD.FormShow(Sender: TObject);
begin
  inherited;
  InitGrid1();
  InitGrid2();
  InitGrid3();
  InitGrid4();

//  InitForm();
end;

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

end;

procedure TfrmTradeMarketList_JD.InitGrid1();
begin
  with ADO_1 do
  begin
    Close;
    sql.clear;
    sql.add('select  cast((case when isnull(isUrgent,'''')<>''紧急'' then 0 else 1 end )as int) as  Urgent,*  from  Trade_Market_Main A   ');
    sql.add('where 1=1 ');
    sql.add('and AddressArea=''温岭县W'' AND isnull(STORE,'''')<>''新余'' ');
    Open;
  end;
  SCreateCDS(ADO_1, CDS_1);
  SInitCDSData(ADO_1, CDS_1);
end;

procedure TfrmTradeMarketList_JD.InitGrid2();
begin
  with ADO_2 do
  begin
    Close;
    sql.clear;
    sql.add('select  cast((case when isnull(isUrgent,'''')<>''紧急'' then 0 else 1 end )as int) as  Urgent,*  from  Trade_Market_Main A	   ');
    sql.add('where 1=1');
    sql.add('and AddressArea=''东塘线D''  AND isnull(STORE,'''')<>''新余'' ');
    Open;
  end;
  SCreateCDS(ADO_2, CDS_2);
  SInitCDSData(ADO_2, CDS_2);
end;

procedure TfrmTradeMarketList_JD.InitGrid3();
begin
  with ADO_3 do
  begin
    Close;
    sql.clear;
    sql.add('select cast((case when isnull(isUrgent,'''')<>''紧急'' then 0 else 1 end )as int) as  Urgent,*  from  Trade_Market_Main A	   ');
    sql.add('where 1=1');
    sql.add('and AddressArea=''石粘线S''  AND isnull(STORE,'''')<>''新余'' ');
    Open;
  end;
  SCreateCDS(ADO_3, CDS_3);
  SInitCDSData(ADO_3, CDS_3);
end;

procedure TfrmTradeMarketList_JD.InitGrid4();
begin
  with ADO_4 do
  begin
    Close;
    sql.clear;
    sql.add('select  cast((case when isnull(isUrgent,'''')<>''紧急'' then 0 else 1 end )as int) as  Urgent,*  from  Trade_Market_Main A	   ');
    sql.add('where 1=1');
    sql.add('and AddressArea=''上洋林Y'' AND isnull(STORE,'''')<>''新余''  ');
    Open;
  end;
  SCreateCDS(ADO_4, CDS_4);
  SInitCDSData(ADO_4, CDS_4);
end;

procedure TfrmTradeMarketList_JD.N1Click(Sender: TObject);
begin
  WRITECxGrid(Self.Caption, Tv1, 'DWSY');
  WRITECxGrid(Self.Caption, Tv2, 'DWSY');
  WRITECxGrid(Self.Caption, Tv3, 'DWSY');
  WRITECxGrid(Self.Caption, Tv4, 'DWSY');
end;

procedure TfrmTradeMarketList_JD.Timer1Timer(Sender: TObject);
begin
  for var v in TArray<TcxGridDBTableView>.Create(TV1, TV2, TV3, TV4) do
  begin
    if v.DataController.RecordCount = 0 then
      Continue;

    if v.Controller.FocusedRowIndex < v.DataController.RecordCount - 1 then
    begin
      v.Controller.FocusedRowIndex := v.Controller.FocusedRowIndex + 1;
      v.Controller.MakeFocusedItemVisible;
    end
    else
    begin
      InitGrid();
      v.Controller.FocusedRowIndex := 0;
      v.Controller.MakeFocusedItemVisible;
    end;
  end;
end;

end.

