@@ -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}
0 commit comments