Exemplo n.º 1
0
        private void UpSert(string Dept, string Site, string Panel, string Alarm, string AlarmType, CurrentUser cuser)
        {
            /* Find If Department Exists or Insert it */
            lkup_department dept = new lkup_department(cuser);
            dept.department_code = Dept;
            dept.LoadSingle();
            if (dept.isNew)
            {
                dept.department_code_description = Dept;
                string desc = dept.ChangedFieldsDescription();
                if (!dept.save())
                {
                    error = new ImportError();
                    error.errorMessage = dept.saveErrorText;
                    error.fieldFQR = dept.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, dept.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }

            lkup_site site = new lkup_site(cuser);
            site.department_code = Dept;
            site.site_code = Site;
            site.LoadSingle();
            if (site.isNew)
            {
                site.site_code_description = Site;
                string desc = site.ChangedFieldsDescription();
                if (!site.save())
                {
                    error = new ImportError();
                    error.errorMessage = site.saveErrorText;
                    error.fieldFQR = site.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, site.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }

            lkup_panel panel = new lkup_panel(cuser);
            panel.panel_code = Panel;
            panel.site_code = Site;
            panel.LoadSingle();
            if (panel.isNew)
            {
                panel.alarm_device_code = Alarm;
                panel.panel_code_description = Panel;
                string desc = panel.ChangedFieldsDescription();
                if (!panel.save())
                {
                    error = new ImportError();
                    error.errorMessage = panel.saveErrorText;
                    error.fieldFQR = panel.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, panel.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }

            lkup_alarm_device alarm = new lkup_alarm_device(cuser);
            alarm.panel_code = Panel;
            alarm.alarm_device_code = Alarm;
            alarm.alarm_type_code = AlarmType;
            alarm.LoadSingle();
            if (alarm.isNew)
            {
                alarm.alarm_device_code_description = Alarm;
                string desc = alarm.ChangedFieldsDescription();
                if (!alarm.save())
                {
                    error = new ImportError();
                    error.errorMessage = alarm.saveErrorText;
                    error.fieldFQR = alarm.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, alarm.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }
        }
Exemplo n.º 2
0
        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>";
            }
        }
Exemplo n.º 3
0
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            CurrentUser cuser = new CurrentUser();
            cuser.userName = "******";
            cuser.Load();
            WebGridController siteGC = WebGridController.ControllerFromName("lkup_site", Request.Form, this.Form.Controls, cuser);
            lkup_department lkupDept = new lkup_department(cuser);
            List<IntelWebObject> lkupDepts = lkupDept.Load();
            this.ltrDepts.Text = string.Join("", lkupDepts.Cast<lkup_department>().Select(x=>"<option value=\"" + HttpUtility.HtmlEncode(x.department_code) + "\">" + HttpUtility.HtmlEncode(x.department_code + " (" + x.department_code_description + ")") + "</option>").ToArray());

            lkup_site lkupSite = new lkup_site(cuser);
            List<IntelWebObject> lkupSites = lkupSite.Load("","department_code,site_code");
            siteGC.grid.data = lkupSites;

            siteGC.grid.uiFormShowJS = @"function(){
            $('#divSiteEntry').dialog({width:750,modal:true,title:'Site/Building Info',close:function(){webGrid.removeNewItems()}});$('#site_code').focus();}";
            siteGC.grid.afterSubmitJS = @"function(result,grid){
                                              if(result.ok && result.gridInfos){
                                                webGrid.mergeGridInfos(result.gridInfos);
                                                webGrid.drawFilteredRows(grid,function(record){
                                                  if((typeof record.fields.markedforremoval != undefined) && !record.fields.markedforremoval){
                                                    return true;
                                                  }
                                                return false;
                                                });
                                               	if($('#divSiteEntry').is(':visible')){
                                                    try{
                                                        $('#divSiteEntry').dialog('close');
                                                    }
                                                    catch(ex){}
                                                }
                                              }
                                            }";

            siteGC.grid.uiFormName = "theform";
            var gtable = new WebGridTable();
            gtable.UIHeaderText = "Site / Building Information";
            gtable.tableId = "tblFieldsId";
            gtable.Grid = siteGC.grid;
            var myButtonFunction = new Func<IntelWebObject, object>((obj) =>
            {
                return @"<a href=""javascript:void(0);"" title=""Edit Site"" onclick=""editSite([gridName],[recordIndex])"" ><img alt=""Edit"" title=""Edit Site"" src=""Images/table_edit.png""></a>&nbsp;<a href=""javascript:void(0);"" title=""Delete Site"" onclick=""delSite([gridName],[recordIndex])"" ><img title=""Delete Site"" src=""Images/delete.png"" alt=""delete""></a>";
            });

            gtable.extraColumns.Add(new WebGridTable.extraColumn()
            {
                fieldTemplate = new DisplayField()
                {
                    submitField = false
                    ,
                    fieldName = "EditButtons"
                    ,
                    formatFunction = myButtonFunction
                    ,
                    isHeaderField = true
                    ,
                    jsFormatFunction = @"return '<a href=""javascript:void(0);"" title=""Edit Site"" onclick=""editSite([gridName],[recordIndex])"" ><img alt=""Edit"" title=""Edit Site"" src=""Images/table_edit.png""></a>&nbsp;<a href=""javascript:void(0);"" title=""Delete Site"" onclick=""delSite([gridName],[recordIndex])"" ><img title=""Delete Site"" src=""Images/delete.png"" alt=""delete""></a> '"
                }
            });

            ltrGrid.Text = "<div class=\"centered\">" + gtable.tableUI() + "</div>";
            ltrGridScript.Text = "<script type=\"text/javascript\">" + siteGC.grid.gridScript() + "</script>\n" + gtable.tableScript();
        }