⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upgrade.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
namespace PowerEasy.WebSite.Install
{
    using PowerEasy.Common;
    using PowerEasy.CommonModel;
    using PowerEasy.Components;
    using PowerEasy.Enumerations;
    using PowerEasy.Model.CommonModel;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web.Configuration;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Xml;

    public class Upgrade : Page
    {
        protected HtmlInputButton BtnUpgrade;
        public string dataBaseVersion = "0.0.0.0";
        protected DropDownList DropSqlVersion;
        protected HtmlForm form1;
        private static FileVersionInfo fvInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
        protected HtmlHead Head1;
        public static readonly string ProductCopyright = fvInfo.LegalCopyright;
        public string ProductName;
        public static readonly string ProductVersion = fvInfo.ProductVersion;

        private void AddVersion(string conn, string version)
        {
            using (SqlConnection connection = new SqlConnection(conn))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                string[] strArray = version.ToString().Split(new char[] { '.' });
                command.CommandText = "INSERT INTO PE_Version (Major,Minor,Build,Revision,CreatedDate)VALUES(@Major,@Minor,@Build,@Revision,@CreatedDate)";
                command.CommandType = CommandType.Text;
                command.Parameters.Add(new SqlParameter("@Major", SqlDbType.Int));
                command.Parameters.Add(new SqlParameter("@Minor", SqlDbType.Int));
                command.Parameters.Add(new SqlParameter("@Build", SqlDbType.Int));
                command.Parameters.Add(new SqlParameter("@Revision", SqlDbType.Int));
                command.Parameters.Add(new SqlParameter("@CreatedDate", SqlDbType.DateTime));
                command.Parameters["@Major"].Value = strArray[0];
                command.Parameters["@Minor"].Value = strArray[1];
                command.Parameters["@Build"].Value = strArray[2];
                command.Parameters["@Revision"].Value = strArray[3];
                command.Parameters["@CreatedDate"].Value = DateTime.Now;
                command.ExecuteNonQuery();
                connection.Close();
            }
        }

