public int Add(Drol entiti) { resul = 0; using (SqlConnection cnn = RConexion.Getconectar()) { cnn.Open(); cmd = null; using (cmd = new SqlCommand()) { cmd.Connection = cnn; cmd.CommandText = "SP_INSERT_ROL"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@rol", SqlDbType.VarChar, 30).Value = entiti.Nombre_rol; resul = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return(resul); } } }
//METODO SAVE CHANGES public String SaveChanges() { mesage = ""; try { Drol dr = new Drol(); dr.Idrol = idrol; dr.Nombre_rol = nombre_rol; switch (state) { case EntityState.Guardar: rol_repository.Add(dr); mesage = "Successfully Record!"; break; case EntityState.Modificar: rol_repository.Edit(dr); mesage = "Successfully Edited!"; break; case EntityState.Remover: rol_repository.Delete(dr); mesage = dr.mesage; break; default: mesage = "Error in transaction"; break; } } catch (Exception ex) { mesage = ex.ToString(); } finally { } return(mesage); }
//SHOW DATA public DataTable GetData(Drol entiti) { using (SqlConnection cnn = RConexion.Getconectar()) { cnn.Open(); cmd = null; SqlDataAdapter da = new SqlDataAdapter(); using (cmd = new SqlCommand()) { cmd.Connection = cnn; cmd.CommandText = "SP_SHOW_ROL"; cmd.CommandType = CommandType.StoredProcedure; da.SelectCommand = cmd; using (DataTable dt = new DataTable()) { da.Fill(dt); da.Dispose(); return(dt); } } } }
//REMOVE public int Delete(Drol entiti) { resul = 0; using (SqlConnection cnn = RConexion.Getconectar()) { cnn.Open(); cmd = null; using (cmd = new SqlCommand()) { cmd.Connection = cnn; cmd.CommandText = "SP_REMOVE_ROL"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@idrol", SqlDbType.Int).Value = entiti.Idrol; cmd.Parameters.Add("@mesage", SqlDbType.VarChar, 100).Direction = ParameterDirection.Output; resul = cmd.ExecuteNonQuery(); entiti.mesage = cmd.Parameters["@mesage"].Value.ToString(); cmd.Parameters.Clear(); return(resul); } } }