• 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(
    false1);
                    
    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(
    false1);
                    
    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(
    false1);
                    
    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(
    false1);
                    
    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
    }

  • 相关阅读:
    数据结构课后
    idea 使用java 链接sqlservice 2008
    超链接 a href 提交表单通过post方式
    课程主页之课程接口
    课程主页之课程表数据
    课程表分析
    课程前端简单页面
    前台的登录注册
    ORM常用字段及参数与查询 -刘
    Celery配置与使用
  • 原文地址:https://www.cnblogs.com/ziyan22/p/1258698.html
Copyright © 2020-2023  润新知