Example #1
0
        /// <summary>
        /// 查询数据集Dataset集合
        /// </summary>
        /// <param name="_option">操作类型</param>
        /// <param name="_selecttype">查询类型</param>
        /// <param name="P_IgnoreCase">是否大小写</param>
        /// <returns>Dataset集合</returns>
        public virtual List <T> SelectPage <T>(KdtFieldEntityEx _option, KdtPageEx _selecttype, bool P_IgnoreCase = false)
            where T : class, new()
        {
            using (var adapter = LoadAdapter())
            {
                adapter.Open(); // 打开执行数据库
                if (!P_IgnoreCase)
                {
                    adapter.BindFlag.script = "{0}";                // 消除插入数据执行T-SQL语法
                }
                KdtParameterCollection props;
                _option.SetAdapter(Driver);
                string sqltext = _option.Select(_selecttype.selpagetotal, out props);
                if (string.IsNullOrEmpty(sqltext))
                {
                    throw new DataException("执行的查询统计总数语句为空!");
                }
                int total = adapter.ExecuteScalar <int>(sqltext, props);
                _selecttype.total = total;

                if (total > 0)
                {
                    //adapter.Open(); // 打开执行数据库
                    sqltext = _option.Select(_selecttype.selpage, out props);
                    if (string.IsNullOrEmpty(sqltext))
                    {
                        throw new DataException("执行的查询分页语句为空!");
                    }
                    props.AddParameter("start", _selecttype.start, ProcInPutEnum.InPut);
                    props.AddParameter("end", _selecttype.end, ProcInPutEnum.InPut);
                    return(adapter.ExecuteQuery <T>(sqltext, props));
                }
                return(new List <T>());
            }
        }
Example #2
0
        /// <summary>
        /// 回滚,无返回值执行方法
        /// </summary>
        /// <param name="_option"></param>
        /// <param name="_selecttype"></param>
        /// <param name="P_IgnoreCase"></param>
        public virtual void TransExecute(KdtFieldEntityEx _option, string _selecttype, bool P_IgnoreCase = false)
        {
            using (var adapter = LoadAdapter())
            {
                adapter.Open(); // 打开执行数据库
                if (!P_IgnoreCase)
                {
                    adapter.BindFlag.script = "{0}";                // 消除插入数据执行T-SQL语法
                }
                KdtParameterCollection props;
                _option.SetAdapter(Driver);
                string sqltext = _option.Select(_selecttype, out props);
                if (string.IsNullOrEmpty(sqltext))
                {
                    throw new DataException("执行的SQL语句为空!");
                }

                adapter.BeginTrans();
                try
                {
                    _option.Affected = adapter.ExecuteNoQuery(sqltext, props);
                    adapter.CommitTrans();
                }
                catch (Exception ex)
                {
                    // 写日志
                    KdtLoger.Instance.Error(ex);
                    adapter.RollbackTrans();
                }
            }
        }
Example #3
0
        public virtual List <KeyValueCollection> SelectKVCollectionPage(KdtFieldEntityEx _option, string _selecttype, int offset, int limit, bool P_IgnoreCase = false)
        {
            using (var adapter = LoadAdapter())
            {
                adapter.Open(); // 打开执行数据库
                if (!P_IgnoreCase)
                {
                    adapter.BindFlag.script = "{0}";                // 消除插入数据执行T-SQL语法
                }
                KdtParameterCollection props;
                _option.SetAdapter(Driver);
                string sqltext = _option.Select(_selecttype, out props);
                if (string.IsNullOrEmpty(sqltext))
                {
                    throw new DataException("执行的SQL语句为空!");
                }

                return(adapter.ExecuteQueryPageKVCollection(sqltext, props, offset, limit));
            }
        }
Example #4
0
        /// <summary>
        /// 查询数据集Dataset集合
        /// </summary>
        /// <param name="_option">操作类型</param>
        /// <param name="_selecttype">查询类型</param>
        /// <param name="P_IgnoreCase">是否大小写</param>
        /// <returns>Dataset集合</returns>
        public virtual T SelectField <T>(KdtFieldEntityEx _option, string _selecttype, bool P_IgnoreCase = false)
        {
            using (var adapter = LoadAdapter())
            {
                adapter.Open(); // 打开执行数据库
                if (!P_IgnoreCase)
                {
                    adapter.BindFlag.script = "{0}";                // 消除插入数据执行T-SQL语法
                }
                KdtParameterCollection props;
                _option.SetAdapter(Driver);
                string sqltext = _option.Select(_selecttype, out props);
                if (string.IsNullOrEmpty(sqltext))
                {
                    throw new DataException("执行的SQL语句为空!");
                }

                return(adapter.ExecuteScalar <T>(sqltext, props));
            }
        }
Example #5
0
        /// <summary>
        /// 执行添加或更新数据操作(该方方法目前只支持SQLSERVER,ORACLE数据库)
        /// </summary>
        /// <param name="_option">操作实体类</param>
        /// <param name="P_IgnoreCase">是否忽略大小写</param>
        public virtual void AddOrUpdate(KdtFieldEntityEx _option, bool P_IgnoreCase = false)
        {
            using (var adapter = LoadAdapter())
            {
                adapter.Open(); // 打开执行数据库
                if (!P_IgnoreCase)
                {
                    adapter.BindFlag.script = "{0}";                // 消除插入数据执行T-SQL语法
                }
                bool istran;
                KdtParameterCollection props;
                _option.SetAdapter(Driver);
                if (adapter is MySqlClientAdapter)
                {
                    // 执行查询是否存在
                    string esql = _option.GetMainTableExist();
                    if (adapter.ExecuteScalar <bool>(esql))
                    {
                        Update(_option, P_IgnoreCase);
                    }
                    else
                    {
                        Add(_option, P_IgnoreCase);
                    }
                }
                else
                {
                    string sqltext = _option.AddOrUpdate(out istran, out props);
                    if (string.IsNullOrEmpty(sqltext))
                    {
                        throw new DataException("执行的SQL语句为空!");
                    }

                    if (istran) // 执行回滚方法
                    {
                        adapter.BeginTrans();
                        try
                        {
                            var vals = adapter.ExecuteKVCollection(sqltext, props);
                            if (vals != null && vals.Count > 0)
                            {
                                foreach (var val in vals)
                                {
                                    if (_option.IncrVal.ContainsKey(val.key.TrimStart('p')))
                                    {
                                        _option.IncrVal[val.key.TrimStart('p')] = val.val.Convert(0);
                                    }
                                }
                            }
                            adapter.CommitTrans();
                        }
                        catch (Exception ex)
                        {
                            // 写日志
                            KdtLoger.Instance.Error(ex);
                            adapter.RollbackTrans();
                        }
                    }
                    else // 执行非回滚数据
                    {
                        var vals = adapter.ExecuteKVCollection(sqltext, props);
                        if (vals != null && vals.Count > 0)
                        {
                            _option.Affected = vals.Count;
                            foreach (var val in vals)
                            {
                                if (_option.IncrVal.ContainsKey(val.key.TrimStart('p')))
                                {
                                    _option.IncrVal[val.key.TrimStart('p')] = val.val.Convert(0);
                                }
                            }
                        }
                        else
                        {
                            _option.Affected = adapter.ExecuteNoQuery(sqltext, props);
                        }
                    }
                }
            }
        }