You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
6.7 KiB
199 lines
6.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
|
|
namespace XS_BLL
|
|
{
|
|
public static class Global
|
|
{
|
|
|
|
#region 操作配置文件(App.config)
|
|
/// <summary>
|
|
/// 保存配置参数
|
|
/// </summary>
|
|
/// <param name="key">关键字</param>
|
|
/// <param name="value">参数值</param>
|
|
public static void SetAppConfig(string key, string value)
|
|
{
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
//获得配置文件的全路径
|
|
string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
|
|
|
xmlDoc.Load(strFileName);
|
|
|
|
//取软件配置节点
|
|
XmlNode xNode = xmlDoc.SelectSingleNode("//appSettings");
|
|
//取与目标元素匹配的节点
|
|
XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add [@key=\"" + key + "\"]");
|
|
if (xElem != null)
|
|
{
|
|
xElem.SetAttribute("value", value);
|
|
}
|
|
|
|
//保存上面的修改
|
|
xmlDoc.Save(strFileName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取配置参数
|
|
/// </summary>
|
|
/// <param name="key">关键字</param>
|
|
public static string GetAppConfig(string key)
|
|
{
|
|
string value = "";
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
//获得配置文件的全路径
|
|
string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
|
|
|
xmlDoc.Load(strFileName);
|
|
|
|
//取数据库连接配置节点
|
|
XmlNode xNode = xmlDoc.SelectSingleNode("//appSettings");
|
|
//取与目标元素匹配的节点
|
|
XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add [@key=\"" + key + "\"]");
|
|
if (xElem != null)
|
|
{
|
|
value = xElem.GetAttribute("value");
|
|
}
|
|
return value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存数据库配置参数
|
|
/// </summary>
|
|
/// <param name="name">关键字</param>
|
|
/// <param name="connectionString">数据库连接参数</param>
|
|
public static void SetConnConfig(string name, string connectionString)
|
|
{
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
//获得配置文件的全路径
|
|
string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
|
|
|
xmlDoc.Load(strFileName);
|
|
|
|
//取数据库连接配置节点
|
|
XmlNode xNode = xmlDoc.SelectSingleNode("//connectionStrings");
|
|
//取与目标元素匹配的节点
|
|
XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add [@name=\"" + name + "\"]");
|
|
if (xElem != null)
|
|
{
|
|
xElem.SetAttribute("connectionString", connectionString);
|
|
}
|
|
|
|
//保存修改
|
|
xmlDoc.Save(strFileName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取数据库连接字符
|
|
/// </summary>
|
|
/// <param name="nodeName"></param>
|
|
/// <returns></returns>
|
|
public static string getConnNode(string nodeName, int i = 0)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
SqlConnectionStringBuilder scb = new SqlConnectionStringBuilder(Global.connstring);
|
|
|
|
if (nodeName == "DBUrl") { return scb.DataSource; }
|
|
else if (nodeName == "DBName") { return scb.InitialCatalog; }
|
|
else if (nodeName == "DBUsetName") { return scb.UserID; }
|
|
else if (nodeName == "DBUserPwd") { return scb.Password; }
|
|
else { return ""; }
|
|
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取数据库配置参数
|
|
/// </summary>
|
|
/// <param name="name">关键字</param>
|
|
public static string GetConnConfig(string name, int i = 0)
|
|
{
|
|
string connectionString = "";
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
//获得配置文件的全路径
|
|
string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
|
|
|
|
xmlDoc.Load(strFileName);
|
|
|
|
//取数据库连接配置节点
|
|
XmlNode xNode = xmlDoc.SelectSingleNode("//connectionStrings");
|
|
//取与目标元素匹配的节点
|
|
XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add [@name=\"" + name + "\"]");
|
|
if (xElem != null)
|
|
{
|
|
connectionString = xElem.GetAttribute("connectionString");
|
|
}
|
|
return connectionString;
|
|
}
|
|
#endregion 操作配置文件(App.config)
|
|
|
|
/// <summary>
|
|
/// 线程时间间隔
|
|
/// </summary>
|
|
public static int ThreadTime { get; set; } = Convert.ToInt32(GetAppConfig("ThreadTime"));
|
|
|
|
#region 数据库链接
|
|
/// <summary>
|
|
/// 数据库连接方式
|
|
/// </summary>
|
|
public static string DbType { get; set; } = GetAppConfig("DbType");
|
|
/// <summary>
|
|
/// 数据库连接路径
|
|
/// </summary>
|
|
public static string connstring { get; set; } = GetConnConfig("connstring");
|
|
/// <summary>
|
|
/// 数据库链接地址
|
|
/// </summary>
|
|
public static string DBUrl { get; set; } = getConnNode("DBUrl");
|
|
/// <summary>
|
|
/// 数据库名称
|
|
/// </summary>
|
|
public static string DBName { get; set; } = getConnNode("DBName");
|
|
/// <summary>
|
|
/// 数据库登录名
|
|
/// </summary>
|
|
public static string DBUsetName { get; set; } = getConnNode("DBUsetName");
|
|
/// <summary>
|
|
/// 数据库密码
|
|
/// </summary>
|
|
public static string DBUserPwd { get; set; } = getConnNode("DBUserPwd");
|
|
#endregion 数据库链接
|
|
|
|
#region 接口
|
|
/// <summary>
|
|
/// HTTP 接口 URL 接收地址
|
|
/// </summary>
|
|
public static string Receive_HTTPURL { get; set; } = GetAppConfig("Receive_HTTPURL");
|
|
/// <summary>
|
|
/// HTTP 接口 URL 请求上位MWS接口地址
|
|
/// </summary>
|
|
public static string upper_WMSURL { get; set; } = GetAppConfig("upper_WMSURL");
|
|
#endregion 接口
|
|
|
|
/// <summary>
|
|
/// 设备信息及货位信息对照
|
|
/// </summary>
|
|
public static Dictionary<string, string> deviceCell { get; set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// 反馈信息是否显示
|
|
/// </summary>
|
|
public static int checkBox1 { get; set; } = 0;
|
|
}
|
|
}
|