点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 论坛社区>> 动网论坛DotNet版1.0源码(VS2005)>> 源文件浏览
[免费版 Free] WebForm,下载次数:6237 次 | 关键字: 持久层 动网 论坛 ORM框架多层开发

源码截图

源码目录树

当前路径:WebApp/upgrade/upgrade.1.0 Release.aspx     <%@ Page Src="UpgradeBase.cs" Inherits="Dvbbs.Upgrade.UpgradeBase" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="Dvbbs.Utils" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="Dvbbs.bbs.Entity" %>
<%@ Import Namespace="Dvbbs.bbs.Handlers" %>
<%@ Import Namespace="Dvbbs.Data" %>
<script language="C#" runat="server">
	private BoardStatus mBoardStatus;
	/// <summary>
	/// 本版包含的所有子版面 SubBoardList
	/// </summary>
	protected BoardStatus BoardStatus
	{
		get
		{
			return mBoardStatus;
		}
	}
	private string mBoardMaster;
	/// <summary>
	/// 版主
	/// </summary>
	protected string BoardMaster
	{
		get
		{
			return mBoardMaster;
		}
	}

//	private void WriteLog(string filePath, string data, bool append)
//	{
//		if (null == filePath || 0 == filePath.Length)
//		{
//			filePath = Server.MapPath("./tmp.log");
//		}
//		using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath, append))
//		{
//			writer.Write(data);
//		}
//	}

