protected void ResetDBInfo_Click(object sender, EventArgs e) { if (AdminPasswordTextBox.Text.Length < 6) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统管理员密码不能少于6位!');</script>"); return; } if (DatabaseTextBox.Text.Length == 0 && DBTypeDropDownList.SelectedValue == "SqlServer") { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>数据库名称不能为空!</script>"); return; } if (DBTypeDropDownList.SelectedIndex == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择数据库类型!');</script>"); return; } try { SiteConfigInfo __configinfo; try { __configinfo = SiteConfigs.GetConfig(); } catch { __configinfo = new SiteConfigInfo(); } __configinfo.AdministratorKey = Encrypt(AdminPasswordTextBox.Text); __configinfo.IsPasswordHashed = true; __configinfo.SiteName = WebsiteNameTextBox.Text; __configinfo.AdministratorName = AdminNameTextBox.Text; SiteConfigs.Serialize(__configinfo, Server.MapPath("~/Config/site.config")); Session["SystemAdminName"] = AdminNameTextBox.Text; Session["SystemAdminPwd"] = AdminPasswordTextBox.Text; } catch { } string setupDBType = SelectDB = DBTypeDropDownList.SelectedValue; DatabaseInfo dbi = new DatabaseInfo(); dbi.Server = ServerTextBox.Text; dbi.Database = DatabaseTextBox.Text; dbi.User = UserTextBox.Text; dbi.Password = PasswordTextBox.Text; dbi.DBFile = DBFileNameTextBox.Text; BaseConfigInfo bci = Installer.GenerateConnectionString(setupDBType, dbi); if (!SaveDBConfig(bci)) { ResetDBInfo.Enabled = false; Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>if(confirm('无法把设置写入\"db.config\"文件,系统将把文件内容显示出来,您可以将内容保存为\"db.config\",然后通过FTP软件上传到网站根目录下.. \\r\\n*注意:db.config位于网站Config目录下。\\r\\n\\r\\n如要继续运行安装,请按\"确定\"按钮.')){window.location.href='step4.aspx?isforceload=1';}else{window.location.href='step3.aspx';}</script>"); return; } if (bci.DBType == "Oracle" || bci.DBType == "MySql") { CreateNewDBCheckBox.Checked = false; } if (CreateNewDBCheckBox.Checked) { Exception ex = null; int ret = Installer.CreateDatabase(bci, out ex); if (ret == -1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据库已经存在,请重新命名或去掉“创建新数据库”前的勾,使用已有数据库');</script>"); return; } if (ret == 0) { string exceptionMsgs = We7Helper.ConvertTextToHtml(ex.Message); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据库创建失败,错误原因:" + exceptionMsgs + "');</script>"); return; } } string msg = ""; if (!Installer.CheckConnection(bci, out msg)) { msg = We7Helper.ConvertTextToHtml(msg); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('连接数据库失败,请检查您填写的数据库信息。" + msg + "');</script>"); return; } else { Response.Redirect(Server.HtmlEncode(string.Format("step4.aspx?db={0}", setupDBType)), true); } }
[SoapHeader("header")] //用户身份验证的soap header public string InitDBConfig(string setupDbType, DatabaseInfo dbi) { //验证是否有权访问(当然,也可以通过查询数据库实现,具体视项目要求) if (!CheckAdmin(header.UserName, header.PassWord)) { throw new Exception("无权使用此服务"); } string source = "We7.CMS.Install-InstallWebService-SetSiteConfig"; try { BaseConfigInfo baseConfig = Installer.GenerateConnectionString(setupDbType, dbi); string file = Server.MapPath("~/config/db.config"); BaseConfigs.SaveConfigTo(baseConfig, file); BaseConfigs.ResetConfig(); if (dbi.CreateDB) { Exception ex = null; int ret = Installer.CreateDatabase(baseConfig, out ex); if (ret == -1) { string msg = "数据库已存在,请重新命名或去掉重新“创建新数据库”前面的勾,使用已有数据库。"; Exception ex1 = new Exception(msg); EventLogHelper.WriteToLog(source, ex1, EventLogEntryType.Error); return(msg); } else if (ret == 0) { string exceptionMsgs = ex.Message; EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); return("创建数据库发生错误。错误原因:" + exceptionMsgs); } } //设置数据库脚本路径 //string basePath = Server.MapPath("/install/SQL"); //if (!Directory.Exists(basePath)) //{ // basePath = Server.MapPath("../install/SQL"); //} if (!Directory.Exists(Server.MapPath("/_data/"))) { Directory.CreateDirectory(Server.MapPath("/_data/")); } List <string> files = new List <string>(); files.Add("create.xml"); files.Add("install.xml"); files.Add("update.xml"); Installer.ExcuteSQLGroup(baseConfig, files); //创建内容模型表 Installer.CreateModelTables(); ApplicationHelper.ResetApplication(); return("0"); } catch (Exception ex) { EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); return("创建数据库发生错误。错误原因:" + ex.Message); } }
private void CopyFilesButton_Click(object sender, EventArgs e) { //configuration文件夹改名 兼容2.7以前版本方法 string oldConfigPath = Path.Combine(Server.MapPath("~/"), "configuration"); if (Directory.Exists(oldConfigPath)) { string destDirName = Path.Combine(Server.MapPath("~/"), "config"); if (Directory.Exists(destDirName)) { Directory.Delete(destDirName, true); } Directory.Move(oldConfigPath, Path.Combine(Server.MapPath("~/"), "config")); } if (BackUpPanel.Visible) { if (BackUpCheckBox.Checked) { Installer.BackupOldFiles(Server.MapPath("~/"), Server.MapPath("~/_backup/update/")); } //检查是否有冗余文件 if (ClearOldCheckBox.Visible && ClearOldCheckBox.Checked) { //此处应该返回错误信息,目前存储在LOG文件中 DeleteFiles(); } } string ext = Path.GetExtension(UploadFile); switch (ext.ToLower()) { case ".zip": try { //DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath("~/bin")); //Helper.DeleteFileTree(directoryInfo, false); We7Helper.CopyDirectory(UnZipPath, Server.MapPath("~/")); Directory.Delete(UnZipPath, true); // /* * * 保存新版本号 * GeneralConfigInfo si = GeneralConfigs.GetConfig(); * if (si != null) * { * //si.ProductVersion = NewVersion; * GeneralConfigs.SaveConfig(si); * } */ RegisterScript("alert('操作成功!');location.href='upgrade-db.aspx?from=upgrade.aspx'"); } catch (IOException ex) { RegisterScript("alert('文件复制失败。原因:" + ex.Message + "');"); } break; case ".dll": try { string targetfile = Path.Combine(Server.MapPath("~/bin/"), Path.GetFileName(UploadFile)); File.Copy(UploadFile, targetfile, true); RegisterScript("alert('文件更新成功!');"); } catch (IOException ex) { RegisterScript("alert('文件复制失败。原因:" + ex.Message + "');"); } break; case ".xml": try { //读取默认db.config文件内容 BaseConfigInfo bci = BaseConfigs.GetBaseConfig(); if (bci != null && bci.DBType != "" && bci.DBConnectionString != "") { Installer.ExcuteSQL(bci, UploadFile); } RegisterScript("alert('XML文件执行成功!');"); } catch (IOException ex) { RegisterScript("alert(''XML文件执行出现错误。原因:" + ex.Message + "');"); } break; } }