示例#1
0
        public void AvrDataTableRejectChangesTest()
        {
            QueryTableHeaderModel model = GetQueryTableHeaderModel();

            var table = new AvrDataTable(model, 1024);

            table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount]));
            table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount]));
            Assert.AreEqual(2, table.Rows.Count);

            table.RejectChanges();
            Assert.AreEqual(0, table.Rows.Count);

            table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount]));
            table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount]));
            Assert.AreEqual(2, table.Rows.Count);
            table.AcceptChanges();
            table.RejectChanges();
            Assert.AreEqual(2, table.Rows.Count);

            table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount]));
            Assert.AreEqual(3, table.Rows.Count);
            table.RejectChanges();
            Assert.AreEqual(2, table.Rows.Count);

            table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount]));
            Assert.AreEqual(3, table.Rows.Count);
            table.AcceptChanges();
            table.RejectChanges();
            Assert.AreEqual(3, table.Rows.Count);
        }
示例#2
0
        public static DataTable DeserializeToTable(BaseTableDTO dto)
        {
            List <BaseColumnModel> deserializedHeader = DeserializeHeader(dto.Header);
            var result = new DataTable();

            result.BeginInit();
            result.TableName = dto.TableName;
            foreach (BaseColumnModel columnModel in deserializedHeader)
            {
                var column = new DataColumn(columnModel.Name, columnModel.FinalType)
                {
                    Caption = columnModel.Caption
                };
                result.Columns.Add(column);
            }
            result.EndInit();

            AvrDataTable avrTable = new AvrDataTable(result);

            result.BeginLoadData();
            Type[] types = deserializedHeader.Select(c => c.FinalType).ToArray();

            foreach (BaseTablePacketDTO packet in dto.BodyPackets)
            {
                DeserializeBodyPacket(packet, types, avrTable);
            }
            avrTable.AcceptChanges();

            foreach (AvrDataRowBase avrRow in avrTable.Rows)
            {
                object[] array = new object[avrRow.Count];
                for (int j = 0; j < avrRow.Count; j++)
                {
                    array[j] = avrRow[j];
                }
                result.Rows.Add(array);
            }

            result.AcceptChanges();
            result.EndLoadData();

            return(result);
        }
示例#3
0
        private static AvrPivotGridData GetTestData()
        {
            var table = new AvrDataTable();

            for (int i = 0; i < 10; i++)
            {
                var rowDTO = new AvrDataRowDTO(1, 2, 2);
                rowDTO.SetInt(0, i);
                rowDTO.SetInt(1, 2 * i);
                rowDTO.SetObject(2, "xx_" + i);
                rowDTO.SetObject(3, true);
                rowDTO.SetDateTime(4, new DateTime(2000, 1, i + 1));

                AvrDataRowEx row = table.NewRow(rowDTO);
                table.ThreadSafeAdd(row);
            }

            table.AcceptChanges();
            return(new AvrPivotGridData(table));
        }
示例#4
0
        public void DeserializeBodyTest()
        {
            List <BaseColumnModel>      columnModels;
            IList <QueryTablePacketDTO> bodyPackets = new List <QueryTablePacketDTO>();

            using (var manager = new DbManager(new SqlDataProvider(), Config.GetSetting("TestConnectionString")))
            {
                using (IDbCommand command = manager.Connection.CreateCommand())
                {
                    command.CommandText = @"select  * from dbo.AVR_HumanCaseReport";
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        columnModels = BinarySerializer.GetSchemaColumnModels(reader.GetSchemaTable());
                        BinarySerializer.SerializeHeader(columnModels, false);
                        QueryTablePacketDTO packet = BinarySerializer.SerializeBodyPacket(reader, columnModels, false, 10);
                        while (packet.RowCount != 0)
                        {
                            bodyPackets.Add(packet);
                            packet = BinarySerializer.SerializeBodyPacket(reader, columnModels, false, 10);
                        }
                    }
                }
            }
            Assert.AreEqual(4, bodyPackets.Count);
            Type[] types = columnModels.Select(c => c.FinalType).ToArray();

            AvrDataTable array = new AvrDataTable(new DataTable());

            for (int i = 0; i < 4; i++)
            {
                BinarySerializer.DeserializeBodyPacket(bodyPackets[i], types, array);
            }
            array.AcceptChanges();
            Assert.AreEqual(31, array.Count);
            Assert.AreEqual(54, array[0].Count);

            AvrDataRowEx row3 = (AvrDataRowEx)array[3];

            Assert.AreEqual(typeof(string), row3[53].GetType());
            Assert.AreEqual("2", row3[53].ToString());

            AvrDataRowEx row5 = (AvrDataRowEx)array[5];

            Assert.AreEqual(typeof(DateTime), row5[50].GetType());
            Assert.AreEqual(2010, ((DateTime)row5[50]).Year);

            AvrDataRowEx row8 = (AvrDataRowEx)array[8];

            Assert.AreEqual(typeof(decimal), row8[52].GetType());
            Assert.AreEqual(0m, row8[52]);

            AvrDataRowEx row = (AvrDataRowEx)array[30];

            Assert.AreEqual(new DateTime(1990, 02, 01), row[0]);
            Assert.AreEqual(23, row[1]);
            Assert.AreEqual(DBNull.Value, row[3]);
            Assert.AreEqual("xxx", row[4]);
            Assert.AreEqual("Male", row[6]);
            Assert.AreEqual(DBNull.Value, row[7]);
            Assert.AreEqual(DateTime.Now.Year, ((DateTime)row[50]).Year);
            Assert.AreEqual(DateTime.Now.Year, row[51]);
            Assert.AreEqual(25460000000m, row[52]);
            Assert.AreEqual("Yes", row[53]);
        }