コード例 #1
0
 private void buttonLoad_Click(object sender, EventArgs e)
 {
     myDevicePara = DevicePara.Load(myDevicePara.Path_PathName);
     ShowPara();
 }
コード例 #2
0
        private bool GetPara()
        {
            bool result = true;

            if (myDevicePara == null)
            {
                myDevicePara = new DevicePara();
            }
            myDevicePara.DeviceName  = this.textBoxDeviceName.Text;
            myDevicePara.BaudRate    = this.comboBoxBaudRate.SelectedIndex;
            myDevicePara.DataBits    = this.comboBoxDataBits.SelectedIndex;
            myDevicePara.Parity      = this.comboBoxPatity.SelectedIndex;
            myDevicePara.StopBits    = this.comboBoxStopBits.SelectedIndex;
            myDevicePara.FlowControl = this.comboBoxFlowControl.SelectedIndex;
            myDevicePara.IPMode      = this.comboBoxIPMode.SelectedIndex;
            //IP地址
            if (StringOperation.IsIP(this.textBoxIP.Text))
            {
                myDevicePara.IPaddress = this.textBoxIP.Text;
            }
            else
            {
                result = false;
                MessageBox.Show("IP地址格式错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //this.textBoxPort.Text = myDevicePara.Port.ToString();
            myDevicePara.WorkMode = this.comboBoxWorkMode.SelectedIndex;
            //子网掩码
            if (StringOperation.IsIP(this.textBoxMask.Text))
            {
                myDevicePara.NetMask = this.textBoxMask.Text;
            }
            else
            {
                result = false;
                MessageBox.Show("子网掩码格式错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //网关
            if (StringOperation.IsIP(this.textBoxGateway.Text))
            {
                myDevicePara.Gateway = this.textBoxGateway.Text;
            }
            else
            {
                result = false;
                MessageBox.Show("网关格式错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //端口号
            if (!int.TryParse(this.textBoxPort.Text, out myDevicePara.Port))
            {
                MessageBox.Show("端口号错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                result = false;
            }
            //目标IP地址
            if (StringOperation.IsIP(this.textBoxDestIP.Text))
            {
                myDevicePara.DestIP = this.textBoxDestIP.Text;
            }
            else
            {
                result = false;
                MessageBox.Show("目的IP或域名格式错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //目标端口号
            if (!int.TryParse(this.textBoxDestPort.Text, out myDevicePara.DestPort))
            {
                MessageBox.Show("目标端口号错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                result = false;
            }

            return(result);
        }
コード例 #3
0
 private void buttonDefault_Click(object sender, EventArgs e)
 {
     myDevicePara = new DevicePara();
     ShowPara();
 }