unit U_YYBB;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxPC, cxCheckComboBox, cxDropDownEdit, Menus, RM_e_Xls, TeEngine,
  Series, TeeProcs, Chart, DbChart, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxBarBuiltInMenu;

type
  TfrmYYBB = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    MachineNo: TEdit;
    RMXLSExport2: TRMXLSExport;
    v2Column8: TcxGridDBColumn;
    Label1: TLabel;
    v2Column12: TcxGridDBColumn;
    ToolButton3: TToolButton;
    ADOQueryPrt: TADOQuery;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    Tv2Column2: TcxGridDBColumn;
    CDS_DB: TClientDataSet;
    DS_DB: TDataSource;
    ADOQuerySub: TADOQuery;
    ToolButton6: TToolButton;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    Label2: TLabel;
    Fault: TEdit;
    Label3: TLabel;
    Filler: TEdit;
    Label4: TLabel;
    repairMan: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Timer1: TTimer;
    Tv2Column1: TcxGridDBColumn;
    ADOQuery1: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CustomerChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure v2Column8PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    procedure PrintReport(FZDYNo: string);
    procedure InitGrid();
    procedure InitGridDB();
    procedure InitGridBB();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage: string;
    JTH, JXG: string;
    SJ1000: Integer;
  end;

var
  frmYYBB: TfrmYYBB;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, MMSystem;

{$R *.dfm}

