unit U_FHSQListSel2;

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, cxLookAndFeels, cxLookAndFeelPainters,
  dxBarBuiltInMenu, cxNavigator;

type
  TfrmFHSQListSel2 = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CustomerNoName: TEdit;
    MPRTCodeName: TEdit;
    HZSCConNo: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    cxTabControl1: TcxTabControl;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    Label2: TLabel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    cv1Column12: TcxGridDBColumn;
    cv1Column14: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cv2Column10: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    cv2Column4: TcxGridDBColumn;
    cv2Column12: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cv2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label3: TLabel;
    FSID: TEdit;
    cxTabControl2: TcxTabControl;
    //RMllPDFExport1: TRMllPDFExport;
    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 CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure cxTabControl2Change(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitSubGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    { Public declarations }
  end;

var
  frmFHSQListSel2: TfrmFHSQListSel2;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmFHSQListSel2.FormDestroy(Sender: TObject);
begin
  frmFHSQListSel2 := nil;
end;

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

procedure TfrmFHSQListSel2.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
end;

procedure TfrmFHSQListSel2.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('发货申请选择ZY', Tv1, '发货申请管理');
  WriteCxGrid('发货申请选择ZY', Tv2, '发货申请管理');
  Close;
end;

procedure TfrmFHSQListSel2.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      Sql.Add(' select A.*,NoteZ=A.Note,dfpshz=(SQPSHZ-isnull(FHPSHZ,0)) ');
      Sql.Add(' ,HZSCConNo=CAST((select  distinct(SCConNo) +  ''  '' from FHSQ_Sub X where A.FSID=X.FSID for xml path('''') ) AS VARCHAR(100))');
      sql.Add(' from FHSQ_Main A');

      sql.Add(' where chkstatus=''审核通过'' ');
//      sql.Add('and SQQTYHZ>isnull(FHQTYHZ,0)');
      if cxTabControl1.TabIndex <> 0 then
      begin
        sql.Add(' and SQDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and SQDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
      end;

      if cxTabControl2.TabIndex = 0 then
      begin
        sql.Add('and isnull(FHPSHZ,0)=0');
      end;
      if cxTabControl2.TabIndex = 1 then
      begin
        sql.Add('and isnull(FHPSHZ,0)>0');
      end;
      SQL.Add('order by sqdate desc');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmFHSQListSel2.InitForm();
begin
  ReadCxGrid('发货申请选择ZY', Tv1, '发货申请管理');
  ReadCxGrid('发货申请选择ZY', Tv2, '发货申请管理');

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 7;
  InitGrid();

end;

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

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

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

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

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

procedure TfrmFHSQListSel2.cxTabControl1Change(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmFHSQListSel2.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    if Order_Main.IsEmpty = False then
    begin
      sql.Add('select A.* from FHSQ_Sub A ');
//      sql.Add(' inner join CLoth_Sub B on A.SubId=B.SubId');
//      sql.Add(' inner join CLoth_Main C on B.MainId=C.MainId');
      sql.Add(' where A.FSId=''' + Trim(Order_Main.fieldbyname('FSId').AsString) + '''');
    end
    else
    begin
      sql.Add('select A.* from FHSQ_Sub A ');
//      sql.Add(' inner join CLoth_Sub B on A.SubId=B.SubId');
//      sql.Add(' inner join CLoth_Main C on B.MainId=C.MainId');
      sql.Add('  where 1=2');
    end;

    Open;
  end;
  SCreateCDS20(ADOQueryTemp, ClientDataSet2);
  SInitCDSData20(ADOQueryTemp, ClientDataSet2);
end;

procedure TfrmFHSQListSel2.ToolButton2Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmFHSQListSel2.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ModalResult := 1;
end;

procedure TfrmFHSQListSel2.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ToolButton2.Click;
end;

procedure TfrmFHSQListSel2.cxTabControl2Change(Sender: TObject);
begin
  InitGrid();
end;

end.

