Exemplo n.º 1
0
        private DataSet CreateDataset(Dictionary <string, object> reader, Dictionary <string, object> globalTypes)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            ReadSchema(reader, ds, globalTypes);

            foreach (KeyValuePair <string, object> pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                List <object> rows = (List <object>)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 2
0
Arquivo: Json.cs Projeto: i-e-b/ADSD
        DataSet CreateDataset(IDictionary <string, object> reader, IDictionary <string, object> globalTypes)
        {
            var ds = new DataSet {
                EnforceConstraints = false
            };

            ds.BeginInit();

            // read dataset schema here
            ReadSchema(reader, ds, globalTypes);

            foreach (var pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                var rows = (ArrayList)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                var dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 3
0
        public ReportOwnersViewModel()
        {
            // загружает нативные библиотеки из папки SqlServerType (для отчетов, но работает и без данных библиотек)
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            dataAccess             = new DataAccess();
            WindowsFormsHost       = new WindowsFormsHost();
            reportViewer           = new ReportViewer();
            WindowsFormsHost.Child = reportViewer;

            ReportDataSource reportDataSource = new ReportDataSource();
            DataSet          dataset          = new DataSet();

            dataset.BeginInit();

            reportDataSource.Name  = "Owners"; // имя датасета отчета в .RDLC файле
            reportDataSource.Value = dataset.OWNERS;
            reportViewer.LocalReport.DataSources.Add(reportDataSource);
            reportViewer.LocalReport.ReportEmbeddedResource = "SNT.Reports.Owners.ReportOwners.rdlc";

            dataset.EndInit();

            // заполнение данных адаптером
            DataSetTableAdapters.OWNERSTableAdapter ownersTableAdapter = new DataSetTableAdapters.OWNERSTableAdapter();
            // замена строки подключения на строку из dataAccess
            ownersTableAdapter.Connection.ConnectionString = dataAccess.connectionString;
            ownersTableAdapter.ClearBeforeFill             = true;
            ownersTableAdapter.Fill(dataset.OWNERS);

            reportViewer.RefreshReport();
        }
Exemplo n.º 4
0
        public int DSRestore(bool bOnlyClear, string sDS)
        {
            int nRet = AppC.RC_OK;

            try
            {
                dsM.BeginInit();
                dsM.EnforceConstraints = false;
                dsM.Clear();
                if (bOnlyClear != true)
                {
                    dsM.ReadXml(sDS);
                    try
                    {
                        //dsM.Tables.Remove(DT[NSI.I_TZVK].dt.TableName);
                    }
                    catch
                    {// ну, значит, не было
                    }
                }

                dsM.EnforceConstraints = true;
                dsM.EndInit();
            }
            catch
            {
                nRet = AppC.RC_NOFILE;
            }

            return(nRet);
        }
Exemplo n.º 5
0
        public void Creation4()
        {
            DataRelation Relation = new DataRelation("Rel", "Mom", "Child",
                                                     new string[] { "ChildName" },
                                                     new string[] { "Name" }, true);

            Assert.Throws <NullReferenceException>(() => _set.Relations.Add(Relation));
            Assert.Throws <NullReferenceException>(() => _set.Relations.AddRange(new DataRelation[] { Relation }));

            _set.BeginInit();
            _set.Relations.AddRange(new DataRelation[] { Relation });
            _set.EndInit();

            DataRelation Test = null;

            Assert.Equal(1, _mom.ChildRelations.Count);
            Assert.Equal(0, _child.ChildRelations.Count);
            Assert.Equal(0, _mom.ParentRelations.Count);
            Assert.Equal(1, _child.ParentRelations.Count);

            Test = _child.ParentRelations[0];
            Assert.Equal("Rel", Test.ToString());
            Assert.Equal("Rel", Test.RelationName);
            Assert.Equal("Mom", Test.ParentTable.TableName);

            Assert.Null(Test.ParentKeyConstraint);

            Assert.Equal(1, Test.ParentColumns.Length);
            Assert.True(Test.Nested);
            Assert.Equal(0, Test.ExtendedProperties.Count);
            Assert.Equal("Child", Test.ChildTable.TableName);
            Assert.Null(Test.ChildKeyConstraint);
            Assert.Equal(1, Test.ChildColumns.Length);
        }
Exemplo n.º 6
0
        private DataSet CreateDataset(Dictionary <string, object> reader, Dictionary <string, object> globalTypes)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader["$schema"];

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)ParseDictionary((Dictionary <string, object>)schema, globalTypes, typeof(DatasetSchema), null);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    // blacklist checking
                    var t = //Type.GetType(ms.Info[i + 2]);
                            Reflection.Instance.GetTypeFromCache(ms.Info[i + 2], true);
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], t);
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                List <object> rows = (List <object>)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 7
0
        public void Creation4()
        {
            DataRelation Relation = new DataRelation("Rel", "Mom", "Child",
                                                     new string [] { "ChildName" },
                                                     new string [] { "Name" }, true);

            try
            {
                Set.Relations.Add(Relation);
                Fail("test#01");
            }
            catch (Exception e)
            {
                AssertEquals("test#02", typeof(NullReferenceException), e.GetType());
            }

            try
            {
                Set.Relations.AddRange(new DataRelation [] { Relation });
                Fail("test#03");
            }
            catch (Exception e)
            {
                AssertEquals("test#04", typeof(NullReferenceException), e.GetType());
            }

            Set.BeginInit();
            Set.Relations.AddRange(new DataRelation [] { Relation });
            Set.EndInit();

            DataRelation Test = null;

            AssertEquals("test#01", 1, Mom.ChildRelations.Count);
            AssertEquals("test#02", 0, Child.ChildRelations.Count);
            AssertEquals("test#03", 0, Mom.ParentRelations.Count);
            AssertEquals("test#04", 1, Child.ParentRelations.Count);

            Test = Child.ParentRelations [0];
            AssertEquals("test#05", "Rel", Test.ToString());
            AssertEquals("test#06", "Rel", Test.RelationName);
            AssertEquals("test#07", "Mom", Test.ParentTable.TableName);

            AssertEquals("test#08", true, Test.ParentKeyConstraint == null);

            AssertEquals("test#10", 1, Test.ParentColumns.Length);
            AssertEquals("test#11", true, Test.Nested);
            AssertEquals("test#12", 0, Test.ExtendedProperties.Count);
            AssertEquals("test#13", "Child", Test.ChildTable.TableName);
            AssertEquals("test#14", true, Test.ChildKeyConstraint == null);
            AssertEquals("test#15", 1, Test.ChildColumns.Length);
        }
