unit U_TatWBOutputList_XZ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, MovePanel, cxButtonEdit, cxCalendar, RM_System, RM_Common,
  RM_Class, RM_GridReport, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, cxCheckBox, Vcl.Menus, dxSkinWXI, dxScrollbarAnnotations,
  FrameDateTimeSel, cxContainer, cxTextEdit, U_SLTGDTP, cxMemo, Vcl.Imaging.jpeg,
  dxSkinBasic, dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel,
  dxSkinCoffee, dxSkinDarkroom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinOffice2016Colorful,
  dxSkinOffice2016Dark, dxSkinOffice2019Black, dxSkinOffice2019Colorful,
  dxSkinOffice2019DarkGray, dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringtime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinTheBezier, dxSkinValentine, dxSkinVisualStudio2013Blue,
  dxSkinVisualStudio2013Dark, dxSkinVisualStudio2013Light, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue, cxPC;

type
  TfrmTatWBOutputList_XZ = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    pcid: TcxTextEdit;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    MovePanel2: TMovePanel;
    RMGridReport1: TRMGridReport;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    TBdel: TToolButton;
    ToolButton1: TToolButton;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Label4: TLabel;
    GlideName: TcxTextEdit;
    Tv1Column17: TcxGridDBColumn;
    ToolButton2: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    frmFrameDateTimeSel1: TfrmFrameDateTimeSel;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1Column18: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1SPName: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    ADO_2: TADOQuery;
    CDS_2: TClientDataSet;
    GPM_2: TcxGridPopupMenu;
    DS_2: TDataSource;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    adoqueryPicture: TADOQuery;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    Tv1Column33: TcxGridDBColumn;
    Tv1Column34: TcxGridDBColumn;
    Tv1Column35: TcxGridDBColumn;
    Tv1Column36: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    Panel3: TPanel;
    Label1: TLabel;
    XGPrice: TcxTextEdit;
    Button2: TButton;
    Button1: TButton;
    Tv1Column13: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure pcidChange(Sender: TObject);
    procedure TBdelClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure pcidPropertiesChange(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TextEdit(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Tv1Column13PropertiesEditValueChanged(Sender: TObject);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    procedure setstatus();
    procedure initZX();
    procedure InitImages();
    { Private declarations }
  public
    fsyrName, canshu1, canshu2: string;
    { Public declarations }
  end;

var
  frmTatWBOutputList_XZ: TfrmTatWBOutputList_XZ;
  Mach: array of TfrmSLTGDTP;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_OutPutHelp;

{$R *.dfm}
procedure TfrmTatWBOutputList_XZ.InitImages();
var
  i, j: integer;
  jpg: TJpegImage;
  myStream: TADOBlobStream;
begin
  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  if CDS_Main.IsEmpty then
    exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add('select * from TP_File A');
      sql.Add('where isnull(WBID,'''')<>'''' and WBID=' + quotedstr(Trim(CDS_Main.fieldbyname('GOID').AsString)));
      open;
    end;
    j := adoqueryPicture.RecordCount;
    if j < 1 then
      exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg := TJpegImage.Create();
    for i := 0 to j - 1 do
    begin
      if triM(adoqueryPicture.fieldbyname('FilesOther').AsString) <> '' then
      begin
        myStream := tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')), bmread);
        jpg.LoadFromStream(myStream);
        Mach[i] := TfrmSltGDTP.Create(Self);
        Mach[i].Name := trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[i].Left := 0 + i * 165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString, adoqueryPicture.fieldbyname('FileName').AsString, jpg, adoqueryPicture.fieldbyname('URL').AsString, Trim(CDS_Main.fieldbyname('GOID').AsString));
      end;
      adoqueryPicture.Next;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmTatWBOutputList_XZ.initZX();
begin
  with ADO_2 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* from Tat_WB_Formula A inner join Tat_WB_Spec B on A.WBSID=B.WBSID ');
    sql.Add(' where WB_Code=''' + Trim(CDS_Main.fieldbyname('WB_Code').AsString) + '''');
//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS(ADO_2, CDS_2);
  SInitCDSData(ADO_2, CDS_2);
end;

procedure TfrmTatWBOutputList_XZ.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTatWBOutputList_XZ := nil;
end;

procedure TfrmTatWBOutputList_XZ.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  initgrid();
end;

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

procedure TfrmTatWBOutputList_XZ.FormCreate(Sender: TObject);
begin
  inherited;

  frmFrameDateTimeSel1.EndDate.Date := SGetServerDateTime(ADOQueryTemp);
  frmFrameDateTimeSel1.BegDate.Date := frmFrameDateTimeSel1.EndDate.Date - 30;
  fsyrName := trim(DdataBase);
  canshu1 := trim(DParameters1);
end;

procedure TfrmTatWBOutputList_XZ.InitGrid();
var
  Msql, mbegdate, menddate: string;
  SqlStr: string;
begin

  mbegdate := FormatDateTime('yyyy-MM-dd', frmFrameDateTimeSel1.begdate.Date) + ' ' + FormatDateTime('HH:nn', frmFrameDateTimeSel1.begTime.Time);
  menddate := FormatDateTime('yyyy-MM-dd', frmFrameDateTimeSel1.enddate.Date) + ' ' + FormatDateTime('HH:nn', frmFrameDateTimeSel1.endTime.Time);
  SqlStr := 'select A.GOID,A.GOTime,A.StaffId,A.StaffName,A.PCID,A.GlideName,A.FillTime,A.Qty,A.OutMoney,A.Price,A.Reward,A.Fine,A.JCSM        ';
  SqlStr := SqlStr + ',B.WB_Code,B.WB_Name,B.WB_MachNo,B.WB_Macher,B.WB_Code,B.WB_Code,B.WB_YarnLen,B.WB_YarnQty,B.WB_YarnArr  ';
  SqlStr := SqlStr + ',B.Note,B.WB_Arg_QJZL,B.WB_Move,B.WB_Arg_SDWZ,B.WB_Arg_PXDS,B.WB_ReedNote,B.WB_ReedNo,B.WB_Width,B.WB_YarnStripRemainder,B.WB_YarnStripQty  ';
  SqlStr := SqlStr + ',JGSJ=DATEDIFF(MI, A.FillTime, A.EndTime)       ';
  SqlStr := SqlStr + ' ,Money=round(( isnull(Price,0)* isnull(Qty,0) + isnull(Reward,0) - isnull(Fine,0)  ),2) ';
  SqlStr := SqlStr + ' from Tat_Plan_OutPut A left join Tat_WB_Card B on A.PCID=B.WBCID ';
  SqlStr := SqlStr + 'where GlideName=''接头''  and A.GOTime>=''' + trim(mbegdate) + ''' ';
  SqlStr := SqlStr + 'and A.GOTime<''' + trim(menddate) + ''' ';

  case cxTabControl1.TabIndex of
    0:
      begin
        SqlStr := SqlStr + ' and isnull(ISDZ,0) = 0';
      end;
    1:
      begin
        SqlStr := SqlStr + ' and isnull(ISDZ,0) = 1';
      end;
    2:
      begin

      end;
  end;

  SqlStr := SqlStr + 'order by GOTime,pcid';

  InitCDSData(ADOQueryMain, CDS_Main, Tv1, SqlStr, SGetFilters(Panel1, 1, 2), 'GOID');
  initZX();
  InitImages();
end;

procedure TfrmTatWBOutputList_XZ.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

procedure TfrmTatWBOutputList_XZ.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmTatWBOutputList_XZ.TBRafreshClick(Sender: TObject);
begin
//  MovePanel2.Visible := True;
//  MovePanel2.Refresh;
  ToolBar1.SetFocus;
  InitGrid();
//  MovePanel2.Visible := False;
end;

procedure TfrmTatWBOutputList_XZ.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(self.Caption + tv1.Name, Tv1, '成品仓库');
end;

procedure TfrmTatWBOutputList_XZ.ToolButton2Click(Sender: TObject);
var
  MGOIDS: string;
begin
  if CDS_Main.IsEmpty then
    exit;

  if not CDS_Main.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;

  with CDS_Main do
  begin
    DisableControls;
    while CDS_Main.Locate('SSel', True, []) do
    begin
      MGOIDS := MGOIDS + Trim(CDS_Main.fieldbyname('GOID').AsString) + ',';
      CDS_Main.Delete;
    end;
    EnableControls;
  end;
  try
    frmOutPutHelp := TfrmOutPutHelp.Create(Application);
    with frmOutPutHelp do
    begin
      FGOIDS := MGOIDS;
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmOutPutHelp.Free;
  end;
end;

procedure TfrmTatWBOutputList_XZ.ToolButton3Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := SelCDSKey(CDS_Main, ['GOID'])[0];
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Plan_OutPut_DZ ');
      Sql.Add(' @GOIDS=' + quotedstr(Trim(WSql)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
    application.MessageBox('对账成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatWBOutputList_XZ.ToolButton4Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := SelCDSKey(CDS_Main, ['GOID'])[0];
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Plan_OutPut_CXDZ ');
      Sql.Add(' @GOIDS=' + quotedstr(Trim(WSql)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
    application.MessageBox('撤销对账成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatWBOutputList_XZ.ToolButton5Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  Panel3.Visible := true;
  CDS_Main.DisableControls;
end;

procedure TfrmTatWBOutputList_XZ.TextEdit(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      FieldByName('Money').Value := CDS_Main.fieldbyname('Price').asfloat * CDS_Main.fieldbyname('Qty').asfloat + CDS_Main.fieldbyname('Reward').asfloat - CDS_Main.fieldbyname('Fine').asfloat;
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate Tat_Plan_OutPut ');
      sql.Add(' Set ' + FFieldName + '=' + Trim(mvalue) + '');
      sql.Add(' where GOID=' + QuotedStr(CDS_Main.fieldbyname('GOID').AsString));
//      ShowMessage(sql.text);
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv1.Controller.EditingController.ShowEdit();
  except
    tv1.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmTatWBOutputList_XZ.Tv1Column13PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);

  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate Tat_Plan_OutPut ');
      sql.Add(' Set ' + FFieldName + '=''' + Trim(mvalue) + '''');
      sql.Add(' where GOID=' + QuotedStr(CDS_Main.fieldbyname('GOID').AsString));
//      ShowMessage(sql.text);
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv1.Controller.EditingController.ShowEdit();
  except
    tv1.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmTatWBOutputList_XZ.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  initZX();
  InitImages();
end;

procedure TfrmTatWBOutputList_XZ.Button1Click(Sender: TObject);
begin
  Panel3.Visible := false;
  CDS_Main.EnableControls;
  XGPrice.text := '';
end;

procedure TfrmTatWBOutputList_XZ.Button2Click(Sender: TObject);
var
  WSql: string;
begin
  WSql := SelCDSKey(CDS_Main, ['GOID'])[0];
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Plan_OutPut_Price ');
      Sql.Add(' @GOIDS=' + quotedstr(Trim(WSql)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Sql.Add(',@Price=' + floattostr(strtofloatdef(XGPrice.text, 0)));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;

    Panel3.Visible := false;
    CDS_Main.EnableControls;
    XGPrice.text := '';
    InitGrid();
    application.MessageBox('修改成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatWBOutputList_XZ.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmTatWBOutputList_XZ.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmTatWBOutputList_XZ.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(self.Caption + tv1.Name, Tv1, '成品仓库');
  canshu1 := self.fParameters1;
  canshu2 := self.fParameters2;
  setstatus();
  initgrid();
end;

procedure TfrmTatWBOutputList_XZ.setstatus();
begin
  ToolButton3.Enabled := False;
  ToolButton4.Enabled := False;
  TBdel.Enabled := False;
  ToolButton5.Enabled := False;

  Tv1Column35.Options.Editing := false;
  Tv1Column36.Options.Editing := false;

  case cxTabControl1.TabIndex of
    0:
      begin
        ToolButton3.Enabled := true;
        TBdel.Enabled := true;
        ToolButton5.Enabled := true;

        Tv1Column35.Options.Editing := true;
        Tv1Column36.Options.Editing := true;

      end;
    1:
      begin
        ToolButton4.Enabled := true;

      end;
    2:
      begin

      end;
  end;

end;

procedure TfrmTatWBOutputList_XZ.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel(self.Caption, cxGrid1);
end;

procedure TfrmTatWBOutputList_XZ.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
    initZX();
    InitImages();
  end;
end;

procedure TfrmTatWBOutputList_XZ.pcidChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTatWBOutputList_XZ.pcidPropertiesChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTatWBOutputList_XZ.TBdelClick(Sender: TObject);
var
  WSql: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := SelCDSKey(CDS_Main, ['GOID'])[0];
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Plan_OutPut_Del ');
      Sql.Add(' @GOIDS=' + quotedstr(Trim(WSql)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
    application.MessageBox('删除成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

end.

