/// <summary> /// Function to extract the images from the database and copy then to the temp location Get icons referred inside metadata /// </summary> private static void ExtractImage(int elementNId, IconElementType IconElementType, DIConnection DIConnection, DIQueries DIQueries, String OutPutPath) { string sSql = DIQueries.Icon.GetIcon(elementNId.ToString(), IconElementType); DataTable dtIcon = DIConnection.ExecuteDataTable(sSql); try { if (dtIcon != null) { for (int index = 0; index < dtIcon.Rows.Count; index++) { Byte[] Buffer; Buffer = (Byte[])dtIcon.Rows[index][Icons.ElementIcon]; //create memory stream from this array of bytes System.IO.MemoryStream str = new System.IO.MemoryStream(Buffer); System.Drawing.Image.FromStream(str).Save(System.IO.Path.Combine(OutPutPath, dtIcon.Rows[index][Icons.IconNId].ToString() + "." + dtIcon.Rows[index][Icons.IconType].ToString())); str.Dispose(); } } } catch (Exception) { //throw ex; } }
/// <summary> /// Import HighISGood from Source database /// </summary> /// <param name="sourceDBConnection"></param> /// <param name="sourceDBQueries"></param> public void ImportHighISGood(DIConnection sourceDBConnection, DIQueries sourceDBQueries) { string IUSNids = string.Empty; DataTable IndTable = null; //-- Get IUS from Source Database IndTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.Indicators.GetIndicator(FilterFieldType.None, string.Empty, FieldSelection.Light)); foreach (DataRow Row in IndTable.Rows) { bool HighISGood = false; int IndNid = this.GetIndicatorNid(Convert.ToString(Row[Indicator.IndicatorGId]), Convert.ToString(Row[Indicator.IndicatorName])); if (IndNid > 0) { if (!string.IsNullOrEmpty(Convert.ToString(Row[Indicator.HighIsGood]))) { HighISGood = Convert.ToBoolean(Row[Indicator.HighIsGood]); } this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Indicator.Update.UpdateISHighGood(this.DBConnection.ConnectionStringParameters.ServerType, this.DBQueries.TablesName.Indicator, IndNid, HighISGood)); } } }
/// <summary> /// Get layer name based on layer nid /// </summary> /// <param name="LayerNId">Layer NId</param> /// <param name="DIConnection">DIConnection</param> /// <param name="DIQueries">DIQueries</param> /// <returns>Layer Name</returns> private static string GetLayerName(string layerNId, DIConnection DIConnection, DIQueries DIQueries) { string RetVal = string.Empty; string sSql = DIQueries.Area.GetAreaMapLayer(DevInfo.Lib.DI_LibDAL.Queries.Area.Select.MapFilterFieldType.LayerNId, layerNId.ToString(), FieldSelection.Light); DataTable dtLayer = DIConnection.ExecuteDataTable(sSql); if (dtLayer != null & dtLayer.Rows.Count > 0) { RetVal = dtLayer.Rows[0][Area_Map_Metadata.LayerName].ToString(); } dtLayer.Dispose(); return(RetVal); }
/// <summary> /// Get the base layer (most recent) associated with an area /// </summary> /// <param name="AreaNId"></param> /// <param name="DIConnection"></param> /// <param name="DIQueries"></param> /// <returns>Layer NId</returns> private static int GetLayerNId(string AreaNId, DIConnection DIConnection, DIQueries DIQueries) { int RetVal = -1; string sSql = DIQueries.Area.GetAreaMapByAreaNIds(AreaNId, false); //Consider base layers only DataTable dtAreaMap = DIConnection.ExecuteDataTable(sSql); if (dtAreaMap != null && dtAreaMap.Rows.Count > 0) { //OPT If multiple base layer are associated with an area select latest map available RetVal = (int)dtAreaMap.Rows[0][Area_Map.LayerNId]; } dtAreaMap.Dispose(); return(RetVal); }
/// <summary> /// Import ISDefaultSubgroup from database /// </summary> /// <param name="sourceDatabase"></param> /// <param name="sourceDBQueries"></param> public void ImportDefaultSubgroups(DIConnection sourceDBConnection, DIQueries sourceDBQueries) { string IUSNids = string.Empty; DataTable IUSTable = null; DataTable IUTable = null; IUSInfo IUSInfoObj = new IUSInfo(); //-- Get IUS from Source Database IUSTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IUS.GetIUS(FilterFieldType.None, string.Empty, FieldSelection.Light, true)); //-- Get Default IUS Values DataRow[] IUSRows = IUSTable.Select(Indicator_Unit_Subgroup.IsDefaultSubgroup + "=1"); foreach (DataRow Row in IUSRows) { IUSInfoObj = new IUSInfo(); IUSInfoObj.IndicatorInfo = new IndicatorInfo(); IUSInfoObj.UnitInfo = new UnitInfo(); IUSInfoObj.SubgroupValInfo = new DI6SubgroupValInfo(); IUSInfoObj.IndicatorInfo.Name = Convert.ToString(Row[Indicator.IndicatorName]); IUSInfoObj.IndicatorInfo.GID = Convert.ToString(Row[Indicator.IndicatorGId]); IUSInfoObj.UnitInfo.Name = Convert.ToString(Row[Unit.UnitName]); IUSInfoObj.UnitInfo.GID = Convert.ToString(Row[Unit.UnitGId]); IUSInfoObj.SubgroupValInfo.Name = Convert.ToString(Row[SubgroupVals.SubgroupVal]); IUSInfoObj.SubgroupValInfo.GID = Convert.ToString(Row[SubgroupVals.SubgroupValGId]); int IUSNid = this.GetIUSNid(IUSInfoObj); //-- Set Default Subgroup if IUS exists if (IUSNid > 0) { IUTable = this.DBConnection.ExecuteDataTable(this.DBQueries.IUS.GetIUSByI_U_S(IUSInfoObj.IndicatorInfo.Nid.ToString(), IUSInfoObj.UnitInfo.Nid.ToString(), string.Empty)); IUSNids = DIConnection.GetDelimitedValuesFromDataTable(IUTable, Indicator_Unit_Subgroup.IUSNId); //-- Make ISDefault false for other subgroupval for current I-U this.UpdateIUSISDefaultSubgroup(IUSNids, false); //-- Set DefaultSubgroupVal for IUSNid this.UpdateIUSISDefaultSubgroup(IUSNid.ToString(), true); } } }
/// <summary> /// Imports metadata from the source database into current database /// </summary> /// <param name="srcConnection"></param> /// <param name="srcQueries"></param> /// <param name="srcElementNid"></param> /// <param name="trgElementNid"></param> /// <param name="categoryType"></param> /// <param name="metadataType"></param> /// <param name="iconType"></param> public void ImportMetadata(DIConnection srcConnection, DIQueries srcQueries, int srcElementNid, int trgElementNid, MetadataElementType categoryType, MetaDataType metadataType, IconElementType iconType) { string SrcCategoryGID = string.Empty; string MetadataText = string.Empty; int TrgCategoryNid = 0; DataTable TrgCategoryTable = null; Dictionary <String, String> OldIconNIdnNewIconNId = new Dictionary <string, string>(); try { // Get target Category table TrgCategoryTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType])); // update metadata icon in DICon table OldIconNIdnNewIconNId = DIIcons.ImportElement(srcElementNid, trgElementNid, iconType, srcQueries, srcConnection, this.DBQueries, this.DBConnection); //get source metadata reports foreach (DataRow SrcRow in srcConnection.ExecuteDataTable(srcQueries.MetadataReport.GetMetadataReportsByTargetNid(srcElementNid.ToString(), categoryType)).Rows) { SrcCategoryGID = Convert.ToString(SrcRow[Metadata_Category.CategoryGId]); // check source category GID exists in current database // Import metadta report only if category exists in current database foreach (DataRow TrgCategoryRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryGID) + "' ")) { MetadataText = Convert.ToString(SrcRow[MetadataReport.Metadata]); // Update IconNids in metadata if exists foreach (string OldIconName in OldIconNIdnNewIconNId.Keys) { MetadataText = MetadataText.Replace(OldIconName, OldIconNIdnNewIconNId[OldIconName].ToString()); } TrgCategoryNid = Convert.ToInt32(TrgCategoryRow[Metadata_Category.CategoryNId]); this.InsertORUpdateMetadataInfo(metadataType, TrgCategoryNid.ToString(), trgElementNid, MetadataText); } } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } }
private static bool ISColumnExists(DIConnection dbConnection, string columnName, string tableName) { bool RetVal = false; string SqlQuery = string.Empty; //-- Check orgTextual_Data_value exists or not. try { SqlQuery = "Select " + columnName + " FROM " + tableName; DataTable Table = dbConnection.ExecuteDataTable(SqlQuery); RetVal = true; } catch (Exception) { RetVal = false; } return(RetVal); }
/// <summary> /// Dictionary containing old IconNId as key and new IconNId as value. /// This information shall be utilised to update metadata xml being inserted / updated /// </summary> /// <param name="NidInSourceDB"></param> /// <param name="NidInTargetDB"></param> /// <param name="elementType"></param> /// <param name="sourceQurey"></param> /// <param name="SourceDBConnection"></param> /// <param name="targetQurey"></param> /// <param name="TargetDBConnection"></param> /// <returns> /// </returns> /// <remarks></remarks> public static Dictionary <string, string> ImportElement(int NidInSourceDB, int NidInTargetDB, IconElementType elementType, DIQueries sourceQurey, DIConnection sourceDBConnection, DIQueries targetQurey, DIConnection targetDBConnection) { Dictionary <string, string> RetVal = new Dictionary <string, string>(); string ElementValue = DIIcons.Elements[elementType]; string SqlQuery = string.Empty; DataTable IconsDatatable; string OldIconNId = string.Empty; string NewIconNId = string.Empty; try { if ((sourceDBConnection != null)) { if (DIIcons.IsIconsTblExists(sourceQurey.TablesName.Icons, sourceDBConnection)) { //-- In Target Database: delete records from UT_Icon table if Icon is already associated with given Element Type SqlQuery = DevInfo.Lib.DI_LibDAL.Queries.Icon.Delete.DeleteIcon(targetQurey.DataPrefix, ElementValue, NidInTargetDB.ToString()); targetDBConnection.ExecuteNonQuery(SqlQuery); //-- In Source Database: check Icon is associated with the given Element type in UT_ICon table SqlQuery = sourceQurey.Icon.GetIcon(NidInSourceDB.ToString(), ElementValue); IconsDatatable = sourceDBConnection.ExecuteDataTable(SqlQuery); //-- If associated, then copy it it from Source database into target database foreach (DataRow Row in IconsDatatable.Rows) { //-- Insert Icon and get new IconNId NewIconNId = DIIcons.InsertIcon(targetDBConnection, targetQurey, (byte[])(Row["Element_Icon"]), Row["Icon_Type"].ToString(), Convert.ToInt32(Row["Icon_Dim_W"]), Convert.ToInt32(Row["Icon_Dim_H"]), ElementValue, Convert.ToString(NidInTargetDB)).ToString(); //-- Add Item to Dictionary with New IconNId as Key and Old IconNId as Value RetVal.Add(IMG_PREFIX + Row["Icon_NId"].ToString() + ".", IMG_PREFIX + NewIconNId + "."); } } } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
private static DI7MetadataCategoryInfo GetMetadataCategoryInfo(DataRow row, DIConnection dbConnection, DIQueries dbQueries) { DI7MetadataCategoryInfo RetVal = new DI7MetadataCategoryInfo(); DI7MetadataCategoryInfo SubCategory; RetVal.CategoryNId = Convert.ToInt32(row[Metadata_Category.CategoryNId]); RetVal.CategoryGID = Convert.ToString(row[Metadata_Category.CategoryGId]); RetVal.CategoryName = Convert.ToString(row[Metadata_Category.CategoryName]); RetVal.Description = Convert.ToString(row[Metadata_Category.CategoryDescription]); RetVal.CategoryOrder = Convert.ToInt32(row[Metadata_Category.CategoryOrder]); RetVal.CategoryType = Convert.ToString(row[Metadata_Category.CategoryType]); RetVal.IsMandatory = Convert.ToBoolean(row[Metadata_Category.IsMandatory]); RetVal.IsPresentational = Convert.ToBoolean(row[Metadata_Category.IsPresentational]); RetVal.ParentNid = Convert.ToInt32(row[Metadata_Category.ParentCategoryNId]); // add subcategories (if any) RetVal.SubCategories = new Dictionary <string, DI7MetadataCategoryInfo>(); foreach (DataRow SubCategoryRow in dbConnection.ExecuteDataTable(dbQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, "'" + RetVal.CategoryType + "'", RetVal.CategoryNId.ToString())).Rows) { if (!RetVal.SubCategories.ContainsKey(Convert.ToString(SubCategoryRow[Metadata_Category.CategoryGId]))) { RetVal.SubCategories.Add(Convert.ToString(SubCategoryRow[Metadata_Category.CategoryGId]), new DI7MetadataCategoryInfo()); } // Add subcategory information SubCategory = RetVal.SubCategories[Convert.ToString(SubCategoryRow[Metadata_Category.CategoryGId])]; SubCategory.CategoryNId = Convert.ToInt32(SubCategoryRow[Metadata_Category.CategoryNId]); SubCategory.CategoryGID = Convert.ToString(SubCategoryRow[Metadata_Category.CategoryGId]); SubCategory.CategoryName = Convert.ToString(SubCategoryRow[Metadata_Category.CategoryName]); SubCategory.Description = Convert.ToString(SubCategoryRow[Metadata_Category.CategoryDescription]); SubCategory.CategoryOrder = Convert.ToInt32(SubCategoryRow[Metadata_Category.CategoryOrder]); SubCategory.CategoryType = Convert.ToString(SubCategoryRow[Metadata_Category.CategoryType]); SubCategory.IsMandatory = Convert.ToBoolean(SubCategoryRow[Metadata_Category.IsMandatory]); SubCategory.IsPresentational = Convert.ToBoolean(SubCategoryRow[Metadata_Category.IsPresentational]); SubCategory.ParentNid = Convert.ToInt32(SubCategoryRow[Metadata_Category.ParentCategoryNId]); } return(RetVal); }
/// <summary> /// Get path for selected area starting from root area /// </summary> /// <param name="ElementNid">ID of selected Data</param> /// <param name="DI_QueryBase">This contains Connection Details</param> /// <returns>String containg the path of area node starting from root node</returns> public static string GetAreaChain(int AreaNId, DIConnection DIConnection, DIQueries DIQueries) { string RetVal = string.Empty; string sSql = string.Empty; int AreaLevel = 1; // Get Current Area Level sSql = DIQueries.Area.GetArea(FilterFieldType.NId, AreaNId.ToString()); DataTable dtArea = DIConnection.ExecuteDataTable(sSql); if (dtArea != null & dtArea.Rows.Count > 0) { AreaLevel = (int)dtArea.Rows[0][Area.AreaLevel]; } //Get concatinated Area names sSql = DIQueries.Area.GetAreaChain(AreaNId, AreaLevel, DIConnection.ConnectionStringParameters.ServerType); RetVal = DIConnection.ExecuteScalarSqlQuery(sSql).ToString(); 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> /// Getting MetaData and writing them to Rtf file. /// </summary> public static string ExtractRtfMetadata(ICType ICType, int ICNId, DIConnection DIConnection, DIQueries DIQueries, String outputFolder, String outputFileName) { string RetVal = string.Empty; string RtfFilePath = System.IO.Path.Combine(outputFolder, outputFileName + ".rtf"); DataTable RtfDataTable = new DataTable(); try { if (System.IO.File.Exists(RtfFilePath)) { System.IO.File.Delete(RtfFilePath); } // getting metadata informationn from Database into DataTable RtfDataTable string sSql = DIQueries.IndicatorClassification.GetIC(FilterFieldType.NId, ICNId.ToString(), ICType, FieldSelection.Heavy); RtfDataTable = DIConnection.ExecuteDataTable(sSql); if (RtfDataTable != null & RtfDataTable.Rows.Count > 0) { RetVal = RtfDataTable.Rows[0][IndicatorClassifications.ICName].ToString(); if (!Convert.IsDBNull(RtfDataTable.Rows[0][IndicatorClassifications.ICInfo])) { string RtfString = RtfDataTable.Rows[0][IndicatorClassifications.ICInfo].ToString(); // Writng metadata into a rtf file in output directory if (RtfString.Trim().Length > 0) { WriteToFile(RtfString, RtfFilePath); } } } } catch (Exception) { //throw ex; } return(RetVal); }
/// <summary> /// Imports area metadata from template/database /// </summary> /// <param name="dataPrefix"></param> /// <param name="sourceDBConnection"></param> /// <param name="sourceDBQueries"></param> /// <param name="selectedNIDs"></param> /// <param name="selectionCount"></param> /// <param name="metadataType"></param> public void ImportAreaMetadata(string dataPrefix, DIConnection sourceDBConnection, DIQueries sourceDBQueries, string selectedNIDs, int selectionCount, MetaDataType metadataType) { DataTable TempDataTable; int CurrentRecordIndex = 0; DI7MetadataCategoryBuilder AreaMetadataCategoryBuilder; DataTable TempTargetTable; try { this.RaiseStartProcessEvent(); // import area categories AreaMetadataCategoryBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries); AreaMetadataCategoryBuilder.ImportAllMetadataCategories(sourceDBConnection, sourceDBQueries, MetadataElementType.Area); if (selectionCount == -1) { // -- GET ALL TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.Area.GetAreaMapMetadata(string.Empty)); } else { // -- GET SELECTED TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.Area.GetAreaMapMetadata(selectedNIDs)); } // -- Initialize Progress Bar this.RaiseBeforeProcessEvent(TempDataTable.Rows.Count); CurrentRecordIndex = 0; //import area metadata foreach (DataRow Row in TempDataTable.Rows) { CurrentRecordIndex++; //-- Get Target table against LayerName TempTargetTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetAreaMapMetadataByName( Row[Area_Map_Metadata.LayerName].ToString())); foreach (DataRow TrgRow in TempTargetTable.Rows) { this.ImportMetadata(sourceDBConnection, sourceDBQueries, Convert.ToInt32(Row[Area_Map_Layer.LayerNId]), Convert.ToInt32(TrgRow[Area_Map_Layer.LayerNId]), MetadataElementType.Area, MetaDataType.Map, IconElementType.MetadataArea); break; } // -- Increemnt the Progress Bar Value this.RaiseProcessInfoEvent(CurrentRecordIndex); } } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } finally { this.RaiseEndProcessEvent(); } }
/// <summary> /// To import indicator information from mapped indicator /// </summary> /// <param name="indicatorInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="NidInTrgDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportIndicatorFrmMappedIndicator(IndicatorInfo indicatorInfo, int NidInSourceDB, int NidInTrgDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; string metadataInfo = string.Empty; string SqlString = string.Empty; DataRow Row; DataTable TempTable; Dictionary <String, String> OldIconNId_NewIconNId = new Dictionary <string, string>(); MetaDataBuilder MetaDataBuilderObj; IndicatorInfo TrgIndicatorInfo; try { // set RetVal to targetNID RetVal = NidInTrgDB; if (RetVal > 0) { TrgIndicatorInfo = this.GetIndicatorInfo(FilterFieldType.NId, RetVal.ToString(), FieldSelection.Light); // dont import if trg indicator is global but source indicator is local if (TrgIndicatorInfo.Global & indicatorInfo.Global == false) { // dont import if trg indicator is global but source indicator is local } else { //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Indicator.Update.UpdateByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, indicatorInfo.Name, indicatorInfo.GID, indicatorInfo.Global, indicatorInfo.Info, RetVal)); } } //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.Indicator, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); OldIconNId_NewIconNId = DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.MetadataIndicator, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // get metadata info. metadataInfo = indicatorInfo.Info; // Update IconNids in xml if exists foreach (string OldIconName in OldIconNId_NewIconNId.Keys) { metadataInfo = metadataInfo.Replace(OldIconName, OldIconNId_NewIconNId[OldIconName].ToString()); } metadataInfo = DICommon.CheckNConvertMetadataXml(metadataInfo); // Update Metadata this.DBConnection.ExecuteNonQuery(DALQueries.Indicator.Update.UpdateIndicatorInfo(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, DICommon.RemoveQuotes(metadataInfo), FilterFieldType.GId, indicatorInfo.GID)); // -- insert records in xslt tables SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Indicator); TempTable = sourceDBConnection.ExecuteDataTable(SqlString); if (TempTable.Rows.Count > 0) { Row = TempTable.Rows[0]; MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Indicator); } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
internal int CreateClassificationChainFromExtDB(int srcICNId, int srcParentNId, string srcICGid, string srcICName, ICType srcICType, string srcICInfo, bool isGlobal, DIQueries srcQueries, DIConnection srcDBConnection, DIQueries targetDBQueries, DIConnection targetDBConnection) { int RetVal; //int TrgParentNId; //string TrgParentName; int NewParentNId; DataTable TempTable; IndicatorClassificationInfo ICInfo; IndicatorClassificationBuilder ClassificationBuilder = new IndicatorClassificationBuilder(targetDBConnection, targetDBQueries); // -- STEP 1: If the Parent NID is -1 then create the Classification at the root if (srcParentNId == -1) { // -- Create the Classification // -------------------------------------------------------------- // While importing the Classifications, if the NId of the Source Classification is _ // the same as that of the one created, then the Duplicate check fails and a duplicate // classification getscreated. PASS -99 as the first parameter to the calling function // -------------------------------------------------------------- ICInfo = new IndicatorClassificationInfo(); ICInfo.Parent = new IndicatorClassificationInfo(); ICInfo.Parent.Nid = srcParentNId; ICInfo.Nid = srcICNId; ICInfo.Name = srcICName; ICInfo.ClassificationInfo = srcICInfo; ICInfo.GID = srcICGid; ICInfo.IsGlobal = isGlobal; ICInfo.Type = srcICType; RetVal = ClassificationBuilder.ImportIndicatorClassification(ICInfo, srcICNId, srcQueries, srcDBConnection); } else { // -- STEP 2: If the Parent is not -1 then check for the existence of the Parent and then create the Classification // Classification can only be created if the parent exists // -- STEP 2.1: If the Parent Exists then create the Classification under that parent // -- STEP 2.2: If the Parent does not Exist then create the Parent first and then the Classification under that parent // -- STEP 2: Check the existence of the Parent in the Target Database // -- get the parent from the source database TempTable = srcDBConnection.ExecuteDataTable(srcQueries.IndicatorClassification.GetIC(FilterFieldType.NId, srcParentNId.ToString(), srcICType, FieldSelection.Heavy)); { // -------------------------------------------------------------- // While importing the Classifications, if the NId of the Source Classification is _ // the same as that of the one created, then the Duplicate check fails and a duplicate // classification getscreated. PASS -99 as the first parameter to the calling function // -------------------------------------------------------------- DataRow Row; string ClassificationInfo = string.Empty; Row = TempTable.Rows[0]; ClassificationInfo = Convert.ToString(Row[IndicatorClassifications.ICInfo]); NewParentNId = CreateClassificationChainFromExtDB( Convert.ToInt32(Row[IndicatorClassifications.ICNId]), Convert.ToInt32(Row[IndicatorClassifications.ICParent_NId]), Row[IndicatorClassifications.ICGId].ToString(), Row[IndicatorClassifications.ICName].ToString(), srcICType, ClassificationInfo, Convert.ToBoolean(Row[IndicatorClassifications.ICGlobal]), srcQueries, srcDBConnection, targetDBQueries, targetDBConnection);; } // -- Create the Child Now ICInfo = new IndicatorClassificationInfo(); ICInfo.Parent = new IndicatorClassificationInfo(); ICInfo.Parent.Nid = NewParentNId; // set new parent nid ICInfo.Nid = srcICNId; ICInfo.Name = srcICName; ICInfo.ClassificationInfo = srcICInfo; ICInfo.GID = srcICGid; ICInfo.IsGlobal = isGlobal; ICInfo.Type = srcICType; RetVal = ClassificationBuilder.ImportIndicatorClassification(ICInfo, srcICNId, srcQueries, srcDBConnection); } //import ic and ius relationship into indicator_classification_IUS table ClassificationBuilder.ImportICAndIUSRelations(srcICNId, RetVal, ICInfo.Type, srcQueries, srcDBConnection); return(RetVal); }
/// <summary> /// Imports all metadata categories from given source database to current database /// </summary> /// <param name="srcDBConnection"></param> /// <param name="srcDBQueries"></param> /// <param name="categoryType"></param> public void ImportAllMetadataCategories(DIConnection srcDBConnection, DIQueries srcDBQueries, MetadataElementType categoryType) { // import by GID. If GID exists then update existing category otherwise insert it into current database // update process will update in current langauge but insert process will insert in all langauges DataTable SrcCategoryTable = null; DI7MetadataCategoryInfo SrcCategoryInfo = null; DataTable TrgCategoryTable = null; int TrgCategoryNid = 0; int TrgCategoryParentNid = -1; try { // get source category table SrcCategoryTable = srcDBConnection.ExecuteDataTable(srcDBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType])); // get target(current database) category table TrgCategoryTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType])); // import categories & sub categories from source database into current database foreach (DataRow SrcRow in SrcCategoryTable.Select(Metadata_Category.ParentCategoryNId + "=-1")) { // get category from source database SrcCategoryInfo = DI7MetadataCategoryBuilder.GetMetadataCategoryInfo(SrcRow, srcDBConnection, srcDBQueries); // check src category gid exists in current(target) database of not TrgCategoryNid = 0; TrgCategoryParentNid = -1; foreach (DataRow TrgRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryInfo.CategoryGID) + "' OR " + Metadata_Category.CategoryName + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryInfo.CategoryName) + "'")) { // if exists then get nid and parent nid TrgCategoryNid = Convert.ToInt32(TrgRow[Metadata_Category.CategoryNId]); TrgCategoryParentNid = Convert.ToInt32(TrgRow[Metadata_Category.ParentCategoryNId]); } // update nid & parent nid in src category info SrcCategoryInfo.CategoryNId = TrgCategoryNid; SrcCategoryInfo.ParentNid = TrgCategoryParentNid; if (TrgCategoryNid > 0) { // update category info this.UpdateMetadataCategory(SrcCategoryInfo); } else { // insert category into current database TrgCategoryNid = this.InsertIntoDatabase(SrcCategoryInfo); } #region -- insert/update sub categories into current database -- // insert/update only if target category parent nid is equal to -1 (means at level1) if (TrgCategoryParentNid == -1) { foreach (DI7MetadataCategoryInfo SrcSubCategory in SrcCategoryInfo.SubCategories.Values) { SrcSubCategory.CategoryNId = 0; SrcSubCategory.ParentNid = TrgCategoryNid; // check sub category exists ( where gid=<src gid> and parent nid=<trg nid> foreach (DataRow TrgSubCategoryRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcSubCategory.CategoryGID) + "' AND " + Metadata_Category.ParentCategoryNId + "=" + TrgCategoryNid)) { // if exists then get nid SrcSubCategory.CategoryNId = Convert.ToInt32(TrgSubCategoryRow[Metadata_Category.CategoryNId]); } if (SrcSubCategory.CategoryNId > 0) { // update sub category into current database this.UpdateMetadataCategory(SrcSubCategory); } else { // insert sub category into current database this.InsertIntoDatabase(SrcSubCategory); } } } #endregion } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } }
/// <summary> /// Main Method for Displaying Metadata /// </summary> /// <param name="elementType"> Element Type.<example>ElementType.All, ElementType.Indicator </example> <seealso cref="DI_MetaInfo.ElementType"/></param> /// <param name="elementNid">ID of selected Data.IND - IndicatorNId, Area - AreaNId, Source - ICNId</param> /// <param name="DI_QueryBase"> This contain Connection Details</param> /// <param name="outPutPath">This contains the path where output files were created</param> /// <param name="outputFileName"> /// this will be the name of outputFile without extention /// which will be created at the output path to display metadata /// <remarks> extension like ".xml" ".xsl" and ".html" are added to this outputFile name /// while creating files </remarks> /// </param> /// <returns> /// </returns> public static bool ExtractXmlMetadata(MetadataElementType metadataElementType, int elementNId, DIConnection DIConnection, DIQueries DIQueries, string outputFolder, string outputFileName, ref string infoTitle) { bool RetVal = false; infoTitle = string.Empty; //Will return the Element name against ElementNId IconElementType IconElementType = IconElementType.MetadataIndicator; XmlDocument XMLDoc = new XmlDocument(); DataTable DTMetaDataInfo = null; string MetadataInfo = string.Empty; String sSql = ""; int LayerNId = -1; string TargetObjectID = string.Empty; Lib.DI_LibSDMX.MetadataTypes SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator; switch (metadataElementType) { case MetadataElementType.Area: IconElementType = IconElementType.MetadataArea; SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Area; //-- Get LayerNId associated with AreaNId if (_LayerNId == -1) { LayerNId = GetLayerNId(elementNId.ToString(), DIConnection, DIQueries); } else { LayerNId = _LayerNId; } //if (LayerNId != -1) //{ // //-- Get Layer Metadata Info // sSql = DIQueries.Area.GetAreaMapMetadata(LayerNId.ToString()); // DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql); // if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0) // { // MetadataInfo = DTMetaDataInfo.Rows[0][Area_Map_Metadata.MetadataText].ToString(); // } //} // Set Meta Info title. sSql = DIQueries.Area.GetArea(FilterFieldType.NId, elementNId.ToString()); DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql); if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0) { infoTitle = DTMetaDataInfo.Rows[0][Area.AreaName].ToString() + " (" + DTMetaDataInfo.Rows[0][Area.AreaID].ToString() + ")"; TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][Area.AreaID]); } break; case MetadataElementType.Indicator: IconElementType = IconElementType.MetadataIndicator; SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator; sSql = DIQueries.Indicators.GetIndicator(FilterFieldType.NId, elementNId.ToString(), FieldSelection.Heavy); DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql); if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0) { infoTitle = DTMetaDataInfo.Rows[0][Indicator.IndicatorName].ToString(); TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][Indicator.IndicatorGId]); } break; case MetadataElementType.Source: IconElementType = IconElementType.MetadataSource; SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Source; sSql = DIQueries.IndicatorClassification.GetIC(FilterFieldType.NId, elementNId.ToString(), ICType.Source, FieldSelection.Heavy); DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql); if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0) { infoTitle = DTMetaDataInfo.Rows[0][IndicatorClassifications.ICName].ToString(); TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][IndicatorClassifications.ICGId]); } break; } try { // Get metadata xml file using SDMX library MetadataInfo = Lib.DI_LibSDMX.SDMXUtility.Get_MetadataReport(DevInfo.Lib.DI_LibSDMX.SDMXSchemaType.Two_One, TargetObjectID, SDMXMetadataType, "MDAgency", DIQueries.LanguageCode.Replace("_", ""), DIConnection, DIQueries).InnerXml; DevInfo.Lib.DI_LibBAL.DA.DML.DI7MetaDataBuilder MetadataBuilder = new DevInfo.Lib.DI_LibBAL.DA.DML.DI7MetaDataBuilder(DIConnection, DIQueries); // Get metadata xml file with category name.. XMLDoc = MetadataBuilder.GetMetadataReportWCategoryName(MetadataInfo, metadataElementType); MetadataInfo = XMLDoc.InnerXml; //Write Metadata text to physical file // --Change on 18-03-08 .blank xml with root element will be written in case of no metadata info found in database // If no metadata info create a blank xml file. with root element. if (string.IsNullOrEmpty(MetadataInfo) || MetadataInfo.Trim().Length == 0) { WriteToFile("<?xml version='1.0'?><root ></root >", System.IO.Path.Combine(outputFolder, outputFileName + ".xml")); } else { WriteToFile(MetadataInfo, System.IO.Path.Combine(outputFolder, outputFileName + ".xml")); } // Commented on 18-march -2008. shifted in if else part above. ////WriteToFile(MetadataInfo, System.IO.Path.Combine(outputFolder, outputFileName + ".xml")); } catch (Exception ex) { RetVal = false; } if (MetadataInfo.Trim().Length > 0) { RetVal = true; //Write XLS and HTMLFile try { switch (metadataElementType) { case MetadataElementType.Area: //In Case Area Get Xslt associated with LayerNId (not with AreaNId) sSql = DIQueries.Xslt.GetXSLT(LayerNId.ToString(), metadataElementType); break; case MetadataElementType.Indicator: case MetadataElementType.Source: sSql = DIQueries.Xslt.GetXSLT(elementNId.ToString(), metadataElementType); break; default: break; } DataTable XSLTInfo = (DIConnection.ExecuteDataTable(sSql)); // If XSLT info was Found Write write Xsl and Html file if (XSLTInfo != null & XSLTInfo.Rows.Count > 0) { // Creating Xsl File String xslString = XSLTInfo.Rows[0]["XSLT_Text"].ToString(); WriteToFile(xslString, System.IO.Path.Combine(outputFolder, outputFileName + ".xsl")); //Write HTml file WriteHtmlFile(outputFolder, outputFileName); } } catch (Exception) { } //Extract Images associated with metadata try { if (metadataElementType == MetadataElementType.Area) { ExtractImage(LayerNId, IconElementType, DIConnection, DIQueries, outputFolder); } else { ExtractImage(elementNId, IconElementType, DIConnection, DIQueries, outputFolder); } } catch (Exception) { //Old database may not have Icon table } } infoTitle = infoTitle.Replace("&", "&&"); //label control do not display & character return(RetVal); }
/// <summary> /// To import IC and IUS realtionship into Indicator_Classification_IUS table /// </summary> /// <param name="NidInSourceDB"></param> /// <param name="NidinTargetDB"></param> /// <param name="classificationType"></param> /// <param name="srcQueries"></param> /// <param name="srcDBConnection"></param> public void ImportICAndIUSRelations(int NidInSourceDB, int NidinTargetDB, ICType classificationType, DIQueries srcQueries, DIConnection srcDBConnection) { // -- Create the IUS Links // -- STEP 1: Get the Indicator, Unit and Subgroup Names from the Source Database // -- STEP 2: Get IUSNIds from the Target Database against the I-U-S from the Source Database int TempIUSNId; int ClassificationNId; string IndicatorName; string UnitName; string SGVal; string IndicatorGID; string UnitGID; string SGValGID; bool RecommendedSource; DataTable TempTable = null; DataTable Table = null; // -- STEP 1: Get the Indicator, Unit and Subgroup Names from the Source Database TempTable = srcDBConnection.ExecuteDataTable(srcQueries.IUS.GetIUSByIC(classificationType, NidInSourceDB, FieldSelection.Light)); for (int Index = 0; Index <= TempTable.Rows.Count - 1; Index++) { try { // -- STEP 2: Get IUSNIds from the Target Database against the I-U-S from the Source Database IndicatorName = DICommon.RemoveQuotes(TempTable.Rows[Index][Indicator.IndicatorName].ToString()); UnitName = DICommon.RemoveQuotes(TempTable.Rows[Index][Unit.UnitName].ToString()); SGVal = DICommon.RemoveQuotes(TempTable.Rows[Index][SubgroupVals.SubgroupVal].ToString()); RecommendedSource = Convert.ToBoolean(TempTable.Rows[Index][IndicatorClassificationsIUS.RecommendedSource]); IndicatorGID = DICommon.RemoveQuotes(TempTable.Rows[Index][Indicator.IndicatorGId].ToString()); UnitGID = DICommon.RemoveQuotes(TempTable.Rows[Index][Unit.UnitGId].ToString()); SGValGID = DICommon.RemoveQuotes(TempTable.Rows[Index][SubgroupVals.SubgroupValGId].ToString()); // get records it by GID try { Table = this.DBConnection.ExecuteDataTable(this.DBQueries.IUS.GetIUSNIdsByGID( IndicatorGID, UnitGID, SGValGID)); } catch (Exception) { } // if records not found then get it by Name if (Table == null || Table.Rows.Count == 0) { Table = this.DBConnection.ExecuteDataTable(this.DBQueries.IUS.GetIUSByI_U_S_Name(IndicatorName, UnitName, SGVal, FieldSelection.Light)); } if (Table.Rows.Count > 0) { TempIUSNId = Convert.ToInt32(Table.Rows[0][Indicator_Unit_Subgroup.IUSNId]); //create relationship for parent_IC_NID also try { ClassificationNId = NidinTargetDB; while (true) { // -- Create IUS Relationship this.AddNUpdateICIUSRelation(ClassificationNId, TempIUSNId, RecommendedSource); //-- find parent IC_NId DataTable ICTable; try { ICTable = this.DBConnection.ExecuteDataTable(this.DBQueries.IndicatorClassification.GetIC(FilterFieldType.NId, ClassificationNId.ToString(), classificationType, FieldSelection.Light)); if (ICTable.Rows.Count > 0) { ClassificationNId = Convert.ToInt32(ICTable.Rows[0][IndicatorClassifications.ICParent_NId]); } else { ClassificationNId = -1; } } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } finally { if ((Table != null)) { Table.Dispose(); } Table = null; } if (ClassificationNId == -1) { break; } } } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } } } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } } }
/// <summary> /// To Import indicator classification into database or template /// </summary> /// <param name="ICInfo">Instance of IndicatorClassificationInfo</param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns>new indicator classification nid</returns> public int ImportIndicatorClassification(IndicatorClassificationInfo ICInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; bool ISTrgICGlobal = false; DataTable TempTable; try { //check item is already exist in database or not RetVal = this.GetIndicatorClassificationNid(ICInfo.GID, ICInfo.Name, ICInfo.Parent.Nid, ICInfo.Type); if (RetVal > 0) { // check target ic is global TempTable = this.DBConnection.ExecuteDataTable(this.DBQueries.IndicatorClassification.GetIC(FilterFieldType.NId, RetVal.ToString(), FieldSelection.Light)); if (TempTable.Rows.Count > 0) { ISTrgICGlobal = Convert.ToBoolean(TempTable.Rows[0][IndicatorClassifications.ICGlobal]); } // if target item is not global if (!ISTrgICGlobal) { //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DALQueries.IndicatorClassification.Update.UpdateIC(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, ICInfo.Name, ICInfo.GID, ICInfo.IsGlobal, ICInfo.Parent.Nid, ICInfo.ClassificationInfo, ICInfo.Type, RetVal)); } } else { if (this.InsertIntoDatabase(ICInfo)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } // update UT_CF_FLOWCHART table if (ICInfo.Type == ICType.CF) { string NewXMLText = "<?xml version=\"1.0\"?><!--AddFlow.net diagram--><AddFlow Nodes=\"1\" Links=\"0\"><Version>1.5.2.0</Version></AddFlow>"; DataTable SrcCFTable = null; DataTable TrgCFTable = null; try { // get node where URL ==NidInSourceDB SrcCFTable = sourceDBConnection.ExecuteDataTable(sourceQurey.IndicatorClassification.GetCFFlowCharts()); if (SrcCFTable.Rows.Count > 0) { string SrcXMLString = string.Empty; string TrgXMLString = string.Empty; // get xml from src database SrcXMLString = Convert.ToString(SrcCFTable.Rows[0][CFFlowChart.CF_FlowChart]); XmlDocument SrcXmlDoc = new XmlDocument(); SrcXmlDoc.LoadXml(SrcXMLString); SrcXmlDoc.PreserveWhitespace = true; //update Nid in src node XmlNodeList SrcNodeList = SrcXmlDoc.SelectNodes("/AddFlow/Node[./Url='" + NidInSourceDB + "']"); SrcNodeList.Item(0).LastChild.InnerText = RetVal.ToString(); // get target CF table XmlDocument TrgXmlDoc = new XmlDocument(); TrgXmlDoc.PreserveWhitespace = true; TrgCFTable = this.DBConnection.ExecuteDataTable(this.DBQueries.IndicatorClassification.GetCFFlowCharts()); if (TrgCFTable.Rows.Count > 0) { //update TrgXMLString = Convert.ToString(TrgCFTable.Rows[0][CFFlowChart.CF_FlowChart]); if (string.IsNullOrEmpty(TrgXMLString)) { TrgXMLString = NewXMLText; } TrgXmlDoc.LoadXml(TrgXMLString); XmlNodeList TrgNodeList = TrgXmlDoc.SelectNodes("/AddFlow/Node[./Url='" + RetVal + "']"); if (TrgNodeList != null & TrgNodeList.Count > 0) { TrgXmlDoc.SelectNodes("/AddFlow").Item(0).RemoveChild(TrgNodeList.Item(0)); } XmlNode SrcImpNode = SrcXmlDoc.SelectSingleNode("/AddFlow/Node[./Url='" + RetVal + "']"); //NewNode XmlNode NewNode = TrgXmlDoc.ImportNode(SrcImpNode, true); TrgXmlDoc.SelectNodes("/AddFlow").Item(0).AppendChild(NewNode); TrgXMLString = DICommon.IndentXMLString(TrgXmlDoc.InnerXml); TrgXMLString = DICommon.RemoveQuotes(TrgXMLString); //TrgXmlDoc.Save("c:\\testtest.xml"); this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.IndicatorClassification.Update.UpateCFFlowChart(this.DBQueries.TablesName.CFFlowChart, TrgXMLString)); } } } catch (Exception) { } } //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.IndicatorClassification, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// To Import metadata information /// </summary> /// <param name="dataPrefix"></param> /// <param name="sourceDBConnection"></param> /// <param name="sourceDBQueries"></param> /// <param name="selectedNIDs"></param> /// <param name="selectionCount"></param> /// <param name="metadataType"> </param> public void ImportICMetadata(string dataPrefix, DIConnection sourceDBConnection, DIQueries sourceDBQueries, string selectedNIDs, int selectionCount, MetaDataType metadataType, ICType classificationType) { string MetadataInfo = string.Empty; DataTable TempDataTable; DataTable TempTargetIdTable = new DataTable(); IndicatorClassificationBuilder ICBuilder; int TargetICNid = 0; int CurrentRecordIndex = 0; this.RaiseStartProcessEvent(); try { ICBuilder = new IndicatorClassificationBuilder(this.DBConnection, this.DBQueries); if (selectionCount == -1) { // -- GET ALL TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.None, string.Empty, classificationType, FieldSelection.Heavy)); } else { // -- GET SELECTED TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.NId, selectedNIDs, classificationType, FieldSelection.Heavy)); } // -- Initialize Progress Bar this.RaiseBeforeProcessEvent(TempDataTable.Rows.Count); CurrentRecordIndex = 0; for (int Index = 0; Index <= TempDataTable.Rows.Count - 1; Index++) { CurrentRecordIndex++; if (!Information.IsDBNull(TempDataTable.Rows[Index][IndicatorClassifications.ICInfo])) { if (!(TempDataTable.Rows[Index][IndicatorClassifications.ICInfo].ToString().Length == 0)) { //-- Retrieve Metadata Information MetadataInfo = TempDataTable.Rows[Index][IndicatorClassifications.ICInfo].ToString(); // Get Target IC NID by Source IC GID TargetICNid = ICBuilder.GetNidByGID(Convert.ToString(TempDataTable.Rows[Index][IndicatorClassifications.ICGId]), classificationType); if (TargetICNid > 0) { //-- Update Metadata ICBuilder.UpdateICInfo(TargetICNid, MetadataInfo); } } } // -- Increemnt the Progress Bar Value this.RaiseProcessInfoEvent(CurrentRecordIndex); } // -- Dispose the Data Table object TempDataTable.Dispose(); } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } }
/// <summary> /// Imports source metadata from template/database /// </summary> /// <param name="dataPrefix"></param> /// <param name="sourceDBConnection"></param> /// <param name="sourceDBQueries"></param> /// <param name="selectedNIDs"></param> /// <param name="selectionCount"></param> /// <param name="metadataType"></param> public void ImportSourceMetadata(string dataPrefix, DIConnection sourceDBConnection, DIQueries sourceDBQueries, string selectedNIDs, int selectionCount, MetaDataType metadataType) { DataTable TempDataTable; ICType ClassificationType; int CurrentRecordIndex = 0; int SrcElementNid; int TrgElementNid; DI7MetadataCategoryBuilder SourceMetadataCategoryBuilder; SourceBuilder ICBuilder; try { this.RaiseStartProcessEvent(); ICBuilder = new SourceBuilder(this.DBConnection, this.DBQueries); // import source categories SourceMetadataCategoryBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries); SourceMetadataCategoryBuilder.ImportAllMetadataCategories(sourceDBConnection, sourceDBQueries, MetadataElementType.Source); ClassificationType = ICType.Source; if (selectionCount == -1) { // -- GET ALL TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.None, string.Empty, ClassificationType, FieldSelection.Heavy)); } else { // -- GET SELECTED TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.NId, selectedNIDs, ClassificationType, FieldSelection.Heavy)); } ////// -- Initialize Progress Bar this.RaiseBeforeProcessEvent(TempDataTable.Rows.Count); CurrentRecordIndex = 0; foreach (DataRow Row in TempDataTable.Rows) { CurrentRecordIndex++; SrcElementNid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]); TrgElementNid = ICBuilder.CheckSourceExists(Convert.ToString(Row[IndicatorClassifications.ICName])); // import source metadadta if (TrgElementNid > 0) { this.ImportMetadata(sourceDBConnection, sourceDBQueries, SrcElementNid, TrgElementNid, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource); } ////// -- Increemnt the Progress Bar Value this.RaiseProcessInfoEvent(CurrentRecordIndex); } // -- Dispose the Data Table object TempDataTable.Dispose(); } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } }
/// <summary> /// Imports indicator metadata from template/database /// </summary> /// <param name="dataPrefix"></param> /// <param name="sourceDBConnection"></param> /// <param name="sourceDBQueries"></param> /// <param name="selectedNIDs"></param> /// <param name="selectionCount"></param> /// <param name="metadataType"></param> public void ImportIndicatorMetadata(string dataPrefix, DIConnection sourceDBConnection, DIQueries sourceDBQueries, string selectedNIDs, int selectionCount, MetaDataType metadataType) { DataTable TempDataTable; int CurrentRecordIndex = 0; DI7MetadataCategoryBuilder MetadataCategoryBuilderObj; IndicatorInfo SourceIndicatorInfo = new IndicatorInfo(); IndicatorBuilder IndBuilder = null; try { this.RaiseStartProcessEvent(); IndBuilder = new IndicatorBuilder(this.DBConnection, this.DBQueries); // 1. import metadta categories // import indicator metadata categories MetadataCategoryBuilderObj = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries); MetadataCategoryBuilderObj.ImportAllMetadataCategories(sourceDBConnection, sourceDBQueries, MetadataElementType.Indicator); // 2. Imort metadata reports if (selectionCount == -1) { // -- GET ALL TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.Indicators.GetIndicator(FilterFieldType.None, string.Empty, FieldSelection.Heavy)); } else { // -- GET SELECTED TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.Indicators.GetIndicator(FilterFieldType.NId, selectedNIDs, FieldSelection.Heavy)); } //////// -- Initialize Progress Bar this.RaiseBeforeProcessEvent(TempDataTable.Rows.Count); foreach (DataRow Row in TempDataTable.Rows) { CurrentRecordIndex++; // get source indicator info SourceIndicatorInfo = new IndicatorInfo(); SourceIndicatorInfo.Nid = Convert.ToInt32(Row[Indicator.IndicatorNId]); SourceIndicatorInfo.GID = Convert.ToString(Row[Indicator.IndicatorGId]); SourceIndicatorInfo.Name = Convert.ToString(Row[Indicator.IndicatorName]); SourceIndicatorInfo.Global = Convert.ToBoolean(Row[Indicator.IndicatorGlobal]); //import metadata IndBuilder.ImportIndicatorMetadata(SourceIndicatorInfo, SourceIndicatorInfo.Nid, sourceDBQueries, sourceDBConnection); // -- Increemnt the Progress Bar Value this.RaiseProcessInfoEvent(CurrentRecordIndex); } } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } finally { this.RaiseEndProcessEvent(); } }