Exemplo n.º 8
0
        // introduces a special table '__timenow__' with a datetimne column NOT NULL and one row with initial value
        public static DataSet Register(DataSet ds)
        {
            ds.BeginInit();
            InitDataSetClass(ds);

            // PostDeploy
            DateTime db_utc_now = new DateTime(2001, 2, 3, 4, 5, 6, 789, DateTimeKind.Utc);
            var      table      = GetTable <TimeNowDataTable>(ds, TimeNowDataTable.TimeNowTableName);

            table.Rows.Add(1, db_utc_now);

            ds.EndInit();
            return(ds);
        }
Exemplo n.º 9
0
        DataSet CreateDataSet(JsonDict reader)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader.Schema;

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)CreateObject((JsonDict)schema, _manager.GetReflectionCache(typeof(DatasetSchema)), null);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], Type.GetType(ms.Info[i + 2]));
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                //if (pair.Key == "$type" || pair.Key == "$schema") continue;

                JsonArray rows = (JsonArray)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                ReadDataTable(rows, dt);
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 10
0
        public void Creation4()
        {
            DataRelation Relation = new DataRelation("Rel", "Mom", "Child",
                                                     new string [] { "ChildName" },
                                                     new string [] { "Name" }, true);

            try {
                Set.Relations.Add(Relation);
                Assert.Fail("test#01");
            } catch (Exception e) {
                Assert.That(e, Is.TypeOf(typeof(NullReferenceException)), "test#02");
            }

            try {
                Set.Relations.AddRange(new DataRelation [] { Relation });
                Assert.Fail("test#03");
            } catch (Exception e) {
                Assert.That(e, Is.TypeOf(typeof(NullReferenceException)), "test#04");
            }

            Set.BeginInit();
            Set.Relations.AddRange(new DataRelation [] { Relation });
            Set.EndInit();

            DataRelation Test = null;

            Assert.That(Mom.ChildRelations.Count, Is.EqualTo(1), "test#01");
            Assert.That(Child.ChildRelations.Count, Is.EqualTo(0), "test#02");
            Assert.That(Mom.ParentRelations.Count, Is.EqualTo(0), "test#03");
            Assert.That(Child.ParentRelations.Count, Is.EqualTo(1), "test#04");

            Test = Child.ParentRelations [0];
            Assert.That(Test.ToString(), Is.EqualTo("Rel"), "test#05");
            Assert.That(Test.RelationName, Is.EqualTo("Rel"), "test#06");
            Assert.That(Test.ParentTable.TableName, Is.EqualTo("Mom"), "test#07");

            Assert.That(Test.ParentKeyConstraint, Is.Null, "test#08");

            Assert.That(Test.ParentColumns.Length, Is.EqualTo(1), "test#10");
            Assert.That(Test.Nested, Is.True, "test#11");
            Assert.That(Test.ExtendedProperties.Count, Is.EqualTo(0), "test#12");
            Assert.That(Test.ChildTable.TableName, Is.EqualTo("Child"), "test#13");
            Assert.That(Test.ChildKeyConstraint, Is.Null, "test#14");
            Assert.That(Test.ChildColumns.Length, Is.EqualTo(1), "test#15");
        }
