ulysseskao
2016-04-29 b0c18d369abd06075c83759b0e19823c2a11d716
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
 
using System.Collections;
using System.Collections.Generic;
using System.Data.OracleClient;
using System.Linq;
using CCSTrace.CCS.Domain;
 
namespace CCSTrace.CCS.Object
{
    public class EosCodelist
    {
        private readonly Dictionary<int, Dictionary<int, Codelist>> _mTotalData = new Dictionary<int, Dictionary<int, Codelist>>();
 
        public EosCodelist(OracleConnection connection)
        {
            var sqlStmt = "SELECT INDEXID,KEYID,ITEM,CONTENT FROM EOS.CODELIST ORDER BY INDEXID,KEYID";
            OracleCommand command = new OracleCommand(sqlStmt, connection);
            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)
            {
                Console.WriteLine("Error on Startup EOSCodelist: " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
            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 int GetContentNumber(int mIndexId)
        {
            return (_mTotalData[mIndexId]).Count;
        }
 
        public int Count => _mTotalData.Count;
    }
}