PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/Epi Info 7.1.4.0 Release - Web Enter Integration/EpiDashboard/Mapping/DotDensityServerLayerProperties.xaml.cs

#
C# | 282 lines | 246 code | 29 blank | 7 comment | 33 complexity | 6fb768931137846a46635f9d6fc4fa34 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Epi;
  15. using Epi.Fields;
  16. namespace EpiDashboard.Mapping
  17. {
  18. /// <summary>
  19. /// Interaction logic for ChoroplethLayerProperties.xaml
  20. /// </summary>
  21. public partial class DotDensityServerLayerProperties : UserControl, ILayerProperties
  22. {
  23. private ESRI.ArcGIS.Client.Map myMap;
  24. private DashboardHelper dashboardHelper;
  25. private DotDensityServerLayerProvider provider;
  26. private System.Xml.XmlElement currentElement;
  27. public event EventHandler MapGenerated;
  28. public event EventHandler FilterRequested;
  29. private IMapControl mapControl;
  30. private string shapeFilePath;
  31. public DotDensityServerLayerProperties(ESRI.ArcGIS.Client.Map myMap, DashboardHelper dashboardHelper, IMapControl mapControl)
  32. {
  33. InitializeComponent();
  34. this.myMap = myMap;
  35. this.dashboardHelper = dashboardHelper;
  36. this.mapControl = mapControl;
  37. provider = new DotDensityServerLayerProvider(myMap);
  38. provider.FeatureLoaded += new FeatureLoadedHandler(provider_FeatureLoaded);
  39. FillComboBoxes();
  40. mapControl.MapDataChanged += new EventHandler(mapControl_MapDataChanged);
  41. btnShapeFile.Click += new RoutedEventHandler(btnShapeFile_Click);
  42. cbxDataKey.SelectionChanged += new SelectionChangedEventHandler(keys_SelectionChanged);
  43. cbxShapeKey.SelectionChanged += new SelectionChangedEventHandler(keys_SelectionChanged);
  44. cbxValue.SelectionChanged += new SelectionChangedEventHandler(keys_SelectionChanged);
  45. rctDotColor.MouseUp += new MouseButtonEventHandler(rctDotColor_MouseUp);
  46. rctFilter.MouseUp += new MouseButtonEventHandler(rctFilter_MouseUp);
  47. }
  48. void provider_FeatureLoaded(string serverName, IDictionary<string, object> featureAttributes)
  49. {
  50. if (!string.IsNullOrEmpty(serverName))
  51. {
  52. shapeFilePath = serverName;
  53. if (featureAttributes != null)
  54. {
  55. cbxShapeKey.Items.Clear();
  56. foreach (string key in featureAttributes.Keys)
  57. {
  58. cbxShapeKey.Items.Add(key);
  59. }
  60. }
  61. }
  62. if (currentElement != null)
  63. {
  64. foreach (System.Xml.XmlElement child in currentElement.ChildNodes)
  65. {
  66. if (child.Name.Equals("dataKey"))
  67. {
  68. cbxDataKey.SelectedItem = child.InnerText;
  69. }
  70. if (child.Name.Equals("shapeKey"))
  71. {
  72. cbxShapeKey.SelectedItem = child.InnerText;
  73. }
  74. if (child.Name.Equals("value"))
  75. {
  76. cbxValue.SelectedItem = child.InnerText;
  77. }
  78. if (child.Name.Equals("dotValue"))
  79. {
  80. txtDotValue.Text = child.InnerText;
  81. }
  82. if (child.Name.Equals("dotColor"))
  83. {
  84. rctDotColor.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(child.InnerText));
  85. }
  86. }
  87. RenderMap();
  88. }
  89. }
  90. void rctFilter_MouseUp(object sender, MouseButtonEventArgs e)
  91. {
  92. if (FilterRequested != null)
  93. {
  94. FilterRequested(this, new EventArgs());
  95. }
  96. }
  97. public void MoveUp()
  98. {
  99. provider.MoveUp();
  100. }
  101. public void MoveDown()
  102. {
  103. provider.MoveDown();
  104. }
  105. void rctDotColor_MouseUp(object sender, MouseButtonEventArgs e)
  106. {
  107. System.Windows.Forms.ColorDialog dialog = new System.Windows.Forms.ColorDialog();
  108. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  109. {
  110. rctDotColor.Fill = new SolidColorBrush(Color.FromArgb(0xF0, dialog.Color.R, dialog.Color.G, dialog.Color.B));
  111. RenderMap();
  112. }
  113. }
  114. private void RenderMap()
  115. {
  116. //System.ComponentModel.BackgroundWorker worker = new System.ComponentModel.BackgroundWorker();
  117. //worker.DoWork += new System.ComponentModel.DoWorkEventHandler(worker_DoWork);
  118. //worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
  119. //worker.RunWorkerAsync();
  120. if (cbxDataKey.SelectedIndex != -1 && cbxShapeKey.SelectedIndex != -1 && cbxValue.SelectedIndex != -1)
  121. {
  122. provider.SetShapeRangeValues(dashboardHelper, cbxShapeKey.SelectedItem.ToString(), cbxDataKey.SelectedItem.ToString(), cbxValue.SelectedItem.ToString(), ((SolidColorBrush)rctDotColor.Fill).Color, int.Parse(txtDotValue.Text));
  123. if (MapGenerated != null)
  124. {
  125. MapGenerated(this, new EventArgs());
  126. }
  127. }
  128. }
  129. void worker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
  130. {
  131. if (cbxDataKey.SelectedIndex != -1 && cbxShapeKey.SelectedIndex != -1 && cbxValue.SelectedIndex != -1)
  132. {
  133. provider.SetShapeRangeValues(dashboardHelper, cbxShapeKey.SelectedItem.ToString(), cbxDataKey.SelectedItem.ToString(), cbxValue.SelectedItem.ToString(), ((SolidColorBrush)rctDotColor.Fill).Color, int.Parse(txtDotValue.Text));
  134. if (MapGenerated != null)
  135. {
  136. MapGenerated(this, new EventArgs());
  137. }
  138. }
  139. }
  140. void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
  141. {
  142. System.Threading.Thread.Sleep(10000);
  143. }
  144. public StackPanel LegendStackPanel
  145. {
  146. get
  147. {
  148. return provider.LegendStackPanel;
  149. }
  150. }
  151. public DashboardHelper GetDashboardHelper()
  152. {
  153. return this.dashboardHelper;
  154. }
  155. void mapControl_MapDataChanged(object sender, EventArgs e)
  156. {
  157. provider.Refresh();
  158. }
  159. void keys_SelectionChanged(object sender, EventArgs e)
  160. {
  161. RenderMap();
  162. }
  163. void btnShapeFile_Click(object sender, RoutedEventArgs e)
  164. {
  165. provider.LoadShapeFile();
  166. }
  167. private void FillComboBoxes()
  168. {
  169. cbxDataKey.Items.Clear();
  170. cbxValue.Items.Clear();
  171. ColumnDataType columnDataType = ColumnDataType.Boolean | ColumnDataType.DateTime | ColumnDataType.Numeric | ColumnDataType.Text | ColumnDataType.UserDefined;
  172. List<string> fields = dashboardHelper.GetFieldsAsList(columnDataType); // dashboardHelper.GetFormFields();
  173. columnDataType = ColumnDataType.Numeric;
  174. List<string> numericFields = dashboardHelper.GetFieldsAsList(columnDataType); //dashboardHelper.GetNumericFormFields();
  175. foreach (string field in fields)
  176. {
  177. cbxDataKey.Items.Add(field);
  178. }
  179. foreach (string field in numericFields)
  180. {
  181. cbxValue.Items.Add(field);
  182. }
  183. cbxValue.Items.Insert(0, "{Record Count}");
  184. }
  185. #region ILayerProperties Members
  186. public void CloseLayer()
  187. {
  188. provider.CloseLayer();
  189. }
  190. public Color FontColor
  191. {
  192. set
  193. {
  194. SolidColorBrush brush = new SolidColorBrush(value);
  195. lblDataKey.Foreground = brush;
  196. lblShapeKey.Foreground = brush;
  197. lblValueField.Foreground = brush;
  198. }
  199. }
  200. public void MakeReadOnly()
  201. {
  202. this.FontColor = Colors.Black;
  203. cbxDataKey.IsEnabled = false;
  204. cbxShapeKey.IsEnabled = false;
  205. cbxValue.IsEnabled = false;
  206. txtDotValue.IsReadOnly = true;
  207. btnShapeFile.Visibility = Visibility.Collapsed;
  208. grdMain.Width = 700;
  209. lblTitle.Visibility = System.Windows.Visibility.Visible;
  210. }
  211. public System.Xml.XmlNode Serialize(System.Xml.XmlDocument doc)
  212. {
  213. string connectionString = string.Empty;
  214. string tableName = string.Empty;
  215. string projectPath = string.Empty;
  216. string viewName = string.Empty;
  217. if (dashboardHelper.View == null)
  218. {
  219. connectionString = dashboardHelper.Database.ConnectionString;
  220. tableName = dashboardHelper.TableName;
  221. }
  222. else
  223. {
  224. projectPath = dashboardHelper.View.Project.FilePath;
  225. viewName = dashboardHelper.View.Name;
  226. }
  227. string dataKey = cbxDataKey.SelectedItem.ToString();
  228. string shapeKey = cbxShapeKey.SelectedItem.ToString();
  229. string value = cbxValue.SelectedItem.ToString();
  230. SolidColorBrush dotColor = (SolidColorBrush)rctDotColor.Fill;
  231. string xmlString = "<shapeFile>" + shapeFilePath + "</shapeFile><dotColor>" + dotColor.Color.ToString() + "</dotColor><dotValue>" + txtDotValue.Text + "</dotValue><dataKey>" + dataKey + "</dataKey><shapeKey>" + shapeKey + "</shapeKey><value>" + value + "</value>";
  232. System.Xml.XmlElement element = doc.CreateElement("dataLayer");
  233. element.InnerXml = xmlString;
  234. element.AppendChild(dashboardHelper.Serialize(doc));
  235. System.Xml.XmlAttribute type = doc.CreateAttribute("layerType");
  236. type.Value = "EpiDashboard.Mapping.DotDensityServerLayerProperties";
  237. element.Attributes.Append(type);
  238. return element;
  239. }
  240. public void CreateFromXml(System.Xml.XmlElement element)
  241. {
  242. currentElement = element;
  243. foreach (System.Xml.XmlElement child in element.ChildNodes)
  244. {
  245. if (child.Name.Equals("shapeFile"))
  246. {
  247. provider.LoadShapeFile(child.InnerText);
  248. }
  249. }
  250. }
  251. #endregion
  252. }
  253. }