Ejemplo n.º 1
0
        private async void cbDiagramSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            System.Collections.Generic.List<UIElement> Removelist = new System.Collections.Generic.List<UIElement>();

            int planeid= (cbDiagramSelect.SelectedItem as tblERPlane).PlaneID;
             this.imgPic.Source = new BitmapImage(new Uri("/Diagrams/" + (cbDiagramSelect.SelectedItem as tblERPlane).PlaneID+".png", UriKind.Relative));
             foreach (UIElement c in grdDeviceLayer.Children)
             {
                 if (c is Image) continue;
                 Removelist.Add(c);
                 //grdDeviceLayer.Children.Remove(c);
             }

            foreach(UIElement ui in Removelist)
                grdDeviceLayer.Children.Remove(ui);
            Removelist.Clear();
             #region  Door
             var q = from n in db.GetTblControllerConfigQuery() where (n.ControlType == 1 || n.ControlType == 2  ) && n.PlaneID== (cbDiagramSelect.SelectedValue as tblERPlane).PlaneID   select n;
             var res= await   DB.LoadAsync<tblControllerConfig>(db, q);

             foreach (tblControllerConfig tbl in res)
             {
                DOOR item = new DOOR();
                item.Name = "Door"+tbl.ControlID;
             //  tblItem info = CreateInputItemInfo("DOOR", "DOOR", "", 1, 0);
                
                item.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                item.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                item.SetValue(Grid.MarginProperty, new Thickness(tbl.X??0, tbl.Y??0, 0, 0));
              
              //  item.Margin = new Thickness(0);

              // grdSetting.DataContext = 
                item.DataContext = tbl;
                 
                item.SetDefaultColor();
                

                this.grdDeviceLayer.Children.Add(item);

                item.MouseLeftButtonDown += selectedDevice_MouseLeftButtonDown;
                item.MouseLeftButtonUp += selectedDevice_MouseLeftButtonUp;
                item.MouseMove += selectedDevice_MouseMove;
               // ctl = item;

             }
             #endregion
            #region          CCTV
             var q2 = from n in db.GetTblCCTVConfigQuery() where n.PlaneID == planeid select n;
             var res2 = await DB.LoadAsync<tblCCTVConfig>(db, q2);
             foreach (tblCCTVConfig tbl in res2)
             {
                 CCTV item = new CCTV();
                 item.Name = "CCTV" + tbl.CCTVID;
                 item.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                 item.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                 item.SetValue(Grid.MarginProperty, new Thickness(tbl.X, tbl.Y, 0, 0));
                 //  item.Margin = new Thickness(0);

                 //  grdSetting.DataContext = 
                 item.DataContext = tbl;



                 this.grdDeviceLayer.Children.Add(item);

                 item.MouseLeftButtonDown += selectedDevice_MouseLeftButtonDown;
                 item.MouseLeftButtonUp += selectedDevice_MouseLeftButtonUp;
                 item.MouseMove += selectedDevice_MouseMove;
             }

            #endregion
#region AI DI DO  
             var qai = from n in db.GetTblItemConfigQuery() where n.IsShow && n.tblItemGroup.PlaneID==planeid   select n;
             var resqai = await DB.LoadAsync<tblItemConfig>(db, qai);

             foreach (tblItemConfig tbl in resqai)
             {
                 if (tbl.Type == "AI")
                 {
                     AI ai = new AI();
                     ai.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                     ai.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                     ai.SetValue(Grid.MarginProperty, new Thickness(tbl.X ?? 0, tbl.Y ?? 0, 0, 0));
                     ai.Content ="AI:"+ tbl.ItemName;
                     //CompositeTransform transform = new CompositeTransform() { Rotation = tbl.Rotation ?? 0, ScaleX = tbl.ScaleX ?? 1, ScaleY = tbl.ScaleY ?? 1 };
                     //ai.RenderTransform = transform;
                     ai.DataContext = tbl;    //new SecureServer.BindingData.ItemBindingData { ColorString = "Green", Content = "100V", ItemID =1, Type=  "AI" };
                     this.grdDeviceLayer.Children.Add(ai);
                     ai.MouseLeftButtonDown += selectedDevice_MouseLeftButtonDown;
                     ai.MouseLeftButtonUp += selectedDevice_MouseLeftButtonUp;
                     ai.MouseMove += selectedDevice_MouseMove;
                 }
                 else if (tbl.Type == "DI")
                 {
                     DI di = new DI();
                     di.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                     di.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                     di.SetValue(Grid.MarginProperty, new Thickness(tbl.X ?? 0, tbl.Y ?? 0, 0, 0));
                     di.Content ="DI:"+ tbl.ItemName;
                     
                     //CompositeTransform transform = new CompositeTransform() { Rotation = tbl.Rotation ?? 0, ScaleX = tbl.ScaleX ?? 1, ScaleY = tbl.ScaleY ?? 1 };
                     //ai.RenderTransform = transform;
                     di.DataContext = tbl;    //new SecureServer.BindingData.ItemBindingData { ColorString = "Green", Content = "100V", ItemID =1, Type=  "AI" };
                     this.grdDeviceLayer.Children.Add(di);
                     di.MouseLeftButtonDown += selectedDevice_MouseLeftButtonDown;
                     di.MouseLeftButtonUp += selectedDevice_MouseLeftButtonUp;
                     di.MouseMove += selectedDevice_MouseMove;

                 }
                 else if (tbl.Type == "DO")
                 {

                     DO di = new DO();
                     di.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                     di.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                     di.SetValue(Grid.MarginProperty, new Thickness(tbl.X ?? 0, tbl.Y ?? 0, 0, 0));
                     di.Content ="DO:"+ tbl.ItemName;
                     //CompositeTransform transform = new CompositeTransform() { Rotation = tbl.Rotation ?? 0, ScaleX = tbl.ScaleX ?? 1, ScaleY = tbl.ScaleY ?? 1 };
                     //ai.RenderTransform = transform;
                     di.DataContext = tbl;    //new SecureServer.BindingData.ItemBindingData { ColorString = "Green", Content = "100V", ItemID =1, Type=  "AI" };
                     this.grdDeviceLayer.Children.Add(di);
                     di.Width = 52;
                     di.Height = 40;
                     di.MouseLeftButtonDown += selectedDevice_MouseLeftButtonDown;
                     di.MouseLeftButtonUp += selectedDevice_MouseLeftButtonUp;
                     di.MouseMove += selectedDevice_MouseMove;

                 }
                 
             }

