//Shows confirmation dialog, starts update and exits application
        private void ShutDownAndStartUpdate()
        {
            if (this.updateDownloadProgressBar.Value == 100)
            {
                var result = MessageBoxDialogWindow.Show("Aktualizace stažena",
                                                         "Aktualizace byla stažena, přejete si nyní ukončit program a aktualizovat?",
                                                         "Yes", "No", true, MessageBoxDialogWindow.Icons.Question);

                if (result == true)
                {
                    try
                    {
                        //start update in new process
                        Process updateProcess = new Process();
                        updateProcess.StartInfo.FileName        = this.updateChecker.FilePath;
                        updateProcess.StartInfo.UseShellExecute = false;
                        updateProcess.Start();

                        //close application
                        this.forceShutDown = true;
                        Application.Current.Shutdown();
                    }
                    catch (Exception)
                    {
                        MessageBoxDialogWindow.Show("Aktualizace stažena",
                                                    "Nepodařilo se spustit aktualizaci, ukončete program a spusťte ji ručně.",
                                                    "OK", MessageBoxDialogWindow.Icons.Error);
                    }
                }
            }
            else
            {
                MessageBoxDialogWindow.Show("Stahování nekompletní", "Aktualizace zatím nebyla stažena.", "OK", MessageBoxDialogWindow.Icons.Information);
            }
        }
        // Complex actions after update file was downloaded
        private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            this.downloadUpdateButton.IsEnabled = true;
            if (e.Error != null)
            {
                MessageBoxDialogWindow.Show("Chyba při stahování aktualizace",
                                            "Počas stahování aktualizace došlo k chybě. Zkuste spustit stahování opakovaně.",
                                            "OK", MessageBoxDialogWindow.Icons.Error);
                this.updateDownloadTextBox.Visibility     = Visibility.Collapsed;
                this.updateDownloadProgressBar.Visibility = Visibility.Collapsed;
            }
            else if (e.Cancelled)
            {
                MessageBoxDialogWindow.Show("Stahování přerušeno", "Stahování bylo přerušeno.",
                                            "OK", MessageBoxDialogWindow.Icons.Warning);
                this.updateDownloadTextBox.Visibility     = Visibility.Collapsed;
                this.updateDownloadProgressBar.Visibility = Visibility.Collapsed;
            }
            else
            {
                //check checksum
                try
                {
                    string checksum;
                    using (FileStream stream = File.OpenRead(this.updateChecker.FilePath))
                    {
                        SHA256Managed sha           = new SHA256Managed();
                        byte[]        checksumBytes = sha.ComputeHash(stream);
                        checksum = BitConverter.ToString(checksumBytes).Replace("-", String.Empty);
                    }

                    if (!this.updateChecker.Checksum.ToLower().Equals(checksum.ToLower()))
                    {
                        File.Delete(this.updateChecker.FilePath);
                        MessageBoxDialogWindow.Show("Aktualizace poškozena",
                                                    "Kontrolní součet stažené aktualizace se neshoduje, soubor byl smazán, stáhněte aktualizaci opakovaně.",
                                                    "OK", MessageBoxDialogWindow.Icons.Error);
                        this.updateDownloadProgressBar.Value      = 0;
                        this.updateDownloadProgressBar.Visibility = Visibility.Collapsed;
                        this.updateDownloadTextBox.Visibility     = Visibility.Collapsed;
                        return;
                    }
                }
                catch (Exception)
                {
                    MessageBoxDialogWindow.Show("Chyba kontroly aktualizace",
                                                "Při kontrole integrity aktualizace došlo k chybě, stáhněte aktualizaci opakovaně.",
                                                "OK", MessageBoxDialogWindow.Icons.Error);
                    this.updateDownloadProgressBar.Value      = 0;
                    this.updateDownloadProgressBar.Visibility = Visibility.Collapsed;
                    this.updateDownloadTextBox.Visibility     = Visibility.Collapsed;
                    return;
                }

                ShutDownAndStartUpdate();
            }
        }
 // Disables closing of this windows until isClosable flag isn't set to true
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (!isClosable)
     {
         MessageBoxDialogWindow.Show("Vydržte prosím",
                                     "Prosím počkejte než se odešlou všechny soubory.",
                                     "OK", MessageBoxDialogWindow.Icons.Information);
         e.Cancel = true;
     }
 }
        // 2 buttons with checkbox and icon
        public static bool?Show(string title, string message, out bool isCheckBoxChecked, string checkBoxLabel,
                                string buttonTrueLabel, string buttonFalseLabel, bool defaultChoice, Icons icon)
        {
            MessageBoxDialogWindow msgBox = new MessageBoxDialogWindow(title, message, checkBoxLabel,
                                                                       buttonTrueLabel, buttonFalseLabel, defaultChoice, icon, null);

            bool?returnValue = msgBox.ShowDialog();

            isCheckBoxChecked = (bool)msgBox.checkBox.IsChecked;
            return(returnValue);
        }
