private Business.Registration CopyConfig(Business.Configuration itemConfig, Business.RegistrationList list, bool global) { Business.Role itemRole = itemConfig.FindRole(list.CurrentRoles); if (itemRole == null) { return(null); } Business.Registration itemReg = new Business.Registration(list.CurrentUser.UserID); itemReg.Identifier = itemConfig.Identifier; itemReg.IsGlobal = global; foreach (CarrierType soll in itemRole.CarrierTypes) { Business.Carrier itemCarr = new Business.Carrier(itemReg.Carriers); itemCarr.Type = soll; itemCarr.Availably = list.CurrentUser.Carriers.Item(soll).IsValid; itemReg.Carriers.Add(itemCarr); } foreach (Business.ObjType itemObjectType in itemConfig.ObjTypes) { Business.ObjType objType = new Business.ObjType(itemReg.ObjectTypeList, itemObjectType.Identifier); if (!itemConfig.IsObjectTypeAvailably(itemObjectType.Identifier, global)) { objType.Availably = false; } /*else if (!global && objectType.IndexOf(string.Format(",{0},", (int)itemObjectType.Identifier)) == -1) * objType.Availably = false;*/ itemReg.ObjectTypeList.Add(objType); } itemReg.ObjectTypeList.SetChecked(itemReg.ObjectTypeList.GetChecked()); return(itemReg); }
public void Load(bool useConfig, Business.RegistrationList list, Guid currentUserID, Guid?objectID, Guid?userID, Guid?communityID, int[] objectTypes, List <Business.TagWord> tagWords, bool global) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("SELECT * "); sb.AppendFormat("FROM hitbl_Notification_RegisteredEvent_NRE "); sb.AppendFormat("WHERE "); sb.AppendFormat("NUS_USR_ID = '{0}' ", currentUserID); sb.AppendFormat("AND NRE_IsGlobal = {0} ", global ? 1 : 0); if (objectID.HasValue) { sb.AppendFormat("AND NRE_ObjectID = '{0}' ", objectID); } if (userID.HasValue) { sb.AppendFormat("AND NRE_UserID = '{0}' ", userID); } if (communityID.HasValue) { sb.AppendFormat("AND NRE_CommunityID = '{0}' ", communityID); } if (objectTypes != null && objectTypes.Length > 0) { sb.AppendFormat("AND ("); for (int i = 0; i < objectTypes.Length; i++) { sb.AppendFormat("({0} IN (SELECT OBJ_Type FROM hirel_Notification_Event_ObjectType_NEO WHERE hirel_Notification_Event_ObjectType_NEO.NRE_ID = hitbl_Notification_RegisteredEvent_NRE.NRE_ID)) ", (int)objectTypes[i]); if (i < objectTypes.Length - 1) { sb.AppendFormat("AND "); } } sb.AppendFormat(") "); } if (tagWords != null && tagWords.Count > 0) { sb.AppendFormat("AND ( 1=1 "); for (int tagGroupID = 1; tagGroupID < 4; tagGroupID++) { List <Business.TagWord> tagWordPerGroup = tagWords.FindAll(x => x.GroupID == tagGroupID); if (tagWordPerGroup.Count > 0) { for (int i = 0; i < tagWordPerGroup.Count; i++) { sb.AppendFormat("AND ('{0}' IN (SELECT TGW_ID FROM hirel_Notification_Event_TagLog_NET WHERE hirel_Notification_Event_TagLog_NET.NRE_ID = hitbl_Notification_RegisteredEvent_NRE.NRE_ID AND hirel_Notification_Event_TagLog_NET.NET_TagWordGroup = {1})) ", tagWordPerGroup[i].TagID, tagWordPerGroup[i].GroupID); } } else { sb.AppendFormat("AND (NOT EXISTS (SELECT TGW_ID FROM hirel_Notification_Event_TagLog_NET WHERE hirel_Notification_Event_TagLog_NET.NRE_ID = hitbl_Notification_RegisteredEvent_NRE.NRE_ID AND hirel_Notification_Event_TagLog_NET.NET_TagWordGroup = {0})) ", tagGroupID); } } sb.AppendFormat(") "); } sb.AppendFormat(" ORDER BY NRE_CommunityID, NRE_UserID, NRE_Identifier"); SqlConnection sqlConnection = new SqlConnection(connectionString); try { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = sqlConnection; sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = sb.ToString(); sqlConnection.Open(); SqlDataReader registrationItemSqlReader = sqlCommand.ExecuteReader(); while (registrationItemSqlReader.Read()) { Business.Registration item; if (useConfig) { EventIdentifier identifier = (EventIdentifier)Convert.ToInt32(registrationItemSqlReader["NRE_Identifier"]); item = list.GetItemByType(identifier); } else { Business.ConfigurationList listConfig = new Business.ConfigurationList(); // TODO: Load config in business logic listConfig.Load(list.RootFolder); EventIdentifier eventType = (EventIdentifier)Convert.ToInt32(registrationItemSqlReader["NRE_Identifier"]); item = CopyConfig(listConfig[eventType], list, (bool)registrationItemSqlReader["NRE_IsGlobal"]); list.Add(item); } FillObject(item, registrationItemSqlReader); } registrationItemSqlReader.Close(); foreach (Business.Registration item in list) { Business.Carrier objCarrier = item.Carriers.CheckedCarrier(); if (objCarrier != null && objCarrier.Type != CarrierType.None) { SqlCommand sqlCommand2 = new SqlCommand(); sqlCommand2.Connection = sqlConnection; sqlCommand2.CommandType = CommandType.Text; sqlCommand2.CommandText = string.Format("SELECT * FROM hirel_Notification_Event_ObjectType_NEO WHERE NRE_ID = '{0}'", item.ID); SqlDataReader objectTypesSqlReader = sqlCommand2.ExecuteReader(); item.ObjectTypeList.Clear(); while (objectTypesSqlReader.Read()) { FillObjectTypes(item, objectTypesSqlReader); } objectTypesSqlReader.Close(); SqlCommand sqlCommand3 = new SqlCommand(); sqlCommand3.Connection = sqlConnection; sqlCommand3.CommandType = CommandType.Text; sqlCommand3.CommandText = string.Format("SELECT * FROM hirel_Notification_Event_TagLog_NET WHERE NRE_ID = '{0}'", item.ID); SqlDataReader tagWordsSqlReader = sqlCommand3.ExecuteReader(); item.TagWords.Clear(); while (tagWordsSqlReader.Read()) { FillObjectTagWords(item, tagWordsSqlReader); } tagWordsSqlReader.Close(); } } } finally { if (sqlConnection != null && sqlConnection.State != ConnectionState.Closed) { sqlConnection.Close(); } } }