PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/IntelWebSite/wfIntelWebMap.aspx.cs

https://github.com/sirivedula/IntelWebPro
C# | 203 lines | 180 code | 14 blank | 9 comment | 8 complexity | d5a01004d866d337ee1a4d0c93c6bc22 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.OleDb;
  8. using System.Data;
  9. using IntelWeb;
  10. namespace IntelWebSite
  11. {
  12. public partial class wfIntelWebMap : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. }
  17. protected void Page_LoadComplete(object sender, EventArgs e)
  18. {
  19. CurrentUser cuser = new CurrentUser();
  20. cuser.userName = "Balaji";
  21. cuser.Load();
  22. string formTier = Request.Form["tiercode"] ?? "";
  23. string formdept = Request.Form["deptcode"] ?? "";
  24. string formfdate = Request.Form["fromdate"] ?? "";
  25. string formtdate = Request.Form["todate"] ?? "";
  26. // Testing
  27. if (string.IsNullOrEmpty(formfdate)) formfdate = "04/01/2011";
  28. if (string.IsNullOrEmpty(formtdate)) formtdate = "04/30/2011";
  29. /*
  30. * if (string.IsNullOrEmpty(formfdate)) formfdate = DateTime.Today.ToString("MM/dd/yyyy");
  31. * if (string.IsNullOrEmpry(formtdate)) formtdate = DateTime.Today.AddMonths(1).ToString("MM/dd/yyyy");
  32. */
  33. lkup_tier tier = new lkup_tier(cuser);
  34. List<IntelWebObject> tiers = tier.Load();
  35. this.ltrTiers.Text = "<option value=\"\"></option>" + string.Join("", tiers.Cast<lkup_tier>().Select(x=>"<option value=\"" + HttpUtility.HtmlEncode(x.tier_code) + "\" " + (formTier.Equals(x.tier_code)?"selected":"") + " >" + HttpUtility.HtmlEncode(x.tier_code) + "</option>").ToArray());
  36. lkup_department lkupDept = new lkup_department(cuser);
  37. List<IntelWebObject> lkupDepts = lkupDept.Load();
  38. this.ltrDepts.Text = "<option value=\"\"></option>" + string.Join("", lkupDepts.Cast<lkup_department>().Select(x => "<option value=\"" + HttpUtility.HtmlEncode(x.department_code) + "\" " + (formdept.Equals(x.department_code)?"selected":"") + " >" + HttpUtility.HtmlEncode(x.department_code + " (" + x.department_code_description + ")") + "</option>").ToArray());
  39. tbl_alarm_time_details alarmDet = new tbl_alarm_time_details(cuser);
  40. List<IntelWebField> bparams = new List<IntelWebField>();
  41. IntelWebField tierFld = alarmDet.Field("tier_code");
  42. tierFld.fieldValue = formTier;
  43. IntelWebField deptFld = alarmDet.Field("department_code");
  44. deptFld.fieldValue = formdept;
  45. IntelWebField fdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, formfdate);
  46. IntelWebField tdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, formtdate);
  47. bparams.Add(tierFld);
  48. bparams.Add(deptFld);
  49. bparams.Add(fdateFld);
  50. bparams.Add(tdateFld);
  51. List<IntelWebObject> alaramDets = alarmDet.Load("tier_code=? and department_code=? and alarm_date between ? and ?", "site_code,panel_code,alarm_device_code", bparams);
  52. if (alaramDets.Count > 0)
  53. {
  54. var distSites = alaramDets.Select(x => x.Field("site_code").fieldValue ?? "").Distinct().ToList();
  55. /* Distinct Sites get Address City, State, Country */
  56. lkup_site lkupsite = new lkup_site(cuser);
  57. bparams.Clear();
  58. string qs = "";
  59. foreach (string site in distSites)
  60. {
  61. qs += ("?,");
  62. IntelWebField fld = new IntelWebField("site_code", OleDbType.VarChar, 50, 50, 0, DataRowVersion.Current, false, null);
  63. fld.fieldValue = site;
  64. bparams.Add(fld);
  65. }
  66. bparams.Add(IntelWebParameter.GetParam("deptcode", OleDbType.VarChar, 50, formdept));
  67. if (qs.Length > 0) qs = qs.Substring(0, qs.Length - 1);
  68. List<IntelWebObject> Sites = lkupsite.Load("(site_code in (" + qs + ") or department_code=?)and city is not null ", "city", bparams);
  69. Dictionary<string, string> distCities = new Dictionary<string, string>();
  70. foreach (lkup_site site in Sites)
  71. {
  72. string mapcity = site.city + (((site.state_code ?? "").Length > 0) ? "," + site.state_code.Trim() : "");
  73. string siteDets = site.site_code + "\t" + site.address1 + "\t" + site.address2 + "\t" + site.city + "\t" + site.country_code;
  74. if (distCities.ContainsKey(mapcity))
  75. {
  76. distCities[mapcity] = distCities[mapcity] + "\n" + siteDets;
  77. }
  78. else
  79. {
  80. distCities.Add(mapcity, siteDets);
  81. }
  82. }
  83. string jsCities = "[";
  84. foreach (string key in distCities.Keys)
  85. {
  86. jsCities += "{\"address\":\"" + key + "\",\"sitesHtml\":\"";
  87. string[] arySites = distCities[key].Split('\n');
  88. jsCities += "<table style=\\\"width:95%;\\\"><tr>";
  89. foreach (string st in arySites)
  90. {
  91. string[] arySiteAddr = st.Split('\t');
  92. jsCities += "<td>";
  93. if (arySiteAddr.Length > 0)
  94. {
  95. jsCities += "<div><img style=\\\"cursor:pointer;\\\" onclick=\\\"showDiv(this, '" + arySiteAddr[0] + "');\\\" src=\'Images/house.png\' alt=\'site\' /> " + JSUtil.EnquoteJS(HttpUtility.HtmlEncode(arySiteAddr[0])) + " </div>";
  96. }
  97. if(arySiteAddr.Length > 3)
  98. {
  99. jsCities += "<div style=\\\"border:1px solid #999;padding:2px;white-space:nowrap;\\\"><div>" + JSUtil.EnquoteJS(HttpUtility.HtmlEncode(arySiteAddr[1])) + "</div><div>" + JSUtil.EnquoteJS(HttpUtility.HtmlEncode(arySiteAddr[2])) + "</div><div>" + JSUtil.EnquoteJS(HttpUtility.HtmlEncode(arySiteAddr[3] + " " + arySiteAddr[4])) + "</div></div>";
  100. }
  101. jsCities += "</td>";
  102. //<br />" + st + "<br /> Peak:50 <br />Non-Peak:20</td>";
  103. }
  104. jsCities += "</tr></table>\"},";
  105. }
  106. if (distCities.Count > 0) jsCities = jsCities.Substring(0, jsCities.Length - 1);
  107. jsCities += "];";
  108. /* Map Script STARTS */
  109. ltrMapScript.Text = @"<script type=""text/javascript"">
  110. jsMapCities = " + jsCities + @"
  111. jsFromDate = '" + formfdate + @"';
  112. jsToDate = '" + formtdate + @"';
  113. function mapInit(){
  114. if (GBrowserIsCompatible()) {
  115. var map = new GMap2(document.getElementById('map_canvas'));
  116. map.addControl(new GLargeMapControl());
  117. map.addControl(new GMapTypeControl());
  118. map.addControl(new GOverviewMapControl());
  119. map.enableScrollWheelZoom();
  120. map.setCenter(new GLatLng(39, -93), 4);
  121. map.setUIToDefault();
  122. var bounds = new GLatLngBounds();
  123. geocoder = new GClientGeocoder();
  124. function createMarker(address, thtml, cnt){
  125. // Creates the customized marker icon
  126. var blueIcon = new GIcon(G_DEFAULT_ICON);
  127. if(cnt % 2 == 0) {
  128. blueIcon.image = ""http://iweb.vasbal.com/images/grn-pushpin.png"";
  129. } else if(cnt % 3 == 0) {
  130. blueIcon.image = ""http://iweb.vasbal.com/images/red-pushpin.png"";
  131. } else {
  132. blueIcon.image = ""http://iweb.vasbal.com/images/ylw-pushpin.png"";
  133. }
  134. blueIcon.iconSize = new GSize(32, 32);
  135. // Set up our GMarkerOptions object
  136. var markerOptions = { icon:blueIcon };
  137. if(geocoder){
  138. geocoder.getLatLng(address, function(point) {
  139. if (point) {
  140. var marker = new GMarker(point, markerOptions);
  141. map.addOverlay(marker);
  142. bounds.extend(marker.getPoint());
  143. var mhtml = thtml;
  144. var mklatlng = new GLatLng(marker.getPoint().lat(), marker.getPoint().lng());
  145. GEvent.addListener(marker, ""click"", function () { map.openInfoWindowHtml(mklatlng, '<div>'+mhtml+'</div>'); });
  146. GEvent.addListener(marker, ""mouseover"", function () { map.openInfoWindowHtml(mklatlng, '<div>'+mhtml+'</div>'); });
  147. }
  148. });
  149. }
  150. }
  151. map.clearOverlays();
  152. var cnt = 0;
  153. for(var x in jsMapCities){
  154. createMarker(jsMapCities[x].address, jsMapCities[x].sitesHtml, cnt);
  155. cnt++;
  156. }
  157. }
  158. }
  159. </script>";
  160. /* End Script */
  161. }
  162. else
  163. {
  164. ltrMessage.Text = @"<div class=""ui-widget"">
  165. <div class=""ui-state-error ui-corner-all"" style=""width:70%;margin-left:200px;margin-top: 5px; padding: 0 .7em;"">
  166. <p style=""height:35px;""><span class=""ui-icon ui-icon-alert"" style=""float: left; margin-right: .3em;""></span>
  167. <strong>Alert:</strong>There are no alarm details found between selected date period.</p></div></div>";
  168. ltrMapScript.Text = @"<script type=""text/javascript"">
  169. function mapInit(){
  170. if (GBrowserIsCompatible()) {
  171. var map = new GMap2(document.getElementById('map_canvas'));
  172. map.addControl(new GLargeMapControl());
  173. map.addControl(new GMapTypeControl());
  174. map.addControl(new GOverviewMapControl());
  175. map.enableScrollWheelZoom();
  176. map.setCenter(new GLatLng(39, -93), 4);
  177. map.setUIToDefault();
  178. }
  179. }
  180. </script>";
  181. }
  182. }
  183. }
  184. }