#endregion

#region ItemGroup
             var qgrouo = from n in db.GetTblItemGroupQuery() where n.IsShow && n.PlaneID == planeid select n;
             var resgroup = await DB.LoadAsync<tblItemGroup>(db, qgrouo);
             foreach (tblItemGroup tbl in resgroup)
             {
                 ItemGroup grp = new ItemGroup();
                 grp.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                 grp.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                 grp.SetValue(Grid.MarginProperty, new Thickness(tbl.X  , tbl.Y , 0, 0));
                 grp.Content ="Group:"+ tbl.GroupName;
                
                 grp.DataContext = tbl;
                 this.grdDeviceLayer.Children.Add(grp);
                 grp.MouseLeftButtonDown += selectedDevice_MouseLeftButtonDown;
                 grp.MouseLeftButtonUp += selectedDevice_MouseLeftButtonUp;
                 grp.MouseMove += selectedDevice_MouseMove;
             }


#endregion

        }
Ejemplo n.º 2
0
        async void PlaceCCTV()
        {
            //CCTV temp = new CCTV();
            //temp.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            //temp.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            //temp.SetValue(Grid.MarginProperty, new Thickness(625, 500, 0, 0));
            //this.Canvas.Children.Add(temp);
            //return;

            if (IsExit)
                return;
            var q = from n in db.GetTblCCTVConfigQuery() where  n.PlaneID == this.PlaneID select n;
            var res = await db.LoadAsync<tblCCTVConfig>(q);

            foreach (tblCCTVConfig tbl in res)
            {

               
                CCTV item = new CCTV();
                item.Name = "CCTV" + tbl.CCTVID;
                

                item.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                item.VerticalAlignment = System.Windows.VerticalAlignment.Top;




                // this.Canvas.DataContext = item.DataContext = tbl;



                
                item.SetValue(Grid.MarginProperty, new Thickness(tbl.X, tbl.Y, 0, 0));
               // CompositeTransform transform = new CompositeTransform() { Rotation = tbl.Rotation, ScaleX = tbl.ScaleX, ScaleY = tbl.ScaleY };
               // item.RenderTransform = transform;
                CCTVBindingData bindingdata=null;
                
                if (CCTVBindingDatas == null)
                    return;
             
                  bindingdata=CCTVBindingDatas.FirstOrDefault(n => n.CCTVID==tbl.CCTVID );
                item.UserName = bindingdata.UserName;
                item.Password = bindingdata.Password;
                item.Url = bindingdata.MjpegCgiString;
                 
                item.DataContext =   bindingdata;
                item.MouseLeftButtonDown += CCTVLock_MouseLeftButtonDown;


                this.Canvas.Children.Add(item);
               
             //   CCTVLock_MouseLeftButtonDown(item, null);
               
                


            }

            CCTVBindingData cctvdata = CCTVBindingDatas.FirstOrDefault();
            if (cctvdata == null)
                return;
            if (IsExit)
                return;
            CCTVControl cctv = new CCTVControl(cctvdata.MjpegCgiString, cctvdata.UserName, cctvdata.Password);
            cctv.Name = "cctvctl"+cctvdata.CCTVName;
         //   cctv.Width = 400;
          //  cctv.Width = 300;
            cctv.Height = 200;
          //  Interaction.GetBehaviors(cctv).Add(new Microsoft.Expression.Interactivity.Layout.MouseDragElementBehavior());
            cctv.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            cctv.VerticalAlignment = System.Windows.VerticalAlignment.Top;
          //  this.Canvas.Children.Add(cctv);
            cctv.Margin = new Thickness(5,35,0,0);
            cctv.IsEnableCloseButton = false;
            Grid.SetRow(cctv, 0);
            Grid.SetColumn(cctv, 1);
            LayoutRoot.Children.Add(cctv);
        }