Esempio n. 1
0
        private void CreateObjects()
        {
            long i = 1;

            _data.Each(r =>
            {
                if (i > Sheet.DataRowStart - 1)
                {
                    if (r.ItemArray[0] is DBNull)
                    {
                        return;
                    }

                    T temp = new T();

                    _properties.Each(p =>
                    {
                        ISheetColumn col = Sheet.SheetColumns.FirstOrDefault(sc => sc.TableMap == p.Name);

                        if (col != null && col.Import == true && col.ObjSkip == false)
                        {
                            object val = r.Field <object>(col.Name);
                            if (val is DBNull || val == null)
                            {
                                if (p.PropertyType.IsNumeric())
                                {
                                    val = 0;
                                }
                                else
                                {
                                    val = string.Empty;
                                }
                            }
                            p.SetValue(temp, Convert.ChangeType(val, p.PropertyType));
                        }
                    });
                    if (typeof(IImportable).IsAssignableFrom(typeof(T)))
                    {
                        (temp as IImportable).import_id = _import.ImportID;
                    }
                    _objectCollection.Add(temp);
                }
                i++;
            });
        }
Esempio n. 2
0
        private void FillValues(ref OleDbCommand cmd, T obj)
        {
            foreach (PropertyInfo p in _properties)
            {
                ISheetColumn col = Sheet.SheetColumns.FirstOrDefault(sc => sc.TableMap == p.Name);
                if (col != null && col.Import == true)
                {
                    object val = p.GetValue(obj);
                    if (val is DBNull)
                    {
                        if (p.PropertyType.IsNumeric())
                        {
                            val = 0;
                        }
                        else
                        {
                            val = string.Empty;
                        }
                    }

                    cmd.Parameters.AddWithValue("@" + col.TableMap, val);
                }
            }
        }