| using System;  | 
|   | 
| using System.Collections;  | 
| using System.Collections.Generic;  | 
| 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 static readonly Logger Logger = LogManager.GetCurrentClassLogger();  | 
|   | 
|         private readonly Dictionary<int, Dictionary<int, CODELIST>> _mTotalData = new Dictionary<int, Dictionary<int, CODELIST>>();  | 
|   | 
|         public CcsCodelist(OracleConnection connectionTpc)  | 
|         {  | 
|             var sqlStmt = "SELECT INDEXID,KEYID,ITEM,CONTENT FROM CCS.CODELIST ORDER BY INDEXID,KEYID";  | 
|             OracleCommand command = new OracleCommand(sqlStmt, connectionTpc);  | 
|             OracleDataReader reader = command.ExecuteReader();  | 
|   | 
|             try  | 
|             {  | 
|                 while (reader.Read())  | 
|                 {  | 
|                     var indexId = Convert.ToInt32(reader["INDEXID"].ToString());  | 
|                     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);  | 
|                     if (!_mTotalData.ContainsKey(indexId))  | 
|                     {  | 
|                         _mTotalData.Add(indexId, new Dictionary<int, CODELIST>());  | 
|                     }  | 
|                     Dictionary<int, CODELIST> keys = _mTotalData[indexId];  | 
|                     if (keys.ContainsKey(keyId))  | 
|                     {  | 
|                         keys.Add(keyId, codelist);  | 
|                     }  | 
|   | 
|                 }  | 
|             }  | 
|             catch (Exception e)  | 
|             {  | 
|                 Logger.Warn(e, "Error on Startup CCSCodelist: " + e.Message);  | 
|             }  | 
|             finally  | 
|             {  | 
|                 reader.Close();  | 
|                 command.Dispose();  | 
|             }  | 
|         }  | 
|   | 
|         public CODELIST[] GetAllContent(int mIndexId)  | 
|         {  | 
|             return _mTotalData[mIndexId].Values.ToArray();  | 
|         }  | 
|   | 
|         public string GetContent(int mIndexId, int mKeyId)  | 
|         {  | 
|             return _mTotalData[mIndexId][mKeyId].CONTENT;  | 
|         }  | 
|   | 
|         public string GetContent(int mIndexId, string mItem)  | 
|         {  | 
|             string mResult = "";  | 
|   | 
|             Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];  | 
|   | 
|             foreach (KeyValuePair<int, CODELIST> pair in mTmp)  | 
|             {  | 
|                 if (pair.Value.ITEM.Equals(mItem))  | 
|                 {  | 
|                     mResult = pair.Value.CONTENT;  | 
|                     break;  | 
|                 }  | 
|             }  | 
|             return mResult;  | 
|         }  | 
|   | 
|         public int GetKeyId(int mIndexId, string mContent)  | 
|         {  | 
|             Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];  | 
|             int mResult = 0;  | 
|   | 
|             foreach (KeyValuePair<int, CODELIST> pair in mTmp)  | 
|             {  | 
|                 if (pair.Value.CONTENT.Equals(mContent))  | 
|                 {  | 
|                     mResult = pair.Key;  | 
|                     break;  | 
|                 }  | 
|             }  | 
|             return mResult;  | 
|         }  | 
|   | 
|         public string GetItem(int mIndexId, string mContent)  | 
|         {  | 
|             Dictionary<int, CODELIST> mTmp = _mTotalData[mIndexId];  | 
|             string mResult = "";  | 
|   | 
|             foreach (KeyValuePair<int, CODELIST> pair in mTmp)  | 
|             {  | 
|                 if (pair.Value.CONTENT.Equals(mContent))  | 
|                 {  | 
|                     mResult = pair.Value.ITEM;  | 
|                     break;  | 
|                 }  | 
|             }  | 
|             return mResult;  | 
|         }  | 
|   | 
|         public int GetContentNumber(int mIndexId)  | 
|         {  | 
|             return _mTotalData[mIndexId].Count;  | 
|         }  | 
|   | 
|         public int Count => _mTotalData.Count;  | 
|     }  | 
| } |