/****************************** * 说明:业务基类 * 创建人:龚宇超 * 创建日期:2017-09-01 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using Lskj.Model; using Lskj.Core; using Lskj.Util; using System.Data.SqlClient; using System.Data.Common; namespace Lskj.Business.Impl { /// /// 业务基类 /// public class BaseImpl { /// /// 检查数据库某表的结构是否完整 /// /// /// public static bool CheckTable(Dictionary colDic, string tableName) { try { string isExitTab = $"select top 1 * from sysObjects where Id=OBJECT_ID(N'{tableName}') and xtype='U'"; DataTable apiTab = SqlHelper.ExecuteDataTable(isExitTab); if (apiTab.Rows.Count > 0)//存在表 { DataTable columnsTab = SqlHelper.ExecuteDataTable(string.Format($"select name from syscolumns where id=object_id('{tableName}')")); foreach (KeyValuePair colunmField in colDic) { DataRow[] dataRows = columnsTab.Select().Where(n => (n["name"] + "").Equals(colunmField.Key)).ToArray(); if (dataRows.Length == 0) { string addColSql = string.Format($"alter table {tableName} add {0} {1}", colunmField.Key, colunmField.Value); SqlHelper.ExecuteNonQuery(addColSql);//添加列 } } } else { string createCol = string.Empty; foreach (KeyValuePair colunmField in colDic) { createCol += string.Format("{0} {1},", colunmField.Key, colunmField.Value); } string createTabSql = $"create table {tableName}(id int IDENTITY(1,1) NOT NULL,{createCol.TrimEnd(',')})"; SqlHelper.ExecuteNonQuery(createTabSql);//创建表 } return true; } catch (Exception) { return false; } } /// /// 说明:检查数据库表是否包含某列 /// 创建人:龚宇超 /// 创建日期:2017-08-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// Name of the col. /// true if [has contain column]; otherwise, false. public static bool HasExistsColumn(string tableName, string colName) { string sqlValue = string.Format("select object_id from sys.columns where object_id = object_id('{0}') and name = '{1}'", tableName, colName); if (SqlHelper.ConnectionType == ConnectionType.DmServer) { sqlValue = string.Format("select COLUMN_NAME from ALL_TAB_COLUMNS where TABLE_NAME = '{0}' and COLUMN_NAME = '{1}'", tableName, colName); } return SqlHelper.ExecuteDataTable(sqlValue).Rows.Count > 0; } /// /// 说明:检查数据库表是否包含某列,不存在则创建 /// 创建人:龚宇超 /// 创建日期:2017-08-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// Name of the col. /// true if [has contain column]; otherwise, false. public static bool HasExistsColumn(string tableName, string colName, string colType) { if (!HasExistsColumn(tableName, colName)) { return ExecSqlValue(string.Format("ALTER TABLE {0} ADD {1} {2}", tableName, colName, colType)) > 0; } return true; } /// /// 说明:是否存在xxx表 /// 创建人:龚宇超 /// 创建日期:2018-02-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// true if [has exists table] [the specified table name]; otherwise, false. public static bool HasExistsTable(string tableName) { try { string sqlValue = "select 1 from " + tableName + " where 1<>1"; return SqlHelper.ExecuteDataTable(sqlValue).Rows.Count >= 0; } catch (Exception) { } return false; } /// /// 判断是否存在指定存储过程 /// /// /// public static bool HasExistsStoredProcedure(string Name) { try { string sqlValue = string.Format("select OBJECT_ID(N'{0}', N'P') ", Name); return !string.IsNullOrWhiteSpace(SqlHelper.ExecuteScalar(sqlValue) + ""); } catch (Exception) { } return false; } /// /// 说明:获取树节点配置表 /// 创建人:王一帆 /// 创建日期:2020-12-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// true if [has exists table] [the specified table name]; otherwise, false. public static DataRow TreeNodeSetTab(string treeTable) { string sqlValue = string.Format("select * from p_systemTreeNodeSetTab" + " where treeTable='{0}'", treeTable); DataTable dt = SqlHelper.ExecuteDataTable(sqlValue); return dt != null ? dt.Rows.Count > 0 ? dt.Rows[0] : null : null; } /// /// 说明:是否包含某条数据 /// 创建人:龚宇超 /// 创建日期:2018-02-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// The key. /// The value. /// The row. /// true if [has exists data row] [the specified table name]; otherwise, false. public static bool HasExistsDataRow(string tableName, string key, string value, out DataRow row) { return HasExistsDataRow(tableName, key, value, "", out row); } /// /// 说明:是否包含某条数据 /// 创建人:龚宇超 /// 创建日期:2018-08-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// The key. /// The value. /// The where cond. /// The row. /// true if [has exists data row] [the specified table name]; otherwise, false. public static bool HasExistsDataRow(string tableName, string key, string value, string whereCond, out DataRow row) { try { string sqlValue = string.Format("select * from {0} where {1}='{2}' {3}", tableName, key, value, whereCond); row = GetDataRowResult(sqlValue); return true; } catch (Exception) { } row = null; return false; } /// /// 说明:修改某个表字段 /// 创建人:龚宇超 /// 创建日期:2018-02-02 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// Name of the field. /// Type of the field. /// true if XXXX, false otherwise. public static bool UpdateTableField(string tableName, string fieldName, string fieldType) { string sqlValue = string.Format("ALTER TABLE {0} ALTER COLUMN {1} {2}", tableName, fieldName, fieldType); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:添加业务异常数据到lscrm系统 /// 创建人:龚宇超 /// 创建日期:2018-03-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The MSG. /// true if XXXX, false otherwise. public static bool AddExceptionToLsCrm(string msg) { try { using (SqlConnection conn = new SqlConnection(DBConfig.Instance.GetLsCrmConnection())) { conn.Open(); string commText = string.Format("insert into Crm_ProblemTab(OperatorName,ProDesc,CusName,CusConnection) values('{0}','{1}','{2}','{3}')", ERPInfo.Instance.UserName, msg, SystemInfo.Instance.ClientName, DBConfig.Instance.GetConnection()); using (SqlCommand comm = new SqlCommand(commText, conn)) { int result = comm.ExecuteNonQuery(); comm.Dispose(); return result > 0; } } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); } return true; } /// /// 说明:通过模块ID获取用户模块权限 /// 创建人:龚宇超 /// 创建日期:2017-08-18 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sub identifier. /// The menu identifier. /// 1.有操作权限.0.无权限.2.只读权限 public static int GetUserPurviewsByMenuId(string menuId) { if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.HeadMenuId) && SystemInfo.Instance.HeadMenuId.Split(',').Contains(menuId)) { return 1; } //2026-08-08 pz说不要判断,工具统一处理 //P_MessageToolLinkDllTab表中cardId=-99为通用模块(右侧快捷通道通用模块),默认有权限 2023-12-4 徐成说的cardId=-99的配置 //string sql = string.Format("select a.*,b.PurviewId,b.MouseOutImg,b.MouseOverImg1 from(" // + " select * from P_MessageToolLinkDllTab where cardId=-99 and ( grouptagid=2 or grouptagid=1) " // + ")a join p_formmenuconfigtab b on a.LMenuId=b.MenuId where LinkModeTag=1 and LMenuid='{1}' order by grouptagid,ItemTagId", ERPInfo.Instance.UserId, menuId); //DataTable table = SqlHelper.ExecuteDataTable(sql); //if (table.Rows.Count > 0) //{ // return 1; //} if (ERPInfo.Instance.UserName == ERPInfo.Instance.UserManager) return 1; string readPurview = "," + menuId + "|,"; string editPurview = "," + menuId + ","; string allPurview = ","; string sqlValue = "select top 1 * from p_SubsysPurviewTab where employeeid=@employeeid"; DataTable tablePurviews = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@employeeid", ERPInfo.Instance.UserId) }); for (int i = 0; i < tablePurviews.Columns.Count; i++) { DataColumn col = tablePurviews.Columns[i]; if (col.ColumnName.ToLower().Contains("purview")) { DataRow item = tablePurviews.Rows[0]; allPurview += item[col.ColumnName] + ","; } } if (string.IsNullOrEmpty(allPurview)) return 0; if (allPurview.Contains(editPurview)) return 1; if (allPurview.Contains(readPurview)) return 2; return 0; } /// /// 说明:通过模块编号获取用户模块权限 /// 创建人:龚宇超 /// 创建日期:2017-11-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// System.Int32. public static int GetUserPurviewsByMenuCode(string menuCode) { string where = string.IsNullOrEmpty(ERPInfo.Instance.SeriesId) ? "" : string.Format("and SeriesId={0}", ERPInfo.Instance.SeriesId); string sqlValue = string.Format("select top 1 MenuId from P_FormMenuConfigTab where UrlParams='{0}' and lower(DllFileName) not like '%accraditation%' and subsysid in (select SubSysId from P_SubSystemTab where UseEd=1 {1}) {1}", menuCode, where); string menuId = SqlHelper.ExecuteString("MenuId", sqlValue); return GetUserPurviewsByMenuId(menuId); } /// /// 说明:获取单据是否有多表头 /// 创建人:王一帆 /// 创建日期:2020-07-31 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// 0.普通表格、1.多表头、2.树结构表格 public static int GetBillDetailType(string menuCode) { if (HasExistsColumn("p_systembillDetail", "bandTitle") && HasExistsColumn("p_systembillDetail", "bandFields")) { string sqlValue = "select 1 from p_systembillDetail where typeCode=@tab and ISNULL(bandTitle,'')<>'' and ISNULL(bandFields,'')<>''"; bool isBanded = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", menuCode) }).Rows.Count > 0; return isBanded ? 1 : 0; } return 0; } /// /// 说明:获取基础档案、报表模版类型 /// 创建人:龚宇超 /// 创建日期:2017-11-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// 0.普通表格、1.多表头、2.树结构表格 public static int GetBaseType(string menuCode) { // 是否为多表头 string sqlValue = "select 1 from p_systemwordbooktab where tab=@tab and ISNULL(bandTitle,'')<>'' and ISNULL(bandFields,'')<>''"; bool isBanded = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", menuCode) }).Rows.Count > 0; if (isBanded) return 1; // 是否为树结构表格 sqlValue = "select 1 from P_FormMenuConfigTab where PurviewId=@tab and ISNULL(TRCReport,0)=1"; bool isTreeGrid = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", menuCode) }).Rows.Count > 0; return isTreeGrid ? 2 : 0; } /// /// 说明:获取扫码控件表格 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// 控件为扫码框且内容隐藏就为扫码控件 public static DataTable GetSweepCode(string menuCode) { // 是否为存在扫码控件 string sqlValue = "select * from p_systemwordbooktab where tab=@tab and vislble='1' and fieldsqlTag='98' ORDER BY orderid"; return SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", menuCode) }); } /// /// 说明:获取扫码控件表格 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// 扫码控件的提醒 public static DataTable GetSweepCodeTips(string menuCode) { // 是否为多表头 string sqlValue = "select * from p_systemwordbooktab where tab=@tab and TM_tagID=-1 ORDER BY orderid"; return SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", menuCode) }); } /// /// 说明:验证是否允许删除记录 /// 创建人:龚宇超 /// 创建日期:2018-01-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// The key value. /// The tip MSG. /// System.Int32. public static int VerifyCanDelete(string menuCode, string fieldKey, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@modid",SqlDbType.VarChar,20), new SqlParameter("@keyvalue",SqlDbType.VarChar,40), pMsg, returnValue }; param[0].Value = menuCode; param[1].Value = fieldKey; SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_VerifyCanDelete", "baseSave", param); tipMsg = pMsg.Value + ""; return Convert.ToInt32(returnValue.Value + ""); } /// /// 说明:树结构自定义配置功能 /// 创建人:王一帆 /// 创建日期:2020-12-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// The key value. /// The tip MSG. /// System.Int32. public static int ReBuildTreeNode(string treeModid, int operType, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@treeModid",SqlDbType.VarChar,20), new SqlParameter("@operType",SqlDbType.Int), new SqlParameter("@operatorid",SqlDbType.Int), new SqlParameter("@operatorname",SqlDbType.VarChar,20), pMsg, returnValue }; param[0].Value = treeModid; param[1].Value = operType; param[2].Value = ERPInfo.Instance.UserId; param[3].Value = ERPInfo.Instance.UserName; SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_system_ReBuildTreeNode", "treeDrop", param); tipMsg = pMsg.Value + ""; return Convert.ToInt32(returnValue.Value + ""); } /// /// 说明:执行SQL语句返回受影响行 /// 创建人:龚宇超 /// 创建日期:2017-12-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// The parameters. /// System.Int32. public static int ExecSqlValue(string sqlValue, params DbParameter[] parameters) { try { return SqlHelper.ExecuteNonQuery(CommandType.Text, sqlValue, parameters); } catch (Exception ex) { } return 0; } /// /// 说明:执行SQL语句返回受影响行,mes使用,报错抛出 /// 创建人:龚宇超 /// 创建日期:2017-12-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// The parameters. /// System.Int32. public static int ExecSqlValueMes(string sqlValue, params DbParameter[] parameters) { try { return SqlHelper.ExecuteNonQuery(CommandType.Text, sqlValue, parameters); } catch (Exception ex) { throw; } return 0; } /// /// 说明:执行SQL语句返回受影响行,带事务 /// 创建人:龚宇超 /// 创建日期:2017-12-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// The parameters. /// System.Int32. public static int ExecSqlValue(string sqlValue, DbTransaction Trans, params DbParameter[] parameters) { try { return SqlHelper.ExecuteNonQuery(CommandType.Text, sqlValue, Trans, 1, parameters); } catch (Exception ex) { } return 0; } public static int ExecSqlValue(string sqlValue, bool isTip, params SqlParameter[] parameters) { try { return SqlHelper.ExecuteNonQuery(CommandType.Text, sqlValue, parameters); } catch (Exception) { if (isTip) throw; } return 0; } /// /// 说明:执行存储过程 /// 创建人:龚宇超 /// 创建日期:2017-10-31 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// The parameters. /// System.Object. public static int ExecProcedure(string sqlValue, params DbParameter[] parameters) { return SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, sqlValue, parameters); } /// /// 说明:执行存储过程,带事务 /// 创建人:龚宇超 /// 创建日期:2017-10-31 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// The parameters. /// System.Object. public static int ExecProcedure(string sqlValue, DbTransaction Trans, params DbParameter[] parameters) { return SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, sqlValue, Trans, 1, parameters); } /// /// 说明:获取列前缀 /// 创建人:龚宇超 /// 创建日期:2017-11-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// System.String. /// public static string GetColumnPrefix(string tableName) { string sqlValue = "select column_prefix from p_systemtables where lower(table_name)=@tableName"; return SqlHelper.ExecuteString("column_prefix", sqlValue, new SqlParameter[] { new SqlParameter("@tableName", tableName) }); } /// /// 说明:获取主键 /// 创建人:龚宇超 /// 创建日期:2017-10-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// System.String. /// public static string GetBasePrimaryKey(string menuCode) { string sqlValue = "select top 1 fieldname from P_systemwordbooktab where tab = @tab order by orderid"; DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", menuCode) }); return (dtTable.Rows.Count > 0) ? dtTable.Rows[0]["fieldname"] + "" : string.Empty; } /// /// 说明:获取当前登录用户权限 /// 创建人:龚宇超 /// 创建日期:2017-08-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.String. public static string GetPurviewCond() { string operColumn = string.Empty; string viewColumn = string.Empty; string targetColumn = string.Empty; string sqlValue = "select name from sys.columns where object_id=object_id('p_SubsysPurviewTab') and name like '%purview'"; if (SqlHelper.ConnectionType == ConnectionType.DmServer) { sqlValue = "select COLUMN_NAME name from ALL_TAB_COLUMNS where TABLE_NAME = 'p_SubsysPurviewTab' and COLUMN_NAME like '%purview%'"; } DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); if (dtTable.Rows.Count == 0) { operColumn = @"','+isnull([KcPurview],'')+','+isnull([crmPurview],'')+','+isnull([bomPurview],'')+','+ isnull([mrpPurview],'')+','+isnull([scmPurview],'')+','+isnull([sellPurview],'')+','+ isnull([RdmPurview],'')+','+isnull([hrPurview],'')+','+isnull([costPurview],'')+','+ isnull([eamPurview],'')+','+isnull([FmPurview],'')+','+isnull([oaPurview],'')+','+ isnull([BiPurview],'')+','+isnull([QmsPurview],'')+','"; viewColumn = @"','+isnull([KcPurview],'')+'|,'+isnull([crmPurview],'')+'|,'+isnull([bomPurview],'')+'|,'+ isnull([mrpPurview],'')+'|,'+isnull([scmPurview],'')+'|,'+isnull([sellPurview],'')+'|,'+ isnull([RdmPurview],'')+'|,'+isnull([hrPurview],'')+'|,'+isnull([costPurview],'')+'|,'+ isnull([eamPurview],'')+'|,'+isnull([FmPurview],'')+'|,'+isnull([oaPurview],'')+'|,'+ isnull([BiPurview],'')+'|,'+isnull([QmsPurview],'')+'|,'"; } else { foreach (DataRow item in dtTable.Rows) { operColumn += "','+isnull(" + item["name"] + ",'')+','"; viewColumn += "','+isnull(" + item["name"] + ",'')+'|,'"; } } return @"and (CHARINDEX(','+CAST(menuid as varchar)+',',(select top 1 " + operColumn + @" from [p_SubsysPurviewTab] where employeeid=" + ERPInfo.Instance.UserId + "))>0 " + @" or CHARINDEX(','+CAST(menuid as varchar)+'|,',(select top 1 " + viewColumn + @" from [p_SubsysPurviewTab] where employeeid=" + ERPInfo.Instance.UserId + "))>0 " + "or len(menustruct)=2 or " + ERPInfo.Instance.UserId + "=1 or '" + ERPInfo.Instance.UserName + "'='管理员')"; } /// /// 说明:替换默认值 /// 创建人:龚宇超 /// 创建日期:2017-08-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The default value. /// System.String. public static string GetDefaultValue(string defaultValue, string parentValue = "", string[] otherParams = null) { if (string.IsNullOrEmpty(defaultValue)) return defaultValue; defaultValue = defaultValue.TrimStart(new char[] { '\r', '\n' }); // 去除前后空格、制表符等 defaultValue = ReplaceHelper.ReplaceUserInfo(defaultValue);// defaultValue = ReplaceHelper.ReplaceTreeViewParentKeyCond(defaultValue, parentValue); if ("guid".Equals(defaultValue)) return Guid.NewGuid().ToString(); if (defaultValue.StartsWith("@")) return GetResult(defaultValue.Replace("@", "")) + ""; if (defaultValue.StartsWith("!")) { defaultValue = "exec " + defaultValue.Replace("!", "").Replace("(", " ").Replace(")", ""); return GetResult(defaultValue) + ""; } if (defaultValue.ToLower().Contains("{#p_")) { try { List paramList = ReplaceHelper.GetParamFields(defaultValue); foreach (var item in paramList) { string index = item.Replace("{#p_", "").Replace("}", ""); int i = 0; if (int.TryParse(index, out i)) { defaultValue = defaultValue.Replace(item, otherParams != null ? otherParams[i - 1] : ""); } } } catch (Exception) { } } return defaultValue; } /// /// 替换特殊字符 {#p_ /// /// /// /// /// public static string SpecialReplacement(string defaultValue, string[] otherParams = null) { if (string.IsNullOrEmpty(defaultValue)) return defaultValue; if (defaultValue.ToLower().Contains("{#p_")) { try { List paramList = ReplaceHelper.GetParamFields(defaultValue); foreach (var item in paramList) { string index = item.Replace("{#p_", "").Replace("}", ""); int i = 0; if (int.TryParse(index, out i)) { defaultValue = defaultValue.Replace(item, otherParams != null ? otherParams[i - 1] : ""); } } } catch (Exception) { } } return defaultValue; } /// /// 说明:获取记录 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// Name of the field. /// The cond key. /// The cond value. /// System.Object. public static object GetRecord(string tableName, string fieldName, string condKey, string condValue) { if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(fieldName) || string.IsNullOrEmpty(condKey) || string.IsNullOrEmpty(condValue)) return new object(); string sqlValue = string.Format("select top 1 {0} from {1} where {2}='{3}'", fieldName, tableName, condKey, condValue); return GetResult(sqlValue); } /// /// 说明:执行sql语句返回数据 /// 创建人:龚宇超 /// 创建日期:2017-08-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// System.String. public static object GetResult(string sqlValue) { return SqlHelper.ExecuteScalar(sqlValue); } /// /// 说明:执行sql语句返回数据,带事务 /// 创建人:龚宇超 /// 创建日期:2017-08-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// System.String. public static object GetResult(string sqlValue, DbTransaction Trans) { return SqlHelper.ExecuteScalar(sqlValue, Trans); } /// /// 说明:执行sql语句返回数据 /// 创建人:龚宇超 /// 创建日期:2018-01-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// The parameters. /// System.Object. public static object GetResult(string sqlValue, SqlParameter[] parameters) { return SqlHelper.ExecuteScalar(CommandType.Text, sqlValue, parameters); } /// /// 说明:获取菜单其他配置 /// 创建人:龚宇超 /// 创建日期:2017-11-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The module identifier. /// DataRow. public static DataRow GetMenuConfigTab(int moduleId) { string sqlValue = "select * from P_FormMenuConfigTab where menuid=@menuid"; DataTable table = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@menuid", moduleId) }); return table != null && table.Rows.Count > 0 ? table.Rows[0] : null; } /// /// 说明:获取右键具体配置 /// 创建人:龚宇超 /// 创建日期:2017-11-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The module identifier. /// DataRow. public static DataRow GetPopMenu(string tab, string menuname) { string sqlValue = string.Format("select* from P_systempopupmenu where tab='{0}' and menuname = '{1}'", tab, menuname); DataTable table = SqlHelper.ExecuteDataTable(sqlValue); return table != null && table.Rows.Count > 0 ? table.Rows[0] : null; } /// /// 说明:获取系统配置 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataRow. public static DataRow GetSystemTab() { string sqlValue = "select * from p_systemtab"; return GetDataRowResult(sqlValue); } /// /// 说明:获取验证系统配置 /// 创建人:王一帆 /// 创建日期:2020-12-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataRow. public static DataRow GetVeriSystemTab() { string sqlValue = "select isnull(clientcode,'') AS coid,ClientName,* from p_systemtab"; return GetDataRowResult(sqlValue); } /// /// 说明:执行SQL语句返回第一行 /// 创建人:龚宇超 /// 创建日期:2017-12-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// DataRow. public static DataRow GetDataRowResult(string sqlValue) { DataTable table = GetDataTableResult(sqlValue); return table.Rows.Count > 0 ? table.Rows[0] : null; } /// /// 说明:获取某个表的列 /// 创建人:龚宇超 /// 创建日期:2017-11-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the table. /// DataTable. public static DataTable GetTableColumns(string tableName) { string sqlValue = string.Format("select * from {0} where 1<>1", tableName); return SqlHelper.ExecuteDataTable(sqlValue); } /// /// 说明:执行SQL语句返回结果集 /// 创建人:龚宇超 /// 创建日期:2017-08-23 /// 修改人: /// 修改日期:2017-10-25 /// 修改备注:1. 2017-10-25增加传入参数为空处理,返回空DataTable /// 版本:1.1 /// /// The SQL value. /// DataTable. public static DataTable GetDataTableResult(string sqlValue) { try { if (string.IsNullOrWhiteSpace(sqlValue)) return new DataTable(); sqlValue = GetDefaultValue(sqlValue); sqlValue = ReplaceHelper.ReplaceParam(sqlValue); return SqlHelper.ExecuteDataTable(sqlValue); } catch (Exception ex) { } return new DataTable(); } public static DataTable GetDataTableResultGetTableStructure(string sqlValue) { try { if (string.IsNullOrWhiteSpace(sqlValue)) return new DataTable(); sqlValue = GetDefaultValue(sqlValue); sqlValue = ReplaceHelper.ReplaceParamGetTableStructure(sqlValue); return SqlHelper.ExecuteDataTable(sqlValue); } catch (Exception) { } return new DataTable(); } /// /// 说明:执行SQL语句返回结果集 /// 创建人:龚宇超 /// 创建日期:2018-10-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The SQL value. /// SqlDataAdapter. public static DbDataAdapter GetAdapterResult(string sqlValue) { try { if (string.IsNullOrWhiteSpace(sqlValue)) return null; sqlValue = GetDefaultValue(sqlValue); sqlValue = ReplaceHelper.ReplaceParam(sqlValue); return SqlHelper.ExecuteAdapter(CommandType.Text, sqlValue); } catch (Exception) { } return null; } /// /// 说明:获取打印配置 /// 创建人:龚宇超 /// 创建日期:2019-07-31 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The key. /// DataTable. public static DataTable GetPrintTemp70(string key) { string sqlValue = string.Format(@"select * from p_systemPrintDesignTab where modid='{0}'", key); return GetDataTableResult(sqlValue); } /// /// 执行删除存储过程 /// /// /// /// /// public static int deleteFlow(int tagid, string Dllcode, string stepCode, int typeID, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@tagid",SqlDbType.Int), new SqlParameter("@Dllcode",SqlDbType.VarChar,50), new SqlParameter("@stepCode",SqlDbType.VarChar,50), new SqlParameter("@typeID",SqlDbType.Int), pMsg, returnValue }; param[0].Value = tagid; param[1].Value = Dllcode; param[2].Value = stepCode; param[3].Value = typeID; BaseImpl.ExecProcedure("[p_systemDeleteFlowInfo]", param); tipMsg = pMsg.Value + ""; return Convert.ToInt32(returnValue.Value.ToString()); } /// /// 执行删除存储过程,带事务 /// /// /// /// /// public static int deleteFlow(int tagid, string Dllcode, string stepCode, int typeID, out string tipMsg, DbTransaction Trans) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@tagid",SqlDbType.Int), new SqlParameter("@Dllcode",SqlDbType.VarChar,50), new SqlParameter("@stepCode",SqlDbType.VarChar,50), new SqlParameter("@typeID",SqlDbType.Int), pMsg, returnValue }; param[0].Value = tagid; param[1].Value = Dllcode; param[2].Value = stepCode; param[3].Value = typeID; BaseImpl.ExecProcedure("[p_systemDeleteFlowInfo]", Trans, param); tipMsg = pMsg.Value + ""; return Convert.ToInt32(returnValue.Value.ToString()); } /// /// 执行通过人员id获取权限菜单存储过程 /// /// /// /// /// public static DataSet getAuthorityByEmpid(int typeId, string empid, string operatorId, string operatorName, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@typeId",SqlDbType.Int), new SqlParameter("@empid",SqlDbType.VarChar,50), new SqlParameter("@operatorId",SqlDbType.VarChar,50), new SqlParameter("@operatorName",SqlDbType.VarChar,50), pMsg, returnValue }; param[0].Value = typeId; param[1].Value = empid; param[2].Value = operatorId; param[3].Value = operatorName; tipMsg = pMsg.Value + ""; DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_getAuthorityByEmpid", "#ba_firstpage", param); return ds; } /// /// 说明:拖拽后执行存储过程 /// 创建人:王一帆 /// 创建日期:2022-12-12 /// /// /// /// public static int getMrpPlanAdd(string operType, string billno, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@operType",SqlDbType.VarChar,50), new SqlParameter("@billno",SqlDbType.VarChar,50), new SqlParameter("@operatorid",SqlDbType.Int), new SqlParameter("@operatorname",SqlDbType.VarChar,50), pMsg, returnValue }; param[0].Value = operType; param[1].Value = billno; param[2].Value = ERPInfo.Instance.UserId; param[3].Value = ERPInfo.Instance.UserName; tipMsg = pMsg.Value + ""; BaseImpl.ExecProcedure("[pr_mrp_planadd]", param); tipMsg = pMsg.Value + ""; return Convert.ToInt32(returnValue.Value.ToString()); } /// /// 说明:获取表的主键值 /// 创建人:王一帆 /// 创建日期:2020-05-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// public static string GetPrimaryKey(string TableName) { //string sqlValue = string.Format("SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='{0}'", TableName); DataTable dtTable = MainImpl.GetDatabaseProperty(TableName); //DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); return (dtTable.Rows.Count > 0) ? dtTable.Rows[0]["COLUMN_NAME"] + "" : string.Empty; } /// /// 说明:获取表中是否包含其主键列 /// 创建人:王一帆 /// 创建日期:2021-04-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// public static bool GetIsContainKey(string TableName, string ParmaryKey, string ids) { int idCount = ids.Split(',').Count(); string sqlValue = string.Format("SELECT * from {0} where {1} in({2})", TableName, ParmaryKey, ids); DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); return dtTable != null ? dtTable.Rows.Count == idCount : false; } /// /// 说明:根据模块id判断是否设置不能同时打开多个相同模块 /// 创建人:曹屹峰 /// 创建日期:2024-02-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// public static bool GetOpenRestrictions(string MenuId) { if (ERPInfo.Instance.SingleOpenMode) { string sqlValue = string.Format("SELECT SingleOpenMode from p_formmenuconfigtab where MenuId='{0}'", MenuId); DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); if (dtTable.Rows.Count > 0) { return "1".Equals(dtTable.Rows[0]["SingleOpenMode"] + ""); } } return false; } } }