Exemplo n.º 1
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (txtSourceDomainNodeName.Text.Trim() == "")
            {
                MessageBox.Show("请指定要添加域名的位置!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (!txtDomainNodeName.Text.Trim().Equals(""))
            {
                //添加域结点
                if ((Parameters.DomainActionInfoClass.NodeType.Equals(NodeType.StructureNode.ToString()) || Parameters.DomainActionInfoClass.NodeType.Equals(NodeType.RootNode.ToString())) &&
                    Parameters.DomainActionInfoClass.IsStation.Equals("0"))
                {
                    if (MessageBox.Show("确定添加域名吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
                    {
                        try
                        {
                            Parameters.DomainActionInfoClass.SelfName    = txtDomainNodeName.Text.Trim();
                            Parameters.DomainActionInfoClass.NodeContent = txtDomainNodeName.Text.Trim();
                            Parameters.DomainActionInfoClass.IsStation   = "0";
                            Parameters.DomainActionInfoClass.NodeType    = NodeType.StructureNode.ToString();
                            Parameters.DomainActionInfoClass.NodeIcon    = new NodeIcon().StructureCloseNodeIcon;
                            NetWorkClient.ControllerServer.Send(JsonInterFace.AddDomainNodeName(Parameters.DomainActionInfoClass.PathName, Parameters.DomainActionInfoClass.SelfName, Convert.ToInt32(Parameters.DomainActionInfoClass.IsStation), ""));
                            txtDomainNodeName.Text = "";
                        }
                        catch (Exception ex)
                        {
                            Parameters.PrintfLogsExtended(ex.Message, ex.StackTrace);
                        }
                    }
                }
                else if (Parameters.DomainActionInfoClass.NodeType.Equals(NodeType.StructureNode.ToString()) &&
                         Parameters.DomainActionInfoClass.IsStation.Equals("1"))
                {
                    MessageBox.Show("站点中只能添加设备,要添加设备,请在设备管理中操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                else if (Parameters.DomainActionInfoClass.NodeType.Equals(NodeType.LeafNode.ToString()))
                {
                    MessageBox.Show("不能在设备中添加域名!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            else
            {
                MessageBox.Show("请输入域名!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Exemplo n.º 2
0
        private void btnEnter_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TreeViewNodeInfoClass.IsStation = (bool)chkStation.IsChecked;

                if (TreeViewNodeInfoClass.NodeName.Trim().Equals(""))
                {
                    MessageBox.Show("请输入域名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                else
                {
                    if (!NetWorkClient.ControllerServer.Connected)
                    {
                        MessageBox.Show("网络已断开!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                    else
                    {
                        if (regexDomain.Match(TreeViewNodeInfoClass.NodeName).Success)
                        {
                            JsonInterFace.ShowMessage("输入的域名称格式非法,域名只能为[128位以下划线开头的字母或中文或英文组成的名称]!", 16);
                            return;
                        }
                        //添加域名
                        if (TreeViewNodeInfoClass.Operation == DeviceTreeOperation.DomainAdd)
                        {
                            Parameters.DomainActionInfoClass.SelfID     += 1;
                            Parameters.DomainActionInfoClass.SelfName    = TreeViewNodeInfoClass.NodeName;
                            Parameters.DomainActionInfoClass.NodeContent = TreeViewNodeInfoClass.DesInfo;
                            Parameters.DomainActionInfoClass.IsStation   = (Convert.ToInt32((bool)chkStation.IsChecked)).ToString();
                            NetWorkClient.ControllerServer.Send(JsonInterFace.AddDomainNodeName(TreeViewNodeInfoClass.FullNodeName, TreeViewNodeInfoClass.NodeName, Convert.ToInt32(TreeViewNodeInfoClass.IsStation), txtDesContent.Text));

                            //添加经纬度
                            if (TreeViewNodeInfoClass.IsStation && txtLngContent.Text != "" & txtLatContent.Text != "")
                            {
                                Regex re = new Regex(@"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
                                if (!re.IsMatch(txtLngContent.Text) || !re.IsMatch(txtLatContent.Text))
                                {
                                    MessageBox.Show("经纬度输入格式有误", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                    return;
                                }
                                NetWorkClient.ControllerServer.Send(JsonInterFace.Set_station_location_Request(TreeViewNodeInfoClass.FullNodeName, TreeViewNodeInfoClass.NodeName, JsonInterFace.StationMap.Lng, JsonInterFace.StationMap.Lat));
                            }
                        }
                        //重命名域名
                        else if (TreeViewNodeInfoClass.Operation == DeviceTreeOperation.DomainReName)
                        {
                            string   oldDomainName = TreeViewNodeInfoClass.FullNodeName;
                            string   newDomainName = string.Empty;
                            string[] tmpDomainName = oldDomainName.Split(new char[] { '.' });
                            if (!Parameters.DomainActionInfoClass.SelfID.Equals(1))
                            {
                                for (int i = 0; i < tmpDomainName.Length - 1; i++)
                                {
                                    if (!newDomainName.Trim().Equals(""))
                                    {
                                        newDomainName += "." + tmpDomainName[i];
                                    }
                                    else
                                    {
                                        newDomainName += tmpDomainName[i];
                                    }
                                }

                                newDomainName = newDomainName + "." + TreeViewNodeInfoClass.NodeName;
                                Parameters.DomainActionInfoClass.OldFullDomainName = oldDomainName;
                                Parameters.DomainActionInfoClass.SelfName          = txtInputContent.Text;
                                Parameters.DomainActionInfoClass.NodeContent       = txtInputContent.Text;
                                Parameters.DomainActionInfoClass.AliasName         = txtDesContent.Text;
                                Parameters.DomainActionInfoClass.PathName          = newDomainName;
                                Parameters.DomainActionInfoClass.NewFullDomainName = newDomainName;
                                Parameters.DomainActionInfoClass.IsStation         = (Convert.ToInt32((bool)chkStation.IsChecked)).ToString();

                                if (NetWorkClient.ControllerServer.Connected)
                                {
                                    //判断域名是否修改,如果没有修改就更新备注或者是否站点(需增加接口支持)
                                    NetWorkClient.ControllerServer.Send(JsonInterFace.ReNameDomainNodeName(oldDomainName, newDomainName, Convert.ToInt32(Parameters.DomainActionInfoClass.IsStation), Parameters.DomainActionInfoClass.AliasName));
                                }
                                else
                                {
                                    JsonInterFace.ShowMessage("网络与服务器断开!", (int)WindowMessageType.Warnning);
                                }
                            }
                            else
                            {
                                JsonInterFace.ShowMessage("该主域名称不能修改!", (int)WindowMessageType.Warnning);
                            }
                            //添加经纬度
                            if (TreeViewNodeInfoClass.IsStation && txtLngContent.Text != "" & txtLatContent.Text != "")
                            {
                                string ParentName = string.Empty;
                                Regex  re         = new Regex(@"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
                                for (int i = 0; i < TreeViewNodeInfoClass.FullNodeName.Split(new char[] { '.' }).Length - 1; i++)
                                {
                                    if (i == 0)
                                    {
                                        ParentName += TreeViewNodeInfoClass.FullNodeName.Split(new char[] { '.' })[i];
                                    }
                                    else
                                    {
                                        ParentName += "." + TreeViewNodeInfoClass.FullNodeName.Split(new char[] { '.' })[i];
                                    }
                                }
                                if (!re.IsMatch(txtLngContent.Text) || !re.IsMatch(txtLatContent.Text))
                                {
                                    MessageBox.Show("经纬度输入格式有误", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                    return;
                                }
                                NetWorkClient.ControllerServer.Send(JsonInterFace.Set_station_location_Request(ParentName, TreeViewNodeInfoClass.NodeName, JsonInterFace.StationMap.Lng, JsonInterFace.StationMap.Lat));
                            }
                        }
                        else if (TreeViewNodeInfoClass.Operation == DeviceTreeOperation.DeviceAdd)
                        {
                            Parameters.DeviceActionInfoClass.SelfID   = Parameters.DomainActionInfoClass.SelfID.ToString();
                            Parameters.DeviceActionInfoClass.ParentID = Parameters.DomainActionInfoClass.ParentID.ToString();

                            Parameters.DeviceActionInfoClass.DeviceName     = txtInputContent.Text.Trim();
                            Parameters.DeviceActionInfoClass.DomainFullName = TreeViewNodeInfoClass.FullNodeName;
                            NetWorkClient.ControllerServer.Send(JsonInterFace.AddDeviceNameRequest(Parameters.DeviceActionInfoClass.DomainFullName, Parameters.DeviceActionInfoClass.DeviceName, Parameters.DeviceActionInfoClass.Mode));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Parameters.PrintfLogsExtended(ex.Message, ex.StackTrace);
            }
        }