Пример #1
0
        private void btnsure_Click(object sender, EventArgs e)
        {
            List <ServerList> tmpServerList     = new List <ServerList>();
            ServerList        _ServerList       = new ServerList();//StationList
            Server_Command    tmpServer_Command = new Server_Command();

            if (txtname.Text.Trim() == "")
            {
                MessageBox.Show("请填写服务器名称!"); return;
            }
            else if (txtname.Text.Trim().ToString().Length > 25)
            {
                MessageBox.Show("服务器名称超过25个字符!"); return;
            }

            string[] ipstring = txtip.Text.Trim().Split('.');
            if (ipstring.Length == 0)
            {
                MessageBox.Show("请填写IP"); return;
            }
            else
            {
                if (ipstring.Length == 4)
                {
                    int string_to_int = 0;
                    for (int i = 0; i < ipstring.Length; i++)
                    {
                        if (!int.TryParse(ipstring[i], out string_to_int))
                        {
                            MessageBox.Show("IP格式不合法"); return;
                        }
                        if (string_to_int > 254 || string_to_int < 0 || string_to_int.ToString() != ipstring[i])
                        {
                            MessageBox.Show("IP格式不合法"); return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("IP格式不合法"); return;
                }
            }
            if (tmpStation != null)
            {
                _ServerList.DeviceID = tmpStation.DeviceID;
            }
            _ServerList.Name   = txtname.Text.Trim();
            _ServerList.Ip     = txtip.Text.Trim();
            _ServerList.TypeID = Convert.ToInt32(DeviceParamType.ServerDevice);
            if (comboBox1.SelectedValue.ToString() != "")
            {
                _ServerList.StationID = new Guid(comboBox1.SelectedValue.ToString());
            }
            else
            {
                _ServerList.StationID = null;
            }
            _ServerList.Description = txtdescription.Text.Trim();
            tmpServerList.Add(_ServerList);
            if (tmpStation == null)
            {
                tmpServer_Command._AddData(tmpServerList);
                result = MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK);
            }
            else
            {
                tmpServer_Command._ReviseData(tmpServerList);
                result = MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK);
            }
            this.Close();
        }