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

📄 dbcustomaction.cs

📁 是 个典型的 OA系统
💻 CS
字号:
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Reflection;


namespace DBCustomAction
{
	/// <summary>
	/// DBCustomAction 的摘要说明。
	/// </summary>
	[RunInstaller(true)]
	public class DBCustomAction : System.Configuration.Install.Installer
	{
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public DBCustomAction()
		{
			// 该调用是设计器所必需的。
			InitializeComponent();

			// TODO: 在 InitializeComponent 调用后添加任何初始化
		}

		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		private void ExecuteSql(string DataBaseName,string Sql) 
		{ 
			System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql,sqlConnection1); 

			Command.Connection.Open(); 
			Command.Connection.ChangeDatabase(DataBaseName); 
			try 
			{ 
				Command.ExecuteNonQuery(); 
			} 
			finally 
			{ 
				Command.Connection.Close(); 
			} 
		} 


		protected void AddDBTable(string strDBName) 
		{ 
			try 
			{ 
				ExecuteSql("master","CREATE DATABASE "+ strDBName); 
				try 
				{ 
					Assembly Asm = Assembly.GetExecutingAssembly(); 
					Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + ".sql.txt"); 
					StreamReader reader = new StreamReader((strm),System.Text.Encoding.Default); 
					string [] sqlstr = reader.ReadToEnd().Split(new char[] {'|'});
					for(int i = 0; i < sqlstr.Length; i++)
					{
						if(sqlstr[i]!="")
				        ExecuteSql(strDBName,sqlstr[i]); 
					}
				} 
				catch (Exception ex) 
				{ 
					Console.Write("In GetSql:"+ex.Message); 
					throw ex; 
				} 

			} 
			catch(Exception ex) 
			{ 
				Console.Write("In exception handler :"+ex.Message); 
			} 
		} 
		public void AddShortcut() 
		{ 
			try 
			{           
				string ShortcutFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\AntaiOA.url";
				FileStream fs = new FileStream(ShortcutFile,FileMode.CreateNew, FileAccess.Write, FileShare.None);
				StreamWriter swFromFile = new StreamWriter(fs);
				swFromFile.Write("[InternetShortcut]\r");
				swFromFile.Write("URL=http://localhost/OA/index.htm\r");
				swFromFile.Write("modified=2329483928383");
				swFromFile.Flush();
				swFromFile.Close();
			} 
			catch(Exception ex) 
			{ 
				Console.Write("In exception handler :"+ex.Message); 
			} 
		}
		public override void Install(System.Collections.IDictionary stateSaver) 
		{ 
			base.Install(stateSaver); 
			AddDBTable(this.Context.Parameters["dbname"]);
            AddShortcut(); 
//			System.Diagnostics.Process aa=new  System.Diagnostics.Process();
//			System.Diagnostics.Process myProcess = new System.Diagnostics.Process();         
//            myProcess.StartInfo.FileName = @"dotnetfx.exe";
//            myProcess.Start();
		} 


		#region 组件设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=(Local);packet size=4096;integrated security=SSPI;data source=(Loc" +
				"al);persist security info=False;initial catalog=master";

		}
		#endregion
	}
}

⌨️ 快捷键说明

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