//////////////////////////////////////////////////////////////////////////
        private void OnAddLog(object sender, AddLogEventArgs e)
        {
            TxtLog.SelectionLength = 0;
            TxtLog.AppendText(e.Message.Replace("\n", "\r\n"));

            TxtLog.SelectionStart  = TxtLog.Text.Length;
            TxtLog.SelectionLength = 0;
            TxtLog.ScrollToCaret();
        }
Esempio n. 2
0
 public void AddLogLine(string logLine)
 {
     if (TxtLog != null && !TxtLog.IsDisposed)
     {
         TxtLog.AppendText(logLine.EndsWith(Environment.NewLine) ? logLine : (logLine + Environment.NewLine));
         if (!CkAutoScroll.Checked)
         {
             TxtLog.ScrollToCaret();
         }
     }
 }
Esempio n. 3
0
        private void SetText(string text)
        {
            if (TxtLog.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                Invoke(d, new object[] { text });
            }
            else
            {
                TxtLog.Text += text + Environment.NewLine + Environment.NewLine;

                TxtLog.SelectionStart = TxtLog.Text.Length;
                TxtLog.ScrollToCaret();
            }
        }
Esempio n. 4
0
 private void AppendLogToUI(string format, params object[] args)
 {
     try
     {
         Invoke(new MethodInvoker(delegate
         {
             try
             {
                 int iMax = 10000;
                 TxtLog.AppendText((TxtLog.TextLength > 0 ? Environment.NewLine : null) + ((args?.Length ?? 0) < 1 ? format : string.Format(format, args)));
                 if (TxtLog.TextLength > iMax)
                 {
                     TxtLog.Text = TxtLog.Text.Substring(TxtLog.Text.Length - iMax);
                 }
                 TxtLog.SelectionStart = TxtLog.TextLength;
                 TxtLog.ScrollToCaret();
             }
             catch (Exception ex2) { Logger?.Error(ex2); }
         }));
     } catch (Exception ex) { Logger?.Error(ex); }
 }
Esempio n. 5
0
        private async void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string RfcNumber = string.Empty;

            if (CheckConnect())
            {
                try
                {
                    string line = serialPort1.ReadLine();
                    TxtLog.Invoke(new MethodInvoker(delegate
                    {
                        TxtLog.Text          += DateTime.Now + ": " + line + "\n";
                        TxtLog.SelectionStart = TxtLog.Text.Length;
                        TxtLog.ScrollToCaret();
                    }));

                    if (line == "timeWait is Done\r")
                    {
                        timeWaitIsDone = true;
                    }
                    else
                    if (line.Substring(0, CardIDStringBegin.Length) == CardIDStringBegin)
                    {
                        RfcNumber = line.Substring(CardIDStringBegin.Length, line.Length - CardIDStringBegin.Length);
                        TxtCardID.Invoke(new MethodInvoker(delegate
                        {
                            TxtCardID.Text = RfcNumber;
                        }));


                        await PostNfcCard(RfcNumber);
                    }
                }
                catch (Exception ex)
                { }
            }
        }
Esempio n. 6
0
 private void WriteLogToUI(string format, params object[] args)
 {
     try
     {
         if (IsExit)
         {
             return;
         }
         Invoke(new MethodInvoker(delegate
         {
             try
             {
                 int iMax          = 100000;
                 char[] cArrayTrim = { ' ', '\t', (char)10, (char)13 };
                 string s          = (args?.Length ?? 0) < 1 ? format : string.Format(format, args);
                 TxtLog.AppendText(s.Trim(cArrayTrim) + Environment.NewLine);
                 if (TxtLog.TextLength > iMax)
                 {
                     TxtLog.Text = TxtLog.Text.Substring(TxtLog.Text.Length - iMax);
                 }
                 TxtLog.SelectionStart = TxtLog.TextLength;
                 TxtLog.ScrollToCaret();
             }
             catch (Exception ex2)
             {
                 try { Logger?.Error(ex2); }
                 catch (Exception ex3) { Console.WriteLine("[error] {0}.{1}. {2}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, System.Reflection.MethodBase.GetCurrentMethod().Name, ex3.Message); }
             }
         }));
     }
     catch (Exception ex)
     {
         try { Logger?.Error(ex); }
         catch (Exception ex4) { Console.WriteLine("[error] {0}.{1}. {2}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, System.Reflection.MethodBase.GetCurrentMethod().Name, ex4.Message); }
     }
 }
 private void TxtLog_TextChanged(object sender, EventArgs e)
 {
     // 设置日志显示在最底端
     TxtLog.SelectionStart = TxtLog.Text.Length;
     TxtLog.ScrollToCaret();
 }