Skip to content

Commit fe3fc29

Browse files
committed
v2.37
- Added profile selection home page - Fixed bug live edit hex values - Changed FC tab order - Fixed live edit binary values - Fixed minor bugs like profile refresh, string datatypes, language translation
1 parent ab15b6a commit fe3fc29

33 files changed

Lines changed: 601 additions & 489 deletions

ModBus_Client/DatabaseManager.xaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:ModBus_Client"
77
mc:Ignorable="d"
8-
Title="DatabaseManager" Height="436.423" Width="417.127" Loaded="Window_Loaded" KeyUp="Window_KeyUp" Closing="Window_Closing">
8+
Title="DatabaseManager" Height="462" Width="417.127" Loaded="Window_Loaded" KeyUp="Window_KeyUp" Closing="Window_Closing">
99
<Grid>
10-
<DataGrid x:Name="DataGridDb" Margin="10,5,10,72" SelectionMode="Single" AutoGenerateColumns="False" Width="Auto" SelectedCellsChanged="DataGridDb_SelectedCellsChanged" IsReadOnly="True" FontSize="14">
11-
<DataGrid.Columns>
12-
<DataGridTextColumn Header="Profile" Binding="{Binding name}" Width="400"/>
13-
</DataGrid.Columns>
14-
</DataGrid>
15-
<Button x:Name="ButtonExportZip" Content="Export .zip" Margin="0,0,10.429,10" Click="ButtonExportZip_Click" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" IsEnabled="False"/>
16-
<Button x:Name="ButtonImportZip" Content="Import .zip" Margin="0,0,90.286,10" Click="ButtonImportZip_Click" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" IsEnabled="True"/>
10+
<Button x:Name="ButtonExportZip" Content="Export .zip" Margin="0,0,11,8" Click="ButtonExportZip_Click" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" IsEnabled="False"/>
11+
<Button x:Name="ButtonImportZip" Content="Import .zip" Margin="0,0,91,8" Click="ButtonImportZip_Click" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" IsEnabled="True"/>
1712
<Button x:Name="buttonOpenFileLocation" Content="Open directory" HorizontalAlignment="Left" Margin="10,0,0,10" Width="104" Click="ButtonOpenFileLocation_Click" Height="25" VerticalAlignment="Bottom"/>
1813
<Button x:Name="ButtonRefresh" Content="Refresh" HorizontalAlignment="Left" Margin="119,0,0,10" Width="75" Click="ButtonRefresh_Click" Height="21" VerticalAlignment="Bottom" Visibility="Hidden"/>
1914
<Label x:Name="labelProfileSelected" Content="Profile" HorizontalAlignment="Left" Margin="10,0,0,35" Height="32" VerticalAlignment="Bottom" Visibility="Visible" FontSize="14"/>
20-
<Button x:Name="ButtonDeleteProfile" Content="Delete" Margin="0,0,170,10" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="71" IsEnabled="False" Click="ButtonDeleteProfile_Click"/>
15+
<Button x:Name="ButtonDeleteProfile" Content="Delete" Margin="0,0,11,42" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="72" IsEnabled="False" Click="ButtonDeleteProfile_Click"/>
16+
<ListBox x:Name="ListBoxProfiles" d:ItemsSource="{d:SampleData ItemCount=5}" Margin="10,10,10,72" SelectionChanged="ListBoxProfiles_SelectionChanged" FontSize="14"/>
2117

2218
</Grid>
2319
</Window>

