Exemple #1
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;
            }
        }
Exemple #2
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();
        }