Пример #1
0
		private static void CopyAndReparentElement(UpdateQueryBatch batch, int elmObjid, int childShowObjid,
		                                           int newParentShowObjid)
		{
			log.LogDebug("CopyAndReparentElement called. Elmenet: {0}, Child Show: {1}, New Parent Show: {2}",
			             elmObjid, childShowObjid, newParentShowObjid);

			// Get table ID's for hgbst_elm and hgbst_show
			var sqlHelper = new SqlHelper(batch.Provider)
			                {
			                	Transaction = batch.Transaction,
			                	CommandText = @"SELECT type_id, type_name FROM adp_tbl_name_map WHERE type_name = 'hgbst_elm' OR type_name = 'hgbst_show'"
			                };

			var hgbstElmTableID = 0;
			var hgbstShowTableID = 0;

			using (var dataReader = sqlHelper.ExecuteReader())
			{
				while (dataReader.Read())
				{
					if (String.Compare(Convert.ToString(dataReader["type_name"]), "hgbst_elm", true) == 0)
					{
						hgbstElmTableID = Convert.ToInt32(dataReader["type_id"]);
					}
					else if (String.Compare(Convert.ToString(dataReader["type_name"]), "hgbst_show", true) == 0)
					{
						hgbstShowTableID = Convert.ToInt32(dataReader["type_id"]);
					}
				}
			}

			sqlHelper = new SqlHelper(batch.Provider)
			            {
			            	Transaction = batch.Transaction,
			            	CommandText = "SELECT site_id FROM adp_db_header"
			            };
			var siteId = Convert.ToInt32(sqlHelper.ExecuteScalar());

			var objidBase = siteId*Convert.ToInt32(Math.Pow(2, 28));
			//this.objidBase = 0;

			// Duplicate the element
			var dupeElmObjid = DuplicateElement(batch, elmObjid, newParentShowObjid, objidBase, hgbstElmTableID);
			log.LogDebug("Duplicated element. New Objid: {0}", dupeElmObjid);

			// Duplicate the child show and link it to the new element
			var dupeChildShowObjid = DuplicateShow(batch, childShowObjid, dupeElmObjid, newParentShowObjid, objidBase, hgbstShowTableID);
			log.LogDebug("Duplicated child show. New Objid: {0}", dupeChildShowObjid);

			// Get the whole child hierarchy for this element starting from its childShowObjid and duplicate it
			log.LogDebug("Duplicating child hierarchy...");
			DuplicateChildHierarchy(batch, elmObjid, childShowObjid, dupeChildShowObjid, objidBase, hgbstElmTableID,
			                        hgbstShowTableID);

			// Unlink the old elm from the new parent show (if it was linked - a la the Best Buy double-linked problem)
			log.LogDebug("Unlinking original element (if necessary) from new parent to complete the separation");
			var commandParameters = new DataParameterCollection {{"elmObjid", elmObjid}, {"newParent", newParentShowObjid}};
			batch.AddStatement(@"DELETE FROM mtm_hgbst_elm0_hgbst_show1 WHERE hgbst_elm2hgbst_show = {0} and hgbst_show2hgbst_elm = {1}", commandParameters);
		}
Пример #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //尝试连接数据库服务器
            string master_conn_str = string.Format("Data Source={0};Initial Catalog=master;Persist Security Info=True;User ID={1};Password={2}", txt_Server.Text, txt_Username.Text, txt_Password.Text);
            string ConnStr = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}", txt_Server.Text, txt_DbName.Text, txt_Username.Text, txt_Password.Text);
            SqlConnection master_conn = new SqlConnection(master_conn_str);
            try
            {
                master_conn.Open();
            }
            catch
            {
                Js.AlertAndGoback("数据库服务器连接失败,请重试!");
            }
            finally
            {
                if (master_conn.State == ConnectionState.Open)
                {
                    master_conn.Close();
                }
            }
            IDbHelper Helper = new SqlHelper(master_conn_str);
            try
            {
                //判断数据库是否存在

                DbDataReader dr = Helper.ExecuteReader(CommandType.Text, string.Format("select 0 From master.dbo.sysdatabases where name='{0}' ", txt_DbName.Text));
                if (!dr.Read())
                {
                    //不存在的话创建
                    dr.Close();
                    dr.Dispose();
                    Helper = new SqlHelper(master_conn_str);
                    Helper.ExecuteNonQuery(CommandType.Text, string.Format("CREATE DATABASE {0}", txt_DbName.Text));

                }
                dr.Close();
                dr.Dispose();
            }
            catch (Exception ex)
            {
                //无法写入数据库
            }

            //写入连接字符串
            try
            {
                Voodoo.Config.Info.SetAppSetting("ConnStr", ConnStr);
            }
            catch { }

            //导入表

            string str_sql = Voodoo.IO.File.Read(Server.MapPath("~/e/installer/tablescript.txt"));
            Helper = new SqlHelper(ConnStr);
            Helper.ExecuteNonQuery(CommandType.Text, str_sql);

            //导入数据
            if (chk_WithData.Checked)
            {
                string str_data = Voodoo.IO.File.Read(Server.MapPath("~/e/installer/tabledata.txt"));
                Helper = new SqlHelper(ConnStr);
                Helper.ExecuteNonQuery(CommandType.Text, str_data);
            }

            //导入管理员
            Helper = new SqlHelper(ConnStr);
            Helper.ExecuteNonQuery(CommandType.Text, string.Format("insert into [SysUser]([UserName],[UserPass],[Logincount],[LastLoginTime],[LastLoginIP],[SafeQuestion],[SafeAnswer],[Department],[ChineseName],[UserGroup],[Email],[TelNumber],[Enabled]) values('{0}','{1}','0','2011-11-21 12:38:50','127.0.0.1','','','1','超管','1','*****@*****.**','13813894138','True')", txt_AdminName.Text, Voodoo.Security.Encrypt.Md5(txt_AdminPass.Text)));

            Voodoo.IO.File.Write(Server.MapPath("~/e/installer/intaller.off"), "1");
            Js.AlertAndChangUrl("安装完成!马上进入登陆界面!", "/e/admin/");
        }