zoukankan      html  css  js  c++  java
  • DBAnyWhere 演示代码

      //设置IP和Port
      RemoteUdpConnection1.RemoteIp:=Edit1.Text;
      RemoteUdpConnection1.RemoteLoginPort:=StrToInt(Edit2.Text);
      RemoteUdpConnection1.RemoteDataPort:=StrToInt(Edit3.Text);
      //启动登陆(StartLogin属于非阻塞的方法)
      RemoteUdpConnection1.StartLogin;

    procedure TForm1.RemoteUdpConnection1Connect(OnLine: Boolean);//onConnect事件
    begin
      //显示在线状态
      if OnLine then Edit4.Text:='在线' else Edit4.Text:='离线';
    end;

      //断开
      RemoteUdpConnection1.StopLogin;

      //获取终端列表
      dt.udp.GetClientsList(listbox1.Items);

      //sendtext方法的前两个参数如果都为空,意思为直接发信息给服务器
      //第一个参数是通过终端名发送,第二个参数通过终端mac发送,写其中一个就行
      dt.udp.SendText(edit2.Text,edit1.Text);

    procedure Tdt.udpMsg(SourceMac, Msg: String);//onMsg事件
    begin
      form1.Chat_Memo.Lines.Add('终端['+sourcemac+']对您说:'+msg);
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
      RemoteUdpDataSet2.Close;
      RemoteUdpDataSet2.SQL.Text:='insert into dtproperties(property,lvalue,version) values(:A,:B,:C)';
      RemoteUdpDataSet2.ParamByName('A').AsString:='Test';
      //操作blob字段
      RemoteUdpDataSet2.ParamByName('B').LoadFromFile(ExtractFilePath(ParamStr(0))+'Test.bmp',ftBlob);
      RemoteUdpDataSet2.ParamByName('C').AsInteger:=1;
      RemoteUdpDataSet2.ExecSQL;
      //刷新查询
      RemoteUdpDataSet1.Refresh;
    end;

    //TApplicationUpdate(在线升级)
    三个属性: LocalRoot(本地目录), RemoteIp, RemotePort
    procedure TMainForm.BtnUpdateClick(Sender: TObject);
    var
      ini1: Tinifile;
    begin
      if Application.MessageBox('升级前请您先退出待升级的程序文件!' + #13#10 +
        '继续操作请选确定,放弃请选取消!', '提示', MB_OKCANCEL +
        MB_ICONINFORMATION) = IDCANCEL then
      begin
        exit;
      end;
      ini1 := Tinifile.create(ExtractFilePath(application.ExeName) + 'netconfig.ini');
      ApplicationUpdate1.RemotePort :=StrToInt(ini1.ReadString('Update', 'RemotePort', '88'));
      ApplicationUpdate1.RemoteIp := ini1.ReadString('Update', 'RemoteIp', '127.0.0.1');
      ApplicationUpdate1.GetUpdateFilesList(nil);
      ApplicationUpdate1.UpdateFiles;
      ini1.Free;
      Application.MessageBox('恭喜您,升级完成,请测试您的程序!', '提示', MB_OK +
        MB_ICONINFORMATION);   
    end;

    procedure TMainForm.ApplicationUpdate1Update(UpdateFileName: String;//OnUpdate事件
      UpdatedBytes, FileSize, TotalUpdatedBytes: Integer);
    begin
      pb1.Max:=FileSize;
      pb1.Position:=UpdatedBytes;//当前文件进度

      pb2.Max:=ApplicationUpdate1.TotalFileSize;
      pb2.Position:=TotalUpdatedBytes;//所有文件进度

      Edit1.Text:=UpdateFileName;
      Edit1.Repaint;
    end;

    //数据索引
      //获取所有字段
      RemoteUdpDataSet1.GetFieldNames('authors',ComboBox1.Items);//'authors', 表名

      //排序
      if ComboBox1.ItemIndex>-1 then
        RemoteUdpDataSet1.Sort(ComboBox1.Text,TSortType(ComboBox2.ItemIndex));

      //从服务器获取文件
      RemoteUdpConnection1.GetFileFromServer(RemoteFileName,LocalFileName);

      //上载文件到服务器
      RemoteUdpConnection1.PutFileToServer(LocalFileName,RemoteFileName);

    //sql 查询
      RemoteUdpDataSet1.Close;
      RemoteUdpDataSet1.SQL.Text:='Select * from Employee where job_id>:Id';
      RemoteUdpDataSet1.ParamByName('id').AsInteger:=5;
      RemoteUdpDataSet1.Open;

    //分页查询
    RemoteUdpDataSet1.SelectType:=SelectPage;
    RemoteUdpDataSet1.FirstPage;
    RemoteUdpDataSet1.PriorPage;
    RemoteUdpDataSet1.NextPage;
    Edit2.Text:='第'+IntToStr(RemoteUdpDataSet1.PageNo)+'页/共'+IntToStr(RemoteUdpDataSet1.PageNum)+'页';

    //执行存储过程
      RemoteStoredProc1.Close;
      RemoteStoredProc1.ProcedureName:='byroyalty';
      //获取参数列表
      RemoteStoredProc1.RefreshParameters;
      //给参数赋值
      RemoteStoredProc1.Parameters.ParamValues['@percentage']:=100;
      //执行存储过程
      RemoteStoredProc1.Open;

      //设置保持连接,这样在执行中,只要不断线,服务器就一直保持和数据库的连接
      RemoteUdpConnection1.KeepConnection:=True;

    //创建临时表 
    RemoteUdpDataSet1.Close;
      RemoteUdpDataSet1.sql.Text:='Create table #tempTable('+
                                  'Id Integer not null,'+
                                  'Text Varchar(50) null)';
      RemoteUdpDataSet1.ExecSQL;

    //往临时表里面插入数据
      RemoteUdpDataSet1.Close;
      RemoteUdpDataSet1.SQL.Text:='insert into #TempTable(id,Text) values(:A,:B)';
      RemoteUdpDataSet1.ParamByName('A').AsInteger:=1;
      RemoteUdpDataSet1.ParamByName('B').AsString:='TestText';
      RemoteUdpDataSet1.ExecSQL;

    //查询临时表数据
      RemoteUdpDataSet1.Close;
      RemoteUdpDataSet1.SQL.Text:='select * from #TempTable';
      RemoteUdpDataSet1.Open;

    //事务处理
      //开始事务
      RemoteUdpConnection1.BeginTrans;
      try
        RemoteUdpDataSet1.Close;
        RemoteUdpDataSet1.SQL.Text:='update jobs set job_desc=''test'' where job_id=1';
        RemoteUdpDataSet1.ExecSQL;
        RemoteUdpDataSet1.Close;
        RemoteUdpDataSet1.SQL.Text:='update jobs set job_desc=''test1'' where job_id=2';
        RemoteUdpDataSet1.ExecSQL;
        RemoteUdpConnection1.CommitTrans;//提交事务
        ShowMessage('事务操作成功!');
      Except
        on E:exception do
        begin
          RemoteUdpConnection1.RollbackTrans;//回滚事务
          Showmessage(E.Message);
        end;
      end;

      //设置为批量提交模式
      RemoteUdpDataSet1.LockType:=etBatchOptimistic;

      //通过RemoteUpdateSQL方式批量提交(一般是复杂提交或者自定义提交)
      RemoteUdpDataSet1.RemoteUpdateObject:=RemoteUpdateSql1;
      RemoteUdpDataSet1.UpdateBatch;

      //系统默认的批量提交方式
      RemoteUdpDataSet1.RemoteUpdateObject:=nil;
      RemoteUdpDataSet1.UpdateBatch;

  • 相关阅读:
    Tomcat 管理页面 403 Access Denied 解决方法
    解决 Flowable 部署在服务器上后 重定向为 localhost 问题
    删除数据库下的所有表结构
    Errcode: 13 "Permission denied"
    mysql-bin.index not found
    JPA 使用@Where 注解实现全局过滤
    Linux 安装 telnet
    JavaScript基础巩固系列——面向对象编程(构造函数、new、对象继承、对象拷贝、严格模式)
    Javascript基础巩固系列——标准库JSON对象
    Javascript基础巩固系列——标准库Math对象+Date对象
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940853.html
Copyright © 2011-2022 走看看