Example #1
0
        /// <summary>
        /// 功能: ExcuteTransaction
        /// 作者:wangguan
        /// 创建日期:2008-10-10
        /// 最后修改日期:
        /// Review:*********
        /// </summary>
        /// <param name="p_parameters">ParameterCollection</param>
        /// <param name="p_transactionName">TransactionName</param>
        /// <param name="strError">Error Discription</param>
        /// <returns>Success or fail</returns>
        public bool ExcuteByTransaction(CParameters p_parameters, string p_transactionName, out string strError)
        {
            bool result = false;

            strError = string.Empty;

            #region check strConnection
            if (null == m_strConnection || 0 == m_strConnection.Length)
            {
                strError = "construct's parameter can not be emply";
                return(result);
            }
            if (null == p_transactionName || 0 == p_transactionName.Length)
            {
                strError = "parameter p_transactionName can not be emply";
                return(result);
            }
            #endregion

            result = true;
            #region connect
            try
            {
                con = new SqlConnection(m_strConnection);
                cmd = new SqlCommand();

                cmd.CommandTimeout = 60000;
                cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                cmd.CommandText    = p_transactionName;
                cmd.Connection     = con;
                foreach (SqlParameter para in p_parameters)
                {
                    cmd.Parameters.Add(para);
                }


                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                result   = false;
            }
            finally
            {
                if (con != null && con.State == System.Data.ConnectionState.Open)
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                    con.Close();
                }
            }
            #endregion

            return(result);
        }
Example #2
0
        /// <summary>
        /// 功能: Excute Sql
        /// 作者:wangguan
        /// 创建日期:2009-02-06
        /// 最后修改日期:
        /// Review:*********
        /// </summary>
        /// <param name="sqlString">Sql string</param>
        /// <param name="strError">Error Discription</param>
        /// <returns>Success or Fail</returns>
        public bool ExcuteBySql(string p_sqlString, CParameters p_paramters, out string strError)
        {
            bool result = false;

            strError = string.Empty;

            #region check strConnection
            if (null == m_strConnection || 0 == m_strConnection.Length)
            {
                strError = "construct's parameter can not be emply";
                return(result);
            }
            if (null == p_sqlString || 0 == p_sqlString.Length)
            {
                strError = "parameter sqlString can not be emply";
                return(result);
            }
            #endregion

            #region connect
            result = true;
            try
            {
                con = new SqlConnection(m_strConnection);
                con.Open();
                cmd = con.CreateCommand();

                foreach (SqlParameter para in p_paramters)
                {
                    cmd.Parameters.Add(para);
                }

                cmd.CommandText = p_sqlString;
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                result   = false;
            }
            finally
            {
                if (con != null && con.State == System.Data.ConnectionState.Open)
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                    con.Close();
                }
            }
            #endregion

            return(result);
        }
Example #3
0
        /// <summary>
        /// 功能: ExcuteTransaction return DataSet & PageParas
        /// 作者: LD
        /// 创建日期:2008-11-9
        /// 最后修改日期:
        /// Review:*********
        /// </summary>
        /// <param name="p_paramters">ParameterCollection</param>
        /// <param name="strError">Error Discription</param>
        /// <returns></returns>
        public bool ExcuteByTransaction(CParameters p_paramters, string p_transactionName, out decimal minPrice,
                                        out decimal maxPrice, out DataSet ds, out string strError)
        {
            maxPrice = 0;
            minPrice = 0;
            bool result = false;

            strError = string.Empty;
            ds       = new DataSet();

            #region check strConnection
            if (null == m_strConnection || 0 == m_strConnection.Length)
            {
                strError = "construct's parameter can not be emply";
                return(result);
            }
            if (null == p_transactionName || 0 == p_transactionName.Length)
            {
                strError = "parameter p_transactionName can not be emply";
                return(result);
            }
            #endregion

            result = true;
            #region connect
            try
            {
                con = new SqlConnection(m_strConnection);
                cmd = new SqlCommand();
                cmd.CommandTimeout = 60000;
                cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                cmd.CommandText    = p_transactionName;
                cmd.Connection     = con;
                foreach (SqlParameter para in p_paramters)
                {
                    cmd.Parameters.Add(para);
                }

                SqlParameter paraMinPrice = new SqlParameter("@minPrice", SqlDbType.Decimal);
                paraMinPrice.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(paraMinPrice);

                SqlParameter paraMaxPrice = new SqlParameter("@maxPrice", SqlDbType.Decimal);
                paraMaxPrice.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(paraMaxPrice);

                SqlParameter paraReturnvalue = new SqlParameter("@O_RETURN", SqlDbType.Int);
                paraReturnvalue.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(paraReturnvalue);

                adapter = new SqlDataAdapter();
                adapter.SelectCommand = cmd;
                con.Open();
                adapter.Fill(ds);

                minPrice = (decimal)paraMinPrice.Value;
                maxPrice = (decimal)paraMaxPrice.Value;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                result   = false;
            }
            finally
            {
                if (con != null && con.State == System.Data.ConnectionState.Open)
                {
                    if (adapter != null)
                    {
                        adapter.Dispose();
                    }
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                    con.Close();
                }
            }
            #endregion

            return(result);
        }
