unit U_TradeDefectKCListSel;

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, dxSkinsCore, dxSkinsDefaultPainters, cxNavigator,
  dxDateRanges, dxBarBuiltInMenu, System.ImageList, U_BaseInput, cxButtonEdit,
  cxDropDownEdit, cxCheckBox, Vcl.Menus, cxPC, dxScrollbarAnnotations;

type
  TfrmTradeDefectKCListSel = 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;
    Label1: TLabel;
    OrderNo: TEdit;
    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;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxGrid2: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TV1Column1: TcxGridDBColumn;
    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 OrderNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority: string;
    { Public declarations }
  end;

var
  frmTradeDefectKCListSel: TfrmTradeDefectKCListSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

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

procedure TfrmTradeDefectKCListSel.OrderNoChange(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 TfrmTradeDefectKCListSel.cxTabControl1Change(Sender: TObject);
begin
  inherited;
  InitGrid();
end;

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

  OrderNo.SetFocus;

  Action := cahide;
end;

procedure TfrmTradeDefectKCListSel.InitGrid();
var
  WSql: string;
begin
  WSql := WSql + ' and ConDate>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
  WSql := WSql + ' and ConDate<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select B.BuyConNo,A.* from Trade_Cloth_Inspect A  Left join Trade_Plan_Sub B on A.SubID=B.SubID   where A.Grade=''次品'' ');
      sql.Add('and A.ProcessType=''索赔'' and not EXISTS (select CIID from Claims_Sub X where X.CIID=A.CIID) ');

      sql.Add('Order By A.FillTime ');
//      ShowMessage(sql.text);
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

end;

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

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

  InitGrid();

  ReadCxGrid(Trim(self.Caption), TV1, '自定义数据');

end;

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

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

end;

procedure TfrmTradeDefectKCListSel.ToolButton1Click(Sender: TObject);
var
  Count: Integer;
  Value: string;
begin
//  OrderNo.SetFocus;
//  Count := 1;
////  value :=FConNo;
//  with CDS_1 do
//  begin
//    First;
//    while not Eof do
//    begin
//      if CDS_1.fieldbyname('SSel').AsBoolean then
//      begin
//        if Value = '' then
//        begin
//          Value := FieldByName('ConNo').AsString;
//        end;
//        if Value <> '' then
//        begin
//          if Value <> FieldByName('ConNo').AsString then
//          begin
//            Count := Count + 1;
//          end;
//        end;
//      end;
//
//      Next;
//    end;
//  end;
//  if Count = 1 then
//  begin
    ModalResult := 1;
//  end
//  else
//  begin
//    application.MessageBox('选择的不是同一销售合同！', '提示信息');
//    exit;
//  end;
end;

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

procedure TfrmTradeDefectKCListSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradeDefectKCListSel := nil;
end;

end.

