예제 #1
0
        //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);
            }
        }
예제 #2
0
        // 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í znovu.",
                                            "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 nezhoduje, soubor byl zmazán, stáhněte aktualizaci znovu.",
                                                    "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 znovu.",
                                                "OK", MessageBoxDialogWindow.Icons.Error);
                    this.updateDownloadProgressBar.Value      = 0;
                    this.updateDownloadProgressBar.Visibility = Visibility.Collapsed;
                    this.updateDownloadTextBox.Visibility     = Visibility.Collapsed;
                    return;
                }

                ShutDownAndStartUpdate();
            }
        }
예제 #3
0
 /// <summary>Shows important new changes</summary>
 private void ShowVersionChanges()
 {
     if (!Settings.Version.ToString().Equals(Settings.VersionInfo))
     {
         MessageBoxDialogWindow.Show("Verze 0.10", "Změny ve verzi 0.10:\n"
                                     + "Opraveno stahování EAN kódu z katalogu.", "OK", MessageBoxDialogWindow.Icons.Information);
         Settings.VersionInfo = Settings.Version.ToString();
     }
 }
 // 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;
     }
 }
예제 #5
0
        // 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);

            bool?returnValue = msgBox.ShowDialog();

            isCheckBoxChecked = (bool)msgBox.checkBox.IsChecked;
            return(returnValue);
        }
예제 #6
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);
     }
 }
예제 #7
0
        // Opens CreateNewUnitWindow
        internal void ShowNewUnitWindow()
        {
            try
            {
                foreach (string fileName in Directory.GetFiles(Settings.TemporaryFolder))
                {
                    // remove all previous image files
                    if (fileName.EndsWith(".tif") || fileName.EndsWith(".bmp") ||
                        fileName.Equals("obalkyknih-scanner_setup.exe"))
                    {
                        File.Delete(fileName);
                    }
                }
            }
            // don't care if some file can't be deleted right now
            catch (Exception) { }

            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)
                {
                    Window newWindow = new CreateNewUnitWindow(this.dockPanel);
                    newWindow.ShowDialog();
                }
                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);
            }
        }
예제 #8
0
        // 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;
            }
        }
        // shows tabsControl for the unit with entered barcode
        private void ShowNewUnitTabsControl(string barcode)
        {
            if (string.IsNullOrWhiteSpace(barcode))
            {
                //show error message, if barcode was not entered
                MessageBoxDialogWindow.Show("Chyba!", "Zadejte čárový kód.", "OK", MessageBoxDialogWindow.Icons.Error);
                return;
            }

            List <UIElement> childrenList = new List <UIElement>();

            //get all children of parent of remote window
            foreach (UIElement item in parentOfTabsControl.Children)
            {
                //don't add Menu item
                if (item is Menu || item is StatusBar)
                {
                    continue;
                }
                childrenList.Add(item);
            }
            //remove all these children from remote window
            foreach (UIElement item in childrenList)
            {
                parentOfTabsControl.Children.Remove(item);
            }
            //put there new tabsControl with appropriate barcode
            parentOfTabsControl.Children.Add(new TabsControl(barcode));

            //close the window, if it was called from new window
            Window parentWindow = Window.GetWindow(this);

            if (parentWindow != null)
            {
                parentWindow.Close();
            }
            (Window.GetWindow(parentOfTabsControl) as MainWindow).AddMessageToStatusBar("Stahuji metadata.");
        }
예제 #10
0
        // 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);
        }
예제 #11
0
        /// <summary>Copies settings from config file into registry</summary>
        public static void MigrateOldSettings()
        {
            // if settings were already migrated, do nothing
            if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\ObalkyKnih-scanner", "isMigrated", null) != null)
            {
                return;
            }

            if (!File.Exists(SettingsFile))
            {
                MessageBoxDialogWindow.Show("Nastavení neexistují", "Soubor s uživatelskými nastaveními neexistuje.",
                                            "OK", MessageBoxDialogWindow.Icons.Error);
                return;
            }

            try
            {
                ReloadSettings();
            }
            catch (Exception)
            {
                MessageBoxDialogWindow.Show("Poškozené nastavení", "Soubor s uživatelskými nastaveními je poškozen.",
                                            "OK", MessageBoxDialogWindow.Icons.Error);
                return;
            }

            if (Settings.UserName == null && !string.IsNullOrEmpty(UserName))
            {
                Settings.UserName = UserName;
            }

            if (string.IsNullOrEmpty(Settings.Password) && !string.IsNullOrEmpty(Password))
            {
                Settings.Password = Password;
            }

            Settings.IsXServerEnabled = IsXServerEnabled;

            if (Settings.XServerUrl == null && !string.IsNullOrEmpty(XServerUrl))
            {
                Settings.XServerUrl = XServerUrl;
            }

            if (Settings.XServerBase == null && !string.IsNullOrEmpty(XServerBase))
            {
                Settings.XServerBase = XServerBase;
            }

            Settings.IsZ39Enabled = IsZ39Enabled;

            if (Settings.Z39ServerUrl == null && !string.IsNullOrEmpty(Z39Server))
            {
                Settings.Z39ServerUrl = Z39Server;
            }

            if (Settings.Z39Port == 0 && Z39Port != 0)
            {
                Settings.Z39Port = Z39Port;
            }

            if (Settings.Z39Base == null && !string.IsNullOrEmpty(Z39Base))
            {
                Settings.Z39Base = Z39Base;
            }

            if (Settings.Z39Encoding == Record_Character_Encoding.UNRECOGNIZED &&
                Z39Encoding != Record_Character_Encoding.UNRECOGNIZED)
            {
                Settings.Z39Encoding = Z39Encoding;
            }

            if (Settings.Z39UserName == null && !string.IsNullOrEmpty(Z39UserName))
            {
                Settings.Z39UserName = Z39UserName;
            }

            if (Settings.Z39Password == null && !string.IsNullOrEmpty(Z39Password))
            {
                Settings.Z39Password = Z39Password;
            }

            if (Settings.Z39BarcodeField == 0 && Z39BarcodeField != 0)
            {
                Settings.Z39BarcodeField = Z39BarcodeField;
            }

            if (Settings.Sigla == null && !string.IsNullOrEmpty(Sigla))
            {
                Settings.Sigla = Sigla;
            }

            // delete config file if possible
            try
            {
                File.Delete(SettingsFile);
            }
            catch (Exception) { }

            // save indicator that values have been migrated successfully
            Registry.SetValue(@"HKEY_CURRENT_USER\Software\ObalkyKnih-scanner",
                              "isMigrated", 1, RegistryValueKind.DWord);
        }
예제 #12
0
        // Complex actions after update-info was retrieved
        private void UpdateInfoBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            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
                {
                    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 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 || 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);
                        }
                    }
                }
            }
        }