Exemplo n.º 11
0
        public Warehouse(SqlConnection connection)
        {
            sqlConnection = connection;
            warehouse     = new DataSet("Warehouse");
            warehouse.BeginInit();
            var          articles  = CreateArticles();
            var          customers = CreateCustomers();
            var          documents = CreateDocuments();
            DataRelation relation  = new DataRelation("articles_documents",
                                                      articles.Columns["articleId"],
                                                      documents.Columns["articleId"]);

            warehouse.Relations.Add(relation);
            relation = new DataRelation("customers_documents",
                                        customers.Columns["customerId"],
                                        documents.Columns["customerId"]);
            warehouse.Relations.Add(relation);
            warehouse.EndInit();
            CreateAdapters();
        }
Exemplo n.º 12
0
        internal static DataSet ExecuteSelect(EDtxReaderType connType, int timeout, IDbConnection conn, string cmdText, ParamHelper[] paramList, ref TimeSpan executionTime)
        {
            DateTime       started         = DateTime.Now;
            IDataReader    reader          = null;
            IDbCommand     cmd             = null;
            bool           bConnOpenedHere = EnsureConnectionOpen(conn);
            IDbTransaction transaction     = conn.BeginTransaction();
            DataSet        retv            = new DataSet();

            try
            {
                cmd = conn.CreateCommand();
                cmd.CommandTimeout = timeout;
                cmd.Transaction    = transaction;
                cmd.CommandText    = cmdText;
                DbType[] reqLenTypes = new DbType[] { DbType.AnsiString, DbType.AnsiStringFixedLength, DbType.String, DbType.StringFixedLength, DbType.Binary, DbType.Object, DbType.Xml };
                for (int i = 0; i < paramList.Length; i++)
                {
                    IDbDataParameter idb = cmd.CreateParameter();
                    cmd.Parameters.Add(BuildParameter(idb, paramList[i]));
                    if (reqLenTypes.Contains(idb.DbType))
                    {
                        if (idb is OdbcParameter)
                        {
                            (idb as OdbcParameter).Size = paramList[i].Size;
                        }
                        else if (idb is CtreeSqlParameter)
                        {
                            (idb as CtreeSqlParameter).Size = paramList[i].Size;
                        }
                    }
                }
                switch (connType)
                {
                case EDtxReaderType.Adapter:
                case EDtxReaderType.FaircomAdapter:
                {
                    IDbDataAdapter adap = GetAdapter(connType, cmd);
                    retv.BeginInit();

                    //Since the FillSchema and Fill functions return the same instance of 'DataTable'
                    //There is probably a better way of doing this, but for sake of explination
                    //Read the db schema
                    bool        bSchemaFound = false;
                    DataTable[] dta          = adap.FillSchema(retv, SchemaType.Source);
                    DataTable   clone        = null;
                    if (dta.Length > 0)
                    {
                        bSchemaFound     = true;
                        dta[0].TableName = "SchemaTable";  //Ensure the table is named 'SchemaTable'
                        retv.Tables.Remove(dta[0]);        //Drop the table from the dataset
                        clone            = dta[0].Clone(); //Clone the results
                        dta[0].TableName = "Table";        //Rename the datatable instance back to table
                    }
                    adap.Fill(retv);                       //Fill 'Table' with the actual results
                    if (bSchemaFound && clone != null)
                    {
                        retv.Tables.Add(clone);         //Now add the 'schematable' back to the results
                    }
                    retv.EndInit();
                    break;
                }

                default:
                {
                    DataTable dt;
                    reader = cmd.ExecuteReader();
                    if (reader.FieldCount > 0)
                    {
                        retv.Tables.Add(dt = new DataTable("Table"));
                        retv.Tables.Add(reader.GetSchemaTable());
                        switch (connType)
                        {
                        case EDtxReaderType.FaircomReader:
                        case EDtxReaderType.Reader:
                        {
                            dt.Load(reader, LoadOption.OverwriteChanges);
                        }
                        break;

                        case EDtxReaderType.FaircomReaderSafe:
                        case EDtxReaderType.ReaderSafe:
                        default:
                        {
                            bool columnsBuilt = false;
                            while (reader.Read())
                            {
                                if (columnsBuilt == false)
                                {
                                    BuildColumnData(dt, reader);
                                    columnsBuilt = true;
                                }
                                AddDataRow(dt, reader);
                            }
                        }
                        break;
                        }
                    }
                    break;
                }
                }
                transaction.Commit();
                executionTime = DateTime.Now - started;
                //Now update parameter inputs with their respective values
                for (int i = 0; i < paramList.Length; i++)
                {
                    IDbDataParameter p = (IDbDataParameter)cmd.Parameters[i];
                    if (p.Direction != ParameterDirection.Input)
                    {
                        paramList[i].OutValue = p.Value;
                    }
                }
            }
            catch (Exception e)
            {
                transaction.Rollback();
                executionTime = DateTime.Now - started;
                HelperFunctions.LogException(e, false);
                throw e;
            }
            finally
            {
                if (reader != null)
                {
                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                    reader.Dispose();
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (bConnOpenedHere)
                {
                    conn.Close();
                }
            }

            return(retv);
        }
Exemplo n.º 13
0
        private DataSet CreateDataset(Dictionary <string, object> reader)
        {
            DataSet ds = new DataSet();

            ds.EnforceConstraints = false;
            ds.BeginInit();

            // read dataset schema here
            var schema = reader["$schema"];

            if (schema is string)
            {
                TextReader tr = new StringReader((string)schema);
                ds.ReadXmlSchema(tr);
            }
            else
            {
                DatasetSchema ms = (DatasetSchema)ParseDictionary((Dictionary <string, object>)schema);
                ds.DataSetName = ms.Name;
                for (int i = 0; i < ms.Info.Count; i += 3)
                {
                    if (ds.Tables.Contains(ms.Info[i]) == false)
                    {
                        ds.Tables.Add(ms.Info[i]);
                    }
                    ds.Tables[ms.Info[i]].Columns.Add(ms.Info[i + 1], Type.GetType(ms.Info[i + 2]));
                }
            }

            foreach (KeyValuePair <string, object> pair in reader)
            {
                if (pair.Key == "$type" || pair.Key == "$schema")
                {
                    continue;
                }

                ArrayList rows = (ArrayList)pair.Value;
                if (rows == null)
                {
                    continue;
                }

                DataTable dt = ds.Tables[pair.Key];
                dt.BeginInit();
                dt.BeginLoadData();
                List <int> guidcols = new List <int>();

                foreach (DataColumn c in dt.Columns)
                {
                    if (c.DataType == typeof(Guid) || c.DataType == typeof(Guid?))
                    {
                        guidcols.Add(c.Ordinal);
                    }
                }

                foreach (ArrayList row in rows)
                {
                    object[] v = new object[row.Count];
                    row.CopyTo(v, 0);
                    foreach (int i in guidcols)
                    {
                        string s = (string)v[i];
                        if (s != null && s.Length < 36)
                        {
                            v[i] = new Guid(Convert.FromBase64String(s));
                        }
                    }
                    dt.Rows.Add(v);
                }

                dt.EndLoadData();
                dt.EndInit();
            }

            ds.EndInit();

            return(ds);
        }
Exemplo n.º 14
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            try
            {
                evaDataSet.BeginInit();
                evaDataSet.EnforceConstraints = true;
                evaDataSet.ReadXml("EventAction.xml", XmlReadMode.IgnoreSchema);
                evaDataSet.EndInit();
            }
            catch
            {
                updateApplicationStatus(ApplicationState.Alert, @"Unable to read EventAction XML database.");
            }

            try
            {
                configDataSet = new DataSet();
                configDataSet.BeginInit();
                configDataSet.ReadXml("Configuration.xml");
                configDataSet.EndInit();
            }
            catch
            {
                updateApplicationStatus(ApplicationState.Alert, @"Unable to read Configuration XML database.");
            }

            try
            {
                DataTable dataTable   = configDataSet.Tables["GamepadController"];
                DataRow   dataRow     = dataTable.Rows[0];
                int       playerIndex = Convert.ToInt32(dataRow["player"]);
                gamepadController = new PG3B.Interface.GamepadController(playerIndex);
            }
            catch
            {
                updateApplicationStatus(ApplicationState.Warning, @"Unable to initialize GamePad.");
            }

            try
            {
                DataTable dataTable = configDataSet.Tables["XBoxController"];
                DataRow   dataRow   = dataTable.Rows[0];
                string    portName  = Convert.ToString(dataRow["port"]);
                xboxController = new PG3B.Interface.XBoxController(portName);
                switch (Convert.ToString(dataRow["model"]))
                {
                case "WiredCommonLine":
                    xboxController.IsWireless = false;
                    break;

                case "WirelessCommonGround":
                    xboxController.IsWireless = true;
                    break;
                }
            }
            catch
            {
                updateApplicationStatus(ApplicationState.Alert, @"Unable to initialize PG3B using Config.xml file.");
            }

            UpdateControllerStatus();
            InitializeSubForms();
        }
