/// <summary> /// Função que faz INSERT e UPDATE na Tabela PreTesteMts /// </summary> /// <param name="objEnt"></param> /// <returns></returns> public bool salvar(MOD_preTesteMts objEnt) { try { //Varivel boleana que retorna se foi executado ou não no Banco //Tabela PreTesteMts 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.CodPreTesteMts).Equals(0)) { //parametros da tabela principal objParam.Add(new SqlParameter("@CodPreTesteMts", 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("@ModuloMts", string.IsNullOrEmpty(objEnt.ModuloMts) ? DBNull.Value as object : Convert.ToInt16(objEnt.ModuloMts) as object)); objParam.Add(new SqlParameter("@LicaoMts", string.IsNullOrEmpty(objEnt.LicaoMts) ? DBNull.Value as object : Convert.ToInt16(objEnt.LicaoMts) as object)); objParam.Add(new SqlParameter("@TipoMts", string.IsNullOrEmpty(objEnt.TipoMts) ? DBNull.Value as object : objEnt.TipoMts as object)); blnRetorno = objAcessa.executar(strInsert, objParam); } else { //parametros da tabela principal objParam.Add(new SqlParameter("@CodPreTesteMts", Convert.ToInt64(objEnt.CodPreTesteMts))); 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("@ModuloMts", string.IsNullOrEmpty(objEnt.ModuloMts) ? DBNull.Value as object : Convert.ToInt16(objEnt.ModuloMts) as object)); objParam.Add(new SqlParameter("@LicaoMts", string.IsNullOrEmpty(objEnt.LicaoMts) ? DBNull.Value as object : Convert.ToInt16(objEnt.LicaoMts) as object)); objParam.Add(new SqlParameter("@TipoMts", string.IsNullOrEmpty(objEnt.TipoMts) ? DBNull.Value as object : objEnt.TipoMts 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; } }
/// <summary> /// Função que faz DELETE na Tabela PreTesteMts /// </summary> /// <param name="objEnt"></param> /// <returns></returns> public bool excluir(MOD_preTesteMts 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.CodPreTesteMts).Equals(0)) { //parametros da tabela principal objParam.Add(new SqlParameter("@CodPreTesteMts", Convert.ToInt64(objEnt.CodPreTesteMts))); 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; } }