Example #4
0
        /// <summary>
        /// 功能: ExcuteTransaction return DataSet & PageParas
        /// 作者: LD
        /// 创建日期:2008-11-9
        /// 最后修改日期:
        /// Review:*********
        /// </summary>
        /// <param name="p_paramters">ParameterCollection</param>
        /// <param name="strError">Error Discription</param>
        /// <returns></returns>
        public bool ExcuteByTransaction(CParameters p_paramters, string p_transactionName, out int iRecordCount,
                                        out int iPageCount, out DataSet ds, out string strError)
        {
            iRecordCount = 0;
            iPageCount   = 0;
            bool result = false;

            strError = string.Empty;
            ds       = new DataSet();

            #region check strConnection
            if (null == m_strConnection || 0 == m_strConnection.Length)
            {
                strError = "construct's parameter can not be emply";
                return(result);
            }
            if (null == p_transactionName || 0 == p_transactionName.Length)
            {
                strError = "parameter p_transactionName can not be emply";
                return(result);
            }
            #endregion

            result = true;
            #region connect
            try
            {
                con = new SqlConnection(m_strConnection);
                cmd = new SqlCommand();
                cmd.CommandTimeout = 60000;
                cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                cmd.CommandText    = p_transactionName;
                cmd.Connection     = con;
                foreach (SqlParameter para in p_paramters)
                {
                    cmd.Parameters.Add(para);
                }

                SqlParameter RecordCount = new SqlParameter("@RecordCount", SqlDbType.Int);//总记录数
                RecordCount.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(RecordCount);

                SqlParameter PageCount = new SqlParameter("@PageCount", SqlDbType.Int);//总页数
                PageCount.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(PageCount);

                adapter = new SqlDataAdapter();
                adapter.SelectCommand = cmd;
                con.Open();
                adapter.Fill(ds);

                iRecordCount = (int)RecordCount.Value;
                iPageCount   = (int)PageCount.Value;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                result   = false;
            }
            finally
            {
                if (con != null && con.State == System.Data.ConnectionState.Open)
                {
                    if (adapter != null)
                    {
                        adapter.Dispose();
                    }
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                    con.Close();
                }
            }
            #endregion

            return(result);
        }
Example #5
0
        /// <summary>
        /// 功能: Get DataSet
        /// 作者:wangguan
        /// 创建日期:2008-10-10
        /// 最后修改日期:
        /// </summary>
        /// <param name="p_sqlString">Sql String</param>
        /// <param name="ds">DataSet</param>
        /// <param name="error">Error Discription</param>
        /// <returns>Success or Fail</returns>
        public bool ExcuteByDataAdapter(string p_sqlString, CParameters p_paramters, out DataSet ds, out string strError)
        {
            bool result = false;

            strError = string.Empty;
            ds       = new DataSet();

            #region check strConnection
            if (null == m_strConnection || 0 == m_strConnection.Length)
            {
                strError = "construct's parameter can not be emply";
                return(result);
            }
            if (null == p_sqlString || 0 == p_sqlString.Length)
            {
                strError = "parameter sqlString can not be emply";
                return(result);
            }
            #endregion

            #region connect
            result = true;
            try
            {
                con = new SqlConnection(m_strConnection);
                cmd = con.CreateCommand();

                foreach (SqlParameter para in p_paramters)
                {
                    cmd.Parameters.Add(para);
                }

                cmd.CommandText    = p_sqlString;
                cmd.CommandTimeout = 60000;

                adapter = new SqlDataAdapter();
                adapter.SelectCommand = cmd;

                con.Open();
                adapter.Fill(ds);
                if (null == ds)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                result   = false;
            }
            finally
            {
                if (con != null && con.State == System.Data.ConnectionState.Open)
                {
                    if (adapter != null)
                    {
                        adapter.Dispose();
                    }
                    con.Close();
                }
            }
            #endregion

            return(result);
        }