ulysseskao
2016-05-01 8f5c8891aba521570fa63c4baf616e3a3c8d9526
update for logger
24 files modified
978 ■■■■■ changed files
CCSTrace/CCS/CCSMain.cs 98 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/EventAI/JudgeCase.cs 65 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/EventAI/TraceSubject.cs 69 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/FinishEvent.cs 199 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Function/InitialEventData.cs 20 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Function/Leach.cs 82 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Function/MailService.cs 3 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Function/MergeCase.cs 15 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/Addr_Contrast.cs 18 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/AlarmData.cs 36 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/CCSCodelist.cs 41 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/CCSRecord.cs 26 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/Dept_Contrast.cs 3 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/EOSCodelist.cs 30 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/EventQuery.cs 83 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/EventRecord.cs 2 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/LocateEquipment.cs 3 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/Object/NumberContrast.cs 3 ●●●●● patch | view | raw | blame | history
CCSTrace/CCS/ProcessEvent.cs 123 ●●●● patch | view | raw | blame | history
CCSTrace/CCS/RecordLog.cs 23 ●●●●● patch | view | raw | blame | history
CCSTrace/CCSTrace.csproj 4 ●●● patch | view | raw | blame | history
CCSTrace/Global.asax.cs 6 ●●●●● patch | view | raw | blame | history
CCSTrace/NLog.config 24 ●●●●● patch | view | raw | blame | history
CCSTrace/Service1.asmx.cs 2 ●●● patch | view | raw | blame | history
CCSTrace/CCS/CCSMain.cs
@@ -19,7 +19,7 @@
    {
        private const string DbConfigFilename = "DBConfig.xml";
        private static Logger _logger = LogManager.GetCurrentClassLogger();
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private static CcsMain _instance;
        public static ArrayList ProcessCases = new ArrayList();
@@ -29,7 +29,6 @@
        private int _connectionCount = 1;
        private OracleConnection _mainConn = null;
        private SEventLog _mainLog = null;
        private SmartThreadPool _mainjobThreadPool = null;
        private readonly object _syncDbQueue = new object();
@@ -58,15 +57,17 @@
        public void Startup()
        {
            _mainLog = new SEventLog();
            Logger.Info("CCSMain Startup.");
            try
            {
                ReadXml();
                Logger.Info("CCSMain ReadXml Complete.");
                if (_mainConn == null)
                    _mainConn = CreateConnection();
                //MainConn = CreateMainConnection();
                Logger.Info("CCSMain has been connected database.");
                GlobalVariable.CcsCodelist = new CcsCodelist(_mainConn);
                GlobalVariable.EosCodelist = new EosCodelist(_mainConn);
@@ -78,18 +79,11 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                _mainLog.Error(e.Message);
                if (GlobalVariable.ShowError)
                    _mainLog.Error(e.StackTrace);
                Logger.Error(e, e.Message);
                throw;
            }
            finally
            {
                _mainLog.Close();
            }
            CcsRecord mRecord = GetWaitRecord(_mainConn);
@@ -106,6 +100,7 @@
            stpStartInfo.MaxWorkerThreads = GlobalVariable.MaxThreadSize;
            stpStartInfo.MinWorkerThreads = GlobalVariable.MinThreadSize;
            _mainjobThreadPool = new SmartThreadPool(stpStartInfo);
            Logger.Info("Create Thread Pool.");
        }
        public void Shutdown()
@@ -116,8 +111,14 @@
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        public void AcceptEvent(CcsRecord record)
        {
            /*
            WorkItemCallback workItemCallback = new WorkItemCallback(this.DoWork);
            _mainjobThreadPool.QueueWorkItem(workItemCallback, record);
            */
            int i = 0;
            int reConnectCount = 1;
@@ -134,7 +135,8 @@
                            if (mRecord != null)
                            {
                                OracleConnection conn = _dbQueue.Dequeue();
                                OracleConnection conn = null;
                                lock (_syncDbQueue) conn = _dbQueue.Dequeue();
                                ProcessCase(mRecord, conn);
                            }
                        }
@@ -142,8 +144,9 @@
                        break;
                    }
                }
                catch (Exception)
                catch (Exception e)
                {
                    Logger.Error(e, e.Message);
                    if (_mainConn.State == ConnectionState.Closed)
                    {
                        i++;
@@ -216,7 +219,7 @@
            }
            catch (XmlException xe)
            {
                Console.WriteLine(xe.StackTrace);
                Logger.Error(xe, xe.Message);
                reader?.Close();
            }
        }
@@ -237,14 +240,12 @@
            try
            {
                _mainLog = new SEventLog();
                if (conn.State.ToString().Equals("Closed"))
                if (conn.State == ConnectionState.Closed)
                    conn.Open();
                transaction = conn.BeginTransaction();
                if (record.InsertDb(conn, transaction, _mainLog))
                if (record.InsertDb(conn, transaction))
                {
                    var eventQuery = new EventQuery
                    {
@@ -255,11 +256,11 @@
                    };
                    if (eventQuery.Insert(_mainLog, conn, transaction))
                    if (eventQuery.Insert(conn, transaction))
                        transaction.Commit();
                    else
                    {
                        if (transaction.Connection.State.ToString().Equals("Open"))
                        if (transaction.Connection.State == ConnectionState.Open)
                            transaction.Rollback();
                        throw new Exception("案件未受理成功。");
@@ -267,7 +268,7 @@
                }
                else
                {
                    if (transaction.Connection.State.ToString().Equals("Open"))
                    if (transaction.Connection.State == ConnectionState.Open)
                        transaction.Rollback();
                    throw new Exception("案件未受理成功。");
@@ -275,35 +276,21 @@
            }
            catch (OracleException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                _mainLog.Error(e.Message);
                Logger.Error(e, e.Message);
                if (GlobalVariable.ShowError)
                    _mainLog.Error(e.StackTrace);
                if (transaction != null && transaction.Connection.State.ToString().Equals("Open"))
                if (transaction != null && (transaction.Connection.State == ConnectionState.Open))
                    transaction.Rollback();
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                _mainLog.Error(ex.Message);
                Logger.Error(ex, ex.Message);
                if (GlobalVariable.ShowError)
                    _mainLog.Error(ex.StackTrace);
                if (transaction != null && transaction.Connection.State.ToString().Equals("Open"))
                if (transaction != null && (transaction.Connection.State == ConnectionState.Open))
                    transaction.Rollback();
                throw;
            }
            finally
            {
                _mainLog.Close();
            }
            return true;
@@ -391,11 +378,7 @@
                }
                catch (Exception e)
                {
                    Log(e.Message);
                    _mainLog.Error("無法取得等候處理CCS案件資料。錯誤訊息 = " + e.Message);
                    if (GlobalVariable.ShowError)
                        _mainLog.Error(e.StackTrace);
                    Logger.Error(e, e.Message);
                }
                finally
                {
@@ -405,7 +388,7 @@
            }
            if (ccsid.Length != 0)
                record = new CcsRecord(ccsid, conn, _mainLog);
                record = new CcsRecord(ccsid, conn);
            if (record != null)
            {
@@ -418,15 +401,15 @@
                try
                {
                    if (eventQuery.UpdateCaseStatus(_mainLog, conn, transaction))
                    if (eventQuery.UpdateCaseStatus(conn, transaction))
                    {
                        _mainLog.Info("更新EVENTQUERY的案件狀態為處理中.(CCSID = " + record.CcsId + ")");
                        Logger.Info("更新EVENTQUERY的案件狀態為處理中.(CCSID = " + record.CcsId + ")");
                        transaction.Commit();
                        ProcessCases.Add(record.CcsId);
                    }
                    else
                    {
                        _mainLog.Error("無法更新EVENTQUERY的案件狀態.(CCSID = " + record.CcsId + ")");
                        Logger.Error("無法更新EVENTQUERY的案件狀態.(CCSID = " + record.CcsId + ")");
                        if (transaction.Connection.State.ToString().Equals("Open"))
                            transaction.Rollback();
@@ -437,29 +420,12 @@
                    if (transaction.Connection.State.ToString().Equals("Open"))
                        transaction.Rollback();
                    Log(e.Message);
                    Logger.Error(e, e.Message);
                    record = null;
                }
            }
            return record;
        }
        private void Log(string message)
        {
            RecordLog pLog = null;
            try
            {
                pLog = new RecordLog(GlobalVariable.CcsListPath + "MAIN.txt");
                pLog.Error(message);
            }
            finally
            {
                if (pLog != null)
                {
                    pLog.Close();
                }
            }
        }
    }
}
CCSTrace/CCS/EventAI/JudgeCase.cs
@@ -2,11 +2,14 @@
using System.Collections;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.EventAI
{
    public class JudgeCase
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private TraceSubject _mTraceSubject;
        private readonly ArrayList _mCase = new ArrayList();
        private readonly int _damageFdrId;
@@ -23,12 +26,11 @@
        private readonly OracleConnection _connectionTpc;
        private readonly OracleTransaction _transaction;
        private readonly RecordLog _pLog;
        private readonly string _traceConnectionString;
        // int Range = 360; //比事故案件還早多久時間內的案件才作合併 單位:分
        public JudgeCase(int mFdrId, int mFsc, int mUfid, int mCaseId, string mAcceptDate, OracleConnection connection, OracleTransaction trx, string traceConnection, RecordLog log)
        public JudgeCase(int mFdrId, int mFsc, int mUfid, int mCaseId, string mAcceptDate, OracleConnection connection, OracleTransaction trx, string traceConnection)
        {
            _damageFdrId = mFdrId;
            _damageFsc = mFsc;
@@ -39,12 +41,11 @@
            _connectionTpc = connection;
            _transaction = trx;
            _traceConnectionString = traceConnection;
            _pLog = log;
        }
        public void AiBegin()
        {
            _pLog.Info("進行案件追蹤合併.");
            Logger.Info("進行案件追蹤合併.");
            // String ToTime = AcceptDate;
            var sqlStmt = "SELECT R.ACCEPTNUM,R.CASEID as CASEID,R.FDRID as FDRID,R.FSC as FSC,R.UFID as UFID,E.CASESTATUS as CASESTATUS,R.EVENTBRIEF as BRIEF "
@@ -56,7 +57,7 @@
            try
            {
                _pLog.Info("搜尋同一饋線上可供合併之母案件.");
                Logger.Info("搜尋同一饋線上可供合併之母案件.");
                command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
                reader = command.ExecuteReader();
@@ -75,15 +76,15 @@
                    record.Add(reader["BRIEF"].ToString());
                    record.Add(reader["ACCEPTNUM"].ToString());
                    _mCase.Add(record);
                    _pLog.Info(record[7].ToString() + ", " + record[0]);
                    Logger.Info(record[7].ToString() + ", " + record[0]);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Logger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                _pLog.Error("尋找母案件時發生錯誤.");
                Logger.Error("尋找母案件時發生錯誤.");
                throw e;
            }
            finally
@@ -100,8 +101,8 @@
            {
                _inferFsc = _damageFsc;
                _inferUfid = _damageUfid;
                _pLog.Info("此案件為饋線上第一件案件");
                _pLog.Info("追蹤合併結束.");
                Logger.Info("此案件為饋線上第一件案件");
                Logger.Info("追蹤合併結束.");
                return;
            }
@@ -118,8 +119,8 @@
                            _parentCaseId = Convert.ToInt32(((ArrayList)_mCase[i])[0].ToString());
                            _inferFsc = Convert.ToInt32(((ArrayList)_mCase[i])[2].ToString());
                            _inferUfid = Convert.ToInt32(((ArrayList)_mCase[i])[3].ToString());
                            _pLog.Info("相同變壓器");
                            _pLog.Info("與案件" + ((ArrayList)_mCase[i])[7] + "合併,故障點Fsc: " + _inferFsc + " Ufid: " + _inferUfid);
                            Logger.Info("相同變壓器");
                            Logger.Info("與案件" + ((ArrayList)_mCase[i])[7] + "合併,故障點Fsc: " + _inferFsc + " Ufid: " + _inferUfid);
                            return;
                        }
                    }
@@ -127,13 +128,13 @@
            }
            catch (Exception ex)
            {
                _pLog.Error(ex.Message);
                Logger.Error(ex.Message);
                throw ex;
            }
            _pLog.Info("不同變壓器,開始追蹤(New Version)...");
            Logger.Info("不同變壓器,開始追蹤(New Version)...");
            TraceCase();
            _pLog.Warn("追蹤合併結束");
            Logger.Warn("追蹤合併結束");
        }
        private void TraceCase()
