zoukankan
html css js c++ java
PDA mc1000收发类
using
System;
using
System.Text;
using
System.Collections;
using
System.Windows.Forms;
using
OpenNETCF.Desktop.Communication;
//
myRapi
namespace
KelvinHelper.MCTeminals
{
public
class
myRapi
{
private
const
string
MSG_CONNECT
=
"
请把PDA设备放入通讯底座,开启PDA设备,准备通讯!
"
;
private
const
string
MSG_SUCCESS
=
"
文件拷贝成功!\r\n源文件名:'{0}'\r\n目标文件名:'{1}'
"
;
private
const
string
MSG_FAIL
=
"
试图连接PDA设备失败。\r\n错误原因:
"
;
private
static
string
GetFileName(
string
FullName)
{
return
FullName.Substring(FullName.LastIndexOf(
"
\\
"
)
+
1
);
}
//
拷贝多个文件
//
scrs:PC机上源文件文件列表
//
dest:终端设备目标文件目录
/**/
/*
例子:
System.Collections.ArrayList files = new System.Collections.ArrayList();
files.Add(@"E:\cai\Mc1000\sqlce_data_import\bin\Debug\goods.txt");
files.Add(@"E:\cai\Mc1000\sqlce_data_import\bin\Debug\plucode.txt");
myRapi.CopyFilesToDevice(files, "\\", textBox1);
this.Cursor = Cursors.Default;
*/
public
static
bool
CopyFilesToDevice(ArrayList scrs,
string
dest,
object
sender)
{
bool
b
=
false
;
int
i
=
0
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
if
(sender
!=
null
)
((TextBox)sender).Text
+=
MSG_CONNECT
+
"
\r\n
"
;
}
else
{
for
(i
=
0
; i
<
scrs.Count; i
++
)
{
string
destfile
=
dest
+
GetFileName((
string
)scrs[i]);
myRapi.CopyFileToDevice((
string
)scrs[i], destfile,
true
);
if
(sender
!=
null
)
((TextBox)sender).Text
+=
string
.Format(MSG_SUCCESS, (
string
)scrs[i], destfile)
+
"
\r\n
"
;
}
//
end for
myRapi.Disconnect();
myRapi.Dispose();
if
(sender
!=
null
)
((TextBox)sender).Text
+=
"
***** 拷贝文件完毕!*****
"
+
"
\r\n
"
;
MessageBox.Show(MSG_SUCCESS,
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
b
=
true
;
}
//
end if myRapi.Connect()
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
if
(sender
!=
null
)
((TextBox)sender).Text
+=
MSG_FAIL
+
ex.Message
+
"
\r\n
"
;
b
=
false
;
}
return
b;
}
//
end CopyFilesToDevice
//
覆盖拷贝到终端里
//
scr:终端机器里文件名
//
dest:PC机里文件全名
//
例子: myRapi.CopyFileToDevice("C:\\Goods.txt","\\Goods.txt");
public
static
bool
CopyFileToDevice(
string
scr,
string
dest)
{
bool
b
=
false
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
MessageBox.Show(MSG_CONNECT,
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
myRapi.CopyFileToDevice(scr, dest,
true
);
myRapi.Disconnect();
myRapi.Dispose();
MessageBox.Show(
string
.Format(MSG_SUCCESS, scr, dest),
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
b
=
true
;
}
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
MessageBox.Show(MSG_FAIL
+
ex.Message,
"
错误
"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
b
=
false
;
}
return
b;
}
//
end CopyFileToDevice
//
覆盖拷贝到桌面里
//
scr:终端机器里文件名
//
dest:PC机里文件全名
//
例子: myRapi.CoptyFileFormDevice("\\Stock.txt","C:\\Stock.txt");
public
static
bool
CopyFileFromDevice(
string
scr,
string
dest)
{
bool
b
=
false
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
MessageBox.Show(MSG_CONNECT,
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
myRapi.CopyFileFromDevice(dest, scr,
true
);
myRapi.Disconnect();
myRapi.Dispose();
MessageBox.Show(
string
.Format(MSG_SUCCESS, scr, dest),
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
b
=
true
;
}
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
MessageBox.Show(MSG_FAIL
+
ex.Message,
"
错误
"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
b
=
false
;
}
return
b;
}
//
end CopyFileFromDevice
//
测试连接
//
成功返回:true
//
失败返回:false
public
static
bool
TestConnect()
{
bool
b
=
false
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
//
MessageBox.Show("请用ActiveSync将您的PC机和PDA设备连接好。",
//
"提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
b
=
false
;
}
else
{
myRapi.Dispose();
b
=
true
;
}
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
MessageBox.Show(
"
试图连接PDA设备失败。\r\n错误原因:
"
+
ex.Message,
"
错误
"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
b
=
false
;
}
return
b;
}
//
end TestConnect
}
//
end class myRapi
}
查看全文
相关阅读:
使用SpringSession管理分布式会话时遇到的反序列化问题
使用SpringSession管理分布式系统的会话Session
SQL函数TIMEDIFF在Java程序中使用报错的问题分析
基于Java实现的冒泡排序算法
关于.NET Core 2.0.2升级到2.1.1版本相关问题
记开发个人图书收藏清单小程序开发(一)
Windows系统里Oracle 11g R2 Client(64bit)的下载与安装
RHEL 无图形界面安装oracle 11gr2
Linux cat 多行写入文件防止变量替换
Linux rsync 远程同步部署篇
原文地址:https://www.cnblogs.com/ziyan22/p/1258698.html
最新文章
随讲MyIsam和InnoDB的区别
服务器端打开office然后采用虚拟打印 转换成pdf
AJAX 中Sys.WebForms.PageRequestManager的事件激发顺序 《转》
updatepanel刷新后重新加载js脚本问题
如何解决设置Session保存在StateServer后引起WebService/WebMethod无法异步获取Session
SQL SERVER大数据分页
验证整数、小数、实数、有效位小数最简单JavaScript正则表达式
整数,小数及常用的正则表达式
大数据量分页存储过程效率测试附代码
asp.net 由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值
热门文章
SQL约束和字段约束的创建和删除
PHP-5.6.8 源码包编译安装
MySQL编译安装及启动
echo-nginx-module的安装、配置、使用
初识Grep
Nginx虚拟主机配置--配置Nginx的主配置文件
Nginx.conf配置文件默认配置块略解
Nginx的平滑升级记录---适用于编译安装的Nginx
如何修复被破坏的分区文件系统
基于FCM的消息推送功能
Copyright © 2011-2022 走看看