Example #1
0
        public bool  GuardarAroma(Aromas aroma, string operacion)
        {
            SqlTransaction sqlTransaction = null;
            SqlConnection  cnn            = new SqlConnection(this.ConnectionString);

            try
            {
                cnn.Open();
                sqlTransaction = cnn.BeginTransaction();
                SqlDataAdapter sda = new SqlDataAdapter("dbo.Demo_Aromas", cnn);
                sda.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
                sda.SelectCommand.Transaction = sqlTransaction;
                sda.SelectCommand.Parameters.AddWithValue("@Operacion", operacion);
                sda.SelectCommand.Parameters.AddWithValue("@CodigoAroma", aroma.aroma);
                sda.SelectCommand.Parameters.AddWithValue("@Nombre", aroma.nombre);
                sda.SelectCommand.Parameters.AddWithValue("@Abrev", aroma.abreviatura);
                sda.SelectCommand.Parameters.AddWithValue("@Status", aroma.status);
                sda.SelectCommand.Parameters.Add(new SqlParameter("@Msg", SqlDbType.VarChar, 500, ParameterDirection.InputOutput, false, 0, 0, "", DataRowVersion.Current, ""));
                DataTable dt = new DataTable();
                sda.Fill(dt);
                if (!string.IsNullOrEmpty(sda.SelectCommand.Parameters["@Msg"].Value.ToString()))
                {
                    throw new Exception(sda.SelectCommand.Parameters["@Msg"].Value.ToString());
                }
                sqlTransaction.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                sqlTransaction.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                if (cnn.State != ConnectionState.Closed)
                {
                    cnn.Close();
                }
            }
        }
Example #2
0
        public Aromas TraerAroma(string codigo)
        {
            Aromas aromas = new Aromas();

            SqlDataAdapter sda = new SqlDataAdapter("dbo.Demo_Aromas", this.ConnectionString);

            sda.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
            sda.SelectCommand.Parameters.AddWithValue("@Operacion", "R");
            sda.SelectCommand.Parameters.AddWithValue("@CodigoAroma", codigo);
            DataTable dt = new DataTable();

            sda.Fill(dt);
            aromas = dt.AsEnumerable().Select(a =>
                                              new Aromas
            {
                aroma       = a["aroma"].ToString(),
                nombre      = a["nombre"].ToString(),
                abreviatura = a["abreviatura"].ToString(),
                status      = a["status"].ToString()
            }).SingleOrDefault();

            return(aromas);
        }