Beispiel #1
0
        //和客户端对话
        private void dealClient()
        {
            Socket     connection = this.connection;
            IPEndPoint iprm       = (IPEndPoint)connection.RemoteEndPoint;

            this.Dispatcher.Invoke(new Action(() => { TextBox3.AppendText("准备接受消息!\n"); }));
            Thread receiveThread = new Thread(ReceiveMessage);

            receiveThread.Start(connection);
        }
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            if (!double.TryParse(TextBox1.Text, out double a))
            {
                MessageBox.Show("Enter number");
                TextBox1.Clear();
                TextBox1.Focus();
                return;
            }
            if (!double.TryParse(TextBox2.Text, out double b))
            {
                MessageBox.Show("Enter number");
                TextBox2.Clear();
                TextBox2.Focus();
                return;
            }
            Func <double, double, double> f1 = null;
            string op = "";

            if (RadioSaberi.IsChecked == true)
            {
                f1 = (x, y) => x + y;
                op = "+";
            }
            else if (RadioOduzmi.IsChecked == true)
            {
                f1 = (x, y) => x - y;
                op = "-";
            }
            else if (RadioPomnozi.IsChecked == true)
            {
                f1 = (x, y) => x * y;
                op = "*";
            }
            else if (RadioPodeli.IsChecked == true)
            {
                f1 = (x, y) => x / y;
                op = "/";
            }
            else
            {
                MessageBox.Show("Pick operation");
                return;
            }
            double rezultat = f1(a, b);

            TextBox3.AppendText($"{a} {op} {b} = {rezultat}\n");
        }
Beispiel #3
0
        public void ReceiveMessage(object ClientSocket)
        {
            Socket     myClientSocket = (Socket)ClientSocket;
            IPEndPoint iprm           = (IPEndPoint)connection.RemoteEndPoint;

            while (true)
            {
                try
                {
                    //通过clientsocket接收数据
                    int num = myClientSocket.Receive(result);
                    //System.Windows.MessageBox.Show(Encoding.ASCII.GetString(result, 0, num));
                    //TB_recv_1.Text = "sss";
                    this.Dispatcher.Invoke(new Action(() => { TextBox3.AppendText(Encoding.ASCII.GetString(result, 0, num)); }));

                    Thread sendThread = new Thread(SendMessage);
                    sendThread.Start(myClientSocket);
                    // Message c = DealMsg1(Encoding.ASCII.GetString(result));
                    //c.msg2_tkt_ADc = iprm.Address.ToString();
                    //this.Dispatcher.Invoke(new Action(() => { TextBox2.AppendText(c.MMessage(c)); }));
                    //string ssmg;
                    // ssmg=c.ssMessage(c);
                    //this.Dispatcher.Invoke(new Action(() => { TextBox4.AppendText(ssmg); }));
                    // Byte[] ssmg1 = new byte[1024];
                    // ssmg1=Encoding.ASCII.GetBytes(ssmg);
                    // int num1= myClientSocket.Send(ssmg1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    //this.Dispatcher.Invoke(new Action(() => { TextBox3.AppendText("已断开连接"); }));
                    //myClientSocket.Shutdown(SocketShutdown.Both);
                    // myClientSocket.Close();
                    break;
                }
            }
        }
Beispiel #4
0
        private void Button1_Click(object sender, EventArgs e)
        {
            double rate;
            int    newAmount;
            int    euros;
            int    cents;

            if (year == 1)
            {
                oldAmount = Convert.ToInt32(TextBox1.Text);
            }

            rate = Convert.ToDouble(TextBox2.Text);

            newAmount = oldAmount + Convert.ToInt32(oldAmount * (rate / 100));
            euros     = (int)newAmount;
            cents     = 100 * (newAmount - euros);

            TextBox3.AppendText(String.Format("After {0} years the money has become {1} euros and {2} eurocents\r\n\r\n",
                                              year, euros, cents));

            oldAmount = newAmount;
            year      = year + 1;
        }