protected void Page_LoadComplete(object sender, EventArgs e)
        {
            CurrentUser cuser = new CurrentUser();
            cuser.userName = "******";
            cuser.Load();

            string tiercode = Request.QueryString["tiercode"];
            string deptcode = Request.QueryString["deptcode"];
            string sitecode = Request.QueryString["sitecode"];
            string panelcode = Request.QueryString["panelcode"];
            string devicecode = Request.QueryString["devicecode"];
            string fromdate = Request.QueryString["fdate"];
            string todate = Request.QueryString["tdate"];

            tbl_alarm_time_details alarmDet = new tbl_alarm_time_details(cuser);
            IntelWebField tierFld = alarmDet.Field("tier_code");
            tierFld.fieldValue = tiercode;
            IntelWebField deptFld = alarmDet.Field("department_code");
            deptFld.fieldValue = deptcode;
            IntelWebField siteFld = alarmDet.Field("site_code");
            siteFld.fieldValue = sitecode;
            IntelWebField panelFld = alarmDet.Field("panel_code");
            panelFld.fieldValue = panelcode;
            IntelWebField deviceFld = alarmDet.Field("alarm_device_code");
            deviceFld.fieldValue = devicecode;
            IntelWebField fdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, fromdate);
            IntelWebField tdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, todate);
            List<IntelWebField> bparam = new List<IntelWebField>();
            bparam.Add(tierFld);
            bparam.Add(deptFld);
            bparam.Add(siteFld);
            bparam.Add(panelFld);
            bparam.Add(deviceFld);
            bparam.Add(fdateFld);
            bparam.Add(tdateFld);
            List<IntelWebObject> alarmDets = alarmDet.Load("tier_code=? and department_code=? and site_code=? and panel_code=? and alarm_device_code=? and alarm_date between ? and ?", "alarm_date,alarm_time", bparam);
            if (alarmDets.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<table style=\"width:100%;\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"webgrid\"><thead class=\"titlegrid\"><tr><th>Device</th><th>Alarm Date</th><th>Alarm Hour</th><th>Alaram Time</th><th>Alarm Details</th><th>Alarm Comment</th></tr>");
                int rowCnt = 0;
                foreach (tbl_alarm_time_details alarm in alarmDets)
                {
                    string trclass = (rowCnt % 2 == 0 ? "" : " class=\"gridodd\" ");
                    sb.Append("<tr" + trclass + "><td>" + HttpUtility.HtmlEncode(alarm.alarm_device_code) + "</td><td>" + HttpUtility.HtmlEncode(alarm.alarm_date.ToString("MM/dd/yyyy")) + "</td><td>" + HttpUtility.HtmlEncode(alarm.alarm_hour) + "</td><td>" + HttpUtility.HtmlEncode(alarm.alarm_time) + "</td><td>" + HttpUtility.HtmlEncode(alarm.alarm_details) + "</td><td>" + HttpUtility.HtmlEncode(alarm.alarm_comment) + "</td></tr>");
                    rowCnt++;
                }
                sb.Append("</table>");

                Response.Write(sb.ToString());
            }
            else
            {
                Response.Write("There are no details found.");
            }
        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            CurrentUser cuser = new CurrentUser();
            cuser.userName = "******";
            cuser.Load();

            string tiercode = Request.QueryString["tiercode"];
            string deptcode = Request.QueryString["deptcode"];
            string sitecode = Request.QueryString["sitecode"];
            string fromdate = Request.QueryString["fdate"];
            string todate = Request.QueryString["tdate"];

            tbl_alarm_time_details alarmDet = new tbl_alarm_time_details(cuser);
            IntelWebField tierFld = alarmDet.Field("tier_code");
            tierFld.fieldValue = tiercode;
            IntelWebField deptFld = alarmDet.Field("department_code");
            deptFld.fieldValue = deptcode;
            IntelWebField siteFld = alarmDet.Field("site_code");
            siteFld.fieldValue = sitecode;
            IntelWebField fdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, fromdate);
            IntelWebField tdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, todate);
            List<IntelWebField> bparam = new List<IntelWebField>();
            bparam.Add(tierFld);
            bparam.Add(deptFld);
            bparam.Add(siteFld);
            bparam.Add(fdateFld);
            bparam.Add(tdateFld);
            List<IntelWebObject> alarmDets = alarmDet.Load("tier_code=? and department_code=? and site_code=? and alarm_date between ? and ?", "panel_code", bparam);
            if (alarmDets.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                /* Panels Table */
                sb.Append("<table><tr>");
                var distPanels = alarmDets.Select(x => x.Field("panel_code").fieldValue ?? "").Distinct();
                foreach (string panel in distPanels)
                {
                    sb.Append("<td>" + AlaramDeviceHTML(sitecode, panel, alarmDets) + "</td>");
                }

                sb.Append("</tr></table>");

                Response.Write(sb.ToString());
            }
            else
            {
                Response.Write("There are no details found.");
            }
        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            CurrentUser cuser = new CurrentUser();
            cuser.userName = "******";
            cuser.Load();

            string formTier = Request.Form["tiercode"] ?? "";
            string formdept = Request.Form["deptcode"] ?? "";
            string formfdate = Request.Form["fromdate"] ?? "";
            string formtdate = Request.Form["todate"] ?? "";

            // Testing
            if (string.IsNullOrEmpty(formfdate)) formfdate = "04/01/2011";
            if (string.IsNullOrEmpty(formtdate)) formtdate = "04/30/2011";

            /*
             * if (string.IsNullOrEmpty(formfdate)) formfdate = DateTime.Today.ToString("MM/dd/yyyy");
             * if (string.IsNullOrEmpry(formtdate)) formtdate = DateTime.Today.AddMonths(1).ToString("MM/dd/yyyy");
            */

            lkup_tier tier = new lkup_tier(cuser);
            List<IntelWebObject> tiers = tier.Load();
            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());

            lkup_department lkupDept = new lkup_department(cuser);
            List<IntelWebObject> lkupDepts = lkupDept.Load();
            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());

            tbl_alarm_time_details alarmDet = new tbl_alarm_time_details(cuser);
            List<IntelWebField> bparams = new List<IntelWebField>();
            IntelWebField tierFld = alarmDet.Field("tier_code");
            tierFld.fieldValue = formTier;
            IntelWebField deptFld = alarmDet.Field("department_code");
            deptFld.fieldValue = formdept;
            IntelWebField fdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, formfdate);
            IntelWebField tdateFld = new IntelWebField("todate", OleDbType.DBDate, 10, 10, 0, DataRowVersion.Current, false, formtdate);
            bparams.Add(tierFld);
            bparams.Add(deptFld);
            bparams.Add(fdateFld);
            bparams.Add(tdateFld);

            List<IntelWebObject> alaramDets = alarmDet.Load("tier_code=? and department_code=? and alarm_date between ? and ?", "site_code,panel_code,alarm_device_code", bparams);
            if (alaramDets.Count > 0)
            {
                var distSites = alaramDets.Select(x => x.Field("site_code").fieldValue ?? "").Distinct().ToList();
                /* Distinct Sites get Address City, State, Country */
                lkup_site lkupsite = new lkup_site(cuser);
                bparams.Clear();
                string qs = "";
                foreach (string site in distSites)
                {
                    qs += ("?,");
                    IntelWebField fld = new IntelWebField("site_code", OleDbType.VarChar, 50, 50, 0, DataRowVersion.Current, false, null);
                    fld.fieldValue = site;
                    bparams.Add(fld);
                }
                bparams.Add(IntelWebParameter.GetParam("deptcode", OleDbType.VarChar, 50, formdept));
                if (qs.Length > 0) qs = qs.Substring(0, qs.Length - 1);
                List<IntelWebObject> Sites = lkupsite.Load("(site_code in (" + qs + ") or department_code=?)and city is not null ", "city", bparams);
                Dictionary<string, string> distCities = new Dictionary<string, string>();
                foreach (lkup_site site in Sites)
                {
                    string mapcity = site.city + (((site.state_code ?? "").Length > 0) ? "," + site.state_code.Trim() : "");
                    string siteDets = site.site_code + "\t" + site.address1 + "\t" + site.address2 + "\t" + site.city + "\t" + site.country_code;
                    if (distCities.ContainsKey(mapcity))
                    {
                        distCities[mapcity] = distCities[mapcity] + "\n" + siteDets;
                    }
                    else
                    {
                        distCities.Add(mapcity, siteDets);
                    }
                }

                string jsCities = "[";
                foreach (string key in distCities.Keys)
                {
                    jsCities += "{\"address\":\"" + key + "\",\"sitesHtml\":\"";
                    string[] arySites = distCities[key].Split('\n');
                    jsCities += "<table style=\\\"width:95%;\\\"><tr>";
                    foreach (string st in arySites)
                    {
                        string[] arySiteAddr = st.Split('\t');
                        jsCities += "<td>";
                        if (arySiteAddr.Length > 0)
                        {
                            jsCities += "<div><img style=\\\"cursor:pointer;\\\" onclick=\\\"showDiv(this, '" + arySiteAddr[0] + "');\\\" src=\'Images/house.png\' alt=\'site\' /> " + JSUtil.EnquoteJS(HttpUtility.HtmlEncode(arySiteAddr[0])) + " </div>";
                        }
                        if(arySiteAddr.Length > 3)
                        {
                            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>";
                        }
                        jsCities += "</td>";
                        //<br />" + st + "<br />   Peak:50 <br />Non-Peak:20</td>";
                    }
                    jsCities += "</tr></table>\"},";
                }
                if (distCities.Count > 0) jsCities = jsCities.Substring(0, jsCities.Length - 1);
                jsCities += "];";

                /* Map Script STARTS */
                ltrMapScript.Text = @"<script type=""text/javascript"">
                jsMapCities = " + jsCities + @"
                jsFromDate = '" + formfdate + @"';
                jsToDate = '" + formtdate + @"';
                function mapInit(){
                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById('map_canvas'));
                        map.addControl(new GLargeMapControl());
                        map.addControl(new GMapTypeControl());
                        map.addControl(new GOverviewMapControl());
                        map.enableScrollWheelZoom();
                        map.setCenter(new GLatLng(39, -93), 4);
                        map.setUIToDefault();
                        var bounds = new GLatLngBounds();
                        geocoder = new GClientGeocoder();

                        function createMarker(address, thtml, cnt){
                            // Creates the  customized marker icon
                            var blueIcon = new GIcon(G_DEFAULT_ICON);
                            if(cnt % 2 == 0) {
                                blueIcon.image = ""http://iweb.vasbal.com/images/grn-pushpin.png"";
                            } else if(cnt % 3 == 0) {
                                blueIcon.image = ""http://iweb.vasbal.com/images/red-pushpin.png"";
                            } else {
                                blueIcon.image = ""http://iweb.vasbal.com/images/ylw-pushpin.png"";
                            }
                            blueIcon.iconSize = new GSize(32, 32);

                            // Set up our GMarkerOptions object
                            var markerOptions = { icon:blueIcon };

                            if(geocoder){
                                geocoder.getLatLng(address, function(point) {
                                        if (point) {
                                            var marker = new GMarker(point, markerOptions);
                                            map.addOverlay(marker);
                                            bounds.extend(marker.getPoint());
                                            var mhtml = thtml;
                                            var mklatlng = new GLatLng(marker.getPoint().lat(), marker.getPoint().lng());
                                            GEvent.addListener(marker, ""click"", function () { map.openInfoWindowHtml(mklatlng, '<div>'+mhtml+'</div>'); });
                                            GEvent.addListener(marker, ""mouseover"", function () { map.openInfoWindowHtml(mklatlng, '<div>'+mhtml+'</div>'); });

                                        }
                                });
                            }
                        }

                        map.clearOverlays();
                        var cnt = 0;
                        for(var x in jsMapCities){
                            createMarker(jsMapCities[x].address, jsMapCities[x].sitesHtml, cnt);
                            cnt++;
                        }
                    }
                }
                </script>";
                /* End Script */
            }
            else
            {
                ltrMessage.Text = @"<div class=""ui-widget"">
                <div class=""ui-state-error ui-corner-all"" style=""width:70%;margin-left:200px;margin-top: 5px; padding: 0 .7em;"">
                <p style=""height:35px;""><span class=""ui-icon ui-icon-alert"" style=""float: left; margin-right: .3em;""></span>
                <strong>Alert:</strong>There are no alarm details found between selected date period.</p></div></div>";

                ltrMapScript.Text = @"<script type=""text/javascript"">
                function mapInit(){
                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById('map_canvas'));
                        map.addControl(new GLargeMapControl());
                        map.addControl(new GMapTypeControl());
                        map.addControl(new GOverviewMapControl());
                        map.enableScrollWheelZoom();
                        map.setCenter(new GLatLng(39, -93), 4);
                        map.setUIToDefault();
                    }
                }
                </script>";
            }
        }
