Ejemplo n.º 1
0
        public IG_Table ExportTable(string branch)
        {
            // 각종 테이블정보 초기화
            InitiateInfo();

            int cnt = 0;

            Dictionary<string, string> define;
            Dictionary<string, string> dataType;
            Dictionary<string, Dictionary<string, string>> subgroups;

            IG_Table table = new IG_Table(GetTableName());

            if (table == null) throw new Exception("테이블명이 제대로 설정되지 않았습니다.");

            if (!BranchDefines.ContainsKey(branch)) throw new Exception("[" + branch + "] 브랜치 설정이 존재하지 않습니다.");

            define = BranchDefines[branch];
            ChangeBranch(branch);

            dataType = BranchDataTypes[branch];
            subgroups = GetSubgroups();

            // row 순서대로 브랜치를 체크하여 데이터로 출력
            foreach (Excel.Worksheet ws in Globals.IG_PlanAddIn.Application.Worksheets)
            {
                foreach (Excel.ListObject lo in ws.ListObjects)
                {
                    if (lo.Name.Length >= Properties.Settings.Default.TablePrefix.Length && lo.Name.Substring(0, Properties.Settings.Default.TablePrefix.Length).Equals(Properties.Settings.Default.TablePrefix))
                    {
                        // contentsID가 없는 테이블은 무사통과
                        bool hasContentsID = false;

                        // 컨텐츠ID 체크
                        for (int i = 1; i <= lo.ListColumns.Count; i++)
                            if (lo.ListColumns.get_Item(i).Name.ToUpper().Equals("contentsID".ToUpper()))
                            {
                                hasContentsID = true;
                                break;
                            }

                        // 필드가 define에 존재하는지 체크
                        // Alias 필드인지 확인
                        Dictionary<string, int> indexMatch = new Dictionary<string, int>();

                        foreach (string k in BranchDefines[branch].Keys)
                        {
                            try
                            {
                                if (BranchAliases[branch][k] == null) indexMatch.Add(k, lo.ListColumns[k].Index);
                                else indexMatch.Add(k, lo.ListColumns[BranchAliases[branch][k]].Index);
                            }
                            catch
                            {
                                indexMatch.Add(k, 0);
                            }
                        }

                        // 유일키 인덱스 구하기
                        int keyIndex = lo.ListColumns[BranchDefines[branch].First().Key].Index;

                        for (int r = 1; r <= lo.ListRows.Count; r++)
                        {
                            // tableinfo에서 설정된 contents만 출력
                            if (hasContentsID == false || IsValidContentsId(lo.DataBodyRange[r, lo.ListColumns["contentsID"].Index].value2))
                            {
                                cnt++;
                                int id = Convert.ToInt32(lo.DataBodyRange[r, keyIndex].value2);
                                if (id > 0)
                                {
                                    if (table.ContainsKey(id))
                                        throw new Exception(String.Format("인덱스 중복오류: {0}", id));

                                    table.StartAdd(id);

                                    foreach (string k in BranchDefines[branch].Keys)
                                    {
                                        object tmp = lo.DataBodyRange[r, indexMatch[k]].value2;

                                        // 데이터 타입 검증 후, 출력
                                        try
                                        {
                                            // 필드정의에 존재하나 실데이터가 없는 경우, 기본값 출력
                                            if (indexMatch[k] > 0 && tmp != null && dataType[k] != null)
                                                table.AddElement(k, ToXmlString(GetValidateData(Convert.ToString(tmp), dataType[k], subgroups)), dataType[k], subgroups);
                                            else
                                                table.AddElement(k, ToXmlString(GetValidateData(Convert.ToString(BranchDefines[branch][k]), dataType[k], subgroups)), dataType[k], subgroups);
                                        }
                                        catch(Exception e)
                                        {
                                            System.Windows.Forms.Clipboard.Clear();
                                            System.Windows.Forms.Clipboard.SetText(Convert.ToString(id));
                                            if (dataType[k] != null)
                                                throw new Exception(String.Format("[{0} 데이터타입 오류]\n인덱스: {1}\n필드명: {2}", e.Message, id, k));
                                            else
                                                throw new Exception(String.Format("[데이터타입 미설정 오류]\n필드명: {0}", k));
                                        }
                                    }
                                    table.EndAdd();
                                }
                            }
                        }
                    }
                }
            }
            if (cnt <= 0) throw new Exception("테이블명이 정확하지 않습니다.");

            return table;
        }
