unit U_MarketValueSel;

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, cxButtonEdit,
  cxDropDownEdit, cxCheckBox, Vcl.Menus,  dxScrollbarAnnotations,
      
     
     
     
     
    
    
    
    
    
     
     
     
    
    
    cxContainer, cxImageList, cxPC,
  FrameDateSel;

type
  TfrmMarketValueSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    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;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label2: TLabel;
    C_Name: TcxTextEdit;
    Label3: TLabel;
    BuyName: TcxTextEdit;
    Label4: TLabel;
    GC_Name: TcxTextEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1Column7: TcxGridDBColumn;
    VC_SCSCode: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    v1PRTPrice: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    Tv1Column33: TcxGridDBColumn;
    Tv1Column34: TcxGridDBColumn;
    Label1: TLabel;
    Label5: TLabel;
    CraftCode: TcxTextEdit;
    MVCNo: TcxTextEdit;
    cxImageList_bar: TcxImageList;
    frmFrameDateSel1: TfrmFrameDateSel;
    cxTabControl1: TcxTabControl;
    ToolButton2: TToolButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure BuyNamePropertiesChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority, FConNo, FC_Code: string;
    { Public declarations }
  end;

var
  frmMarketValueSel: TfrmMarketValueSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmMarketValueSel.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 TfrmMarketValueSel.BuyNamePropertiesChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmMarketValueSel.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMarketValueSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  BuyName.SetFocus;

  Action := cahide;
end;

procedure TfrmMarketValueSel.InitGrid();
var
  WSql, SqlStr: string;
begin
  WSql := SGetFilters(Panel1, 1, 2);

  SqlStr := SqlStr + ' select * from MV_Cloth_Main A left join MV_Cloth_sub B on A.MVCMID=B.MVCMID';
  SqlStr := SqlStr + ' where MVCType=''报价'' ';
  SqlStr := SqlStr + ' and MVCDate>=' + quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date));
  SqlStr := SqlStr + ' and MVCDate<' + quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date + 1));
  SqlStr := SqlStr + ' and  isnull(status,''0'')<>''-1'' ';
//  case cxTabControl1.TabIndex of
//    0:
//      begin
//        SqlStr := SqlStr + ' and  isnull(status,''0'')=''0''';
//      end;
//    1:
//      begin
//        SqlStr := SqlStr + ' and  isnull(status,''0'')=''1''';
//      end;
//    2:
//      begin
//        SqlStr := SqlStr + ' and  isnull(status,''0'')=''9''';
//      end;
//    3:
//      begin
//        SqlStr := SqlStr + ' and  isnull(status,''0'')=''-1''';
//      end;
//  end;

  if Trim(GC_Name.Text) <> '' then
  begin
    SqlStr := SqlStr + ' and  isnull(Price,0)<>0 ';
  end;

//  showmessage(SqlStr);

  InitCDSData(ADOQueryMain, CDS_1, Tv1, SqlStr, WSql, 'MVCNo');

end;

procedure TfrmMarketValueSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);

end;

procedure TfrmMarketValueSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);
end;

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

  ReadCxGrid(Trim(self.Caption), TV1, '自定义数据');
  frmFrameDateSel1.EndDate.Date := SGetServerDate(ADOQueryTemp);
  frmFrameDateSel1.BegDate.Date := frmFrameDateSel1.EndDate.Date - 90;
  InitGrid();
end;

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

procedure TfrmMarketValueSel.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption), TV1, '自定义数据');

end;

procedure TfrmMarketValueSel.ToolButton1Click(Sender: TObject);
begin
  BuyName.SetFocus;
  ModalResult := 1;
end;

procedure TfrmMarketValueSel.ToolButton2Click(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmMarketValueSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmMarketValueSel := nil;
end;

end.

