/// <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); }