unit U_SXFHList;

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

type
  TfrmFHSQListHD = 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;
    TBExport: TToolButton;
    v1OrdDate: TcxGridDBColumn;
    v1OrdPerson1: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    v1CustomerNoName: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column4: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CustomerNoName: TEdit;
    ConPerson1: TEdit;
    MPRTCodeName: TEdit;
    ConNo: 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;
    cxGridLevel1: TcxGridLevel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v2Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label7: TLabel;
    Label10: TLabel;
    PrtCode: TEdit;
    PrtCodeName: TEdit;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    Label3: TLabel;
    SQBatchNoHZ: TEdit;
    Label6: TLabel;
    SQGCCode: TEdit;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    //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 TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CustomerNoNameChange(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);
  private
    procedure InitGrid();
    procedure InitSubGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    { Public declarations }
  end;

var
  frmFHSQListHD: TfrmFHSQListHD;

implementation

uses
  U_DataLink, U_FHSQInPut, U_Fun, U_ZDYHelp;

{$R *.dfm}



procedure TfrmFHSQListHD.FormDestroy(Sender: TObject);
begin
  frmFHSQListHD:=nil;
end;

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

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

procedure TfrmFHSQListHD.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('发货主表HD', Tv1, '发货管理');
  WriteCxGrid('发货子表HD', Tv2, '发货管理');
end;

procedure TfrmFHSQListHD.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      Sql.Add(' select A.* ');
      sql.Add(' from FHSQ_Main A');
      sql.Add(' where 1=1');
      begin
        sql.Add(' and SQDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and SQDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        SQL.Add(' and isnull(A.Chker,'''')<>'''' ');
        sql.Add(' and isnull(A.CRType,'''')=''对外销售'' ');
      end;
      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;
     { if Trim(canshu1) = '对外审核' then
      begin
        sql.Add(' and isnull(A.CRType,'''')=''对外销售'' ');
      end;
      }
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmFHSQListHD.InitForm();
begin

  ReadCxGrid('发货主表HD', Tv1, '发货管理');
  ReadCxGrid('发货子表HD', Tv2, '发货管理');

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

end;

procedure TfrmFHSQListHD.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 TfrmFHSQListHD.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '发货核对列表');
end;

procedure TfrmFHSQListHD.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  TBFind.Click;
  InitSubGrid();
end;

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

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

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

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

      end;
    end;
  finally
    frmFHSQInPut.Free;
  end;
end;

procedure TfrmFHSQListHD.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 TfrmFHSQListHD.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  FHSQ_Main SET HDPerson=''' + Trim(DName) + ''',HDTime=getdate(),HDFlag=1 ');
      sql.Add('where FSID=' + quotedstr(trim(Order_Main.fieldbyname('FSID').AsString)));
      execsql;
    end;
    Order_Main.Delete;
    InitSubGrid();
  except
    application.MessageBox('核对失败！', '提示信息', 0);
  end;
end;

procedure TfrmFHSQListHD.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 TfrmFHSQListHD.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  FHSQ_Main SET HDPerson=Null,HDTime=Null,HDFlag=0 ');
      sql.Add('where FSID=' + quotedstr(trim(Order_Main.fieldbyname('FSID').AsString)));
      execsql;
    end;
    Order_Main.Delete;
    InitSubGrid();
  except
    application.MessageBox('撤销失败！', '提示信息', 0);
  end;
end;

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

procedure TfrmFHSQListHD.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.*,B.BatchNoHZ,C.GCCode 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.*,B.BatchNoHZ,C.GCCode 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;

end.

