Beispiel #1
0
        void CheckLogin()
        {
            try
            {
                if (!System.Windows.Browser.HtmlPage.Document.QueryString.ContainsKey("CustomerID"))
                {
                    System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(
                           "Default.aspx", UriKind.Relative), "_self");
                    return;
                }

                CustomerID = System.Windows.Browser.HtmlPage.Document.QueryString["CustomerID"];
                // MessageBox.Show(CustomerID);

                MapApplication.Web.DbContext context = new Web.DbContext();
                InvokeOperation<bool> inv = context.IsUserLogin(CustomerID);
                inv.Completed += (s, a) =>
                {
                    if (!inv.Value)
                    {
                        System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(
                            "Default.aspx", UriKind.Relative), "_self");
                    }
                    else
                    {
                        this.sSHMC_MapControl1.Initial(CustomerID);
                    }

                };

            }
            catch(Exception ex)
            {
               MessageBox.Show(ex.Message) ;}
        }
        void Load_Site(string user_id)
        {
            MapApplication.Web.DbContext db = new Web.DbContext();
            if (this.siteCollection == null)
            {
                EntityQuery<vwSiteDegree> q = db.GetVwSiteDegreeQuery();
                LoadOperation<vwSiteDegree> lo = db.Load<vwSiteDegree>(q);
                lo.Completed += (s, a) =>
                    {
                        if (lo.Error != null)
                        {
                            MessageBox.Show(lo.Error.Message);
                            return;
                        }

                        siteCollection = new ObservableCollection<vwSiteDegree>(lo.Entities);
                        DisplayGlobalAndBindingSite();
                        BindingMenu();

                        return;
                    };

            }

            if(siteCollection!=null)
             BindingMenu();
        }
        void loadSiteSensor(vwSiteDegree site)
        {
            MapApplication.Web.DbContext db = new Web.DbContext();

            string site_id = site.SITE_ID;
            if (sensorsCollection != null)
                sensorsCollection.Clear();

                EntityQuery<vwSensorDegree> qry = from n in db.GetVwSensorDegreeQuery() where n.SITE_ID == site_id select n;
                LoadOperation<vwSensorDegree> lo = db.Load<vwSensorDegree>(qry);
                lo.Completed += (s, a) =>
                    {
                        if (lo.Error != null)
                        {
                            MessageBox.Show(lo.Error.Message);
                            return;

                        }
                        dictSensors.Clear();
                        sensorsCollection = new ObservableCollection<vwSensorDegree>(lo.Entities);
                        this.lstMenu.ItemTemplate = this.Resources["SITE_VIEW_TEMPLATE"] as DataTemplate;
                        this.lstMenu.ItemsSource = sensorsCollection;
                        foreach (vwSensorDegree sensorInfo in sensorsCollection)
                        {
                            ElementLayer lyr = this.map1.Layers["sensorLyr"] as ElementLayer;
                            Sensor sensor = new Sensor();

                            MapPoint mp = ConvertMapPointTo102100(new MapPoint((double)sensorInfo.X, (double)sensorInfo.Y));
                            sensor.DataContext = sensorInfo;

                            ElementLayer.SetEnvelope(sensor, new Envelope(mp, mp));
                            dictSensors.Add(sensorInfo.SENSOR_ID, sensor);
                            lyr.Children.Add(sensor);

                        }

                    };
        }
        private void loadSiteCCTV(vwSiteDegree site)
        {
            // throw new NotImplementedException();
            MapApplication.Web.DbContext db = new Web.DbContext();
            string site_id = site.SITE_ID;
            EntityQuery<tblCCTV> qry = from n in db.GetTblCCTVQuery() where n.SITE_ID == site_id select n;
            LoadOperation<tblCCTV> lo = db.Load<tblCCTV>(qry);

            lo.Completed += (s, a) =>
               {
                   if (lo.Error != null)
                   {
                       MessageBox.Show(lo.Error.Message);
                       return;

                   }
                   dictCCTVs.Clear();
                   this.lstCCTV.ItemsSource = lo.Entities;
                   foreach (tblCCTV cctvInfo  in lo.Entities   )
                   {
                       ElementLayer lyr = this.map1.Layers["sensorLyr"] as ElementLayer;
                       CCTV sensor = new CCTV();

                       MapPoint mp = ConvertMapPointTo102100(new MapPoint((double)cctvInfo.X, (double)cctvInfo.Y));
                       sensor.DataContext = cctvInfo;

                       ElementLayer.SetEnvelope(sensor, new Envelope(mp, mp));
                       dictCCTVs.Add(cctvInfo.CCTV_ID, sensor);
                       lyr.Children.Add(sensor);
                   }

               };
        }
        public void UpdateSiteDegree(string user_id)
        {
            MapApplication.Web.DbContext db = new Web.DbContext();
               EntityQuery<vwSiteDegree> qry= from n in db.GetVwSiteDegreeQuery() select n;
               LoadOperation<vwSiteDegree> lo = db.Load<vwSiteDegree>(qry);
               lo.Completed += (s, a) =>
               {
                   if (lo.Error != null)
                       return;
                   foreach (vwSiteDegree siteinfo in lo.Entities)
                   {
                       if (!dictPins.ContainsKey(siteinfo.SITE_ID))
                           continue;

                       (dictPins[siteinfo.SITE_ID].DataContext as vwSiteDegree).CURRENT_DEGREE = siteinfo.CURRENT_DEGREE;

                   }
               };
        }
        public void UpdateSensorDegree( )
        {
            MapApplication.Web.DbContext db = new Web.DbContext();
            EntityQuery<vwSensorDegree> qry = from n in db.GetVwSensorDegreeQuery()   select n;
            LoadOperation<vwSensorDegree> lo = db.Load<vwSensorDegree>(qry);
            lo.Completed += (s, a) =>
            {
                if (lo.Error != null)
                    return;
                foreach (vwSensorDegree sensorinfo in lo.Entities)
                {
                    if (!dictSensors.ContainsKey(sensorinfo.SENSOR_ID))
                        continue;

                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).CURRENT_DEGREE = sensorinfo.CURRENT_DEGREE;
                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).VALUE0 = sensorinfo.VALUE0;
                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).VALUE1 = sensorinfo.VALUE1;
                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).VALUE2 = sensorinfo.VALUE2;
                   // dictSensors[sensorinfo.SENSOR_ID].DataContext = sensorinfo;
                  dictSensors[sensorinfo.SENSOR_ID].PlayAlarm();
                }
            };
        }
        void Load_Site(string customerid)
        {
            MapApplication.Web.DbContext db = new Web.DbContext();
            if (this.siteCollection == null)
            {
                EntityQuery<vwSiteDegree> q ;
                if (customerid == "1")
                {
                    q = db.GetVwSiteDegreeQuery();
                    (this.map1.Layers["buildingPointLyr"] as FeatureLayer).Visible = false;
                  //  (this.map1.Layers["buildingPointLyr"] as FeatureLayer).Refresh();
                }
                else
                {
                    q = db.GetVwSiteDegreeQuery().Where(n => n.CUSTOMER_ID == System.Convert.ToInt32(customerid) || n.CUSTOMER_ID == 1);

                    (this.map1.Layers["buildingPointLyr"] as FeatureLayer).Where = "CUSTOMER_ID<>1 and CUSTOMER_ID<>" + customerid;
                    (this.map1.Layers["buildingPointLyr"] as FeatureLayer).Refresh();
                }

                LoadOperation<vwSiteDegree> lo = db.Load<vwSiteDegree>(q);
                lo.Completed += (s, a) =>
                    {
                        if (lo.Error != null)
                        {
                            MessageBox.Show(lo.Error.Message);
                            return;
                        }

                        siteCollection = new ObservableCollection<vwSiteDegree>(lo.Entities);
                        DisplayGlobalAndBindingSite();
                        BindingMenu();

                        return;
                    };

            }

            if(siteCollection!=null)
             BindingMenu();
        }
        void loadSiteSensor(vwSiteDegree site)
        {
            MapApplication.Web.DbContext db = new Web.DbContext();

            string site_id = site.SITE_ID;
            if (sensorsCollection != null)
                sensorsCollection.Clear();

                EntityQuery<vwSensorDegree> qry = from n in db.GetVwSensorDegreeQuery() where n.SITE_ID == site_id select n;
                LoadOperation<vwSensorDegree> lo = db.Load<vwSensorDegree>(qry);
                lo.Completed += (s, a) =>
                    {
                        if (lo.Error != null)
                        {
                            MessageBox.Show(lo.Error.Message);
                            return;

                        }
                        dictSensors.Clear();
                        sensorsCollection = new ObservableCollection<vwSensorDegree>(lo.Entities);
                        this.lstMenu.ItemTemplate = this.Resources["SITE_VIEW_TEMPLATE"] as DataTemplate;
                        this.lstMenu.ItemsSource = sensorsCollection;
                        foreach (vwSensorDegree sensorInfo in sensorsCollection)
                        {
                            ElementLayer lyr = this.map1.Layers["sensorLyr"] as ElementLayer;
                            Sensor sensor = new Sensor();

                            MapPoint mp = ConvertMapPointTo102100(new MapPoint((double)sensorInfo.X, (double)sensorInfo.Y));
                            sensor.DataContext = sensorInfo;

                            ElementLayer.SetEnvelope(sensor, new Envelope(mp, mp));
                            dictSensors.Add(sensorInfo.SENSOR_ID, sensor);
                            lyr.Children.Add(sensor);

                        }

                    };
                EntityQuery<tblTC> qBA = from n in db.GetTblTCQuery() where n.SITE_ID == this.CURRENT_SITE_ID && n.DEVICE_TYPE == "BA" select n;
                LoadOperation<tblTC> loBA = db.Load<tblTC>(qBA);
                loBA.Completed += (s, a) =>
                {
                    if (loBA.Error != null)
                    {
                        MessageBox.Show(lo.Error.Message);
                        return;
                    }
                    if (loBA.Entities.Count() == 0)
                        txtBA.Visibility = System.Windows.Visibility.Collapsed;
                    else
                    {
                        txtBA.Visibility = System.Windows.Visibility.Visible;
                        if (loBA.Entities.FirstOrDefault().ISCONNECTED == "N")
                            txtBA.Foreground = new SolidColorBrush(Colors.Gray);
                        else
                            txtBA.Foreground = new SolidColorBrush(Colors.Green);
                    }

                };
        }
        public void UpdateSiteDegree(string customerid)
        {
            MapApplication.Web.DbContext db = new Web.DbContext();
               EntityQuery<vwSiteDegree> qry;
            if(customerid=="1")
                 qry= from n in db.GetVwSiteDegreeQuery() select n;
            else
                qry= from n in db.GetVwSiteDegreeQuery() where n.CUSTOMER_ID==System.Convert.ToInt32(customerid)  select n;
               LoadOperation<vwSiteDegree> lo = db.Load<vwSiteDegree>(qry);
               lo.Completed += (s, a) =>
               {
                   if (lo.Error != null)
                       return;
                   foreach (vwSiteDegree siteinfo in lo.Entities)
                   {
                       if (!dictPins.ContainsKey(siteinfo.SITE_ID))
                           continue;

                       (dictPins[siteinfo.SITE_ID].DataContext as vwSiteDegree).CURRENT_DEGREE = siteinfo.CURRENT_DEGREE;

                   }
               };
        }
        public void UpdateSensorDegree( )
        {
            if (this.view_mode != enumDisplayMode.SITE_VIEW)
                return;
            MapApplication.Web.DbContext db = new Web.DbContext();
            EntityQuery<vwSensorDegree> qry = from n in db.GetVwSensorDegreeQuery() where n.SITE_ID==CURRENT_SITE_ID  select n;
            LoadOperation<vwSensorDegree> lo = db.Load<vwSensorDegree>(qry);
            lo.Completed += (s, a) =>
            {
                if (lo.Error != null)
                    return;
                foreach (vwSensorDegree sensorinfo in lo.Entities)
                {
                    if (!dictSensors.ContainsKey(sensorinfo.SENSOR_ID))
                        continue;

                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).CURRENT_DEGREE = sensorinfo.CURRENT_DEGREE;
                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).VALUE0 = sensorinfo.VALUE0;
                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).VALUE1 = sensorinfo.VALUE1;
                  (dictSensors[sensorinfo.SENSOR_ID].DataContext as vwSensorDegree).VALUE2 = sensorinfo.VALUE2;
                   // dictSensors[sensorinfo.SENSOR_ID].DataContext = sensorinfo;
                  dictSensors[sensorinfo.SENSOR_ID].PlayAlarm();
                }
            };

            EntityQuery<tblTC> qBA = from n in db.GetTblTCQuery() where n.SITE_ID == this.CURRENT_SITE_ID && n.DEVICE_TYPE == "BA" select n;

            LoadOperation<tblTC> loBA = db.Load<tblTC>(qBA);
            loBA.Completed += (s, a) =>
            {
                if (loBA.Error != null)
                {
                    MessageBox.Show(lo.Error.Message);
                    return;
                }
                if (loBA.Entities.Count() == 0)
                    txtBA.Visibility = System.Windows.Visibility.Collapsed;
                else
                {
                    txtBA.Visibility = System.Windows.Visibility.Visible;
                    if (loBA.Entities.FirstOrDefault().ISCONNECTED == "N")
                        txtBA.Foreground = new SolidColorBrush(Colors.Gray);
                    else
                        txtBA.Foreground = new SolidColorBrush(Colors.Green);
                }

            };
        }