Ejemplo n.º 2
0
 internal void WriteTable(string[] fileNames, IG_Table[] tables)
 {
     for (int i = 0; i < fileNames.Length; i++)
         WriteTable(fileNames[i], tables[i]);
 }
Ejemplo n.º 3
0
        internal void WriteMetaTableType(string branch)
        {
            StringBuilder sb = new StringBuilder();
            string filePath = null;

            // 각종 테이블정보 초기화
            InitiateInfo();

            IG_Table table = new IG_Table(GetTableName());
            if (table == null) throw new Exception("테이블명이 제대로 설정되지 않았습니다.");

            Dictionary<string, string> define;
            Dictionary<string, string> dataType;
            Dictionary<string, Dictionary<string, string>> subgroups;

            if (!BranchDefines.ContainsKey(branch)) throw new Exception("[" + branch + "] 브랜치 설정이 존재하지 않습니다.");

            define = BranchDefines[branch];
            dataType = BranchDataTypes[branch];
            subgroups = GetSubgroups();

            // Subgroup마다 파일 생성
            foreach (string field in subgroups.Keys)
            {
                string type = Properties.Settings.Default.MetaTableSubgroup_Prefix + field;

                // 생성자에서 초기값 설정
                var defaultValue = subgroups[field].Keys.FirstOrDefault();

                sb.Append(MetaTable.MetaTypeContent[0]);
                sb.AppendLine();

                sb.Append(
            @"	public	class	" + type + @" : " + Path.GetFileNameWithoutExtension(MetaTable.MetaAbKVTypeName) + @"<int, string, " + type + @">
            {
            public " + type + @"() { " + @"var obj = " + type + @"." + defaultValue + @"; }" + @"
            protected " + type + @"(string fieldName, int k, string v)
            : base(fieldName, k, v) {	typeName = """";}"); // 일단 typeName은 빈칸: 입력받는 곳이 없음
                sb.AppendLine();

                foreach (string k in subgroups[field].Keys)
                {
                    string[] typeValue = subgroups[field][k].Split(Properties.Settings.Default.SubgroupSeperator);
                    sb.Append(
            @"		public static " + type + @" " + k + @" = new " + type + @"(""" + k + @""", " + typeValue[0] + @", """ + typeValue[1] + @""");");
                    sb.AppendLine();
                }

                sb.Append(
            @"		public static " + type + @" Get" + Properties.Settings.Default.MetaTableSubgroup_Prefix + @"Type(int key)
            {
            " + type + @" result = null;");
                sb.AppendLine();

                sb.Append(MetaTable.MetaTypeContent[1]);
                sb.AppendLine();

                filePath = Path.GetFullPath(Properties.Settings.Default.MetaTablePath + Path.DirectorySeparatorChar + type + MetaTable.MetaTableName);
                File.WriteAllText(filePath, sb.ToString(), Encoding.UTF8);
                SVNDiff(filePath);

                sb.Clear();
            }
        }
Ejemplo n.º 4
0
 internal void WriteTable(string fileName, IG_Table table)
 {
     if (fileName != "")
     {
         File.WriteAllText(fileName, table.ToString(), Encoding.UTF8);
     }
     else
     {
         throw new Exception("파일명 - " + fileName + " - 이 정확하지 않습니다.");
     }
 }
Ejemplo n.º 5
0
        internal void WriteMetaTableTable(string branch)
        {
            StringBuilder sb = new StringBuilder();
            string filePath = null;

            // 각종 테이블정보 초기화
            InitiateInfo();

            IG_Table table = new IG_Table(GetTableName());
            if (table == null) throw new Exception("테이블명이 제대로 설정되지 않았습니다.");

            Dictionary<string, string> define;
            Dictionary<string, string> dataType;
            Dictionary<string, string> description;
            //Dictionary<string, List<string>> subgroups;

            if (!BranchDefines.ContainsKey(branch)) throw new Exception("[" + branch + "] 브랜치 설정이 존재하지 않습니다.");

            define = BranchDefines[branch];
            dataType = BranchDataTypes[branch];
            description = BranchDataDescriptions[branch];
            //subgroups = GetSubgroups();

            sb.Append(MetaTable.MetaTableContent[0]);

            sb.Append(
            @"	public	class	" + Properties.Settings.Default.MetaTable_Prefix + table.Name + @" : " + Properties.Settings.Default.MetaTable_Prefix + @"Object {
            public	" + Properties.Settings.Default.MetaTable_Prefix + table.Name + @"() {}");
            sb.AppendLine();

            foreach (string k in dataType.Keys)
            {
                sb.Append(@"		public ");
                switch(dataType[k].ToUpper())
                {
                    case "INTEGER":
                    case "BOOL":    // 논리값은 1 or 0으로 출력
                    case "FLOAT":   // 실수값은 천분율 정수값으로 출력
                        sb.Append("int " + k);
                        break;
                    case "TEXT":
                        sb.Append("string " + k);
                        break;
                    default:
                        // SUBGROUP이 존재할 때
                        if (dataType.ContainsKey(k))
                            //sb.Append(Properties.Settings.Default.MetaTableSubgroup_Prefix + dataType[k].ToUpper() + " " + k);
                            sb.Append("int " + k);
                        else
                            throw new Exception(String.Format("[{0} -> {1}]", k, dataType[k]));
                        break;
                }
                sb.Append(@"{ get; set; }");

                if (!string.IsNullOrEmpty(description[k]))
                    sb.Append("\t" + @"// " + description[k]);

                sb.AppendLine();
            }
            sb.Append(MetaTable.MetaTableContent[1]);
            sb.AppendLine();

            // GetStatByType 메소드가 필요한 테이블일 경우, 메소드 추가
            if (MetaTable.AdditionalMethods.Contains(table.Name))
            {
                sb.Append(MetaTable.MetaTableContent[2]);
                sb.AppendLine();
            }

            sb.Append(
            @"		public void Map(Dictionary<string, object> dic)
            {
            ");
            foreach(string k in dataType.Keys)
            {
                sb.Append(@"			");
                switch (dataType[k].ToUpper())
                {
                    case "INTEGER":
                    case "BOOL":    // 논리값은 1 or 0으로 출력
                    case "FLOAT":   // 실수값은 천분율 정수값으로 출력
                        sb.Append(k + @" = (int)(long)dic[""" + k + @"""];");
                        break;
                    case "TEXT":
                        sb.Append(k + @" = (string)dic[""" + k + @"""];");
                        break;
                    default:
                        // SUBGROUP이 존재할 때
                        if (dataType.ContainsKey(k))
                            sb.Append(k + @" = (int)(long)dic[""" + k + @"""];");
                        else
                            throw new Exception(String.Format("[{0} -> {1}]", k, dataType[k]));
                        break;
                }
                sb.AppendLine();
            }

            sb.Append(@"		}");
            sb.AppendLine();
            sb.Append(MetaTable.MetaTableContent[3]);

            filePath = Path.GetFullPath(Properties.Settings.Default.MetaTablePath + Path.DirectorySeparatorChar + Properties.Settings.Default.MetaTable_Prefix + table.Name + MetaTable.MetaTableName);
            File.WriteAllText(filePath, sb.ToString(), Encoding.UTF8);

            SVNDiff(filePath);
        }