/// <summary> /// Add subgroup type record into collection /// </summary> /// <param name="subgroupInfo">object of DI6SubgroupTypeInfo</param> private void AddSubgroupTypeIntoCollection(DI6SubgroupTypeInfo subgroupTypeInfo) { if (!this.SubgroupCollection.ContainsKey(subgroupTypeInfo.Name)) { this.SubgroupCollection.Add(subgroupTypeInfo.Name, subgroupTypeInfo); } }
/// <summary> /// Returns the instance of SubgroupTypeInfo on the basis of Subgroup Nid /// </summary> /// <param name="subgroupTypeNid"></param> /// <returns></returns> public DI6SubgroupTypeInfo GetSubgroupTypeInfoByNid(int subgroupTypeNid) { DI6SubgroupTypeInfo RetVal = new DI6SubgroupTypeInfo(); string Query = string.Empty; DataTable Table; //get subgroup type info from source database try { if (subgroupTypeNid > 0) { Query = this.DBQueries.SubgroupTypes.GetSubgroupTypes(FilterFieldType.NId, subgroupTypeNid.ToString()); Table = this.DBConnection.ExecuteDataTable(Query); if (Table.Rows.Count > 0) { RetVal.Nid = subgroupTypeNid; RetVal.GID = Table.Rows[0][SubgroupTypes.SubgroupTypeGID].ToString(); RetVal.Name = Table.Rows[0][SubgroupTypes.SubgroupTypeName].ToString(); RetVal.Global = Convert.ToBoolean(Table.Rows[0][SubgroupTypes.SubgroupTypeGlobal]); RetVal.Order = Convert.ToInt32(Table.Rows[0][SubgroupTypes.SubgroupTypeOrder]); } } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// Check and create Subgroup Type record /// </summary> /// <param name="subgroupTypeInfo">object of DI6SubgroupTypeInfo </param> /// <returns>Nid</returns> public int CheckNCreateSubgroupType(DI6SubgroupTypeInfo subgroupTypeInfo) { int RetVal = 0; try { // check Subgroup type exists or not RetVal = this.CheckSubgroupTypeExists(subgroupTypeInfo); // if Subgroup type does not exist then create it. if (RetVal <= 0) { // insert subgroup if (this.InsertIntoDatabase(subgroupTypeInfo)) { RetVal = this.GetSubgroupTypeByName(subgroupTypeInfo.Name); } } // add Subgroup information into collection subgroupTypeInfo.Nid = RetVal; this.AddSubgroupTypeIntoCollection(subgroupTypeInfo); } catch (Exception) { RetVal = 0; } return(RetVal); }
/// <summary> /// To Import SubgroupType information from mapped subgroup type /// </summary> /// <param name="subgroupTypeInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="NidInTrgDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSubgroupTypeFrmMappedSubgroupType(DI6SubgroupTypeInfo subgroupTypeInfo, int NidInSourceDB, int NidInTrgDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; bool SkipRecord = false; try { // set RetVal to NidInTrgDB RetVal = NidInTrgDB; if (!SkipRecord) { //insert or update record if (RetVal > 0) { // update only if source item is global if (subgroupTypeInfo.Global) { try { // dont change the order into target database //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DALQueries.SubgroupTypes.Update.UpdateSubgroupTypeByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, subgroupTypeInfo.Name, subgroupTypeInfo.GID, subgroupTypeInfo.Global, this.GetSubgroupTypeInfoByNid(RetVal).Order, RetVal)); } catch (Exception) { RetVal = -1; } } } else { // get the last subgroup Type order and update order in source subgrouptype subgroupTypeInfo.Order = this.GetLastSubgroupTypeOrder() + 1; if (this.InsertIntoDatabase(subgroupTypeInfo)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// Check existance of Subgroup type first in collection Then In database /// </summary> /// <param name="subgroupInfo">object of DI6SubgroupTypeInfo</param> /// <returns> Nid</returns> private int CheckSubgroupTypeExists(DI6SubgroupTypeInfo subgroupTypeInfo) { int RetVal = 0; //Step 1: check subgroup type exists in collection RetVal = this.CheckSubgroupTypeInCollection(subgroupTypeInfo.Name); //Step 2: check it exists in database. if (RetVal <= 0) { RetVal = this.GetSubgroupTypeNid(subgroupTypeInfo.GID, subgroupTypeInfo.Name); } return(RetVal); }
/// <summary> /// Import Subgroup: by SubgroupGID and Name /// </summary> /// <param name="subgroupName"></param> /// <param name="subgroupGID"></param> /// <param name="subgroupType"></param> /// <param name="isGlobal"></param> /// <returns></returns> public int ImportSubgroup(string subgroupName, string subgroupGID, string subgroupTypeName, bool isGlobal) { int RetVal = -1; int NIDByName = 0; int SGTypeNIdInTargetDB = 0; bool SkipRecord = false; DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries); DI6SubgroupTypeInfo SourceSGTypeInfo = new DI6SubgroupTypeInfo(); DI6SubgroupInfo TargetSGInfo; DI6SubgroupInfo SubgroupInfoObj = new DI6SubgroupInfo(); try { SubgroupInfoObj.Name = subgroupName; SubgroupInfoObj.GID = subgroupGID; SubgroupInfoObj.Global = isGlobal; //check already exists in database or not //Get NId by Name if (!string.IsNullOrEmpty(SubgroupInfoObj.GID)) { //first check by gid and then by name RetVal = this.GetNidByGID(SubgroupInfoObj.GID); if (RetVal > 0) { // check for the duplicacy by name NIDByName = this.GetSubgroupByName(SubgroupInfoObj.Name); if (RetVal != NIDByName & NIDByName > 0) { //skip records SkipRecord = true; RetVal = -1; } } } //if GID is empty or GID doesnt match then get NId by name if (RetVal <= 0 & SkipRecord == false) { RetVal = this.GetSubgroupByName(SubgroupInfoObj.Name); } if (!SkipRecord) { //-- PreRequisite to Import SubgroupType First // get subgroupTypeInfo from source database SourceSGTypeInfo.Name = subgroupTypeName; SGTypeNIdInTargetDB = (new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries)).CheckNCreateSubgroupType(SourceSGTypeInfo); //insert or update subgroup record if (RetVal > 0) { // get target subgroup info TargetSGInfo = this.GetSubgroupInfo(FilterFieldType.NId, RetVal.ToString()); // Dont update if target is global and source is local if (!(SubgroupInfoObj.Global == false & TargetSGInfo.Global)) { try { //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DALQueries.Subgroup.Update.UpdateSubgroupByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, SubgroupInfoObj.Name, SubgroupInfoObj.GID, SubgroupInfoObj.Global, SGTypeNIdInTargetDB, RetVal)); } catch (Exception) { RetVal = -1; } } } else { // get the last subgroup Type order and update order in source subgrouptype SubgroupInfoObj.Type = SGTypeNIdInTargetDB; if (this.InsertIntoDatabase(SubgroupInfoObj)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// To Import Subgroup information from mapped subgroup /// </summary> /// <param name="subgroupInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="NidInTrgDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSubgroupFrmMappedSubgroup(DI6SubgroupInfo subgroupInfo, int NidInSourceDB, int NidInTrgDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; int SGTypeNIdInTargetDB = 0; bool SkipRecord = false; DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries); DI6SubgroupTypeInfo SourceSGTypeInfo = new DI6SubgroupTypeInfo(); DI6SubgroupInfo TargetSGInfo; try { // set RetVal to NidInTrgDB RetVal = NidInTrgDB; if (!SkipRecord) { // get subgroupTypeInfo from source database SourceSGTypeInfo = (new DI6SubgroupTypeBuilder(sourceDBConnection, sourceQurey)).GetSubgroupTypeInfoByNid(subgroupInfo.Type); // import SubgroupType SGTypeNIdInTargetDB = SGTypeBuilder.ImportSubgroupType(SourceSGTypeInfo, SourceSGTypeInfo.Nid, sourceQurey, sourceDBConnection); //insert or update subgroup record if (RetVal > 0) { // get target subgroup info TargetSGInfo = this.GetSubgroupInfo(FilterFieldType.NId, RetVal.ToString()); // Dont update if target is global and source is local if (!(subgroupInfo.Global == false & TargetSGInfo.Global)) { try { //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DALQueries.Subgroup.Update.UpdateSubgroupByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, subgroupInfo.Name, subgroupInfo.GID, subgroupInfo.Global, SGTypeNIdInTargetDB, RetVal)); } catch (Exception) { RetVal = -1; } } } else { // get the last subgroup Type order and update order in source subgrouptype subgroupInfo.Type = SGTypeNIdInTargetDB; if (this.InsertIntoDatabase(subgroupInfo)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// Import Subgroup Type /// </summary> /// <param name="subgroupTypeInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSubgroupType(string subgroupTypeName, string subgroupTypeGID, bool isGlobal) { int RetVal = -1; int NIDByName = 0; bool SkipRecord = false; DI6SubgroupTypeInfo SubgroupTypeInfo = new DI6SubgroupTypeInfo(); try { SubgroupTypeInfo.Name = subgroupTypeName; SubgroupTypeInfo.GID = subgroupTypeGID; SubgroupTypeInfo.Global = isGlobal; //check already exists in database or not //Get NId by Name if (!string.IsNullOrEmpty(SubgroupTypeInfo.GID)) { //first check by gid and then by name RetVal = this.GetNidByGID(SubgroupTypeInfo.GID); if (RetVal > 0) { // check for the duplicacy by name NIDByName = this.GetSubgroupTypeByName(SubgroupTypeInfo.Name); if (RetVal != NIDByName & NIDByName > 0) { //skip records SkipRecord = true; RetVal = -1; } } } //if GID is empty or GID doesnt match then get NId by name if (RetVal <= 0 & SkipRecord == false) { RetVal = this.GetSubgroupTypeByName(SubgroupTypeInfo.Name); } if (!SkipRecord) { //insert or update record if (RetVal > 0) { // update only if source item is global if (SubgroupTypeInfo.Global) { try { // dont change the order into target database //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DALQueries.SubgroupTypes.Update.UpdateSubgroupTypeByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, SubgroupTypeInfo.Name, SubgroupTypeInfo.GID, SubgroupTypeInfo.Global, this.GetSubgroupTypeInfoByNid(RetVal).Order, RetVal)); } catch (Exception) { RetVal = -1; } } } else { // get the last subgroup Type order and update order in source subgrouptype SubgroupTypeInfo.Order = this.GetLastSubgroupTypeOrder() + 1; if (this.InsertIntoDatabase(SubgroupTypeInfo)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// Insert record into subgroup type table /// </summary> /// <param name="subgroupTypeInfo">object of DI6SubgroupTypeInfo </param> /// <returns>Ture/False. Return true after successful insertion otherwise false</returns> private bool InsertIntoDatabase(DI6SubgroupTypeInfo subgroupTypeInfo) { bool RetVal = false; string Name = subgroupTypeInfo.Name; string subgroupTypeGID = subgroupTypeInfo.GID; string SubgroupTypeGId = Guid.NewGuid().ToString(); string LanguageCode = string.Empty; string DefaultLanguageCode = string.Empty; string SubgroupTypeForDatabase = string.Empty; DITables TablesName; int LastOrder = 0; try { DefaultLanguageCode = this.DBQueries.LanguageCode; //replace GID only if given gid is not empty or null. if (!string.IsNullOrEmpty(subgroupTypeGID)) { SubgroupTypeGId = subgroupTypeGID; } // if subgroup type order <= 0 then set the subgroup type order if (subgroupTypeInfo.Order <= 0) { try { LastOrder = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(this.DBQueries.SubgroupTypes.GetMaxSubgroupTypeOrder())); } catch (Exception) { } // set subgroup order subgroupTypeInfo.Order = LastOrder + 1; } foreach (DataRow languageRow in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows) { LanguageCode = languageRow[Language.LanguageCode].ToString(); TablesName = new DITables(this.DBQueries.DataPrefix, LanguageCode); if (LanguageCode == DefaultLanguageCode.Replace("_", String.Empty)) { SubgroupTypeForDatabase = Name; } else { SubgroupTypeForDatabase = Constants.PrefixForNewValue + Name; } this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.SubgroupTypes.Insert.InsertSubgroupType(TablesName.SubgroupType, SubgroupTypeForDatabase, SubgroupTypeGId, subgroupTypeInfo.Order, subgroupTypeInfo.Global)); } RetVal = true; } catch (Exception) { RetVal = false; } return(RetVal); }