|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Mesnac.Maths;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using Mesnac.Equips;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Math.Feeding
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 称量信息列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class WeightInfoList : IMath
|
|
|
|
|
{
|
|
|
|
|
private object NullResult = new DataTable();
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "称量信息"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Caption
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine("必须填写使用数据库连接的设备名称");
|
|
|
|
|
sb.AppendLine("例:");
|
|
|
|
|
sb.Append(" ").Append(Name).AppendLine("(A1)");
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Execute(string[] parameters, object[] buff)
|
|
|
|
|
{
|
|
|
|
|
string id = string.Empty;
|
|
|
|
|
if ((buff.Length > 0)
|
|
|
|
|
&& (buff[0] != null)
|
|
|
|
|
&& (!string.IsNullOrWhiteSpace(buff[0].ToString())))
|
|
|
|
|
{
|
|
|
|
|
id = buff[0].ToString();
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
|
|
|
{
|
|
|
|
|
return this.NullResult;
|
|
|
|
|
}
|
|
|
|
|
if (parameters.Length < 1)
|
|
|
|
|
{
|
|
|
|
|
return this.NullResult;
|
|
|
|
|
}
|
|
|
|
|
string equipName = parameters[0];
|
|
|
|
|
BaseEquip equip = null;
|
|
|
|
|
if (!Mesnac.Equips.Factory.Instance.AllEquips.TryGetValue(equipName, out equip))
|
|
|
|
|
{
|
|
|
|
|
return this.NullResult;
|
|
|
|
|
}
|
|
|
|
|
DataTable Result = new DataTable();
|
|
|
|
|
string xml = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DbConnection conn = equip.Main.ConnType.Connection as DbConnection;
|
|
|
|
|
if (conn == null)
|
|
|
|
|
{
|
|
|
|
|
return this.NullResult;
|
|
|
|
|
}
|
|
|
|
|
using (SqlConnection sqlCon = new SqlConnection(conn.ConnectionString))
|
|
|
|
|
{
|
|
|
|
|
sqlCon.Open();
|
|
|
|
|
|
|
|
|
|
SqlCommand sqlcmd = new SqlCommand();
|
|
|
|
|
sqlcmd.Connection = sqlCon;
|
|
|
|
|
sqlcmd.CommandType = System.Data.CommandType.Text;
|
|
|
|
|
string sqlstr = "SELECT ssValue FROM SysKeyValue WHERE ssKey='RecipeCache_WeightListTable'";
|
|
|
|
|
sqlcmd.CommandText = sqlstr;
|
|
|
|
|
object obj = sqlcmd.ExecuteScalar();
|
|
|
|
|
if (obj != null && obj != DBNull.Value)
|
|
|
|
|
{
|
|
|
|
|
xml = obj.ToString();
|
|
|
|
|
}
|
|
|
|
|
sqlCon.Close();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(xml))
|
|
|
|
|
{
|
|
|
|
|
return this.NullResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#region 旧代码,在多线程并发访问数据库时,容易产生DataReader未关闭错误
|
|
|
|
|
//bool isOpen = true;
|
|
|
|
|
//if (conn.State != ConnectionState.Open)
|
|
|
|
|
//{
|
|
|
|
|
// isOpen = false;
|
|
|
|
|
// conn.Open();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//DbCommand sqlcmd = conn.CreateCommand();
|
|
|
|
|
|
|
|
|
|
//sqlcmd.CommandType = System.Data.CommandType.Text;
|
|
|
|
|
//string sqlstr = "SELECT ssValue FROM SysKeyValue WHERE ssKey='RecipeCache_WeightListTable'";
|
|
|
|
|
//sqlcmd.CommandText = sqlstr;
|
|
|
|
|
//object obj = sqlcmd.ExecuteScalar();
|
|
|
|
|
//string xml = string.Empty;
|
|
|
|
|
//if (obj != null && obj != DBNull.Value)
|
|
|
|
|
//{
|
|
|
|
|
// xml = obj.ToString();
|
|
|
|
|
//}
|
|
|
|
|
//sqlcmd.Dispose();
|
|
|
|
|
//if (!isOpen)
|
|
|
|
|
//{
|
|
|
|
|
// conn.Close();
|
|
|
|
|
//}
|
|
|
|
|
//if (string.IsNullOrWhiteSpace(xml))
|
|
|
|
|
//{
|
|
|
|
|
// return this.NullResult;
|
|
|
|
|
//}
|
|
|
|
|
#endregion
|
|
|
|
|
Result = DeserializeObject<DataTable>(xml);
|
|
|
|
|
//ICSharpCode.Core.LoggingService.Debug("函数(称量信息):" + Result.Rows.Count);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Error("发生错误在Mesnac.Math.Fedding.WeightInfoList:" + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
Result.TableName = String.Format("T_WeightInfoList_{0}", Guid.NewGuid().ToString());
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 把xml字符串反序列化为对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <param name="xmlString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private T DeserializeObject<T>(string xmlString)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrEmpty(xmlString))
|
|
|
|
|
{
|
|
|
|
|
StringReader strReader = new StringReader(xmlString);
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
|
|
|
|
T obj = (T)serializer.Deserialize(strReader);
|
|
|
|
|
strReader.Close();
|
|
|
|
|
strReader.Dispose();
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return default(T);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|