@@ -142,12 +143,12 @@
            try
            {
                _mTraceSubject = new TraceSubject(_connectionTpc, _transaction, _traceConnectionString, _pLog);
                _pLog.Info("TraceSubject Startup....");
                _mTraceSubject = new TraceSubject(_connectionTpc, _transaction, _traceConnectionString);
                Logger.Info("TraceSubject Startup....");
            }
            catch (Exception ex)
            {
                _pLog.Error("TraceObject.dll無法初始化,請確認該元件是否存在或jre是否為 1.4 版,並確認是否註冊.");
                Logger.Error("TraceObject.dll無法初始化,請確認該元件是否存在或jre是否為 1.4 版,並確認是否註冊.");
                throw ex;
            }
@@ -155,7 +156,7 @@
            {
                _mTraceSubject.StartTrace(_damageFsc, _damageUfid, true);
                _newCase = _mTraceSubject.GetNewResult(); // 新案件所建出來的linkedlist(往上追到breaker)
                _pLog.Info("追蹤新案件完成");
                Logger.Info("追蹤新案件完成");
                for (int i = 0; i < _mCase.Count; i++)
                {
@@ -171,7 +172,7 @@
                        _mTraceSubject.StartTrace(Convert.ToInt32(((ArrayList)_mCase[i])[2].ToString()),
                                                       Convert.ToInt32(((ArrayList)_mCase[i])[3].ToString()), false);
                        _oldCase = _mTraceSubject.GetOldResult(); // 母案件所建出來的TreeMap(往上追到breaker)
                        _pLog.Info("追蹤母案件完成");
                        Logger.Info("追蹤母案件完成");
                        for (int j = 0; j < _newCase.Count; j++)
                        {
@@ -185,7 +186,7 @@
                                    _inferFsc = ((Equipment)_newCase[j]).Fsc;
                                    _inferUfid = ((Equipment)_newCase[j]).Ufid;
                                    _mEquip = (Equipment)((ArrayList)_mCase[i])[5];
                                    _pLog.Info("與案件" + ((ArrayList)_mCase[i])[7] + "合併,故障點Fsc: " + _inferFsc + " Ufid: " + _inferUfid);
                                    Logger.Info("與案件" + ((ArrayList)_mCase[i])[7] + "合併,故障點Fsc: " + _inferFsc + " Ufid: " + _inferUfid);
                                    return;
                                }
                            }
@@ -193,15 +194,15 @@
                    }
                    else
                    {
                        for (int k = 0; k < facilitySet.Count; k++)
                        foreach (object t1 in facilitySet)
                        {
                            bool merge = false; // 損壞設備是否在所切開的設備下游
                            Equipment damageEquipment = (Equipment)facilitySet[k]; // 切開的設備
                            Equipment damageEquipment = (Equipment)t1; // 切開的設備
                            for (int z = 0; z < _newCase.Count; z++)
                            foreach (object t in _newCase)
                            {
                                if ((((Equipment)_newCase[z]).Fsc== damageEquipment.Fsc) &&
                                     (((Equipment)_newCase[z]).Ufid== damageEquipment.Ufid))
                                if ((((Equipment)t).Fsc== damageEquipment.Fsc) &&
                                    (((Equipment)t).Ufid== damageEquipment.Ufid))
                                {
                                    merge = true;
                                    break;
@@ -217,18 +218,18 @@
                                    _inferFsc = damageEquipment.Fsc;
                                    _inferUfid = damageEquipment.Ufid;
                                    _mEquip = (Equipment)((ArrayList)_mCase[i])[5];
                                    _pLog.Info("與案件" + ((ArrayList)_mCase[i])[7] + "合併,故障點Fsc: " + _inferFsc + " Ufid: " + _inferUfid);
                                    Logger.Info("與案件" + ((ArrayList)_mCase[i])[7] + "合併,故障點Fsc: " + _inferFsc + " Ufid: " + _inferUfid);
                                    return;
                                }
                            }
                        } // for loop(k)
                        }
                    } // else
                } // for loop(i)
            }
            catch (Exception ex)
            {
                _pLog.Error(ex.Message);
                _pLog.Error("追蹤時發生錯誤.");
                Logger.Error(ex, ex.Message);
                Logger.Error("追蹤時發生錯誤.");
                throw;
            }
            finally
@@ -286,7 +287,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error("Problems occur: " + e.Message);
                Logger.Error("Problems occur: " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
@@ -321,7 +322,7 @@
            catch (Exception e)
            {
                // CCS.GlobalVariable.ErrorLog.setErrorLog("Error in JudgeCase(RealDamageEquipment) :" + e.getMessage());
                _pLog.Error("Problems occur: " + e.Message);
                Logger.Error("Problems occur: " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
CCSTrace/CCS/EventAI/TraceSubject.cs
@@ -1,12 +1,15 @@
using System;
using System.Collections;
using System.Data.OracleClient;
using NLog;
using TRACEROBJECTLib;
namespace CCSTrace.CCS.EventAI
{
    public class TraceSubject
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private string _mDbConnectionString;
        private static bool _isNewCase;
        private static ArrayList _mLinkList;                                // store the switch of the new case path
@@ -14,18 +17,16 @@
        private static Hashtable _mTreeMap;                             // store the switch of the old case path
        private static int _sFsc;
        private static int _sUfid;
        private readonly RecordLog _plogger;
        private readonly ArrayList _mTmp = new ArrayList();
        private NetworkContext _mPContext;
        private readonly OracleConnection _connectionTpc;
        private readonly OracleTransaction _transaction;
        public TraceSubject(OracleConnection conn, OracleTransaction trx, string traceConnectionString, RecordLog log)
        public TraceSubject(OracleConnection conn, OracleTransaction trx, string traceConnectionString)
        {
            _connectionTpc = conn;
            _transaction = trx;
            _plogger = log;
            _mDbConnectionString = traceConnectionString;
            try
@@ -37,7 +38,7 @@
            }
            catch (Exception ex)
            {
                _plogger.Error(ex.Message);
                Logger.Error(ex, ex.Message);
                throw ex;
            }
        }
@@ -72,9 +73,8 @@
            }
            catch (Exception e)
            {
                _plogger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                throw e;
                Logger.Error(e, e.Message);
                throw;
            }
        }
@@ -100,8 +100,7 @@
            }
            catch (Exception e)
            {
                _plogger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
@@ -133,16 +132,13 @@
            }
            catch (Exception e)
            {
                _plogger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
                if (command != null)
                    command.Dispose();
                command?.Dispose();
                if (reader != null)
                    reader.Close();
                reader?.Close();
            }
            return false;
        }
@@ -193,7 +189,7 @@
                        }
                        Console.WriteLine(node.ClassID + "----->" + node.ObjectID);
                        _plogger.Info(node.ClassID + "----->" + node.ObjectID);
                        Logger.Info(node.ClassID + "----->" + node.ObjectID);
                        iti.MoveDescent((short)0);
                    }
@@ -220,10 +216,8 @@
                        }
                        i++;    //後面直接就FINISH,所以就不用判斷tracecount
                        Console.WriteLine(node.ClassID + "----->" + node.ObjectID);
                        _plogger.Info(node.ClassID + "----->" + node.ObjectID);
                        Console.WriteLine("Trace Finish....");
                        _plogger.Info("Trace Finish....");
                        Logger.Info(node.ClassID + "----->" + node.ObjectID);
                        Logger.Info("Trace Finish....");
                        break;
                    }
                    // 當追蹤到被切開的開關且該上一層設備只有該開關一個child)
@@ -245,10 +239,8 @@
                            }
                            i++;    //後面直接就FINISH,所以就不用判斷tracecount
                            Console.WriteLine(node.ClassID + "----->" + node.ObjectID);
                            _plogger.Info(node.ClassID + "----->" + node.ObjectID);
                            Console.WriteLine("Trace Finish....");
                            _plogger.Info("Trace Finish....");
                            Logger.Info(node.ClassID + "----->" + node.ObjectID);
                            Logger.Info("Trace Finish....");
                            break;
                        }
@@ -309,8 +301,7 @@
                                        _mTmp.Add(equip);
                                    }
                                    Console.WriteLine(node.ClassID + "----->" + node.ObjectID);
                                    _plogger.Info(node.ClassID + "----->" + node.ObjectID);
                                    Logger.Info(node.ClassID + "----->" + node.ObjectID);
                                    i++;
                                    /*                                if (getTraceCount(node.ClassID, node.ObjectID) > 2)
@@ -344,8 +335,7 @@
                                            _mTmp.Add(equip);
                                        }
                                        Console.WriteLine(node.ClassID + "----->" + node.ObjectID);
                                        _plogger.Info(node.ClassID + "----->" + node.ObjectID);
                                        Logger.Info(node.ClassID + "----->" + node.ObjectID);
                                        i++;
                                        /*                                    if (getTraceCount(node.ClassID, node.ObjectID) > 2)
@@ -370,13 +360,11 @@
                        }
                    } // for
                } // while
                Console.WriteLine("Tree Node Count = " + i);
                _plogger.Info("Tree Node Count = " + i);
                Logger.Info("Tree Node Count = " + i);
            }
            else
            {
                Console.WriteLine("Tree is null");
                _plogger.Info("Tree is null");
                Logger.Info("Tree is null");
                throw new Exception("無法追蹤到任何設備,可能是該用戶所在變壓器設備連結性有問題。");
            }
        }
@@ -388,11 +376,11 @@
            try
            {
                ConfigTrace();
                _plogger.Info("configTrace OK.");
                Logger.Info("configTrace OK.");
            }
            catch (Exception e)
            {
                _plogger.Error(e.Message);
                Logger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                return tree;
            }
@@ -403,7 +391,7 @@
            }
            catch (Exception e)
            {
                _plogger.Error(e.Message);
                Logger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
            }
@@ -427,7 +415,7 @@
            }
            catch (Exception ex)
            {
                _plogger.Error(ex.Message);
                Logger.Error(ex, ex.Message);
            }
        }
@@ -459,13 +447,13 @@
            _mPContext.ResetContext();
            _plogger.Info("Set ModeTrace OK.");
            Logger.Info("Set ModeTrace OK.");
            ResultTreeBuilder trBuilder = _mPContext.CreateTreeBuilder();
            if (!trBuilder.constructResultTree(tContext, TRAVELTHREADMODE.CONMODE_SYNCHRONOUS)) { return null; }
            _plogger.Info("ConstructResultTree OK.");
            Logger.Info("ConstructResultTree OK.");
            ResultTree result = trBuilder.ResultTree;
            _plogger.Info("getResultTree OK.");
            Logger.Info("getResultTree OK.");
            return result;
        }
@@ -546,8 +534,7 @@
            }
            catch (Exception e)
            {
                _plogger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
                return false;
            }
            finally
CCSTrace/CCS/FinishEvent.cs
@@ -2,15 +2,17 @@
using System.Data.OracleClient;
using CCSTrace.CCS.Domain;
using NLog;
namespace CCSTrace.CCS
{
    public class FinishEvent
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private bool _upLevel;
        private int _originCaseStatus = 0;
        private Object.EventRecord _mEventRec = null;
        private RecordLog _pLog;
        private OracleConnection _connectionTpc;
        private OracleTransaction _transaction;
@@ -18,21 +20,20 @@
        {
        }
        public bool Finish(int mKind, Object.EventRecord mRecord, OracleConnection conn, OracleTransaction trx, RecordLog log)
        public bool Finish(int mKind, Object.EventRecord mRecord, OracleConnection conn, OracleTransaction trx)
        {
            _mEventRec = mRecord;
            _pLog = log;
            _connectionTpc = conn;
            _transaction = trx;
            _pLog.Info("進行OMS資料更新程序...");
            Logger.Info("進行OMS資料更新程序...");
            if (mRecord.ParentId== 0)
            { // Original Case
                if (!(ProcessSingalCase(mRecord)))
                {
                    return false;
                }
                _pLog.Info("更新eos.events成功!");
                Logger.Info("更新eos.events成功!");
            }
            else
            { // Child Case
@@ -40,7 +41,7 @@
                {
                    return false;
                }
                _pLog.Info("更新eos.events成功!");
                Logger.Info("更新eos.events成功!");
            }
            // inert into eos.eventrecord && eos.eventrecord_ex
@@ -51,7 +52,7 @@
            {
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("儲存資料時發生錯誤: 無法更新eos.eventrecord");
                    Logger.Error("儲存資料時發生錯誤: 無法更新eos.eventrecord");
                    command.Dispose();
                    return false;
                }
@@ -59,7 +60,7 @@
                command.CommandText = mRecord.LocateEquipment.GetSqlStmt();
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("儲存資料時發生錯誤: 無法更新eos.eventrecord_ex");
                    Logger.Error("儲存資料時發生錯誤: 無法更新eos.eventrecord_ex");
                    command.Dispose();
                    return false;
                }
@@ -72,81 +73,80 @@
                    {
                        if (!SetVisualCustomer(mRecord))
                        {
                            _pLog.Error("新增影響用戶資料錯誤.");
                            Logger.Error("新增影響用戶資料錯誤.");
                            return false;
                        }
                        _pLog.Info("新增影響用戶成功!");
                        Logger.Info("新增影響用戶成功!");
                    }
                    _upLevel = false; /* 判斷交辦案件是否升級為母案件 */
                    if (!(UpdateImportCase(mRecord)))
                    {
                        _pLog.Error("處理案件等級變更時發生錯誤.");
                        Logger.Error("處理案件等級變更時發生錯誤.");
                        return false;
                    }
                    _pLog.Info("處理案件等級變更成功!");
                    Logger.Info("處理案件等級變更成功!");
                    if (!(UpdateRecuseOrder(mRecord)))
                    {
                        _pLog.Error("新增搶修順序資料時發生錯誤.");
                        Logger.Error("新增搶修順序資料時發生錯誤.");
                        return false;
                    }
                    _pLog.Info("新增搶修順序成功!");
                    Logger.Info("新增搶修順序成功!");
                    if (mKind == GlobalVariable.CaseTypeChanged)
                    {
                        if (!DeleteOldCase(mRecord))
                        {
                            _pLog.Error("案件轉換發生錯誤");
                            Logger.Error("案件轉換發生錯誤");
                            return false;
                        }
                        _pLog.Info("案件轉換成功!");
                        Logger.Info("案件轉換成功!");
                    }
                    if (!SaveCustomerTel(mRecord))
                    {
                        _pLog.Error("無法將用戶電話回存回資料庫.");
                        Logger.Error("無法將用戶電話回存回資料庫.");
                        return false;
                    }
                    _pLog.Info("將用戶電話回存回資料庫成功!");
                    Logger.Info("將用戶電話回存回資料庫成功!");
                }
                else if (mKind == GlobalVariable.NoMeter)
                {
                    string sqlStmt;
                    sqlStmt = "INSERT INTO EOS.RESCUE_ORDER SELECT " + mRecord.CaseId+ ",999,COUNT(*) + 1,'',"
                            + mRecord.LocateEquipment.GetDsufid() + " FROM EOS.RESCUE_ORDER WHERE DSUFID = "
                            + mRecord.LocateEquipment.GetDsufid();
                    var sqlStmt = "INSERT INTO EOS.RESCUE_ORDER SELECT " + mRecord.CaseId+ ",999,COUNT(*) + 1,'',"
                                     + mRecord.LocateEquipment.GetDsufid() + " FROM EOS.RESCUE_ORDER WHERE DSUFID = "
                                     + mRecord.LocateEquipment.GetDsufid();
                    command1 = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
                    if (command1.ExecuteNonQuery() <= 0)
                    {
                        _pLog.Error("新增搶修順序資料時發生錯誤.");
                        Logger.Error("新增搶修順序資料時發生錯誤.");
                        command1.Dispose();
                        return false;
                    }
                    command1.Dispose();
                    _pLog.Info("新增搶修順序成功!");
                    Logger.Info("新增搶修順序成功!");
                }
                if (mRecord.ParentId== 0)
                {
                    if (!InsertIntoSri(mRecord))
                    {
                        _pLog.Error("新增資料庫(OCSDB.SRI)錯誤.");
                        Logger.Error("新增資料庫(OCSDB.SRI)錯誤.");
                        return false;
                    }
                    _pLog.Info("新增資料庫(OCSDB.SRI)成功!");
                    Logger.Info("新增資料庫(OCSDB.SRI)成功!");
                }
            }
            catch (Exception e)
            {
                Logger.Warn(e, e.Message);
                command.Dispose();
                if (command1 != null)
                    command1.Dispose();
                command1?.Dispose();
                throw e;
                throw;
            }
            /** COMMIT的動作須連外面CCS的資料都正確輸入完才作 */
