aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.CatalogImporter/Program.cs
blob: baf4e90f5521701180171585e62a2f4b22a6a711 (plain)
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
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core.Helpers;
using Tango.Documents;

namespace Tango.CatalogImporter
{
    class Program
    {
        private class CatalogItem
        {
            public int Code { get; set; }
            public int Red { get; set; }
            public int Green { get; set; }
            public int Blue { get; set; }
            public String S1 { get; set; }
            public String Group { get; set; }
            public float Cyan { get; set; }
            public float Magenta { get; set; }
            public float Yellow { get; set; }
            public float Black { get; set; }
            public float L { get; set; }
            public float A { get; set; }
            public float B { get; set; }
            public int GamutRegion { get; set; }
        }

        static void Main(string[] args)
        {
            ExcelReader reader = new ExcelReader(AssemblyHelper.GetCurrentAssemblyFolder() + "\\Catalog.xlsx");
            var items = reader.GetDataByIndex<CatalogItem>("400ColorsCat", 2);
            reader.Dispose();

            Console.Write("Please enter the catalog name: ");
            String catalog_name = Console.ReadLine();

            if (!String.IsNullOrWhiteSpace(catalog_name))
            {
                using (ObservablesContext db = ObservablesContext.CreateDefault(new Core.DataSource()
                {
                    Address = "localhost\\SQLEXPRESS",
                    Catalog = "Tango",
                    Type = Core.DataSourceType.SQLServer,
                    UserName = "Roy",
                    Password = "Aa123456",
                    IntegratedSecurity = true,
                }))
                {
                    ColorCatalog catalog = new ColorCatalog();
                    catalog.Name = catalog_name;

                    foreach (var group in items.GroupBy(x => x.Group))
                    {
                        int nameCounter = 1;

                        ColorCatalogsGroup g = new ColorCatalogsGroup();
                        g.Name = group.First().Group;
                        g.Description = g.Name;
                        catalog.ColorCatalogsGroups.Add(g);

                        foreach (var item in group)
                        {
                            var catalogItem = new ColorCatalogsItem();

                            catalogItem.Code = item.Code;

                            catalogItem.Red = item.Red;
                            catalogItem.Green = item.Green;
                            catalogItem.Blue = item.Blue;

                            catalogItem.Cyan = item.Cyan;
                            catalogItem.Magenta = item.Magenta;
                            catalogItem.Yellow = item.Yellow;
                            catalogItem.Black = item.Black;

                            catalogItem.L = item.L;
                            catalogItem.A = item.A;
                            catalogItem.B = item.B;

                            catalogItem.ProcessParametersTableIndex = item.GamutRegion;

                            catalogItem.Name = item.Group + nameCounter++;
                            catalogItem.Description = catalogItem.Name;

                            g.ColorCatalogsItems.Add(catalogItem);

                            Console.WriteLine($"Added catalog item {catalogItem.Name}...");
                        }
                    }

                    db.ColorCatalogs.Add(catalog);

                    db.SaveChanges();

                    Console.WriteLine("Done");
                    Console.ReadLine();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
    }
}