unit U_KHInfo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, DBClient,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, StdCtrls, ComCtrls, ExtCtrls,
  ToolWin, cxCalendar, cxButtonEdit, cxCheckBox, cxGridBandedTableView,
  cxGridDBBandedTableView;

type
  TfrmKHInfo = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    TBTP: TToolButton;
    Panel1: TPanel;
    Label3: TLabel;
    Label5: TLabel;
    OrderNo: TEdit;
    WFBCodeName: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column16: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column18: TcxGridDBBandedColumn;
    V1Column19: TcxGridDBBandedColumn;
    V1Column20: TcxGridDBBandedColumn;
    V1Column21: TcxGridDBBandedColumn;
    V1Column22: TcxGridDBBandedColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure WFBCodeNameChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBTPClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure v1Column16PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    { Private declarations }
    procedure InitGrid();
    function DelData():Boolean;
  public
    { Public declarations }
  end;

var
  frmKHInfo: TfrmKHInfo;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}

procedure TfrmKHInfo.FormDestroy(Sender: TObject);
begin
  frmKHInfo:=nil;
end;

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

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

procedure TfrmKHInfo.FormShow(Sender: TObject);
begin
  ReadCxBandedGrid('状态列表',Tv1,'无纺布订单');
  InitGrid();
end;

procedure TfrmKHInfo.WFBCodeNameChange(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 TfrmKHInfo.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxBandedGrid('状态列表',Tv1,'无纺布订单');
end;

procedure TfrmKHInfo.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alClient;
end;

procedure TfrmKHInfo.TBTPClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
  except
    Application.MessageBox('更新失败！','提示',0);
  end;
end;

function TfrmKHInfo.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Order_Sub_KC where KCId='''+Trim(Order_Main.fieldbyname('KCId').AsString)+'''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmKHInfo.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('订单状态列表',cxGrid1);
end;

procedure TfrmKHInfo.v1Column16PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='hdmc';
      flagname:='货代名称';
      if ShowModal=1 then
      begin
        Order_Main.Edit;
        Order_Main.FieldByName('OSStr1').Value:=ClientDataSet1.fieldbyname('ZDYName').AsString;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