@@ -155,10 +155,9 @@
        private bool ProcessSingalCase(Object.EventRecord mRecord)
        {
            string sqlStmt;
            bool result = false;
            sqlStmt = "INSERT INTO EOS.EVENTS VALUES(" + mRecord.CaseId+ "," + CCSCaseState.WaitForDespatch + ",1,"
                    + GlobalVariable.OriginalCase + ",0)";
            var result = false;
            var sqlStmt = "INSERT INTO EOS.EVENTS VALUES(" + mRecord.CaseId+ "," + CCSCaseState.WaitForDespatch + ",1,"
                             + GlobalVariable.OriginalCase + ",0)";
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
@@ -167,12 +166,11 @@
                if (command.ExecuteNonQuery() > 0)
                    result = true;
                else
                    _pLog.Error("儲存資料時發生錯誤:  無法insert eos.events");
                    Logger.Error("儲存資料時發生錯誤:  無法insert eos.events");
            }
            catch (Exception e)
            {
                _pLog.Error("儲存資料時發生錯誤:  無法insert eos.events. Error = " + e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, "儲存資料時發生錯誤:  無法insert eos.events. Error = " + e.Message);
            }
            finally
            {
@@ -183,10 +181,9 @@
        private bool ProcessMergeCase(Object.EventRecord mRecord)
        {
            string sqlStmt;
            // insert eos.events
            sqlStmt = "INSERT INTO EOS.EVENTS VALUES(" + mRecord.CaseId+ "," + CCSCaseState.WaitForDespatch + ",1,"
                    + GlobalVariable.ChildCase + ",0)";
            var sqlStmt = "INSERT INTO EOS.EVENTS VALUES(" + mRecord.CaseId+ "," + CCSCaseState.WaitForDespatch + ",1,"
                             + GlobalVariable.ChildCase + ",0)";
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
@@ -194,7 +191,7 @@
            {
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("儲存資料時發生錯誤:  無法insert eos.events");
                    Logger.Error("儲存資料時發生錯誤:  無法insert eos.events");
                    command.Dispose();
                    return false;
                }
@@ -205,7 +202,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("儲存資料時發生錯誤:  無法insert eos.mergecase");
                    Logger.Error("儲存資料時發生錯誤:  無法insert eos.mergecase");
                    command.Dispose();
                    return false;
                }
@@ -217,7 +214,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("儲存資料時發生錯誤:  無法更改母案件資料");
                    Logger.Error("儲存資料時發生錯誤:  無法更改母案件資料");
                    command.Dispose();
                    return false;
                }
@@ -229,7 +226,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("儲存資料時發生錯誤:  無法update eos.eventrecord(FSC,UFID)");
                    Logger.Error("儲存資料時發生錯誤:  無法update eos.eventrecord(FSC,UFID)");
                    command.Dispose();
                    return false;
                }
@@ -237,8 +234,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error("儲存資料時發生錯誤: " + e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, "儲存資料時發生錯誤: " + e.Message);
                command.Dispose();
                return false;
            }
@@ -267,7 +263,7 @@
            }
            catch (Exception)
            {
                _pLog.Error("無法判斷用戶種類.");
                Logger.Error("無法判斷用戶種類.");
                return false;
            }
            finally
@@ -321,7 +317,7 @@
            }
            catch (Exception)
            {
                _pLog.Error("無法確認是否需重新修改原始母案件之影響用戶資料.");
                Logger.Error("無法確認是否需重新修改原始母案件之影響用戶資料.");
                return false;
            }
            finally
@@ -358,7 +354,7 @@
                        command1.CommandText = sqlStmt;
                        if (command1.ExecuteNonQuery() < 0)
                        {
                            _pLog.Error("無法刪除原始案件的既有用戶資料.");
                            Logger.Error("無法刪除原始案件的既有用戶資料.");
                            command1.Dispose();
                            return false;
                        }
@@ -372,7 +368,7 @@
                        command1.CommandText = sqlStmt;
                        if (command1.ExecuteNonQuery() <= 0)
                        {
                            _pLog.Error("無法將原始案件的影響用戶數改為變壓器的全部用戶.");
                            Logger.Error("無法將原始案件的影響用戶數改為變壓器的全部用戶.");
                            command1.Dispose();
                            return false;
                        }
@@ -381,9 +377,8 @@
                }
                catch (Exception e)
                {
                    _pLog.Error("無法更新原始案件影響用戶資料: " + e.Message);
                    Console.WriteLine(e.StackTrace);
                    command1.Dispose();
                    Logger.Error(e, "無法更新原始案件影響用戶資料: " + e.Message);
                    command1?.Dispose();
                    return false;
                }
            }
@@ -397,7 +392,7 @@
            OracleCommand command2 = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            if (command2.ExecuteNonQuery() < 0)
            {
                _pLog.Error("無法新增新受理案件的影響用戶資料.");
                Logger.Error("無法新增新受理案件的影響用戶資料.");
                command2.Dispose();
                return false;
            }
@@ -407,8 +402,6 @@
        private bool UpdateImportCase(Object.EventRecord mRecord)
        {
            string sqlStmt;
            /* 該案件不為交辦案件 */
            if (mRecord.ImportCase!= GlobalVariable.IsImportCase)
            {
@@ -422,7 +415,7 @@
            }
            /* 若母案件已為交辦案件,則不需再作任何更動 */
            sqlStmt = "SELECT IMPORTCASE FROM EOS.EVENTRECORD WHERE CASEID = " + mRecord.ParentId;
            var sqlStmt = "SELECT IMPORTCASE FROM EOS.EVENTRECORD WHERE CASEID = " + mRecord.ParentId;
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            OracleDataReader reader = command.ExecuteReader();
@@ -434,9 +427,9 @@
                        return true;
                }
            }
            catch (Exception)
            catch (Exception e)
            {
                _pLog.Error("無法取得母案件之等級.");
                Logger.Error(e, "無法取得母案件之等級." + e.Message);
                return false;
            }
            finally
@@ -455,7 +448,7 @@
            OracleCommand command1 = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            if (command1.ExecuteNonQuery() <= 0)
            {
                _pLog.Error("無法將交辦案件改為母案件.");
                Logger.Error("無法將交辦案件改為母案件.");
                command1.Dispose();
                return false;
            }
@@ -466,7 +459,7 @@
            command1.CommandText = sqlStmt;
            if (command1.ExecuteNonQuery() <= 0)
            {
                _pLog.Error("無法將母案件改為子案件.");
                Logger.Error("無法將母案件改為子案件.");
                command1.Dispose();
                return false;
            }
@@ -477,7 +470,7 @@
            command1.CommandText = sqlStmt;
            if (command1.ExecuteNonQuery() <= 0)
            {
                _pLog.Error("無法將原先該母案件下的子案件都改掛在交辦案件下.");
                Logger.Error("無法將原先該母案件下的子案件都改掛在交辦案件下.");
                command1.Dispose();
                return false;
            }
@@ -488,7 +481,7 @@
            command1.CommandText = sqlStmt;
            if (command1.ExecuteNonQuery() <= 0)
            {
                _pLog.Error("無法將已INSERT入EOS.MERGECASE內的交辦案件資料改為原先母案件的資料(CaseID,AcceptNum).");
                Logger.Error("無法將已INSERT入EOS.MERGECASE內的交辦案件資料改為原先母案件的資料(CaseID,AcceptNum).");
                command1.Dispose();
                return false;
            }
@@ -499,9 +492,7 @@
        private bool UpdateOtherTable(int oldCaseId, int newCaseId, string newAcceptNum)
        {
            string sqlStmt;
            sqlStmt = "SELECT CASESTATUS FROM EOS.EVENTS WHERE CASEID = " + oldCaseId;
            var sqlStmt = "SELECT CASESTATUS FROM EOS.EVENTS WHERE CASEID = " + oldCaseId;
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            OracleDataReader reader = command.ExecuteReader();
@@ -516,7 +507,7 @@
                switch (_originCaseStatus)
                {
                    case 0:
                        _pLog.Error("找不到原始母案件之案件狀態.");
                        Logger.Error("找不到原始母案件之案件狀態.");
                        command.Dispose();
                        return false;
@@ -529,7 +520,7 @@
                        command.CommandText = sqlStmt;
                        if (command.ExecuteNonQuery() < 0)
                        {
                            _pLog.Error("無法更新EOS.EVENTDESPATCH.");
                            Logger.Error("無法更新EOS.EVENTDESPATCH.");
                            command.Dispose();
                            return false;
                        }
@@ -538,7 +529,7 @@
                        command.CommandText = sqlStmt;
                        if (command.ExecuteNonQuery() < 0)
                        {
                            _pLog.Error("無法更新EOS.EVENTS.");
                            Logger.Error("無法更新EOS.EVENTS.");
                            command.Dispose();
                            return false;
                        }
@@ -552,7 +543,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("無法更新EOS.Events的CaseStatus.");
                    Logger.Error("無法更新EOS.Events的CaseStatus.");
                    command.Dispose();
                    return false;
                }
@@ -563,7 +554,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() < 0)
                {
                    _pLog.Error("無法更新OCSDB.SRI.");
                    Logger.Error("無法更新OCSDB.SRI.");
                    command.Dispose();
                    return false;
                }
