Example #1
0
        public static void ExportParameterList(List <FHXParameter> data, string file)
        {
            using (var pkg = new ExcelPackage())
            {
                var wbk = pkg.Workbook;
                var sht = wbk.Worksheets.Add("Parameters");

                sht.Cells[1, 1].Value = "Path";
                sht.Cells[1, 2].Value = "Area";
                sht.Cells[1, 3].Value = "Module";
                sht.Cells[1, 4].Value = "Parameter";
                sht.Cells[1, 5].Value = "Value";

                int i = 2;

                foreach (var param in data)
                {
                    string    area   = "";
                    string    tag    = "";
                    FHXObject module = param.Module;

                    if (module != null)
                    {
                        area = module.GetParameter("PLANT_AREA").Value;
                        tag  = module.GetParameter("TAG").Value;
                    }

                    sht.Cells[i, 1].Value = param.Path;
                    sht.Cells[i, 2].Value = area;
                    sht.Cells[i, 3].Value = tag;
                    sht.Cells[i, 4].Value = module == null ? param.Parent.Name + "." + param.Name : param.RelativePath(module);
                    sht.Cells[i, 5].Value = param.Value;
                    i++;
                }

                pkg.SaveAs(new FileInfo(file));
            }
        }
Example #2
0
        private static void ProcessFB(FHXObject fb, List <FHXObject> FUNCTION_BLOCK_DEFINITION)
        {
            FHXObject parent = fb.Parent;

            fb.Parent.RemoveChild(fb);
            fb.SetParent(null);

            if (FUNCTION_BLOCK_DEFINITION.Any(i => i.Name == fb.GetParameter("DEFINITION").Value))
            {
                foreach (FHXObject newChild in FUNCTION_BLOCK_DEFINITION.Where(i => i.Name == fb.GetParameter("DEFINITION").Value))
                {
                    newChild.mName = fb.Name;
                    newChild.Type  = "FUNCTION_BLOCK";
                    newChild.Parent.RemoveChild(newChild);
                    newChild.SetParent(null);
                    parent.AddChild(newChild);
                }
            }
        }
Example #3
0
        public static void ExportBulkEdit(List <FHXParameter> data, string file)
        {
            using (var pkg = new ExcelPackage())
            {
                var wbk = pkg.Workbook;
                var sht = wbk.Worksheets.Add("Parameters");

                List <string> headers = new List <string>();
                Dictionary <string, Dictionary <string, string> > table = new Dictionary <string, Dictionary <string, string> >();

                int i = 2;

                foreach (var param in data)
                {
                    string    area   = "";
                    string    tag    = "";
                    FHXObject module = param.Module;
                    if (module != null)
                    {
                        area = module.GetParameter("PLANT_AREA").Value;
                        tag  = module.GetParameter("TAG").Value;
                        string id = module == null ? param.Parent.Name + "." + param.Name : param.RelativePath(module);

                        if (!headers.Contains(id))
                        {
                            headers.Add(id);
                        }
                        if (!table.ContainsKey(tag))
                        {
                            table.Add(tag, new Dictionary <string, string>());
                        }

                        if (!table[tag].ContainsKey(id))
                        {
                            table[tag].Add(id, param.Value);
                        }
                        else
                        {
                            table[tag][id] = param.Value;
                        }
                    }
                }

                sht.Cells[1, 1].Value = "Module";

                for (int j = 0; j < headers.Count; j++)
                {
                    sht.Cells[1, j + 2].Value = headers[j];
                }

                foreach (string k in table.Keys) //For each modules
                {
                    sht.Cells[i, 1].Value = k;

                    for (int j = 0; j < headers.Count; j++)
                    {
                        int h = j + 2;
                        if (table[k].ContainsKey(headers[j]))
                        {
                            sht.Cells[i, h].Value = table[k][headers[j]];
                        }
                        else
                        {
                            sht.Cells[i, h].Value = "<NULL>";
                        }
                    }
                    i++;
                }
                pkg.SaveAs(new FileInfo(file));
            }
        }