Skip to content

Commit 86309df

Browse files
committed
Add Some Feature
Add Some Feature
1 parent 8aaed8c commit 86309df

File tree

5 files changed

+511
-0
lines changed

5 files changed

+511
-0
lines changed

Loger2.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.IO;
6+
using System.Reflection;
7+
using System.Windows.Forms;
8+
9+
namespace PrintApp.Common
10+
{
11+
public class Loger
12+
{
13+
14+
public static void WriteLog(string Message)
15+
{
16+
if (System.Configuration.ConfigurationManager.AppSettings["Log"] != null
17+
&& "TRUE".Equals(System.Configuration.ConfigurationManager.AppSettings["Log"].ToUpper()))
18+
{
19+
string filePath = Path.Combine(Application.StartupPath, "Logs");
20+
if (!Directory.Exists(filePath))
21+
{
22+
Directory.CreateDirectory(filePath);
23+
}
24+
List<string> list = new List<string>();
25+
list.Add(string.Format("时间:{0}----------------------------------------------------------------------", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
26+
list.Add(Message);
27+
28+
try
29+
{
30+
if (!Directory.Exists(filePath))
31+
{
32+
Directory.CreateDirectory(filePath);
33+
}
34+
35+
File.AppendAllLines(Path.Combine(filePath, DateTime.Now.ToString("yyyy-MM-dd") + ".log"), list, Encoding.Default);
36+
}
37+
catch
38+
{ }
39+
}
40+
}
41+
42+
public static void WriteLog(Exception ex)
43+
{
44+
if (System.Configuration.ConfigurationManager.AppSettings["Log"] == null
45+
|| !"TRUE".Equals(System.Configuration.ConfigurationManager.AppSettings["Log"].ToUpper()))
46+
{
47+
return;
48+
}
49+
50+
StringBuilder sb = new StringBuilder();
51+
sb.AppendLine(string.Format("[ERRORMESSAGE]:{0}", ex.Message));
52+
sb.AppendLine(string.Format("[INNEREXCEPTION]:{0}", ex.InnerException));
53+
sb.AppendLine(string.Format("[SOURCE]:{0}", ex.Source));
54+
sb.AppendLine(string.Format("[STACKTRACE]:{0}", ex.StackTrace));
55+
WriteLog(sb.ToString());
56+
}
57+
}
58+
}

MessageHelperWinform.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows.Forms;
6+
7+
namespace PrintApp.Common
8+
{
9+
public class MessageHelper
10+
{
11+
private static string MessageTitle = "¿¨Æ¬´òӡϵͳ";
12+
13+
/// <summary>
14+
/// Show a error message
15+
/// </summary>
16+
/// <param name="Error"></param>
17+
public static void ShowError(string Error)
18+
{
19+
MessageBox.Show(Error, MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
20+
}
21+
22+
/// <summary>
23+
/// Show a info message
24+
/// </summary>
25+
/// <param name="Info"></param>
26+
public static void ShowInfo(string Info)
27+
{
28+
MessageBox.Show(Info, MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
29+
}
30+
31+
/// <summary>
32+
/// Show a question when click 'Yes' Button return ture else return false
33+
/// </summary>
34+
/// <param name="Question"></param>
35+
/// <returns></returns>
36+
public static bool ShowQuestion(string Question)
37+
{
38+
if (MessageBox.Show(Question, MessageTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
39+
{
40+
return true;
41+
}
42+
else
43+
{
44+
return false;
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)