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 { /// /// 基础业务辅助类 /// public class BasicHelper { private static Entity.BasEquip _BasEquip = null; #region 设备单元 /// /// 判断设备单元编号是否存在 /// /// 要判断的设备单元编号 /// 如果存在返回true,否则返回false 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; } /// /// 判断设备单元名称是否存在 /// /// 要判断的设备单元名称 /// 如果存在返回true,否则返回false 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; } /// /// 根据设备单元号查找某条设备单元数据 /// /// 设备单元号 /// 返回对应的设备单元号的数据行 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; } /// /// 根据GUID获取设备单元实体对象 /// /// GUID参数 /// 返回对应的设备单元实体对象 public static Entity.BasUnit GetUnitEntityByGUID(string guid) { DataRow dr = BaseDataHelper.GetDataRowByTableAndGUID("BasUnit", guid); return ConvertDataRowToBasUnit(dr); } /// /// 根据设备单元号查找某条设备单元实体 /// /// 设备单元号 /// 返回对应的设备单元号的实体对象 public static Entity.BasUnit GetUnitEntityByUnitNum(string unitNum) { DataRow dr = GetUnitDataRowByUnitNum(unitNum); return ConvertDataRowToBasUnit(dr); } /// /// 把数据行转换为BasUnit实体对象 /// /// 数据行 /// 返回转化后的设备单元实体对象 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; } } /// /// 获取所有的设备单元数据表 /// /// 返回所有设备单元数据表 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; } /// /// 获取所有的设备单元实体列表 /// /// 返回设备单元实体列表 public static List GetAllUnitEntity() { List lst = new List(); 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 机台设备 /// /// 机台设备信息 /// 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; } } /// /// 刷新机台设备信息 /// public static void RefreshBasEquip() { _BasEquip = null; } /// /// 获取机台设备数据行 /// /// public static DataRow GetBasEquip() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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; } } /// /// 获取机台设备guid /// /// 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.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 机台设备单元 /// /// 获取当前机台的设备单元列表 /// /// public static DataTable GetBasEquipUnitList() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.Error("获取数据连接失败,请检查数据库连接字符串是否正确!!"); throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError); } string sqlstr = "select * from BasEquipUnit"; DataTable dt = dbHelper.GetDataTableBySql(sqlstr); return dt; } /// /// 获取当前机台指定工艺分组的带罐设备单元(即对应工艺分组的秤设备) /// /// 工艺分组列表:1,2 /// 返回当前机台指定工艺分组的带罐设备单元(即对应工艺分组的秤设备) 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 胶料类别 /// /// 获取胶料类型列表 /// /// 返回胶料类型列表 public static DataTable GetRubTypeListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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); } /// /// 判断胶料类别编号是否存在 /// /// 要判断的胶料类别编号 /// 如果存在返回true,否则返回false public static bool IsExistsRubTypeCode(string rubTypeCode) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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; } /// /// 判断胶料类别名称是否存在 /// /// 要判断的胶料类别名称 /// 如果存在返回true,否则返回false public static bool IsExistsRubTypeName(string rubTypeName) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 胶料轮胎部件 /// /// 获取胶料轮胎部件列表 /// /// 返回胶料轮胎部件列表 public static DataTable GetRubTyrePartListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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); } /// /// 判断轮胎部件代码是否存在 /// /// 要判断的轮胎部件代码 /// 如果存在返回true,否则返回false public static bool IsExistsTyrePartCode(string tyrePartCode) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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; } /// /// 判断轮胎部件名称是否存在 /// /// 要判断的轮胎部件名称 /// 如果存在返回true,否则返回false public static bool IsExistsTyrePartName(string tyrePartName) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 胶料信息 /// /// 获取胶料信息列表 /// /// 返回胶料列表 public static DataTable GetRubInfoListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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); } /// /// 判断胶料代码是否存在 /// /// 要判断的胶料代码 /// 如果存在返回true,否则返回false public static bool IsExistsRubCode(string rubCode) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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; } /// /// 判断胶料名称是否存在 /// /// 要判断的胶料名称 /// 如果存在返回true,否则返回false public static bool IsExistsRubName(string rubName) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 物料大类 /// /// 判断物料大类名称是否存在 /// /// 要判断的物料大类名称 /// 如果存在返回true,否则返回false public static bool IsExistsMKindName(string mkindNamed) { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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; } /// /// 获取大类列表,用于组合框 /// /// 返回大类列表 public static DataTable GetMKindListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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); } /// /// 根据大类GUID获取大类编码 /// /// GUID /// 返回对应的大类编码 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; } /// /// 根据大类代号获取大类名称 /// /// 物料大类代号 /// 返回对应的物料大类名称 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 物料细类 /// /// 判断物料细类名称是否存在 /// /// 要判断的物料细类名称 /// 如果存在返回true,否则返回false 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; } /// /// 获取某个大类下的物料细类,用于组合框 /// /// 大类GUID /// 返回符合条件的物料细类列表 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; } /// /// 根据细类GUID获取细类编码 /// /// GUID /// 返回对应的细类编码 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; } /// /// 根据细类GUID获取细类统计类别 /// /// GUID /// 返回对应的统计类别 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 物料类别 /// /// 根据物料GUID获取物料类别(物料大类+物料细类) /// /// 物料GUID /// 返回对应的物料类别 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 胶料段数 /// /// 获取胶料段数 /// /// 返回胶料段数数据表 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 胶料称量类型 /// /// 获取胶料称量类型,默认请选择 /// /// 返回胶料称量类型数据表 public static DataTable GetRubberWeightType() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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; } /// /// 获取胶料称量类型,无"请选择" /// /// 返回胶料称量类型数据表 public static DataTable GetRubberWeightTypeNoSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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位流水 /// /// 获取下一个可用的物料代码,1位大类代码+2位细类代码+10位流水 /// /// 物料大类代码 /// 物料细类代码 /// 返回可用的物料代码 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位流水) /// /// 获取下一个可用的物料代码,1位大类代码+2位细类代码+(4位胶号+6位流水)或(10位流水) /// /// 大类GUID /// 细类GUID /// 大类代码 /// 细类代码 /// 胶号 /// 是否原材料 /// 返回下一个可用的物料代码 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 获取物料列表 /// /// 获取物料列表 /// /// 返回物料列表 public static DataTable GetMaterialListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 获取物料列表(有罐的) /// /// 获取物料列表(有罐的) /// /// 返回物料列表 public static DataTable GetMaterialListForSelectIsPutJar() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 /// /// 根据物料编码和物料名称获取物料GUID /// /// 物料编码 /// 物料名称 /// 返回对应的GUID 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获取物料数据行 /// /// 根据GUID获取物料数据行 /// /// guid /// 返回数据行 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,获取物料代码 /// /// 根据GUID,获取物料代码 /// /// GUID /// 返回物料代码 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,获取物料名称 /// /// 根据GUID,获取物料名称 /// /// GUID /// 返回物料名称 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获取物料类型(物料大类名称 + 物料细类名称) /// /// 根据物料GUID获取物料类型(物料大类名称 + 物料细类名称) /// /// 物料GUID /// 返回物料细类数据行 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 判断物料名称是否在物料表中存在 /// /// 判断物料名称是否在物料表中存在 /// /// 要判断的物料名称 /// 如果存在返回true,否则返回false 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 判断某个胶料物料是否存在 /// /// 判断某个胶料物料是否存在 /// /// 物料大类GUID /// 物料细类GUID /// 胶料GUID /// 存在返回true,不存在返回false 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获取产生物料列表 /// /// 根据胶料代码,物料大类GUID,物料细类GUID获取产生物料列表 /// /// 胶料GUID /// 物料大类GUID /// 物料细类GUID /// 返回对应的产生物料列表 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获取终炼胶物料信息 /// /// 根据胶料GUID获取终炼胶物料信息 /// /// 胶料GUID /// 返回终炼胶物料列表 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 大罐物料参数 /// /// 判断大罐号是否存在 /// /// 要判断的大罐号 /// 如果存在返回true,否则返回false 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 日罐物料参数 /// /// 判断某个类型的日罐号是否存在 /// /// 设备号 /// 秤内罐号 /// 存在返回true,否在返回false 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; } /// /// 判断某个类型的日罐号是否存在 /// /// 罐类型 /// 罐号 /// 存在返回true,否在返回false 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 } }