public static SimpDataEntery DataTableToSimpDataEntery(DataTable covDt)
        {
            int i = 0, iCnt = covDt.Columns.Count, r = 0, rCnt = covDt.Rows.Count;
            var simpCols = new SimpDataColInf[iCnt];

            for (; i < iCnt; i++)
            {
                simpCols[i].name = covDt.Columns[i].ColumnName;
                simpCols[i].type = (DotNetType)Enum.Parse(typeof(DotNetType), covDt.Columns[i].DataType.Name);
            }

            var simpRows = new List <object[]>();

            for (; r < rCnt; r++)
            {
                var objs = covDt.Rows[r].ItemArray;
                ConvertObjects(ref objs);
                simpRows.Add(objs);
            }
            var simpDt = new SimpDataEntery {
                Cols = simpCols, Rows = simpRows, TVal = DateTime.Now.Ticks
            };

            return(simpDt);
        }
Esempio n. 2
0
        public List <SimpDataEntery> ExecuteSimpData(DbCommand cmd)
        {
            MyTransaction         _tran          = MyTransaction.BeginTransaction(cmd);
            List <SimpDataEntery> _simpDbEnterys = new List <SimpDataEntery>();

            SimpDataColInf[] _simpCols;
            List <object[]>  _simpRows;
            string           _fieldType = string.Empty;

            try
            {
                using (DbDataReader _reader = cmd.ExecuteReader())
                {
                    do
                    {
                        _simpCols = new SimpDataColInf[_reader.FieldCount];
                        for (int _i = 0, _iCnt = _reader.FieldCount; _i < _iCnt; _i++)
                        {
                            _simpCols[_i].name = _reader.GetName(_i);
                            _simpCols[_i].type = (DotNetType)Enum.Parse(typeof(DotNetType), _reader.GetFieldType(_i).Name);
                        }
                        _simpRows = new List <object[]>();
                        while (_reader.Read())
                        {
                            object[] _objs = new object[_reader.FieldCount];

                            for (int _i = 0, _iCnt = _reader.FieldCount; _i < _iCnt; _i++)
                            {
                                if ((_objs[_i] = _reader.GetValue(_i)).Equals(DBNull.Value))
                                {
                                    _objs[_i] = null;
                                }
                                if (_objs[_i] is DateTime)
                                {
                                    _objs[_i] = ((DateTime)_objs[_i]).ToString();
                                }
                                if (_objs[_i] is Boolean)
                                {
                                    _objs[_i] = _objs[_i].Equals(true) ? 1 : 0;
                                }
                            }
                            //_reader.GetValues(_objs);
                            _simpRows.Add(_objs);
                        }
                        _simpDbEnterys.Add(new SimpDataEntery()
                        {
                            Cols = _simpCols, Rows = _simpRows, TVal = System.DateTime.Now.Ticks
                        });
                    } while (_reader.NextResult());
                    _reader.Close();
                    _tran.Commit();
                }
            }
            catch (Exception e)
            {
                _tran.Rollback();
                _simpDbEnterys.Add(CreateErrorSimpDataEntery(e.ToString()));
            }
            return(_simpDbEnterys);
        }
        public static SimpDataEntery DataRowToSimpDataEntery(DataRow dr)
        {
            var dt = dr.Table;
            int i = 0, iCnt = dt.Columns.Count;
            var simpCols = new SimpDataColInf[iCnt];

            for (; i < iCnt; i++)
            {
                simpCols[i].name = dt.Columns[i].ColumnName;
                simpCols[i].type = (DotNetType)Enum.Parse(typeof(DotNetType), dt.Columns[i].DataType.Name);
            }

            var objs = dr.ItemArray;

            ConvertObjects(ref objs);
            var simpRows = new List <object[]> {
                objs
            };
            var simpDt = new SimpDataEntery {
                Cols = simpCols, Rows = simpRows, TVal = DateTime.Now.Ticks
            };

            return(simpDt);
        }