Ejemplo n.º 1
0
 /// <summary>
 /// Handler for window Loaded event.
 /// Loads Adif and card files that were loaded last time the program was terminated
 /// </summary>
 /// <param name="sender">not used</param>
 /// <param name="e">not used</param>
 void Window_Loaded(object sender, EventArgs e)
 {
     UserPreferences prefs = ((App)App.Current).UserPreferences;
     // load card files
     if(prefs.CardsReloadOnStartup)
     {
         string[] fileNames = prefs.CardFiles.ToArray();
         prefs.CardFiles.Clear();
         CardWF card;
         foreach(string fileName in fileNames)
         {
             try
             {
                 card = CardWF.DeserializeCard(fileName);
             }
             catch(Exception ex)
             {
                 App.Logger.Log(ex);
                 continue;
             }
             card.FileName = fileName;
             card.IsInDesignMode = true;
             CardTabItem cti = new CardTabItem(card);
             mainTabControl.Items.Add(cti);
             cti.IsSelected = true;		// select the new tab
             card.IsDirty = false;
             cti.SetTabLabel();
             // need to call SetTitle here because mainTabControl SelectionChanged event is not fired.
             SetTitle(card.FileName, card.IsDirty);
             prefs.CardFiles.Add(fileName);
         }
     }
     // load Adif files
     if(prefs.AdifReloadOnStartup)
     {
         string[] adifFiles = prefs.AdifFiles.ToArray();
         prefs.AdifFiles.Clear();
         if(adifFiles.Length > 0)
         {
             // import the QSOs from the ADIF file
             for(int i = 0; i < adifFiles.Length; i++)
             {
                 try
                 {
                     string error = qsosView.DisplayQsos.AddQsos(adifFiles[i], qsosView.SortOrder,
                                                                App.AdifEnums);
                     if(error != null)
                     {
                         MessageBox.Show("Either there are errors in the ADIF file loaded, or" +
                                         Environment.NewLine +
                                         "individual QSO fields were modified during load." +
                                         Environment.NewLine +
                                         "See log file for details.", "Import Error or Change",
                                         MessageBoxButton.OK, MessageBoxImage.Warning);
                         App.Logger.Log(error);
                     }
                 }
                 catch(Exception ex)
                 {
                     App.Logger.Log(ex);
                     prefs.AdifFiles.Remove(adifFiles[i]);
                     ((App)Application.Current).UserPreferences = prefs;
                     ((App)Application.Current).UserPreferences.SerializeAsXml();
                 }
             }
             qsosView.ShowIncludeSelectors();
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handler for CardOpen Executed event
        /// </summary>
        /// <param name="sender">not used</param>
        /// <param name="e">not used</param>
        private void CardOpenCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog oDialog = new OpenFileDialog();
            oDialog.Filter = "QSL Card(*.xq1)|*.xq1";
            oDialog.InitialDirectory =
                ((App)Application.Current).UserPreferences.DefaultCardFilesFolder;
            if(oDialog.ShowDialog(this) == true)
            {
                string fileName = oDialog.FileName;
                string fileExt = fileName.Substring(fileName.Length - 4);
                CardWF card = null;
                if(fileExt.Equals(".xq1"))		// HamQSLer card file
                {
                    try
                    {
                        card = CardWF.DeserializeCard(fileName);
                    }
                    catch(InvalidOperationException ioe)
                    {
                        MessageBox.Show("An error occurred while opening "
                                        + "the card. See the log file for details. The problem "
                                        + "must be fixed before the card can be loaded.",
                                        "Error Loading Card", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        App.Logger.Log(ioe, true, false);
                        return;

                    }
                    catch(Exception ex)
                    {
                        App.Logger.Log(ex);
                        return;
                    }
                    card.FileName = fileName;
                    UserPreferences prefs = ((App)App.Current).UserPreferences;
                    if(prefs.CardsReloadOnStartup)
                    {
                        prefs.CardFiles.Add(fileName);
                        prefs.SerializeAsXml();
                    }
                }
                else			// bad file type - this really is a programming error
                {
                    return;
                }
                // Card.IsDirty is set to true in CardTabItem constructor so we must
                // save IsDirty and restore its value afterwards
                CardTabItem cti = new CardTabItem(card);
                card.IsInDesignMode = true;
                // if background or secondary image fileName changed, mark
                // card as dirty
                bool dirty = card.BackgroundImage.ModifiedDuringLoad;
                foreach(SecondaryWFImage image in card.SecondaryImages)
                {
                    dirty = dirty || image.ModifiedDuringLoad;
                }
                card.IsDirty = dirty;
                // add the CardTabItem to the mainTabControl and set title and
                // tab label
                mainTabControl.Items.Add(cti);
                cti.IsSelected = true;		// select the new tab
                cti.SetTabLabel();
                // need to call SetTitle here because mainTabControl SelectionChanged event is not fired.
                SetTitle(card.FileName, card.IsDirty);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Save card to new file
 /// <param name="cti">CardTabItem containing card to save</param>
 /// </summary>
 private void SaveCardAs(CardTabItem cti)
 {
     CardWF qslCard = cti.cardPanel.QslCard;
     string fileName = qslCard.FileName;
     SaveFileDialog sDialog = new SaveFileDialog();
     sDialog.Filter = "QSL Card(*.xq1)|*.xq1";
     sDialog.InitialDirectory =
         ((App)Application.Current).UserPreferences.DefaultCardFilesFolder;
     if(fileName != null)
     {
         sDialog.FileName = fileName;
     }
     if(sDialog.ShowDialog() == true)
     {
         qslCard.SaveAsXml(sDialog.FileName);
         cti.SetTabLabel();
         SetTitle(sDialog.FileName, qslCard.IsDirty);
         UserPreferences prefs = ((App)App.Current).UserPreferences;
         if(prefs.CardsReloadOnStartup)
         {
             if(fileName != sDialog.FileName)
             {
                 prefs.CardFiles.Remove(fileName);
                 prefs.CardFiles.Add(sDialog.FileName);
                 prefs.SerializeAsXml();
             }
         }
         // If the last property control changed was a color button, then the background
         // color of the button will cycle from 0 to 100% opacity. By moving focus to a
         // different control, this will not happen
         cti.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Save card to file named in Card.FileName
 /// <param name="cti">CardTabItem containing card to save</param>
 /// </summary>
 private void SaveCard(CardTabItem cti)
 {
     CardWF qslCard = cti.cardPanel.QslCard;
     if(qslCard.FileName != null)
     {
         qslCard.SaveAsXml(qslCard.FileName);
         cti.SetTabLabel();
         SetTitle(qslCard.FileName, qslCard.IsDirty);
         // If the last property control changed was a color button, then the background
         // color of the button will cycle from 0 to 100% opacity. By moving focus to a
         // different control, this will not happen
         cti.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
     }
     else
     {
         SaveCardAs(cti);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Close the CardTabItem
 /// </summary>
 /// <param name="cti">CardTabItem to close</param>
 /// <param name="doNotReloadCard">Boolean indicating that the card should not
 /// be reloaded next time program is started.</param>
 public void CloseCardTab(CardTabItem cti, bool doNotReloadCard)
 {
     if(cti.cardPanel.QslCard.IsDirty)
     {
         MessageBoxResult result = MessageBox.Show("The design of this card has been modified.\n"
                         + "Do you want to save the card before closing?", "Card Modified",
                         MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
         if(result == MessageBoxResult.Yes)
         {
             SaveCard(cti);
         }
     }
     mainTabControl.Items.Remove(cti);
     UserPreferences prefs = ((App)App.Current).UserPreferences;
     if(doNotReloadCard && prefs.CardsReloadOnStartup)
     {
         if(cti.cardPanel.QslCard.FileName != null)
         {
             prefs.CardFiles.Remove(cti.cardPanel.QslCard.FileName);
             prefs.SerializeAsXml();
         }
     }
     cti = null;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Handles New -> Bureau Card menu item processing
 /// </summary>
 /// <param name="sender">not used</param>
 /// <param name="e">not used</param>
 void NewBureauCardCommand_Executed(object sender, RoutedEventArgs e)
 {
     // create a CardTabItem and add it to the mainTabControl
     CardTabItem cardTab = new CardTabItem(550, 350);
     mainTabControl.Items.Add(cardTab);
     cardTab.IsSelected = true;		// select the new tab
     cardTab.cardPanel.QslCard.IsDirty = false;
     cardTab.SetTabLabel();
     // need to call SetTitle here because mainTabControl SelectionChanged event is not fired.
     SetTitle(cardTab.cardPanel.QslCard.FileName, cardTab.cardPanel.QslCard.IsDirty);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Handles New -> 4 by 6 inch Card menu item processing
 /// </summary>
 /// <param name="sender">not used</param>
 /// <param name="e">not used</param>
 void New46CardCommand_Executed(object sender, RoutedEventArgs e)
 {
     // create a CardTabItem and add it to the mainTabControl
     CardTabItem cardTab = new CardTabItem(600, 400);
     mainTabControl.Items.Add(cardTab);
     cardTab.IsSelected = true;		// select the new tab
     cardTab.cardPanel.QslCard.IsDirty = false;
     cardTab.SetTabLabel();
     SetTitle(cardTab.cardPanel.QslCard.FileName, cardTab.cardPanel.QslCard.IsDirty);
 }