예제 #1
0
        private void AddLog(LogData log)
        {
            if (log.Log == "")
            {
                string logstr;
                this.myRichtextBox1.AppendTextAsRtf("【", this.myRichtextBox1.Font, Color.Black);
                if (this.checkBoxX1.Checked)
                {
                    this.myRichtextBox1.AppendTextAsRtf(string.Format("{0}收到数据(HEX)", log.Time.ToString("yyyy-MM-dd HH:mm:ss")), this.myRichtextBox1.Font, Color.DarkSlateGray);
                    logstr = CVT.ByteToHexStr(log.Data);
                }
                else
                {
                    this.myRichtextBox1.AppendTextAsRtf(string.Format("{0}收到数据", log.Time.ToString("yyyy-MM-dd HH:mm:ss")), this.myRichtextBox1.Font, Color.DarkSlateGray);
                    logstr = Encoding.Default.GetString(log.Data);
                }
                if (!log.IsTcpClient)
                {
                    this.myRichtextBox1.AppendTextAsRtf(string.Format(",{0}:", log.IP), this.myRichtextBox1.Font, Color.SandyBrown);
                    this.myRichtextBox1.AppendTextAsRtf(string.Format("{0}", log.Port), this.myRichtextBox1.Font, Color.RoyalBlue);
                }
                this.myRichtextBox1.AppendTextAsRtf(string.Format(" Len:{0}", log.Data.Length), this.myRichtextBox1.Font, Color.Silver);
                this.myRichtextBox1.AppendTextAsRtf("】:", this.myRichtextBox1.Font, Color.Black);
                this.myRichtextBox1.AppendTextAsRtf(string.Format("{0}\r\n", logstr), this.myRichtextBox1.Font, Color.DarkBlue);
            }
            else
            {
                Color clr = Color.Green;
                switch (log.Loglevel)
                {
                case 1:
                    clr = Color.Green;
                    break;

                case 2:
                    clr = Color.Blue;
                    break;

                case 3:
                    clr = Color.Red;
                    break;

                default:
                    clr = Color.Blue;
                    break;
                }
                this.myRichtextBox1.AppendTextAsRtf(string.Format("【{0}:{1}】\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), log.Log), this.myRichtextBox1.Font, clr);
            }
        }
예제 #2
0
 private void buttonX_send_Click(object sender, EventArgs e)
 {
     if (!this.isend.IsStarted)
     {
         this.isend.SetLog(new LogData("尚未启动服务或未连接", 3));
     }
     else
     {
         if (!this.textBoxX_ip.Visible)
         {
             if (this.isend.GetClientsForSend().Count == 0)
             {
                 this.isend.SetLog(new LogData("请在先在左边列表框里选中要发送的列表", 3));
                 return;
             }
         }
         else if (this.textBoxX_ip.Text.Length == 0)
         {
             this.isend.SetLog(new LogData("请输入目标IP和端口号", 3));
             return;
         }
         if (this.textBoxX1.Text.Length == 0)
         {
             this.isend.SetLog(new LogData("请输入要发送的数据", 3));
         }
         else if (this.checkBoxX1.Checked)
         {
             try
             {
                 this.isend.Send(CVT.StrToHexByte(this.textBoxX1.Text));
             }
             catch
             {
                 this.isend.SetLog(new LogData("非法十六进制表示方式,请确认所输入字符为(0-9)(a-z)(A-Z)", 3));
             }
         }
         else
         {
             this.isend.Send(Encoding.Default.GetBytes(this.textBoxX1.Text));
         }
     }
 }
예제 #3
0
 private void checkBoxX1_CheckedChanged(object sender, EventArgs e)
 {
     if (this.textBoxX1.Text.Length != 0)
     {
         if (this.checkBoxX1.Checked)
         {
             this.textBoxX1.Text = CVT.ByteToHexStr(Encoding.Default.GetBytes(this.textBoxX1.Text));
         }
         else
         {
             try
             {
                 this.textBoxX1.Text = Encoding.Default.GetString(CVT.StrToHexByte(this.textBoxX1.Text));
             }
             catch
             {
                 MessageBoxEx.Show("非法十六进制表示方式,请确认所输入字符为(0-9)(a-z)(A-Z)");
             }
         }
     }
 }