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);
        }
Exemple #2
0
        public List <SimpDataEntery> ExecuteSimpData(DbCommand cmd)
        {
            var tran = MyTransaction.BeginTransaction(cmd);
            List <SimpDataEntery> simpDbEnterys = new List <SimpDataEntery>();
            string _fieldType = string.Empty;

            try
            {
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    do
                    {
                        var 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);
                        }
                        var 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(CultureInfo.InvariantCulture);
                                }
                                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);
        }