jace.tang
2023-02-11 ed8d469ccdc0e627d8f180bb92a9d78dbdb008b1
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
 
namespace M423project
{
    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 = "C:\\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)
        {
            //if (!Directory.Exists(ResultPath))
            //{
            //    Directory.CreateDirectory(ResultPath);
            //}
            //lock (_lock)
            //{
            //OperatorExcel operatorexcel = new OperatorExcel(ResultPath +name + ".xls", str1,str2,str3,flag);
            //operatorexcel.operatorExcel();
            //}
        }
    }
}