        protected void BtnUpgrade_Click(object sender, EventArgs e)
        {
            string connectionString = WebConfigurationManager.ConnectionStrings["Connection String"].ConnectionString;
            string s = "<html>\r\n<head>\r\n  <title>动易软件产品升级程序</title>\r\n  <link rel=\"stylesheet\" type=\"text/css\" href=\"images/upgrade.css\">\r\n</head>\r\n<body>\r\n    <div class=\"top\">\r\n        <form id=\"search\" action=\"http://help.powereasy.net/search.asp\" method=\"post\">\r\n            <dl>\r\n                <dt class=\"linking\"><a href=\"http://www.powereasy.net/\" target=\"_blank\" title=\"访问动易官方网站\">\r\n                    powereasy.net</a> | <a href=\"http://powereasy.net/soft/\" target=\"_blank\" title=\"免费下载动易系列软件产品\">\r\n                        免费下载</a> | <a href=\"http://powereasy.net/User/\" target=\"_blank\" title=\"动易官方网站客户自助服务\">\r\n                            客户自助服务</a> | <a href=\"http://bbs.powereasy.net/\" target=\"_blank\" title=\"今天您上动易论坛了吗?\">\r\n                                动易论坛</a></dt>\r\n                <dt class=\"search\"><span style=\"width: 320px; height: 22px; height: 26px; padding: 6px 0 0 0;\r\n                    padding: 2px 0 0 0; _padding: 4px 0 0 0; overflow: hidden; float: right;\">\r\n                    <span style=\"float: right; padding: 0px 0 0 10px; padding: 2px 0 0 10px;\">\r\n                        <input id=\"Submit\" style=\"border: 0px; width: 47px; height: 20px;\" type=\"image\" src=\"Images/upgrade_search_but.gif\"\r\n                            name=\"Submit\" />\r\n                    </span>\r\n                    <span>\r\n                        <input name=\"Keyword\" id=\"Keyword\" onclick=\"value=''\"  style=\"background:#ebf7ff\" onmouseover=\"this.style.backgroundColor='#ffffff'\"\r\n                            onmouseout=\"this.style.backgroundColor='#ebf7ff'\" value=\"动易全站搜索\" size=\"35\" />\r\n                        <input name=\"ModuleName\" type=\"hidden\" id=\"ModuleName\" value=\"Article\" />\r\n                        <input id=\"Field\" type=\"hidden\" value=\"Title\" name=\"Field\" />\r\n                    </span>\r\n                </span></dt>\r\n            </dl>\r\n        </form>\r\n    </div>\r\n  <br />\r\n<!-- tags excluded on purpose so that installation feedback messages are displayed\r\n</body>\r\n</html>\r\n-->";
            base.Response.Clear();
            base.Response.Write(s);
            base.Response.Flush();
            base.Response.Write("<h1>正在升级" + this.ProductName + "</h1>");
            base.Response.Write("<h2>当前程序集版本:" + ProductVersion + "</h2>");
            base.Response.Write("<h2>当前数据库版本:" + this.dataBaseVersion + "</h2><br>");
            base.Response.Write("<h2>升级状态报告</h2>");
            base.Response.Flush();
            ArrayList upgradeScripts = this.GetUpgradeScripts(this.dataBaseVersion);
            base.Response.Write(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff") + " -&nbsp;正在升级到版本:" + ProductVersion + "<br/>");
            if (upgradeScripts.Count == 0)
            {
                this.AddVersion(connectionString, ProductVersion);
            }
            else
            {
                string str3 = "2005.";
                if (this.DropSqlVersion.SelectedValue == "2000")
                {
                    str3 = "2000.";
                }
                foreach (object obj2 in upgradeScripts)
                {
                    base.Response.Write(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff") + " -&nbsp;&nbsp;&nbsp;正在执行数据库脚本:" + obj2.ToString() + ".sql&nbsp;");
                    base.Response.Flush();
                    if (UpgradeDataBase(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\" + str3 + obj2.ToString() + ".sql"), connectionString))
                    {
                        base.Response.Write(" <font color='green'>执行成功</font><br>");
                    }
                    else
                    {
                        base.Response.Write(" <font color='red'>执行失败</font><br>");
                    }
                    this.AddVersion(connectionString, obj2.ToString());
                    base.Response.Flush();
                }
                if (string.Compare(upgradeScripts[upgradeScripts.Count - 1].ToString(), ProductVersion) != 0)
                {
                    this.AddVersion(connectionString, ProductVersion);
                }
            }
            if (this.dataBaseVersion == "0.9.8.0")
            {
                this.RCToRelease();
            }
            base.Response.Write(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff") + " -&nbsp;更新版本号&nbsp;");
            base.Response.Flush();
            try
            {
                System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
                AppSettingsSection section = (AppSettingsSection) configuration.GetSection("appSettings");
                section.Settings["Version"].Value = ProductVersion;
                configuration.Save();
            }
            catch (FileNotFoundException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (ConfigurationErrorsException)
            {
            }
            base.Response.Write("<br><h2>升级完成</h2><br><br><h2><a href='../Default.aspx'>返回网站首页</a></h2><br><br><div class=\"copy\">" + ProductCopyright + "</div></body></html>");
            base.Response.End();
        }

        private ArrayList GetUpgradeScripts(string databaseVersion)
        {
            ArrayList list = new ArrayList();
            string[] files = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data"), "*.sql");
            string str2 = @"2005\.";
            if (this.DropSqlVersion.SelectedValue == "2000")
            {
                str2 = @"2000\.";
            }
            Regex regex = new Regex(str2 + @"[0123456789]{1,}\.[0123456789]{1,}\.[0123456789]{1,}\.[0123456789]{1,}");
            foreach (string str3 in files)
            {
                string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(str3);
                if (regex.IsMatch(fileNameWithoutExtension))
                {
                    fileNameWithoutExtension = fileNameWithoutExtension.Remove(0, 5);
                    if ((string.Compare(fileNameWithoutExtension, databaseVersion) > 0) && (string.Compare(fileNameWithoutExtension, ProductVersion) <= 0))
                    {
                        list.Add(fileNameWithoutExtension);
                    }
                }
            }
            list.Sort();
            return list;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.ProductName))
            {
                string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Config\Site.config");
                if (string.Compare(ReadSiteConfigElement(fileName, "ProductEdition"), "eShop", true) == 0)
                {
                    this.ProductName = "PowerEasy SiteFactory eShop";
                }
                if (string.Compare(ReadSiteConfigElement(fileName, "ProductEdition"), "CMS", true) == 0)
                {
                    this.ProductName = "PowerEasy SiteFactory CMS";
                }
            }
            SiteCache.Remove("CK_System_DataBaseCurrentVersion");
            string connectionString = WebConfigurationManager.ConnectionStrings["Connection String"].ConnectionString;
            this.dataBaseVersion = "0.0.0.0";
            try
            {
                SqlConnection connection = new SqlConnection(connectionString);
                connection.Open();
                try
                {
                    SqlCommand command = connection.CreateCommand();
                    command.CommandText = "SELECT TOP 1 * FROM PE_Version ORDER BY VersionID DESC";
                    command.CommandType = CommandType.Text;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            this.dataBaseVersion = reader["Major"].ToString() + "." + reader["Minor"].ToString() + "." + reader["Build"].ToString() + "." + reader["Revision"].ToString();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -