private string GetRelWhere(string relSource, int tableIndex, char prefix, object[] curPks) { StringBuilder whereBuilder = new StringBuilder(); LibSqlModel relModel = LibSqlModelCache.Default.GetSqlModel(relSource); DataColumn[] cols = relModel.Tables[tableIndex].PrimaryKey; for (int i = 0; i < curPks.Length; i++) { DataColumn pk = cols[i]; if (i != 0) { whereBuilder.Append(" AND "); } LibDataType dataType = (LibDataType)pk.ExtendedProperties[FieldProperty.DataType]; if (dataType == LibDataType.Text) { whereBuilder.AppendFormat("{0}.{1} = {2}", prefix, pk.ColumnName, LibStringBuilder.GetQuotObject(curPks[i])); } else { whereBuilder.AppendFormat("{0}.{1} = {2}", prefix, pk.ColumnName, LibSysUtils.ToString(curPks[i]) == "" ? 0 : curPks[i]); } } return(whereBuilder.ToString()); }
/// <summary> /// 静态构造函数 /// </summary> static LibDeptDutyPersonCache() { //初始即查找是否具有按部门岗位审核的相关字段 LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("com.Dept"); if (sqlModel != null && sqlModel.Tables.Count > 1 && sqlModel.Tables[1].Columns.Contains("DUTYID")) { HasAduitOfDuty = true; } }
public void RemoveUserPicture(string progId, string internalId, string fileName) { string path = Path.Combine(EnvProvider.Default.RuningPath, "UserPicture", progId, internalId, fileName); if (File.Exists(path)) { File.Delete(path); LibDataAccess dataAccess = new LibDataAccess(); LibSqlModel model = LibSqlModelCache.Default.GetSqlModel(progId); dataAccess.ExecuteNonQuery(string.Format("update {0} set IMGSRC='' where INTERNALID={1}", model.Tables[0].TableName, LibStringBuilder.GetQuotString(internalId)), false); } }
public static string GetQueryData(string progId, LibQueryCondition condition, string prefix = "A", bool useRelativeField = true) { if (condition == null) { return(string.Empty); } StringBuilder builder = new StringBuilder(); LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel(progId); if (sqlModel == null) { throw new ArgumentNullException("sqlModel", "GetQueryData方法解析的progId取不到sqlModel"); } LibSqlModelTable table = (LibSqlModelTable)sqlModel.Tables[0]; foreach (LibQueryField queryField in condition.QueryFields) { if (!table.Columns.Contains(queryField.Name)) { continue; } LibSqlModelColumn col = (LibSqlModelColumn)table.Columns[queryField.Name]; if (col.ExtendedProperties.ContainsKey(FieldProperty.FieldType)) { FieldType fieldType = (FieldType)col.ExtendedProperties[FieldProperty.FieldType]; if (FieldType.Virtual == fieldType) { continue; } if (!useRelativeField && FieldType.Relative == fieldType) { continue; } } LibDataType dataType = (LibDataType)col.ExtendedProperties[FieldProperty.DataType]; BuildQueryStr(dataType, queryField, builder, prefix, true, string.Empty); //加入权限 if (condition.PowerQueryFieldDic.ContainsKey(queryField.Name)) { BuildPowserQueryStr(dataType, condition.PowerQueryFieldDic[queryField.Name], builder, prefix, true, string.Empty); } } if (builder.Length > 0) { builder.Remove(builder.Length - 4, 4); } return(builder.ToString()); }
private void MergeQueryField(string progId, LibPermission curPermission, LibPermission otherPermission) { LibSqlModel sqlModel = null; LibSqlModelTable table = null; List <string> removeList = new List <string>(); foreach (var item in curPermission.QueryFieldDic) { if (otherPermission.QueryFieldDic.ContainsKey(item.Key)) { LibQueryField other = otherPermission.QueryFieldDic[item.Key][0]; bool exist = false; foreach (var subItem in item.Value) { if (table == null) { sqlModel = LibSqlModelCache.Default.GetSqlModel(progId); if (sqlModel != null) { table = (LibSqlModelTable)sqlModel.Tables[0]; } } if (table != null) { LibSqlModelColumn col = (LibSqlModelColumn)table.Columns[item.Key]; LibDataType dataType = (LibDataType)col.ExtendedProperties[FieldProperty.DataType]; exist = LibQueryConditionParser.GetQueryFieldStr(dataType, subItem).CompareTo(LibQueryConditionParser.GetQueryFieldStr(dataType, other)) == 0; if (exist) { break; } } } if (!exist) { item.Value.Add(other); } } else { removeList.Add(item.Key); } } foreach (var item in removeList) { curPermission.QueryFieldDic.Remove(item); } }
private void InitData() { //授权规格 LibDataAccess dataAccess = new LibDataAccess(); decimal count = LibSysUtils.ToDecimal((dataAccess.ExecuteScalar("select count(*) from AXPPURCHASESPEC"))); if (count == 0) { dataAccess.ExecuteNonQuery("insert into AXPPURCHASESPEC(PURCHASERID,PURCHASERNAME,MAXUSERCOUNT,MAXWORKSTATIONCOUNT) values('ax','ax',1000,-1)"); } bool existsINTERNALID = false; LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("axp.User"); if (sqlModel != null && sqlModel.Tables.Count > 0 && sqlModel.Tables[0].Columns.Contains("INTERNALID")) { existsINTERNALID = true; } string userId = LibSysUtils.ToString(dataAccess.ExecuteScalar("select USERID from AXPUSER where USERID='admin'")); if (string.IsNullOrEmpty(userId)) { //考虑默认账户 使用admin if (existsINTERNALID == false) { dataAccess.ExecuteNonQuery("insert into AXPUSER(USERID,USERPASSWORD,ISUSE) values('admin','admin',1)"); } else { //如果AXPUser不再是Grid数据,则会有内码字段 dataAccess.ExecuteNonQuery("insert into AXPUSER(USERID,USERPASSWORD,ISUSE,INTERNALID,CREATORID,CURRENTSTATE) values('admin','admin',1,'" + Guid.NewGuid().ToString() + "','(NotSet)',2)"); } } if (existsINTERNALID) { // 升级时如果发现系统账户(axp.User)的数据表存在内码字段(即类型已修改为主数据),则需要修改所有内码为空的账户信息,为其生成新的Guid if (dataAccess.DatabaseType == LibDatabaseType.SqlServer) { dataAccess.ExecuteNonQuery("update AXPUSER set INTERNALID = NEWID(),CURRENTSTATE = 2 where INTERNALID=''"); } else if (dataAccess.DatabaseType == LibDatabaseType.Oracle) { dataAccess.ExecuteNonQuery("update AXPUSER set INTERNALID = sys_guid(),CURRENTSTATE = 2 where INTERNALID=''"); } } }
private void SaveSqlModel(string name, DataSet dataSet) { string preFix = name.Substring(0, name.IndexOf('.')); string path = Path.Combine(EnvProvider.Default.MainPath, "SqlModel", preFix); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } LibSqlModel libDataSet = new LibSqlModel(); libDataSet.CloneDataSet(dataSet); using (FileStream fs = new FileStream(Path.Combine(path, string.Format("{0}.bin", name)), FileMode.Create, FileAccess.Write)) { LibBinaryFormatter formatter = new LibBinaryFormatter(); formatter.Serialize(fs, libDataSet); } }
public LibSqlModel GetSqlModel(string name) { #region 序列化 byte[] mybyte = Default.StringGetBytes(name); LibSqlModel dataSet = null; LibBinaryFormatter formatter = new LibBinaryFormatter(); if (mybyte != null && mybyte.Length != 0) { MemoryStream stream = new MemoryStream(mybyte); stream.Position = 0; dataSet = (LibSqlModel)formatter.Deserialize(stream); } #endregion if (dataSet == null || mybyte == null) { object lockItem = lockObjDic.GetOrAdd(name, new object()); lock (lockItem) { string preFix = name.Substring(0, name.IndexOf('.')); string path = Path.Combine(EnvProvider.Default.MainPath, "SqlModel", preFix, string.Format("{0}.bin", name)); if (File.Exists(path)) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { dataSet = (LibSqlModel)formatter.Deserialize(fs); fs.Position = 0; BinaryReader br = new BinaryReader(fs); byte[] bytes = br.ReadBytes((int)br.BaseStream.Length); br.Close(); Default.StringSetBytes(name, bytes, new TimeSpan(0, 30, 0)); } } } } return(dataSet); }
public string MoveUserPicture(string progId, string internalId, string fileName) { string path = Path.Combine(EnvProvider.Default.RuningPath, "UserPicture", progId, internalId); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string orgFilePath = Path.Combine(EnvProvider.Default.RuningPath, "UserPicture", fileName); DirectoryInfo info = new DirectoryInfo(path); FileInfo[] files = info.GetFiles(); foreach (var item in files) { item.Delete(); } File.Move(orgFilePath, Path.Combine(path, fileName)); LibDataAccess dataAccess = new LibDataAccess(); LibSqlModel model = LibSqlModelCache.Default.GetSqlModel(progId); dataAccess.ExecuteNonQuery(string.Format("update {0} set IMGSRC={1} where INTERNALID={2}", model.Tables[0].TableName, LibStringBuilder.GetQuotString(fileName), LibStringBuilder.GetQuotString(internalId))); return(fileName); }
/// <summary> /// 根据单据操作类型和发送人列表获取推送目标 /// </summary> /// <param name="billAction">表单操作类型</param> /// <param name="send">主要发送到的PERSONID</param> /// <param name="to">发送到的PERSONID列表</param> /// <param name="cc">抄送的人员PERSONID列表</param> /// <returns></returns> public static List <PushTarget> GetPushTarget(BillAction billAction, string send, IList <string> to, IList <string> cc) { //检查是否具有 AXPUSERAPP数据表 LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("axp.User"); bool hasAXPUSERAPP = false; if (sqlModel != null && sqlModel.Tables.Count > 1 && sqlModel.Tables[1].TableName.Equals("AXPUSERAPP")) { hasAXPUSERAPP = true; } if (hasAXPUSERAPP == false) { return(null);//如果没有需要的相关字段则直接返回 } // 查找支持指定BillAction的AppType类型 List <AppType> listType = AppTypeBillActionConfig.Instance.QueryCan(billAction); string listTypeStr = string.Empty; if (listType == null || listType.Count == 0) { return(null); } List <int> listTypeInt = new List <int>(); listType.ForEach(type => { listTypeInt.Add((int)type); }); listTypeStr = string.Join(",", listTypeInt); List <PushTarget> targetList = new List <PushTarget>(); StringBuilder builder = new StringBuilder(); if (!string.IsNullOrEmpty(send)) { builder.AppendFormat("C.PERSONID={0} OR ", LibStringBuilder.GetQuotString(send)); } if (to != null) { foreach (string item in to) { builder.AppendFormat("C.PERSONID={0} OR ", LibStringBuilder.GetQuotString(item)); } } if (cc != null) { foreach (string item in cc) { builder.AppendFormat("C.PERSONID={0} OR ", LibStringBuilder.GetQuotString(item)); } } if (builder.Length > 0) { builder.Remove(builder.Length - 3, 3); string sql = string.Format("select distinct A.CLIENTTYPE,A.CLIENTID from AXPUSERAPP A " + " left join AXPUSER B on A.USERID = B.USERID " + " left join COMPERSON C on B.PERSONID = C.PERSONID " + " where ( {0} ) and A.CLIENTTYPE in ({1})", builder.ToString(), listTypeStr); LibDataAccess dataAccess = new LibDataAccess(); using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { while (reader.Read()) { int appType = LibSysUtils.ToInt32(reader[0]); string clientId = LibSysUtils.ToString(reader[1]); if (string.IsNullOrEmpty(clientId) == false) { targetList.Add(new PushTarget() { AppType = appType, ClientId = clientId }); } } } } return(targetList); }
public object GetValueByName(string progId, object[] pks, string name) { object value = null; string key = BuildCacheKey(progId, pks); Dictionary <string, object> destObj = this.Get <Dictionary <string, object> >(key); if (destObj == null) { destObj = new Dictionary <string, object>(); LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel(progId); DataColumnCollection columns = sqlModel.Tables[0].Columns; //说明缓存不存在则需创建 StringBuilder whereBuilder = new StringBuilder(); for (int i = 0; i < sqlModel.Tables[0].PrimaryKey.Length; i++) { if (i != 0) { whereBuilder.AppendFormat(" AND "); } if (pks[i].GetType() == typeof(string)) { whereBuilder.AppendFormat("A.{0}={1}", sqlModel.Tables[0].PrimaryKey[i].ColumnName, LibStringBuilder.GetQuotObject(pks[i])); } else { whereBuilder.AppendFormat("A.{0}={1}", sqlModel.Tables[0].PrimaryKey[i].ColumnName, pks[i]); } } SqlBuilder sqlBuilder = new SqlBuilder(progId); string sql = sqlBuilder.GetQuerySql(0, "A.*", whereBuilder.ToString()); //TODO固定字段应排除 LibDataAccess dataAccess = new LibDataAccess(); using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { if (reader.Read()) { int count = reader.FieldCount; for (int i = 0; i < count; i++) { string columnName = reader.GetName(i); object columnValue = reader.GetValue(i); if (dataAccess.DatabaseType == LibDatabaseType.Oracle && columnValue.GetType() == typeof(decimal)) { //如果是oracle 数值类型都是number LibDataType dataType = (LibDataType)((int)columns[columnName].ExtendedProperties[FieldProperty.DataType]); switch (dataType) { case LibDataType.Int32: columnValue = decimal.ToInt32((decimal)columnValue); break; case LibDataType.Int64: columnValue = decimal.ToInt64((decimal)columnValue); break; case LibDataType.Float: columnValue = decimal.ToSingle((decimal)columnValue); break; case LibDataType.Double: columnValue = decimal.ToDouble((decimal)columnValue); break; case LibDataType.Byte: columnValue = decimal.ToByte((decimal)columnValue); break; case LibDataType.Boolean: columnValue = (decimal)columnValue == decimal.Zero ? false : true; break; } } destObj.Add(columnName, columnValue); } } } if (destObj.Count > 0) { //CacheItemPolicy policy = new CacheItemPolicy(); //policy.SlidingExpiration = new TimeSpan(0, 180, 0); //30分钟内不访问自动剔除 _Default.Set(key, destObj, new TimeSpan(0, 180, 0)); } } destObj.TryGetValue(name, out value); return(value); }
public LoginInfo AppLogin(string userId, string password, string clientId, int clientType, bool quitOther = false) { LoginInfo loginInfo = new LoginInfo(); //检查是否具有 AXPUSERAPP数据表,用于判定是否支持移动端App登录 LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("axp.User"); bool hasAXPUSERAPP = false; if (sqlModel != null && sqlModel.Tables.Count > 1 && sqlModel.Tables[1].TableName.Equals("AXPUSERAPP")) { hasAXPUSERAPP = true; } if (hasAXPUSERAPP == false) { return(loginInfo);//如果没有需要的相关字段则直接返回 } SqlBuilder builder = new SqlBuilder("axp.User"); string sql = string.Format(@"SELECT A.PERSONID, A.ROLEID, A.WALLPAPER,A.WALLPAPERSTRETCH,B.PERSONNAME,B.PHONENO,B.CORNET,B.HEADPORTRAIT,B.MAIL FROM AXPUSER A LEFT JOIN COMPERSON B ON B.PERSONID=A.PERSONID WHERE A.USERID={0} and A.USERPASSWORD={1} AND A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password)); //builder.GetQuerySql(0, "A.PERSONID,A.PERSONNAME,A.PHONENO,A.CORNET,A.HEADPORTRAIT,A.MAIL,A.ROLEID,A.WALLPAPER,A.WALLPAPERSTRETCH", string.Format("A.USERID={0} And A.USERPASSWORD={1} And A.ISUSE=1", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(password))); LibDataAccess dataAccess = new LibDataAccess(); string roleId = string.Empty; bool exists = false; using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { if (reader.Read()) { loginInfo.PersonId = LibSysUtils.ToString(reader["PERSONID"]); loginInfo.PersonName = LibSysUtils.ToString(reader["PERSONNAME"]); roleId = LibSysUtils.ToString(reader["ROLEID"]); loginInfo.Wallpaper = LibSysUtils.ToString(reader["WALLPAPER"]); loginInfo.Stretch = LibSysUtils.ToBoolean(reader["WALLPAPERSTRETCH"]); //20170214 施卢威 增加头像 Email 短号信息 loginInfo.Headportrait = LibSysUtils.ToString(reader["HEADPORTRAIT"]); loginInfo.UserEMail = LibSysUtils.ToString(reader["MAIL"]); loginInfo.Cornet = LibSysUtils.ToString(reader["CORNET"]); loginInfo.UserPhone = LibSysUtils.ToString(reader["PHONENO"]); exists = true; } } if (exists) { #region 帐号与登录设备关联 string appSql = string.Empty; //查询帐号是否已有设备标识 int isAPPClient = LibSysUtils.ToInt32(dataAccess.ExecuteScalar(string.Format("SELECT COUNT(*) from AXPUSERAPP WHERE USERID = '{0}' and CLIENTTYPE={1}", userId, clientType))); if (isAPPClient > 0) { //更新设备标识信息 appSql = string.Format("UPDATE AXPUSERAPP SET CLIENTID={1} WHERE USERID={0} AND CLIENTTYPE={2}", LibStringBuilder.GetQuotString(userId), LibStringBuilder.GetQuotString(clientId), clientType); } else { int curMaxRowId = LibSysUtils.ToInt32(dataAccess.ExecuteScalar(string.Format("SELECT Max(ROW_ID) from AXPUSERAPP WHERE USERID='{0}'", userId))); //插入账户对应的App设备标识信息。 appSql = string.Format("insert into AXPUSERAPP(USERID,ROW_ID,ROWNO,CLIENTTYPE,CLIENTID) values('{0}',{1},{2},{3},'{4}')", userId, curMaxRowId + 1, curMaxRowId + 1, clientType, clientId, 1); } dataAccess.ExecuteNonQuery(appSql); #endregion LibHandle handle = LibHandleCache.Default.IsExistsHandle(LibHandeleType.PC, userId); if (handle != null) { if (quitOther) { LibHandleCache.Default.RemoveHandle(handle.Handle); } else { loginInfo.IsUsed = true; } } if (!loginInfo.IsUsed) { long currentCount = LibHandleCache.Default.GetCount(); long maxUserCount = (long)LibHandleCache.Default.MaxUserCount; if (maxUserCount != -1 && maxUserCount < currentCount) { loginInfo.IsOverUser = true; } else { string loginIp = string.Empty; //Zhangkj20161219 增加LoginIp System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current; //对于非WCF的访问context为null if (context != null) { System.ServiceModel.Channels.MessageProperties properties = context.IncomingMessageProperties; System.ServiceModel.Channels.RemoteEndpointMessageProperty endpoint = properties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty; loginIp = endpoint.Address + ":" + endpoint.Port.ToString(); handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId, loginIp); } else { handle = LibHandleCache.Default.GetHandle(string.Empty, LibHandeleType.PC, userId, loginInfo.PersonId, loginInfo.PersonName, roleId); } //创建新的Handle if (handle != null) { loginInfo.Handle = handle.Handle; } } } } return(loginInfo); }
public IList <FuzzyResult> FuzzySearchField(int tableIndex, string fieldName, string relSource, string relName, string query, object[] curPks = null, Dictionary <string, object> selConditionParam = null, string[] currentPks = null) { IList <FuzzyResult> list = new List <FuzzyResult>(); RelativeSourceCollection relSources = (RelativeSourceCollection)this.DataSet.Tables[tableIndex].Columns[fieldName].ExtendedProperties[FieldProperty.RelativeSource]; RelativeSource curRelSource = null; foreach (RelativeSource item in relSources) { if (string.Compare(relSource, item.RelSource, true) == 0) { curRelSource = item; break; } } if (curRelSource == null) { return(list); } SqlBuilder sqlBuilder = new SqlBuilder(relSource); StringBuilder builder = new StringBuilder(); LibBcfBase bcfBase = LibBcfSystem.Default.GetBcfInstance(relSource); BillType billType = bcfBase.Template.BillType; if (relSource.Split(new string[] { "axp" }, StringSplitOptions.None).Length == 1 && (billType == BillType.Bill || billType == BillType.Master)) { builder.AppendFormat("And A.CURRENTSTATE=2"); } if (curPks != null && curPks.Length > 0) { builder.AppendFormat(" And {0}", GetRelWhere(relSource, curRelSource.TableIndex, 'A', curPks)); } string selCondition = string.Empty; if (curRelSource.SelConditions.Count > 0) { foreach (SelCondition item in curRelSource.SelConditions) { builder.AppendFormat(" And {0}", item.Condition); } selCondition = builder.ToString(); selCondition = selCondition.Replace("CURRENT_PERSON", LibStringBuilder.GetQuotObject(this.Handle.PersonId)); if (selConditionParam != null && selConditionParam.Count > 0) { LibSqlModel model = LibSqlModelCache.Default.GetSqlModel(this.ProgId); if (model != null) { foreach (KeyValuePair <string, object> item in selConditionParam) { string[] temp = item.Key.Split('.'); int index = (int)temp[0][0] - (int)'A'; DataColumn col = model.Tables[index].Columns[temp[1]]; LibDataType dataType = (LibDataType)col.ExtendedProperties[FieldProperty.DataType]; if (dataType == LibDataType.Text) { selCondition = selCondition.Replace(string.Format("@{0}", item.Key), LibStringBuilder.GetQuotObject(item.Value)); } else { selCondition = selCondition.Replace(string.Format("@{0}", item.Key), item.Value.ToString()); } } } } } else { selCondition = builder.ToString(); } string powerStr = LibPermissionControl.Default.GetShowCondition(this.Handle, relSource, this.Handle.PersonId); if (!string.IsNullOrEmpty(powerStr)) { selCondition = string.Format("{0} and {1}", selCondition, powerStr); } if (curRelSource.ContainsSub == false && string.IsNullOrEmpty(curRelSource.ParentColumnName) == false && currentPks != null && currentPks.Length > 0 && string.IsNullOrEmpty(currentPks[0]) == false) { //对于父子结构数据,如果不包含子数据且指定了父列外键列的名称,则添加额外的查询条件 Zhangkj 20170316 DataColumn keyColumn = this.DataSet.Tables[tableIndex].PrimaryKey[0]; string keyColumnName = this.DataSet.Tables[tableIndex].PrimaryKey[0].ColumnName;//目前仅支持单主键 string dataId = currentPks[0]; LibDataType dataType = keyColumn.ExtendedProperties.ContainsKey(FieldProperty.DataType) ? (LibDataType)keyColumn.ExtendedProperties[FieldProperty.DataType] : LibDataTypeConverter.ConvertToLibType(keyColumn.DataType); List <object> subIds = this.GetSubDataIds(dataType, dataId, this.DataSet.Tables[tableIndex].TableName, keyColumnName, curRelSource.ParentColumnName, true); if (subIds != null && subIds.Count > 0) { bool needQuot = dataType == LibDataType.Text || dataType == LibDataType.NText; List <object> quotSubIds = new List <object>(); foreach (object obj in subIds) { quotSubIds.Add((needQuot) ? LibStringBuilder.GetQuotObject(obj) : obj); } selCondition = string.Format("{0} and A.{1} not in ({2})", selCondition, keyColumnName, string.Join(",", quotSubIds)); } } string sql = sqlBuilder.GetFuzzySql(curRelSource.TableIndex, relSources, query, selCondition, curRelSource.ParentColumnName); LibDataAccess dataAccess = new LibDataAccess(); int count = 0; int filterCount = curRelSource.SearchFilterCount; using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { while (reader.Read()) { if (reader.FieldCount == 1) { list.Add(new FuzzyResult(LibSysUtils.ToString(reader[0]), string.Empty)); } else if (reader.FieldCount == 2) { list.Add(new FuzzyResult(LibSysUtils.ToString(reader[0]), LibSysUtils.ToString(reader[1]))); } else if (reader.FieldCount == 3) { FuzzyResult fuzzyResult = new FuzzyResult(LibSysUtils.ToString(reader[0]), LibSysUtils.ToString(reader[1])); fuzzyResult.ContainsKeyField = LibSysUtils.ToString(reader[2]);//将除Id Name列以外的包含查询关键字的列的内容 list.Add(fuzzyResult); } else if (reader.FieldCount == 4) { FuzzyResult fuzzyResult = new FuzzyResult(LibSysUtils.ToString(reader[0]), LibSysUtils.ToString(reader[1])); fuzzyResult.ContainsKeyField = LibSysUtils.ToString(reader[2]); //将除Id Name列以外的包含查询关键字的列的内容 fuzzyResult.ParentId = LibSysUtils.ToString(reader[3]); //树形结构的父数据Id if (curRelSource.ExpandAll) { fuzzyResult.TreeNodeExpanded = true; } list.Add(fuzzyResult); } count++; if (count == filterCount) { break; } } } if (list.Count > 1) { LibControlType controlType = (LibControlType)this.DataSet.Tables[tableIndex].Columns[fieldName].ExtendedProperties[FieldProperty.ControlType]; if (controlType == LibControlType.IdNameTree && string.IsNullOrEmpty(curRelSource.ParentColumnName) == false) { //处理树形结构数据 List <FuzzyResult> newList = list.ToList();//先全部放入 List <FuzzyResult> tempList = null; using (MemoryStream stream = new MemoryStream()) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); formatter.Serialize(stream, list.ToList()); stream.Position = 0; tempList = formatter.Deserialize(stream) as List <FuzzyResult>;//深度复制一份 } //查找是其他节点的子节点的进行处理 int index = 0; while (index < list.Count) { FuzzyResult child = list[index]; FuzzyResult parent = (from re in list where re != null && re.Id.Equals(child.ParentId) select re).FirstOrDefault(); if (parent != default(FuzzyResult)) { newList.Remove(child); parent.Children.Add(child); } index++; } newList[0].TotalList = tempList; list = newList; } } return(list); }
/// <summary> /// 是否包含指定功能模块、指定数据表、指定数据列 /// </summary> /// <param name="progId"></param> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <returns></returns> public bool Contains(string progId, string tableName = "", string columnName = "") { if (string.IsNullOrEmpty(progId)) { return(false); } if (string.IsNullOrEmpty(tableName) && string.IsNullOrEmpty(columnName) == false) { return(false);//指定了列名未指定表名,直接返回true } bool stepContains = true; LibSqlModel sqlModel = null; lock (_dicContainsLock) { if (_DicContainsProg.ContainsKey(progId) == false) { sqlModel = GetSqlModel(progId); if (sqlModel == null) { _DicContainsProg[progId] = false; } else { _DicContainsProg[progId] = true; } } stepContains = _DicContainsProg[progId]; if (string.IsNullOrEmpty(tableName) == false && stepContains) { string key = string.Format("{0}_{1}", progId, tableName); if (_DicContainsProgTable.ContainsKey(key) == false) { sqlModel = GetSqlModel(progId); if (sqlModel == null || sqlModel.Tables.Contains(tableName) == false) { _DicContainsProgTable[key] = false; } else { _DicContainsProgTable[key] = true; } } stepContains = _DicContainsProgTable[key]; if (string.IsNullOrEmpty(columnName) == false && stepContains) { key = string.Format("{0}_{1}_{2}", progId, tableName, columnName); if (_DicContainsProgTableColumn.ContainsKey(key) == false) { sqlModel = GetSqlModel(progId); if (sqlModel == null || sqlModel.Tables.Contains(tableName) == false || sqlModel.Tables[tableName].Columns.Contains(columnName) == false) { _DicContainsProgTableColumn[key] = false; } else { _DicContainsProgTableColumn[key] = true; } } stepContains = _DicContainsProgTableColumn[key]; } } } return(stepContains); }
/// <summary> /// 根据信息发送参数中的收件人、抄送人等获取各用户对应手机号 /// </summary> /// <param name="sendMailParam">消息参数</param> /// <param name="weixinList">人员Id对应的微信号列表,如果人员表没有微信号字段,或者微信号字段为空,则使用手机号</param> /// <returns></returns> private static List <string> GetSendPhoneList(LibMailParam sendMailParam, out List <string> weixinList) { List <string> personIdList = new List <string>(); List <string> phoneList = new List <string>(); weixinList = new List <string>(); if (sendMailParam == null) { return(phoneList); } if (string.IsNullOrEmpty(sendMailParam.PersonId) == false && personIdList.Contains(sendMailParam.PersonId) == false) { personIdList.Add(sendMailParam.PersonId); } if (sendMailParam.To != null) { foreach (string per in sendMailParam.To) { if (personIdList.Contains(per) == false && personIdList.Contains(per) == false) { personIdList.Add(per); } } } if (sendMailParam.CC != null) { foreach (string per in sendMailParam.CC) { if (personIdList.Contains(per) == false && personIdList.Contains(per) == false) { personIdList.Add(per); } } } if (personIdList.Count == 0) { return(phoneList); } StringBuilder builder = new StringBuilder(); personIdList.ForEach(personId => { builder.AppendFormat("{0},", LibStringBuilder.GetQuotString(personId)); }); if (builder.Length > 0) { builder.Remove(builder.Length - 1, 1); bool existsWeixin = false; LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("com.Person"); if (sqlModel != null && sqlModel.Tables.Count > 0 && sqlModel.Tables[0].Columns.Contains("WECHAT")) { existsWeixin = true; } LibDataAccess dataAccess = new LibDataAccess(); string sql = string.Empty; if (existsWeixin) { sql = string.Format("select PHONENO,WECHAT from COMPERSON " + " where PERSONID in ({0})", builder.ToString()); using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { while (reader.Read()) { string phoneNo = LibSysUtils.ToString(reader[0]); string weixin = LibSysUtils.ToString(reader[1]); if (string.IsNullOrEmpty(phoneNo) == false) { phoneList.Add(phoneNo); if (string.IsNullOrEmpty(weixin) == false) { weixinList.Add(weixin); } else { weixinList.Add(phoneNo); } } else { if (string.IsNullOrEmpty(weixin) == false) { weixinList.Add(weixin); } } } } } else { sql = string.Format("select PHONENO from COMPERSON " + " where PERSONID in ({0})", builder.ToString()); using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { while (reader.Read()) { string phoneNo = LibSysUtils.ToString(reader[0]); if (string.IsNullOrEmpty(phoneNo) == false) { phoneList.Add(phoneNo); weixinList.Add(phoneNo); } } } } } return(phoneList); }
public LibApproveFlow GetCacheItem(string progId, bool isApproveRow = false) { string key = isApproveRow ? string.Format("{0}_Row", progId) : progId; LibApproveFlow value = this.Get <LibApproveFlow>(key); if (value == null) { //检查审核过程(Sub表)中是否有DutyId字段,如有则说明是数据库表是新的 bool isExistDuty = false; LibSqlModel sqlModel = LibSqlModelCache.Default.GetSqlModel("axp.ApproveFlow"); if (sqlModel != null && sqlModel.Tables.Count > 2 && sqlModel.Tables[2].Columns.Contains("DUTYID")) { isExistDuty = true; } LibDataAccess dataAccess = new LibDataAccess(); if (isExistDuty == false) { string sql = string.Format("Select D.USECONDITION,A.FLOWLEVEL,A.PERSONID,C.PERSONNAME,C.POSITION,A.INDEPENDENT,A.ROWNO " + " From AXPAPPROVEFLOWSUB A inner join AXPAPPROVEFLOW B on B.APPROVEFLOWID=A.APPROVEFLOWID " + " inner join AXPAPPROVEFLOWDETAIL D on D.APPROVEFLOWID=A.APPROVEFLOWID and D.ROW_ID=A.PARENTROWID " + " left join COMPERSON C on C.PERSONID=A.PERSONID Where B.PROGID={0} and B.ISAPPROVEROW={1}", LibStringBuilder.GetQuotString(progId), isApproveRow ? 1 : 0); using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { while (reader.Read()) { if (value == null) { value = new LibApproveFlow(); } string useCondition = LibSysUtils.ToString(reader["USECONDITION"]); int flowLevel = LibSysUtils.ToInt32(reader["FLOWLEVEL"]); string personId = LibSysUtils.ToString(reader["PERSONID"]); string personName = LibSysUtils.ToString(reader["PERSONNAME"]); string position = LibSysUtils.ToString(reader["POSITION"]); bool independent = LibSysUtils.ToBoolean(reader["INDEPENDENT"]); int subRowNO = LibSysUtils.ToInt32(reader["ROWNO"]); if (!value.ApproveFlowList.ContainsKey(useCondition)) { value.ApproveFlowList.Add(useCondition, new LibApproveFlowItem()); } LibApproveFlowItem flowItem = value.ApproveFlowList[useCondition]; flowItem.UseCondition = useCondition; if (!flowItem.FlowInfoDic.ContainsKey(flowLevel)) { flowItem.FlowInfoDic.Add(flowLevel, new List <LibApproveFlowInfo>()); } List <LibApproveFlowInfo> flowInfoList = flowItem.FlowInfoDic[flowLevel]; flowInfoList.Add(new LibApproveFlowInfo() { PersonId = personId, PersonName = personName, Position = position, Independent = independent, FlowLevel = flowLevel, FlowProcRowNo = subRowNO }); } } } else { //审核配置表中包含了岗位相关字段,则多查找相关字段的信息 Zhangkj 20170323 string sql = string.Format("Select D.USECONDITION,A.FLOWLEVEL,A.PERSONID,C.PERSONNAME,C.POSITION,A.INDEPENDENT,A.ROWNO, " + " B.CANEDITWHENDOING,B.CANEDITWHENDONE,B.CANDELETEWHENDONE," + //主表增加的审核中和审核通过后的是否可编辑删除配置项 " D.SORTORDER," + //审核流程从表中增加的排序号 " A.DEPTID,F.DEPTNAME,A.DEPTIDCOLUMN,A.DUTYID,E.DUTYNAME,E.DUTYLEVEL,A.ISDUTYUP,A.ISDEPTUP,A.CANJUMP,A.NOTSELF,A.MUSTHIGHLEVEL,A.ISSAMEDEFAULT " + //Sub中增加的部门、岗位、及相关配置项字段 " From AXPAPPROVEFLOWSUB A inner join AXPAPPROVEFLOW B on B.APPROVEFLOWID=A.APPROVEFLOWID " + " inner join AXPAPPROVEFLOWDETAIL D on D.APPROVEFLOWID=A.APPROVEFLOWID and D.ROW_ID=A.PARENTROWID " + " left join COMPERSON C on C.PERSONID=A.PERSONID " + " left join COMDUTY E on A.DUTYID=E.DUTYID " + //职务表 " left join COMDEPT F on A.DEPTID=F.DEPTID " + //部门表 " Where B.PROGID={0} and B.ISAPPROVEROW={1}", LibStringBuilder.GetQuotString(progId), isApproveRow ? 1 : 0); using (IDataReader reader = dataAccess.ExecuteDataReader(sql)) { while (reader.Read()) { if (value == null) { value = new LibApproveFlow(); } string useCondition = LibSysUtils.ToString(reader["USECONDITION"]); int flowLevel = LibSysUtils.ToInt32(reader["FLOWLEVEL"]); string personId = LibSysUtils.ToString(reader["PERSONID"]); string personName = LibSysUtils.ToString(reader["PERSONNAME"]); string position = LibSysUtils.ToString(reader["POSITION"]); bool independent = LibSysUtils.ToBoolean(reader["INDEPENDENT"]); int subRowNO = LibSysUtils.ToInt32(reader["ROWNO"]); bool canEditWhenDoing = LibSysUtils.ToBoolean(reader["CANEDITWHENDOING"]); bool canEditWhenDone = LibSysUtils.ToBoolean(reader["CANEDITWHENDONE"]); bool canDeleteWhenDone = LibSysUtils.ToBoolean(reader["CANDELETEWHENDONE"]); int sortOrder = LibSysUtils.ToInt32(reader["SORTORDER"]); string deptId = LibSysUtils.ToString(reader["DEPTID"]); string deptName = LibSysUtils.ToString(reader["DEPTNAME"]); string deptIdColumn = LibSysUtils.ToString(reader["DEPTIDCOLUMN"]); string dutyId = LibSysUtils.ToString(reader["DUTYID"]); string dutyName = LibSysUtils.ToString(reader["DUTYNAME"]); int dutyLevel = LibSysUtils.ToInt32(reader["DUTYLEVEL"]); bool isDutyUp = LibSysUtils.ToBoolean(reader["ISDUTYUP"]); bool isDeptUp = LibSysUtils.ToBoolean(reader["ISDEPTUP"]); bool canJump = LibSysUtils.ToBoolean(reader["CANJUMP"]); bool netSelf = LibSysUtils.ToBoolean(reader["NOTSELF"]); bool mustHighLevel = LibSysUtils.ToBoolean(reader["MUSTHIGHLEVEL"]); bool isSameDefalut = LibSysUtils.ToBoolean(reader["ISSAMEDEFAULT"]); value.CanEditWhenDoing = canEditWhenDoing; value.CanEditWhenDone = canEditWhenDone; value.CanDeleteWhenDone = canDeleteWhenDone; if (!value.ApproveFlowList.ContainsKey(useCondition)) { value.ApproveFlowList.Add(useCondition, new LibApproveFlowItem()); } LibApproveFlowItem flowItem = value.ApproveFlowList[useCondition]; flowItem.SortOrder = sortOrder; flowItem.UseCondition = useCondition; if (!flowItem.FlowInfoDic.ContainsKey(flowLevel)) { flowItem.FlowInfoDic.Add(flowLevel, new List <LibApproveFlowInfo>()); } List <LibApproveFlowInfo> flowInfoList = flowItem.FlowInfoDic[flowLevel]; flowInfoList.Add(new LibApproveFlowInfo() { PersonId = personId, PersonName = personName, Position = position, Independent = independent, FlowLevel = flowLevel, FlowProcRowNo = subRowNO, DeptId = deptId, DeptName = deptName, DeptIdColumn = deptIdColumn, DutyId = dutyId, DutyName = dutyName, DutyLevel = dutyLevel, IsDutyUp = isDutyUp, IsDeptUp = isDutyUp, CanJump = canJump, NotSelf = netSelf, MustHighLevel = mustHighLevel, IsSameDefault = isSameDefalut, ExecuteDesc = (string.IsNullOrEmpty(deptIdColumn) ? "" : "动态字段:" + deptIdColumn) //初始执行信息的提示 }); } } } if (value != null && value.ApproveFlowList.Count > 0) { //对审核流程按序号从小到大排序 Zhangkj 20170323 List <LibApproveFlowItem> list = (from item in value.ApproveFlowList.Values orderby item.SortOrder ascending select item).ToList(); value.ApproveFlowList = new Dictionary <string, LibApproveFlowItem>(); for (int i = 0; i < list.Count; i++) { if (value.ApproveFlowList.ContainsKey(list[i].UseCondition) == false) { value.ApproveFlowList.Add(list[i].UseCondition, list[i]); } else { //正常情况下不会有相同的使用条件(配置时已约束),如果有,则替换掉 value.ApproveFlowList[list[i].UseCondition] = list[i]; } } //180分钟内不访问自动剔除 this.Set(key, value, new TimeSpan(0, 180, 0)); } } return(value); }