You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Basic/BasicHelper.cs

1444 lines
61 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ICSharpCode.Core;
using Mesnac.Codd.Session;
using Mesnac.Action.ChemicalWeighing.Entity;
namespace Mesnac.Action.ChemicalWeighing.Basic
{
/// <summary>
/// 基础业务辅助类
/// </summary>
public class BasicHelper
{
private static Entity.BasEquip _BasEquip = null;
#region 设备单元
/// <summary>
/// 判断设备单元编号是否存在
/// </summary>
/// <param name="unitNum">要判断的设备单元编号</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsUnitNum(string unitNum)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasUnit where UnitNum=@UnitNum";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@UnitNum", unitNum);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 判断设备单元名称是否存在
/// </summary>
/// <param name="equipUnitName">要判断的设备单元名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsEquipUnitName(string equipUnitName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasUnit where EquipUnitName=@EquipUnitName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@EquipUnitName", equipUnitName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 根据设备单元号查找某条设备单元数据
/// </summary>
/// <param name="unitNum">设备单元号</param>
/// <returns>返回对应的设备单元号的数据行</returns>
public static DataRow GetUnitDataRowByUnitNum(string unitNum)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select * from BasUnit where UnitNum=@UnitNum";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@UnitNum", unitNum);
DataTable dt = dbHelper.ToDataTable();
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0];
}
return null;
}
/// <summary>
/// 根据GUID获取设备单元实体对象
/// </summary>
/// <param name="guid">GUID参数</param>
/// <returns>返回对应的设备单元实体对象</returns>
public static Entity.BasUnit GetUnitEntityByGUID(string guid)
{
DataRow dr = BaseDataHelper.GetDataRowByTableAndGUID("BasUnit", guid);
return ConvertDataRowToBasUnit(dr);
}
/// <summary>
/// 根据设备单元号查找某条设备单元实体
/// </summary>
/// <param name="unitNum">设备单元号</param>
/// <returns>返回对应的设备单元号的实体对象</returns>
public static Entity.BasUnit GetUnitEntityByUnitNum(string unitNum)
{
DataRow dr = GetUnitDataRowByUnitNum(unitNum);
return ConvertDataRowToBasUnit(dr);
}
/// <summary>
/// 把数据行转换为BasUnit实体对象
/// </summary>
/// <param name="dr">数据行</param>
/// <returns>返回转化后的设备单元实体对象</returns>
private static Entity.BasUnit ConvertDataRowToBasUnit(DataRow dr)
{
if (dr != null)
{
Entity.BasUnit entity = new Entity.BasUnit();
entity.GUID = Mesnac.Basic.DataProcessor.RowValue(dr, "GUID", String.Empty);
entity.UnitNum = Mesnac.Basic.DataProcessor.RowValue(dr, "UnitNum", String.Empty);
entity.EquipUnitName = Mesnac.Basic.DataProcessor.RowValue(dr, "EquipUnitName", String.Empty);
entity.IsNeedJar = Mesnac.Basic.DataProcessor.RowValue(dr, "IsNeedJar", "0");
entity.JarType = Mesnac.Basic.DataProcessor.RowValue(dr, "JarType", String.Empty);
entity.FinishBatchType = Mesnac.Basic.DataProcessor.RowValue(dr, "FinishBatchType", String.Empty);
entity.ProcessGroup = Mesnac.Basic.DataProcessor.RowValue(dr, "ProcessGroup", String.Empty);
entity.RecordTime = Mesnac.Basic.DataProcessor.RowValue(dr, "RecordTime", DateTime.Now);
entity.RecordUser = Mesnac.Basic.DataProcessor.RowValue(dr, "RecordUser", Mesnac.Basic.UserInfo.Instance.UserName);
entity.DataSource = Mesnac.Basic.DataProcessor.RowValue(dr, "DataSource", "0");
entity.DeleteFlag = Mesnac.Basic.DataProcessor.RowValue(dr, "DeleteFlag", "0");
entity.Remark = Mesnac.Basic.DataProcessor.RowValue(dr, "Remark", String.Empty);
return entity;
}
else
{
return null;
}
}
/// <summary>
/// 获取所有的设备单元数据表
/// </summary>
/// <returns>返回所有设备单元数据表</returns>
public static DataTable GetAllUnitTable()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select * from BasUnit where DeleteFlag = '0' order by UnitNum";
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
return dt;
}
/// <summary>
/// 获取所有的设备单元实体列表
/// </summary>
/// <returns>返回设备单元实体列表</returns>
public static List<Entity.BasUnit> GetAllUnitEntity()
{
List<Entity.BasUnit> lst = new List<Entity.BasUnit>();
DataTable dt = GetAllUnitTable();
if (dt != null && dt.Rows.Count > 0)
{
Entity.BasUnit entity = null;
foreach(DataRow dr in dt.Rows)
{
entity = GetUnitEntityByGUID(Mesnac.Basic.DataProcessor.RowValue(dr, "GUID", String.Empty));
lst.Add(entity);
}
}
return lst;
}
#endregion
#region 机台设备
/// <summary>
/// 机台设备信息
/// </summary>
public static Entity.BasEquip BasEquip
{
get
{
if (_BasEquip == null)
{
DataRow dr = GetBasEquip();
if (dr != null)
{
Entity.BasEquip equip = new BasEquip();
equip.GUID = Mesnac.Basic.DataProcessor.RowValue(dr, "GUID", String.Empty);
equip.EquipCode = Mesnac.Basic.DataProcessor.RowValue(dr, "EquipCode", String.Empty);
equip.EquipType = Mesnac.Basic.DataProcessor.RowValue(dr, "EquipType", String.Empty);
equip.EquipName = Mesnac.Basic.DataProcessor.RowValue(dr, "EquipName", String.Empty);
equip.EquipIP = Mesnac.Basic.DataProcessor.RowValue(dr, "EquipIP", String.Empty);
DataTable dtUnitList = GetBasEquipUnitList();
if (dtUnitList != null && dtUnitList.Rows.Count > 0)
{
Entity.BasUnit unit = null;
foreach (DataRow drUnit in dtUnitList.Rows)
{
string unitGUID = Mesnac.Basic.DataProcessor.RowValue(drUnit, "UnitGUID", String.Empty);
unit = GetUnitEntityByGUID(unitGUID);
equip.UnitList.Add(unit);
equip.StrUnitList.Add(unit.UnitNum);
equip.DicUnitList.Add(unit.UnitNum, unit);
}
}
_BasEquip = equip;
}
}
return _BasEquip;
}
}
/// <summary>
/// 刷新机台设备信息
/// </summary>
public static void RefreshBasEquip()
{
_BasEquip = null;
}
/// <summary>
/// 获取机台设备数据行
/// </summary>
/// <returns></returns>
public static DataRow GetBasEquip()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select top 1 * from BasEquip";
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
if (dt != null && dt.Rows.Count == 1)
{
return dt.Rows[0];
}
else
{
return null;
}
}
/// <summary>
/// 获取机台设备guid
/// </summary>
/// <returns></returns>
public static string GetBasEquipGUID()
{
string strSql = "select top 1 GUID from BasEquip";
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = System.Data.CommandType.Text;
dbHelper.CommandText = strSql;
//dbHelper.ExecuteNonQuery();
string guid = dbHelper.ToScalar() as string;
return guid;
}
#endregion
#region 机台设备单元
/// <summary>
/// 获取当前机台的设备单元列表
/// </summary>
/// <returns></returns>
public static DataTable GetBasEquipUnitList()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select * from BasEquipUnit";
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
return dt;
}
/// <summary>
/// 获取当前机台指定工艺分组的带罐设备单元(即对应工艺分组的秤设备)
/// </summary>
/// <param name="processGroups">工艺分组列表1,2</param>
/// <returns>返回当前机台指定工艺分组的带罐设备单元(即对应工艺分组的秤设备)</returns>
public static DataTable GetJarUnitByProcessGroup(string processGroups)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select * from BasUnit where IsNeedJar = '1' and ProcessGroup in ({0}) and UnitNum in (select UnitNum from BasEquipUnit)";
sqlstr = String.Format(sqlstr, processGroups);
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
return dt;
}
#endregion
#region 胶料类别
/// <summary>
/// 获取胶料类型列表
/// </summary>
/// <returns>返回胶料类型列表</returns>
public static DataTable GetRubTypeListForSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS GUID, '0' AS RubTypeCode, '{0}' AS RubTypeName
UNION ALL
SELECT GUID, RubTypeCode, RubTypeName FROM BasRubType WHERE DeleteFlag = '0' ORDER BY RubTypeCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
return dbHelper.GetDataTableBySql(sqlstr);
}
/// <summary>
/// 判断胶料类别编号是否存在
/// </summary>
/// <param name="rubTypeCode">要判断的胶料类别编号</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsRubTypeCode(string rubTypeCode)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasRubType where RubTypeCode = @RubTypeCode";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RubTypeCode", rubTypeCode);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 判断胶料类别名称是否存在
/// </summary>
/// <param name="rubTypeName">要判断的胶料类别名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsRubTypeName(string rubTypeName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasRubType where RubTypeName = @RubTypeName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RubTypeName", rubTypeName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
#endregion
#region 胶料轮胎部件
/// <summary>
/// 获取胶料轮胎部件列表
/// </summary>
/// <returns>返回胶料轮胎部件列表</returns>
public static DataTable GetRubTyrePartListForSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"select * from
(
SELECT '' AS GUID, '0' AS TyrePartCode, '{0}' AS TyrePartName
UNION ALL
SELECT GUID, TyrePartCode, TyrePartName FROM BasRubTyrePart WHERE DeleteFlag = '0'
) as temp
order by cast(TyrePartCode as int)";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
return dbHelper.GetDataTableBySql(sqlstr);
}
/// <summary>
/// 判断轮胎部件代码是否存在
/// </summary>
/// <param name="tyrePartCode">要判断的轮胎部件代码</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsTyrePartCode(string tyrePartCode)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasRubTyrePart where TyrePartCode = @TyrePartCode";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@TyrePartCode", tyrePartCode);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 判断轮胎部件名称是否存在
/// </summary>
/// <param name="tyrePartName">要判断的轮胎部件名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsTyrePartName(string tyrePartName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasRubTyrePart where TyrePartName = @TyrePartName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@TyrePartName", tyrePartName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
#endregion
#region 胶料信息
/// <summary>
/// 获取胶料信息列表
/// </summary>
/// <returns>返回胶料列表</returns>
public static DataTable GetRubInfoListForSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS GUID, '0000' AS RubCode, '{0}' AS RubName
UNION ALL
SELECT GUID, RubCode, RubName FROM BasRubInfo WHERE DeleteFlag = '0' ORDER BY RubCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
return dbHelper.GetDataTableBySql(sqlstr);
}
/// <summary>
/// 判断胶料代码是否存在
/// </summary>
/// <param name="rubCode">要判断的胶料代码</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsRubCode(string rubCode)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasRubInfo where RubCode = @RubCode";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RubCode", rubCode);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 判断胶料名称是否存在
/// </summary>
/// <param name="rubName">要判断的胶料名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsRubName(string rubName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasRubInfo where RubName = @RubName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RubName", rubName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
#endregion
#region 物料大类
/// <summary>
/// 判断物料大类名称是否存在
/// </summary>
/// <param name="mkindNamed">要判断的物料大类名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsMKindName(string mkindNamed)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasMkind where MKindName = @MKindName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@MKindName", mkindNamed);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 获取大类列表,用于组合框
/// </summary>
/// <returns>返回大类列表</returns>
public static DataTable GetMKindListForSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS GUID, '0' AS MKindCode, '{0}' AS MKindName
UNION ALL
SELECT GUID, MKindCode, MKindName FROM BasMkind WHERE DeleteFlag = '0' ORDER BY MKindCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
return dbHelper.GetDataTableBySql(sqlstr);
}
/// <summary>
/// 根据大类GUID获取大类编码
/// </summary>
/// <param name="guid">GUID</param>
/// <returns>返回对应的大类编码</returns>
public static string GetMKindCode(string guid)
{
DataRow row = BaseDataHelper.GetDataRowByTableAndGUID("BasMkind", guid);
if (row != null)
{
return Mesnac.Basic.DataProcessor.RowValue(row, "MKindCode", String.Empty);
}
return String.Empty;
}
/// <summary>
/// 根据大类代号获取大类名称
/// </summary>
/// <param name="mkindCode">物料大类代号</param>
/// <returns>返回对应的物料大类名称</returns>
public static string GetMKindNameByCode(string mkindCode)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string sqlstr = @"select MKindName from BasMkind where MKindCode = @MKindCode";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@MKindCode", mkindCode);
object result = dbHelper.ToScalar();
if (!Mesnac.Basic.DataProcessor.IsNullOrEmpty(result))
{
return result.ToString();
}
return String.Empty;
}
#endregion
#region 物料细类
/// <summary>
/// 判断物料细类名称是否存在
/// </summary>
/// <param name="ikindName">要判断的物料细类名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsIKindName(string ikindName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasIkind where IKindName = @IKindName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@IKindName", ikindName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
/// <summary>
/// 获取某个大类下的物料细类,用于组合框
/// </summary>
/// <param name="mkindGUID">大类GUID</param>
/// <returns>返回符合条件的物料细类列表</returns>
public static DataTable GetIKindForSelectByMKindGUID(string mkindGUID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS GUID, '' AS MKindGUID, '00' AS IKindCode, '{0}' AS IKindName
UNION ALL
SELECT GUID, MKindGUID, IKindCode, IKindName FROM BasIkind WHERE DeleteFlag = '0' AND MKindGUID = @MKindGUID ORDER BY IKindCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@MKindGUID", mkindGUID);
DataTable dt = dbHelper.ToDataTable();
return dt;
}
/// <summary>
/// 根据细类GUID获取细类编码
/// </summary>
/// <param name="guid">GUID</param>
/// <returns>返回对应的细类编码</returns>
public static string GetIKindCode(string guid)
{
DataRow row = BaseDataHelper.GetDataRowByTableAndGUID("BasIkind", guid);
if (row != null)
{
return Mesnac.Basic.DataProcessor.RowValue(row, "IKindCode", String.Empty);
}
return String.Empty;
}
/// <summary>
/// 根据细类GUID获取细类统计类别
/// </summary>
/// <param name="guid">GUID</param>
/// <returns>返回对应的统计类别</returns>
public static string GetIKindRemark(string guid)
{
DataRow row = BaseDataHelper.GetDataRowByTableAndGUID("BasIkind", guid);
if (row != null)
{
return Mesnac.Basic.DataProcessor.RowValue(row, "Remark", String.Empty);
}
return String.Empty;
}
#endregion
#region 物料类别
/// <summary>
/// 根据物料GUID获取物料类别物料大类+物料细类)
/// </summary>
/// <param name="materialGUID">物料GUID</param>
/// <returns>返回对应的物料类别</returns>
public static string GetMaterialTypeByGUID(string materialGUID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string sqlstr = @"select TD.MKindName + TE.IKindName from BasMaterial TC
left join BasMkind TD on TD.GUID = TC.MKindGUID
left join BasIkind TE on TE.GUID = TC.IKindGUID
where TC.GUID = @MaterialGUID";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@MaterialGUID", materialGUID);
object result = dbHelper.ToScalar();
if (!Mesnac.Basic.DataProcessor.IsNullOrEmpty(result))
{
return result.ToString();
}
return String.Empty;
}
#endregion
#region 胶料段数
/// <summary>
/// 获取胶料段数
/// </summary>
/// <returns>返回胶料段数数据表</returns>
public static DataTable GetRubSection()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"select * from
(
select '' as ItemCode, '{0}' as ItemName, '' as MKindGUID, '' as IKindGUID
union all
select TB.MKindCode + TA.IKindCode as ItemCode, TB.MKindName + TA.IKindName as ItemName, TB.GUID as MKindGUID, TA.GUID as IKindGUID
from BasIkind TA inner join BasMkind TB on TA.MKindGUID = TB.GUID where TA.DeleteFlag='0' and TB.DeleteFlag='0' and TB.MKindCode > '2'
) as temp order by ItemCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
return dt;
}
#endregion
#region 胶料称量类型
/// <summary>
/// 获取胶料称量类型,默认请选择
/// </summary>
/// <returns>返回胶料称量类型数据表</returns>
public static DataTable GetRubberWeightType()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS ItemCode, '{0}' AS ItemName
UNION ALL
SELECT ItemCode, ItemName FROM SysCode WHERE TypeID='RubberWeightType'";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
return dt;
}
/// <summary>
/// 获取胶料称量类型,无"请选择"
/// </summary>
/// <returns>返回胶料称量类型数据表</returns>
public static DataTable GetRubberWeightTypeNoSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "SELECT ItemCode, ItemName FROM SysCode WHERE TypeID='RubberWeightType'";
DataTable dt = dbHelper.GetDataTableBySql(sqlstr);
return dt;
}
#endregion
#region 物料业务
#region 获取下一个可用的物料代码1位大类代码+2位细类代码+10位流水
/// <summary>
/// 获取下一个可用的物料代码1位大类代码+2位细类代码+10位流水
/// </summary>
/// <param name="mkindCode">物料大类代码</param>
/// <param name="ikindCode">物料细类代码</param>
/// <returns>返回可用的物料代码</returns>
public static string GetNextMaterialCode(string mkindGUID, string ikindGUID, string mkindCode, string ikindCode)
{
string strSql = "select MAX(MaterialCode) from BasMaterial where MKindGUID = @MKindGUID and IKindGUID = @IKindGUID";
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
dbHelper.CommandText = strSql;
dbHelper.CommandType = System.Data.CommandType.Text;
dbHelper.AddParameter("@MKindGUID", mkindGUID);
dbHelper.AddParameter("@IKindGUID", ikindGUID);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
string currMaterialCode = result.ToString();
int intMaterialCode = 1;
if (int.TryParse(currMaterialCode.Substring(3), out intMaterialCode))
{
intMaterialCode++;
return currMaterialCode.Substring(0, 3) + Mesnac.Basic.DataProcessor.FillZero(intMaterialCode.ToString(), 10);
}
else
{
return mkindCode + ikindCode + "0000000001";
}
}
else
{
return mkindCode + ikindCode + "0000000001";
}
}
#endregion
#region 获取下一个可用的物料代码1位大类代码+2位细类代码+(4位胶号+6位流水)或(10位流水)
/// <summary>
/// 获取下一个可用的物料代码1位大类代码+2位细类代码+(4位胶号+6位流水)或(10位流水)
/// </summary>
/// <param name="mkindGUID">大类GUID</param>
/// <param name="ikindGUID">细类GUID</param>
/// <param name="mkindCode">大类代码</param>
/// <param name="ikindCode">细类代码</param>
/// <param name="rubCode">胶号</param>
/// <param name="isOriginal">是否原材料</param>
/// <returns>返回下一个可用的物料代码</returns>
public static string GetNextMaterialCode(string mkindGUID, string ikindGUID, string mkindCode, string ikindCode, string rubCode, bool isOriginal)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
string strSql = String.Empty;
if (isOriginal)
{
//原材料
strSql = "select MAX(MaterialCode) from BasMaterial where MKindGUID = @MKindGUID and IKindGUID = @IKindGUID";
}
else
{
//小料或胶料
strSql = "select MAX(MaterialCode) from BasMaterial where MKindGUID = @MKindGUID and IKindGUID = @IKindGUID and substring(MaterialCode,4,4)=@RubCode";
}
dbHelper.CommandText = strSql;
dbHelper.CommandType = System.Data.CommandType.Text;
dbHelper.AddParameter("@MKindGUID", mkindGUID);
dbHelper.AddParameter("@IKindGUID", ikindGUID);
if (!isOriginal)
{
dbHelper.AddParameter("@RubCode", rubCode);
}
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
string currMaterialCode = result.ToString();
int intMaterialCode = 1;
if (isOriginal)
{
if (int.TryParse(currMaterialCode.Substring(3), out intMaterialCode))
{
intMaterialCode++;
return currMaterialCode.Substring(0, 3) + Mesnac.Basic.DataProcessor.FillZero(intMaterialCode.ToString(), 10);
}
else
{
return mkindCode + ikindCode + "0000000001";
}
}
else
{
if (int.TryParse(currMaterialCode.Substring(7), out intMaterialCode))
{
intMaterialCode++;
return currMaterialCode.Substring(0, 7) + Mesnac.Basic.DataProcessor.FillZero(intMaterialCode.ToString(), 6);
}
else
{
return mkindCode + ikindCode + rubCode + "000001";
}
}
}
else
{
if (isOriginal)
{
return mkindCode + ikindCode + "0000000001";
}
else
{
return mkindCode + ikindCode + rubCode + "000001";
}
}
}
#endregion
#region 获取物料列表
/// <summary>
/// 获取物料列表
/// </summary>
/// <returns>返回物料列表</returns>
public static DataTable GetMaterialListForSelect()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS GUID, '0' AS MaterialCode, '{0}' AS MaterialName
UNION ALL
SELECT GUID, MaterialCode, MaterialName FROM BasMaterial WHERE DeleteFlag = '0' ORDER BY MaterialCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
return dbHelper.GetDataTableBySql(sqlstr);
}
#endregion
#region 获取物料列表(有罐的)
/// <summary>
/// 获取物料列表(有罐的)
/// </summary>
/// <returns>返回物料列表</returns>
public static DataTable GetMaterialListForSelectIsPutJar()
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<BasicHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = @"SELECT '' AS GUID, '0' AS MaterialCode, '{0}' AS MaterialName
UNION ALL
SELECT GUID, MaterialCode, MaterialName FROM BasMaterial WHERE DeleteFlag = '0' and IsPutJar='1' ORDER BY MaterialCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
return dbHelper.GetDataTableBySql(sqlstr);
}
#endregion
#region 根据物料编码和物料名称获取GUID
/// <summary>
/// 根据物料编码和物料名称获取物料GUID
/// </summary>
/// <param name="materialCode">物料编码</param>
/// <param name="materialName">物料名称</param>
/// <returns>返回对应的GUID</returns>
public static string GetMaterialGUID(string materialCode, string materialName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select top 1 GUID from BasMaterial where MaterialCode=@MaterialCode and MaterialName=@MaterialName order by DeleteFlag";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@MaterialCode", materialCode);
dbHelper.AddParameter("@MaterialName", materialName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
return result.ToString();
}
else
{
return String.Empty;
}
}
#endregion
#region 根据GUID获取物料数据行
/// <summary>
/// 根据GUID获取物料数据行
/// </summary>
/// <param name="guid">guid</param>
/// <returns>返回数据行</returns>
public static DataRow GetMaterialRowByGUID(string guid)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select * from BasMaterial where GUID = @GUID";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@GUID", guid);
DataTable dt = dbHelper.ToDataTable();
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0];
}
else
{
return null;
}
}
#endregion
#region 根据GUID获取物料代码
/// <summary>
/// 根据GUID获取物料代码
/// </summary>
/// <param name="guid">GUID</param>
/// <returns>返回物料代码</returns>
public static string GetMaterialCodeByGUID(string guid)
{
DataRow dr = GetMaterialRowByGUID(guid);
if (dr != null)
{
return Mesnac.Basic.DataProcessor.RowValue(dr, "MaterialCode", String.Empty);
}
else
{
return String.Empty;
}
}
#endregion
#region 根据GUID获取物料名称
/// <summary>
/// 根据GUID获取物料名称
/// </summary>
/// <param name="guid">GUID</param>
/// <returns>返回物料名称</returns>
public static string GetMaterialNameByGUID(string guid)
{
DataRow dr = GetMaterialRowByGUID(guid);
if (dr != null)
{
return Mesnac.Basic.DataProcessor.RowValue(dr, "MaterialName", String.Empty);
}
else
{
return String.Empty;
}
}
#endregion
#region 根据物料GUID获取物料类型(物料大类名称 + 物料细类名称)
/// <summary>
/// 根据物料GUID获取物料类型(物料大类名称 + 物料细类名称)
/// </summary>
/// <param name="materialGUID">物料GUID</param>
/// <returns>返回物料细类数据行</returns>
public static string GetMaterialTypeMaterialGUID(string materialGUID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
//string sqlstr = "select (TB.MKindName + TC.IKindName) as MaterialIKindName from BasMaterial TA left join BasMkind TB on TA.MKindGUID = TB.GUID left join BasIkind TC on TA.IKindGUID = TC.GUID where TA.GUID = @MaterialGUID";
string sqlstr = @"if exists(select RubberWeightType from BasMaterial where GUID=@MaterialGUID and RubberWeightType > 0)
Select ItemName from SysCode where TypeID='RubberWeightType' and ItemCode = (select RubberWeightType from BasMaterial where GUID=@MaterialGUID)
else
select (TB.MKindName + TC.IKindName) as MaterialIKindName from BasMaterial TA left join BasMkind TB on TA.MKindGUID = TB.GUID left join BasIkind TC on TA.IKindGUID = TC.GUID where TA.GUID = @MaterialGUID";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@MaterialGUID", materialGUID);
object result = dbHelper.ToScalar();
if (!Mesnac.Basic.DataProcessor.IsNullOrEmpty(result))
{
return result.ToString();
}
else
{
return String.Empty;
}
}
#endregion
#region 判断物料名称是否在物料表中存在
/// <summary>
/// 判断物料名称是否在物料表中存在
/// </summary>
/// <param name="materialName">要判断的物料名称</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsMaterialName(string materialName)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasMaterial where MaterialName = @MaterialName";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@MaterialName", materialName);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
#endregion
#region 判断某个胶料物料是否存在
/// <summary>
/// 判断某个胶料物料是否存在
/// </summary>
/// <param name="mkindGUID">物料大类GUID</param>
/// <param name="IKindGUID">物料细类GUID</param>
/// <param name="rubGUID">胶料GUID</param>
/// <returns>存在返回true不存在返回false</returns>
public static bool IsExistsMaterial(string mkindGUID, string ikindGUID, string rubGUID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from BasMaterial where MKindGUID = @MKindGUID and IKindGUID = @IKindGUID and RubGUID = @RubGUID";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@MKindGUID", mkindGUID);
dbHelper.AddParameter("@IKindGUID", ikindGUID);
dbHelper.AddParameter("@RubGUID", rubGUID);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
#endregion
#region 根据胶料代码物料大类GUID物料细类GUID获取产生物料列表
/// <summary>
/// 根据胶料代码物料大类GUID物料细类GUID获取产生物料列表
/// </summary>
/// <param name="rubGUID">胶料GUID</param>
/// <param name="mkindGUID">物料大类GUID</param>
/// <param name="ikindGUID">物料细类GUID</param>
/// <returns>返回对应的产生物料列表</returns>
public static DataTable GetProductMaterial(string rubGUID, string mkindGUID, string ikindGUID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select '' as GUID, '{0}' as MaterialName union all select GUID, MaterialName from BasMaterial where RubGUID = @RubGUID and MKindGUID = @MKindGUID and IKindGUID = @IKindGUID";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RubGUID", rubGUID);
dbHelper.AddParameter("@MKindGUID", mkindGUID);
dbHelper.AddParameter("@IKindGUID", ikindGUID);
DataTable dt = dbHelper.ToDataTable();
return dt;
}
#endregion
#region 根据胶料GUID获取终炼胶物料信息
/// <summary>
/// 根据胶料GUID获取终炼胶物料信息
/// </summary>
/// <param name="rubGUID">胶料GUID</param>
/// <returns>返回终炼胶物料列表</returns>
public static DataTable GetFinalRubMaterial(string rubGUID)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select GUID, MaterialCode, MaterialName from BasMaterial where LEFT(MaterialCode,1) > '4' and RubGUID = @RubGUID order by MaterialCode";
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@RubGUID", rubGUID);
DataTable dt = dbHelper.ToDataTable();
return dt;
}
#endregion
#endregion
#region 大罐物料参数
/// <summary>
/// 判断大罐号是否存在
/// </summary>
/// <param name="bigSerial">要判断的大罐号</param>
/// <returns>如果存在返回true否则返回false</returns>
public static bool IsExistsBigSerial(string bigSerial)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
string sqlstr = "select count(GUID) from SytBig where BigSerial=@BigSerial";
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@BigSerial", bigSerial);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
if (int.TryParse(result.ToString(), out intResult))
{
if (intResult > 0)
{
return true;
}
}
}
return false;
}
#endregion
#region 日罐物料参数
/// <summary>
/// 判断某个类型的日罐号是否存在
/// </summary>
/// <param name="unitNum">设备号</param>
/// <param name="jarSerial">秤内罐号</param>
/// <returns>存在返回true否在返回false</returns>
public static bool ExistsSytJarByUnitNum(string unitNum, int jarSerial)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select count(*) from SytJar where UnitNum=@UnitNum and JarSerial=@JarSerial";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@UnitNum", unitNum);
dbHelper.AddParameter("@JarSerial", jarSerial);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
int.TryParse(result.ToString(), out intResult);
if (intResult > 0)
{
return true;
}
}
return false;
}
/// <summary>
/// 判断某个类型的日罐号是否存在
/// </summary>
/// <param name="jarType">罐类型</param>
/// <param name="jarSerial">罐号</param>
/// <returns>存在返回true否在返回false</returns>
public static bool ExistsSytJar(string jarType, int jarSerial)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.CommandType = CommandType.Text;
string sqlstr = "select count(*) from SytJar where JarType=@JarType and JarSerial=@JarSerial";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@JarType", jarType);
dbHelper.AddParameter("@JarSerial", jarSerial);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
int.TryParse(result.ToString(), out intResult);
if (intResult > 0)
{
return true;
}
}
return false;
}
#endregion
}
}