Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //ip地址
            string[] ip = ipAddressControl1.Text.Split(new char[] { '.' });

            for (int i = 0; i < ip.Length; i++)
            {
                if (ip[i].Equals(""))
                {
                    MessageBox.Show("IP地址不可以空!");
                    return;
                }
            }
            //用户名
            string username = this.textBox2.Text.Trim();

            if (username.Equals(""))
            {
                MessageBox.Show("用户名不可以空!");
                return;
            }
            else if (username.Length < 4)
            {
                MessageBox.Show("用户名必须大于等于4个字符!");
                return;
            }

            //密码
            string password = this.textBox3.Text;

            string password2 = this.textBox4.Text;

            if (!password.Equals(password2))
            {
                MessageBox.Show("两次输入的密码必须相同!");
                return;
            }
            else if (password.Length < 6)
            {
                MessageBox.Show("密码长度必须大于等于6个字符!");
                return;
            }
            //组
            int groupid = -1;

            if (comboBox1.SelectedIndex < 0)
            {
                MessageBox.Show("请选择组!");
                return;
            }
            else
            {
                foreach (SysguardWS.GroupInfo info in groupInfo.Values)
                {
                    if (info.groupName.Equals(comboBox1.SelectedItem.ToString()))
                    {
                        groupid = info.groupId;
                        break;
                    }
                }
                if (groupid < 0)
                {
                    MessageBox.Show("未找到组!");
                    return;
                }
            }
            //主机名

            if (this.textBox1.Text.Trim().Equals(""))
            {
                MessageBox.Show("请输入主机名!");
                return;
            }
            //分区
            if (this.textBox7.Text.Trim().Equals(""))
            {
                MessageBox.Show("分区不能为空!");
                return;
            }

            //-------------------------

            sysguard.SysguardWS.HostInfo host = new sysguard.SysguardWS.HostInfo();

            host.description   = this.textBox8.Text;
            host.diskpartition = this.textBox7.Text;
            host.groupId       = groupid;
            host.hostIp        = this.ipAddressControl1.Text;
            host.validate      = 0;
            host.hostName      = this.textBox1.Text;


            DataLayerResult result = dataLayer.AddHost(host, textBox2.Text, textBox3.Text);

            if (result == DataLayerResult.Success)
            {
                DialogResult resultdialo = MessageBox.Show("添加主机成功!", "添加成功", MessageBoxButtons.YesNo);
                if (resultdialo == DialogResult.Yes)
                {
                    this.DialogResult = DialogResult.OK;

                    this.Dispose();
                }
                else
                {
                    reset();
                    hostControl.Flush();
                }
            }
            else if (result == DataLayerResult.HostIPAlreadyExist)
            {
                MessageBox.Show("主机IP已经存在无法添加!", "添加主机失败", MessageBoxButtons.OK);
                this.ipAddressControl1.Text = string.Empty;
                this.ipAddressControl1.Focus();
            }
            else if (result == DataLayerResult.HostNameAlreadyExist)
            {
                MessageBox.Show("主机名已经存在无法添加!", "添加主机失败", MessageBoxButtons.OK);
                this.textBox1.Text = string.Empty;
                this.textBox1.Focus();
            }
            else if (result == DataLayerResult.HostUserNameOrPwdError)
            {
                MessageBox.Show("用来登陆主机的用户名或密码错误无法添加!", "添加主机失败", MessageBoxButtons.OK);
                this.textBox2.Text = string.Empty;
                this.textBox3.Text = string.Empty;
                this.textBox4.Text = string.Empty;
                this.textBox2.Focus();
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            sysguard.SysguardWS.HostInfo host = new sysguard.SysguardWS.HostInfo();

            DataLayerResult result = dataLayer.GetAllGroupInfo();

            int group_id = -1;

            if (result == DataLayerResult.Success)
            {
                foreach (SysguardWS.GroupInfo info in dataLayer.GroupInfoList.Values)
                {
                    if (this.comboBox1.Text.Equals(info.groupName))
                    {
                        group_id = info.groupId;
                        break;
                    }
                }
            }

            if (group_id >= 0)
            {
                host.groupId = group_id;
            }
            else
            {
                MessageBox.Show("请选择组!");
                return;
            }
            //IP
            string[] ip = ipAddressControl1.Text.Split(new char[] { '.' });

            for (int i = 0; i < ip.Length; i++)
            {
                if (ip[i].Equals(""))
                {
                    MessageBox.Show("IP地址不可以空!");
                    return;
                }
            }
            //主机名
            if (this.textBox1.Text.Trim().Equals(""))
            {
                MessageBox.Show("请输入主机名!");
                return;
            }
            //分区
            if (this.textBox7.Text.Trim().Equals(""))
            {
                MessageBox.Show("分区不能为空!");
                return;
            }

            //

            host.hostId        = host_id;
            host.hostIp        = this.ipAddressControl1.Text;
            host.hostName      = this.textBox1.Text;
            host.description   = this.textBox8.Text;
            host.diskpartition = this.textBox7.Text;

            DataLayerResult result2 = dataLayer.ModifyHostInfo(host);

            if (result2 == DataLayerResult.Success)
            {
                DialogResult resultDialo = MessageBox.Show("修改主机信息成功是否退出?", "修改成功!", MessageBoxButtons.YesNo);

                if (resultDialo == DialogResult.Yes)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Dispose();
                }
                else
                {
                    hostControl.Flush();
                }
            }
        }