123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace FPER
- {
- public partial class Form_Debug : Form
- {
- // 디버그 창 표시
- delegate void DebugEditBox_SetTextCallback(string Data);
- // 락킹
- public static Object lockInfo = new Object();
- public Form_Debug()
- {
- InitializeComponent();
- // 로그를 출력하는 이벤트
- _Event.Log_SendMessage_Event += new _Event.Log_SendMessage_Handler(_Event_DebugView_SendMessage_Event);
- }
- // 폼로드
- private void Form_Debug_Load(object sender, EventArgs e)
- {
- ComboBox_FontSize.Text = "10";
- ComboBox_Color.Text = "White";
- }
- // 폼클로우즈
- private void Form_Debug_FormClosed(object sender, FormClosedEventArgs e)
- {
- _Data.Enable_Form_Debug = false;
- _Data.Enable_Log = false;
- // 로그를 출력하는 이벤트
- _Event.Log_SendMessage_Event -= new _Event.Log_SendMessage_Handler(_Event_DebugView_SendMessage_Event);
- }
- // 디버그 메세지 이벤트
- public void _Event_DebugView_SendMessage_Event(string Data)
- {
- try
- {
- if (this.CheckBox_LogEnable.Checked == true)
- {
- if (this.editBox_Log.InvokeRequired)
- {
- DebugEditBox_SetTextCallback d = new DebugEditBox_SetTextCallback(_Event_DebugView_SendMessage_Event);
- this.Invoke(d, new object[] { Data });
- }
- else
- {
- lock (lockInfo)
- {
- if (this.editBox_Log.Text.Length > 100000) this.editBox_Log.Clear();
- this.editBox_Log.AppendText("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") + "]" + " " + Data + "\r\n");
- }
- }
- }
- }
- catch
- {
- ;
- }
- }
- // 클리어 버튼
- private void Button_Clear_Click(object sender, EventArgs e)
- {
- this.editBox_Log.Text = null;
- }
- // 저장 버튼
- private void Button_Save_Click(object sender, EventArgs e)
- {
- SaveFileDialog dialog = new SaveFileDialog();
- dialog.Filter = "(*.txt)|*.txt";
- dialog.FileName = Environment.CurrentDirectory + "\\" + "Log_Error.txt";
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- Write_Log(dialog.FileName, this.editBox_Log.Text);
- //_Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, "OK", 250, 150, "로그를 저장하였습니다", 0);
- }
- }
- public static void Write_Log(string path, string txt)
- {
- try
- {
- if (path != null)
- path = Environment.CurrentDirectory + "\\" + "Log_Error.txt";
- if (!File.Exists(path))
- {
- // Create a file to write to.
- string createText = txt + "\r\n";// Environment.NewLine;
- File.WriteAllText(path, createText);
- }
- else
- {
- // This text is always added, making the file longer over time
- // if it is not deleted.
- string appendText = txt + "\r\n";
- File.AppendAllText(path, appendText);
- }
- }
- catch // (Exception e)
- {
- // LOG
- //_Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
- // 복사 버튼
- private void Button_Copy_Click(object sender, EventArgs e)
- {
- Clipboard.Clear();
- Clipboard.SetText(this.editBox_Log.Text);
- //_Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, "OK", 350, 150, "로그를 클립보드에 저장하였습니다", 0);
- }
- private void ComboBox_FontSize_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (this.ComboBox_FontSize.Text)
- {
- case "8":
- this.editBox_Log.Font = new System.Drawing.Font("굴림", 8F);
- break;
- case "10":
- this.editBox_Log.Font = new System.Drawing.Font("굴림", 10F);
- break;
- case "12":
- this.editBox_Log.Font = new System.Drawing.Font("굴림", 12F);
- break;
- case "14":
- this.editBox_Log.Font = new System.Drawing.Font("굴림", 14F);
- break;
- case "16":
- this.editBox_Log.Font = new System.Drawing.Font("굴림", 16F);
- break;
- }
- this.editBox_Log.ResumeLayout();
- }
- private void ComboBox_Color_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (this.ComboBox_Color.Text)
- {
- case "White":
- this.editBox_Log.ForeColor = Color.White;
- break;
- case "Blue":
- this.editBox_Log.ForeColor = Color.Blue;
- break;
- case "Yellow":
- this.editBox_Log.ForeColor = Color.Yellow;
- break;
- case "Red":
- this.editBox_Log.ForeColor = Color.Red;
- break;
- }
- this.editBox_Log.ResumeLayout();
- }
- private void CheckBox_LogEnable_CheckedChanged(object sender, EventArgs e)
- {
- if (CheckBox_LogEnable.Checked == true) _Data.Enable_Log = true;
- else _Data.Enable_Log = false;
- }
- }
- }
|