using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

//		如何读INI文件中的设置信息 

namespace JXC_MIS.MyClass
{
	/// <summary>
	/// ClsReadINI 的摘要说明。
	/// </summary>
	public class ClsReadIniFile
	{
		//文件INI名称
		public string Path;

		////声明读写INI文件的API函数 
		[DllImport("kernel32")]

		private static extern long WritePrivateProfileString(string section,string 
			key,string val,string filePath);

//		Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

		[DllImport("kernel32")]

		private static extern int GetPrivateProfileString(string section,string 
			key,string def,StringBuilder retVal,int size,string filePath);

		[DllImport("shell32.dll")]
			private static extern long ShellExecute(long hwnd, string lpOperation,string  lpFile , string lpParameters,string  lpDirectory, long nShowCmd);
		//Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
		//ShellExecute Me.hWnd, "open", "http://www.ruentex.com.tw", "", "", 5


			//类的构造函数，传递INI文件名
			public ClsReadIniFile(string inipath)
			{
				//
				// TODO: Add constructor logic here
				//
				Path = inipath;
			}

			//写INI文件
			public void IniWriteValue(string Section,string Key,string Value)
			{
				WritePrivateProfileString(Section,Key,Value,this.Path);

			}

			//读取INI文件指定
			public string IniReadValue(string Section,string Key)
			{
				StringBuilder temp = new StringBuilder(255);
				int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path);
				return temp.ToString();

			}


		}
	}

//	操作范例：
//
//	public static SqlConnection MyConnection()
//{
//	string sPath;
//	string ServerName,userId,sPwd,DataName;
//
//	sPath = GetPath();
//	IniFile ini = new IniFile(sPath);
//	ServerName = ini.IniReadValue ("Database","server");
//	userId = ini.IniReadValue ("Database","uid");
//	sPwd = ini.IniReadValue ("Database","pwd");
//	DataName = ini.IniReadValue ("Database","database");
//	string strSql = "server =" + ServerName+";uid ="+ userId +";pwd =;database 
//	="+ DataName;
//      　　　 SqlConnection myConn=new SqlConnection(strSql);
//      　　　 return myConn; 
//}







	
