Exemplo n.º 1
0
        private void btnFinished_Click(object sender, System.EventArgs e)
        {
            this.DialogResult = DialogResult.None;
            int ControlPort = 0;
            lbFSAddress.ForeColor = Color.Black;
            lbFSPort.ForeColor = Color.Black;

            try
            {
                ControlPort = System.Convert.ToInt32(tbFSPort.Text,10);
                if((ControlPort < 1)||(ControlPort > 65535))
                    ControlPort = System.Convert.ToInt32("Mess this up on purpose to trigger catch!",10);
            }
            catch
            {
                MessageBox.Show("Control Port must be a value between 1 and 65535!");
                lbFSPort.ForeColor = Color.Red;
                return;
            }

            if(FS != null)
            {
                if((FS.Address != tbFSAddress.Text)||(FS.Port != ControlPort))
                {
                    if(!FrmParent.OSystem.CheckAddressPortPair(tbFSAddress.Text,ControlPort))
                    {
                        MessageBox.Show("Address/Port Pair not unique in system");
                        lbFSAddress.ForeColor = Color.Red;
                        lbFSPort.ForeColor = Color.Red;
                        return;
                    }
                }
            }
            else
            {
                if(!FrmParent.OSystem.CheckAddressPortPair(tbFSAddress.Text,ControlPort))
                {
                    MessageBox.Show("Address/Port Pair not unique in system");
                    lbFSAddress.ForeColor = Color.Red;
                    lbFSPort.ForeColor = Color.Red;
                    return;
                }
            }
            int VSIndex = cbFSVSS.SelectedIndex;

            if(FS == null)
            {
                //Creating New Forwarding Server
                OysterClassLibrary.Functions F = new OysterClassLibrary.Functions();
                F.CreateForwardingServer(tbFSAddress.Text,Convert.ToInt32(VSID[VSIndex,1],10),ControlPort);
                F.Dispose();

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                //Editing Current Forward Server
                FS.Update(tbFSAddress.Text,Convert.ToInt32(VSID[VSIndex,1],10),ControlPort);
                Trace.WriteLine("Edited Forwarding Server: " + FS.Address + "(" + FS.ID + ")",
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);

                this.DialogResult = DialogResult.OK;
            }
        }