Esempio n. 1
0
        public List <InDateRow> GetData()
        {
            var sheets          = pack.Workbook.Worksheets;
            var dataSheet       = sheets.FirstOrDefault(s => s.Name == "Исх. данные");
            var numberOfRows    = dataSheet.Dimension.End.Row;
            var numberOfCols    = dataSheet.Dimension.End.Column;
            var Cells           = dataSheet.Cells;
            var _SampleTreeView = new List <InDateRow>();

            for (int rowIterator = 2; rowIterator <= numberOfRows; rowIterator++)
            {
                var e = new InDateRow()
                {
                    Program = Cells[rowIterator, 1].Value.ToString(),
                    Project = Cells[rowIterator, 2].Value.ToString(),
                    Budjet  = Cells[rowIterator, 3].Value.ToString(),
                    Stage   = Cells[rowIterator, 4].Value.ToString(),
                    System  = Cells[rowIterator, 5].Value.ToString(),
                    Element = Cells[rowIterator, 6].Value.ToString(),
                    ISR     = Convert.ToInt32(Cells[rowIterator, 7].Value),
                    PIR     = Cells[rowIterator, 8].Value.ToString(),
                    Mark    = Cells[rowIterator, 9].Value.ToString(),
                    CID     = Convert.ToInt32(Cells[rowIterator, 10].Value),
                };
                _SampleTreeView.Add(e);
            }
            return(_SampleTreeView);
        }
Esempio n. 2
0
        private static void AddLine(HashSet <NodeModel> nodes, InDateRow row)
        {
            var exportProps = typeof(InDateRow)
                              .GetProperties()
                              .Select(p => new
            {
                Prop = p,
                Attr = p.GetCustomAttribute <TreeViewAttribute>()
            })
                              .Where(x => x.Attr != null)
                              .OrderBy(x => x.Attr.Level)
                              .ToList();

            NodeModel parent = null;

            foreach (var prop in exportProps)
            {
                var node = new NodeModel()
                {
                    Level = prop.Attr.Level,
                    Name  = prop.Prop.GetValue(row).ToString(),
                    CID   = prop.Attr.Level == 9 ? row.CID : -2
                };

                if (parent == null)
                {
                    if (!nodes.Contains(node))
                    {
                        nodes.Add(node);
                        parent = node;
                    }
                    else
                    {
                        parent = nodes.FirstOrDefault(el => el.Equals(node));
                    }
                }
                else
                {
                    if (!parent.Children.Contains(node))
                    {
                        node.Parent = parent;
                        parent.Children.Add(node);
                        parent = node;
                    }
                    else
                    {
                        parent = parent.Children.FirstOrDefault(el => el.Equals(node));
                    }
                }
            }
        }