websql操作类封装

  在之前,我写了一个websql的封装类库,代码如下:

(function(win) {
    function smpWebSql(options){
        options = options || {};
        this.database = null;
        this.DateBaseName = options.DateBaseName || ‘SmpDB‘;
        this.Version = options.Version || ‘1.0‘;
        this.Description = options.Description || ‘SmpDB‘;
        this.DataBaseSize = options.DataBaseSize || 2 * 1024 * 1024;
        this.init();
    }
    smpWebSql.prototype = {
        init: function() {
            this.database = openDatabase(this.DateBaseName, this.Version, this.Description, this.DataBaseSize); //初始化数据库
        },
        addBlob: function (tableName, arr,index,isFirst,callback) {//批量添加字段
            /*
                注 : 数据里面的第一个key存储类型为BLOB
                @param  tableName 表名
                @param  arr 更新的数据    [{key1:value1 , key2 : value2 ...},{key1:value1 , key2 : value2 ...}]
                @param  index BLOG字段所在的索引位置
                @param  isFirst 是否是第一次创建表
                @param  callback  回调
             */
            if (arr == null) {
                return this;
            }
            callback = this.isFunction(callback) ? callback : new Function();
            var _me = this,
                _db = this.database,
                keyC = [],
                keyI = [],
                _key = ‘‘;
            arr = arr || [];
            if (arr && arr.constructor == Array) {
                for (var i in arr[0]) {
                    keyC.push(i);
                    keyI.push(i);
                }
                _key = keyI.join(",");
                index = index == undefined ? 0 : index;
                keyC[index] = keyC[index] + ‘ BLOB‘;
                _db.transaction(function (tx, result) {
                    //var csql = ‘CREATE TABLE IF NOT EXISTS ‘ + tableName + ‘ (‘ + keyC.join(",") + ‘)‘;
                    //console.log(‘csql:‘ + csql);
                    if (isFirst == true) {
                        tx.executeSql(‘CREATE TABLE IF NOT EXISTS ‘ + tableName + ‘ (‘ + keyC.join(",") + ‘)‘);
                    }
                    //var sql = "";
                    for (var s = 0, _len = arr.length; s < _len ; s++) {
                        var _value = _me.split(arr[s]);
                        //sql += ‘INSERT INTO ‘ + tableName + ‘ (‘ + _key + ‘) VALUES (‘ + _value + ‘)‘;
                        //console.log("sql:" + sql);
                        tx.executeSql(‘INSERT INTO ‘ + tableName + ‘ (‘ + _key + ‘) VALUES (‘ + _value + ‘)‘,[],function (tx, result) {
                            callback(result.rowsAffected);
                            //console.log(‘添加成功‘+result.rowsAffected);
                        },function (tx, error) {
                            console.error(‘添加失败‘);
                            callback(false);
                        });
                    }
                    _key = keyI = keyC = null;
                    callback();
                });
            }
            return this;
        },
        add: function (tableName, arr, callback, noKey) {//批量添加字段
            /*
                注 : 数据里面的第一个key 为主键
                @param  tableName 表名
                @param  arr 更新的数据    [{key1:value1 , key2 : value2 ...},{key1:value1 , key2 : value2 ...}]
                @param  callback  回调
                @param  noKey 第一个字段是否是主键(默认是)
             */
            if(arr==null){
                return this;
            }
            callback = this.isFunction(callback) ? callback : new Function();
            var _me = this,
                _db = this.database,
                keyC = [],
                keyI = [],
                _key = ‘‘;
            arr = arr || [];
            if (arr && arr.constructor == Array) {
                for(var i in arr[0]){
                    keyC.push(i);
                    keyI.push(i);
                }
                if (noKey==undefined) {
                    keyC[0] = keyC[0] + ‘ unique‘;
                }
                _key = keyI.join(",");
                _db.transaction(function (tx) {
                   ///var csql = ‘CREATE TABLE IF NOT EXISTS ‘ + tableName + ‘ (‘ + keyC.join(",") + ‘)‘;
                    // console.log(‘csql:‘ + csql);
                     tx.executeSql(‘CREATE TABLE IF NOT EXISTS ‘ + tableName + ‘ (‘ + keyC.join(",") + ‘)‘);
                    //var sql = "";
                    for(var s = 0 , _len = arr.length; s < _len ; s++){
                        var _value = _me.split(arr[s]);
                        //sql += ‘INSERT INTO ‘ + tableName + ‘ (‘ + _key + ‘) VALUES (‘ + _value + ‘)‘;
                        //console.log("sql:" + sql);
                        tx.executeSql(‘INSERT INTO ‘+tableName+‘ (‘+_key+‘) VALUES (‘+_value+‘)‘,[],function (tx, result) {
                            callback(result.rowsAffected);
                            //console.log(‘添加成功‘+result.rowsAffected);
                        },function (tx, error) {
                            console.error(‘添加失败‘);
                            callback(false);
                        });
                    }
                    _key = keyI = keyC = null;
                    callback();
                });
            }
            return this;
        },
        update : function(tableName,key,value,obj,callback){//更新指定数据
            /*
                @param  tableName 表名
                @param  key 查询的键
                @param  value 对应键的值
                @param  obj 更新的数据    {key1:value1 , key2 : value2 ...}
                @param  callback  回调  传递参数为真则查询成功 反之更新失败
             */
            callback = this.isFunction(callback) ? callback : new Function();
            var _db = this.database,
                _value = this.splitU(obj);
            _db.transaction(function (tx) {
                //console.log(‘sql:‘ + ‘UPDATE ‘ + tableName + ‘ set ‘ + _value + ‘ where ‘ + key + ‘="‘ + value + ‘"‘)
                tx.executeSql(‘UPDATE ‘+tableName+‘ set ‘+_value+‘ where ‘+key+‘="‘+value+‘"‘,[],function (tx, result) {
                    callback(result.rowsAffected);
                },function (tx, error) {
                    console.error(‘更新失败‘);
                    callback(false);
                });
            });
            return this;
        },
        updateWhere: function (tableName, where, obj, callback) {//更新指定数据
            /*
                @param  tableName 表名
                @param  查询条件
                @param  obj 更新的数据    {key1:value1 , key2 : value2 ...}
                @param  callback  回调  传递参数为真则查询成功 反之更新失败
             */
            callback = this.isFunction(callback) ? callback : new Function();
            var _db = this.database,
                _value = this.splitU(obj);
            _db.transaction(function (tx) {
                console.log(‘UPDATE ‘ + tableName + ‘ set ‘ + _value + ‘ where ‘ + where + ‘"‘)
                tx.executeSql(‘UPDATE ‘ + tableName + ‘ set ‘ + _value + ‘ where ‘ + where + ‘"‘, [], function (tx, result) {
                    callback(result.rowsAffected);
                }, function (tx, error) {
                    console.error(‘更新失败‘);
                    callback(false);
                });
            });
            return this;
        },
        read : function(tableName,condition,callback){ //读取表数据
            /*
                @param  tableName 表名
                @param  condition 查询条件   ‘where name="汪文君"‘
                @param  callback  回调  传递参数为真则查询成功 反之查询失败
             */
            var _condition = this.isString(condition) ? condition : ‘‘;
            var _callback = this.isFunction(condition) ? condition : this.isFunction(callback) ? callback : new Function;
            var _db = this.database,
                _me = this,
                _re = [];
                _db.transaction(function (tx) {
                    tx.executeSql(‘SELECT * FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘, [], function (tx, results) {
                        if(results && results.rows){
                            _re =_me.toArray(results.rows);
                            _callback(_re);
                        }else{
                            _callback([]);
                        }
                    },function(tx,error){
                        _callback([]);
                        console.error(‘查询失败‘);
                    });
                });
                return this;
        },
        remove:function(tableName,condition,callback){//删除数据
            /*
                @param  tableName 表名
                @param  condition 查询条件   ‘where name="汪文君"‘
                @param  callback  回调  传递参数为真则删除成功 反之删除失败
             */
            var _me = this;
            var _condition = this.isString(condition) ? condition : ‘‘;
            var _callback = this.isFunction(condition) ? condition : this.isFunction(callback) ? callback : new Function;
            _me.database.transaction(function (tx) {
                tx.executeSql(‘DELETE FROM ‘+tableName+ ‘ ‘+ _condition+‘ ‘,[],function (tx, result) {
                    _callback(result.rowsAffected);
                },function (tx, error) {
                    _callback(false);
                    console.error(‘删除失败‘);
                });
            });
        },
        counts: function (tableName, condition, callback) { //读取表数据
            /*
                @param  tableName 表名
                @param  condition 查询条件   ‘where name="汪文君"‘
                @param  callback  回调  传递参数为真则查询成功 反之查询失败
             */
            var _condition = this.isString(condition) ? condition : ‘‘;
            var _callback = this.isFunction(condition) ? condition : this.isFunction(callback) ? callback : new Function;
            var _db = this.database,
                _me = this,
                _re = [];
            if (mui.os.ios) { //ios下面特有的
                _db.transaction(function (tx) {
                    tx.executeSql(‘SELECT NO FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘, [], function (tx, results) {// count (*) as num
                        if (results && results.rows) {
                            _re = _me.toArray(results.rows);
                            _callback(_re.length);
                        } else {
                            _callback(0);
                        }
                    }, function (tx, error) {
                        _callback(0);
                        console.error(‘查询失败‘);
                    });
                });
            } else {
                _db.transaction(function (tx) {
                    tx.executeSql(‘SELECT count (*) as num FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘, [], function (tx, results) {// count (*) as num
                        if (results && results.rows) {
                            if (results.rows[0]) {
                                _callback(results.rows[0].num);
                            } else {
                                _callback(0);
                            }
                        } else {
                            _callback(0);
                        }
                    }, function (tx, error) {
                        _callback(0);
                        console.error(‘查询失败‘);
                    });
                });
            }
            return this;
        },
        delTable:function(tableName,callback){ //删除数据表
            callback = this.isFunction(callback) ? callback : new Function();
            this.database.transaction(function(tx){
                tx.executeSql(‘DROP TABLE IF EXISTS ‘+tableName,[],function(tx,res){
                    callback();
                },function(tx,err){
                    console.error(err);
                });
            });
            return this;
        },
        splitU: function(obj){//更新字符处理
            var _arr = [];
            for(var t in obj){
                _arr.push(t+‘="‘+obj[t]+‘"‘);
            }
            return _arr.join(‘,‘);
        },
        split : function(obj){//添加字符处理
            var _arr = [];
            for(var m in obj){
                _arr.push("‘"+obj[m]+"‘");
            }
            return _arr.join(‘,‘);
        },
        isFunction : function(callback){
            return typeof callback != ‘undefined‘ && callback.constructor == Function ? true : false
        },
        isString : function(string){
            return typeof string == ‘string‘ ? true : false
        },
        toArray : function(obj){
            var _arr = [],
                _len = obj.length;
                if(_len > 0){
                    for (var i = 0; i < _len; i++) {
                        _arr.push(obj.item(i));
                    };
                }
                return _arr;
        }
    }
    win.smpWebSql = smpWebSql;
}(window))

  上述代码存在的问题非常明显,由于websql操作都是异步操作,当我们为了获取到websql操作的结果之后再进行后续操作时,往往是通过回调函数来实现的,当回调一多的时候,回调地狱就出现了,为了解决回调地狱问题,我将通过Promise来改写,后续调用时,可以直接通过await和async来调用,或者直接通过Promise链式调用也是可以的。

  现在我将通过ES6的语法重写之前的封装类,为了应用ES6中js面向对象的思想,我这里用到了class,最终代码如下:

import utils from ‘@/utils/utils.js‘;
class SmpWebSql {
  constructor(options) {
    options = options || {};
    this.database = null;
    this.DateBaseName = options.DateBaseName || ‘RedDB‘;
    this.Version = options.Version || ‘1.0‘;
    this.Description = options.Description || ‘智维离线工单数据库‘;
    this.DataBaseSize = options.DataBaseSize || 2 * 1024 * 1024;
    this.init();
  }
  /**
   * 初始化数据库
   */
  init() {
    this.database = openDatabase(
      this.DateBaseName,
      this.Version,
      this.Description,
      this.DataBaseSize
    );
  }
  /**
   * 批量添加字段
   * @param {*} tableName 表名
   * @param {*} arr 更新的数据    [{key1:value1 , key2 : value2 ...},{key1:value1 , key2 : value2 ...}]
   * @param {*} index BLOG字段所在的索引位置
   * @param {*} isFirst 是否是第一次创建表
   */
  addBlob(tableName, arr, index, isFirst) {
    var _db = this.database;
    var _me = this;
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      if (arr == null) {
        return this;
      }
      var keyC = [];
      var keyI = [];
      var _key = ‘‘;
      arr = arr || [];
      if (arr && arr.constructor == Array) {
        for (var i in arr[0]) {
          keyC.push(i);
          keyI.push(i);
        }
        _key = keyI.join(‘,‘);
        index = index == undefined ? 0 : index;
        keyC[index] = keyC[index] + ‘ BLOB‘;
        // eslint-disable-next-line promise/param-names

        _db.transaction(function(tx, result) {
          // var csql = ‘CREATE TABLE IF NOT EXISTS ‘ + tableName + ‘ (‘ + keyC.join(",") + ‘)‘;
          // console.log(‘csql:‘ + csql);
          if (isFirst == true) {
            tx.executeSql(
              ‘CREATE TABLE IF NOT EXISTS ‘ +
                tableName +
                ‘ (‘ +
                keyC.join(‘,‘) +
                ‘)‘
            );
          }
          // var sql = "";
          for (var s = 0, _len = arr.length; s < _len; s++) {
            var _value = _me.split(arr[s]);
            // sql += ‘INSERT INTO ‘ + tableName + ‘ (‘ + _key + ‘) VALUES (‘ + _value + ‘)‘;
            // console.log("sql:" + sql);
            tx.executeSql(
              ‘INSERT INTO ‘ +
                tableName +
                ‘ (‘ +
                _key +
                ‘) VALUES (‘ +
                _value +
                ‘)‘,
              [],
              function(tx, result) {
                resovle(result.rowsAffected);
                // console.log(‘添加成功‘+result.rowsAffected);
              },
              function(tx) {
                console.error(‘添加失败‘);
                // eslint-disable-next-line prefer-promise-reject-errors
                reject(false);
              }
            );
          }
          _key = keyI = keyC = null;
          resovle();
        });
      }
    });
  }
  /**
   * 批量添加字段 注 : 数据里面的第一个key 为主键
   * @param {*} tableName 表名
   * @param {*} arr arr 更新的数据    [{key1:value1 , key2 : value2 ...},{key1:value1 , key2 : value2 ...}]
   * @param {*} noKey noKey 第一个字段是否是主键(默认是)
   */
  add(tableName, arr, noKey) {
    var _me = this;
    var _db = this.database;
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      if (arr == null) {
        return this;
      }
      var keyC = [];
      var keyI = [];
      var _key = ‘‘;
      arr = arr || [];
      if (arr && arr.constructor == Array) {
        for (var i in arr[0]) {
          keyC.push(i);
          keyI.push(i);
        }
        if (noKey == undefined) {
          keyC[0] = keyC[0] + ‘ unique‘;
        }
        _key = keyI.join(‘,‘);
        _db.transaction(function(tx) {
          // /var csql = ‘CREATE TABLE IF NOT EXISTS ‘ + tableName + ‘ (‘ + keyC.join(",") + ‘)‘;
          // console.log(‘csql:‘ + csql);
          tx.executeSql(
            ‘CREATE TABLE IF NOT EXISTS ‘ +
              tableName +
              ‘ (‘ +
              keyC.join(‘,‘) +
              ‘)‘
          );
          // var sql = "";
          for (var s = 0, _len = arr.length; s < _len; s++) {
            var _value = _me.split(arr[s]);
            // sql += ‘INSERT INTO ‘ + tableName + ‘ (‘ + _key + ‘) VALUES (‘ + _value + ‘)‘;
            // console.log("sql:" + sql);
            tx.executeSql(
              ‘INSERT INTO ‘ +
                tableName +
                ‘ (‘ +
                _key +
                ‘) VALUES (‘ +
                _value +
                ‘)‘,
              [],
              function(tx, result) {
                resovle(result.rowsAffected);
                // console.log(‘添加成功‘+result.rowsAffected);
              },
              function(tx, error) {
                console.error(‘添加失败‘);
                // eslint-disable-next-line prefer-promise-reject-errors
                reject(false);
              }
            );
          }
          _key = keyI = keyC = null;
          // resovle();
        });
      }
    });
  }
  /**
   * 更新指定数据
   * @param {*} tableName 表名
   * @param {*} key 查询的键
   * @param {*} value 对应键的值
   * @param {*} obj obj 更新的数据    {key1:value1 , key2 : value2 ...}
   */
  update(tableName, key, value, obj) {
    var _db = this.database;
    var _value = this.splitU(obj);
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      _db.transaction(function(tx) {
        // console.log(‘sql:‘ + ‘UPDATE ‘ + tableName + ‘ set ‘ + _value + ‘ where ‘ + key + ‘="‘ + value + ‘"‘)
        tx.executeSql(
          ‘UPDATE ‘ +
            tableName +
            ‘ set ‘ +
            _value +
            ‘ where ‘ +
            key +
            ‘="‘ +
            value +
            ‘"‘,
          [],
          function(tx, result) {
            resovle(result.rowsAffected);
          },
          function(tx, error) {
            console.error(‘更新失败‘);
            // eslint-disable-next-line prefer-promise-reject-errors
            reject(false);
          }
        );
      });
    });
  }
  /**
   * 更新指定数据
   * @param {*} tableName 表名
   * @param {*} where 查询条件
   * @param {*} obj obj 更新的数据    {key1:value1 , key2 : value2 ...}
   */
  updateWhere(tableName, where, obj) {
    var _db = this.database;
    var _value = this.splitU(obj);
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      _db.transaction(function(tx) {
        console.log(
          ‘UPDATE ‘ + tableName + ‘ set ‘ + _value + ‘ where ‘ + where + ‘"‘
        );
        tx.executeSql(
          ‘UPDATE ‘ + tableName + ‘ set ‘ + _value + ‘ where ‘ + where + ‘"‘,
          [],
          function(tx, result) {
            resovle(result.rowsAffected);
          },
          function(tx, error) {
            console.error(‘更新失败‘);
            // eslint-disable-next-line prefer-promise-reject-errors
            reject(false);
          }
        );
      });
    });
  }
  /**
   * 读取表数据
   * @param {*} tableName 表名
   * @param {*} condition 查询条件   ‘where name="jiekzou"‘
   */
  read(tableName, condition) {
    var _db = this.database;
    var _me = this;
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      var _condition = this.isString(condition) ? condition : ‘‘;
      var _re = [];
      _db.transaction(function(tx) {
        tx.executeSql(
          ‘SELECT * FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘,
          [],
          function(tx, results) {
            if (results && results.rows) {
              _re = _me.toArray(results.rows);
              resovle(_re);
            } else {
              resovle([]);
            }
          },
          function(tx, error) {
            // eslint-disable-next-line prefer-promise-reject-errors
            reject([]);
            console.error(‘查询失败‘);
          }
        );
      });
    });
  }
  /**
   * 删除数据
   * @param {*} tableName 表名
   * @param {*} condition 查询条件   ‘where name="jiekzou"‘
   */
  remove(tableName, condition) {
    var _me = this;
    var _condition = this.isString(condition) ? condition : ‘‘;
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      _me.database.transaction(function(tx) {
        tx.executeSql(
          ‘DELETE FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘,
          [],
          function(tx, result) {
            resovle(result.rowsAffected);
          },
          function(tx, error) {
            // eslint-disable-next-line prefer-promise-reject-errors
            reject(false);
            console.error(‘删除失败‘);
          }
        );
      });
    });
  }
  /**
   * 根据查询条件读取表记录数
   * @param {*} tableName 表名
   * @param {*} condition 查询条件   ‘where name="jiekzou"‘
   */
  counts(tableName, condition) {
    if (utils.browserVersions.android) {
      return this.androidCounts(tableName, condition);
    } else {
      return this.iosCounts(tableName, condition);
    }
  }
  // ios下面特有的
  /**
   * 读取表数据(ios下面特有的)
   * @param {*} tableName 表名
   * @param {*} condition  查询条件   ‘where name="jiekzou"‘
   */
  iosCounts(tableName, condition) {
    var _condition = this.isString(condition) ? condition : ‘‘;
    var _db = this.database;
    var _me = this;
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      var _re = [];
      _db.transaction(function(tx) {
        tx.executeSql(
          ‘SELECT NO FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘,
          [],
          function(tx, results) {
            // count (*) as num
            if (results && results.rows) {
              _re = _me.toArray(results.rows);
              resovle(_re.length);
            } else {
              resovle(0);
            }
          },
          function(tx, error) {
            // eslint-disable-next-line prefer-promise-reject-errors
            reject(0);
            console.error(‘查询失败‘);
          }
        );
      });
    });
  }
  /**
   * 读取表数据(Android)
   * @param {*} tableName 表名
   * @param {*} condition 查询条件   ‘where name="jiekzou"‘
   */
  androidCounts(tableName, condition) {
    var _condition = this.isString(condition) ? condition : ‘‘;
    var _db = this.database;
    var _me = this;
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      var _re = [];
      _db.transaction(function(tx) {
        tx.executeSql(
          ‘SELECT count (*) as num FROM ‘ + tableName + ‘ ‘ + _condition + ‘ ‘,
          [],
          function(tx, results) {
            // count (*) as num
            if (results && results.rows) {
              if (results.rows[0]) {
                resovle(results.rows[0].num);
              } else {
                resovle(0);
              }
            } else {
              resovle(0);
            }
          },
          function(tx, error) {
            // eslint-disable-next-line prefer-promise-reject-errors
            reject(0);
            console.error(‘查询失败‘);
          }
        );
      });
    });
  }
  /**
   * 删除数据表
   * @param {*} tableName 表名
   */
  delTable(tableName) {
    // eslint-disable-next-line promise/param-names
    return new Promise(function(resovle, reject) {
      this.database.transaction(function(tx) {
        tx.executeSql(
          ‘DROP TABLE IF EXISTS ‘ + tableName,
          [],
          function(tx, res) {
            resovle();
          },
          function(tx, err) {
            console.error(err);
            // eslint-disable-next-line prefer-promise-reject-errors
            reject(0);
          }
        );
      });
    });
  }
  // 更新字符处理
  splitU(obj) {
    var _arr = [];
    for (var t in obj) {
      _arr.push(t + ‘="‘ + obj[t] + ‘"‘);
    }
    return _arr.join(‘,‘);
  }
  // 添加字符处理
  split(obj) {
    var _arr = [];
    for (var m in obj) {
      _arr.push(‘\‘‘ + obj[m] + ‘\‘‘);
    }
    return _arr.join(‘,‘);
  }
  isFunction(callback) {
    return !!(
      typeof callback != ‘undefined‘ && callback.constructor == Function
    );
  }
  isString(string) {
    return typeof string == ‘string‘;
  }
  toArray(obj) {
    var _arr = [];
    var _len = obj.length;
    if (_len > 0) {
      for (var i = 0; i < _len; i++) {
        _arr.push(obj.item(i));
      }
    }
    return _arr;
  }
}