@@ -588,7 +579,7 @@
                    command.CommandText = sqlStmt;
                    if (command.ExecuteNonQuery() < 0)
                    {
                        _pLog.Error("無法更新EOS.EVENTFACILITY.");
                        Logger.Error("無法更新EOS.EVENTFACILITY.");
                        command.Dispose();
                        return false;
                    }
@@ -598,7 +589,7 @@
                    command.CommandText = sqlStmt;
                    if (command.ExecuteNonQuery() < 0)
                    {
                        _pLog.Error("無法更新EOS.CRTAPOLOGY.");
                        Logger.Error("無法更新EOS.CRTAPOLOGY.");
                        command.Dispose();
                        return false;
                    }
@@ -608,7 +599,7 @@
                    command.CommandText = sqlStmt;
                    if (command.ExecuteNonQuery() < 0)
                    {
                        _pLog.Error("無法更新EOS.EVENTAFFECT.");
                        Logger.Error("無法更新EOS.EVENTAFFECT.");
                        command.Dispose();
                        return false;
                    }
@@ -616,7 +607,7 @@
                    //                SqlStmt = "UPDATE EOS.VOICE SET CASEID = " + NewCaseID + " WHERE CASEID = " + OldCaseID;
                    //                if (CCS.GlobalVariable.Conn.UpdateDB(SqlStmt) < 0) {
                    //                    _PLog.error("無法更新EOS.VOICE.");
                    //                    Logger.error("無法更新EOS.VOICE.");
                    //                    return false;
                    //                }
@@ -626,7 +617,7 @@
                    command.CommandText = sqlStmt;
                    if (command.ExecuteNonQuery() < 0)
                    {
                        _pLog.Error("無法更新OCSDB.LOCKFEATURE");
                        Logger.Error("無法更新OCSDB.LOCKFEATURE");
                        command.Dispose();
                        return false;
                    }
@@ -635,8 +626,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
                reader.Close();
                command.Dispose();
                return false;
@@ -646,7 +636,6 @@
        private bool UpdateRecuseOrder(Object.EventRecord mRecord)
        {
            string sqlStmt;
            int rank = 999;
            int priority = 1;
            OracleCommand command = null;
@@ -665,6 +654,7 @@
            try
            {
                string sqlStmt;
                if (_upLevel)
                {
                    /* 將原先母案件的編號改為新的母案件編號 */
@@ -673,7 +663,7 @@
                    command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
                    if (command.ExecuteNonQuery() <= 0)
                    {
                        _pLog.Error("無法更新EOS.RESCUE_ORDER: 無法將原先母案件的編號改為新的母案件編號.");
                        Logger.Error("無法更新EOS.RESCUE_ORDER: 無法將原先母案件的編號改為新的母案件編號.");
                        command.Dispose();
                        return false;
                    }
@@ -736,7 +726,7 @@
                    command.CommandText = sqlStmt;
                    if (command.ExecuteNonQuery() < 0)
                    {
                        _pLog.Error("無法更新EOS.RESCUE_ORDER舊的搶修號碼.");
                        Logger.Error("無法更新EOS.RESCUE_ORDER舊的搶修號碼.");
                        command.Dispose();
                        return false;
                    }
@@ -748,7 +738,7 @@
                    command.CommandText = sqlStmt;
                    if (command.ExecuteNonQuery() <= 0)
                    {
                        _pLog.Error("無法新增EOS.RESCUE_ORDER的資料");
                        Logger.Error("無法新增EOS.RESCUE_ORDER的資料");
                        command.Dispose();
                        return false;
                    }
@@ -758,8 +748,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error("Problems occue during updating eos.rescue_order: " + e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, "Problems occue during updating eos.rescue_order: " + e.Message);
                if (command != null)
                    command.Dispose();
@@ -800,7 +789,7 @@
                {
                    reader.Close();
                    command.Dispose();
                    _pLog.Error("無法找到原先舊的案件.");
                    Logger.Error("無法找到原先舊的案件.");
                    return false;
                }
@@ -809,7 +798,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("刪除原先舊的案件的EOS.EVENTS發生錯誤.");
                    Logger.Error("刪除原先舊的案件的EOS.EVENTS發生錯誤.");
                    command.Dispose();
                    return false;
                }
@@ -819,7 +808,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("刪除原先舊的案件的EOS.EVENTRECORD發生錯誤.");
                    Logger.Error("刪除原先舊的案件的EOS.EVENTRECORD發生錯誤.");
                    command.Dispose();
                    return false;
                }
@@ -829,7 +818,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("刪除原先舊的案件的EOS.EVENTRECORD_EX發生錯誤.");
                    Logger.Error("刪除原先舊的案件的EOS.EVENTRECORD_EX發生錯誤.");
                    command.Dispose();
                    return false;
                }
@@ -839,7 +828,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() < 0)
                {
                    _pLog.Error("刪除原先舊的案件的EOS.TMPAFFECTCUSTMS發生錯誤.");
                    Logger.Error("刪除原先舊的案件的EOS.TMPAFFECTCUSTMS發生錯誤.");
                    command.Dispose();
                    return false;
                }
