alvin.chen
2019-11-29 edf127edc771f715c49f86e91e768633f0a0ed93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
 
namespace LLMF
{
    public class Log
    {
        private static string logPath = string.Empty;
        private static string resultPath = string.Empty;
        private static object _lock = new object();
 
        public static string LogPath
        {
            get
            {
                if (logPath == string.Empty)
                {
                    //logPath = System.AppDomain.CurrentDomain.BaseDirectory+"\\Log\\";
                    //logPath = Application.StartupPath + "\\";
                    logPath = "D:\\Log\\";
                }
                return logPath;
            }
            set { Log.logPath = value; }
        }
        public static string ResultPath
        {
            get
            {
                if (resultPath == string.Empty)
                {
                    resultPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\Result\\";
                    //logPath = Application.StartupPath + "\\";
                }
                return resultPath;
            }
            set { Log.resultPath = value; }
        }
        public static void WriteLog(string text)
        {
            System.IO.StreamWriter sw = null;
            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }
            string fileFullFileName = LogPath + DateTime.Now.ToString("yyyyMMdd") + ".Log";
            try
            {
                lock (_lock)
                {
                    using (sw = System.IO.File.AppendText(fileFullFileName))
                    {
                        sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss: ") + text);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
 
        }
 
        public static void WriteExcel(string name, string str1, string str2, string str3, string flag)
        {
 
            string stringpath = resultPath + name + ".csv";
 
            if (!File.Exists(stringpath))
            {
                StringBuilder tile = new StringBuilder();
 
                tile.Append("Time" + "," + "Row" + "," + "Column" + "," + "Radius");
                File.AppendAllText(stringpath, tile.ToString());
                File.AppendAllText(stringpath, "\r\n");
            }
 
            StringBuilder Result = new StringBuilder();
            Result.Append(DateTime.Now.ToString("MM-dd HH:mm:ss"));
 
 
            Result.Append("," + str1 + "," + str2 + "," + str3 + "," + flag);
 
            File.AppendAllText(stringpath, Result.ToString());
            File.AppendAllText(stringpath, "\r\n");
        }
    }
}