/// <summary>
 ///添加产品分类
 /// </summary>
 /// <param name="ptype"></param>
 /// <returns></returns>
 public RespResult AddProductionType(ProProductionType ptype)
 {
     RespResult result = new RespResult();
     try
     {
         result.Error = ProProductionTypeAccessor.Instance.Insert(ptype) ? AppError.ERROR_SUCCESS : AppError.ERROR_FAILED;
     }
     catch (Exception e)
     {
         result.Error = AppError.ERROR_FAILED;
         result.ExMessage = e.ToString();
     }
     return result;
 }
        /// <summary>
        /// 添加产品分类
        /// <param name="es">数据实体对象数组</param>
        /// <returns></returns>
        /// </summary>
        public bool Insert(ProProductionType e)
        {
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand _cmdInsertProProductionType = cmdInsertProProductionType.Clone() as MySqlCommand;
            bool returnValue = false;
            _cmdInsertProProductionType.Connection = oc;
            try
            {
                if (oc.State == ConnectionState.Closed)
                    oc.Open();
                _cmdInsertProProductionType.Parameters["@PTypeName"].Value = e.PTypeName;
                _cmdInsertProProductionType.Parameters["@UserId"].Value = e.UserId;

                returnValue = _cmdInsertProProductionType.ExecuteNonQuery() > 0 ? true : returnValue;
                return returnValue;
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdInsertProProductionType.Dispose();
                _cmdInsertProProductionType = null;
            }
        }
        /// <summary>
        /// 修改指定的数据
        /// <param name="e">修改后的数据实体对象</param>
        /// <para>数据对应的主键必须在实例中设置</para>
        /// </summary>
        public void Update(ProProductionType e)
        {
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand _cmdUpdateProProductionType = cmdUpdateProProductionType.Clone() as MySqlCommand;
            _cmdUpdateProProductionType.Connection = oc;

            try
            {
                if (oc.State == ConnectionState.Closed)
                    oc.Open();

                _cmdUpdateProProductionType.Parameters["@PTypeId"].Value = e.PTypeId;
                _cmdUpdateProProductionType.Parameters["@PTypeName"].Value = e.PTypeName;
                _cmdUpdateProProductionType.Parameters["@UserId"].Value = e.UserId;

                _cmdUpdateProProductionType.ExecuteNonQuery();

            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdUpdateProProductionType.Dispose();
                _cmdUpdateProProductionType = null;
                GC.Collect();
            }
        }
        /// <summary>
        /// 获取指定记录
        /// <param name="id">Id值</param>
        /// </summary>
        public ProProductionType Get(int PTypeId)
        {
            ProProductionType returnValue = null;
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand _cmdGetProProductionType = cmdGetProProductionType.Clone() as MySqlCommand;

            _cmdGetProProductionType.Connection = oc;
            try
            {
                _cmdGetProProductionType.Parameters["@PTypeId"].Value = PTypeId;

                if (oc.State == ConnectionState.Closed)
                    oc.Open();

                MySqlDataReader reader = _cmdGetProProductionType.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    returnValue = new ProProductionType().BuildSampleEntity(reader);
                }
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdGetProProductionType.Dispose();
                _cmdGetProProductionType = null;
                GC.Collect();
            }
            return returnValue;
        }