export default SmpWebSql;

原文地址:https://www.cnblogs.com/jiekzou/p/11366121.html

时间: 2024-11-02 20:14:36

websql操作类封装的相关文章

操作类封装

/*操作类封装 */ /*调用方法 如下: * var str= new IStrManipulation();//实例化字符串处理接口 * console.log(str.StrManipulation('StrManipulation',"111sss23123").getLength()); * var convert =new IConvert();//实例化类型转换接口 * console.log(convert.Convert('Convert',"1112312

[No0000DE]C# XmlHelper XML类型操作 类封装

using System; using System.Data; using System.IO; using System.Text; using System.Threading; using System.Xml; using System.Xml.Serialization; using Shared; namespace Helpers { public static class XmlHelper { #region Fields and Properties public enum

QT 操作excel 类封装

1 # pro file 2 [plain] view plaincopy 3 CONFIG += qaxcontainer 4 5 QT += core 6 7 QT -= gui 8 9 TARGET = QExcel 10 CONFIG += console 11 CONFIG -= app_bundle 12 13 TEMPLATE = app 14 15 16 SOURCES += main.cpp \ 17 qexcel.cpp 18 19 HEADERS += \ 20 qexce

c# 封装的文件夹操作类之复制文件夹

c#  封装的文件夹操作类之复制文件夹 一.复制文件夹原理: 1.递归遍历文件夹 2.复制文件 二.FolderHelper.cs 1 /// <summary> 2 /// 文件夹操作类 3 /// </summary> 4 public static class FolderHelper 5 { 6 /// <summary> 7 /// 复制文件夹 8 /// </summary> 9 /// <param name="sourceFo

Android适配器之DataModifyHelper数据操作类的封装

编写适配器代码时常常被以下几个问题所困扰: 1.业务层和适配器中对同一组数据进行维护,难以管理 2.在业务层针对数据进行修改后必须通知适配器更新,否则提示The content of the adapter has changed but ListView did not receive anotification 3.业务层修改数据时充斥大量的非空&数据标准化等冗余代码 针对前两个问题,可以将数据交由适配器去管理,业务层对数据的增删改查均通过适配器进行处理,这样仅需要维护好adapter中的数

自己封装的ASP.NET的MYSQL的数据库操作类

/** * 作者:牛腩 * 创建时间:2010年3月7日17时35分 * 类说明:对MYSQL数据库的操作类 */ using System; using System.Data; using MySql.Data.MySqlClient; namespace Niunan.BYLW.Utility { /// <summary>对MYSQL数据库的操作类 /// /// </summary> public class MYSQLHelper { private MySqlConn

C#封装的常用文件操作类实例

本文实例讲述了C#封装的常用文件操作类.分享给大家供大家参考.具体如下: 这个C#类封装了我们经常能用到的文件操作方法,包括读写文件.获取文件扩展名.复制文件.追加内容到文件.删除文件.移动文件.创建目录.递归删除文件及目录.列目录.列文件等,不可多得. using System; using System.Text; using System.Web; using System.IO; namespace DotNet.Utilities { public class FileOperate

C#使用iTextSharp封装的PDF文件操作类实例

本文实例讲述了C#使用iTextSharp封装的PDF文件操作类.分享给大家供大家参考.具体分析如下: 这个C#代码主要讲iTextSharp中用于操作PDF文件的方法进行了再次封装,可以更加方便的访问PDF文档,可以动态生成PDF文件.添加内容.设置段落.设置字体等. using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace DotNet.Utilities { /// <summary> ///

封装php redis缓存操作类

封装php redis缓存操作类,集成了连接redis并判断连接是否成功,redis数据库选择,检测redis键是否存在,获取值,写入值,设置生存时间和删除清空操作. php redis类代码: <?php/*** redisdrive.class.php* php redis 操作类**/class redisdrive{ //键名 public $key; //值 public $value; //默认生存时间 public $expire = 86400; /*60*60*24*/ //连