示例#1
0
        /// <summary>
        /// Função que faz INSERT e UPDATE na Tabela PreTesteMet
        /// </summary>
        /// <param name="objEnt"></param>
        /// <returns></returns>
        public bool salvar(MOD_preTesteMet objEnt)
        {
            try
            {
                //Varivel boleana que retorna se foi executado ou não no Banco
                //Tabela PreTesteMet
                bool blnRetorno = false;
                //Declara a lista de parametros da tabela
                List <SqlParameter> objParam = new List <SqlParameter>();

                //se não estiver marcado, é feita a inclusao na tabela
                if (Convert.ToInt64(objEnt.CodPreTesteMet).Equals(0))
                {
                    //parametros da tabela principal
                    objParam.Add(new SqlParameter("@CodPreTesteMet", retornaId()));
                    objParam.Add(new SqlParameter("@CodFichaPreTeste", string.IsNullOrEmpty(objEnt.CodFichaPreTeste) ? DBNull.Value as object : Convert.ToInt64(objEnt.CodFichaPreTeste) as object));
                    objParam.Add(new SqlParameter("@CodMetodo", string.IsNullOrEmpty(objEnt.CodMetodo) ? DBNull.Value as object : Convert.ToInt16(objEnt.CodMetodo) as object));
                    objParam.Add(new SqlParameter("@PaginaMet", string.IsNullOrEmpty(objEnt.PaginaMet) ? DBNull.Value as object : Convert.ToInt16(objEnt.PaginaMet) as object));
                    objParam.Add(new SqlParameter("@LicaoMet", string.IsNullOrEmpty(objEnt.LicaoMet) ? DBNull.Value as object : Convert.ToInt16(objEnt.LicaoMet) as object));
                    objParam.Add(new SqlParameter("@FaseMet", string.IsNullOrEmpty(objEnt.FaseMet) ? DBNull.Value as object : Convert.ToInt16(objEnt.FaseMet) as object));
                    blnRetorno = objAcessa.executar(strInsert, objParam);
                }
                else
                {
                    //parametros da tabela principal
                    objParam.Add(new SqlParameter("@CodPreTesteMet", Convert.ToInt64(objEnt.CodPreTesteMet)));
                    objParam.Add(new SqlParameter("@CodFichaPreTeste", string.IsNullOrEmpty(objEnt.CodFichaPreTeste) ? DBNull.Value as object : Convert.ToInt64(objEnt.CodFichaPreTeste) as object));
                    objParam.Add(new SqlParameter("@CodMetodo", string.IsNullOrEmpty(objEnt.CodMetodo) ? DBNull.Value as object : Convert.ToInt16(objEnt.CodMetodo) as object));
                    objParam.Add(new SqlParameter("@PaginaMet", string.IsNullOrEmpty(objEnt.PaginaMet) ? DBNull.Value as object : Convert.ToInt16(objEnt.PaginaMet) as object));
                    objParam.Add(new SqlParameter("@LicaoMet", string.IsNullOrEmpty(objEnt.LicaoMet) ? DBNull.Value as object : Convert.ToInt16(objEnt.LicaoMet) as object));
                    objParam.Add(new SqlParameter("@FaseMet", string.IsNullOrEmpty(objEnt.FaseMet) ? DBNull.Value as object : Convert.ToInt16(objEnt.FaseMet) as object));
                    blnRetorno = objAcessa.executar(strUpdate, objParam);
                }
                //retorna o blnRetorno da tabela principal
                return(blnRetorno);
            }
            catch (SqlException exl)
            {
                if (exl.Number.Equals(2601))
                {
                    throw new Exception("Não foi possivel salvar o registro, já que criaram" + "\n" +
                                        "valores duplicados na base de dados.");
                }
                else
                {
                    throw new Exception("Erro: " + exl.Message + "\n" + "Erro nº: " + exl.Number);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        /// <summary>
        /// Função que faz DELETE na Tabela PreTesteMet
        /// </summary>
        /// <param name="objEnt"></param>
        /// <returns></returns>
        public bool excluir(MOD_preTesteMet objEnt)
        {
            try
            {
                //Varivel boleana que retorna se foi executado ou não no Banco
                //Tabela
                bool blnRetorno = false;
                //Declara a lista de parametros da tabela
                List <SqlParameter> objParam = new List <SqlParameter>();

                //se não estiver marcado, é feita a inclusao na tabela
                if (!Convert.ToInt64(objEnt.CodPreTesteMet).Equals(0))
                {
                    //parametros da tabela principal
                    objParam.Add(new SqlParameter("@CodPreTesteMet", Convert.ToInt64(objEnt.CodPreTesteMet)));
                    blnRetorno = objAcessa.executar(strDelete, objParam);
                }

                //retorna o blnRetorno da tabela principal
                return(blnRetorno);
            }
            catch (SqlException exl)
            {
                if (exl.Number.Equals(547))
                {
                    throw new Exception("Impossivel excluir. Quebra de integridade!");
                }
                else
                {
                    throw new Exception("Erro: " + exl.Message + "\n" + "Erro nº: " + exl.Number);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }