unit U_TradeMarketListSEL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  System.ImageList, U_BaseInput, cxContainer, cxImageList,
  dxScrollbarAnnotations, dxSkinsCore, dxSkinsDefaultPainters, cxCheckBox,
  cxCalendar, FrameDateSel;

type
  TfrmTradeMarketListSEL = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    cxImageList_bar: TcxImageList;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column16: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel1: TPanel;
    Label3: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    TMMNo: TcxTextEdit;
    CustName: TcxTextEdit;
    C_Name: TcxTextEdit;
    ConNo: TcxTextEdit;
    frmFrameDateSel1: TfrmFrameDateSel;
    ToolButton2: TToolButton;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    procedure InitGrid();
    //function SaveData(): Boolean;
    { Private declarations }
  public
    FCoType, FAuthority, FStores, FSTKName: string;
    { Public declarations }
  end;

var
  frmTradeMarketListSEL: TfrmTradeMarketListSEL;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

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

procedure TfrmTradeMarketListSEL.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmTradeMarketListSEL.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select * ');
      sql.Add(' from Trade_Market_Main A inner join Trade_Market_sub b on a.tmmid=b.tmmid  ');
      sql.Add(' where   	CustNo= ''DQ0001''');
      sql.Add('    and A.Filltime>' + quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date)));
      sql.Add('    and    A.Filltime<=' + quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date + 1)));
      SQL.ADD('AND STATUS IN (''9'',''10'')');
      Open;
    end;

    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmTradeMarketListSEL.FormShow(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.BegDate.Date := SGetServerDate(ADOQueryTemp) - 180;
  frmFrameDateSel1.EndDate.Date := SGetServerDate(ADOQueryTemp);
  InitGrid();

  ReadCxGrid('单位名称' + Trim(FCoType), TV1, '自定义数据');

end;

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

procedure TfrmTradeMarketListSEL.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid('单位名称' + Trim(FCoType), TV1, '自定义数据');

end;

procedure TfrmTradeMarketListSEL.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmTradeMarketListSEL.ToolButton2Click(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmTradeMarketListSEL.TV1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmTradeMarketListSEL.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradeMarketListSEL := nil;
end;

end.

