示例#1
0
        public DomainModel GetById(int id)
        {
            res     = new ArrayList();
            this.id = id;
            string key = this.GetType() + "." + id;

            if (!list.ContainsKey(key))
            {
                comm.CommandText = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "'";
                int cnt = Convert.ToInt32(comm.ExecuteScalar());
                comm.CommandText = "SELECT * FROM " + tableName + " WHERE id = " + id.ToString();
                reader           = comm.ExecuteReader();
                reader.Read();
                int i = 1;
                while (i < cnt)
                {
                    res.Add(reader[i].ToString());
                    i += 1;
                }
                reader.Close();
                FillObj();
                ObjectWatcher.AddToList(this);
                return(this);
            }
            else
            {
                return(ObjectWatcher.GetFromList(key));
            }
        }
示例#2
0
        public void Delete(int id)
        {
            ObjectWatcher.DeleteFromList(tableName + "." + id);
            comm.CommandText = "DELETE FROM " + tableName + " WHERE id = " + id;
            comm.ExecuteNonQuery();
            if (this.id == id)
            {
                this.id = default(int);
                res     = new ArrayList();
            }
            string key = tableName + "." + id;

            ObjectWatcher.DeleteFromList(key);
        }