@@ -856,7 +845,7 @@
                        switch (Convert.ToInt32(reader["COUNT"].ToString()))
                        {
                            case 0:
                                _pLog.Error("無法找到原先母案件下掛的子案件.");
                                Logger.Error("無法找到原先母案件下掛的子案件.");
                                reader.Close();
                                command.Dispose();
                                return false;
@@ -868,7 +857,7 @@
                                command.CommandText = sqlStmt;
                                if (command.ExecuteNonQuery() <= 0)
                                {
                                    _pLog.Error("無法更新原先子案件(要提升為母案件)的資料.");
                                    Logger.Error("無法更新原先子案件(要提升為母案件)的資料.");
                                    reader.Close();
                                    command.Dispose();
                                    return false;
@@ -880,7 +869,7 @@
                                command.CommandText = sqlStmt;
                                if (command.ExecuteNonQuery() < 0)
                                {
                                    _pLog.Error("無法刪除原先子案件(要提升為母案件)EOS.TMPAFFECTYCUSTMS的資料.");
                                    Logger.Error("無法刪除原先子案件(要提升為母案件)EOS.TMPAFFECTYCUSTMS的資料.");
                                    reader.Close();
                                    command.Dispose();
                                    return false;
@@ -894,7 +883,7 @@
                                command.CommandText = sqlStmt;
                                if (command.ExecuteNonQuery() < 0)
                                {
                                    _pLog.Error("無法更新EOS.EVENTS的資料.");
                                    Logger.Error("無法更新EOS.EVENTS的資料.");
                                    reader.Close();
                                    command.Dispose();
                                    return false;
@@ -907,7 +896,7 @@
                    {
                        reader.Close();
                        command.Dispose();
                        _pLog.Error("無法找到原先母案件下掛的子案件.");
                        Logger.Error("無法找到原先母案件下掛的子案件.");
                        return false;
                    }
                }
@@ -917,7 +906,7 @@
                command.CommandText = sqlStmt;
                if (command.ExecuteNonQuery() <= 0)
                {
                    _pLog.Error("刪除EOS.MERGECASE發生錯誤");
                    Logger.Error("刪除EOS.MERGECASE發生錯誤");
                    command.Dispose();
                    return false;
                }
@@ -926,8 +915,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
                if (command != null)
                    command.Dispose();
@@ -939,12 +927,11 @@
        private bool InsertIntoSri(Object.EventRecord mRecord)
        {
            string sqlStmt;
            int count = 0;
            OracleCommand command = null;
            OracleDataReader reader = null;
            sqlStmt = "SELECT COUNT(*) as COUNT FROM OCSDB.SRI WHERE SCENENAME = '" + mRecord.AcceptNum+ "'";
            var sqlStmt = "SELECT COUNT(*) as COUNT FROM OCSDB.SRI WHERE SCENENAME = '" + mRecord.AcceptNum+ "'";
            try
            {
@@ -956,14 +943,12 @@
            }
            catch (Exception e)
            {
                _pLog.Error("Problems occur when checking SCENE Data: " + e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, "Problems occur when checking SCENE Data: " + e.Message);
                return false;
            }
            finally
            {
                if (reader != null)
                    reader.Close();
                reader?.Close();
            }
            if (count > 0)
@@ -983,8 +968,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Warn(e, e.Message);
            }
            finally
            {
@@ -1012,7 +996,7 @@
            // 電話資料過長
            if (mRecord.Tel.Trim().Length > 24)
            {
                _pLog.Warn("電話過長號碼,無法回存資料庫.");
                Logger.Warn("電話過長號碼,無法回存資料庫.");
                return true;
            }
@@ -1023,12 +1007,11 @@
            try
            {
                if (command.ExecuteNonQuery() <= 0)
                    _pLog.Warn("無法將用戶電話回存回資料庫.");
                    Logger.Warn("無法將用戶電話回存回資料庫.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Warn(e, e.Message);
            }
            finally
            {
CCSTrace/CCS/Function/InitialEventData.cs
@@ -1,28 +1,29 @@
using System;
using System.Data.OracleClient;
using System.Runtime.CompilerServices;
using NLog;
namespace CCSTrace.CCS.Function
{
    public class InitialEventData
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private string _mAcceptNum = "";
        private int _mCaseId = 0;
        private int _mYear = 0;
        private bool _mChangeYear = false;
        private string _mNowYear = string.Empty;
        private readonly string _mAcceptTime = "";
        private readonly RecordLog _pLog;
        private readonly OracleConnection _connectionTpc;
        //New CaseID and New AcceptNum must be seen by others,so it need not controled by transaction
        [MethodImpl(MethodImplOptions.Synchronized)]
        public InitialEventData(OracleConnection conn, RecordLog log)
        public InitialEventData(OracleConnection conn)
        {
            _connectionTpc = conn;
            _pLog = log;
            string sqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR,TO_CHAR(SYSDATE,'YYYY/MM/DD') as ACCEPTTIME FROM EOS.EVENTNUM";
            var sqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR,TO_CHAR(SYSDATE,'YYYY/MM/DD') as ACCEPTTIME FROM EOS.EVENTNUM";
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc);
            OracleDataReader reader = command.ExecuteReader();
@@ -38,13 +39,13 @@
                }
                else
                {
                    _pLog.Error("起始號碼資料遺失!");
                    Logger.Error("起始號碼資料遺失!");
                    return;
                }
            }
            catch (Exception e)
            {
                _pLog.Error("Problems occur when Initializing EventData: " + e.Message);
                Logger.Error(e, "Problems occur when Initializing EventData: " + e.Message);
                Console.WriteLine(e.StackTrace);
                return;
            }
@@ -94,9 +95,8 @@
            }
            catch (Exception e)
            {
                _pLog.Error("Problems occur during EventNumCreating: " + e.Message);
                Console.WriteLine(e.StackTrace);
                throw e;
                Logger.Error(e, "Problems occur during EventNumCreating: " + e.Message);
                throw;
            }
            finally
            {
@@ -137,7 +137,7 @@
        private void RegetNumber()
        {
            string sqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR FROM EOS.EVENTNUM";
            var sqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR FROM EOS.EVENTNUM";
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc);
            OracleDataReader reader = command.ExecuteReader();
CCSTrace/CCS/Function/Leach.cs
@@ -2,23 +2,24 @@
using System.Data.OracleClient;
using CCSTrace.CCS.Domain;
using NLog;
namespace CCSTrace.CCS.Function
{
    public class Leach
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private readonly MergeCase _mergeCase = new MergeCase();
        private readonly RecordLog _pLog;
        private readonly OracleConnection _connectionTpc;
        private readonly OracleTransaction _transaction;
        private readonly string _traceConnectionString;
        public Leach(OracleConnection conn, OracleTransaction trx, string traceConnection, RecordLog log)
        public Leach(OracleConnection conn, OracleTransaction trx, string traceConnection)
        {
            _connectionTpc = conn;
            _transaction = trx;
            _traceConnectionString = traceConnection;
            _pLog = log;
        }
        public int LeachCase(Object.EventRecord mNewRec)
@@ -58,7 +59,7 @@
            int importCase = -1;
            int tmpCaseId = 0;
            int caseType = -1;
            _pLog.Info("利用電號或地址檢查是否有已成立之案件.");
            Logger.Info("利用電號或地址檢查是否有已成立之案件.");
            // 檢查資料庫中此電號或地址是否已成立案件
            if (mNewRec.Meter.Trim().Length != 0)
@@ -83,13 +84,12 @@
                    tmpCaseId = Convert.ToInt32(reader["CASEID"].ToString());
                    caseType = Convert.ToInt32(reader["CASETYPE"].ToString());
                    mNewRec.TmpCaseId = tmpCaseId;
                    _pLog.Info("案件已成立:" + reader["ACCEPTNUM"].ToString() + " " + tmpCaseId + " " + caseType);
                    Logger.Info("案件已成立:" + reader["ACCEPTNUM"].ToString() + " " + tmpCaseId + " " + caseType);
                }
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e.Message);
                return GlobalVariable.FailureByDb;
            }
            finally
@@ -118,10 +118,10 @@
                    break;
                default:
                    _pLog.Error("無法辨別案件種類.");
                    Logger.Error("無法辨別案件種類.");
                    return GlobalVariable.FailureByDb;
            }
            _pLog.Info("檢查該案件有無切開關紀錄.");
            Logger.Info("檢查該案件有無切開關紀錄.");
            try
            {
@@ -133,7 +133,7 @@
                    // 有開關尚未恢復
                    if (reader["CLOSETIME"] == null)
                    {
                        _pLog.Info("有切開關且尚未恢復.");
                        Logger.Info("有切開關且尚未恢復.");
                        if ((mNewRec.ImportCase== importCase) || (importCase == GlobalVariable.IsImportCase))
                        {
                            mResult = AddCount(tmpCaseId);
@@ -146,7 +146,7 @@
                    else
                    {
                        // 開關都已恢復(同用戶須重新受理)
                        _pLog.Info("有切開關且已經恢復.");
                        Logger.Info("有切開關且已經恢復.");
                        int caseId;
                        // 找出案件編號需以母案件編號或該案件編號去找casestatus
@@ -172,7 +172,7 @@
                else
                {
                    // 未切過開關
                    _pLog.Info("無切開關紀錄.");
                    Logger.Info("無切開關紀錄.");
                    if ((mNewRec.ImportCase== importCase) || (importCase == GlobalVariable.IsImportCase))
                    {
                        mResult = AddCount(tmpCaseId);
@@ -204,8 +204,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
                return GlobalVariable.FailureByDb;
            }
            finally
@@ -218,18 +217,16 @@
        private int AddCount(int mCaseId)
        {
            string sqlStmt = "UPDATE EOS.EVENTS SET COUNT = COUNT + 1 WHERE CASEID = " + mCaseId;
            var sqlStmt = "UPDATE EOS.EVENTS SET COUNT = COUNT + 1 WHERE CASEID = " + mCaseId;
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            try
            {
                if (command.ExecuteNonQuery() > 0)
                    return GlobalVariable.SameCustomer;
                else
                    return GlobalVariable.FailureByDb;
                return command.ExecuteNonQuery() > 0 ? GlobalVariable.SameCustomer : GlobalVariable.FailureByDb;
            }
            catch (Exception)
            catch (Exception e)
            {
                Logger.Warn(e, e.Message);
                return GlobalVariable.FailureByDb;
            }
            finally
@@ -240,10 +237,9 @@
        private int GetCastStatus(int caseId)
        {
            string sqlStmt;
            int status = 0;
            sqlStmt = "SELECT CASESTATUS FROM CCS.EVENTQUERY WHERE CCSID IN (SELECT CCSID FROM CCS.NUM_CONTRAST " + "WHERE CASEID = " + caseId + ")";
            var sqlStmt = "SELECT CASESTATUS FROM CCS.EVENTQUERY WHERE CCSID IN (SELECT CCSID FROM CCS.NUM_CONTRAST " + "WHERE CASEID = " + caseId + ")";
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            OracleDataReader reader = null;
@@ -256,8 +252,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
@@ -285,30 +280,32 @@
                {
                    mNewRec.LocateEquipment.SetFsc(GlobalVariable.Breaker);
                    mNewRec.LocateEquipment.SetUfid(mNewRec.Ufid);
                    _pLog.Info("饋線全停:" + mNewRec.Fsc+ ", " + mNewRec.Ufid);
                    _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString, _pLog);
                    Logger.Info("饋線全停:" + mNewRec.Fsc+ ", " + mNewRec.Ufid);
                    _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString);
                    return GlobalVariable.Success;
                }
            }
            catch (EventAI.TraceLoopException)
            catch (EventAI.TraceLoopException e)
            {
                Logger.Warn(e, e.Message);
                return GlobalVariable.TraceCounts3;
            }
            catch (TraceException)
            catch (TraceException e)
            {
                Logger.Warn(e, e.Message);
                return GlobalVariable.TraceFailure;
            }
            catch (Exception ex)
            {
                _pLog.Error(ex.Message);
                Logger.Error(ex, ex.Message);
                return GlobalVariable.FailureByDb;
            }
            try
            {
                _pLog.Info("定位損壞設備!");
                Logger.Info("定位損壞設備!");
                int result = GetEquipment(mNewRec);
                _pLog.Info("FSC:" + mNewRec.Fsc+ ", Ufid:" + mNewRec.Ufid+ ", Tpclid:" + mNewRec.Tpclid+ ", FeederID:" + mNewRec.FdrId);
                Logger.Info("FSC:" + mNewRec.Fsc+ ", Ufid:" + mNewRec.Ufid+ ", Tpclid:" + mNewRec.Tpclid+ ", FeederID:" + mNewRec.FdrId);
                switch (result)
                { // get fsc,ufid,fdrid of sxfmr by meter
@@ -324,12 +321,12 @@
                            if (mNewRec.Brief.Length != 0 && mNewRec.Brief.Substring(0, 1).Equals("A"))
                            { // A類事故原因,做追蹤合併
                                _pLog.Info("<A類案件>");
                                _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString, _pLog);
                                Logger.Info("<A類案件>");
                                _mergeCase.Merge(mNewRec, _connectionTpc, _transaction, _traceConnectionString);
                            }
                            else
                            {
                                _pLog.Info("<非A類案件>");
                                Logger.Info("<非A類案件>");
                            }
                            if (changeCaseType)
@@ -352,17 +349,19 @@
                        break;
                }
            }
            catch (EventAI.TraceLoopException)
            catch (EventAI.TraceLoopException e)
            {
                Logger.Warn(e, e.Message);
                return GlobalVariable.TraceCounts3;
            }
            catch (TraceException)
            catch (TraceException e)
            {
                Logger.Warn(e, e.Message);
                mResult = GlobalVariable.TraceFailure;
            }
            catch (Exception ex1)
            {
                _pLog.Error(ex1.Message);
                Logger.Error(ex1, ex1.Message);
                mResult = GlobalVariable.FailureByDb;
            }
            return mResult;
@@ -408,7 +407,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Logger.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                return GlobalVariable.FailureByDb;
            }
@@ -452,7 +451,7 @@
            }
            catch (Exception ex)
            {
                _pLog.Error(ex.Message);
                Logger.Error(ex, ex.Message);
            }
            finally
            {
@@ -494,7 +493,7 @@
            }
            catch (Exception ex)
            {
                _pLog.Error(ex.Message);
                Logger.Error(ex, ex.Message);
                return GlobalVariable.FailureByDb;
            }
            finally
@@ -532,8 +531,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
CCSTrace/CCS/Function/MailService.cs
@@ -2,11 +2,14 @@
using System.Data.OracleClient;
using System.Net;
using System.Net.Mail;
using NLog;
namespace CCSTrace.CCS.Function
{
    public class MailService
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private SmtpClient _smtpClient;
        private string _smtpIp;
        private int _smtpPort;
CCSTrace/CCS/Function/MergeCase.cs
@@ -2,11 +2,14 @@
using System.Data.OracleClient;
using CCSTrace.CCS.Object;
using NLog;
namespace CCSTrace.CCS.Function
{
    public class MergeCase
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private EventRecord _lEventrecord;
        private EventAI.JudgeCase _mJudgeCase;
@@ -14,12 +17,12 @@
        {
        }
        public void Merge(EventRecord mEventrecord, OracleConnection conn, OracleTransaction trx, string traceConnection, RecordLog log)
        public void Merge(EventRecord mEventrecord, OracleConnection conn, OracleTransaction trx, string traceConnection)
        {
            try
            {
                _mJudgeCase = new EventAI.JudgeCase(mEventrecord.FdrId, mEventrecord.Fsc, mEventrecord.Ufid,
                                                        mEventrecord.CaseId, mEventrecord.AcceptDate, conn, trx, traceConnection, log);
                                                        mEventrecord.CaseId, mEventrecord.AcceptDate, conn, trx, traceConnection);
                _lEventrecord = mEventrecord;
                _mJudgeCase.AiBegin();
                _lEventrecord.ParentId = _mJudgeCase.GetParentCaseId();
@@ -28,13 +31,13 @@
            }
            catch (EventAI.TraceLoopException tle)
            {
                log.Error(tle.Message);
                throw tle;
                Logger.Error(tle, tle.Message);
                throw;
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                throw e;
                Logger.Error(e.Message);
                throw;
            }
        }
CCSTrace/CCS/Object/Addr_Contrast.cs
@@ -2,23 +2,22 @@
using System.Collections;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class AddrContrast
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        public static Hashtable MTotalData = null;
        public static string DefaultDept = "市區巡修課";
        private OracleConnection _connectionTpc;
        private RecordLog _pLog;
        public AddrContrast(OracleConnection conn, OracleTransaction trx, RecordLog log)
        public AddrContrast(OracleConnection conn, OracleTransaction trx)
        {
            _connectionTpc = conn;
            _pLog = log;
            string sqlStmt;
            string city;
            ArrayList mData = new ArrayList();
            string tmp = "";
@@ -26,7 +25,7 @@
                return;
            MTotalData = new Hashtable();
            sqlStmt = "SELECT DEPTID,CITY,TOWN,ROAD FROM CCS.ADDR_CONTRAST ORDER BY CITY,TOWN,ROAD";
            var sqlStmt = "SELECT DEPTID,CITY,TOWN,ROAD FROM CCS.ADDR_CONTRAST ORDER BY CITY,TOWN,ROAD";
            OracleCommand command = null;
            OracleDataReader reader = null;
@@ -38,7 +37,7 @@
                while (reader.Read())
                {
                    ArrayList mRecord = new ArrayList();
                    city = reader["CITY"].ToString();
                    var city = reader["CITY"].ToString();
                    mRecord.Add(city);
                    mRecord.Add(reader["TOWN"].ToString());
                    mRecord.Add(reader["ROAD"].ToString());
@@ -86,9 +85,10 @@
                        return deptId;
                }
            }
            catch (Exception)
            catch (Exception e)
            {
                _pLog.Warn("無法取得所屬巡修部門代號,預設案件所屬巡修部門為市區巡修課!");
                Logger.Warn(e , e.Message);
                Logger.Warn("無法取得所屬巡修部門代號,預設案件所屬巡修部門為市區巡修課!");
            }
            // 當找不到部門別時,Default 設定為市巡
            dept = GlobalVariable.EosCodelist.GetKeyId(GlobalVariable.Dept, DefaultDept);
CCSTrace/CCS/Object/AlarmData.cs
@@ -4,25 +4,23 @@
using System.Data.OracleClient;
using System.Net;
using System.Net.Sockets;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class AlarmData
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private Hashtable _mTotalData = new Hashtable();
        private RecordLog _pLog;
        private OracleConnection _connectionTpc;
        private OracleTransaction _transaction;
        public AlarmData(OracleConnection conn, OracleTransaction trx, RecordLog log)
        public AlarmData(OracleConnection conn, OracleTransaction trx)
        {
            _connectionTpc = conn;
            _transaction = trx;
            _pLog = log;
            string sqlStmt;
            sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
            var sqlStmt = "SELECT DEPTID,IP1,IP2,IP_PATROL FROM CCS.ALARM_IP";
            OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc, _transaction);
            OracleDataReader reader = command.ExecuteReader();
@@ -41,7 +39,7 @@
            }
            catch (Exception e)
            {
                _pLog.Error("Problems occur when fetch alarm data: (" + e.Message + ")");
                Logger.Error(e, "Problems occur when fetch alarm data: (" + e.Message + ")");
                Console.WriteLine(e.StackTrace);
            }
            finally
@@ -94,7 +92,7 @@
        public bool Alarm(string acceptNum, int dept)
        {
            _pLog.Info("開始Alarm...");
            Logger.Info("開始Alarm...");
            Socket mClient;
            ArrayList ipAddressSet = GetIpAddress(GetSscCode(dept, Convert.ToInt32(DateTime.Now.DayOfWeek)));
            string ip1;
@@ -104,14 +102,14 @@
            if (ipAddressSet != null)
            {
                _pLog.Info("已取得該部門所需通知的IP Address.");
                Logger.Info("已取得該部門所需通知的IP Address.");
                ip1 = ipAddressSet[1].ToString();
                ip2 = ipAddressSet[2].ToString();
                ipPatrol = ipAddressSet[3].ToString();
            }
            else
            {
                _pLog.Warn("無法取得該部門所需通知的IP Address!");
                Logger.Warn("無法取得該部門所需通知的IP Address!");
                return false;
            }
@@ -130,12 +128,12 @@
                mClient.Shutdown(SocketShutdown.Both);
                mClient.Close();
                RecordAlarmIp(acceptNum, ip1);
                _pLog.Info("已成功通知" + ip1 + " !");
                Logger.Info("已成功通知" + ip1 + " !");
                return true;
            }
            catch (Exception e)
            {
                _pLog.Warn("無法通知" + ip1 + ": " + e.Message);
                Logger.Warn("無法通知" + ip1 + ": " + e.Message);
            }
            try
@@ -153,12 +151,12 @@
                mClient.Shutdown(SocketShutdown.Both);
                mClient.Close();
                RecordAlarmIp(acceptNum, ip2);
                _pLog.Info("已成功通知" + ip2 + " !");
                Logger.Info("已成功通知" + ip2 + " !");
                return true;
            }
            catch (Exception e)
            {
                _pLog.Warn("無法通知" + ip2 + ": " + e.Message);
                Logger.Warn("無法通知" + ip2 + ": " + e.Message);
            }
            try
@@ -176,13 +174,13 @@
                mClient.Shutdown(SocketShutdown.Both);
                mClient.Close();
                RecordAlarmIp(acceptNum, ipPatrol);
                _pLog.Info("已成功通知" + ipPatrol + " !");
                Logger.Info("已成功通知" + ipPatrol + " !");
                return true;
            }
            catch (Exception e)
            {
                _pLog.Warn("無法通知" + ipPatrol + ": " + e.Message);
                _pLog.Warn("三個IP均無法通知到!");
                Logger.Warn("無法通知" + ipPatrol + ": " + e.Message);
                Logger.Warn("三個IP均無法通知到!");
                return false;
            }
        }
