📄 default.cs
字号:
namespace PowerEasy.WebSite.Install
{
using PowerEasy.Templates;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
public class Default : Page
{
protected Button BtnCreateDateBase;
protected CheckBox ChlkAgreeLicense;
protected CheckBox ChlkIsCreateDataBase;
protected HtmlGenericControl DivDefault;
protected HtmlGenericControl DivInstall1;
protected HtmlGenericControl DivInstall2;
protected HtmlGenericControl DivInstall3;
protected HtmlGenericControl DivInstall4;
protected HtmlGenericControl DivIntallComplete;
protected DropDownList DropSqlVersion;
protected HtmlForm form1;
private static FileVersionInfo FvInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
protected HtmlInputHidden HdnPassword;
protected HtmlImage ImgCreateDataBaseFail;
protected HtmlImage ImgCreateDataBaseOK;
protected Label LblCheckConnectString;
protected HtmlGenericControl LblCreateDataBaseBefore;
protected HtmlGenericControl LblCreateDataBaseMessage;
protected HtmlGenericControl LblCreateDataProgress;
protected Label LblErrorMessage;
protected Label LblInstallMessage;
protected Label LblProductCopyright;
protected Label LblProductName1;
protected Label LblProductName2;
protected Label LblProductName3;
protected Button NextButtonStep2;
protected Button NextButtonStep3;
protected Button NextButtonStep4;
protected Button NextButtonStep5;
protected Button PreviousButtonStep2;
protected Button PreviousButtonStep3;
protected Button PreviousButtonStep4;
protected Button PreviousButtonStep5;
private const string PreviousProductName = "PEOLD";
public static readonly string ProductVersion = FvInfo.ProductVersion;
protected Button StartNextButton;
protected Table TblInstallFileCheck;
protected TextBox TxtAdminName;
protected TextBox TxtAdminPassword;
protected TextBox TxtAdminPasswordAgain;
protected TextBox TxtDataBase;
protected TextBox TxtDataSource;
protected HtmlTextArea TxtLicense;
protected TextBox TxtManageDir;
protected TextBox TxtPassword;
protected TextBox TxtSiteManageCode;
protected TextBox TxtSiteTitle;
protected TextBox TxtSiteUrl;
protected TextBox TxtUserID;
private const string UpgradeProductName = "PENEW";
protected CompareValidator ValcAdminPasswordAgain;
protected RequiredFieldValidator ValrAdminPassword;
protected RequiredFieldValidator ValrAdminPasswordAgain;
protected RequiredFieldValidator ValrDataBase;
protected RequiredFieldValidator ValrDataSource;
protected RequiredFieldValidator ValrManageDir;
protected RequiredFieldValidator ValrPassword;
protected RequiredFieldValidator ValrSiteManageCode;
protected RequiredFieldValidator ValrSiteTitle;
protected RequiredFieldValidator ValrSiteUrl;
protected RequiredFieldValidator ValrUserID;
protected WizardStep WizardStep1;
protected WizardStep WizardStep2;
protected WizardStep WizardStep3;
protected WizardStep WizardStep4;
protected WizardStep WizardStep5;
protected WizardStep WizardStep6;
protected Wizard WzdInstall;
public static TableRow BinDllCheck(ref bool error)
{
string binDirectory = HttpRuntime.BinDirectory;
string[] strArray = new string[] {
"AjaxControlToolkit.dll", "CodeEngine.Framework.dll", "ICSharpCode.SharpZipLib.dll", "Microsoft.Practices.EnterpriseLibrary.Common.dll", "Microsoft.Practices.EnterpriseLibrary.Data.dll", "Microsoft.Practices.ObjectBuilder.dll", "Microsoft.ReportViewer.WebForms.dll", "PowerEasy.AccessManage.dll", "PowerEasy.Accessories.dll", "PowerEasy.AD.dll", "PowerEasy.Analytics.dll", "PowerEasy.Collection.dll", "PowerEasy.Common.dll", "PowerEasy.CommonModel.dll", "PowerEasy.Components.dll", "PowerEasy.Contents.dll",
"PowerEasy.Controls.dll", "PowerEasy.Crm.dll", "PowerEasy.DalFactory.dll", "PowerEasy.Enumerations.dll", "PowerEasy.ExtendedControls.dll", "PowerEasy.IDal.dll", "PowerEasy.Logging.dll", "PowerEasy.Model.dll", "PowerEasy.ModelControls.dll", "PowerEasy.Shop.dll", "PowerEasy.SqlServerDal.dll", "PowerEasy.StaticHtml.dll", "PowerEasy.Survey.dll", "PowerEasy.TableCacheDependency.dll", "PowerEasy.Templates.dll", "PowerEasy.UserManage.dll",
"PowerEasy.Web.dll", "PowerEasy.WebSite.dll", "System.Web.Extensions.dll"
};
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Attributes["bgcolor"] = "#ffffff";
cell.Attributes["width"] = "85%";
TableCell cell2 = new TableCell();
cell2.Attributes["bgcolor"] = "#ffffff";
cell2.Attributes["width"] = "15%";
Image child = new Image();
try
{
FileInfo[] files = new DirectoryInfo(binDirectory).GetFiles("*.dll");
foreach (string str2 in strArray)
{
int num = 0;
foreach (FileInfo info2 in files)
{
if (string.Compare(str2, info2.Name, true) == 0)
{
break;
}
num++;
if (num == files.Length)
{
error = true;
}
}
}
if (error)
{
cell.Text = "缺少程序集文件,请将所有的dll文件复制到目录 " + binDirectory + " 中。";
child.ImageUrl = "images/error.gif";
cell2.Controls.Add(child);
return row;
}
cell.Text = "程序集文件完整性验证通过!";
child.ImageUrl = "images/ok.gif";
cell2.Controls.Add(child);
}
catch (DllNotFoundException)
{
cell.Text = "请将所有的程序集文件复制到目录 " + binDirectory + " 中。";
child.ImageUrl = "images/error.gif";
cell2.Controls.Add(child);
error = true;
}
finally
{
row.Cells.Add(cell);
row.Cells.Add(cell2);
}
return row;
}
protected void BtnCreateDateBase_Click(object sender, EventArgs e)
{
this.LblCreateDataBaseBefore.InnerText = "正在创建数据库。";
this.LblCreateDataProgress.Visible = true;
string connectString = "server=" + this.TxtDataSource.Text + ";database=" + this.TxtDataBase.Text + ";uid=" + this.TxtUserID.Text + ";pwd=" + this.HdnPassword.Value;
string fileName = string.Empty;
if (string.Compare(this.DropSqlVersion.SelectedValue, "2005") == 0)
{
fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\SQLServer2005.sql");
}
if (string.Compare(this.DropSqlVersion.SelectedValue, "2000") == 0)
{
fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\SQLServer2000.sql");
}
if (CreateDataBase(fileName, connectString))
{
this.ImgCreateDataBaseOK.Visible = true;
this.LblCreateDataBaseBefore.InnerText = "创建数据库成功!";
this.BtnCreateDateBase.Visible = false;
this.NextButtonStep4.Enabled = true;
}
else
{
this.ImgCreateDataBaseFail.Visible = true;
this.LblCreateDataBaseBefore.InnerText = "创建数据库失败!";
}
this.LblCreateDataProgress.Visible = false;
}
protected void BtnCreateDateBase_ServerClick(object sender, EventArgs e)
{
}
private static void ChangeAdminPassword(string connectString, string password)
{
string str = string.Empty;
using (MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider())
{
str = BitConverter.ToString(provider.ComputeHash(Encoding.UTF8.GetBytes(password))).Replace("-", "").ToLower();
}
SqlConnection connection = new SqlConnection(connectString);
SqlCommand command = new SqlCommand();
connection.Open();
SqlTransaction transaction = connection.BeginTransaction();
command.Connection = connection;
command.Parameters.Add("@password", SqlDbType.NVarChar).Value = str;
command.CommandText = "update PE_Admin set AdminPassword=@password WHERE AdminName='admin'";
command.CommandType = CommandType.Text;
command.Transaction = transaction;
try
{
command.ExecuteNonQuery();
transaction.Commit();
}
catch (SqlException exception)
{
transaction.Rollback();
throw new Exception(exception.Message);
}
finally
{
command.Dispose();
connection.Close();
connection.Dispose();
}
}
protected void ChlkAgreeLicense_CheckedChanged(object sender, EventArgs e)
{
this.StartNextButton.Enabled = this.ChlkAgreeLicense.Checked;
}
protected void ChlkIsCreateDataBase_CheckedChanged(object sender, EventArgs e)
{
if (this.ChlkIsCreateDataBase.Checked)
{
this.NextButtonStep4.Enabled = true;
this.BtnCreateDateBase.Enabled = false;
}
else
{
this.NextButtonStep4.Enabled = false;
this.BtnCreateDateBase.Enabled = true;
}
}
private static bool CreateDataBase(string fileName, string connectString)
{
SqlConnection connection = new SqlConnection(connectString);
SqlCommand command = new SqlCommand();
connection.Open();
command.Connection = connection;
using (StreamReader reader = new StreamReader(fileName, Encoding.UTF8))
{
try
{
while (!reader.EndOfStream)
{
StringBuilder builder = new StringBuilder();
while (!reader.EndOfStream)
{
string str = reader.ReadLine();
if (!string.IsNullOrEmpty(str) && str.ToUpper().Trim().Equals("GO"))
{
break;
}
builder.AppendLine(str);
}
command.CommandType = CommandType.Text;
command.CommandText = builder.ToString();
command.CommandTimeout = 300;
command.ExecuteNonQuery();
}
}
catch (SqlException)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -