unit U_LSFHSQListSel;

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, cxButtonEdit,
  RM_E_llPDF, cxDropDownEdit, cxTextEdit, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdHTTP, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmLSFHSQListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    RMDB_Main: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    Panel1: TPanel;
    Label1: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    MPRTCodeName: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    Label2: TLabel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    CDS_Note: TClientDataSet;
    RM1: TRMGridReport;
    CDSUser: TClientDataSet;
    IdHTTP1: TIdHTTP;
    ToolButton1: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1OrdPerson1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label4: TLabel;
    Label5: TLabel;
    KHName: TEdit;
    YwyName: TEdit;
    Label3: TLabel;
    SQType: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column5: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Tv2Column1: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure KHNameChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitSubGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    FSQType:String;
    { Public declarations }
  end;

var
  frmLSFHSQListSel: TfrmLSFHSQListSel;

implementation

uses
  U_DataLink, U_LSFHSQInPut, U_Fun, U_ZDYHelp;

{$R *.dfm}



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

procedure TfrmLSFHSQListSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption)+'JTS', Tv1, 'JTS发货申请管理');
  WriteCxGrid(trim(self.Caption)+'JTS', Tv2, 'JTS发货申请管理');
end;

procedure TfrmLSFHSQListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      Sql.Add(' select A.*');
      sql.Add(' from SQ_FHYT_Main A');
      sql.Add(' where SQType='''+Trim(FSQType)+'''');

      sql.Add(' and filltime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
      sql.Add(' and filltime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');

      SQL.Add(' and isnull(A.Chker,'''')<>'''' ');
      SQL.Add(' and A.EndFlag=0 ');

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmLSFHSQListSel.InitForm();
begin
  ReadCxGrid(trim(self.Caption)+'JTS', Tv1, 'JTS发货申请管理');
  ReadCxGrid(trim(self.Caption)+'JTS', Tv2, 'JTS发货申请管理');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  InitGrid();

end;

procedure TfrmLSFHSQListSel.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 TfrmLSFHSQListSel.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  TBFind.Click;
  InitSubGrid();
end;

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

procedure TfrmLSFHSQListSel.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLSFHSQListSel.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmLSFHSQListSel.KHNameChange(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 TfrmLSFHSQListSel.InitSubGrid();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    if Order_Main.IsEmpty = False then
      sql.Add('select * from SQ_FHYT_Sub A where A.FHMainId=''' + Trim(Order_Main.fieldbyname('FHMainId').AsString) + '''')
    else
      sql.Add('select * from SQ_FHYT_Sub A where 1=2');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, ClientDataSet2);
  SInitCDSData20(ADOQueryTemp, ClientDataSet2);
end;

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

procedure TfrmLSFHSQListSel.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  InitSubGrid();
end;

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

procedure TfrmLSFHSQListSel.Tv1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

end.

