public override void Import(string selectedNids) { DataTable Table = null; int ProgressCounter = 0; DI6SubgroupTypeBuilder SGBuilderObj = null; DI6SubgroupTypeInfo SGInfoObj = null; Dictionary<string, DataRow> FileWithNids = new Dictionary<string, DataRow>(); DIConnection SourceDBConnection = null; DIQueries SourceDBQueries = null; DI6SubgroupTypeBuilder SourceSGTypeBuilder = null; //-- Step 1: Get TempTable with Sorted SourceFileName Table = this._TargetDBConnection.ExecuteDataTable(this.ImportQueries.GetImportSubgroupDimensions(selectedNids)); //-- Step 2:Initialise Indicator Builder with Target DBConnection SGBuilderObj = new DI6SubgroupTypeBuilder(this.TargetDBConnection, this.TargetDBQueries); // Initialize progress bar this.RaiseProgressBarInitialize(selectedNids.Split(',').GetUpperBound(0) + 1); //-- Step 3: Import Nids for each SourceFile foreach (DataRow Row in Table.Copy().Rows) { try { string SourceFileWPath = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]); SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SourceFileWPath, String.Empty, MergetTemplateConstants.DBPassword); SourceDBQueries = DataExchange.GetDBQueries(SourceDBConnection); // get subgroup type info from source SourceSGTypeBuilder = new DI6SubgroupTypeBuilder(SourceDBConnection, SourceDBQueries); SGInfoObj =SourceSGTypeBuilder.GetSubgroupTypeInfoByNid(Convert.ToInt32(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID])); // import subgroup type only if doesnt exist SGBuilderObj.ImportSubgroupType(SGInfoObj, Convert.ToInt32(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]), SourceDBQueries, SourceDBConnection); ProgressCounter += 1; this.RaiseProgressBarIncrement(ProgressCounter); } catch (Exception ex) { ExceptionFacade.ThrowException(ex); } finally { if (SourceDBConnection != null) SourceDBConnection.Dispose(); if (SourceDBQueries != null) SourceDBQueries.Dispose(); } } this._AvailableTable = this.GetAvailableTable(); this._UnmatchedTable = this.GetUnmatchedTable(); // Close ProgressBar this.RaiseProgressBarClose(); }
/// <summary> /// Returns the instance of SubgroupInfo on the basis of Subgroup Nid /// </summary> /// <param name="sourceQuery"></param> /// <param name="sourceDBConnection"></param> /// <param name="subgroupNid"></param> /// <returns></returns> public static DI6SubgroupInfo GetSubgroupInfo(DIQueries queries, DIConnection dbConnection, FilterFieldType filterClause, string filterText) { string Query = string.Empty; DI6SubgroupInfo RetVal = new DI6SubgroupInfo(); DataTable SubgroupTable; DI6SubgroupTypeBuilder SGTypeBuilder; try { Query = queries.Subgroup.GetSubgroup(filterClause, filterText); SubgroupTable = dbConnection.ExecuteDataTable(Query); //set Subgroup info if (SubgroupTable != null) { if (SubgroupTable.Rows.Count > 0) { RetVal.GID = SubgroupTable.Rows[0][Subgroup.SubgroupGId].ToString(); RetVal.Global = Convert.ToBoolean(SubgroupTable.Rows[0][Subgroup.SubgroupGlobal]); RetVal.Name = SubgroupTable.Rows[0][Subgroup.SubgroupName].ToString(); RetVal.Nid = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupNId].ToString()); RetVal.Type = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupType].ToString()); // Get subgrouptype info if (RetVal.Type > 0) { SGTypeBuilder = new DI6SubgroupTypeBuilder(dbConnection, queries); RetVal.DISubgroupType = SGTypeBuilder.GetSubgroupTypeInfoByNid(RetVal.Type); } } } } catch (Exception) { RetVal = null; } return RetVal; }
/// <summary> /// Returns the instance of SubgroupInfo on the basis of Subgroup Nid /// </summary> /// <param name="sourceQuery"></param> /// <param name="sourceDBConnection"></param> /// <param name="subgroupNid"></param> /// <returns></returns> public static DI6SubgroupInfo GetSubgroupInfo(DIQueries queries, DIConnection dbConnection, FilterFieldType filterClause, string filterText) { string Query = string.Empty; DI6SubgroupInfo RetVal = new DI6SubgroupInfo(); DataTable SubgroupTable; DI6SubgroupTypeBuilder SGTypeBuilder; try { Query = queries.Subgroup.GetSubgroup(filterClause, filterText); SubgroupTable = dbConnection.ExecuteDataTable(Query); //set Subgroup info if (SubgroupTable != null) { if (SubgroupTable.Rows.Count > 0) { RetVal.GID = SubgroupTable.Rows[0][Subgroup.SubgroupGId].ToString(); RetVal.Global = Convert.ToBoolean(SubgroupTable.Rows[0][Subgroup.SubgroupGlobal]); RetVal.Name = SubgroupTable.Rows[0][Subgroup.SubgroupName].ToString(); RetVal.Nid = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupNId].ToString()); RetVal.Type = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupType].ToString()); // Get subgrouptype info if (RetVal.Type > 0) { SGTypeBuilder = new DI6SubgroupTypeBuilder(dbConnection, queries); RetVal.DISubgroupType = SGTypeBuilder.GetSubgroupTypeInfoByNid(RetVal.Type); } } } } catch (Exception) { RetVal = null; } 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: 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; }
private void ProcessMappedSubgroupType() { DIConnection SrcDBConnection = null; DIQueries SrcDBQueries = null; DI6SubgroupTypeBuilder TrgSubgroupTypeBilder = null; DI6SubgroupTypeBuilder SourceSGTypeBuilder = null; DI6SubgroupTypeInfo SrcSubgroupTypeInfo = null; DataTable Table = null; string SourceFileWPath = string.Empty; int TrgSGDNid = 0; if (this.MappedTables.ContainsKey(TemplateMergeControlType.SubgroupDimensions)) { TrgSubgroupTypeBilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries); foreach (DataRow Row in this.MappedTables[TemplateMergeControlType.SubgroupDimensions].MappedTable.MappedTable.Rows) { Table = this.DBConnection.ExecuteDataTable(TemplateQueries.GetImportSubgroupDimensions(Convert.ToString(Row[MergetTemplateConstants.Columns.UNMATCHED_COL_Prefix + SubgroupTypes.SubgroupTypeNId]))); TrgSGDNid = Convert.ToInt32(Row[MergetTemplateConstants.Columns.AVAILABLE_COL_Prefix + SubgroupTypes.SubgroupTypeNId]); if (Table != null && Table.Rows.Count > 0) { try { SourceFileWPath = Convert.ToString(Table.Rows[0][MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]); SrcDBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, SourceFileWPath, string.Empty, string.Empty); SrcDBQueries = DataExchange.GetDBQueries(SrcDBConnection); // get subgroup type info SourceSGTypeBuilder = new DI6SubgroupTypeBuilder(SrcDBConnection, SrcDBQueries); SrcSubgroupTypeInfo = SourceSGTypeBuilder.GetSubgroupTypeInfoByNid(Convert.ToInt32(Table.Rows[0][MergetTemplateConstants.Columns.COLUMN_SRCNID])); // Import Mapped Subgroup Type Values TrgSubgroupTypeBilder.ImportSubgroupTypeFrmMappedSubgroupType(SrcSubgroupTypeInfo, SrcSubgroupTypeInfo.Nid, TrgSGDNid, SrcDBQueries, SrcDBConnection); } finally { if (SrcDBConnection != null) { SrcDBConnection.Dispose(); } } } } } }
/// <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> /// Process Matched Subgroup Type /// </summary> public void ProcessSubgroupDimensions() { DataTable Table = null; DI6SubgroupTypeBuilder SGBuilderObj = null; DI6SubgroupTypeInfo SourceSGInfoObj = null; DI6SubgroupTypeBuilder SourceSGTypeBuilder = null; Dictionary<string, DataRow> FileWithNids = new Dictionary<string, DataRow>(); DIConnection SourceDBConnection = null; DIQueries SourceDBQueries = null; //-- Step 1: Get TempTable with Sorted SourceFileName Table = this.DBConnection.ExecuteDataTable(this.TemplateQueries.GetMatchedSubgroupDimensions()); //-- Step 2:Initialise Indicator Builder with Target DBConnection SGBuilderObj = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries); //-- Step 3: Import Nids for each SourceFile foreach (DataRow Row in Table.Copy().Rows) { try { string SourceFileWPath = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]); SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SourceFileWPath, String.Empty, MergetTemplateConstants.DBPassword); SourceDBQueries = DataExchange.GetDBQueries(SourceDBConnection); // get subgroup type info SourceSGTypeBuilder = new DI6SubgroupTypeBuilder(SourceDBConnection, SourceDBQueries); SourceSGInfoObj = SourceSGTypeBuilder.GetSubgroupTypeInfoByNid(Convert.ToInt32(Row[SubgroupTypes.SubgroupTypeNId])); //import subgroup type SGBuilderObj.ImportSubgroupType(SourceSGInfoObj, Convert.ToInt32(Row[SubgroupTypes.SubgroupTypeNId]), SourceDBQueries, SourceDBConnection); } catch (Exception ex) { ExceptionFacade.ThrowException(ex); } finally { if (SourceDBConnection != null) SourceDBConnection.Dispose(); if (SourceDBQueries != null) SourceDBQueries.Dispose(); } } }