Exemple #4
0
        public void doImport(bool preview)
        {
            if (!File.Exists(fullFileName))
            {
                error = new ImportError();
                error.errorMessage = fullFileName + " does not exist.";
                _importproblems.Add(error);
                return;
            }
            CurrentUser cuser = new CurrentUser();
            cuser.userName = this.UserName;
            cuser.Load();
            using (StreamReader sr = File.OpenText(fullFileName))
            {
                String inputLine;
                /* Read Header */
                inputLine = sr.ReadLine();
                if (inputLine != null)
                {
                    Dictionary<string, string> headers = this.deviceHeaders;
                    string[] lineHeaders = inputLine.Split('\t');
                    int col = 0;
                    foreach (string str in lineHeaders)
                    {
                        if (headers.ContainsKey(str))
                        {
                            headers[str] = col.ToString();
                            col++;
                        }
                    }
                    Dictionary<string, string> mapFields = this.fieldsMap;
                    string deptcode="", sitecode="", panelcode="", alarmcode="", alarmtype="";
                    _line = 0;
                    while ((inputLine = sr.ReadLine()) != null)
                    {
                        /* Read File Each Line */
                        string[] lineFields = inputLine.Split('\t');
                        _line++;
                        tbl_alarm_time_details alarmDet = new tbl_alarm_time_details(cuser);
                        foreach(string fieldname in headers.Keys)
                        {

                            int idx;
                            int.TryParse(headers[fieldname], out idx);
                            object value = lineFields[idx];

                            PropertyInfo pi = alarmDet.GetType().GetProperty(mapFields[fieldname]);
                            if (pi != null)
                            {
                                value = IntelWebDataConverter.toType(lineFields[idx], pi.PropertyType, "Line: [" + _line.ToString() + "] Field: [" + fieldname + "] Value: [" + (lineFields[idx] ?? "") + "]");

                                pi.SetValue(alarmDet, value, null);

                                if (fieldname.Equals("DEPT/REG"))
                                {
                                    deptcode = value.ToString();
                                }

                                if (fieldname.Equals("SITE"))
                                {
                                    sitecode = value.ToString();
                                }

                                if (fieldname.Equals("PANEL"))
                                {
                                    panelcode = value.ToString();
                                }

                                if (fieldname.Equals("ALARM DEVICE"))
                                {
                                    alarmcode = value.ToString();
                                }
                                if (fieldname.Equals("ALARM TYPE"))
                                {
                                    alarmtype = value.ToString();
                                }
                            }
                        }
                        UpSert(deptcode, sitecode, panelcode, alarmcode, alarmtype, cuser);
                        alarmDet.tier_code = tierCode;
                        alarmDet.LoadSingle();
                        bool isnew = alarmDet.isNew;
                        string desc = alarmDet.ChangedFieldsDescription();
                        if (!alarmDet.save())
                        {
                            error = new ImportError();
                            error.errorMessage = alarmDet.saveErrorText;
                            error.fieldFQR = alarmDet.friendlySingluarName();
                            error.lineNumber = _line;
                            _importproblems.Add(error);
                        }
                        else
                        {
                            iitem = new ImportedItem(_line, isnew, alarmDet.friendlySingluarName(), desc);
                            _importeditems.Add(iitem);
                        }
                    }
                }
            }
            _enddate = DateTime.Now;
        }