unit U_ContractSelList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_e_Xls,
  Menus, cxPC, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans,
  dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter,
  cxNavigator;

type
  TfrmContractSelList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    v1OrdDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1PRTPrice: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label9: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CustomerNoName: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    ToolButton2: TToolButton;
    v1Column13: TcxGridDBColumn;
    MPRTType: TComboBox;
    Label2: TLabel;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    FConNo: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure FConNoKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    FLXStr,KHCode:string;

    { Public declarations }
  end;

var
  frmContractSelList: TfrmContractSelList;

implementation
uses
  U_DataLink,U_Fun10;   //U_ConInPut,

{$R *.dfm}

procedure TfrmContractSelList.FormDestroy(Sender: TObject);
begin
  frmContractSelList:=nil;
end;

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

procedure TfrmContractSelList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmContractSelList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('订单合同列表选择X',Tv1,'生产指示单管理');
end;

procedure TfrmContractSelList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.conno as FConNo,A.*,B.* ');
      sql.Add(' from JYOrderCon_Main A  ');
      sql.Add(' inner join JYOrderCon_Sub B on A.MainId=B.MainId');
      SQL.Add(' where  A.OrdDate>='''+FormatDateTime('yyyy-MM-dd',BegDate.DateTime)+'''');
      SQL.Add(' and  A.OrdDate<'''+FormatDateTime('yyyy-MM-dd',enddate.DateTime+1)+'''');
      if Trim(KHCode)<>'' then
      begin
        sql.Add(' and isnull(A.CustomerNoName,'''')='''+Trim(KHCode)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally;
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmContractSelList.InitForm();
begin
  ReadCxGrid('订单合同列表选择X',Tv1,'生产指示单管理');
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-30;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmContractSelList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;



procedure TfrmContractSelList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmContractSelList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmContractSelList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmContractSelList.FConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(FConNo.Text)<3 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add('select A.*,B.* ');
        sql.Add(' from JYOrderCon_Main A  ');
        sql.Add(' inner join JYOrderCon_Sub B on A.MainId=B.MainId');
        SQL.Add('where  1=1');
        sql.Add(' and A.ConNo like '''+'%'+Trim(FConNo.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

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

procedure TfrmContractSelList.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ModalResult:=1;
end;

end.
