Ejemplo n.º 1
0
        private void changeConnectionState(ConnectionType connectionType, Enums.ConnectionState connectionState)
        {
            ToolStripStatusLabel selectedLabel = null;
            Color selectedColor = Color.Gray;

            switch (connectionType)
            {
            case MSSQL:
                selectedLabel = SQL_StatusLabel;
                break;

            case TCPIP:
                selectedLabel = TCP_StatusLabel;
                break;
            }
            switch (connectionState)
            {
            case disconnected:
                selectedColor = Color.Red;
                if (connectionType == TCPIP)
                {
                    connect_button.Enabled = true;
                    timer1.Stop();
                }
                break;

            case building:
                selectedColor = Color.Orange;
                if (connectionType == TCPIP)
                {
                    connect_button.Enabled = false;
                }
                break;

            case connected:
                selectedColor = Color.Green;
                if (connectionType == TCPIP)
                {
                    connect_button.Enabled = false;
                    timer1.Start();
                }
                break;
            }
            selectedLabel.Text      = connectionState.ToString();
            selectedLabel.ForeColor = selectedColor;
            Application.DoEvents();
        }
Ejemplo n.º 2
0
        private void viewForm_timer_Tick(object sender, EventArgs e)
        {
            if (!connection.Poll(0, SelectMode.SelectRead))
            {
                return;
            }
            try
            {
                byte[]   buffer       = new byte[1024];
                int      recieveSize  = connection.Receive(buffer);
                string   input        = Encoding.ASCII.GetString(buffer, 0, recieveSize);
                string[] splitedInput = input.Split(';');

                if (splitedInput[0] == "mssql")
                {
                    ConnectionType        currentConnectionType  = MSSQL;
                    Enums.ConnectionState currentConnectionState = ToConnectionState(splitedInput[1]);
                    changeConnectionState(currentConnectionType, currentConnectionState);
                }
                else if (splitedInput[0] == "question")
                {
                    if (!send_button.Enabled)
                    {
                        send_button.Enabled = true;
                    }
                    question_textBox.Text = splitedInput[1];
                    a_radioButton.Text    = splitedInput[2];
                    b_radioButton.Text    = splitedInput[3];
                    c_radioButton.Text    = splitedInput[4];
                    d_radioButton.Text    = splitedInput[5];
                }
            }
            catch (SocketException)
            {
                connection.Shutdown(SocketShutdown.Both);
                connection.Close();
                changeConnectionState(TCPIP, disconnected);
                changeConnectionState(MSSQL, disconnected);
            }
        }