示例#5
0
 /// <summary>
 /// Saves settings to disk
 /// </summary>
 internal static void PersistSettings()
 {
     try
     {
         Directory.CreateDirectory(SettingsFile.Remove(SettingsFile.LastIndexOf('\\')));
         XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserSettings));
         UserSettings  us            = new UserSettings();
         using (FileStream fs = new FileStream(SettingsFile, FileMode.Create))
         {
             us.SyncFromSettings();
             xmlSerializer.Serialize(fs, us);
         }
     }
     catch (Exception)
     {
         MessageBoxDialogWindow.Show("Nastavení neuloženo", "Zápis nastavení se nezdařil.",
                                     "OK", MessageBoxDialogWindow.Icons.Error);
     }
 }
示例#6
0
        // shows tabsControl for the unit with entered identifier
        private void ShowNewUnionControl()
        {
            if (string.IsNullOrWhiteSpace(this.identifierTextBox.Text))
            {
                //show error message, if identifier was not entered
                MessageBoxDialogWindow.Show("Chyba!", "Prázdný identifikátor", "OK", MessageBoxDialogWindow.Icons.Error);
                return;
            }

            switch (this.identifierComboBox.Text)
            {
            case "Čárový kód":
                this.GeneralRecord.IdentifierType = IdentifierType.BARCODE;
                this.GeneralRecord.Barcode        = this.identifierTextBox.Text;
                break;

            case "ISBN":
                this.GeneralRecord.IdentifierType    = IdentifierType.ISBN;
                ((Monograph)this.GeneralRecord).Isbn = this.identifierTextBox.Text;
                break;

            case "ČNB":
                this.GeneralRecord.IdentifierType = IdentifierType.CNB;
                this.GeneralRecord.Cnb            = this.identifierTextBox.Text;
                break;

            case "OCLC":
                this.GeneralRecord.IdentifierType = IdentifierType.OCLC;
                this.GeneralRecord.Oclc           = this.identifierTextBox.Text;
                break;

            case "URN":
                this.GeneralRecord.IdentifierType = IdentifierType.URN;
                this.GeneralRecord.Urn            = this.identifierTextBox.Text;
                break;

            default:
                throw new ArgumentException("Unsupported identifier type: " + identifierComboBox.Text);
            }

            this.DialogResult = true;
        }
        // Shows confirmation message and shutdown application
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (forceShutDown || Settings.DisableClosingConfirmation)
            {
                return;
            }
            bool dontAskAgain;

            if (MessageBoxDialogWindow.Show("Potvrzení", "Opravdu chcete ukončit program?",
                                            out dontAskAgain, "Příště se neptat a zavřít", "Ano", "Ne", true, MessageBoxDialogWindow.Icons.Question) == true)
            {
                if (dontAskAgain)
                {
                    Settings.DisableClosingConfirmation = true;
                }
                Application.Current.Shutdown();
            }
            else
            {
                e.Cancel = true;
            }
        }
        public static bool ShowHyperlink(string title, string message,
                                         string hyperlinkLabel, string buttonTrueLabel, Icons icon)
        {
            // creates an additional TextBlock for hyperlink
            MessageBoxDialogWindow msgBox = new MessageBoxDialogWindow(title, message, null, buttonTrueLabel, null, false, icon, hyperlinkLabel);
            TextBlock hypertextBlock      = new TextBlock();

            Mouse.OverrideCursor = Cursors.Arrow;
            hypertextBlock.Inlines.Add(hyperlinkLabel);
            hypertextBlock.TextWrapping        = TextWrapping.Wrap;
            hypertextBlock.Margin              = new Thickness(60, 35, 20, 60);
            hypertextBlock.VerticalAlignment   = VerticalAlignment.Top;
            hypertextBlock.HorizontalAlignment = HorizontalAlignment.Center;
            hypertextBlock.Foreground          = System.Windows.Media.Brushes.Blue;
            hypertextBlock.MouseUp            += new MouseButtonEventHandler(Hyperlink_Click);
            hypertextBlock.MouseEnter         += new MouseEventHandler(MouseEnterTextArea);
            hypertextBlock.MouseLeave         += new MouseEventHandler(MouseLeaveTextArea);
            hypertextBlock.Visibility          = Visibility.Visible;

            msgBox.grid.Children.Add(hypertextBlock);
            msgBox.ShowDialog();
            return(true);
        }
