예제 #1
0
 public static void test124()
 {
     using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
     {
         IRelationAccesser r  = scope.NewRelationAccesser();
         DataTable         tb = r.DoQuery("select * from storages order by Address").Tables[0];
         // ========================
         System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
         int j = 0;
         for (int i = 0; i < 1000; i++)
         {
             foreach (DataRow row0 in tb.Rows)
             {
                 DataRow[] rows = tb.Select(string.Format("Address = '{0}'", row0["Address"]));
                 foreach (DataRow row in rows)
                 {
                     j++;
                 }
             }
         }
         System.Console.WriteLine(j.ToString());
         System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
         // =========================
         scope.Commit();
     }
 }
예제 #2
0
        public SqliteChatRecordPersister(string sqlitePath)
        {
            try
            {
                bool isNew = !File.Exists(sqlitePath);
                //2014.11.27
                string dirName = Path.GetDirectoryName(sqlitePath);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }


                //初始化Sqlite数据库
                DataConfiguration       config = new SqliteDataConfiguration(sqlitePath);
                TransactionScopeFactory transactionScopeFactory = new TransactionScopeFactory(config);
                transactionScopeFactory.Initialize();

                if (isNew)
                {
                    string sql = "CREATE TABLE ChatMessageRecord (AutoID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, SpeakerID VARCHAR( 0, 20 ) NOT NULL, AudienceID VARCHAR( 0, 20 ) NOT NULL, IsGroupChat BOOLEAN NOT NULL,IsNotice BOOLEAN NOT NULL, Content BLOB NOT NULL, OccureTime DATETIME NOT NULL ); "
                                 + "CREATE INDEX idx_ChatMessageRecord ON ChatMessageRecord ( SpeakerID, AudienceID, OccureTime DESC );"
                                 + "CREATE INDEX idx2_ChatMessageRecord ON ChatMessageRecord ( AudienceID, IsGroupChat, OccureTime );";
                    using (TransactionScope scope = transactionScopeFactory.NewTransactionScope())
                    {
                        IRelationAccesser accesser = scope.NewRelationAccesser();
                        accesser.DoCommand(sql);
                        scope.Commit();
                    }
                }

                base.Initialize(transactionScopeFactory);
            }
            catch { }
        }
예제 #3
0
        public static void test123()
        {
            using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
            {
                IRelationAccesser r  = scope.NewRelationAccesser();
                DataTable         tb = r.DoQuery("select * from storages order by Address").Tables[0];

                // =================================
                System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
                ELDB2.HashSelectHandle h = new ELDB2.HashSelectHandle(tb);
                int j = 0;
                for (int k = 0; k < 1000; k++)
                {
                    foreach (DataRow row in tb.Rows)
                    {
                        Hashtable t = h.Select <string>("Address", row.Field <string>("Address").Trim());

                        for (int i = 0; i < t.Count; i++)
                        {
                            j++;
                        }
                    }
                }
                System.Console.WriteLine(j.ToString());
                System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
                // =================================
                scope.Commit();
            }
        }
예제 #4
0
        public IList <TEntity> Select <TEntity>(string sql, bool isUsedHash) where TEntity : new()
        {
            List <TEntity> list = new List <TEntity>();

            using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
            {
                IRelationAccesser r     = scope.NewRelationAccesser();
                DataTable         table = r.DoQuery(sql).Tables[0];
                if (isUsedHash)
                {
                    AddToHash(table);
                }
                foreach (DataRow row  in table.Rows)
                {
                    TEntity entity = new TEntity();
                    foreach (DataColumn col in row.Table.Columns)
                    {
                        ((ELDB2.IHashEntity)entity).PropertySet[col.ColumnName] = row[col.ColumnName];
                    }

                    list.Add(entity);
                }

                scope.Commit();
            }
            return(list);
        }
예제 #5
0
 public void ExecuteNonQuery(string sql)
 {
     using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
     {
         IRelationAccesser r = scope.NewRelationAccesser();
         r.DoCommand(sql);
         scope.Commit();
     }
 }
예제 #6
0
 public HashOrmAccesser(TransactionScope Transcope)
 {
     if (Transcope == null)
     {
         throw new Exception("传入的TransactionScope为空");
     }
     _scope = Transcope;
     if (_accesser == null)
     {
         _accesser = _scope.NewRelationAccesser();
     }
 }
