unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ShellAPI;

type
  TFormMain = class(TForm)
    Panel1: TPanel;
    CameraPanel: TPanel;
    Panel3: TPanel;
    Label64: TLabel;
    edtHDIPEx: TEdit;
    btnSetHDCamera: TButton;
    Label65: TLabel;
    edtHDCameraPortEx: TEdit;
    Label66: TLabel;
    edtTHeadPortEx: TEdit;
    Label67: TLabel;
    edtLoginName: TEdit;
    Label68: TLabel;
    edtLoginPassword: TEdit;
    Label69: TLabel;
    edtConnectType: TComboBox;
    Label70: TLabel;
    edtShowMainCode: TComboBox;
    bvl1: TBevel;
    btnUpdate: TButton;
    Bevel1: TBevel;
    Panel4: TPanel;
    Right: TButton;
    Left: TButton;
    Down: TButton;
    Up: TButton;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Label1: TLabel;
    ntCombox: TComboBox;
    npComBox: TComboBox;
    Label2: TLabel;
    Bevel2: TBevel;
    Button7: TButton;
    SaveDialog: TSaveDialog;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Label3: TLabel;
    poComboBox: TComboBox;
    Button13: TButton;
    procedure FormShow(Sender: TObject);
    procedure btnUpdateClick(Sender: TObject);
    procedure UpClick(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure btnSetHDCameraClick(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

uses HDCameraControl, HDFileOperate;

{$R *.dfm}

procedure TFormMain.FormShow(Sender: TObject);
begin
  InitHDCamerasData;
  edtHDIPEx.Text := HDCamerasData.HDCameraData.IP;
  edtHDCameraPortEx.Text := IntToStr(HDCamerasData.HDcameraData.CameraPort);
  edtTHeadPortEx.Text := IntToStr(HDCamerasData.HDcameraData.THeadPort);
  edtLoginName.Text := HDCamerasData.HDUserName;
  edtLoginPassword.Text := HDCamerasData.HDPassword;
  edtConnectType.ItemIndex := HDCamerasData.bIsTcp;
  if HDCamerasData.IfShowMainCode then
    edtShowMainCode.ItemIndex := 1
  else
    edtShowMainCode.ItemIndex := 0;

  _HDCameraControl := THDCameraControl.Create;
end;

procedure TFormMain.btnUpdateClick(Sender: TObject);
var
  MainCode: Boolean;
begin
  case edtShowMainCode.ItemIndex of
    0: MainCode := False;
    1: MainCode := True;
  end;
  HDCamerasData.SetHDCameraData(Trim(edtHDIPEx.Text), StrToInt(edtHDCameraPortEx.Text),
    StrToInt(edtTHeadPortEx.Text), Trim(edtLoginName.Text), Trim(edtLoginPassword.Text),
    edtConnectType.ItemIndex, MainCode);
  _HDCameraControl.InitHDCameraChannels;

end;

procedure TFormMain.UpClick(Sender: TObject);
var
  nTSpeed, nPSPeed: Integer;
begin
  if _HDCameraControl.LoginChannel <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  nTSpeed := StrToInt(ntCombox.Text);
  nPSpeed := StrToInt(npComBox.Text);          
  case (Sender as TButton).Tag of
    //上下左右
    1: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 21, nTSpeed, nPSPeed);
    2: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 22, nTSpeed, nPSPeed);
    3: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 23, nTSpeed, nPSPeed);
    4: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 24, nTSpeed, nPSPeed);
    //焦距伸缩
    5: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 11, nTSpeed, nPSPeed);
    6: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 12, nTSpeed, nPSPeed);
    //焦点远近
    7: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 13, nTSpeed, nPSPeed);
    8: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 14, nTSpeed, nPSPeed);
    //光圈大小
    9: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel, 15, nTSpeed, nPSPeed);
    10: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel,16, nTSpeed, nPSPeed);
    //停止
    11: IP_NET_DVR_PTZControl(_HDCameraControl.LoginChannel,30, nTSpeed, nPSPeed);

  end;
end;

procedure TFormMain.Button7Click(Sender: TObject);
var
  iFilePath: string;
begin
  if _HDCameraControl.LoginChannel <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  SaveDialog.Filter := 'Bmp图片|*.bmp|Jpg图片|*.jpg';
  if SaveDialog.Execute then
  begin
    case SaveDialog.FilterIndex of
      1: iFilePath := SaveDialog.FileName + '.bmp';
      2: iFilePath := SaveDialog.FileName + '.jpg';
    end;
    IP_TPS_CatchPicByFileName(_HDCameraControl.HsdVideoStream, PChar(iFilePath),
      SaveDialog.FilterIndex - 1);
  end;
end;

procedure TFormMain.btnSetHDCameraClick(Sender: TObject);
begin
  ShellExecute(Application.Handle, 'open', PChar('http://' + Trim(edtHDIPEx.Text)), nil, nil, SW_SHOWNORMAL) ;
end;

procedure TFormMain.Button9Click(Sender: TObject);
begin
  if _HDCameraControl.HsdVideoStream <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  _HDCameraControl.StartHDRecord;
end;

procedure TFormMain.Button10Click(Sender: TObject);
begin
  if _HDCameraControl.HsdVideoStream <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  _HDCameraControl.StopHDRecord;
end;

procedure TFormMain.Button11Click(Sender: TObject);
begin
  if _HDCameraControl.HsdVideoStream <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  IP_NET_DVR_PTZPreset(_HDCameraControl.LoginChannel, 8, StrToInt(poComboBox.Text));
end;

procedure TFormMain.Button12Click(Sender: TObject);
begin
  if _HDCameraControl.HsdVideoStream <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  IP_NET_DVR_PTZPreset(_HDCameraControl.LoginChannel, 39, StrToInt(poComboBox.Text));

end;

procedure TFormMain.Button13Click(Sender: TObject);
begin
  if _HDCameraControl.HsdVideoStream <= 0 then
  begin
    ShowMessage('请先连上摄像头后再执行此项操作！');
    Exit;
  end;
  IP_NET_DVR_PTZPreset(_HDCameraControl.LoginChannel, 9, StrToInt(poComboBox.Text));

end;

end.