procedure TfrmYYBB.PrintReport(FZDYNo: string);
var
  fPrintFile, FFCYID: string;
  i, j: Integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if CDS_HZ.IsEmpty then
    Exit;

  ExportFtErpFile('托盘标签.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\托盘标签.rmf';
  with ADOQueryPrt do
  begin
    close;
    sql.Clear;
    sql.Add(' select * from  BS_Tray where TYId=''' + Trim(FZDYNo) + '''');
    open;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(FZDYNo);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    CDS_HZ.EnableControls;
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;
  RMVariables['QRBARCODE'] := fImagePath;
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.PrintReport;
  //  RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile + '!'), '提示', 0);
    Exit;
  end;
end;

procedure TfrmYYBB.InitGrid();
begin
  Timer1.Enabled := false;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* ');
      sql.Add(' ,CASE WHEN(isnull(status,0)=0) THEN Cast(0 as bit) else Cast(1 as bit) END AS isYD    ');
      sql.Add(' ,CASE WHEN(BegTime is not null and FillTime is not null  ) THEN DATEDIFF(mi, FillTime, BegTime) ELSE '''' END AS YDLong ');
      sql.Add(' ,CASE WHEN(BegTime is not null and endTime is not null  ) THEN DATEDIFF(mi, BegTime, endTime) ELSE '''' END AS WXLong ');
      sql.Add(' ,CASE WHEN(DATEDIFF(mi, Filltime, GETDATE())>10 and isnull(status,0)=0 ) THEN 1 ELSE 0 END AS yellow ');
      sql.Add(' ,CASE WHEN(DATEDIFF(mi, Filltime, GETDATE())>30 and isnull(status,0)=0 ) THEN 1 ELSE 0 END AS red ');
      sql.Add(' from  MachineBy_History A  ');
      sql.Add(' where ByType =''维修''  ');
      sql.add(' and Filltime>=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
      sql.Add(' and Filltime<=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1))));
      sql.Add(' order by status,Filltime  desc  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from MachineBy_History where ByType =''维修'' and isBB =''否'' ');
//      ShowMessage(sql.text);
    open;
  end;
  if ADOQuery1.IsEmpty = False then
  begin

    with CDS_HZ do
    begin
      CDS_HZ.Locate('isBB', '否', []);
    end;

    InitGridBB();

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE MachineBy_History set isBB =''是'' where BYID=' + quotedstr(trim(CDS_HZ.FieldByName('BYID').AsString)) + '');
//      ShowMessage(sql.text);
      ExecSQL;
    end;

  end;
  Sleep(2000);
  Timer1.Enabled := true;
end;

procedure TfrmYYBB.InitGridBB();
begin
  JTH := trim(CDS_HZ.FieldByName('MachineNo').AsString);
  JXG := trim(CDS_HZ.FieldByName('repairMan').AsString);
  SJ1000 := 600;
  Sleep(SJ1000);
  if JTH <> '' then
  begin
    /////////第一位 ////////
    if Copy(JTH, 1, 1) = 'S' then
    begin
      PlaySound('wav\S.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 1, 1) = 'A' then
    begin
      PlaySound('wav\A.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end;
    /////////第一位 ////////

    /////////第二位 ////////
    if Copy(JTH, 2, 1) = 'Z' then
    begin
      PlaySound('wav\Z.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '0' then
    begin
      PlaySound('wav\0.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '1' then
    begin
      PlaySound('wav\1.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '2' then
    begin
      PlaySound('wav\2.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '3' then
    begin
      PlaySound('wav\3.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '4' then
    begin
      PlaySound('wav\4.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '5' then
    begin
      PlaySound('wav\5.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '6' then
    begin
      PlaySound('wav\6.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '7' then
    begin
      PlaySound('wav\7.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '8' then
    begin
      PlaySound('wav\8.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 2, 1) = '9' then
    begin
      PlaySound('wav\9.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end;
    /////////第二位 ////////

    /////////第三位 ////////
    if Copy(JTH, 3, 1) = '0' then
    begin
      PlaySound('wav\0.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '1' then
    begin
      PlaySound('wav\1.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '2' then
    begin
      PlaySound('wav\2.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '3' then
    begin
      PlaySound('wav\3.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '4' then
    begin
      PlaySound('wav\4.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '5' then
    begin
      PlaySound('wav\5.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '6' then
    begin
      PlaySound('wav\6.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '7' then
    begin
      PlaySound('wav\7.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '8' then
    begin
      PlaySound('wav\8.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 3, 1) = '9' then
    begin
      PlaySound('wav\9.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end;
    /////////第三位 ////////

    /////////第四位 ////////
    if Copy(JTH, 4, 1) = '0' then
    begin
      PlaySound('wav\0.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '1' then
    begin
      PlaySound('wav\1.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '2' then
    begin
      PlaySound('wav\2.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '3' then
    begin
      PlaySound('wav\3.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '4' then
    begin
      PlaySound('wav\4.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '5' then
    begin
      PlaySound('wav\5.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '6' then
    begin
      PlaySound('wav\6.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '7' then
    begin
      PlaySound('wav\7.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '8' then
    begin
      PlaySound('wav\8.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 4, 1) = '9' then
    begin
      PlaySound('wav\9.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end;
    /////////第四位 ////////

     /////////第五位 ////////
    if Copy(JTH, 5, 1) = '0' then
    begin
      PlaySound('wav\0.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '1' then
    begin
      PlaySound('wav\1.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '2' then
    begin
      PlaySound('wav\2.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '3' then
    begin
      PlaySound('wav\3.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '4' then
    begin
      PlaySound('wav\4.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '5' then
    begin
      PlaySound('wav\5.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '6' then
    begin
      PlaySound('wav\6.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '7' then
    begin
      PlaySound('wav\7.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '8' then
    begin
      PlaySound('wav\8.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end
    else if Copy(JTH, 5, 1) = '9' then
    begin
      PlaySound('wav\9.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(SJ1000);
    end;
    /////////第五位 ////////
  end;
  if JXG <> '' then
  begin
    PlaySound('wav\呼叫.wav', 0, SND_FILENAME or SND_ASYNC);
    Sleep(1500);
    if JXG = '费建军' then
    begin
      PlaySound('wav\费建军.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '李川阳' then
    begin
      PlaySound('wav\李川阳.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '李家申' then
    begin
      PlaySound('wav\李家申.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '李金荣' then
    begin
      PlaySound('wav\李金荣.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '李俊' then
    begin
      PlaySound('wav\李俊.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '刘志虎' then
    begin
      PlaySound('wav\刘志虎.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '娄国芳' then
    begin
      PlaySound('wav\娄国芳.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '骆永军' then
    begin
      PlaySound('wav\骆永军.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '邵茂军' then
    begin
      PlaySound('wav\邵茂军.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '王龙夫' then
    begin
      PlaySound('wav\王龙夫.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '熊启川' then
    begin
      PlaySound('wav\熊启川.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '余金龙' then
    begin
      PlaySound('wav\余金龙.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '赵奇荣' then
    begin
      PlaySound('wav\赵奇荣.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end
    else if JXG = '周游' then
    begin
      PlaySound('wav\周游.wav', 0, SND_FILENAME or SND_ASYNC);
      Sleep(1500);
    end;
  end;

end;

procedure TfrmYYBB.InitGridDB();
begin
  try
    ADOQuerySub.DisableControls;
    with ADOQuerySub do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,NextDayS=DateDiff(day, GetDate(),NextTime) ');
      sql.Add(' from  DB_Thing A ORDER BY isnull(DateDiff(day, GetDate(),NextTime),9999)  ');
//      ShowMessage(SQL.text);
      Open;
    end;
    SCreateCDS20(ADOQuerySub, CDS_DB);
    SInitCDSData20(ADOQuerySub, CDS_DB);
  finally
    ADOQuerySub.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmYYBB.FormDestroy(Sender: TObject);
begin
  frmYYBB := nil;
end;

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

procedure TfrmYYBB.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption) + '22', Tv2, '机台管理');
  Close;
end;

procedure TfrmYYBB.FormShow(Sender: TObject);
begin
  ReadCxGrid(Trim(Self.Caption) + '22', Tv2, '机台管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime - 30;
//  InitGrid();

end;

procedure TfrmYYBB.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
//  InitGridDB();
end;

procedure TfrmYYBB.ToolButton2Click(Sender: TObject);
var
  sql: string;
begin
  if ADOQueryMain.Active then
  begin
    sql := SGetFilters(Panel1, 1, 2);
    SDofilter(ADOQueryMain, sql);
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmYYBB.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv2, ADOQueryMain, trim(Self.Caption));
end;

procedure TfrmYYBB.cxTabControl1Change(Sender: TObject);
begin
  InitGrid;
end;

procedure TfrmYYBB.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := true;
      post;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmYYBB.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := false;
      post;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmYYBB.CustomerChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYYBB.FormCreate(Sender: TObject);
begin
  fmanage := Trim(DParameters1);
end;

procedure TfrmYYBB.v2Column8PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate BS_Tray ');
      sql.Add(' Set ' + FFieldName + '=''' + Trim(mvalue) + '''');
      sql.Add(' , Editer=''' + Trim(DName) + '''');
      sql.Add(' , Edittime=getdate()');
      sql.Add(' where TYId=' + quotedstr(CDS_HZ.fieldbyname('TYId').AsString));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv2.Controller.EditingController.ShowEdit();
  except
    tv2.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmYYBB.ToolButton3Click(Sender: TObject);
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update BS_Tray set EditFlag=0 where TYID=' + QuotedStr(CDS_HZ.FieldByName('TYID').AsString));
    ExecSQL;
  end;
  PrintReport(Trim(CDS_HZ.fieldbyname('TYId').AsString));
end;

procedure TfrmYYBB.ToolButton4Click(Sender: TObject);
var
  maxId: string;
begin
//  KWNo.SetFocus;
  if GetLSNo(ADOQueryCmd, maxId, 'DB', 'DB_Thing', 4, 1) = False then
  begin
    Application.MessageBox('取最大号失败！', '提示', 0);
    Exit;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('insert into DB_Thing(DBID) values(' + quotedstr(Trim(maxId)) + ')');
//    ShowMessage(sql.text);
    ExecSQL;
  end;
//  InitGridDB();
end;

procedure TfrmYYBB.ToolButton5Click(Sender: TObject);
begin
  if CDS_DB.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete DB_Thing where DBID=' + QuotedStr(CDS_DB.FieldByName('DBID').AsString));
//    ShowMessage(sql.text);
    ExecSQL;
  end;
  CDS_DB.Delete;
end;

procedure TfrmYYBB.Tv2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i: Integer;
begin
  if not CDS_HZ.fieldbyname('EditFlag').AsBoolean then
  begin
    for i := 0 to tv2.ColumnCount - 1 do
    begin
      if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
        tv2.Columns[i].Options.Editing := false;
    end;
  end
  else
  begin
    for i := 0 to tv2.ColumnCount - 1 do
    begin
      if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
        tv2.Columns[i].Options.Editing := True;
    end;
  end;
end;

procedure TfrmYYBB.Timer1Timer(Sender: TObject);
begin
  InitGrid();
end;

end.