예제 #7
0
        public void Run0(bool isHash)
        {
            IList <ELDB2.Storages> list  = null;
            IList <ELDB2.Storages> list1 = null;

            using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
            {
                System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
                ELDB2.HashSelectHandle hashTable = null;
                Hashtable hashTable1             = null;

                IOrmAccesser <ELDB2.Storages> storages = ELDB2.DBFactory.NewOrmAccesser <ELDB2.Storages>(scope);
                Filter filter = new Filter(ELDB2.Storages._Sign, 0, ComparisonOperators.Equal);
                list1 = storages.GetMuch(filter);

                if (isHash)
                {
                    IRelationAccesser r  = scope.NewRelationAccesser();
                    DataTable         tb = r.DoQuery("select * from storages order by Address").Tables[0];
                    hashTable = new ELDB2.HashSelectHandle(tb);
                }
                else
                {
                    list = storages.GetAll();
                }


                for (int mm = 0; mm < 1; mm++)
                {
                    if (list1 != null)
                    {
                        foreach (ELDB2.Storages storage1 in list1)
                        {
                            if (isHash)
                            {
                                //hashTable1 = hashTable.Select(ELDB2.Storages._Address, storage1.Address);
                                list = hashTable.Select <ELDB2.Storages, string>(ELDB2.Storages._Address, storage1.Address);
                                IEnumerable <ELDB2.Storages> storages1 = from storage in list
                                                                         where storage.Address == storage1.Address
                                                                         orderby storage.Address
                                                                         select storage;
                                foreach (ELDB2.Storages item in storages1)
                                {
                                    item.Act = "10";
                                    hashTable.Update <ELDB2.Storages, string>(item);
                                }
                            }
                            else
                            {
                                IEnumerable <String> Address = from storage in list
                                                               where storage.Address == storage1.Address
                                                               orderby storage.Address
                                                               select storage.Address;
                                foreach (string item in Address)
                                {
                                    System.Console.WriteLine(item);
                                }
                            }
                        }
                    }
                }
                System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
                // =========================
                scope.Commit();
            }
        }
예제 #8
0
        public void Run1()
        {
            IList <ELDB2.Storages> list = null;

            using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
            {
                IOrmAccesser <ELDB2.Storages> storages = ELDB2.DBFactory.NewOrmAccesser <ELDB2.Storages>(scope);
                Filter         filter   = new Filter(ELDB2.Storages._Sign, 1, ComparisonOperators.Equal);
                ELDB2.Storages storage1 = storages.GetOne(filter);
                if (storage1 != null)
                {
                    Filter filter1 = new Filter(ELDB2.Storages._Address, storage1.Address, ComparisonOperators.Equal);
                    list = storages.GetMuch(filter1);

                    string[] data = new string[5];
                    for (int i = 0; i < 5; i++)
                    {
                        data[i] = "";
                    }
                    foreach (ELDB2.Storages storage in list)
                    {
                        string s1, s2, s3, s4;
                        switch ("mode1")
                        {
                        case "mode1":
                            s1 = storage.StorageName.Trim() + " " + storage.Act.Trim() + " " + storage.Contents.Trim() + storage.ProductName.Trim() + "".PadRight(56, " "[0]);
                            s1 = StrHandle.GetStringWith(s1, 56);

                            if (storage.Row == "3")
                            {
                                data[0] = s1;
                            }
                            if (storage.Row == "2")
                            {
                                data[1] = s1;
                            }
                            if (storage.Row == "1")
                            {
                                data[2] = s1;
                            }
                            break;

                        case "mode2":
                            s1 = "储位:" + storage.StorageName.Trim();
                            s1 = StrHandle.GetStringWith(s1, 24);

                            s2 = "操作:" + storage.Act.Trim();
                            s2 = StrHandle.GetStringWith(s2, 24);

                            s3 = "品牌:" + storage.ProductName.Trim();
                            s3 = StrHandle.GetStringWith(s3, 24);

                            s4 = "数量:" + storage.Contents.Trim();
                            s4 = StrHandle.GetStringWith(s4, 20);

                            data[0] = s1;
                            data[0] = data[0] + s2;
                            data[0] = data[0] + s3;
                            data[0] = data[0] + s4;
                            break;

                        default:
                            break;
                        }
                        storage.Sign = 2;
                        storages.Update(storage);
                        IRelationAccesser ra = scope.NewRelationAccesser();

                        ra.DoCommand("Update [Sy_ShowInfo] set [HardwareReadState] = 1 where ReadState =1 and [StorageID] = '" + storage.StorageID + "'");
                    }
                    //this.elOpertor.SendData(int.Parse(storage1.Address.Substring(storage1.Address.Length - 2, 2)), data);
                }
                scope.Commit();
            }
        }
