Пример #1
0
        private Row CreateRow(Row rowTemplate, uint index, MyRow item, List <Field> fields)
        {
            try
            {
                var newRow = (Row)rowTemplate.Clone();
                newRow.RowIndex = new UInt32Value(index);

                foreach (var cell in newRow.Elements <Cell>())
                {
                    cell.CellReference = new StringValue(cell.CellReference.Value.Replace(Regex.Replace(cell.CellReference.Value, @"[^\d]+", ""), index.ToString(CultureInfo.InvariantCulture)));
                    foreach (var fil in fields.Where(fil => cell.CellReference == fil.Column + index))
                    {
                        var hasdata = item.Columns.Where(x => x.Name == fil._Field).FirstOrDefault();
                        if (hasdata != null)
                        {
                            cell.CellValue = new CellValue(hasdata.Value == null ? "-" : hasdata.Value.ToString());
                            cell.DataType  = new EnumValue <CellValues>(CellValues.String);
                        }
                    }
                }
                return(newRow);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Has error {ex.ToString()}");
            }
            return(null);
        }
Пример #2
0
        public MyTable CreateMyDataTable <T>(IEnumerable <T> list)
        {
            Type    type       = typeof(T);
            var     properties = type.GetProperties();
            MyTable dataTable  = new MyTable();

            foreach (T entity in list)
            {
                MyRow    dataRow = new MyRow();
                object[] values  = new object[properties.Length];
                for (int i = 0; i < properties.Length; i++)
                {
                    string name     = properties[i].Name;
                    Type   typeCol  = Nullable.GetUnderlyingType(properties[i].PropertyType) ?? properties[i].PropertyType;
                    object valueCol = properties[i].GetValue(entity);

                    MyColumn dataColumn = new MyColumn(name, typeCol, valueCol);
                    dataRow.AddMyColumn(dataColumn);
                }
                dataTable.AddMyRow(dataRow);
            }
            return(dataTable);
        }
Пример #3
0
 public void AddMyRow(MyRow row)
 {
     this.Rows.Add(row);
 }