Exemplo n.º 15
0
        public void BeginInitTest()
        {
            DataSet ds = new DataSet();

            DataTable table1 = new DataTable("table1");
            DataTable table2 = new DataTable("table2");

            DataColumn col1 = new DataColumn("col1", typeof(int));
            DataColumn col2 = new DataColumn("col2", typeof(int));
            table1.Columns.Add(col1);
            table2.Columns.Add(col2);

            UniqueConstraint pkey = new UniqueConstraint("pk", new string[] { "col1" }, true);
            ForeignKeyConstraint fkey = new ForeignKeyConstraint("fk", "table1", new string[] { "col1" },
                                new string[] { "col2" }, AcceptRejectRule.Cascade,
                                Rule.Cascade, Rule.Cascade);
            DataRelation relation = new DataRelation("rel", "table1", "table2", new string[] { "col1" },
                                 new string[] { "col2" }, false);
            ds.BeginInit();
            table1.BeginInit();
            table2.BeginInit();

            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            ds.Relations.AddRange(new DataRelation[] { relation });

            table1.Constraints.AddRange(new Constraint[] { pkey });
            table2.Constraints.AddRange(new Constraint[] { fkey });

            // The tables/relations shud not get added to the DataSet yet
            Assert.Equal(0, ds.Tables.Count);
            Assert.Equal(0, ds.Relations.Count);
            Assert.Equal(0, table1.Constraints.Count);
            Assert.Equal(0, table2.Constraints.Count);
            ds.EndInit();

            Assert.Equal(2, ds.Tables.Count);
            Assert.Equal(1, ds.Relations.Count);
            Assert.Equal(1, ds.Tables[0].Constraints.Count);
            Assert.Equal(1, ds.Tables[1].Constraints.Count);

            // Table shud still be in BeginInit .. 
            DataColumn col3 = new DataColumn("col2");
            UniqueConstraint uc = new UniqueConstraint("uc", new string[] { "col2" }, false);

            table1.Columns.AddRange(new DataColumn[] { col3 });
            table1.Constraints.AddRange(new Constraint[] { uc });

            Assert.Equal(1, table1.Columns.Count);
            Assert.Equal(1, table1.Constraints.Count);

            table1.EndInit();
            Assert.Equal(2, table1.Columns.Count);
            Assert.Equal(2, table1.Columns.Count);
        }