Пример #1
0
        /// <summary>
        /// upload file
        /// 上传文件
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="GridFSName"></param>
        /// <returns></returns>
        public String UploadFile(String FilePath, String GridFSName = "")
        {
            if (System.IO.File.Exists(FilePath) == false)
            {
                throw new Exception("file path not found");
            }

            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }
            String s = _database.UploadFile(_databasename, FilePath, GridFSName);

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(s);
        }
Пример #2
0
        /// <summary>
        /// delete data by key value
        /// 删除指定条件数据
        /// </summary>
        /// <returns></returns>
        public int ExecuteCommand()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }

            Int32 count = 0;

            if (filterDefinition != null)
            {
                count = _database.DeleteData(_databasename, _TableName, filterDefinition);
            }
            else
            {
                count = _database.DeleteData(_databasename, _TableName);
            }

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(count);
        }
Пример #3
0
        /// <summary>
        /// get all database name
        /// </summary>
        /// <returns></returns>
        public List <String> GetDatabaseName()
        {
            List <String> s = new List <String>();

            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }

            s = _database.GetDatabaseName();

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(s);
        }
Пример #4
0
        /// <summary>
        /// insert new data
        /// 插入新数据
        /// </summary>
        public void ExecuteCommand()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }
            _database.InsertData(_databasename, _TableName, MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(MongoDBOP.HashtableToJson(htData)));

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return;
        }
Пример #5
0
        /// <summary>
        /// get all data
        /// 得到表中所有数据
        /// </summary>
        /// <returns></returns>
        public IHashTable Data()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }


            List <Hashtable> hr;

            if (filterDefinition != null)
            {
                hr = _database.GetDataSet(_databasename, _TableName, filterDefinition);
            }
            else
            {
                hr = _database.GetDataSet(_databasename, _TableName, new BsonDocument());
            }

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }


            IHashTable DT = new IHashTable(hr);

            return(DT);
        }
Пример #6
0
        /// <summary>
        /// update new data
        /// 更新数据
        /// </summary>
        /// <returns></returns>
        public Int32 ExecuteCommand()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }
            Int32 count = _database.UpdateData(_databasename, _TableName, filterDefinition, htData);

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(count);
        }
Пример #7
0
 /// <summary>
 /// close connect
 /// 长关闭数据库
 /// </summary>
 public void Close()
 {
     database.Close();
 }