150 lines
5.3 KiB
C#
150 lines
5.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Data.SqlClient;
|
||
using System.Data.Odbc;
|
||
using System.Runtime.InteropServices;
|
||
|
||
namespace HiiShe.Manager
|
||
{
|
||
public class ConfigHelper
|
||
{
|
||
[DllImport("kernel32")]
|
||
private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath);
|
||
[DllImport("kernel32")]
|
||
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
||
|
||
/// <summary>
|
||
/// 读取INI文件
|
||
/// </summary>
|
||
/// <param name="section">项目名称(如 [section] )</param>
|
||
/// <param name="skey">键</param>
|
||
/// <param name="path">路径</param>
|
||
public static string IniReadValue(string section, string skey, string path)
|
||
{
|
||
StringBuilder temp = new StringBuilder(500);
|
||
int i = GetPrivateProfileString(section, skey, "", temp, 500, path);
|
||
return temp.ToString();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 写入ini文件
|
||
/// </summary>
|
||
/// <param name="section">项目名称</param>
|
||
/// <param name="key">键</param>
|
||
/// <param name="value">值</param>
|
||
/// <param name="path">路径</param>
|
||
public static void IniWrite(string section, string key, string value, string path)
|
||
{
|
||
WritePrivateProfileString(section, key, value, path);
|
||
}
|
||
public static string ServerPartCode
|
||
{
|
||
get
|
||
{
|
||
string retString = "";
|
||
try
|
||
{
|
||
retString = System.Configuration.ConfigurationManager.AppSettings["SERVERPARTCODE"].ToString();
|
||
}
|
||
catch
|
||
{
|
||
retString = "";
|
||
}
|
||
return retString;
|
||
}
|
||
}
|
||
|
||
//
|
||
public static string Prower
|
||
{
|
||
get
|
||
{
|
||
string retString = "";
|
||
try
|
||
{
|
||
retString = System.Configuration.ConfigurationManager.AppSettings["Prower"].ToString();
|
||
}
|
||
catch
|
||
{
|
||
retString = "";
|
||
}
|
||
return retString;
|
||
}
|
||
}
|
||
|
||
public static string GetValue(string Name)
|
||
{
|
||
string strLine = "";
|
||
string result = "";
|
||
try
|
||
{
|
||
result = IniReadValue("DBCONECT", Name, "d://HighWayPosSoft/setup.ini");
|
||
//FileStream aFile = new FileStream("d://HighWayPosSoft/setup.ini", FileMode.Open);
|
||
//StreamReader sr = new StreamReader(aFile);
|
||
//for (strLine = sr.ReadLine(); strLine != null; strLine = sr.ReadLine())
|
||
//{
|
||
// if (strLine.ToLower().Contains(Name))
|
||
// {
|
||
// sr.Close();
|
||
// result = strLine.Replace(Name, "");
|
||
// return result;
|
||
// }
|
||
//}
|
||
//sr.Close();
|
||
if (result == "")
|
||
{
|
||
string constr = "DSN=anysql1;UID=dba;PWD=sql;";
|
||
string _Valuestr = "select configuration_name,configuration_values from dba.t_configuration where configuration_name = '" + Name + "'";
|
||
OdbcConnection conany = new OdbcConnection(constr);
|
||
try
|
||
{
|
||
conany.Open();
|
||
OdbcCommand configcom = new OdbcCommand(_Valuestr, conany);
|
||
OdbcDataReader configrd = configcom.ExecuteReader();
|
||
if (configrd.HasRows)
|
||
{
|
||
result = configrd["configuration_values"].ToString();
|
||
}
|
||
conany.Close();
|
||
return result;
|
||
}
|
||
catch
|
||
{
|
||
conany.Close();
|
||
result = "";
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
catch
|
||
{
|
||
string constr = "DSN=anysql1;UID=dba;PWD=sql;";
|
||
string _Valuestr = "select configuration_name,configuration_values from dba.t_configuration where configuration_name = '" + Name + "'";
|
||
OdbcConnection conany = new OdbcConnection(constr);
|
||
try
|
||
{
|
||
conany.Open();
|
||
OdbcCommand configcom = new OdbcCommand(_Valuestr, conany);
|
||
OdbcDataReader configrd = configcom.ExecuteReader();
|
||
if (configrd.HasRows)
|
||
{
|
||
result = configrd["configuration_values"].ToString();
|
||
}
|
||
conany.Close();
|
||
return result;
|
||
}
|
||
catch
|
||
{
|
||
conany.Close();
|
||
result = "";
|
||
}
|
||
return result;
|
||
}
|
||
//return "";
|
||
}
|
||
}
|
||
}
|