ModBus_Client/DatabaseManager.xaml.cs

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ namespace ModBus_Client
5757
/// </summary>
5858
public partial class DatabaseManager : Window
5959
{
60-
ObservableCollection<profile> db = new ObservableCollection<profile>();
61-
6260
Language lang;
6361
public string SelectedProfile = "";
6462

@@ -68,8 +66,6 @@ public DatabaseManager(MainWindow main_)
6866

6967
lang = new Language(this);
7068

71-
DataGridDb.ItemsSource = db;
72-
7369
// Centro la finestra
7470
double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
7571
double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
@@ -88,15 +84,11 @@ void LoadDb()
8884
{
8985
String[] subFolders = Directory.GetDirectories(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Json\\");
9086

91-
db.Clear();
87+
ListBoxProfiles.Items.Clear();
9288

9389
for (int i = 0; i < subFolders.Length; i++)
9490
{
95-
profile tmp = new profile();
96-
97-
tmp.name = subFolders[i].Split('\\')[subFolders[i].Split('\\').Length - 1];
98-
99-
db.Add(tmp);
91+
ListBoxProfiles.Items.Add(subFolders[i].Split('\\')[subFolders[i].Split('\\').Length - 1]);
10092
}
10193
}
10294

@@ -125,21 +117,21 @@ private void ButtonOpenFileLocation_Click(object sender, RoutedEventArgs e)
125117

126118
private void ButtonExportZip_Click(object sender, RoutedEventArgs e)
127119
{
128-
profile currItem = (profile)DataGridDb.SelectedItem;
120+
String currItem = ListBoxProfiles.SelectedItem.ToString();
129121

130122
SaveFileDialog window = new SaveFileDialog();
131123

132124
window.Filter = "Zip Files | *.zip";
133125
window.DefaultExt = ".zip";
134-
window.FileName = currItem.name + ".zip";
126+
window.FileName = currItem + ".zip";
135127

136128
if ((bool)window.ShowDialog())
137129
{
138130
// Se il file lo esiste gia' lo elimino
139131
if (File.Exists(window.FileName))
140132
File.Delete(window.FileName);
141133

142-
ZipFile.CreateFromDirectory("Json\\" + currItem.name, window.FileName);
134+
ZipFile.CreateFromDirectory("Json\\" + currItem, window.FileName);
143135
}
144136
}
145137

@@ -170,30 +162,6 @@ private void ButtonImportZip_Click(object sender, RoutedEventArgs e)
170162
LoadDb();
171163
}
172164

173-
private void DataGridDb_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
174-
{
175-
try
176-
{
177-
if (DataGridDb.SelectedItem != null)
178-
{
179-
profile selected = (profile)DataGridDb.SelectedItem;
180-
181-
labelProfileSelected.Content = labelProfileSelected.Content.ToString().Split(':')[0] + ": " + selected.name;
182-
labelProfileSelected.Visibility = Visibility.Visible;
183-
184-
ButtonExportZip.IsEnabled = true;
185-
//ButtonImportZip.IsEnabled = true;
186-
ButtonDeleteProfile.IsEnabled = true;
187-
}
188-
}
189-
catch
190-
{
191-
ButtonExportZip.IsEnabled = false;
192-
//ButtonImportZip.IsEnabled = false;
193-
ButtonDeleteProfile.IsEnabled = false;
194-
}
195-
}
196-
197165
private void Window_KeyUp(object sender, KeyEventArgs e)
198166
{
199167
if(e.Key == Key.Escape)
@@ -206,33 +174,32 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
206174
{
207175
this.DialogResult = false;
208176

209-
if (DataGridDb.SelectedItem != null)
177+
if (ListBoxProfiles.SelectedItem != null)
210178
{
211-
profile selected = (profile)DataGridDb.SelectedItem;
212-
this.SelectedProfile = selected.name;
179+
this.SelectedProfile = ListBoxProfiles.SelectedItem.ToString();
213180
this.DialogResult = true;
214181

215182
// debug
216-
Console.WriteLine("Selected: {0}", selected.name);
183+
Console.WriteLine("Selected: {0}", this.SelectedProfile);
217184
}
218185
}
219186

220187
private void ButtonDeleteProfile_Click(object sender, RoutedEventArgs e)
221188
{
222189
try
223190
{
224-
if (DataGridDb.SelectedItem != null)
191+
if (ListBoxProfiles.SelectedItem != null)
225192
{
226-
profile selected = (profile)DataGridDb.SelectedItem;
193+
String selected = ListBoxProfiles.SelectedItem.ToString();
227194

228-
labelProfileSelected.Content = labelProfileSelected.Content.ToString().Split(':')[0] + ": " + selected.name;
195+
labelProfileSelected.Content = labelProfileSelected.Content.ToString().Split(':')[0] + ": " + selected;
229196
labelProfileSelected.Visibility = Visibility.Visible;
230197

231-
if (Directory.Exists(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Json\\" + selected.name))
198+
if (Directory.Exists(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Json\\" + selected))
232199
{
233200
if (MessageBox.Show(lang.languageTemplate["strings"]["deleteProfile"], "Info", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
234201
{
235-
Directory.Delete(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Json\\" + selected.name, true);
202+
Directory.Delete(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Json\\" + selected, true);
236203

237204
ButtonExportZip.IsEnabled = false;
238205
ButtonDeleteProfile.IsEnabled = false;
@@ -251,10 +218,31 @@ private void ButtonDeleteProfile_Click(object sender, RoutedEventArgs e)
251218
ButtonDeleteProfile.IsEnabled = false;
252219
}
253220
}
254-
}
255221

256-
public class profile
257-
{
258-
public String name { get; set; }
222+
private void ListBoxProfiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
223+
{
224+
try
225+
{
226+
if (ListBoxProfiles.SelectedItem != null)
227+
{
228+
String selected = ListBoxProfiles.SelectedItem.ToString();
229+
230+
labelProfileSelected.Content = labelProfileSelected.Content.ToString().Split(':')[0] + ": " + selected;
231+
labelProfileSelected.Visibility = Visibility.Visible;
232+
233+
ButtonExportZip.IsEnabled = true;
234+
235+
if (selected == "Default")
236+
ButtonDeleteProfile.IsEnabled = false;
237+
else
238+
ButtonDeleteProfile.IsEnabled = true;
239+
}
240+
}
241+
catch
242+
{
243+
ButtonExportZip.IsEnabled = false;
244+
ButtonDeleteProfile.IsEnabled = false;
245+
}
246+
}
259247
}
260248
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)