示例#1
0
        public void click_submitQuestion(object sender, RoutedEventArgs e)
        {
            string qTextLen = (Question.Text.Length).ToString().PadLeft(2, '0');
            string ans1Len  = (Answer1.Text.Length).ToString().PadLeft(2, '0');
            string ans2Len  = (Answer2.Text.Length).ToString().PadLeft(2, '0');
            string ans3Len  = (Answer3.Text.Length).ToString().PadLeft(2, '0');
            string ans4Len  = (Answer4.Text.Length).ToString().PadLeft(2, '0');

            byte[] buffer = new ASCIIEncoding().GetBytes("230" + qTextLen + Question.Text + ans1Len + Answer1.Text + ans2Len + Answer2.Text + ans3Len + Answer3.Text + ans4Len + Answer4.Text), rcv = new byte[4];
            cl._clientStream.Write(buffer, 0, buffer.Length);
            cl._clientStream.Flush();
            cl._clientStream.Read(rcv, 0, 4);
            string answer = System.Text.Encoding.UTF8.GetString(rcv, 0, 3);

            if (answer != "130")
            {
                MessageBox.Show(this, "Error in sending the question");                 //130 == answer code for add question
            }
            else
            {
                answer = System.Text.Encoding.UTF8.GetString(rcv, 3, 1);
                if (answer == "0")
                {
                    MessageBox.Show(this, "Question added succesfully! Thanks for contributing!");               //1300 == success
                }
                else
                {
                    MessageBox.Show(this, "Error in adding the question"); //1301 == failure
                }
            }
            addQuestion q = new addQuestion();//reset window

            q.Show();
            this.Close();
        }
示例#2
0
        private void click_addQuestions(object sender, RoutedEventArgs e)
        {
            int i;

            for (i = 0; i < WPFclient.App.Current.Windows.Count; i++)
            {
                if (WPFclient.App.Current.Windows[i].ToString() == "WPFclient.addQuestion")
                {
                    break;
                }
            }
            if (i == WPFclient.App.Current.Windows.Count) //if there is createRoom open already
            {
                addQuestion q = new addQuestion();        //else create one and open it
                q.Show();
            }
            else
            {
                WPFclient.App.Current.Windows[i].Show();
            }
            this.Close();
        }