예제 #9
0
        public void Run(bool isHash)
        {
            IList <ELDB2.Storages> list  = null;
            IList <ELDB2.Storages> list1 = null;

            using (TransactionScope scope = ELDB2.DBFactory.NewTransactionScope(false))
            {
                System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
                ELDB2.HashSelectHandle hashTable = null;
                if (isHash)
                {
                    IRelationAccesser r  = scope.NewRelationAccesser();
                    DataTable         tb = r.DoQuery("select * from storages order by Address").Tables[0];
                    hashTable = new ELDB2.HashSelectHandle(tb);
                }


                for (int mm = 0; mm < 5; mm++)
                {
                    IOrmAccesser <ELDB2.Storages> storages = ELDB2.DBFactory.NewOrmAccesser <ELDB2.Storages>(scope);
                    Filter filter = new Filter(ELDB2.Storages._Sign, 0, ComparisonOperators.Equal);
                    list1 = storages.GetMuch(filter);
                    if (list1 != null)
                    {
                        foreach (ELDB2.Storages storage1 in list1)
                        {
                            if (isHash)
                            {
                                list = hashTable.Select <ELDB2.Storages, string>(ELDB2.Storages._Address, storage1.Address);
                            }
                            else
                            {
                                Filter filter1 = new Filter(ELDB2.Storages._Address, storage1.Address, ComparisonOperators.Equal);
                                list = storages.GetMuch(filter1);
                            }

                            string[] data = new string[5];
                            for (int i = 0; i < 5; i++)
                            {
                                data[i] = "";
                            }
                            foreach (ELDB2.Storages storage in list)
                            {
                                string s1, s2, s3, s4;
                                switch ("mode1")
                                {
                                case "mode1":
                                    s1 = storage.StorageName.Trim() + " " + storage.Act.Trim() + " " + storage.Contents.Trim() + storage.ProductName.Trim() + "".PadRight(56, " "[0]);
                                    s1 = StrHandle.GetStringWith(s1, 56);

                                    if (storage.Row == "3")
                                    {
                                        data[0] = s1;
                                    }
                                    if (storage.Row == "2")
                                    {
                                        data[1] = s1;
                                    }
                                    if (storage.Row == "1")
                                    {
                                        data[2] = s1;
                                    }
                                    break;

                                case "mode2":
                                    s1 = "储位:" + storage.StorageName.Trim();
                                    s1 = StrHandle.GetStringWith(s1, 24);

                                    s2 = "操作:" + storage.Act.Trim();
                                    s2 = StrHandle.GetStringWith(s2, 24);

                                    s3 = "品牌:" + storage.ProductName.Trim();
                                    s3 = StrHandle.GetStringWith(s3, 24);

                                    s4 = "数量:" + storage.Contents.Trim();
                                    s4 = StrHandle.GetStringWith(s4, 20);

                                    data[0] = s1;
                                    data[0] = data[0] + s2;
                                    data[0] = data[0] + s3;
                                    data[0] = data[0] + s4;
                                    break;

                                default:
                                    break;
                                }
                                storage.Sign = 0;
                                //storages.Update(storage);
                                IRelationAccesser ra = scope.NewRelationAccesser();

                                //ra.DoCommand("Update [Sy_ShowInfo] set [HardwareReadState] = 1 where ReadState =1 and [StorageID] = '" + storage.StorageID + "'");
                            }
                            //this.elOpertor.SendData(int.Parse(storage1.Address.Substring(storage1.Address.Length - 2, 2)), data);
                        }
                    }
                }
                System.Console.WriteLine(System.DateTime.Now.Second + ":" + System.DateTime.Now.Millisecond);
                // =========================
                scope.Commit();
            }
        }
예제 #10
0
        public static IRelationAccesser NewRelationAccesser(TransactionScope scope)
        {
            IRelationAccesser accesser = scope.NewRelationAccesser();

            return(accesser);
        }
예제 #11
0
        public static IRelationAccesser NewRelationAccesser()
        {
            IRelationAccesser accesser = NewTransactionScope(false).NewRelationAccesser();

            return(accesser);
        }