Skip to content

Commit

Permalink
closeButton fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Art1xFX committed Sep 4, 2018
1 parent 301c64f commit 861822b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 57 deletions.
6 changes: 3 additions & 3 deletions ASDC.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</MenuItem.Icon>
</MenuItem>
<Separator/>
<MenuItem Header="Выход" Template="{DynamicResource MenuItemControlTemplate2}" Click="transformMenuItem_Click">
<MenuItem Header="Выход" Template="{DynamicResource MenuItemControlTemplate2}" Click="closeMenuItem_Click">
<MenuItem.Icon>
<Image Source="Resources/Exit.png"/>
</MenuItem.Icon>
Expand Down Expand Up @@ -80,11 +80,11 @@
<Image Source="Resources/Open.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Template="{DynamicResource MenuItemControlTemplate1}" Click="transformMenuItem_Click" ToolTip="Преобразовать" Visibility="Collapsed">
<!--<MenuItem Template="{DynamicResource MenuItemControlTemplate1}" Click="transformMenuItem_Click" ToolTip="Преобразовать">
<MenuItem.Icon>
<Image Source="Resources/Open.png"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>-->
<Separator/>
<ComboBox x:Name="searchAlgorithmComboBox" Width="86" Style="{DynamicResource ComboBoxStyle1}" IsEnabled="False" ToolTip="Алгоритм поиска" SelectionChanged="searchAlgorithmComboBox_SelectionChanged">
<ComboBoxItem Content="Linear"/>
Expand Down
112 changes: 58 additions & 54 deletions ASDC.Demo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,63 +81,67 @@ private void openMenuItem_Click(object sender, RoutedEventArgs e)
statusTextBlock.Text = "Отменено";
}


// Пример преобразования XML в понятные для программы BIN файлы.

private void transformMenuItem_Click(object sender, RoutedEventArgs e)
private void closeMenuItem_Click(object sender, RoutedEventArgs e)
{
statusTextBlock.Text = "Преобразование...";
List<Citizen> result = new List<Citizen>();
OpenFileDialog openFileDialog = new OpenFileDialog()
{
Title = "Преобразовать",
Filter = "XML файлы (*.xml)|*.xml"
};
if (openFileDialog.ShowDialog() == true)
{
try
{
this.Close();
}

XDocument doc = XDocument.Load(openFileDialog.FileName);
foreach (var record in doc.Element("dataset").Elements("record"))
{
result.Add(new Citizen()
{
PIN = long.Parse(record.Element("PIN").Value),
FirstName = record.Element("FirstName").Value,
LastName = record.Element("LastName").Value,
Gender = (Gender)int.Parse(record.Element("Gender").Value),
Birth = DateTime.Parse(record.Element("Birth").Value),
});
}

using (var writer = new BinaryWriter(new FileStream("citizens.bin", FileMode.OpenOrCreate)))
{
writer.Write(result.Count);
foreach (var item in result)
{
writer.Write(item.PIN);
writer.Write(item.FirstName.Length);
foreach (var c in item.FirstName)
writer.Write(c);

writer.Write(item.LastName.Length);
foreach (var c in item.LastName)
writer.Write(c);
writer.Write(item.Birth.Day);
writer.Write(item.Birth.Month);
writer.Write(item.Birth.Year);
writer.Write((int)item.Gender);
}
}
statusTextBlock.Text = "Готово";
}
catch (Exception)
{
MessageBox.Show("Не удалось преобразовать указанный файл!", "ASDC", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
// Пример преобразования XML в понятные для программы BIN файлы.
//private void transformMenuItem_Click(object sender, RoutedEventArgs e)
//{
// statusTextBlock.Text = "Преобразование...";
// List<Citizen> result = new List<Citizen>();
// OpenFileDialog openFileDialog = new OpenFileDialog()
// {
// Title = "Преобразовать",
// Filter = "XML файлы (*.xml)|*.xml"
// };
// if (openFileDialog.ShowDialog() == true)
// {
// try
// {

// XDocument doc = XDocument.Load(openFileDialog.FileName);
// foreach (var record in doc.Element("dataset").Elements("record"))
// {
// result.Add(new Citizen()
// {
// PIN = long.Parse(record.Element("PIN").Value),
// FirstName = record.Element("FirstName").Value,
// LastName = record.Element("LastName").Value,
// Gender = (Gender)int.Parse(record.Element("Gender").Value),
// Birth = DateTime.Parse(record.Element("Birth").Value),
// });
// }

// using (var writer = new BinaryWriter(new FileStream("citizens.bin", FileMode.OpenOrCreate)))
// {
// writer.Write(result.Count);
// foreach (var item in result)
// {
// writer.Write(item.PIN);
// writer.Write(item.FirstName.Length);
// foreach (var c in item.FirstName)
// writer.Write(c);

// writer.Write(item.LastName.Length);
// foreach (var c in item.LastName)
// writer.Write(c);
// writer.Write(item.Birth.Day);
// writer.Write(item.Birth.Month);
// writer.Write(item.Birth.Year);
// writer.Write((int)item.Gender);
// }
// }
// statusTextBlock.Text = "Готово";
// }
// catch (Exception)
// {
// MessageBox.Show("Не удалось преобразовать указанный файл!", "ASDC", MessageBoxButton.OK, MessageBoxImage.Error);
// }
// }
//}


private async void searchMenuItem_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 861822b

Please sign in to comment.