Ejemplo n.º 1
0
        private void btnFinished_Click(object sender, System.EventArgs e)
        {
            FrmParent.PostActivity();
            int ControlPort = 0;
            lbCardReaderAddress.ForeColor = Color.Black;
            lbCardReaderPort.ForeColor = Color.Black;

            try
            {
                ControlPort = System.Convert.ToInt32(tbCardReaderPort.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!");
                lbCardReaderPort.ForeColor = Color.Red;
                return;
            }
            int Index = cbCRRoom.SelectedIndex;

            if(CR != null)
            {
                if((CR.Address.ToUpper() != tbCardReaderAddress.Text.ToUpper())||(CR.Port != ControlPort))
                {
                    if(!FrmParent.OSystem.CheckAddressPortPair(tbCardReaderAddress.Text,ControlPort))
                    {
                        MessageBox.Show("Address/Port Pair not unique in System");
                        lbCardReaderAddress.ForeColor = Color.Red;
                        lbCardReaderPort.ForeColor = Color.Red;
                        return;
                    }
                }
            }
            else
            {
                if(!FrmParent.OSystem.CheckAddressPortPair(tbCardReaderAddress.Text,ControlPort))
                {
                    MessageBox.Show("Address/Port Pair not unique in System");
                    lbCardReaderAddress.ForeColor = Color.Red;
                    lbCardReaderPort.ForeColor = Color.Red;
                    return;
                }
            }
            if(CR == null)
            {
                //Creating new Card Reader
                try
                {
                    OysterClassLibrary.Functions F = new OysterClassLibrary.Functions();
                    F.CreateCardReader(tbCardReaderAddress.Text,ControlPort,Convert.ToInt32(RoomID[Index,1],10),chkIsOnSerialPort.Checked);
                    this.DialogResult = DialogResult.OK;
                }
                catch(Exception Err)
                {
                    MessageBox.Show(Err.Message);
                    return;
                }
            }
            else
            {
                try
                {
                    CR.Update(tbCardReaderAddress.Text,ControlPort,Convert.ToInt32(RoomID[Index,1],10),chkIsOnSerialPort.Checked);
                    Trace.WriteLine("Edit Card Reader: " + CR.Address +"(" + CR.ID.ToString() + ")",System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);

                    this.DialogResult = DialogResult.OK;
                }
                catch(Exception Err)
                {
                    MessageBox.Show(Err.Message);
                    return;
                }
            }
        }