增加日志功能;关于窗体

This commit is contained in:
zhengxuan.zhang
2024-02-22 09:45:52 +08:00
parent 08daf2ced4
commit c16c4b0fb3
47 changed files with 149847 additions and 203 deletions
+80 -27
View File
@@ -15,10 +15,10 @@ namespace HexcalMC.Base
public static string StrDebugFile = Application.StartupPath + "\\File\\Debug.txt";
public static string StrDebugSavePath = Application.StartupPath + "\\File\\DebugFiles";
public static string StrDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看
static string _strStartTime = ""; //程序启动时间
static string _strEndTime = ""; //程序关闭时间
public static string _strStartTime = ""; //程序启动时间
public static string _strEndTime = ""; //程序关闭时间
public static RichTextBox TextBoxMsg;
public static RichTextBox textBox_Msg;
//=================================================================
@@ -49,50 +49,45 @@ namespace HexcalMC.Base
MyBase.TraceWriteLine(str);
}
public static void AddLogText(string str, Color mColor = new Color())
public static void AddLogText(string str, Color m_Color = new Color())
{
MyBase.TraceWriteLine(str);
try
{
TextBoxMsg.BeginInvoke((EventHandler)delegate
textBox_Msg.BeginInvoke((EventHandler)delegate
{
Color setColor = Color.White;
if (mColor == new Color())
Color SetColor = Color.Black;
if (m_Color == new Color())
{
if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") ||
str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") ||
str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败"))
if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") || str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") || str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败"))
{
setColor = Color.Red;
SetColor = Color.Red;
}
else if (str.ToUpper().Contains("WARNING") || str.ToUpper().Contains("警告"))
{
setColor = Color.DarkOrange;
SetColor = Color.DarkOrange;
}
}
else
{
setColor = mColor;
SetColor = m_Color;
}
string strText = DateTime.Now.ToString("HH:mm:ss.ff") + "--" + str + Environment.NewLine;
TextBoxMsg.SelectionStart = TextBoxMsg.TextLength;
textBox_Msg.SelectionStart = textBox_Msg.TextLength;
if (string.IsNullOrEmpty(str))
SetText(TextBoxMsg, str, setColor, false, 16);
SetText(textBox_Msg, str, SetColor, false, 16);
else
SetText(TextBoxMsg, strText, setColor, false, 16);
if (TextBoxMsg.Lines.Length > 800)
SetText(textBox_Msg, strText, SetColor, false, 16);
if (textBox_Msg.Lines.Length > 800)
{
TextBoxMsg.Select(0, TextBoxMsg.TextLength / 2);
TextBoxMsg.Cut();
textBox_Msg.Select(0, textBox_Msg.TextLength / 2);
textBox_Msg.Cut();
}
TextBoxMsg.ScrollToCaret();
textBox_Msg.ScrollToCaret();
});
}
catch
{
}
catch { }
}
public static void SetText(RichTextBox mRichTextBox, string strText, Color mColor, bool bBold = false,
@@ -116,14 +111,72 @@ namespace HexcalMC.Base
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
}
public static void SetErrorColor(Color inColor)
public static void SetErrorColor(Color InColor)
{
if (TextBoxMsg != null)
if (textBox_Msg != null)
{
TextBoxMsg.BeginInvoke((EventHandler)delegate { TextBoxMsg.BackColor = inColor; });
textBox_Msg.BeginInvoke((EventHandler)delegate
{
textBox_Msg.BackColor = InColor;
});
}
}
#endregion
}
public class Errors
{
/// <summary>
/// 0:无故障 PLC按位求 1对应101
/// 1:通讯故障
/// 2:扫描枪读取故障
/// 3: 控制柜急停被按下
/// 4:外部急停被按下
/// 5:PCL急停,辊道在CMM测量时上料
/// </summary>
public static int iErrors = 0;
/// 101:通讯故障
/// 102:扫描枪读取故障
/// 103: 控制柜急停被按下
/// 104:外部急停被按下
/// 105:PCL急停,辊道在CMM测量时上料
public static bool bCommError = false;
public static bool bReaderError = false;
public static bool bEStop_Controller = false;
public static bool bEStop_Out = false;
public static bool bEStop_Plc = false;
public static bool bTipSwitch = true;
public static StreamWriter ErrorWrite;
public static StreamWriter OtherWrite;
public static StreamWriter StatusWrite;
public static void WriteErrorDebug(string strError)
{
try
{
if (Errors.ErrorWrite == null)
Errors.ErrorWrite = new StreamWriter(DebugDfn.StrDebugSavePath + "Error_(" + DateTime.Now.ToString("yyyy-MM-dd") + ").txt", true);
Errors.ErrorWrite.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + strError);
Errors.ErrorWrite.Flush();
}
finally
{ }
}
public static void WriteOtherDebug(string strMsg)
{
try
{
if (Errors.OtherWrite == null)
Errors.OtherWrite = new StreamWriter(DebugDfn.StrDebugSavePath + "Other_(" + DateTime.Now.ToString("yyyy-MM-dd") + ").txt", true);
Errors.OtherWrite.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + strMsg);
Errors.OtherWrite.Flush();
}
finally
{ }
}
}
}