-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
135 lines (120 loc) · 4.51 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using OpenNETCF.Desktop.Communication;
namespace BusCE
{
public partial class MainForm : Form
{
// constanti locati
private string localDestination = @"C:\scs\ordini";
private string deviceSourceFolder = @"\";
private string deviceFileSearchCriteria = "ORD*.TXT";
private RAPI myRapi;
public MainForm()
{
InitializeComponent();
LocalPath.Text = localDestination;
RemotePath.Text = deviceSourceFolder;
RemoteFileFilter.Text = deviceFileSearchCriteria;
progressBar.Maximum = 1;
progressBar.Hide();
DeviceStatus.Text = "waiting";
}
private void Form1_Load(object sender, EventArgs e)
{
// Abilito il check continuo dello stato del terminale
statusImage.Image = imageList.Images[0];
timer1.Enabled = true;
myRapi = new RAPI();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (myRapi.DevicePresent)
{
DeviceStatus.Text = "CONNESSO";
btnGetFiles.Enabled = true;
statusImage.Image = imageList.Images[1]; // led verde
}
else
{
DeviceStatus.Text = "NON CONNESSO";
btnGetFiles.Enabled = false;
statusImage.Image = imageList.Images[2];
}
}
private void btnGetFiles_Click(object sender, EventArgs e)
{
try
{
// Controllo se esiste la cartella di destinazione locale
if (!Directory.Exists(LocalPath.Text))
Directory.CreateDirectory(LocalPath.Text);
// Creo l'oggetto di cotrollo remoto
if (myRapi.DevicePresent)
{
myRapi.Connect();
var fileNames = myRapi.EnumerateFiles(Path.Combine(RemotePath.Text, RemoteFileFilter.Text));
// Conta i file trovati
int numFiles = 0;
foreach (var item in fileNames)
numFiles++;
if (numFiles == 0) {
MessageBox.Show("Nessun file da ricevere!");
return;
}
progressBar.Maximum = numFiles;
progressBar.Show();
foreach (FileInformation file in fileNames)
{
/*
if (file.FileAttributes == Convert.ToInt16((int) RAPI.RAPIFileAttributes.Normal));
{
* */
myRapi.CopyFileFromDevice(
Path.Combine(LocalPath.Text, file.FileName), // desktop path
Path.Combine(RemotePath.Text, file.FileName), // device path
true // overwrite existing file
);
/*}*/
progressBar.Increment(1);
myRapi.DeleteDeviceFile(file.FileName);
}
}
}
catch
{
MessageBox.Show("Errore nell'accesso ai file locali");
return;
}
}
private void btnLocalPath_Click(object sender, EventArgs e)
{
string filePath = findPath();
if ((filePath.Length > 0) && (filePath != LocalPath.Text))
LocalPath.Text = filePath;
}
private string findPath()
{
string result = "";
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.Cancel) return result;
if (dialog.SelectedPath.Length > 0)
{
return dialog.SelectedPath;
}
return result;
}
private void btnRemotePath_Click(object sender, EventArgs e)
{
string filePath = findPath();
if ((filePath.Length > 0) && (filePath != LocalPath.Text))
RemotePath.Text = filePath;
}
}
}