protected override void OnInit(EventArgs e)
{
	Response.ContentType = "text/html";
	Response.Charset = "gb2312";

	jsonReply.Ver = "1.0 Release";
	jsonReply.FileName ="upgrade.1.0 Release.aspx";
	jsonReply.RetVal = 1;
	jsonReply.ErrorMsg = "";
	jsonReply.Args = "";
	jsonReply.Steps = 0;

	try
	{
		string isclose=config["ServiceDown"].ToString();
		if(isclose=="False")
		{	
			jsonReply.RetVal = 0;
			jsonReply.ErrorMsg = "当前论坛未关闭,请先关闭论坛!";
			return;
		}
		DoUpgrade();
		
		if(jsonReply.RetVal == 1)			
			UpdateVersion(); // 更新版本号
		
		Response.Write(jsonReply.ToJSONString());		
	}
	finally
	{
		base.Finish();
	}
	Response.End();	
}
private void DoUpgrade()
{
	string AccessTimes = Fetch.Get("AccessTimes");
	if(AccessTimes=="" || AccessTimes==null)
	{
		SaveUpgradeLog("******开始升级:VER(" + jsonReply.Ver + ")" + System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString() + "******");
		if(!UpdateUserConfigV1_0_0_2513_rc4())
			return;
		if(!UpdateDataTableV1_0_0_2513_rc4())
			return;	
		if(!UpdateWebConfigV1_0_0_2513_rc4())
			return;
		if (conn.Provider == DbProviderEnum.SqlServer)
		{
			if(!UpdateDv_bbsTablesMSV1_0_0_2513_rc4())
				return;
		}
	
		if (conn.Provider == DbProviderEnum.Access)
		{
			if(!UpdateDv_bbsTablesACV1_0_0_2513_rc4())
				return;
		}		
	}
	string current_proc = Fetch.Get("current_proc");
	if(current_proc=="0" || current_proc=="" || current_proc ==null)
	{
		if(!RebuildIndexV1_0_0_2513_rc4())
			return;
	}
	else
	{
		if(!ReSetUserTableV1_0_0_2513_rc4())
			return;
	}
		
	SaveUpgradeLog("******OK,升级结束:" + System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString() + "******");
	
}
private bool UpdateDv_bbsTablesACV1_0_0_2513_rc4()
{
	DataTable dt = conn.GetDataTable("select TableName from "+Fetch.TablePrefix+"tablelist ");
	bool retval = false;
	for(int tables=0;tables<dt.Rows.Count;tables++)
	{
		try
		{
			conn.Execute(" Alter table "+dt.Rows[tables][0].ToString()+" ADD isaudit  bit not NULL default 0" );
			retval = true;
		}
		catch(Exception)
		{
			SaveUpgradeLog("ERROR-->UpdateUserConfigV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
			retval = false;
		}

	}
	return retval;
}
private bool UpdateDv_bbsTablesMSV1_0_0_2513_rc4()
{
	DataTable dt = conn.GetDataTable("select TableName from "+Fetch.TablePrefix+"tablelist ");
	bool retval = false;
	for(int tables=0;tables<dt.Rows.Count;tables++)
	{
		try
		{
			conn.Execute("if not exists (SELECT name FROM dbo.syscolumns WHERE name=(N'isaudit ') AND id=object_id(N'[dbo].["+Fetch.TablePrefix+"tablelist]')) Alter table "+dt.Rows[tables][0].ToString()+" ADD isaudit  bit not NULL default (0)" );
			retval = true;
		}
		catch(Exception)
		{
			SaveUpgradeLog("ERROR-->UpdateUserConfigV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
			retval = false;
		}

	}
	return retval;
}

private bool UpdateWebConfigV1_0_0_2513_rc4()
{
	XmlDocument xml = new XmlDocument();
	try
	{	
		SaveUpgradeLog("开始升级系统配置文件:");			

		string path = Server.MapPath("../Web.config");
		xml.Load(path);		
		XmlNode ParentNode = xml.DocumentElement.SelectSingleNode("//configuration/appSettings");
		XmlNode node = xml.DocumentElement.SelectSingleNode("//configuration/appSettings/add[@key='PathUpSeek']");
		if(node != null)
		{		
			ParentNode.RemoveChild(node);	
			
			XmlElement ele_wap = xml.CreateElement("add");
			ele_wap.SetAttribute("key", "PathUpSeek");
			ele_wap.SetAttribute("value", @"/install|/templates|/admin|/archiver/xml|/archiver/xhtml|/wap");			
			xml.DocumentElement.SelectSingleNode("//configuration/appSettings").AppendChild(ele_wap.CloneNode(false));
			SaveUpgradeLog("ADD:"+ ele_wap.OuterXml);			
			SaveUpgradeLog("ADD:" + node.OuterXml);
		}
		node = null;
		xml.Save(path);
		SaveUpgradeLog("升级系统配置文件成功!");

		return true;
	} 
	catch(Exception ex)
	{
		jsonReply.ErrorMsg = "升级系统配置文件错误:" + ex.Message;
		jsonReply.RetVal = 0;

		SaveUpgradeLog("ERROR-->UpdateWebConfigV1_0_0_2510_rc4():" + jsonReply.ErrorMsg);
		return false;
	}			
}

private bool UpdateUserConfigV1_0_0_2513_rc4()
{
	// 更新用户配置文件
	XmlDocument xml = new XmlDocument();
	try
	{				
		SaveUpgradeLog("开始升级用户配置文件:");
		// 更新 bbs.config
		string path = Server.MapPath("../" + ApplicationSettings.Get("CustomConfigFile"));
		xml.Load(path);
		XmlNode Pnode = xml.DocumentElement.SelectSingleNode("//Config/Settings/Basic");
		XmlNode node = xml.DocumentElement.SelectSingleNode("//Config/Settings/Basic/Item[Name='EnIndexList']");		
				
		if (null != node)
		{
			Pnode.RemoveChild(node);
			SaveUpgradeLog("ADD:" + node.OuterXml);
		}
		
		XmlNode ValidateCodeSettings = xml.DocumentElement.SelectSingleNode("//Config/Settings/ValidateCodeSettings");
		if(ValidateCodeSettings==null)
		{
			XmlNode Settings = xml.DocumentElement.SelectSingleNode("//Config/Settings");			
			XmlNode ValidateCodeSetting = xml.CreateNode(XmlNodeType.Element,"ValidateCodeSettings","");
			Settings.AppendChild(ValidateCodeSetting);
			//ValidateCodeSetting = xml.DocumentElement.SelectSingleNode("//Config/Settings/ValidateCodeSettings");
			
			
			XmlElement ele_title = xml.CreateElement("Title");
			XmlElement ele_name = xml.CreateElement("Name");
			XmlElement ele_explain = xml.CreateElement("Explain");
			XmlElement ele_mode = xml.CreateElement("Mode");
			XmlElement ele_value = xml.CreateElement("Value");
			XmlElement ele_required = xml.CreateElement("Required");				
			ele_title.InnerText = @"当前验证码文件的路径";
			ele_name.InnerText = "ValidateCodeFilePath";
			ele_explain.InnerText = @"如果您的论坛被人使用了注册机,您可以更改此处的验证码文件的路径,这能让您的论坛在一段时间内免受注册机的侵扰。";
			ele_mode.InnerText = "Text";
			ele_value.InnerText = "image.aspx";
			ele_required.InnerText = "True";			
			XmlElement ele_item = xml.CreateElement("Item");
			ele_item.AppendChild(ele_title);
			ele_item.AppendChild(ele_name);
			ele_item.AppendChild(ele_explain);
			ele_item.AppendChild(ele_mode);
			ele_item.AppendChild(ele_value);
			ele_item.AppendChild(ele_required);
			xml.DocumentElement.SelectSingleNode("//Config/Settings/ValidateCodeSettings").InsertAfter(ele_item, xml.DocumentElement.SelectSingleNode("//Config/Settings/Basic/ValidateCodeSettings[Name='ValidateCodeFilePath']"));
			
			SaveUpgradeLog("ADD:" + ele_item.OuterXml);
			
		}
		
		node = xml.DocumentElement.SelectSingleNode("//Config/Settings/Basic/Item[Name='bbsLogo']");		
		if(null!=node)
		{
			Pnode.RemoveChild(node);	
			
			XmlElement ele_title = xml.CreateElement("Title");
			XmlElement ele_name = xml.CreateElement("Name");
			XmlElement ele_explain = xml.CreateElement("Explain");
			XmlElement ele_mode = xml.CreateElement("Mode");
			XmlElement ele_value = xml.CreateElement("Value");	
			XmlElement ele_Pattern = xml.CreateElement("Pattern");	
			XmlElement ele_required = xml.CreateElement("Required");			
			ele_title.InnerText = @"Logo标志地址";
			ele_name.InnerText = "bbsLogo";
			ele_explain.InnerText = @"您论坛站点的Logo标志地址,在当前使用的皮肤下,如 logo.gif,可为空,为空则使用默认的路径";
			ele_mode.InnerText = "Text";
			ele_value.InnerText = "logo.gif";
			ele_Pattern.InnerText=@"^.*$";   
			ele_required.InnerText="False";		
			XmlElement ele_item = xml.CreateElement("Item");			
			ele_item.AppendChild(ele_title);
			ele_item.AppendChild(ele_name);
			ele_item.AppendChild(ele_explain);
			ele_item.AppendChild(ele_mode);
			ele_item.AppendChild(ele_value);
			ele_item.AppendChild(ele_Pattern);
			ele_item.AppendChild(ele_required);
			xml.DocumentElement.SelectSingleNode("//Config/Settings/Basic").InsertAfter(ele_item, xml.DocumentElement.SelectSingleNode("//Config/Settings/Basic/Item[Name='bbsLogo']"));
			
			SaveUpgradeLog("ADD:" + ele_item.OuterXml);
			
		}
		
		node = xml.DocumentElement.SelectSingleNode("//Config/Settings/UserOperation/Item[Name='FriendPer']");
		if(null==node)
		{
			XmlElement ele_title = xml.CreateElement("Title");
			XmlElement ele_name = xml.CreateElement("Name");
			XmlElement ele_explain = xml.CreateElement("Explain");
			XmlElement ele_mode = xml.CreateElement("Mode");
			XmlElement ele_value = xml.CreateElement("Value");
			XmlElement ele_pattern = xml.CreateElement("Pattern");
			XmlElement ele_required = xml.CreateElement("Required");
			ele_title.InnerText = @"每页显示好友数";
			ele_name.InnerText = "FriendPer";
			ele_explain.InnerText = @"控制面板中每页显示多少好友";
			ele_mode.InnerText = "Numeric";
			ele_value.InnerText = "10";
			ele_pattern.InnerText = @"^[\d]{1,2}$";
			ele_required.InnerText = "False";
			XmlElement ele_item = xml.CreateElement("Item");
			
			ele_item.AppendChild(ele_title);
			ele_item.AppendChild(ele_name);
			ele_item.AppendChild(ele_explain);
			ele_item.AppendChild(ele_mode);
			ele_item.AppendChild(ele_value);
			ele_item.AppendChild(ele_pattern);				
			ele_item.AppendChild(ele_required);		
			xml.DocumentElement.SelectSingleNode("//Config/Settings/UserOperation").AppendChild(ele_item);

			SaveUpgradeLog("ADD:" + ele_item.OuterXml);
			
		}
		node = xml.DocumentElement.SelectSingleNode("//Config/Settings/UserOperation/Item[Name='AttachPer']");
		if(null==node)
		{
			XmlElement ele_title = xml.CreateElement("Title");
			XmlElement ele_name = xml.CreateElement("Name");
			XmlElement ele_explain = xml.CreateElement("Explain");
			XmlElement ele_mode = xml.CreateElement("Mode");
			XmlElement ele_value = xml.CreateElement("Value");
			XmlElement ele_pattern = xml.CreateElement("Pattern");
			XmlElement ele_required = xml.CreateElement("Required");
			ele_title.InnerText = @"每页显示附件数";
			ele_name.InnerText = "AttachPer";
			ele_explain.InnerText = @"控制面板中每页显示多少附件";
			ele_mode.InnerText = "Numeric";
			ele_value.InnerText = "10";
			ele_pattern.InnerText = @"^[\d]{1,2}$";
			ele_required.InnerText = "False";
			XmlElement ele_item = xml.CreateElement("Item");
			ele_item.AppendChild(ele_title);
			ele_item.AppendChild(ele_name);
			ele_item.AppendChild(ele_explain);
			ele_item.AppendChild(ele_mode);
			ele_item.AppendChild(ele_value);
			ele_item.AppendChild(ele_pattern);				
			ele_item.AppendChild(ele_required);		
			xml.DocumentElement.SelectSingleNode("//Config/Settings/UserOperation").AppendChild(ele_item);

			SaveUpgradeLog("ADD:" + ele_item.OuterXml);
			
		}
		node = xml.DocumentElement.SelectSingleNode("//Config/Settings/UserOperation/Item[Name='MessagePer']");
		if(null==node)
		{
			XmlElement ele_title = xml.CreateElement("Title");
			XmlElement ele_name = xml.CreateElement("Name");
			XmlElement ele_explain = xml.CreateElement("Explain");
			XmlElement ele_mode = xml.CreateElement("Mode");
			XmlElement ele_value = xml.CreateElement("Value");
			XmlElement ele_pattern = xml.CreateElement("Pattern");
			XmlElement ele_required = xml.CreateElement("Required");
			ele_title.InnerText = @"每页显示短信数";
			ele_name.InnerText = "MessagePer";
			ele_explain.InnerText = @"短信箱中每页显示多少短信";
			ele_mode.InnerText = "Numeric";
			ele_value.InnerText = "10";
			ele_pattern.InnerText = @"^[\d]{1,2}$";
			ele_required.InnerText = "False";
			XmlElement ele_item = xml.CreateElement("Item");
			ele_item.AppendChild(ele_title);
			ele_item.AppendChild(ele_name);
			ele_item.AppendChild(ele_explain);
			ele_item.AppendChild(ele_mode);
			ele_item.AppendChild(ele_value);
			ele_item.AppendChild(ele_pattern);				
			ele_item.AppendChild(ele_required);		
			xml.DocumentElement.SelectSingleNode("//Config/Settings/UserOperation").AppendChild(ele_item);

			SaveUpgradeLog("ADD:" + ele_item.OuterXml);			
		}
		
		node = null;
		xml.Save(path);
		SaveUpgradeLog("升级用户配置文件成功!");
		return true;
	}
	catch(Exception ex)
	{
		jsonReply.ErrorMsg = "升级用户配置文件错误:" + ex.Message;
		jsonReply.RetVal = 0;
		SaveUpgradeLog("ERROR-->UpdateUserConfigV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
		return false;
	}
}

private bool RebuildIndexV1_0_0_2513_rc4()
{
	try
	{		
		SaveUpgradeLog("开始建立索引:");
		uint start_topicid = (0 == Fetch.Get("start_topicid").Length ? 1 : uint.Parse(Fetch.Get("start_topicid")));
		uint last_topicid = TopicIndexManager.RebuildIndex(conn, start_topicid, 100);
		if(last_topicid > 0)
		{
			jsonReply.RetVal = 2;
			jsonReply.Args = "current_proc=0&AccessTimes=1&start_topicid=" + (last_topicid + 1).ToString();
			SaveUpgradeLog("主题ID:"+last_topicid);
		}
		else
		{

			jsonReply.RetVal = 2;
			jsonReply.Args = "current_proc=1&AccessTimes=1";
			SaveUpgradeLog(jsonReply.Args);
			SaveUpgradeLog("建立索引成功!");
		}
		return true;

	}
	catch(Exception ex)
	{
		jsonReply.ErrorMsg = "建立索引错误:" + ex.Message;
		jsonReply.RetVal = 0;
		SaveUpgradeLog("ERROR-->RebuildIndexV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
		return false;
	}
}
private bool ReSetUserTableV1_0_0_2513_rc4()
{
	try
	{
		SaveUpgradeLog("开始修改用户表权限:");
		uint start_userid = (0 == Fetch.Get("start_userid").Length ? 1 : uint.Parse(Fetch.Get("start_userid")));
		uint last_userid = ReSetUserTable(conn, start_userid, 100);
		if(last_userid > 0)
		{
			jsonReply.RetVal = 2;
			jsonReply.Args = "current_proc=1&AccessTimes=1&start_userid=" + (last_userid + 1).ToString();
			SaveUpgradeLog("用户ID:"+last_userid);
		}
		else
		{
			jsonReply.RetVal = 1;		
		}
		SaveUpgradeLog("修改用户表权限成功!");
		return true;

	}
	catch(Exception ex)
	{
		jsonReply.ErrorMsg = "修改用户表权限错误:" + ex.Message;
		jsonReply.RetVal = 0;
		SaveUpgradeLog("ERROR-->ReSetUserTableV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
		return false;
	}
}
private uint ReSetUserTable(Connection conn, uint startUserId, ushort pageSize)
{
	// 参数检测
	if (null == conn)
	{
		throw new ArgumentNullException("conn");
	}
	if (0 == startUserId)
	{
		throw new ArgumentException("startTopicId的值必须大于0!");
	}
	if (0 == pageSize)
	{
		throw new ArgumentException("pageSize的值必须大于0!");
	}

	int last_UserId = 0;

	// 获取以逗号分隔的 UserId 的列表
	StringBuilder sb = new StringBuilder("0");
	using (IDataReader reader = conn.GetReader("SELECT TOP " + pageSize.ToString() + " userid FROM " + Fetch.TablePrefix + "user WHERE userid>="+ startUserId.ToString()+" order by userid asc"))
	{
		while (reader.Read())
		{
			last_UserId = reader.GetInt32(0);
			sb.Append("," + last_UserId.ToString());
		}
	}
	// 如果 sb.Length 等于 1,说明没有找到更多的记录,此时应返回0
	if (1 == sb.Length)
	{
		return 0;
	}
	// 以逗号分隔的 UserId 的列表
	string ids = sb.ToString();

	// 释放对象 sb
	sb = null;
	try
	{		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid_backup=usergroupid WHERE userid IN(", ids, ")"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set userpower_backup=userpower WHERE userid IN(", ids, ")"));
		if (conn.Provider == DbProviderEnum.SqlServer)
		{
			conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set lastposttime=getdate() WHERE userid IN(", ids, ") and lastposttime is null"));
		}
		else
		{
			conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set lastposttime=now() WHERE userid IN(", ids, ") and lastposttime is null"));
		}
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=9 WHERE userid IN(", ids, ") and usergroupid_backup=1"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=10 WHERE userid IN(", ids, ") and usergroupid_backup=2"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=11 WHERE userid IN(", ids, ") and usergroupid_backup=3"));

		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=12 WHERE userid IN(", ids, ") and usergroupid_backup=4"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=13 WHERE userid IN(", ids, ") and usergroupid_backup=5"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=14 WHERE userid IN(", ids, ") and usergroupid_backup=6"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=15 WHERE userid IN(", ids, ") and usergroupid_backup=7"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=16 WHERE userid IN(", ids, ") and usergroupid_backup=8"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=17 WHERE userid IN(", ids, ") and usergroupid_backup=9"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=18 WHERE userid IN(", ids, ") and usergroupid_backup=10"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=19 WHERE userid IN(", ids, ") and usergroupid_backup=11"));
		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=1 WHERE userid IN(", ids, ") and (usergroupid_backup=12 or userpower_backup=9)"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=2 WHERE userid IN(", ids, ") and (usergroupid_backup=13 or userpower_backup=8)"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=3 WHERE userid IN(", ids, ") and (usergroupid_backup=14 or userpower_backup=7)"));
		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=20 WHERE userid IN(", ids, ") and usergroupid_backup=16"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=21 WHERE userid IN(", ids, ") and usergroupid_backup=17"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=22 WHERE userid IN(", ids, ") and usergroupid_backup=18"));
		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=23 WHERE userid IN(", ids, ") and usergroupid_backup=19"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=24 WHERE userid IN(", ids, ") and usergroupid_backup=20"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=25 WHERE userid IN(", ids, ") and usergroupid_backup=21"));
		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=26 WHERE userid IN(", ids, ") and usergroupid_backup=23"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=7 WHERE userid IN(", ids, ") and usergroupid_backup=24"));
		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=usergroupid+2 WHERE userid IN(", ids, ") and usergroupid_backup>=25"));
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set usergroupid=9 WHERE userid IN(", ids, ") and usergroupid=0 and userpower_backup<7"));		
		conn.ExecuteNonQuery(Text.JoinString("Update ", Fetch.TablePrefix, "user set userpower = dvuserpower WHERE userid IN(", ids, ")"));
	}
	catch(Exception ex)
	{
		SaveUpgradeLog("ERROR-->ReSetUserTableV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
	}
	return (uint)last_UserId;

}

