unit U_LSFHSQListHD;

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, dxBarBuiltInMenu;

type
  TfrmLSFHSQListHD = 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;
    v1OrdPerson1: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    ToolButton1: TToolButton;
    v1Column4: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    KHName: TEdit;
    YwyName: TEdit;
    MPRTCodeName: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    cxTabControl1: TcxTabControl;
    tchk: TToolButton;
    Tnochk: TToolButton;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    v1Column8: TcxGridDBColumn;
    Label2: TLabel;
    //RMllPDFExport1: TRMllPDFExport;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column11: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Label3: TLabel;
    SQType: TEdit;
    Tv2Column1: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: 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 ToolButton1Click(Sender: TObject);
    procedure KHNameChange(Sender: TObject);
    procedure tchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure FormDestroy(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitSubGrid();
    procedure InitForm();

    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    { Public declarations }
  end;
var
  frmLSFHSQListHD: TfrmLSFHSQListHD;

implementation

uses
  U_DataLink, U_LSFHSQInPut, U_Fun, U_ZDYHelp;

{$R *.dfm}


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

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

procedure TfrmLSFHSQListHD.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 1=1');
      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,'''')<>'''' ');
      if cxTabControl1.TabIndex = 0 then
      begin
        SQL.Add(' and isnull(A.HDPerson,'''')='''' ');
      end else
      if cxTabControl1.TabIndex = 1 then
      begin
        SQL.Add(' and isnull(A.HDPerson,'''')<>'''' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmLSFHSQListHD.InitForm();
begin

  ReadCxGrid(trim(self.Caption), Tv1, 'JTS发货申请管理');
  ReadCxGrid(trim(self.Caption), Tv2, 'JTS发货申请管理');

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

end;

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

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

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

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

procedure TfrmLSFHSQListHD.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmLSFHSQInPut := TfrmLSFHSQInPut.Create(Application);
    with frmLSFHSQInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('FHMainId').AsString);
      ToolBar2.Visible := False;
      TBSave.Visible := False;
      ScrollBox1.Enabled := False;
      Tv1.OptionsSelection.CellSelect := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmLSFHSQInPut.Free;
  end;
end;

procedure TfrmLSFHSQListHD.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 TfrmLSFHSQListHD.tchkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if cxTabControl1.TabIndex <> 0 then
    exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  SQ_FHYT_Main SET HDPerson=''' + Trim(DName) + ''',HDTime=getdate(),HDFlag=1 ');
      sql.Add('where FHMainId=' + quotedstr(trim(Order_Main.fieldbyname('FHMainId').AsString)));
      execsql;
    end;
    Order_Main.Delete;
    InitSubGrid();
  except
    application.MessageBox('核对失败！', '提示信息', 0);
  end;
end;

procedure TfrmLSFHSQListHD.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 TfrmLSFHSQListHD.TnochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if cxTabControl1.TabIndex <> 1 then
    exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;

  try

    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  SQ_FHYT_Main SET HDPerson=Null,HDTime=Null,HDFlag=0 ');
      sql.Add('where FHMainId=' + quotedstr(trim(Order_Main.fieldbyname('FHMainId').AsString)));
      execsql;
    end;
    Order_Main.Delete;
    InitSubGrid();
  except
    application.MessageBox('撤销失败！', '提示信息', 0);
  end;
end;

procedure TfrmLSFHSQListHD.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

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

procedure TfrmLSFHSQListHD.FormDestroy(Sender: TObject);
begin
  frmLSFHSQListHD:=nil;
end;

end.

