/// <summary> /// It Updates specified Theme with new Indicator, Units, Subgroups. ThemeType will be same for new Theme. /// </summary> /// <param name="OldTheme">Old theme to update.</param> /// <param name="newIndicatorNid">new Indicator NID for new Theme</param> /// <param name="newUnitNid">new UNit NID for new Theme</param> /// <param name="subgroupValNid">new Subgroup NID for new Theme</param> /// <returns>true, if updated success.</returns> public bool UpdateTheme(Theme OldTheme, string newIndicatorNid, string newUnitNid, string newSubgroupValNid) { bool RetVal = false; Theme NewTheme = null; Theme OldThemeClone = null; try { if ((OldTheme != null) && string.IsNullOrEmpty(newIndicatorNid) == false && string.IsNullOrEmpty(newUnitNid) == false && string.IsNullOrEmpty(newSubgroupValNid) == false) { OldTheme.ID = "TempThemeID"; OldThemeClone = (Theme)(OldTheme.Clone()); //'- Adding new Theme. NewTheme = this.CreateTheme(newIndicatorNid, newUnitNid, newSubgroupValNid, OldTheme.Type); if ((NewTheme == null) == false) { //-- Update new Theme's properties with Old theme. //-- Passing false because Legend's ranges and decimals will be re constructed from new dataValues fo new IUS this.UpdateThemeProperties(OldThemeClone, NewTheme, false, false); //-- Remove old theme from Collection. this.Themes.Remove(this.Themes.ItemIndex(OldTheme.ID)); } //-- update Map Title and Subtitle this.SetMapTitle(); RetVal = true; } } catch (Exception) { } return RetVal; }
/// <summary> /// It initializes Map by adding layers in it and creating Theme on the basis of current userSelections & PresentationDataView. /// </summary> /// <param name="preserveLegendsRanges">true, if Map's existing Legend's settings are required to preserve in new Legends when Map will initialize again.</param> public void Initialize(string p_ImageFolder, string spatialMapFolder, string CFLFolder, bool preserveLegendsRanges) { this.m_ImagePath = p_ImageFolder.Replace("\\", @"\"); this.m_SpatialMapFolder = spatialMapFolder; this.m_CFLPath = CFLFolder; string ExistingPolygonLayers = string.Empty; DataView dvAreaMapLayerInfo; DateTime dtStartDate; DateTime dtEndDate; DateTime dtTempStartDate = DateTime.Parse(DEFAULT_START_DATE).Date; DateTime dtTempEndDate = DateTime.Parse(DEFAULT_START_DATE).Date; CultureInfo ociEnUS = new CultureInfo("en-US", false); this.sbLayerNIDs = new StringBuilder(); this.sbLayerNames = new StringBuilder(); //-- Get the date range for which shapefiles are to be considered //-- handle different Reginal Settings - Thai, Arabic etc dtStartDate = DateTime.Parse(DEFAULT_START_DATE, ociEnUS).Date; dtEndDate = DateTime.Parse(DEFAULT_END_DATE, ociEnUS).Date; //-- CHECK if PresentationData has any record in it. //-- If NO Record found, then clear Themes and Layers. if (this.PresentationData != null && this.PresentationData.Count > 0) { string sSql = string.Empty; if (this.UserPreference.UserSelection.TimePeriodNIds.Length > 0) { // Get TimePeriod from Userselection. sSql = DIQueries.Timeperiod.GetTimePeriod(FilterFieldType.NId, this.UserPreference.UserSelection.TimePeriodNIds); } else { // Get TimePeriod from PresentationData. DataView dvTimeperiods = this.GetTimePeriods(); string TimeNids = string.Empty; for (int k = 0; k < dvTimeperiods.Count; k++) { if (TimeNids.Length > 0) { TimeNids += ","; } TimeNids += dvTimeperiods[k][Timeperiods.TimePeriodNId].ToString(); } sSql = DIQueries.Timeperiod.GetTimePeriod(FilterFieldType.NId, TimeNids); } //string sSql = DIQueries.Timeperiod.GetTimePeriod(FilterFieldType.NId, ""); System.Data.IDataReader dr = DIConnection.ExecuteReader(sSql); int i = 0; while (dr.Read()) { dtStartDate = DateTime.Parse(DEFAULT_START_DATE, ociEnUS).Date; dtEndDate = DateTime.Parse(DEFAULT_END_DATE, ociEnUS).Date; TimePeriodFacade.SetStartDateEndDate(dr[Timeperiods.TimePeriod].ToString(), ref dtTempStartDate, ref dtTempEndDate); if (i == 0) //For first time set dtStartDate dtEndDate { dtStartDate = dtTempStartDate; dtEndDate = dtTempEndDate; } else { if (System.DateTime.Compare(dtTempStartDate, dtStartDate) < 0) dtStartDate = dtTempStartDate; if (System.DateTime.Compare(dtTempEndDate, dtEndDate) > 0) dtEndDate = dtTempEndDate; } i++; } dr.Close(); dr.Dispose(); //*** Add Layer to Layers collection //-- get Areas present in DataView. string sAreaNIds = GetAreaNIds(); //-- Get & Merge Areas from DrillDown Collection. if (this._DrillDownAreaNIds.Count > 0) { sAreaNIds += "," + string.Join(",", this._DrillDownAreaNIds.ToArray()); } List<string> AreaNIds = new List<string>(sAreaNIds.Split(',')); /// Very Important: If total Area selected is more than 1000 then the /// "Query for All Areas and Area Map relation with complete info of Area Map Layer without SHP, SHX and DBF" /// takes a lot of time to execute. /// This also effects the loop below /// Query for All Areas and Area Map relation with complete info of Area Map Layer without SHP, SHX and DBF if (AreaNIds.Count > 1000) { /// TODO: Database based: One Time Process - Could be moved to some better location sSql = this.DIQueries.Area.GetAreaMapLayer(DevInfo.Lib.DI_LibDAL.Queries.Area.Select.MapFilterFieldType.AreaNId, "", FieldSelection.Light); } else { sSql = this.DIQueries.Area.GetAreaMapLayer(DevInfo.Lib.DI_LibDAL.Queries.Area.Select.MapFilterFieldType.AreaNId, sAreaNIds, FieldSelection.Light); } dvAreaMapLayerInfo = this.DIConnection.ExecuteDataTable(sSql).DefaultView; // Filter on Selected Area NIDs //dvAreaMapLayerInfo.RowFilter = Area.AreaNId + " in(" + sAreaNIds + ")"; //StringBuilder sbSortedAreaNIDs = new StringBuilder(); //sAreaNIds = "," + sAreaNIds + ","; //AreaNIds = DIConnection.GetDelimitedValuesFromDataTable(dvAreaMapLayerInfo.Table, Area.AreaNId).Split(','); // Query: Get all Shapes from the database (Layer_NId, SHP, SHX and DBF) // Prepare a DataView for that - LayerDataView // TODO: Database based: One Time Process - Could be moved to some better location //--sSql = this.DIQueries.Area.GetAreaMapLayerByNid("", FieldSelection.Light); //--DataTable dtLayerDataTable = this.DIConnection.ExecuteDataTable(sSql); //-- Get all Polygon layers (if existed in previous Layers Collection). //-- Important DO NOT Delete custom & Feature Layers as not required to be deleted in case of Gallery refresh. for (int p = 0; p < this.Layers.Count; p++) { if (this.Layers[p].LayerType == ShapeType.Polygon) { ExistingPolygonLayers += this.Layers[p].ID + "^"; } } //-- remove polygon layers which are NOT present in new Layer DataView foreach (string lyrId in ExistingPolygonLayers.Split('^')) { if (this.m_Layers.LayerIndex(lyrId.Trim()) >= 0) { // If DataView has a row for perticular LayerName, then delete it from Layers Collection if (dvAreaMapLayerInfo.Table.Select(Area_Map_Metadata.LayerName + " ='" + DICommon.RemoveQuotes(lyrId.Trim()) + "'").Length == 0) { this.m_Layers.RemoveAt(this.m_Layers.LayerIndex(lyrId.Trim())); } } } dvAreaMapLayerInfo.Sort = Area.AreaID + "," + Area_Map_Layer.EndDate; //get distinct layers by max end date dvAreaMapLayerInfo = this.GetDistinctLayersByMaxEndDate(dvAreaMapLayerInfo.Table).DefaultView; // Loop through the SELECTED Areas OR ALL AREAS of the database depending on the number of Areas selected. See above for more details //TODO preserve order of adding feature layer while adding to layer collection //foreach (string AreaNId in AreaNIds) //{ //// Make _drv for selected AreaNId //DataRow[] AreaMapRows = dvAreaMapLayerInfo.Table.Select(Area.AreaNId + " = " + AreaNId); //-- Loop each layer associated with this AreaNid, & add that layer in collection //foreach (DataRow drAreaMap in AreaMapRows) foreach (DataRow drAreaMap in dvAreaMapLayerInfo.Table.Rows) { try { if (AreaNIds.Contains(drAreaMap[Area.AreaNId].ToString())) { //Extarct Shape File from database // Get DataRow from the LayerDataView on the basis of the Layer NID available in the Loop //DataRow drLayer = dtLayerDataTable.Select(Area_Map_Layer.LayerNId + " = " + drAreaMap[Area_Map_Layer.LayerNId])[0]; string sShapeFileNamewoExtension = Path.Combine(spatialMapFolder, drAreaMap[Area_Map_Metadata.LayerName].ToString()); DateTime dUpdateTimeStamp = (DateTime)drAreaMap[Area_Map_Layer.UpdateTimestamp]; //*** Extract Files from database only if they doesn't exist in SpatialMap Folder or database contains a newer version of shape file if (!(File.Exists(sShapeFileNamewoExtension + ".shp") == true & System.DateTime.Compare(dUpdateTimeStamp, File.GetCreationTime(sShapeFileNamewoExtension + ".shp")) <= 0)) { Map.ExtractShapeFileByLayerId(drAreaMap[Area_Map_Layer.LayerNId].ToString(), this.SpatialMapFolder, this.DIConnection, this.DIQueries); } //Checking if same Layer ID already exists in Layers Collection, if yes then skip.. if (Layers[drAreaMap[Area_Map_Metadata.LayerName].ToString()] == null) //"Layer_Name" { #region "Old" ////*** BugFix 01 Feb 2006 Problem with different Reginal Settings - Thai, Arabic etc //dtTempStartDate = (System.DateTime)(Information.IsDBNull(drAreaMap[Area_Map_Layer.StartDate]) ? DateTime.Parse(DEFAULT_START_DATE, ociEnUS) : DateTime.Parse(((System.DateTime)drAreaMap[Area_Map_Layer.StartDate]).Month + "/" + ((System.DateTime)drAreaMap[Area_Map_Layer.StartDate]).Day + "/" + ((System.DateTime)drAreaMap[Area_Map_Layer.StartDate]).Year, ociEnUS)); //dtTempEndDate = (System.DateTime)(Information.IsDBNull(drAreaMap[Area_Map_Layer.EndDate]) ? DateTime.Parse(DEFAULT_END_DATE, ociEnUS) : DateTime.Parse(((System.DateTime)drAreaMap[Area_Map_Layer.EndDate]).Month + "/" + ((System.DateTime)drAreaMap[Area_Map_Layer.EndDate]).Day + "/" + ((System.DateTime)drAreaMap[Area_Map_Layer.EndDate]).Year, ociEnUS)); ////Get only those map files whose start date and end date are between Selected TimePeriods / Presentation data time periods //if (System.DateTime.Compare(dtTempEndDate, dtStartDate) < 0 | System.DateTime.Compare(dtTempStartDate, dtEndDate) > 0) //{ // //--- Do nothing // Console.Write(""); //} //else //{ //} #endregion ////Add Layer to Layers collection Layer _Layer = m_Layers.AddSpatialLayer(spatialMapFolder, drAreaMap[Area_Map_Metadata.LayerName].ToString()); if ((_Layer != null)) //if error while adding layer { // Store the Layer NIDs in the StringBuilder this.sbLayerNIDs.Append("," + drAreaMap[Area_Map_Layer.LayerNId]); this.sbLayerNames.Append("," + drAreaMap[Area_Map_Metadata.LayerName]); //////Set AreaNames for Layer ////sSql = this.DIQueries.Area.GetAreaByLayer(drAreaMap[Area_Map_Layer.LayerNId].ToString()); //////foreach (DataRowView _DRVL in m_QueryBase.Map_GetLayerNames(drAreaMap[Area_Map_Layer.LayerNId].ToString())) ////foreach (DataRowView _DRVL in this.DIConnection.ExecuteDataTable(sSql).DefaultView) ////{ //// _Layer.AreaNames.Add(_DRVL["Area_ID"].ToString(), _DRVL["Area_Name"].ToString()); ////} //Set Layer properties _Layer.LayerName = drAreaMap[Area_Map_Metadata.LayerName].ToString(); _Layer.Area_Level = int.Parse(drAreaMap[Area.AreaLevel].ToString()); _Layer.LayerType = (ShapeType)(int)drAreaMap[Area_Map_Layer.LayerType]; _Layer.StartDate = dtTempStartDate; _Layer.EndDate = dtTempEndDate; //Set property that point layer exists if (_Layer.LayerType == ShapeType.Point) this.m_PointShapeIncluded = true; //Set visibility off for feature layers by default switch (_Layer.LayerType) { case ShapeType.PointFeature: case ShapeType.PolygonFeature: case ShapeType.PolyLineFeature: _Layer.Visible = false; break; } } } } } catch (Exception ex) { //throw; } } // Get Area Names for all the Layer NIDs used - Background Process //FillAreaWorker = new Thread(new ThreadStart(this.FillAreaWorker_DoWork)); //FillAreaWorker.Start(); //-- Threading approch discared as it results into reader alreday open error sometimes this.FillAreaWorker_DoWork(); this.AddCustomFeatureLayers(); //Set Full Extent by default SetFullExtent(); //Create default theme implicitly for first time //In case of map loading from report need not to create this default theme if (this.m_Themes.Count == 0) { this.CreateTheme("-1", "-1", "-1", ThemeType.Color); // for default Theme, use "-1" as NIDs } else { // If Themes are already present then preserve IUS and ThemeType , and re-create Theme again. // New Theme is re-created on the basis of new PresentationData , new userSelection, and new Layers added.. // So Old Theme's settings must be restored in New Theme. Theme TempTheme = new Theme(); Theme NewTheme = null; string[] ThemeIdSettings; string ThemeId; string[] I_U_S_NIds = null; //-- NIds of I, U, S used in Theme for (int c = 0; c < this.Themes.Count; c++) { //_Theme.ID = p_IndicatorNId + "_" + p_UnitNId + "_" + p_SubgroupValNId + "_" + (int)p_ThemeType; TempTheme = this.Themes[c]; ThemeId = TempTheme.ID; TempTheme.ID = "TempThemeID"; // ID changed temperarily. TempTheme = (Theme)(TempTheme.Clone()); int TempThemeIndex = this.Themes.ItemIndex(ThemeId); ThemeIdSettings = ThemeId.Split('_'); //-- Get Nids of Indicator, Unit, Subgroupval used in Theme. on the basis of their GIDs I_U_S_NIds = this.GetI_U_S_NidsByGIDs(this._DIDataView.MainDataTable.DefaultView, TempTheme.I_U_S_GIDs[0], TempTheme.I_U_S_GIDs[1], TempTheme.I_U_S_GIDs[2]); //--Create Theme again and add it in same i th position in collection. try { // Check whather there is only one IUS in userSelection // if one, then IUS must have been changed outside(in Dynamic reports). so, createTheme for default. // if more than one, then createTheme for previus IUS if (this.UserPreference.UserSelection.ShowIUS) { if (this.UserPreference.UserSelection.IndicatorNIds.Split(',').Length == 1) { //if Single IUS, then create Default theme. if (TempTheme.Type == ThemeType.Chart) { NewTheme = this.CreateTheme("-1", "-1", "-1", (ThemeType)int.Parse(ThemeIdSettings[3]), TempTheme.ChartType, TempTheme.ChartSeriestype, c); } else { NewTheme = this.CreateTheme("-1", "-1", "-1", (ThemeType)int.Parse(ThemeIdSettings[3]), c); } } else { // Multiple IUS indicates that IUS are same as previous // so, UpdateTheme for same IUS if (TempTheme.Type == ThemeType.Chart) { NewTheme = this.CreateTheme(I_U_S_NIds[0], I_U_S_NIds[1], I_U_S_NIds[2], (ThemeType)int.Parse(ThemeIdSettings[3]), TempTheme.ChartType, TempTheme.ChartSeriestype, c); } else { NewTheme = this.CreateTheme(I_U_S_NIds[0], I_U_S_NIds[1], I_U_S_NIds[2], (ThemeType)int.Parse(ThemeIdSettings[3]), c); } //-- Set Theme Name same as Previous NewTheme.Name = TempTheme.Name; } } else { if (this.UserPreference.UserSelection.IndicatorNIds.Split(',').Length == 1 && this.UserPreference.UserSelection.UnitNIds.Split(',').Length == 1 && this.UserPreference.UserSelection.SubgroupValNIds.Split(',').Length == 1) { //if Single IUS, then create Default theme. NewTheme = this.CreateTheme("-1", "-1", "-1", (ThemeType)int.Parse(ThemeIdSettings[3]), c); } else { // Multiple IUS indicates that IUS is same as previous IUS in current Theme // so, UpdateTheme for prevoius IUS NewTheme = this.CreateTheme(I_U_S_NIds[0], I_U_S_NIds[1], I_U_S_NIds[2], (ThemeType)int.Parse(ThemeIdSettings[3]), c); //-- Set Theme Name same as Previous NewTheme.Name = TempTheme.Name; } } // Update new Theme with Old Theme's properties this.UpdateThemeProperties(TempTheme, NewTheme, preserveLegendsRanges, true); // remove old Theme this.Themes.Remove(this.Themes.ItemIndex("TempThemeID")); } catch (Exception ex) { //If theme already exists exception will be thrown ApplicationException("3") //If ThemeData.Count == 0 exception will be thrown ApplicationException("5") // Exception to be handled in Desktop web and reporting panel which call Initialize method throw ex; } } int RecordCount = m_Layers.RecordCounts(m_SpatialMapFolder); //-- Set visibility of color theme which was earlier set true when Map Serialized. this.ResetColorThemeVisibility(); //- Clear inset images of previous Themes (if any) try { foreach (Inset inset in this.m_Insets) { if (inset.InsetImage != null) { inset.InsetImage.Dispose(); inset.InsetImage = null; } } } catch { } } this.SetMapTitle(); } else // If No Record Found in Presentation Data, then Clear Themes & Layers collection. { this.Themes.Clear(); this.Layers.Clear(); } }