private bool UpdateDataTableV1_0_0_2513_rc4()
{
	// 更新数据库表		
	string sqlfile = "";
	string SqlPath = "upgrade\\sql\\";
	//string[] arr = null;	
	XmlTextReader reader = null;
	if (conn.Provider == DbProviderEnum.Access)
		sqlfile = Fetch.MapPath(SqlPath+"1.0.0.0.2513.rc4.ac.xml");
	else //if(conn.Provider == DbProviderEnum.SqlServer)
		sqlfile = Fetch.MapPath(SqlPath+"1.0.0.0.2513.rc4.ms.xml");
		
	try
	{
		reader = new XmlTextReader(Fetch.MapPath(sqlfile));
		reader.WhitespaceHandling = WhitespaceHandling.None;
		reader.MoveToContent();
		//StreamReader reader = new StreamReader(sqlfile, System.Text.Encoding.GetEncoding("GB2312"));
		//arr = reader.ReadToEnd().Split('~');
	}
	catch(Exception ex)
	{
		reader.Close();
		reader = null;
		jsonReply.ErrorMsg = "打开数据库升级SQL文件错误:" + ex.Message;
		jsonReply.RetVal = 0;
		SaveUpgradeLog("ERROR-->UpdateDataTableV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
		return false;
	}
	SaveUpgradeLog("开始升级数据库:");		
	OleDbConnection conn1 = null;
	
	try
	{
		if(conn.Provider == DbProviderEnum.SqlServer)                        //升级MSSQL数据库
		{
			try
			{
				while (reader.Read())
				{
					string columns = string.Empty;
					string table = string.Empty;
					string procedure = string.Empty;
					string sql = string.Empty;
					string Operate = string.Empty;
					if(0!=reader.Depth && 1!=reader.Depth)
					{
						if(2==reader.Depth && reader.IsStartElement() && "TableName" == reader.Name)
						{
							table = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "ProcedureName" == reader.Name)
						{
							procedure = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "ColumnName" == reader.Name)
						{
							columns = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "Operate" == reader.Name)
						{
							Operate = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "SqlString" == reader.Name)
						{
							sql = reader.ReadString();
						}
					}
					if(sql != "" || procedure!="")
					{
						if(0==sql.Trim().Length)
						{
							continue;
						}
						string stmt = sql.Trim().Replace("dv_",Fetch.TablePrefix);
						if(procedure!="" && Operate.Trim().ToLower() == "drop")
						{
							try
							{
								conn.Execute(stmt);
								SaveUpgradeLog("Upgrade Database: " + stmt);
							}
							catch
							{
							}
						}
						else if(Operate.Trim().ToLower() == "dropconstraint")
						{
							try
							{
								if(stmt.IndexOf("~")!=-1)
								{
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									for(int i = 0;i<arr.Length;i++)
									{
										conn.Execute(arr[i].Replace("\r\n",""));
										SaveUpgradeLog("Upgrade Database: " + stmt);
									}
								}
								else
								{
									conn.Execute(stmt);
									SaveUpgradeLog("Upgrade Database: " + stmt);
								}
							}
							catch 
							{
							}
						}
						else if (Operate.Trim().ToLower() == "delete")
						{
							try
							{
								conn.Execute(stmt);
								SaveUpgradeLog("Upgrade Database: " + stmt);
							}
							catch 
							{
							}

						}
						else if (Operate.Trim().ToLower() == "create")
						{
							try
							{
								if(stmt.IndexOf("~")!=-1)
								{
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									for(int i = 0;i<arr.Length;i++)
									{
										conn.Execute(arr[i].Replace("\r\n",""));
										SaveUpgradeLog("Upgrade Database: " + stmt);
									}
								}
								else
								{
									conn.Execute(stmt);
									SaveUpgradeLog("Upgrade Database: " + stmt);
								}
							}
							catch
							{
							}
						}
						else if(Operate.Trim().ToLower() == "update")
						{
							try
							{								
								if(sql.IndexOf("~") !=-1)
								{
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);

									for(int i = 0;i<arr.Length;i++)
									{														
											conn.Execute(arr[i].Replace("\r\n",""));
											SaveUpgradeLog("Upgrade Database: " + stmt);
										
									}									

								}
								else
								{
									conn.Execute(stmt);
									SaveUpgradeLog("Upgrade Database: " + stmt);
								}
							}
							catch
							{
							}
						}
						else if(Operate.Trim().ToLower() == "alter")
						{
							string sql111 = "";
							try
							{
								if(sql.IndexOf("~") !=-1)
								{
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									for(int i = 0;i<arr.Length;i++)
									{
										conn.Execute(arr[i].Replace("\r\n",""));
										SaveUpgradeLog("Upgrade Database: " + stmt);
									}
								}
								else
								{
										conn.Execute(stmt);
										SaveUpgradeLog("Upgrade Database: " + stmt);
								}
							}
							catch(Exception ex)
							{
								
							}
						}
						if(Operate.Trim().ToLower() == "insert")
						{
							try
							{								
								if(sql.IndexOf("~") !=-1)
								{
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									string tabHelp = "dv_help";
									if(table.Replace("dv_",Fetch.TablePrefix) == tabHelp.Replace("dv_",Fetch.TablePrefix))
									{	
										if((int)conn.GetScalar("select count(1) from "+ table.Replace("dv_",Fetch.TablePrefix) + " where H_ParentID=1 and H_Title='UBB语法'")==0)
										{
											for(int i = 0;i<arr.Length;i++)
											{

												conn.Execute(arr[i].Replace("\r\n",""));
												SaveUpgradeLog("Upgrade Database: " + stmt);
											}
										}
									}
									else
									{
										if((int)conn.GetScalar("select count(1) from "+table.Replace("dv_",Fetch.TablePrefix))==0)
										{
											for(int i = 0;i<arr.Length;i++)
											{
												
												conn.Execute(arr[i].Replace("\r\n",""));
												SaveUpgradeLog("Upgrade Database: " + stmt);
											}
										}
									}

								}
								else
								{
									conn.Execute(stmt);
									SaveUpgradeLog("Upgrade Database: " + stmt);									
								
								}
							}
							catch
							{
							}
						}	
					}
				}
			}
			catch
			{
			}
		}
		else if(conn.Provider == DbProviderEnum.Access)                        //升级Access数据库
		{
			try
			{
				while (reader.Read())
				{
					//读取数据
					string columns = string.Empty;           
					string table = string.Empty;
					string procedure = string.Empty;
					string sql = string.Empty;
					string Operate = string.Empty;
					if(0!=reader.Depth && 1!=reader.Depth)
					{
						if(2==reader.Depth && reader.IsStartElement() && "TableName" == reader.Name)
						{
							table = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "ProcedureName" == reader.Name)
						{
							procedure = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "ColumnName" == reader.Name)
						{
							columns = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "Operate" == reader.Name)
						{
							Operate = reader.ReadString().Trim().ToLower();
						}
						reader.Read();
						if(2==reader.Depth && reader.IsStartElement() && "SqlString" == reader.Name)
						{
							sql = reader.ReadString();
						}
					}
					if(sql != "")
					{
						if(0==sql.Trim().Length)
						{
							continue;
						}
						string stmt = sql.Trim().Replace("dv_",Fetch.TablePrefix);
						if (Operate.Trim().ToLower() == "drop")
						{
							try
							{
								conn.Execute(stmt);
								SaveUpgradeLog("Upgrade Database: " + stmt);
							}
							catch
							{
							}

						}
						if (Operate.Trim().ToLower() == "delete")
						{
							try
							{
								conn.Execute(stmt);
								SaveUpgradeLog("Upgrade Database: " + stmt);
							}
							catch
							{
							}

						}
						else if (Operate.Trim().ToLower() == "create")
						{
							try
							{
								conn1 = new OleDbConnection(conn.DBLink);                     //判断该表是否存在,不存在则创建
								conn1.Open();
								DataTable schemaTable = conn1.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
																					new object[] {null, null, null, "TABLE"});
								bool isTableExist = false;
								for(int i=0;i<schemaTable.Rows.Count;i++)
								{
									if(table.Replace("dv_",Fetch.TablePrefix) == schemaTable.Rows[i][2].ToString().Trim().ToLower())
									{
										isTableExist = true;
										break;
									}
									else
									{
										isTableExist = false;
									}
								}
								if(!isTableExist)
								{
										conn.Execute(stmt);
										SaveUpgradeLog("Upgrade Database: " + stmt);
								}
							}
							catch
							{
							}
							finally
							{
								if(conn1 != null)
								{
									conn1.Close();
									conn1 = null;
								}
							}
						}
						else if(Operate.Trim().ToLower() == "alter")                  //修改表结构
						{
							try
							{

								DataSet schemaTable = conn.GetDataSet("Select * from "+ table.Replace("dv_",Fetch.TablePrefix));
								if(columns.IndexOf("|") !=-1)
								{
									string[] arrSql = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									string[] arrCol = columns.Split('|');
									bool isExist = false;
									for(int i = 0;i<arrSql.Length;i++)
									{
										for(int k=0;k<schemaTable.Tables[0].Columns.Count;k++)
										{
											if(schemaTable.Tables[0].Columns[k].ColumnName.Trim().ToLower()==arrCol[i].Trim().ToLower())
											{
												isExist = true;
												break;
											}
											else
											{
												isExist = false;
											}
										}
										if(!isExist)                             //字段不存在
										{
											
											conn.Execute(arrSql[i].Replace("\r\n",""));
											SaveUpgradeLog("Upgrade Database: " + stmt);
										}
										if(arrSql[i].ToLower().IndexOf("alter",6) !=-1)
										{
											conn.Execute(arrSql[i].Replace("\r\n",""));
											SaveUpgradeLog("Upgrade Database: " + stmt);
										}
										
									}
								}
								else
								{
									bool isExist = false;                         //字段是否存在的标记
									for(int k=0;k<schemaTable.Tables[0].Columns.Count;k++)
									{
										if(schemaTable.Tables[0].Columns[k].ColumnName.Trim().ToLower()==columns.Trim().ToLower())
										{
											isExist = true;
											break;
										}
										else
										{
											isExist = false;
										}
									}

									if(!isExist)                             //字段不存在
									{
										conn.Execute(stmt);
										SaveUpgradeLog("Upgrade Database: " + stmt);
									}
									if(stmt.ToLower().IndexOf("alter",6)!=-1)
									{
										conn.Execute(stmt);
										SaveUpgradeLog("Upgrade Database: " + stmt);
									}
								}
							}
							catch
							{
							}
							finally
							{
								if(conn1 != null)
								{
									conn1.Close();
									conn1 = null;
								}
							}
						}
						else if(Operate.Trim().ToLower() == "update")
						{
							try
							{								
								if(sql.IndexOf("~") !=-1)
								{
									string tabusergroups = "dv_temp_usergroups";
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									for(int i = 0;i<arr.Length;i++)
									{
								
										conn.Execute(arr[i].Replace("\r\n",""));														
										SaveUpgradeLog("Upgrade Database: " + stmt);
											
									}									

								}
								else
								{
									conn.Execute(stmt);
									SaveUpgradeLog("Upgrade Database: " + stmt);
								}
							}
							catch
							{
							}
						}
						if(Operate.Trim().ToLower() == "insert")                 
						{
							try
							{								
								if(sql.IndexOf("~") !=-1)
								{
									string[] arr = System.Text.RegularExpressions.Regex.Split(stmt,"~",System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
									string tabHelp = "dv_help";
									if(table.Replace("dv_",Fetch.TablePrefix) == tabHelp.Replace("dv_",Fetch.TablePrefix))
									{	
										if((int)conn.GetScalar("select count(1) from "+ table.Replace("dv_",Fetch.TablePrefix) + " where H_ParentID=1 and H_Title='UBB语法'")==0)
										{
											for(int i = 0;i<arr.Length;i++)
											{

												conn.Execute(arr[i].Replace("\r\n",""));
												SaveUpgradeLog("Upgrade Database: " + stmt);
											}
										}
									}
									else
									{
										if((int)conn.GetScalar("select count(1) from "+table.Replace("dv_",Fetch.TablePrefix))==0)
										{
											for(int i = 0;i<arr.Length;i++)
											{
												
												conn.Execute(arr[i].Replace("\r\n",""));
												SaveUpgradeLog("Upgrade Database: " + stmt);
											}
										}
									}

								}
								else
								{
									string tabHelp = "dv_help";
									if(table.Replace("dv_",Fetch.TablePrefix)==tabHelp.Replace("dv_",Fetch.TablePrefix))
									{

										conn.Execute(stmt);
										SaveUpgradeLog("Upgrade Database: " + stmt);
									}
									else
									{
										if((int)conn.GetScalar("select count(1) from "+table.Replace("dv_",Fetch.TablePrefix))==0)
										{
											conn.Execute(stmt);
											SaveUpgradeLog("Upgrade Database: " + stmt);
										}
									}
								}
							}
							catch 
							{
							}
						}
					}
				}
			}
			catch 
			{
			}
		}
	}
	catch(Exception ex)
	{
		jsonReply.ErrorMsg = "升级数据库错误:" + ex.Message;
		jsonReply.RetVal = 0;
		SaveUpgradeLog("ERROR-->UpdateDataTableV1_0_0_2513_rc4():" + jsonReply.ErrorMsg);
		return false;
	}
	finally
	{
		if(reader !=null)
		reader = null;
		conn.Close();
	}
	SaveUpgradeLog("升级数据库成功!");
	return true;
}
</script>
	
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:2852517674
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
分享该页面
关闭侧边栏