示例#9
0
        //validates the user input
        private void getInputBoxResult()
        {
            if (string.IsNullOrWhiteSpace(InputTextBox.Text))
            {
                MessageBoxDialogWindow.Show("Chyba!", "Nezadali jste žádné číslo!", "Ok", MessageBoxDialogWindow.Icons.Error);
                return;
            }

            try
            {
                moveIntoValue = Convert.ToInt32(InputTextBox.Text);
                if (moveIntoValue > maxItemCount || moveIntoValue < 1)
                {
                    MessageBoxDialogWindow.Show("Chyba!", "Zadané číslo je mimo rozsahu!", "Ok", MessageBoxDialogWindow.Icons.Error);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBoxDialogWindow.Show("Chyba!", "Nesprávný formát čísla!", "Ok", MessageBoxDialogWindow.Icons.Error);
                return;
            }
            DialogResult = true;
        }
        // Complex actions after update-info was retrieved
        private void UpdateInfoBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.isVersionCheckFinished = true;
            if (e.Error != null)
            {
                this.versionStateLabel.Content = "";
                if (e.Error.InnerException is FormatException)
                {
                    MessageBoxDialogWindow.Show("Chybné informace o aktualizaci",
                                                "Informace o aktualizaci mají nesprávný formát. Kontaktujte prosím administrátory servru obalkyknih.cz.",
                                                "OK", MessageBoxDialogWindow.Icons.Error);
                }

                /*else if (!Settings.NeverDownloadUpdates)
                 * {
                 *  var result = MessageBoxDialogWindow.Show("Chyba stahování informací o aktualizaci",
                 *      "Při stahování informací o aktualizaci se vyskytla chyba. Po stisknutí OK se zahájí další pokus.",
                 *      "OK", MessageBoxDialogWindow.Icons.Error);
                 *  if (result == true)
                 *  {
                 *      updateInfoBackgroundWorker.RunWorkerAsync();
                 *  }
                 * }*/
                else
                {
                    Settings.offlineMode              = true;
                    this.versionStateLabel.Content    = "Verzi není možné zjistit";
                    this.versionStateLabel.Foreground = Brushes.Red;
                    this.versionStateLabel.FontWeight = FontWeights.Bold;
                    this.offlineModeLabel.Visibility  = Visibility.Visible;
                }
            }
            else if (!e.Cancelled)
            {
                this.latestVersionLabel.Content = this.updateChecker.AvailableVersion.Major.ToString()
                                                  + "." + this.updateChecker.AvailableVersion.Minor.ToString();
                this.latestDateLabel.Content = this.updateChecker.AvailableVersionDate;

                if (!updateChecker.IsSupportedVersion)
                {
                    // suppose that if it is not supported, it can't be up to date
                    this.versionStateImage.Visibility   = Visibility.Visible;
                    this.versionStateLabel.Content      = "Verze není aktuální";
                    this.programSupportLabel.Foreground = Brushes.Red;
                    this.programSupportLabel.Content    = "Nepodporováno";
                    isAllowedVersion = false;
                    this.downloadUpdateButton.Visibility = Settings.DisableUpdate ? Visibility.Hidden : Visibility.Visible;
                    if (Settings.DisableUpdate)
                    {
                        MessageBoxDialogWindow.Show("Nepodporovaná verze",
                                                    "Vaše verze programu je v seznamu nepodporovaných verzí a nelze s ní pracovat."
                                                    + "Požádejte administrátora o instalaci nové verze.",
                                                    "OK", MessageBoxDialogWindow.Icons.Error);
                    }
                    else
                    {
                        bool dontShowAgain = false;
                        bool?result        = true;
                        if (!Settings.AlwaysDownloadUpdates)
                        {
                            result = MessageBoxDialogWindow.Show("Nepodporovaná verze",
                                                                 "Vaše verze programu je v seznamu nepodporovaných verzí a nelze s ní pracovat, musíte stáhnout aktualizaci. Chcete ji stáhnout nyní?",
                                                                 out dontShowAgain, "Příště se neptat a stáhnout", "Ano", "Ne", true, MessageBoxDialogWindow.Icons.Warning);
                        }
                        if (result == true)
                        {
                            if (dontShowAgain)
                            {
                                Settings.AlwaysDownloadUpdates = true;
                            }
                            DownloadUpdateFile();
                        }
                    }
                }
                else
                {
                    this.programSupportLabel.Content = "Podporováno";
                    isAllowedVersion = true;
                    if (this.updateChecker.IsUpdateAvailable)
                    {
                        this.versionStateImage.Visibility    = Visibility.Visible;
                        this.versionStateLabel.Content       = "Verze není aktuální";
                        this.downloadUpdateButton.Visibility = Settings.DisableUpdate ? Visibility.Hidden : Visibility.Visible;
                        if (!Settings.DisableUpdate && (!Settings.NeverDownloadUpdates || Settings.offlineMode || showIsLatestVersionPopup))
                        {
                            bool dontShowAgain;
                            var  result = MessageBoxDialogWindow.Show("Aktualizace", "Aktualizace je k dispozici, chcete ji stáhnout?",
                                                                      out dontShowAgain, "Příště se neptat a použít tuto volbu", "Ano", "Ne", true, MessageBoxDialogWindow.Icons.Question);
                            if (result == true)
                            {
                                if (dontShowAgain)
                                {
                                    Settings.AlwaysDownloadUpdates = true;
                                }
                                DownloadUpdateFile();
                            }
                            else if (dontShowAgain)
                            {
                                Settings.NeverDownloadUpdates = true;
                            }
                        }
                    }
                    else
                    {
                        this.versionStateLabel.Content       = "Verze je aktuální";
                        this.downloadUpdateButton.Visibility = Visibility.Hidden;
                        if (this.showIsLatestVersionPopup)
                        {
                            MessageBoxDialogWindow.Show("Aktualizace", "Verze je aktuální",
                                                        "OK", MessageBoxDialogWindow.Icons.Information);
                        }
                    }
                }
            }
        }
        // Opens CreateNewUnitWindow
        internal void ShowNewUnitWindow()
        {
            try
            {
                foreach (string fileName in Directory.GetFiles(Settings.TemporaryFolder))
                {
                    // images handled after uploading
                    if (fileName.Equals("CDArcha_klient_setup.exe"))
                    {
                        File.Delete(fileName);
                    }
                }
            }
            // don't care if some file can't be deleted right now
            catch (Exception) { }

            if (this.isVersionCheckFinished && (Settings.NeverDownloadUpdates || Settings.offlineMode) && isAllowedVersion != false)
            {
                isAllowedVersion = true;                                                                                                                      //debug
            }
            if (isAllowedVersion == null)
            {
                MessageBoxDialogWindow.Show("Kontrola verze", "Kontrola verze zatím neskončila, počkejte prosím.",
                                            "OK", MessageBoxDialogWindow.Icons.Error);
            }
            else if (isAllowedVersion == true)
            {
                if (!Settings.ForceUpdate || this.updateChecker.IsUpdateAvailable)
                {
                    CreateNewUnitWindow newWindow = new CreateNewUnitWindow();
                    newWindow.ShowDialog();

                    if (newWindow.DialogResult.HasValue && newWindow.DialogResult.Value)
                    {
                        AddMessageToStatusBar("Stahuji metadata.");

                        GeneralRecord generalRecord = newWindow.GeneralRecord;

                        this.dockPanel.Children.Remove(this.mainGrid);
                        foreach (UIElement element in this.dockPanel.Children)
                        {
                            if (element is TabsControl)
                            {
                                this.dockPanel.Children.Remove(element);
                                break;
                            }
                        }
                        this.dockPanel.Children.Add(new TabsControl(generalRecord));
                    }
                }
                else
                {
                    MessageBoxDialogWindow.Show("Zastaralá verze",
                                                "Tato verze programu není aktuální a administrátor vynutil používání jenom aktuální verze."
                                                + "Prosím nainstalujte aktualizaci.", "OK", MessageBoxDialogWindow.Icons.Error);
                }
            }
            else
            {
                MessageBoxDialogWindow.Show("Nepodporovaná verze",
                                            "Tato verze programu není podporována, prosím nainstalujte aktualizaci.",
                                            "OK", MessageBoxDialogWindow.Icons.Error);
            }
        }
        // Validates input - format of sigla, Z39 port and Z39 barcode field
        private bool ValidateInput()
        {
            string errorMsg = "";
            bool   isValid  = true;

            //sigla
            char[] sigla = this.siglaTextBox.Text.ToCharArray();
            if (sigla.Length != 6)
            {
                errorMsg += "Sigla musí mít 6 znaků, 3 písmena a 3 čísla." + Environment.NewLine;
                isValid   = false;
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    if (!char.IsUpper(sigla[i]))
                    {
                        errorMsg += "První 3 písmena sigly musí být velká písmena." + Environment.NewLine;
                        isValid   = false;
                        break;
                    }
                }
                if (!('A'.Equals(sigla[2]) || 'B'.Equals(sigla[2]) || 'C'.Equals(sigla[2]) ||
                      'D'.Equals(sigla[2]) || 'E'.Equals(sigla[2]) || 'F'.Equals(sigla[2]) || 'G'.Equals(sigla[2])))
                {
                    errorMsg += "Třetí písmeno sigly musí být z rozmezí A-G." + Environment.NewLine;
                    isValid   = false;
                }

                for (int i = 3; i < 6; i++)
                {
                    if (!char.IsNumber(sigla[i]))
                    {
                        errorMsg += "Poslední 3 písmena sigly musí být čísla." + Environment.NewLine;
                        isValid   = false;
                        break;
                    }
                }
            }

            int tmp;

            //z39 port
            if (!int.TryParse(this.z39PortTextBox.Text, out tmp))
            {
                errorMsg += "V poli Z39.50 Server Port musí být celé číslo, které reprezentuje port, na kterým je server pro z39.50 dostupný." + Environment.NewLine;
                isValid   = false;
            }

            //z39 barcode field
            if (!int.TryParse(this.z39BarcodeField.Text, out tmp))
            {
                errorMsg += "V poli vyhledávací atribut musí být celé číslo, které reprezentuje kód, kterým se dotazuje přes čárový kód." + Environment.NewLine;
                isValid   = false;
            }

            if (!isValid)
            {
                MessageBoxDialogWindow.Show("Nastavení obsahují chyby", errorMsg, "OK", MessageBoxDialogWindow.Icons.Error);
            }
            return(isValid);
        }
        // shows tabsControl for the unit with entered identifier
        private void ShowNewUnitTabsControl()
        {
            ComboBox identifierComboBox;
            string   identifierValue = null;

            if (this.monographTabItem.IsSelected)
            {
                identifierComboBox = this.monographIdentifierComboBox;
                this.GeneralRecord = new Monograph();
                identifierValue    = this.monographIdentifierTextBox.Text.Trim();
            }
            else
            {
                identifierComboBox = this.periodicalIdentifierComboBox;
                this.GeneralRecord = new Periodical();
                identifierValue    = this.periodicalIdentifierTextBox.Text.Trim();
            }

            if (string.IsNullOrWhiteSpace(identifierValue))
            {
                //show error message, if identifier was not entered
                MessageBoxDialogWindow.Show("Chyba!", "Prázdný identifikátor", "OK", MessageBoxDialogWindow.Icons.Error);
                return;
            }

            switch (identifierComboBox.Text)
            {
            case "Čárový kód":
                this.GeneralRecord.IdentifierType = IdentifierType.BARCODE;
                this.GeneralRecord.Barcode        = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "ISBN":
                this.GeneralRecord.IdentifierType    = IdentifierType.ISBN;
                ((Monograph)this.GeneralRecord).Isbn = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "ISSN":
                this.GeneralRecord.IdentifierType     = IdentifierType.ISSN;
                ((Periodical)this.GeneralRecord).Issn = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "ISMN":
                this.GeneralRecord.IdentifierType = IdentifierType.ISMN;
                this.GeneralRecord.Ismn           = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "EAN":
                this.GeneralRecord.IdentifierType = IdentifierType.EAN;
                this.GeneralRecord.Ean            = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "ČNB":
                this.GeneralRecord.IdentifierType = IdentifierType.CNB;
                this.GeneralRecord.Cnb            = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "OCLC":
                this.GeneralRecord.IdentifierType = IdentifierType.OCLC;
                this.GeneralRecord.Oclc           = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            case "URN":
                this.GeneralRecord.IdentifierType = IdentifierType.URN;
                this.GeneralRecord.Urn            = this.GeneralRecord.IdentifierValue = identifierValue;
                break;

            default:
                this.GeneralRecord.IdentifierType = IdentifierType.BARCODE;
                this.GeneralRecord.Barcode        = this.GeneralRecord.IdentifierValue = identifierValue;
                break;
            }

            this.DialogResult = true;
        }