Exemple #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            switch (_startMode)
            {
            case "-w":
                _sb = FindResource("OnLoadedStoryboard") as Storyboard;
                if (_sb != null)
                {
                    _sb.Begin();
                }
                break;

            case "-m":
                break;
            }

            int wId = AdministrationClass.GetWorkerIdByComputerName();

            if (wId != 0)
            {
                UsersComboBox.SelectedValue = wId;

                if (UsersComboBox.SelectedIndex != -1)
                {
                    PasswordBox.Focus();
                    UsersComboBox_SelectionChanged(null, null);
                }
            }
            else
            {
                UsersComboBox.SelectedIndex = -1;
                UsersComboBox.Focus();
            }

            try
            {
                const int mainversion = 1;
                int       dayversion  = 1;

                string ver = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTimeUtc.ToString("yyMMdd");

                string filePath = Path.Combine(AdministrationClass.GetMainDirectory(), "ver");

                var versionFile = new FileInfo(filePath);


                if (!Directory.Exists(AdministrationClass.GetMainDirectory()))
                {
                    Directory.CreateDirectory(AdministrationClass.GetMainDirectory());
                }

                if (!versionFile.Exists)
                {
                    StreamWriter sw = versionFile.CreateText();
                    sw.Close();
                }

                string version = File.ReadAllText(filePath).Trim();

                if (version != string.Empty)
                {
                    string curVer = version.Remove(0, 2);
                    try
                    {
                        curVer = curVer.Remove(6, curVer.Length - 6);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message);
                    }

                    if (curVer == ver)
                    {
                        int.TryParse(version.Remove(0, version.Length - 1), out dayversion);

                        if (dayversion == 0)
                        {
                            dayversion = 1;
                        }
                    }
                }

                VersionLabel.Content = mainversion + "." + ver + dayversion;

                File.WriteAllText(filePath, VersionLabel.Content.ToString());
            }
            catch (Exception)
            {
                MessageBox.Show("Не удалось создать файл версии", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }