Exemplo n.º 1
0
 void bwRealData_DoWork(object sender, DoWorkEventArgs e)
 {
     //throw new NotImplementedException();
     while (true)
     {
         if (bwRealData.CancellationPending)
         {
             break;
         }
         if (!bwLoadData.IsBusy)
         {
             // 请求最新的数据
             this.Dispatcher.Invoke((Action)(() =>
             {
                 ShowState("更新后台数据中...");
             }));
             Thread.Sleep(1000);
             List <HostInfo> list = new HostInfoBLL().GetModelByPrjGUID(appState.CurrentUserInfo.ProjectGUID);
             if (list != null && list.Count > 0)
             {
                 LightInfoBLL liBLL = new LightInfoBLL();
                 foreach (HostInfo hi in list)
                 {
                     HostInfo h = appState.TreeDatas.ListHostInfo.FirstOrDefault(a => a.GUID == hi.GUID);
                     if (h != null)
                     {
                         h.Online = hi.Online;
                     }
                     // 更新单灯
                     List <LightInfo> listLI = liBLL.GetModelByHost(h);
                     if (listLI != null && listLI.Count > 0)
                     {
                         foreach (LightInfo li in listLI)
                         {
                             LightInfo l = appState.TreeDatas.ListLightInfo.FirstOrDefault(b => b.GUID == li.GUID);
                             if (l != null)
                             {
                                 l.LightStateInfo = li.LightStateInfo;
                                 //Debug.WriteLine(l.LightStateInfo.ToString());
                             }
                         }
                     }
                 }
             }
             this.Dispatcher.Invoke((Action)(() =>
             {
                 ShowState("更新后台数据成功");
             }));
         }
         Thread.Sleep(10000);
     }
 }
Exemplo n.º 2
0
        void OkButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                lightInfo.ID      = txtLightID.Text.Trim();
                lightInfo.Lat     = double.Parse(txtLightLat.Text.Trim());
                lightInfo.Lng     = double.Parse(txtLightLng.Text.Trim());
                lightInfo.Name    = txtLightName.Text.Trim();
                lightInfo.PhyID   = txtLightPhyID.Text.Trim();
                lightInfo.Remark  = txtLightRemark.Text.Trim();
                lightInfo.Enable  = cbLightEnable.IsChecked == true ? 1 : 0;
                lightInfo.Version = txtLightVersion.Text.Trim();
                lightInfo.Type    = (int)(((LightTypeItem)cbLightType.SelectedItem).Value);
            }
            catch
            {
                ModernDialog.ShowMessage("经纬度数据格式错误!", "提示", MessageBoxButton.OK);
                return;
            }

            // 存入组的关联
            if (combLightGroupInfo.SelectedItem != null)
            {
                LightInfoLightGroupInfoBLL ltlgBLL = new LightInfoLightGroupInfoBLL();
                if (lightInfoLightGroupInfo != null)
                {
                    lightInfoLightGroupInfo.LightGroupInfoGUID = (combLightGroupInfo.SelectedItem as LightGroupInfo).GUID;
                    if (!ltlgBLL.Update(lightInfoLightGroupInfo))
                    {
                        ModernDialog.ShowMessage("更新数据库失败!", "提示", MessageBoxButton.OK);
                        return;
                    }
                }
                else
                {
                    lightInfoLightGroupInfo      = new LightInfoLightGroupInfo();
                    lightInfoLightGroupInfo.GUID = Guid.NewGuid().ToString();
                    lightInfoLightGroupInfo.LightGroupInfoGUID = (combLightGroupInfo.SelectedItem as LightGroupInfo).GUID;
                    lightInfoLightGroupInfo.LightInfoGUID      = lightInfo.GUID;
                    lightInfoLightGroupInfo.CreateTime         = DateTime.Now;
                    lightInfoLightGroupInfo.UpdateTime         = lightInfoLightGroupInfo.CreateTime;
                    if (!ltlgBLL.Add(lightInfoLightGroupInfo))
                    {
                        ModernDialog.ShowMessage("增加数据库失败!", "提示", MessageBoxButton.OK);
                        return;
                    }
                }
            }

            // 更新单灯
            LightInfoBLL liBLL = new LightInfoBLL();

            if (liBLL.Update(lightInfo))
            {
                Close();
                mainWindow.MapRefreshLightInfo(lightInfo, lightInfoLightGroupInfo, lightInfoLightGroupInfoBack);
            }
            else
            {
                ModernDialog.ShowMessage("更新数据库失败!", "提示", MessageBoxButton.OK);
                return;
            }
        }
Exemplo n.º 3
0
        void OkButton_Click(object sender, RoutedEventArgs e)
        {
            int    startID, endID, tempID;
            double startLat, endLat, startLng, endLng, tempLat, tempLng;

            try
            {
                startID  = int.Parse(txtStartID.Text.Trim());
                endID    = int.Parse(txtEndID.Text.Trim());
                startLat = double.Parse(txtStartLightLat.Text.Trim());
                startLng = double.Parse(txtStartLightLng.Text.Trim());
                endLat   = double.Parse(txtEndLightLat.Text.Trim());
                endLng   = double.Parse(txtEndLightLng.Text.Trim());
                tempID   = endID - startID + 1;
                tempLat  = (endLat - startLat) / tempID;
                tempLng  = (endLng - startLng) / tempID;
            }
            catch
            {
                ModernDialog.ShowMessage("起始结束地址错误!", "提示", MessageBoxButton.OK);
                return;
            }
            if (startID > endID)
            {
                ModernDialog.ShowMessage("起始地址不能大于结束地址!", "提示", MessageBoxButton.OK);
                return;
            }

            LightInfo    lightInfo;
            LightInfoBLL liBLL = new LightInfoBLL();
            LightInfoLightGroupInfoBLL lilgiBLL = new LightInfoLightGroupInfoBLL();

            LightInfoLightGroupInfo lightInfoLightGroupInfo = null;

            if (combLightGroupInfo.SelectedItem != null)
            {
                lightInfoLightGroupInfo = new LightInfoLightGroupInfo();
                lightInfoLightGroupInfo.LightGroupInfoGUID = ((LightGroupInfo)combLightGroupInfo.SelectedItem).GUID;
                treeLightGroupInfoTag = treeHostInfo.TreeLightGroupInfos.FirstOrDefault(a => a.LightGroupInfo.GUID == lightInfoLightGroupInfo.LightGroupInfoGUID);
            }
            DateTime dtNow = DateTime.Now;

            for (int i = 0; i < tempID; i++)
            {
                try
                {
                    // 增加节点
                    lightInfo            = new LightInfo(hostInfo.Addr);
                    lightInfo.HostGUID   = hostInfo.GUID;
                    lightInfo.GUID       = Guid.NewGuid().ToString();
                    lightInfo.ID         = (startID + i).ToString("D03");
                    lightInfo.Lat        = startLat + tempLat * i;
                    lightInfo.Lng        = startLng + tempLng * i;
                    lightInfo.Name       = lightInfo.ID;
                    lightInfo.PhyID      = lightInfo.ID;
                    lightInfo.Version    = txtLightVersion.Text.Trim();
                    lightInfo.Type       = (int)(((Admin.Pages.Device.LightInfoEditDlg.LightTypeItem)cbLightType.SelectedItem).Value); // 1 太阳能
                    lightInfo.Enable     = 1;                                                                                          // 使能
                    lightInfo.Remark     = "";
                    lightInfo.CreateTime = dtNow;
                    lightInfo.UpdateTime = dtNow;
                    liBLL.Add(lightInfo);
                    if (mainWindow != null)
                    {
                        mainWindow.UIAddLightInfo(lightInfo, treeLightGroupInfo);
                    }

                    // 增加节点关系
                    if (lightInfoLightGroupInfo != null)
                    {
                        lightInfoLightGroupInfo.GUID          = Guid.NewGuid().ToString();
                        lightInfoLightGroupInfo.CreateTime    = dtNow;
                        lightInfoLightGroupInfo.UpdateTime    = dtNow;
                        lightInfoLightGroupInfo.LightInfoGUID = lightInfo.GUID;
                        lilgiBLL.Add(lightInfoLightGroupInfo);
                        if (mainWindow != null && treeLightGroupInfoTag != null)
                        {
                            mainWindow.UIAddLightInfoLightGroupInfo(lightInfo, treeLightGroupInfoTag);
                        }
                    }
                }
                catch
                {
                }
            }
            Close();
        }