unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SynEdit, SynMemo, StdCtrls, OleServer, WMWEBUSBLib_TLB,DateUtils,
  ExtCtrls, Spin;

type
  TForm1 = class(TForm)
    SynMemo1: TSynMemo;
    Wwusb1: TWwusb;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
    gw:Integer;
    procedure ShowMsg(state:Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
const EQUTYPE=2002;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var s:String;
begin
  s:='from '+DateTimeToStr(Now)+' to ';
  if Wwusb1.OpenUsb(EQUTYPE)>0 then
  begin
    Wwusb1.SetModel(2,gw);
    SynMemo1.Clear;
    SynMemo1.Text:=Wwusb1.GetRecordsEx(1);
    SynMemo1.Lines.Add(s+DateTimeToStr(Now));
    Wwusb1.CloseUsb;
    if length(SynMemo1.Text)<=0 then
      Application.MessageBox('无记录或读取失败！','提示',0)
  end
  else
    Application.MessageBox('开启设备失败','提示',0);

end;

procedure TForm1.Button2Click(Sender: TObject);

begin
  if Wwusb1.OpenUsb(EQUTYPE)>0 then
  begin
    Wwusb1.SetModel(2,gw);
    SynMemo1.Clear;
    if Wwusb1.ErasureRecords>=0 then
      Application.MessageBox('清除成功','提示',0)
    else
     Application.MessageBox('清除失败','提示',0)
  end
  else
    Application.MessageBox('开启设备失败','提示',0);
  Wwusb1.CloseUsb;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    SynMemo1.Clear;
    gw:=1;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if Wwusb1.OpenUsb(EQUTYPE)>0 then
  begin
    Wwusb1.SetModel(2,gw);
    ShowMsg(Wwusb1.SetDateTime(YearOf(now),MonthOf(Now),DayOf(now),HourOf(now),MinuteOf(now),SecondOf(Now)));
    end
  else
    Application.MessageBox('开启设备失败','提示',0);
  Wwusb1.CloseUsb;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if Wwusb1.OpenUsb(EQUTYPE)>0 then
  begin
    Wwusb1.SetModel(2,gw);
    ShowMsg(Wwusb1.SetTermno(Edit1.Text));
    end
  else
    Application.MessageBox('开启设备失败','提示',0);
  Wwusb1.CloseUsb;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if Wwusb1.OpenUsb(EQUTYPE)>0 then
  begin
    ShowMessage(Wwusb1.GetTermno);
    end
  else
    Application.MessageBox('开启设备失败','提示',0);
  Wwusb1.CloseUsb;
end;

procedure TForm1.ShowMsg(state: Integer);
begin
  if state>0 then
    Application.MessageBox('成功','提示',0)
  else
    Application.MessageBox('失败','提示',0)
end;

end.
