Form_Debug.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace FPER
  12. {
  13. public partial class Form_Debug : Form
  14. {
  15. // 디버그 창 표시
  16. delegate void DebugEditBox_SetTextCallback(string Data);
  17. // 락킹
  18. public static Object lockInfo = new Object();
  19. public Form_Debug()
  20. {
  21. InitializeComponent();
  22. // 로그를 출력하는 이벤트
  23. _Event.Log_SendMessage_Event += new _Event.Log_SendMessage_Handler(_Event_DebugView_SendMessage_Event);
  24. }
  25. // 폼로드
  26. private void Form_Debug_Load(object sender, EventArgs e)
  27. {
  28. ComboBox_FontSize.Text = "10";
  29. ComboBox_Color.Text = "White";
  30. }
  31. // 폼클로우즈
  32. private void Form_Debug_FormClosed(object sender, FormClosedEventArgs e)
  33. {
  34. _Data.Enable_Form_Debug = false;
  35. _Data.Enable_Log = false;
  36. // 로그를 출력하는 이벤트
  37. _Event.Log_SendMessage_Event -= new _Event.Log_SendMessage_Handler(_Event_DebugView_SendMessage_Event);
  38. }
  39. // 디버그 메세지 이벤트
  40. public void _Event_DebugView_SendMessage_Event(string Data)
  41. {
  42. try
  43. {
  44. if (this.CheckBox_LogEnable.Checked == true)
  45. {
  46. if (this.editBox_Log.InvokeRequired)
  47. {
  48. DebugEditBox_SetTextCallback d = new DebugEditBox_SetTextCallback(_Event_DebugView_SendMessage_Event);
  49. this.Invoke(d, new object[] { Data });
  50. }
  51. else
  52. {
  53. lock (lockInfo)
  54. {
  55. if (this.editBox_Log.Text.Length > 100000) this.editBox_Log.Clear();
  56. this.editBox_Log.AppendText("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") + "]" + " " + Data + "\r\n");
  57. }
  58. }
  59. }
  60. }
  61. catch
  62. {
  63. ;
  64. }
  65. }
  66. // 클리어 버튼
  67. private void Button_Clear_Click(object sender, EventArgs e)
  68. {
  69. this.editBox_Log.Text = null;
  70. }
  71. // 저장 버튼
  72. private void Button_Save_Click(object sender, EventArgs e)
  73. {
  74. SaveFileDialog dialog = new SaveFileDialog();
  75. dialog.Filter = "(*.txt)|*.txt";
  76. dialog.FileName = Environment.CurrentDirectory + "\\" + "Log_Error.txt";
  77. if (dialog.ShowDialog() == DialogResult.OK)
  78. {
  79. Write_Log(dialog.FileName, this.editBox_Log.Text);
  80. //_Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, "OK", 250, 150, "로그를 저장하였습니다", 0);
  81. }
  82. }
  83. public static void Write_Log(string path, string txt)
  84. {
  85. try
  86. {
  87. if (path != null)
  88. path = Environment.CurrentDirectory + "\\" + "Log_Error.txt";
  89. if (!File.Exists(path))
  90. {
  91. // Create a file to write to.
  92. string createText = txt + "\r\n";// Environment.NewLine;
  93. File.WriteAllText(path, createText);
  94. }
  95. else
  96. {
  97. // This text is always added, making the file longer over time
  98. // if it is not deleted.
  99. string appendText = txt + "\r\n";
  100. File.AppendAllText(path, appendText);
  101. }
  102. }
  103. catch // (Exception e)
  104. {
  105. // LOG
  106. //_Event.DebugView_SendMessage_Write(e.ToString());
  107. }
  108. }
  109. // 복사 버튼
  110. private void Button_Copy_Click(object sender, EventArgs e)
  111. {
  112. Clipboard.Clear();
  113. Clipboard.SetText(this.editBox_Log.Text);
  114. //_Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, "OK", 350, 150, "로그를 클립보드에 저장하였습니다", 0);
  115. }
  116. private void ComboBox_FontSize_SelectedIndexChanged(object sender, EventArgs e)
  117. {
  118. switch (this.ComboBox_FontSize.Text)
  119. {
  120. case "8":
  121. this.editBox_Log.Font = new System.Drawing.Font("굴림", 8F);
  122. break;
  123. case "10":
  124. this.editBox_Log.Font = new System.Drawing.Font("굴림", 10F);
  125. break;
  126. case "12":
  127. this.editBox_Log.Font = new System.Drawing.Font("굴림", 12F);
  128. break;
  129. case "14":
  130. this.editBox_Log.Font = new System.Drawing.Font("굴림", 14F);
  131. break;
  132. case "16":
  133. this.editBox_Log.Font = new System.Drawing.Font("굴림", 16F);
  134. break;
  135. }
  136. this.editBox_Log.ResumeLayout();
  137. }
  138. private void ComboBox_Color_SelectedIndexChanged(object sender, EventArgs e)
  139. {
  140. switch (this.ComboBox_Color.Text)
  141. {
  142. case "White":
  143. this.editBox_Log.ForeColor = Color.White;
  144. break;
  145. case "Blue":
  146. this.editBox_Log.ForeColor = Color.Blue;
  147. break;
  148. case "Yellow":
  149. this.editBox_Log.ForeColor = Color.Yellow;
  150. break;
  151. case "Red":
  152. this.editBox_Log.ForeColor = Color.Red;
  153. break;
  154. }
  155. this.editBox_Log.ResumeLayout();
  156. }
  157. private void CheckBox_LogEnable_CheckedChanged(object sender, EventArgs e)
  158. {
  159. if (CheckBox_LogEnable.Checked == true) _Data.Enable_Log = true;
  160. else _Data.Enable_Log = false;
  161. }
  162. }
  163. }