@@ -196,11 +194,11 @@
            try
            {
                if (command.ExecuteNonQuery() <= 0)
                    _pLog.Warn("無法紀錄Alarm IP!");
                    Logger.Warn("無法紀錄Alarm IP!");
            }
            catch (Exception e)
            {
                _pLog.Error("recordAlarmIP Error." + e.Message);
                Logger.Error("recordAlarmIP Error." + e.Message);
                return;
            }
            finally
CCSTrace/CCS/Object/CCSCodelist.cs
@@ -5,12 +5,16 @@
using System.Data.OracleClient;
using System.Linq;
using CCSTrace.CCS.Domain;
using CCSTrace.TPower.DMMS.Model.CCS;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class CcsCodelist
    {
        private readonly Dictionary<int, Dictionary<int, Codelist>> _mTotalData = new Dictionary<int, Dictionary<int, Codelist>>();
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private readonly Dictionary<int, Dictionary<int, CODELIST>> _mTotalData = new Dictionary<int, Dictionary<int, CODELIST>>();
        public CcsCodelist(OracleConnection connectionTpc)
        {
@@ -26,12 +30,12 @@
                    var keyId = Convert.ToInt32(reader["KEYID"].ToString());
                    var item = (reader["ITEM"].ToString());
                    var content = (reader["CONTENT"].ToString());
                    Codelist codelist = new Codelist(indexId, keyId, item, content);
                    CODELIST codelist = new CODELIST(indexId, keyId, item, content);
                    if (!_mTotalData.ContainsKey(indexId))
                    {
                        _mTotalData.Add(indexId, new Dictionary<int, Codelist>());
                        _mTotalData.Add(indexId, new Dictionary<int, CODELIST>());
                    }
                    Dictionary<int, Codelist> keys = _mTotalData[indexId];
                    Dictionary<int, CODELIST> keys = _mTotalData[indexId];
                    if (keys.ContainsKey(keyId))
                    {
                        keys.Add(keyId, codelist);
@@ -41,8 +45,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine("Error on Startup EOSCodelist: " + e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Warn(e, "Error on Startup CCSCodelist: " + e.Message);
            }
            finally
            {
@@ -51,27 +54,27 @@
            }
        }
        public Codelist[] GetAllContent(int mIndexId)
        public CODELIST[] GetAllContent(int mIndexId)
        {
            return _mTotalData[mIndexId].Values.ToArray();
        }
        public string GetContent(int mIndexId, int mKeyId)
        {
            return _mTotalData[mIndexId][mKeyId].Content;
            return _mTotalData[mIndexId][mKeyId].CONTENT;
        }
        public string GetContent(int mIndexId, string mItem)
        {
            string mResult = "";
            Dictionary<int, Codelist> mTmp = _mTotalData[mIndexId];
            Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];
            foreach (KeyValuePair<int, Codelist> pair in mTmp)
            foreach (KeyValuePair<int, CODELIST> pair in mTmp)
            {
                if (pair.Value.Item.Equals(mItem))
                if (pair.Value.ITEM.Equals(mItem))
                {
                    mResult = pair.Value.Content;
                    mResult = pair.Value.CONTENT;
                    break;
                }
            }
@@ -80,12 +83,12 @@
        public int GetKeyId(int mIndexId, string mContent)
        {
            Dictionary<int, Codelist> mTmp = _mTotalData[mIndexId];
            Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];
            int mResult = 0;
            foreach (KeyValuePair<int, Codelist> pair in mTmp)
            foreach (KeyValuePair<int, CODELIST> pair in mTmp)
            {
                if (pair.Value.Content.Equals(mContent))
                if (pair.Value.CONTENT.Equals(mContent))
                {
                    mResult = pair.Key;
                    break;
@@ -96,14 +99,14 @@
        public string GetItem(int mIndexId, string mContent)
        {
            Dictionary<int, Codelist> mTmp = _mTotalData[mIndexId];
            Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];
            string mResult = "";
            foreach (KeyValuePair<int, Codelist> pair in mTmp)
            foreach (KeyValuePair<int, CODELIST> pair in mTmp)
            {
                if (pair.Value.Content.Equals(mContent))
                if (pair.Value.CONTENT.Equals(mContent))
                {
                    mResult = pair.Value.Item;
                    mResult = pair.Value.ITEM;
                    break;
                }
            }
CCSTrace/CCS/Object/CCSRecord.cs
@@ -1,11 +1,14 @@
using System;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class CcsRecord
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private readonly string _meter;
        private readonly string _customerName;
        private readonly string _customerTel;
@@ -45,7 +48,7 @@
            _acceptTime = accepttime;
        }
        public CcsRecord(string ccsid, OracleConnection connectionTpc, SEventLog pLog)
        public CcsRecord(string ccsid, OracleConnection connectionTpc)
        {
            var sqlStmt = "SELECT METER,CUSTOMERNAME,CUSTOMERTEL,ADDR_CITY,ADDR_TOWN,ADDR_ROAD,ADDR_OTHER,RECALLNAME,RECALLTEL,EVENTBRIEF,"
                             + "TO_CHAR(ACCEPTTIME,'YYYY/MM/DD HH24:MI:SS') as ACCEPTTIME,CCSID,IMPORTCASE,DEPT,PARTHICUSTOMER,NOTE FROM CCS.EVENTRECORD "
@@ -78,13 +81,8 @@
            }
            catch (Exception e)
            {
                pLog.Error("無法取得CCS報案資訊!" + e.Message);
                Console.WriteLine(e.StackTrace);
                if (GlobalVariable.ShowError)
                    pLog.Error(e.StackTrace);
                throw e;
                Logger.Error(e, "無法取得CCS報案資訊!" + e.Message);
                throw;
            }
            finally
            {
@@ -125,7 +123,7 @@
        public string Note => _note;
        public bool InsertDb(OracleConnection connectionTpc, OracleTransaction transaction, SEventLog pLog)
        public bool InsertDb(OracleConnection connectionTpc, OracleTransaction transaction)
        {
            var sqlStmt = "INSERT INTO CCS.EVENTRECORD VALUES ('" + _meter + "','" + _customerName + "','" + _customerTel + "','" + _addrCity + "','"
                             + _addrTown + "','" + _addrRoad + "','" + _addrOther + "','" + _recallName + "','" + _recallTel + "',"
@@ -138,20 +136,12 @@
            {
                if (command.ExecuteNonQuery() != 1)
                {
                    pLog.Error("CCS 案件受理程序初始化失敗...無法將CCS報案資訊存入資料庫中!");
                    throw new Exception("CCS 案件受理程序初始化失敗...無法將CCS報案資訊存入資料庫中!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                if (GlobalVariable.ShowError)
                    pLog.Error(e.StackTrace);
                pLog.Error("CCS 案件受理程序初始化失敗...無法將CCS報案資訊存入資料庫中!" + e.Message);
                //throw new Exception("CCS 案件受理程序初始化失敗...無法將CCS報案資訊存入資料庫中");
                Logger.Error(e, e.Message);
                throw;
            }
            finally
CCSTrace/CCS/Object/Dept_Contrast.cs
@@ -2,11 +2,14 @@
using System.Collections;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class DeptContrast
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private ArrayList _mTotalData = null;
        public static string DefaultDept = "市區巡修課";
CCSTrace/CCS/Object/EOSCodelist.cs
@@ -5,12 +5,16 @@
using System.Data.OracleClient;
using System.Linq;
using CCSTrace.CCS.Domain;
using CCSTrace.TPower.DMMS.Model.CCS;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class EosCodelist
    {
        private readonly Dictionary<int, Dictionary<int, Codelist>> _mTotalData = new Dictionary<int, Dictionary<int, Codelist>>();
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private readonly Dictionary<int, Dictionary<int, CODELIST>> _mTotalData = new Dictionary<int, Dictionary<int, CODELIST>>();
        public EosCodelist(OracleConnection connection)
        {
@@ -26,12 +30,12 @@
                    var keyId = Convert.ToInt32(reader["KEYID"].ToString());
                    var item = (reader["ITEM"].ToString());
                    var content = (reader["CONTENT"].ToString());
                    Codelist codelist = new Codelist(indexId, keyId, item, content);
                    CODELIST codelist = new CODELIST(indexId, keyId, item, content);
                    if (!_mTotalData.ContainsKey(indexId))
                    {
                        _mTotalData.Add(indexId, new Dictionary<int, Codelist>());
                        _mTotalData.Add(indexId, new Dictionary<int, CODELIST>());
                    }
                    Dictionary<int, Codelist>  keys = _mTotalData[indexId];
                    Dictionary<int, CODELIST>  keys = _mTotalData[indexId];
                    if (keys.ContainsKey(keyId))
                    {
                        keys.Add(keyId, codelist);
@@ -50,27 +54,27 @@
            }
        }
        public Codelist[] GetAllContent(int mIndexId)
        public CODELIST[] GetAllContent(int mIndexId)
        {
            return _mTotalData[mIndexId].Values.ToArray();
        }
        public string GetContent(int mIndexId, int mKeyId)
        {
            return _mTotalData[mIndexId][mKeyId].Content;
            return _mTotalData[mIndexId][mKeyId].CONTENT;
        }
        public string GetContent(int mIndexId, string mItem)
        {
            string mResult = "";
            Dictionary<int, Codelist> mTmp = _mTotalData[mIndexId];
            Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];
            foreach (KeyValuePair<int, Codelist> pair in mTmp)
            foreach (KeyValuePair<int, CODELIST> pair in mTmp)
            {
                if (pair.Value.Item.Equals(mItem))
                if (pair.Value.ITEM.Equals(mItem))
                {
                    mResult = pair.Value.Content;
                    mResult = pair.Value.CONTENT;
                    break;
                }
            }
@@ -79,12 +83,12 @@
        public int GetKeyId(int mIndexId, string mContent)
        {
            Dictionary<int, Codelist> mTmp = _mTotalData[mIndexId];
            Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];
            int mResult = 0;
            foreach (KeyValuePair<int, Codelist> pair in mTmp)
            foreach (KeyValuePair<int, CODELIST> pair in mTmp)
            {
                if (pair.Value.Content.Equals(mContent))
                if (pair.Value.CONTENT.Equals(mContent))
                {
                    mResult = pair.Key;
                    break;
CCSTrace/CCS/Object/EventQuery.cs
@@ -1,10 +1,13 @@
using System;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class EventQuery
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        //private CCS.Function.TransferDate convert = new CCS.Function.TransferDate();
        public string CcsId { get; set; }
@@ -27,56 +30,7 @@
        public string EventLocation { get; set; } = "";
        public bool Insert(RecordLog pLog, OracleConnection conn, OracleTransaction transaction)
        {
            string sqlStmt;
            if (!Check())
            {
                return false;
            }
            if (Meter == null)
            {
                sqlStmt =
                    $"INSERT INTO CCS.EVENTQUERY (CCSID,CASESTATUS,CHANGETIME,ASSUMEDTIME,ASSUMEDTIME_NTH,DELAYTIMES,REASON,INPUTTIME) values(" +
                    "'" + CcsId
                    + "'," + CaseStatus + ",to_date('" + ChangeTime + "','yyyy/mm/dd hh24:mi:ss'),to_date('"
                    + AssumedTime + "','yyyy/mm/dd hh24:mi:ss'),to_date('" + AssumedTimeNth +
                    "','yyyy/mm/dd hh24:mi:ss')," + DelayTimes + ",'" + Reason + "',SYSDATE)";
            }
            else
            {
                sqlStmt =
                    $"INSERT INTO CCS.EVENTQUERY (CCSID,METER,CASESTATUS,CHANGETIME,ASSUMEDTIME,ASSUMEDTIME_NTH,DELAYTIMES,REASON,INPUTTIME) values(" +
                    "'"
                    + CcsId + "','" + Meter + "'," + CaseStatus + ",to_date('" + ChangeTime +
                    "','yyyy/mm/dd hh24:mi:ss'),to_date('" + AssumedTime + "','yyyy/mm/dd hh24:mi:ss'),to_date('"
                    + AssumedTimeNth + "','yyyy/mm/dd hh24:mi:ss')," + DelayTimes + ",'" + Reason + "',SYSDATE)";
            }
            var command = new OracleCommand(sqlStmt, conn, transaction);
            try
            {
                if (command.ExecuteNonQuery() > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception e)
            {
                pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                return false;
            }
            finally
            {
                command.Dispose();
            }
        }
        public bool Insert(SEventLog pLog, OracleConnection conn, OracleTransaction transaction)
        public bool Insert(OracleConnection conn, OracleTransaction transaction)
        {
            string sqlStmt;
@@ -115,13 +69,8 @@
            }
            catch (Exception e)
            {
                pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                if (GlobalVariable.ShowError)
                    pLog.Error(e.StackTrace);
                throw e;
                Logger.Error(e, e.Message);
                throw;
            }
            finally
            {
@@ -129,7 +78,7 @@
            }
        }
        public bool Update(RecordLog pLog, OracleConnection conn, OracleTransaction transaction)
        public bool Update(OracleConnection conn, OracleTransaction transaction)
        {
            if (!Check())
            {
@@ -148,14 +97,13 @@
            {
                if (command.ExecuteNonQuery() <= 0)
                {
                    pLog.Error("更新CCS.EVENTQUERY資料失敗.");
                    Logger.Error("更新CCS.EVENTQUERY資料失敗.");
                    return false;
                }
            }
            catch (Exception e)
            {
                pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
                return false;
            }
            finally
@@ -166,7 +114,7 @@
            return true;
        }
        public bool UpdateCaseStatus(SEventLog pLog, OracleConnection conn, OracleTransaction transaction)
        public bool UpdateCaseStatus(OracleConnection conn, OracleTransaction transaction)
        {
            var sqlStmt = "UPDATE CCS.EVENTQUERY SET CASESTATUS = " + CaseStatus + " WHERE CCSID = '" + CcsId + "'";
@@ -176,19 +124,14 @@
            {
                if (command.ExecuteNonQuery() <= 0)
                {
                    pLog.Error("更新CCS.EVENTQUERY的CASESTATUS失敗.");
                    Logger.Error("更新CCS.EVENTQUERY的CASESTATUS失敗.");
                    return false;
                }
            }
            catch (Exception e)
            {
                pLog.Error(e.Message);
                Console.WriteLine(e.StackTrace);
                if (GlobalVariable.ShowError)
                    pLog.Error(e.StackTrace);
                throw e;
                Logger.Error(e, e.Message);
                throw;
            }
            finally
            {
CCSTrace/CCS/Object/EventRecord.cs
@@ -1,9 +1,11 @@
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class EventRecord
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        //private CCS.Function.TransferDate Convert = new CCS.Function.TransferDate();
        public EventRecord(int mCaseId, OracleConnection conn, OracleTransaction trx)
CCSTrace/CCS/Object/LocateEquipment.cs
@@ -1,11 +1,14 @@
using System;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class LocateEquipment
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private int _caseId = 0;
        private int _dsUfid = -1;
        private int _fsc = 0;
CCSTrace/CCS/Object/NumberContrast.cs
@@ -1,11 +1,14 @@
using System;
using System.Data.OracleClient;
using NLog;
namespace CCSTrace.CCS.Object
{
    public class NumberContrast
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private string _ccsid;
        private string _acceptNum;
        private int _caseId;
CCSTrace/CCS/ProcessEvent.cs
@@ -12,13 +12,12 @@
    public class ProcessEvent
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        private readonly OracleConnection _connectionTpc;
        private readonly CcsRecord _mCcsRecord;
        private EventRecord _mEventRecord;
        private readonly RecordLog _pLog;
        private readonly string _traceConnectionString = string.Empty;
        private OracleTransaction _trx;
@@ -27,7 +26,6 @@
            _mCcsRecord = record;
            _connectionTpc = conn;
            _traceConnectionString = traceConnection;
            _pLog = new RecordLog(GlobalVariable.CcsListPath + record.CcsId + ".txt");
        }
        public event ThreadEndEventHandler ThreadFinish;
@@ -74,47 +72,47 @@
                */
                if (InitialEventRecord(_mCcsRecord.CcsId))
                {
                    var mLeach = new Leach(_connectionTpc, _trx, _traceConnectionString, _pLog); // 案件過濾與合併
                    _pLog.Info("過濾案件...");
                    var mLeach = new Leach(_connectionTpc, _trx, _traceConnectionString); // 案件過濾與合併
                    Logger.Info("過濾案件...");
                    var returnStatus = mLeach.LeachCase(_mEventRecord);
                    switch (returnStatus)
                    {
                        case GlobalVariable.Success:
                            _pLog.Info("案件過濾完畢....");
                            Logger.Info("案件過濾完畢....");
                            Process(GlobalVariable.Success);
                            break;
                        case GlobalVariable.NoMeter:
                            _pLog.Info("案件過濾完畢,用戶無電號....");
                            Logger.Info("案件過濾完畢,用戶無電號....");
                            _mEventRecord.TraceFinish = GlobalVariable.TraceFinish;
                            Process(GlobalVariable.NoMeter);
                            break;
                        case GlobalVariable.SameCustomer:
                            _pLog.Info("相同用戶重複來電....");
                            Logger.Info("相同用戶重複來電....");
                            ProcessSameCustomer(_mCcsRecord, _mEventRecord);
                            break;
                        case GlobalVariable.NoSupplyElc:
                            _pLog.Warn("該饋線未供電,無法作事故案件追蹤合併....");
                            Logger.Warn("該饋線未供電,無法作事故案件追蹤合併....");
                            _mEventRecord.TraceFinish = GlobalVariable.TraceFinish;
                            Process(GlobalVariable.NoMeter);
                            break;
                        case GlobalVariable.NoSxfmr:
                            _pLog.Warn("該案件無變壓器....");
                            Logger.Warn("該案件無變壓器....");
                            _mEventRecord.TraceFinish = GlobalVariable.TraceFinish;
                            Process(GlobalVariable.NoMeter);
                            break;
                        case GlobalVariable.CaseTypeChanged:
                            _pLog.Info("變更案件狀態....");
                            Logger.Info("變更案件狀態....");
                            Process(GlobalVariable.CaseTypeChanged);
                            break;
                        case GlobalVariable.TraceFailure:
                            _pLog.Error("故障追蹤錯誤,以一般無電號案件方式受理....");
                            Logger.Error("故障追蹤錯誤,以一般無電號案件方式受理....");
                            _mEventRecord.TraceFinish = GlobalVariable.TraceFinish;
                            Process(GlobalVariable.NoMeter);
                            break;
@@ -130,13 +128,13 @@
                                _trx.Dispose();
                                if (returnStatus == GlobalVariable.CaseTransfer)
                                    _pLog.Error("案件已移轉,此事故案件暫不被受理....");
                                    Logger.Error("案件已移轉,此事故案件暫不被受理....");
                                else if (returnStatus == GlobalVariable.FailureByDb)
                                    _pLog.Error("資料庫錯誤,此事故案件暫不被受理....");
                                    Logger.Error("資料庫錯誤,此事故案件暫不被受理....");
                                else if (returnStatus == GlobalVariable.FdrLocked)
                                    _pLog.Error("饋線被鎖定,此事故案件暫不被受理....");
                                    Logger.Error("饋線被鎖定,此事故案件暫不被受理....");
                                else
                                    _pLog.Error("發生非預期錯誤,此事故案件暫不被受理....");
                                    Logger.Error("發生非預期錯誤,此事故案件暫不被受理....");
                                if (traceCount == 0)
                                    UpdateTraceCount(_mCcsRecord.CcsId, true);
@@ -149,7 +147,7 @@
                                if (returnStatus == GlobalVariable.TraceCounts3)
                                    _mEventRecord.Note = _mEventRecord.Note+ "(本案用戶供電資料追蹤失敗)";
                                _pLog.Error("事故案件處理次數3次,仍無法正常處理,以一般無電號案件方式受理....");
                                Logger.Error("事故案件處理次數3次,仍無法正常處理,以一般無電號案件方式受理....");
                                _mEventRecord.TraceFinish = GlobalVariable.TraceFinish;
                                Process(GlobalVariable.NoMeter);
                                sendMail = true;
@@ -239,8 +237,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine("Error = " + e.Message + ". CCSID = " + _mCcsRecord.CcsId);
                _pLog.Error("Error = " + e.Message + ". CCSID = " + _mCcsRecord.CcsId);
                Logger.Error(e, e.Message + ". CCSID = " + _mCcsRecord.CcsId);
                if (_trx != null)
                {
@@ -256,7 +253,6 @@
            }
            finally
            {
                _pLog.Close();
                CcsMain.ProcessCases.Remove(_mCcsRecord.CcsId);
                OnThreadFinish(new ThreadEndEvent(_connectionTpc));
            }
@@ -271,12 +267,12 @@
            try
            {
                if (finishEvent.Finish(kind, _mEventRecord, _connectionTpc, _trx, _pLog))
                if (finishEvent.Finish(kind, _mEventRecord, _connectionTpc, _trx))
                {
                    _pLog.Info("OMS資料更新成功!");
                    Logger.Info("OMS資料更新成功!");
                    if (UpdateCcsData(_mEventRecord, _mCcsRecord, (int) CCSCaseState.WaitForDespatch))
                    {
                        _pLog.Info("CCS資料更新成功!");
                        Logger.Info("CCS資料更新成功!");
                    }
                    else
                    {
@@ -284,7 +280,7 @@
                            _trx.Rollback();
                        _trx.Dispose();
                        _pLog.Error("CCS資料更新程序發生錯誤!");
                        Logger.Error("CCS資料更新程序發生錯誤!");
                        return;
                    }
@@ -292,7 +288,7 @@
                    _trx.Commit();
                    _trx.Dispose();
                    ;
                    var alarmClient = new AlarmData(_connectionTpc, _trx, _pLog);
                    var alarmClient = new AlarmData(_connectionTpc, _trx);
                    alarmClient.Alarm(_mEventRecord.AcceptNum, _mEventRecord.Dept);
                }
                else
@@ -303,9 +299,9 @@
                    _trx.Dispose();
                    ;
                    _pLog.Error("OMS資料更新程序發生錯誤!");
                    Logger.Error("OMS資料更新程序發生錯誤!");
                }
                _pLog.Info("CCS 案件受理程序結束.");
                Logger.Info("CCS 案件受理程序結束.");
            }
            catch (Exception e)
            {
@@ -323,7 +319,7 @@
        private bool UpdateCcsData(EventRecord mRecord, CcsRecord mCcsRecord, int caseStatus)
        {
            _pLog.Info("進行CCS資料更新程序...");
            Logger.Info("進行CCS資料更新程序...");
            var eventQuery = new EventQuery();
            var status = caseStatus;
            // 設定CCSID
@@ -355,12 +351,12 @@
            }
            eventQuery.CaseStatus = status;
            // 更新CCS.EventQuery
            if (!eventQuery.Update(_pLog, _connectionTpc, _trx))
            if (!eventQuery.Update(_connectionTpc, _trx))
            {
                _pLog.Error("更新ccs.eventquery失敗!");
                Logger.Error("更新ccs.eventquery失敗!");
                return false;
            }
            _pLog.Info("更新ccs.eventquery成功!");
            Logger.Info("更新ccs.eventquery成功!");
            var numberContrast = new NumberContrast();
            numberContrast.SetAcceptNum(mRecord.AcceptNum);
            numberContrast.SetCaseId(mRecord.CaseId);
@@ -368,16 +364,16 @@
            // 更新CCS.Num_Contrast
            if (!numberContrast.Update(_connectionTpc, _trx))
            {
                _pLog.Error("更新ccs.num_contrast失敗!");
                Logger.Error("更新ccs.num_contrast失敗!");
                return false;
            }
            _pLog.Info("更新ccs.num_contrast成功!");
            Logger.Info("更新ccs.num_contrast成功!");
            return true;
        }
        private bool InitialEventRecord(string ccsid)
        {
            var initialData = new InitialEventData(_connectionTpc, _pLog);
            var initialData = new InitialEventData(_connectionTpc);
            var mContrast = new NumberContrast();
            DeptContrast deptContrast = null;
@@ -394,7 +390,7 @@
            if (!mContrast.Insert(_connectionTpc, _trx))
            {
                _pLog.Error("初始化寫入CCS.Num_Contrast時發生錯誤!");
                Logger.Error("初始化寫入CCS.Num_Contrast時發生錯誤!");
                if (_trx.Connection.State.ToString().Equals("Open"))
                    _trx.Rollback();
@@ -435,7 +431,7 @@
            if (mAddr.Trim().Length == 0)
            {
                _pLog.Error("CCS 案件受理程序初始化失敗...地址為空白");
                Logger.Error("CCS 案件受理程序初始化失敗...地址為空白");
                if (_trx.Connection.State.ToString().Equals("Open"))
                    _trx.Rollback();
@@ -506,7 +502,7 @@
                _mEventRecord.IsReCall = GlobalVariable.NotReCall;
            }
            _pLog.Info("初始化EOS.EVENTRECORD成功!");
            Logger.Info("初始化EOS.EVENTRECORD成功!");
            return true;
        }
@@ -546,7 +542,7 @@
            }
            catch (Exception ex)
            {
                _pLog.Warn("Problems occur during checking process: " + ex.Message);
                Logger.Warn(ex, "Problems occur during checking process: " + ex.Message);
            }
            finally
            {
@@ -557,7 +553,7 @@
        private int FindoutDeptByAddr(CcsRecord ccsRecord, OracleTransaction trx)
        {
            var addrContrast = new AddrContrast(_connectionTpc, trx, _pLog);
            var addrContrast = new AddrContrast(_connectionTpc, trx);
            return addrContrast.FindDeptId(ccsRecord.AddressCity, ccsRecord.AddressTown, ccsRecord.AddressRoad);
        }
@@ -596,9 +592,10 @@
                    status = Convert.ToInt32(reader["CaseStatus"].ToString());
                }
            }
            catch (Exception)
            catch (Exception e)
            {
                _pLog.Warn("無法取得正確之母案件狀態.");
                Logger.Error(e, e.Message);
                Logger.Warn("無法取得正確之母案件狀態.");
            }
            finally
            {
@@ -632,9 +629,10 @@
                    mEventQry.EventLocation = reader["eventlocation"].ToString();
                }
            }
            catch (Exception)
            catch (Exception e)
            {
                _pLog.Warn("無法取得母案件派工資訊.");
                Logger.Error(e, e.Message);
                Logger.Warn("無法取得母案件派工資訊.");
            }
            finally
            {
@@ -648,7 +646,7 @@
        private void ProcessSameCustomer(CcsRecord mCcsRecord, EventRecord mEventRec)
        {
            _pLog.Info("處理相同用戶重複來電...");
            Logger.Info("處理相同用戶重複來電...");
            StringBuilder note = null;
            var sqlStmt = "select note from eos.eventrecord where caseid = " + mEventRec.TmpCaseId;
@@ -662,8 +660,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
@@ -780,7 +777,7 @@
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Logger.Error(e, e.Message);
                }
                finally
                {
@@ -792,10 +789,10 @@
                }
            }
            var updEosEventRecord = "update eos.eventrecord set note = '" + TrimToLimit(note.ToString(), 127)
            var updEosEventRecord = "UPDATE EOS.EVENTRECORD SET NOTE = '" + TrimToLimit(note.ToString(), 127)
                                    + "' where caseid = " + _mEventRecord.TmpCaseId;
            var updCcsNumContrast = "update ccs.num_contrast set(acceptnum,caseid) = (select acceptnum," +
                                    mEventRec.TmpCaseId                                    + " from eos.eventrecord where caseid = " + mEventRec.TmpCaseId+
            var updCcsNumContrast = "UPDATE CCS.NUM_CONTRAST SET(acceptnum,caseid) = (SELECT acceptnum," +
                                    mEventRec.TmpCaseId                                    + " FROM eos.eventrecord WHERE caseid = " + mEventRec.TmpCaseId+
                                    ") where ccsid='" + mCcsRecord.CcsId + "'";
            var exeCommand = new OracleCommand(updCcsEventQuery, _connectionTpc, _trx);
@@ -808,7 +805,7 @@
                    _trx.Rollback();
                _trx.Dispose();
                _pLog.Error("Fail in write back to ccs.eventquery");
                Logger.Error("Fail in write back to ccs.eventquery");
                return;
            }
@@ -822,7 +819,7 @@
                    _trx.Rollback();
                _trx.Dispose();
                _pLog.Error("Fail in update eos.eventquery");
                Logger.Error("Fail in update eos.eventquery");
                return;
            }
@@ -835,14 +832,14 @@
                    _trx.Rollback();
                _trx.Dispose();
                _pLog.Error("Fail in insert into ccs.num_contrast");
                Logger.Error("Fail in insert into ccs.num_contrast");
                return;
            }
            exeCommand.Dispose();
            _trx.Commit();
            _trx.Dispose();
            _pLog.Info("CCS 案件受理程序結束");
            Logger.Info("CCS 案件受理程序結束");
        }
        private string TrimToLimit(string msg, int maxLen)
@@ -857,12 +854,12 @@
                {
                    return msg;
                }
                msg = msg.Substring(msg.IndexOf("|") + 1);
                msg = msg.Substring(msg.IndexOf("|", StringComparison.Ordinal) + 1);
                return TrimToLimit(msg, maxLen);
            }
            catch (Exception ex)
            catch (Exception e)
            {
                Console.WriteLine(ex.StackTrace);
                Logger.Error(e, e.Message);
                return "";
            }
        }
@@ -882,8 +879,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
@@ -947,8 +943,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
@@ -973,8 +968,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
@@ -1004,8 +998,7 @@
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Logger.Error(e, e.Message);
            }
            finally
            {
CCSTrace/CCS/RecordLog.cs
@@ -1,45 +1,36 @@
using System;
using System.IO;
using NLog;
namespace CCSTrace.CCS
{
    public class RecordLog
    {
        private readonly StreamWriter _sWriter = null;
        public RecordLog(string filePath)
        {
            _sWriter = new StreamWriter(filePath, true);
        }
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        public void Debug(object message)
        {
            _sWriter.WriteLine("[Debug] [" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "] : " + message);
            Logger.Debug(message);
        }
        public void Error(object message)
        {
            _sWriter.WriteLine("[Error] [" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "] : " + message);
            Logger.Error(message);
        }
        public void Fatal(object message)
        {
            _sWriter.WriteLine("[Fatal] [" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "] : " + message);
            Logger.Fatal(message);
        }
        public void Info(object message)
        {
            _sWriter.WriteLine("[Info] [" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "] : " + message);
            Logger.Info(message);
        }
        public void Warn(object message)
        {
            _sWriter.WriteLine("[Warn] [" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "] : " + message);
        }
        public void Close()
        {
            _sWriter.Close();
            Logger.Warn(message);
        }
    }
}
CCSTrace/CCSTrace.csproj
@@ -119,13 +119,11 @@
  <ItemGroup>
    <Compile Include="CCS\CCSMain.cs" />
    <Compile Include="CCS\Domain\CCSCaseState.cs" />
    <Compile Include="CCS\Domain\Codelist.cs" />
    <Compile Include="CCS\EventAI\Equipment.cs" />
    <Compile Include="CCS\EventAI\JudgeCase.cs" />
    <Compile Include="CCS\EventAI\TraceSubject.cs" />
    <Compile Include="CCS\Function\MailService.cs" />
    <Compile Include="CCS\GlobalVariable.cs" />
    <Compile Include="CCS\SEventLog.cs" />
    <Compile Include="CCS\FinishEvent.cs" />
    <Compile Include="CCS\Function\InitialEventData.cs" />
    <Compile Include="CCS\Function\Leach.cs" />
@@ -158,7 +156,7 @@
    <Compile Include="TPower\DMMS\Model\BaseDB\SXFMR.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\ADDRCONTRAST.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\ALARMIP.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\CODELIST.CODELIST.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\CODELIST.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\DEPTCONTRAST.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\EVENTQUERY.cs" />
    <Compile Include="TPower\DMMS\Model\CCS\EVENTRECORD.cs" />
CCSTrace/Global.asax.cs
@@ -5,15 +5,20 @@
using System.Web.Security;
using System.Web.SessionState;
using CCSTrace.CCS;
using NLog;
namespace CCSTrace
{
    public class Global : System.Web.HttpApplication
    {
        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        protected void Application_Start(object sender, EventArgs e)
        {
            Logger.Info("CCSTrace WebService Application Startup.");
            CcsMain appMain = CcsMain.Instance();
            string path = HttpContext.Current.Server.MapPath("~/App_Data");
            appMain.AppDataPath = path;
            appMain.Startup();
        }
@@ -44,6 +49,7 @@
        protected void Application_End(object sender, EventArgs e)
        {
            Logger.Info("CCSTrace WebService Application Shutdown.");
            CcsMain appMain = CcsMain.Instance();
            appMain.Shutdown();
        }
CCSTrace/NLog.config
@@ -29,8 +29,23 @@
    <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
            layout="${longdate} ${uppercase:${level}} ${message}" />
    -->
    <target xsi:type="File" name="file"
                fileName="${basedir}/App_Data/Logs/${shortdate}/ccstrace-${logger}.txt"
                layout="${longdate} | ${level:uppercase=true} | ${logger} | ${message} ${newline}" />
    <target xsi:type="File" name="fileRecord"
                fileName="${basedir}/App_Data/Logs/${shortdate}/ccsrecord-${logger}.txt"
                layout="${longdate} | ${level:uppercase=true} | ${logger} | ${message} ${newline}" />
    <target xsi:type="File" name="FatalFile"
                fileName="${basedir}/App_Data/Logs/${shortdate}/FatalFile.txt"
                layout="${longdate} | ${level:uppercase=true} | ${logger} | ${message} ${newline}" />
    <target xsi:type="EventLog" name="eventlog"
                source="CCSTrace" log="Application"
                layout="${date}: ${message} ${stacktrace}" />
    <target xsi:type="Trace" name="traceLog"
                layout="${longdate} | ${level:uppercase=true} | ${logger} | ${message} ${newline}" />
    <target xsi:type="Console" name="consoleLog"
                layout="${longdate} | ${level:uppercase=true} | ${logger} | ${message} ${newline}" />
  </targets>
  <rules>
    <!-- add your logging rules here -->
@@ -38,5 +53,12 @@
    Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace)  to "f"
    <logger name="*" minlevel="Debug" writeTo="f" />
    -->
    <logger name="*" levels="Trace, Debug, Info, Warn, Error, Fatal" writeTo="file" />
    <logger name="*" levels="Trace, Debug, Info, Warn, Error, Fatal" writeTo="consoleLog" />
    <logger name="*" levels="Trace, Debug, Info, Warn, Error, Fatal" writeTo="traceLog"/>
    <logger name="*" level="Warn, Error, Fatal" writeTo="FatalFile" />
    <logger name="*" level="Warn, Error, Fatal" writeTo="eventlog" />
    <logger name="CCSTrace.CCS.SEventLog" writeTo="eventlog" />
    <logger name="CCSTrace.CCS.RecordLog" writeTo="fileRecord" />
  </rules>
</nlog>
CCSTrace/Service1.asmx.cs
@@ -31,7 +31,7 @@
                                                                             addrOther, recallname, recalltel, eventbrief, accepttime, importcase, dept,
                                                                             partHicustomer, note);
            //_CCSMain.AcceptEvent(_Record);
            CCSTrace.CCS.CcsMain.Instance().AcceptEvent(record);
            CCS.CcsMain.Instance()?.AcceptEvent(record);
        }