示例#1
0
 private void SerializeObject_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (cbListOrders.Text.Length == 0)
         {
             MessageBox.Show("Choose order.");
         }
         else
         {
             int numberToSerialize = int.Parse(cbListOrders.SelectedValue.ToString());
             for (int index = 0; index < _orders.Count; index++)
             {
                 if (numberToSerialize == _orders[index].NumOrder)
                 {
                     SaveFileDialog dialog = new SaveFileDialog();
                     dialog.Filter = "XML file (*.xml)|*.xml|Binary data (*.bin)|*.bin|Json file (*.json)|*.json";
                     var result = dialog.ShowDialog();
                     if (result == null || result == false)
                     {
                         return;
                     }
                     var             extension = Path.GetExtension(dialog.SafeFileName);
                     SerializeObject serialize = new SerializeObject(extension, dialog.FileName);
                     if (cypherType.Text.Length != 0)
                     {
                         serialize.ExecuteSerialization(_orders[index], cypherType.SelectedIndex);
                     }
                     else
                     {
                         serialize.ExecuteSerialization(_orders[index]);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }