Пример #1
0
        //窗口加载时进行更新检测,并进行更新
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //获取配置文件中服务器地址

            //判断文件是否存在
            try
            {
                if (File.Exists(address))
                {
                    FileStream   file   = new FileStream(address, FileMode.Open);
                    StreamReader reader = new StreamReader(file);
                    String       temp   = reader.ReadLine();
                    serverPath = temp;
                    file.Close();
                    reader.Close();
                }
            }
            catch (IOException)
            {
            }
            ;
            Update update       = new Update();
            String serverDbName = GetFileName.GetFileNameWithonExtension(serverPath);

            if (serverDbName == null)
            {
                return;
            }
            String localDbName = GetFileName.GetFileNameWithonExtension(localPath);

            if (update.AntoUpdateOrNot())
            {
                MessageBoxResult result = MessageBox.Show("当前软件需要更新", "提示", MessageBoxButton.OKCancel);
                if (result == MessageBoxResult.OK)
                {
                    String filename = Assembly.GetExecutingAssembly().Location;
                    File.Move(filename, filename + ".delete");
                    File.Copy(serverPath + "\\" + "TeamProjectDevelopment.exe", filename);

                    String          DbName     = GetFileName.getFileName(serverPath);
                    String          conStr     = databaseCon + serverPath + "\\" + DbName;
                    OleDbConnection connection = CreateDb.getConn(conStr);
                    connection.Open();
                    String       selectString = "delete from config1 where fileName=\"TeamProjectDevelopment.exe\"";
                    OleDbCommand command      = new OleDbCommand(selectString, connection);
                    command.ExecuteNonQuery();
                    connection.Close();

                    update.AutoUpdate();
                }
            }
            if (update.UpdateOrNot())
            {
                MessageBoxResult result = MessageBox.Show("当前有版本更新,需要更新吗?", "更新", MessageBoxButton.OKCancel);
                if (result == MessageBoxResult.OK)
                {
                    update.update(this);
                }
            }
        }